From ccdf03daaf880dd0c89a03b50c11eb083ee1cfb0 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 24 Dec 2014 07:20:17 +0100 Subject: Refactored all player block placing to go through hooks. Fixes #1618. --- src/Entities/Player.cpp | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ src/Entities/Player.h | 18 ++++++++++ 2 files changed, 114 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 15920d6cf..7bdd1c6f7 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Player.h" +#include #include "../ChatColor.h" #include "../Server.h" #include "../UI/Window.h" @@ -19,6 +20,10 @@ #include "../WorldStorage/StatSerializer.h" #include "../CompositeChat.h" +#include "../Blocks/BlockHandler.h" +#include "../Blocks/BlockSlab.h" +#include "../Blocks/ChunkInterface.h" + #include "../IniFile.h" #include "json/json.h" @@ -2168,6 +2173,97 @@ void cPlayer::LoadRank(void) +bool cPlayer::PlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +{ + sSetBlockVector blk{{a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta}}; + return PlaceBlocks(blk); +} + + + + + +void cPlayer::SendBlocksAround(int a_BlockX, int a_BlockY, int a_BlockZ, int a_Range) +{ + // Collect the coords of all the blocks to send: + sSetBlockVector blks; + for (int y = a_BlockY - a_Range + 1; y < a_BlockY + a_Range; y++) + { + for (int z = a_BlockZ - a_Range + 1; z < a_BlockZ + a_Range; z++) + { + for (int x = a_BlockX - a_Range + 1; x < a_BlockX + a_Range; x++) + { + blks.emplace_back(x, y, z, E_BLOCK_AIR, 0); // Use fake blocktype, it will get set later on. + }; + }; + } // for y + + // Get the values of all the blocks: + if (!m_World->GetBlocks(blks, false)) + { + LOGD("%s: Cannot query all blocks, not sending an update", __FUNCTION__); + return; + } + + // Divide the block changes by their respective chunks: + std::unordered_map Changes; + for (const auto & blk: blks) + { + Changes[cChunkCoords(blk.m_ChunkX, blk.m_ChunkZ)].push_back(blk); + } // for blk - blks[] + blks.clear(); + + // Send the blocks for each affected chunk: + for (auto itr = Changes.cbegin(), end = Changes.cend(); itr != end; ++itr) + { + m_ClientHandle->SendBlockChanges(itr->first.m_ChunkX, itr->first.m_ChunkZ, itr->second); + } +} + + + + + +bool cPlayer::PlaceBlocks(const sSetBlockVector & a_Blocks) +{ + // Call the "placing" hooks; if any fail, abort: + cPluginManager * pm = cPluginManager::Get(); + for (auto blk: a_Blocks) + { + if (pm->CallHookPlayerPlacingBlock(*this, blk)) + { + // Abort - re-send all the current blocks in the a_Blocks' coords to the client: + for (auto blk2: a_Blocks) + { + m_World->SendBlockTo(blk2.GetX(), blk2.GetY(), blk2.GetZ(), this); + } + return false; + } + } // for blk - a_Blocks[] + + // Set the blocks: + m_World->SetBlocks(a_Blocks); + + // Notify the blockhandlers: + cChunkInterface ChunkInterface(m_World->GetChunkMap()); + for (auto blk: a_Blocks) + { + cBlockHandler * newBlock = BlockHandler(blk.m_BlockType); + newBlock->OnPlacedByPlayer(ChunkInterface, *m_World, this, blk); + } + + // Call the "placed" hooks: + for (auto blk: a_Blocks) + { + pm->CallHookPlayerPlacedBlock(*this, blk); + } + return true; +} + + + + + void cPlayer::Detach() { super::Detach(); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index c643aaa8e..33ab5293c 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -440,8 +440,26 @@ public: Loads the m_Rank, m_Permissions, m_MsgPrefix, m_MsgSuffix and m_MsgNameColorCode members. */ void LoadRank(void); + /** Calls the block-placement hook and places the block in the world, unless refused by the hook. + If the hook prevents the placement, sends the current block at the specified coords back to the client. + Assumes that all the blocks are in currently loaded chunks. */ + bool PlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + + /** Sends the block in the specified range around the specified coord to the client + as a block change packet. + The blocks in range (a_BlockX - a_Range, a_BlockX + a_Range) are sent (NY-metric). */ + void SendBlocksAround(int a_BlockX, int a_BlockY, int a_BlockZ, int a_Range = 1); + // tolua_end + /** Calls the block placement hooks and places the blocks in the world. + First the "placing" hooks for all the blocks are called, then the blocks are placed, and finally + the "placed" hooks are called. + If the any of the "placing" hooks aborts, none of the blocks are placed and the function returns false. + Returns true if all the blocks are placed. + Assumes that all the blocks are in currently loaded chunks. */ + bool PlaceBlocks(const sSetBlockVector & a_Blocks); + // cEntity overrides: virtual bool IsCrouched (void) const { return m_IsCrouched; } virtual bool IsSprinting(void) const { return m_IsSprinting; } -- cgit v1.2.3 From 63de5f8a555e3bd4b9309792e3a9c0dcb9e8f4b6 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 24 Dec 2014 08:38:37 +0100 Subject: Replaced a std::hash specialization with explicit type. std::hash is problematic in gcc / clang, one has a class, the other a struct. --- src/Entities/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 7bdd1c6f7..1d5cc6554 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -2206,7 +2206,7 @@ void cPlayer::SendBlocksAround(int a_BlockX, int a_BlockY, int a_BlockZ, int a_R } // Divide the block changes by their respective chunks: - std::unordered_map Changes; + std::unordered_map Changes; for (const auto & blk: blks) { Changes[cChunkCoords(blk.m_ChunkX, blk.m_ChunkZ)].push_back(blk); -- cgit v1.2.3 From 5609d76ed7d8026b3bcaeb02fb42bd9ba2f27c96 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 24 Dec 2014 20:02:51 +0100 Subject: APIDump: Updated the player block placement documentation. The hooks now have fewer parameters but are called on all player-placed blocks (#1618). --- src/Entities/Player.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 33ab5293c..b94d2659e 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -442,7 +442,8 @@ public: /** Calls the block-placement hook and places the block in the world, unless refused by the hook. If the hook prevents the placement, sends the current block at the specified coords back to the client. - Assumes that all the blocks are in currently loaded chunks. */ + Assumes that the block is in a currently loaded chunk. + Returns true if the block is successfully placed. */ bool PlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); /** Sends the block in the specified range around the specified coord to the client -- cgit v1.2.3 From 2a9664d6ca8aa9eb4f554301e4d9b0ec33b465ce Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 11 Jan 2015 21:12:26 +0000 Subject: Initial convertion of a_Dt to std::chrono also refactored cWorld::m_WorldAge and cWorld::m_TimeOfDay --- src/Entities/ArrowEntity.cpp | 6 +++--- src/Entities/ArrowEntity.h | 2 +- src/Entities/Boat.cpp | 2 +- src/Entities/Boat.h | 2 +- src/Entities/EnderCrystal.cpp | 2 +- src/Entities/EnderCrystal.h | 2 +- src/Entities/Entity.cpp | 26 +++++++++++++------------- src/Entities/Entity.h | 4 ++-- src/Entities/ExpOrb.cpp | 4 ++-- src/Entities/ExpOrb.h | 2 +- src/Entities/FallingBlock.cpp | 4 ++-- src/Entities/FallingBlock.h | 2 +- src/Entities/FireworkEntity.cpp | 8 ++++---- src/Entities/FireworkEntity.h | 4 ++-- src/Entities/Floater.cpp | 2 +- src/Entities/Floater.h | 2 +- src/Entities/HangingEntity.h | 2 +- src/Entities/Minecart.cpp | 10 +++++----- src/Entities/Minecart.h | 4 ++-- src/Entities/Painting.cpp | 2 +- src/Entities/Painting.h | 2 +- src/Entities/Pawn.cpp | 2 +- src/Entities/Pawn.h | 2 +- src/Entities/Pickup.cpp | 6 +++--- src/Entities/Pickup.h | 2 +- src/Entities/Player.cpp | 2 +- src/Entities/Player.h | 4 ++-- src/Entities/ProjectileEntity.cpp | 4 ++-- src/Entities/ProjectileEntity.h | 4 ++-- src/Entities/SplashPotionEntity.h | 2 +- src/Entities/TNTEntity.cpp | 2 +- src/Entities/TNTEntity.h | 2 +- src/Entities/ThrownEggEntity.cpp | 2 +- src/Entities/ThrownEggEntity.h | 2 +- src/Entities/ThrownEnderPearlEntity.cpp | 2 +- src/Entities/ThrownEnderPearlEntity.h | 2 +- src/Entities/ThrownSnowballEntity.cpp | 2 +- src/Entities/ThrownSnowballEntity.h | 2 +- 38 files changed, 69 insertions(+), 69 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index 30f18f677..2ec825ddb 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -174,10 +174,10 @@ void cArrowEntity::CollectedBy(cPlayer & a_Dest) -void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) +void cArrowEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - m_Timer += a_Dt; + m_Timer += a_Dt.count(); if (m_bIsCollected) { @@ -209,7 +209,7 @@ void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) } else { - m_HitGroundTimer += a_Dt; + m_HitGroundTimer += a_Dt.count(); } } diff --git a/src/Entities/ArrowEntity.h b/src/Entities/ArrowEntity.h index 436ec0293..8c92049b0 100644 --- a/src/Entities/ArrowEntity.h +++ b/src/Entities/ArrowEntity.h @@ -103,6 +103,6 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; virtual void CollectedBy(cPlayer & a_Player) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; }; // tolua_export diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index 953213bca..6d8b4ef31 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -91,7 +91,7 @@ void cBoat::OnRightClicked(cPlayer & a_Player) -void cBoat::Tick(float a_Dt, cChunk & a_Chunk) +void cBoat::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); BroadcastMovementUpdate(); diff --git a/src/Entities/Boat.h b/src/Entities/Boat.h index 8de88d165..a873ff822 100644 --- a/src/Entities/Boat.h +++ b/src/Entities/Boat.h @@ -27,7 +27,7 @@ public: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; virtual void OnRightClicked(cPlayer & a_Player) override; virtual bool DoTakeDamage(TakeDamageInfo & TDI) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways) override; cBoat(double a_X, double a_Y, double a_Z); diff --git a/src/Entities/EnderCrystal.cpp b/src/Entities/EnderCrystal.cpp index 30df2c110..7a911d4db 100644 --- a/src/Entities/EnderCrystal.cpp +++ b/src/Entities/EnderCrystal.cpp @@ -29,7 +29,7 @@ void cEnderCrystal::SpawnOn(cClientHandle & a_ClientHandle) -void cEnderCrystal::Tick(float a_Dt, cChunk & a_Chunk) +void cEnderCrystal::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { UNUSED(a_Dt); // No further processing (physics e.t.c.) is needed diff --git a/src/Entities/EnderCrystal.h b/src/Entities/EnderCrystal.h index c98c3b681..8f7e2e9b9 100644 --- a/src/Entities/EnderCrystal.h +++ b/src/Entities/EnderCrystal.h @@ -23,7 +23,7 @@ private: // cEntity overrides: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void KilledBy(TakeDamageInfo & a_TDI) override; }; // tolua_export diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 54b9f2a20..c64d94528 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -772,7 +772,7 @@ void cEntity::SetHealth(int a_Health) -void cEntity::Tick(float a_Dt, cChunk & a_Chunk) +void cEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { m_TicksAlive++; @@ -841,7 +841,7 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk) -void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) +void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { int BlockX = POSX_TOINT; int BlockY = POSY_TOINT; @@ -851,15 +851,15 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) GET_AND_VERIFY_CURRENT_CHUNK(NextChunk, BlockX, BlockZ) // TODO Add collision detection with entities. - a_Dt /= 1000; // Convert from msec to sec + auto DtSec = std::chrono::duration_cast>(a_Dt); Vector3d NextPos = Vector3d(GetPosX(), GetPosY(), GetPosZ()); Vector3d NextSpeed = Vector3d(GetSpeedX(), GetSpeedY(), GetSpeedZ()); if ((BlockY >= cChunkDef::Height) || (BlockY < 0)) { // Outside of the world - AddSpeedY(m_Gravity * a_Dt); - AddPosition(GetSpeed() * a_Dt); + AddSpeedY(m_Gravity * DtSec.count()); + AddPosition(GetSpeed() * DtSec.count()); return; } @@ -930,8 +930,8 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) float fallspeed; if (IsBlockWater(BlockIn)) { - fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water - ApplyFriction(NextSpeed, 0.7, a_Dt); + fallspeed = m_Gravity * DtSec.count() / 3; // Fall 3x slower in water + ApplyFriction(NextSpeed, 0.7, DtSec.count()); } else if (BlockIn == E_BLOCK_COBWEB) { @@ -941,13 +941,13 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) else { // Normal gravity - fallspeed = m_Gravity * a_Dt; + fallspeed = m_Gravity * DtSec.count(); } NextSpeed.y += fallspeed; } else { - ApplyFriction(NextSpeed, 0.7, a_Dt); + ApplyFriction(NextSpeed, 0.7, DtSec.count()); } // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we @@ -1002,14 +1002,14 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { cTracer Tracer(GetWorld()); // Distance traced is an integer, so we round up from the distance we should go (Speed * Delta), else we will encounter collision detection failurse - int DistanceToTrace = (int)(ceil((NextSpeed * a_Dt).SqrLength()) * 2); + int DistanceToTrace = (int)(ceil((NextSpeed * DtSec.count()).SqrLength()) * 2); bool HasHit = Tracer.Trace(NextPos, NextSpeed, DistanceToTrace); if (HasHit) { // Oh noez! We hit something: verify that the (hit position - current) was smaller or equal to the (position that we should travel without obstacles - current) // This is because previously, we traced with a length that was rounded up (due to integer limitations), and in the case that something was hit, we don't want to overshoot our projected movement - if ((Tracer.RealHit - NextPos).SqrLength() <= (NextSpeed * a_Dt).SqrLength()) + if ((Tracer.RealHit - NextPos).SqrLength() <= (NextSpeed * DtSec.count()).SqrLength()) { // Block hit was within our projected path // Begin by stopping movement in the direction that we hit something. The Normal is the line perpendicular to a 2D face and in this case, stores what block face was hit through either -1 or 1. @@ -1044,13 +1044,13 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) // and that this piece of software will come to be hailed as the epitome of performance and functionality in C++, never before seen, and of such a like that will never // be henceforth seen again in the time of programmers and man alike // - NextPos += (NextSpeed * a_Dt); + NextPos += (NextSpeed * DtSec.count()); } } else { // We didn't hit anything, so move =] - NextPos += (NextSpeed * a_Dt); + NextPos += (NextSpeed * DtSec.count()); } } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index af545fe4a..de9b88dfb 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -326,10 +326,10 @@ public: // tolua_end - virtual void Tick(float a_Dt, cChunk & a_Chunk); + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk); /// Handles the physics of the entity - updates position based on speed, updates speed based on environment - virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk); + virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk); /// Updates the state related to this entity being on fire virtual void TickBurning(cChunk & a_Chunk); diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp index 751308661..9767f96ca 100644 --- a/src/Entities/ExpOrb.cpp +++ b/src/Entities/ExpOrb.cpp @@ -42,7 +42,7 @@ void cExpOrb::SpawnOn(cClientHandle & a_Client) -void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk) +void cExpOrb::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { cPlayer * a_ClosestPlayer(m_World->FindClosestPlayer(Vector3f(GetPosition()), 5)); if (a_ClosestPlayer != nullptr) @@ -69,7 +69,7 @@ void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk) } HandlePhysics(a_Dt, a_Chunk); - m_Timer += a_Dt; + m_Timer += a_Dt.count(); if (m_Timer >= 1000 * 60 * 5) // 5 minutes { Destroy(true); diff --git a/src/Entities/ExpOrb.h b/src/Entities/ExpOrb.h index bdb9a5b19..e12e3c504 100644 --- a/src/Entities/ExpOrb.h +++ b/src/Entities/ExpOrb.h @@ -22,7 +22,7 @@ public: cExpOrb(const Vector3d & a_Pos, int a_Reward); // Override functions - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void SpawnOn(cClientHandle & a_Client) override; /** Returns the number of ticks that this entity has existed */ diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index 111c5fa84..75105a0cd 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -31,7 +31,7 @@ void cFallingBlock::SpawnOn(cClientHandle & a_ClientHandle) -void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk) +void cFallingBlock::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { // GetWorld()->BroadcastTeleportEntity(*this); // Test position @@ -82,7 +82,7 @@ void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk) return; } - float MilliDt = a_Dt * 0.001f; + float MilliDt = a_Dt.count() * 0.001f; AddSpeedY(MilliDt * -9.8f); AddPosition(GetSpeed() * MilliDt); diff --git a/src/Entities/FallingBlock.h b/src/Entities/FallingBlock.h index c20fe8eb9..884938f4d 100644 --- a/src/Entities/FallingBlock.h +++ b/src/Entities/FallingBlock.h @@ -30,7 +30,7 @@ public: // cEntity overrides: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; private: BLOCKTYPE m_BlockType; diff --git a/src/Entities/FireworkEntity.cpp b/src/Entities/FireworkEntity.cpp index 68d02640a..9dc7850a7 100644 --- a/src/Entities/FireworkEntity.cpp +++ b/src/Entities/FireworkEntity.cpp @@ -19,7 +19,7 @@ cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, do -void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) +void cFireworkEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; @@ -28,7 +28,7 @@ void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) if ((PosY < 0) || (PosY >= cChunkDef::Height)) { AddSpeedY(1); - AddPosition(GetSpeed() * (a_Dt / 1000)); + AddPosition(GetSpeed() * (a_Dt.count() / 1000)); return; } @@ -53,14 +53,14 @@ void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) } AddSpeedY(1); - AddPosition(GetSpeed() * (a_Dt / 1000)); + AddPosition(GetSpeed() * (a_Dt.count() / 1000)); } -void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) +void cFireworkEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); diff --git a/src/Entities/FireworkEntity.h b/src/Entities/FireworkEntity.h index 300ec571e..c0a38a943 100644 --- a/src/Entities/FireworkEntity.h +++ b/src/Entities/FireworkEntity.h @@ -49,8 +49,8 @@ public: protected: // cProjectileEntity overrides: - virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; private: diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp index 5fe6a1238..cf8dd6c6f 100644 --- a/src/Entities/Floater.cpp +++ b/src/Entities/Floater.cpp @@ -125,7 +125,7 @@ void cFloater::SpawnOn(cClientHandle & a_Client) -void cFloater::Tick(float a_Dt, cChunk & a_Chunk) +void cFloater::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { HandlePhysics(a_Dt, a_Chunk); if (IsBlockWater(m_World->GetBlock((int) GetPosX(), (int) GetPosY(), (int) GetPosZ())) && m_World->GetBlockMeta((int) GetPosX(), (int) GetPosY(), (int) GetPosZ()) == 0) diff --git a/src/Entities/Floater.h b/src/Entities/Floater.h index 96d77ac82..d5715f89e 100644 --- a/src/Entities/Floater.h +++ b/src/Entities/Floater.h @@ -21,7 +21,7 @@ public: cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID, int a_CountDownTime); virtual void SpawnOn(cClientHandle & a_Client) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; // tolua_begin bool CanPickup(void) const { return m_CanPickupItem; } diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h index 67146a20b..d1ef79a68 100644 --- a/src/Entities/HangingEntity.h +++ b/src/Entities/HangingEntity.h @@ -43,7 +43,7 @@ public: private: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override {} + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override {} eBlockFace m_Facing; diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index fac4f0714..552d70de7 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -111,7 +111,7 @@ void cMinecart::SpawnOn(cClientHandle & a_ClientHandle) -void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) +void cMinecart::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (IsDestroyed()) // Mainly to stop detector rails triggering again after minecart is dead { @@ -165,19 +165,19 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) switch (InsideType) { - case E_BLOCK_RAIL: HandleRailPhysics(InsideMeta, a_Dt); break; + case E_BLOCK_RAIL: HandleRailPhysics(InsideMeta, a_Dt.count()); break; case E_BLOCK_ACTIVATOR_RAIL: break; case E_BLOCK_POWERED_RAIL: HandlePoweredRailPhysics(InsideMeta); break; case E_BLOCK_DETECTOR_RAIL: { - HandleDetectorRailPhysics(InsideMeta, a_Dt); + HandleDetectorRailPhysics(InsideMeta, a_Dt.count()); WasDetectorRail = true; break; } default: VERIFY(!"Unhandled rail type despite checking if block was rail!"); break; } - AddPosition(GetSpeed() * (a_Dt / 1000)); // Commit changes; as we use our own engine when on rails, this needs to be done, whereas it is normally in Entity.cpp + AddPosition(GetSpeed() * (a_Dt.count() / 1000)); // Commit changes; as we use our own engine when on rails, this needs to be done, whereas it is normally in Entity.cpp } else { @@ -1213,7 +1213,7 @@ void cMinecartWithFurnace::OnRightClicked(cPlayer & a_Player) -void cMinecartWithFurnace::Tick(float a_Dt, cChunk & a_Chunk) +void cMinecartWithFurnace::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index f7d0d5dda..1c6f4a6c4 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -38,7 +38,7 @@ public: // cEntity overrides: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; - virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; + virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual bool DoTakeDamage(TakeDamageInfo & TDI) override; virtual void Destroyed() override; @@ -171,7 +171,7 @@ public: // cEntity overrides: virtual void OnRightClicked(cPlayer & a_Player) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; // Set functions. void SetIsFueled(bool a_IsFueled, int a_FueledTimeLeft = -1) {m_IsFueled = a_IsFueled; m_FueledTimeLeft = a_FueledTimeLeft;} diff --git a/src/Entities/Painting.cpp b/src/Entities/Painting.cpp index 1aa6da0a1..6f6277f28 100644 --- a/src/Entities/Painting.cpp +++ b/src/Entities/Painting.cpp @@ -31,7 +31,7 @@ void cPainting::SpawnOn(cClientHandle & a_Client) -void cPainting::Tick(float a_Dt, cChunk & a_Chunk) +void cPainting::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { UNUSED(a_Dt); UNUSED(a_Chunk); diff --git a/src/Entities/Painting.h b/src/Entities/Painting.h index 078270b42..6e8a382fc 100644 --- a/src/Entities/Painting.h +++ b/src/Entities/Painting.h @@ -31,7 +31,7 @@ public: private: virtual void SpawnOn(cClientHandle & a_Client) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override; virtual void KilledBy(TakeDamageInfo & a_TDI) override { diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index fc8ca3d47..baf8a2f3b 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -19,7 +19,7 @@ cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) : -void cPawn::Tick(float a_Dt, cChunk & a_Chunk) +void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { // Iterate through this entity's applied effects for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();) diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index d50bcd8af..e3e99651d 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -20,7 +20,7 @@ public: cPawn(eEntityType a_EntityType, double a_Width, double a_Height); - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void KilledBy(TakeDamageInfo & a_TDI) override; // tolua_begin diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index e5e28446d..accb42a63 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -110,12 +110,12 @@ void cPickup::SpawnOn(cClientHandle & a_Client) -void cPickup::Tick(float a_Dt, cChunk & a_Chunk) +void cPickup::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); BroadcastMovementUpdate(); // Notify clients of position - m_Timer += a_Dt; + m_Timer += a_Dt.count(); if (!m_bCollected) { @@ -142,7 +142,7 @@ void cPickup::Tick(float a_Dt, cChunk & a_Chunk) { m_bCollected = true; m_Timer = 0; // We have to reset the timer. - m_Timer += a_Dt; // In case we have to destroy the pickup in the same tick. + m_Timer += a_Dt.count(); // In case we have to destroy the pickup in the same tick. if (m_Timer > 500.f) { Destroy(true); diff --git a/src/Entities/Pickup.h b/src/Entities/Pickup.h index d1176a7cf..67f2756ca 100644 --- a/src/Entities/Pickup.h +++ b/src/Entities/Pickup.h @@ -34,7 +34,7 @@ public: bool CollectedBy(cPlayer & a_Dest); // tolua_export - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; /** Returns the number of ticks that this entity has existed */ int GetAge(void) const { return static_cast(m_Timer / 50); } // tolua_export diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 1d5cc6554..1ca131375 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -191,7 +191,7 @@ void cPlayer::SpawnOn(cClientHandle & a_Client) -void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) +void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (m_ClientHandle != nullptr) { diff --git a/src/Entities/Player.h b/src/Entities/Player.h index b94d2659e..d3ed46db6 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -46,9 +46,9 @@ public: virtual void SpawnOn(cClientHandle & a_Client) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; - virtual void HandlePhysics(float a_Dt, cChunk &) override { UNUSED(a_Dt); } + virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk &) override { UNUSED(a_Dt); } /** Returns the curently equipped weapon; empty item if none */ virtual cItem GetEquippedWeapon(void) const override { return m_Inventory.GetEquippedItem(); } diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 1768714f8..4f20bfae6 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -331,7 +331,7 @@ AString cProjectileEntity::GetMCAClassName(void) const -void cProjectileEntity::Tick(float a_Dt, cChunk & a_Chunk) +void cProjectileEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); @@ -346,7 +346,7 @@ void cProjectileEntity::Tick(float a_Dt, cChunk & a_Chunk) -void cProjectileEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) +void cProjectileEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (m_IsInGround) { diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 2a98e31c7..93e442d8c 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -118,8 +118,8 @@ protected: bool m_IsInGround; // cEntity overrides: - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void SpawnOn(cClientHandle & a_Client) override; } ; // tolua_export diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h index 9302d8292..264dc0eb9 100644 --- a/src/Entities/SplashPotionEntity.h +++ b/src/Entities/SplashPotionEntity.h @@ -58,7 +58,7 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - virtual void Tick (float a_Dt, cChunk & a_Chunk) override + virtual void Tick (std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override { if (m_DestroyTimer > 0) { diff --git a/src/Entities/TNTEntity.cpp b/src/Entities/TNTEntity.cpp index 53af446cc..a89d2f300 100644 --- a/src/Entities/TNTEntity.cpp +++ b/src/Entities/TNTEntity.cpp @@ -50,7 +50,7 @@ void cTNTEntity::Explode(void) -void cTNTEntity::Tick(float a_Dt, cChunk & a_Chunk) +void cTNTEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); BroadcastMovementUpdate(); diff --git a/src/Entities/TNTEntity.h b/src/Entities/TNTEntity.h index 48503cf76..9f894338e 100644 --- a/src/Entities/TNTEntity.h +++ b/src/Entities/TNTEntity.h @@ -21,7 +21,7 @@ public: // cEntity overrides: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; // tolua_begin diff --git a/src/Entities/ThrownEggEntity.cpp b/src/Entities/ThrownEggEntity.cpp index 24c946a9c..e9ef29239 100644 --- a/src/Entities/ThrownEggEntity.cpp +++ b/src/Entities/ThrownEggEntity.cpp @@ -44,7 +44,7 @@ void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_Hit -void cThrownEggEntity::Tick(float a_Dt, cChunk & a_Chunk) +void cThrownEggEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (m_DestroyTimer > 0) { diff --git a/src/Entities/ThrownEggEntity.h b/src/Entities/ThrownEggEntity.h index 6ffedf5b5..620927c5d 100644 --- a/src/Entities/ThrownEggEntity.h +++ b/src/Entities/ThrownEggEntity.h @@ -35,7 +35,7 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; // Randomly decides whether to spawn a chicken where the egg lands. void TrySpawnChicken(const Vector3d & a_HitPos); diff --git a/src/Entities/ThrownEnderPearlEntity.cpp b/src/Entities/ThrownEnderPearlEntity.cpp index 8f1b62934..f01cdc18c 100644 --- a/src/Entities/ThrownEnderPearlEntity.cpp +++ b/src/Entities/ThrownEnderPearlEntity.cpp @@ -46,7 +46,7 @@ void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d -void cThrownEnderPearlEntity::Tick(float a_Dt, cChunk & a_Chunk) +void cThrownEnderPearlEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (m_DestroyTimer > 0) { diff --git a/src/Entities/ThrownEnderPearlEntity.h b/src/Entities/ThrownEnderPearlEntity.h index 475ebde87..94f3ab5cb 100644 --- a/src/Entities/ThrownEnderPearlEntity.h +++ b/src/Entities/ThrownEnderPearlEntity.h @@ -35,7 +35,7 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; /** Teleports the creator where the ender pearl lands */ void TeleportCreator(const Vector3d & a_HitPos); diff --git a/src/Entities/ThrownSnowballEntity.cpp b/src/Entities/ThrownSnowballEntity.cpp index 88e39d22e..24db1e7ee 100644 --- a/src/Entities/ThrownSnowballEntity.cpp +++ b/src/Entities/ThrownSnowballEntity.cpp @@ -48,7 +48,7 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & -void cThrownSnowballEntity::Tick(float a_Dt, cChunk & a_Chunk) +void cThrownSnowballEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (m_DestroyTimer > 0) { diff --git a/src/Entities/ThrownSnowballEntity.h b/src/Entities/ThrownSnowballEntity.h index f806996cc..391b0c40b 100644 --- a/src/Entities/ThrownSnowballEntity.h +++ b/src/Entities/ThrownSnowballEntity.h @@ -35,7 +35,7 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; private: -- cgit v1.2.3 From d6f042da4a4d296ab9be18884996f0d88dd23c39 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 16 Jan 2015 13:13:23 +0000 Subject: Converted ArrowEntityTiers to std::chrono --- src/Entities/ArrowEntity.cpp | 10 +++++----- src/Entities/ArrowEntity.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index 2ec825ddb..0fbbfb681 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -177,17 +177,17 @@ void cArrowEntity::CollectedBy(cPlayer & a_Dest) void cArrowEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - m_Timer += a_Dt.count(); + m_Timer += a_Dt; if (m_bIsCollected) { - if (m_Timer > 500.f) // 0.5 seconds + if (m_Timer > std::chrono::milliseconds(500)) { Destroy(); return; } } - else if (m_Timer > 1000 * 60 * 5) // 5 minutes + else if (m_Timer > std::chrono::minutes(5)) { Destroy(); return; @@ -202,14 +202,14 @@ void cArrowEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) if (!m_HasTeleported) // Sent a teleport already, don't do again { - if (m_HitGroundTimer > 500.f) // Send after half a second, could be less, but just in case + if (m_HitGroundTimer > std::chrono::milliseconds(500)) { m_World->BroadcastTeleportEntity(*this); m_HasTeleported = true; } else { - m_HitGroundTimer += a_Dt.count(); + m_HitGroundTimer += a_Dt; } } diff --git a/src/Entities/ArrowEntity.h b/src/Entities/ArrowEntity.h index 8c92049b0..2ecc16d1c 100644 --- a/src/Entities/ArrowEntity.h +++ b/src/Entities/ArrowEntity.h @@ -85,10 +85,10 @@ protected: bool m_IsCritical; /** Timer for pickup collection animation or five minute timeout */ - float m_Timer; + std::chrono::milliseconds m_Timer; /** Timer for client arrow position confirmation via TeleportEntity */ - float m_HitGroundTimer; + std::chrono::milliseconds m_HitGroundTimer; // Whether the arrow has already been teleported into the proper position in the ground. bool m_HasTeleported; -- cgit v1.2.3 From 7562a381c004470dfa8f0f94cd00f92d3c413f74 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 16 Jan 2015 13:27:10 +0000 Subject: Converted cExpOrbEntity to std::chrono --- src/Entities/ExpOrb.cpp | 8 ++++---- src/Entities/ExpOrb.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp index 9767f96ca..db7f6f2c8 100644 --- a/src/Entities/ExpOrb.cpp +++ b/src/Entities/ExpOrb.cpp @@ -8,7 +8,7 @@ cExpOrb::cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward) : cEntity(etExpOrb, a_X, a_Y, a_Z, 0.98, 0.98) , m_Reward(a_Reward) - , m_Timer(0.f) + , m_Timer(0) { SetMaxHealth(5); SetHealth(5); @@ -21,7 +21,7 @@ cExpOrb::cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward) cExpOrb::cExpOrb(const Vector3d & a_Pos, int a_Reward) : cEntity(etExpOrb, a_Pos.x, a_Pos.y, a_Pos.z, 0.98, 0.98) , m_Reward(a_Reward) - , m_Timer(0.f) + , m_Timer(0) { SetMaxHealth(5); SetHealth(5); @@ -69,8 +69,8 @@ void cExpOrb::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) } HandlePhysics(a_Dt, a_Chunk); - m_Timer += a_Dt.count(); - if (m_Timer >= 1000 * 60 * 5) // 5 minutes + m_Timer += a_Dt; + if (m_Timer >= std::chrono::minutes(5)) { Destroy(true); } diff --git a/src/Entities/ExpOrb.h b/src/Entities/ExpOrb.h index e12e3c504..9aac4f748 100644 --- a/src/Entities/ExpOrb.h +++ b/src/Entities/ExpOrb.h @@ -26,10 +26,10 @@ public: virtual void SpawnOn(cClientHandle & a_Client) override; /** Returns the number of ticks that this entity has existed */ - int GetAge(void) const { return (int)(m_Timer / 50); } // tolua_export + int GetAge(void) const { return std::chrono::duration_cast(m_Timer).count(); } // tolua_export /** Set the number of ticks that this entity has existed */ - void SetAge(int a_Age) { m_Timer = (float)(a_Age * 50); } // tolua_export + void SetAge(int a_Age) { m_Timer = cTickTime(a_Age); } // tolua_export /** Get the exp amount */ int GetReward(void) const { return m_Reward; } // tolua_export @@ -41,5 +41,5 @@ protected: int m_Reward; /** The number of ticks that the entity has existed / timer between collect and destroy; in msec */ - float m_Timer; + std::chrono::milliseconds m_Timer; } ; // tolua_export -- cgit v1.2.3 From 8dc9cf0c769b46dd3a97440f76cae4d83b52348e Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 16 Jan 2015 13:42:44 +0000 Subject: Converted MinecartEntity to std::chrono --- src/Entities/Minecart.cpp | 10 +++++----- src/Entities/Minecart.h | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 552d70de7..a906c9767 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -165,12 +165,12 @@ void cMinecart::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) switch (InsideType) { - case E_BLOCK_RAIL: HandleRailPhysics(InsideMeta, a_Dt.count()); break; + case E_BLOCK_RAIL: HandleRailPhysics(InsideMeta, a_Dt); break; case E_BLOCK_ACTIVATOR_RAIL: break; case E_BLOCK_POWERED_RAIL: HandlePoweredRailPhysics(InsideMeta); break; case E_BLOCK_DETECTOR_RAIL: { - HandleDetectorRailPhysics(InsideMeta, a_Dt.count()); + HandleDetectorRailPhysics(InsideMeta, a_Dt); WasDetectorRail = true; break; } @@ -205,7 +205,7 @@ void cMinecart::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) -void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) +void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::milliseconds a_Dt) { /* NOTE: Please bear in mind that taking away from negatives make them even more negative, @@ -565,7 +565,7 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) -void cMinecart::HandleDetectorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) +void cMinecart::HandleDetectorRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::milliseconds a_Dt) { m_World->SetBlockMeta(m_DetectorRailPosition, a_RailMeta | 0x08); @@ -576,7 +576,7 @@ void cMinecart::HandleDetectorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) -void cMinecart::HandleActivatorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) +void cMinecart::HandleActivatorRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::milliseconds a_Dt) { HandleRailPhysics(a_RailMeta & 0x07, a_Dt); } diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index 1c6f4a6c4..898776e71 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -56,7 +56,7 @@ protected: /** Handles physics on normal rails For each tick, slow down on flat rails, speed up or slow down on ascending/descending rails (depending on direction), and turn on curved rails */ - void HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt); + void HandleRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::milliseconds a_Dt); /** Handles powered rail physics Each tick, speed up or slow down cart, depending on metadata of rail (powered or not) @@ -66,10 +66,10 @@ protected: /** Handles detector rail activation Activates detector rails when a minecart is on them. Calls HandleRailPhysics() for physics simulations */ - void HandleDetectorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt); + void HandleDetectorRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::milliseconds a_Dt); /** Handles activator rails - placeholder for future implementation */ - void HandleActivatorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt); + void HandleActivatorRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::milliseconds a_Dt); /** Snaps a mincecart to a rail's axis, resetting its speed For curved rails, it changes the cart's direction as well as snapping it to axis */ -- cgit v1.2.3 From 05c40db060809612e6d0bb3bee596c4c95ce758d Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 16 Jan 2015 13:49:22 +0000 Subject: Converted cPickupEntity to std::chrono --- src/Entities/Pickup.cpp | 18 +++++++++--------- src/Entities/Pickup.h | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index accb42a63..9f2609894 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -86,7 +86,7 @@ protected: cPickup::cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) : cEntity(etPickup, a_PosX, a_PosY, a_PosZ, 0.2, 0.2) - , m_Timer(0.f) + , m_Timer(0) , m_Item(a_Item) , m_bCollected(false) , m_bIsPlayerCreated(IsPlayerCreated) @@ -115,7 +115,7 @@ void cPickup::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) super::Tick(a_Dt, a_Chunk); BroadcastMovementUpdate(); // Notify clients of position - m_Timer += a_Dt.count(); + m_Timer += a_Dt; if (!m_bCollected) { @@ -141,9 +141,9 @@ void cPickup::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) ) { m_bCollected = true; - m_Timer = 0; // We have to reset the timer. - m_Timer += a_Dt.count(); // In case we have to destroy the pickup in the same tick. - if (m_Timer > 500.f) + m_Timer = std::chrono::milliseconds(0); // We have to reset the timer. + m_Timer += a_Dt; // In case we have to destroy the pickup in the same tick. + if (m_Timer > std::chrono::milliseconds(500)) { Destroy(true); return; @@ -167,14 +167,14 @@ void cPickup::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) } else { - if (m_Timer > 500.f) // 0.5 second + if (m_Timer > std::chrono::milliseconds(500)) // 0.5 second { Destroy(true); return; } } - if (m_Timer > 1000 * 60 * 5) // 5 minutes + if (m_Timer > std::chrono::minutes(5)) // 5 minutes { Destroy(true); return; @@ -200,7 +200,7 @@ bool cPickup::CollectedBy(cPlayer & a_Dest) } // Two seconds if player created the pickup (vomiting), half a second if anything else - if (m_Timer < (m_bIsPlayerCreated ? 2000.f : 500.f)) + if (m_Timer < (m_bIsPlayerCreated ? std::chrono::seconds(2) : std::chrono::milliseconds(500))) { // LOG("Pickup %d cannot be collected by \"%s\", because it is not old enough.", m_UniqueID, a_Dest->GetName().c_str()); return false; // Not old enough @@ -234,7 +234,7 @@ bool cPickup::CollectedBy(cPlayer & a_Dest) // All of the pickup has been collected, schedule the pickup for destroying m_bCollected = true; } - m_Timer = 0; + m_Timer = std::chrono::milliseconds(0); return true; } diff --git a/src/Entities/Pickup.h b/src/Entities/Pickup.h index 67f2756ca..ed5949f37 100644 --- a/src/Entities/Pickup.h +++ b/src/Entities/Pickup.h @@ -37,10 +37,10 @@ public: virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; /** Returns the number of ticks that this entity has existed */ - int GetAge(void) const { return static_cast(m_Timer / 50); } // tolua_export + int GetAge(void) const { return std::chrono::duration_cast(m_Timer).count(); } // tolua_export /** Set the number of ticks that this entity has existed */ - void SetAge(int a_Age) { m_Timer = static_cast(a_Age * 50); } // tolua_export + void SetAge(int a_Age) { m_Timer = cTickTime(a_Age); } // tolua_export /** Returns true if the pickup has already been collected */ bool IsCollected(void) const { return m_bCollected; } // tolua_export @@ -51,7 +51,7 @@ public: private: /** The number of ticks that the entity has existed / timer between collect and destroy; in msec */ - float m_Timer; + std::chrono::milliseconds m_Timer; cItem m_Item; -- cgit v1.2.3 From e211aafaa45b0e4a12e9c50ee445377077ea8172 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 18 Jan 2015 11:02:17 +0100 Subject: Fixed type-conversion warnings. --- src/Entities/Entity.cpp | 8 ++++---- src/Entities/FireworkEntity.cpp | 4 ++-- src/Entities/Minecart.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index c64d94528..c51a27961 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -927,11 +927,11 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) if (!m_bOnGround) { - float fallspeed; + double fallspeed; if (IsBlockWater(BlockIn)) { fallspeed = m_Gravity * DtSec.count() / 3; // Fall 3x slower in water - ApplyFriction(NextSpeed, 0.7, DtSec.count()); + ApplyFriction(NextSpeed, 0.7, static_cast(DtSec.count())); } else if (BlockIn == E_BLOCK_COBWEB) { @@ -943,11 +943,11 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) // Normal gravity fallspeed = m_Gravity * DtSec.count(); } - NextSpeed.y += fallspeed; + NextSpeed.y += static_cast(fallspeed); } else { - ApplyFriction(NextSpeed, 0.7, DtSec.count()); + ApplyFriction(NextSpeed, 0.7, static_cast(DtSec.count())); } // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we diff --git a/src/Entities/FireworkEntity.cpp b/src/Entities/FireworkEntity.cpp index 9dc7850a7..32eaf669a 100644 --- a/src/Entities/FireworkEntity.cpp +++ b/src/Entities/FireworkEntity.cpp @@ -28,7 +28,7 @@ void cFireworkEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_C if ((PosY < 0) || (PosY >= cChunkDef::Height)) { AddSpeedY(1); - AddPosition(GetSpeed() * (a_Dt.count() / 1000)); + AddPosition(GetSpeed() * (static_cast(a_Dt.count()) / 1000)); return; } @@ -53,7 +53,7 @@ void cFireworkEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_C } AddSpeedY(1); - AddPosition(GetSpeed() * (a_Dt.count() / 1000)); + AddPosition(GetSpeed() * (static_cast(a_Dt.count()) / 1000)); } diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index a906c9767..776f957f4 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -177,7 +177,7 @@ void cMinecart::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) default: VERIFY(!"Unhandled rail type despite checking if block was rail!"); break; } - AddPosition(GetSpeed() * (a_Dt.count() / 1000)); // Commit changes; as we use our own engine when on rails, this needs to be done, whereas it is normally in Entity.cpp + AddPosition(GetSpeed() * (static_cast(a_Dt.count()) / 1000)); // Commit changes; as we use our own engine when on rails, this needs to be done, whereas it is normally in Entity.cpp } else { -- cgit v1.2.3