From 856764dee8f0c66397669e8c7c013c758f1d2c81 Mon Sep 17 00:00:00 2001 From: Steven Riehl Date: Sat, 11 Oct 2014 20:39:55 -0600 Subject: convert old style casts to fix warnings --- src/BlockArea.h | 136 ++++++++------- src/BlockEntities/BeaconEntity.cpp | 12 +- src/BlockEntities/DispenserEntity.cpp | 7 +- src/BlockEntities/DropSpenserEntity.cpp | 18 +- src/BlockEntities/FlowerPotEntity.cpp | 10 +- src/BlockEntities/FurnaceEntity.cpp | 52 +++--- src/BlockEntities/HopperEntity.cpp | 66 ++++---- src/BlockEntities/JukeboxEntity.cpp | 6 +- src/BlockEntities/SignEntity.cpp | 8 +- src/ChunkDef.h | 64 ++++--- src/Defines.h | 38 ++--- src/Entities/Entity.h | 184 ++++++++++----------- src/Entities/Pickup.h | 10 +- src/MersenneTwister.h | 44 ++--- src/Mobs/Monster.h | 60 ++++--- src/OSSupport/IsThread.h | 36 ++-- src/World.h | 284 ++++++++++++++++---------------- 17 files changed, 486 insertions(+), 549 deletions(-) diff --git a/src/BlockArea.h b/src/BlockArea.h index 86f7c4f2d..003872635 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -32,7 +32,7 @@ class cBlockArea // tolua_end DISALLOW_COPY_AND_ASSIGN(cBlockArea); // tolua_begin - + public: /** What data is to be queried (bit-mask) */ @@ -43,7 +43,7 @@ public: baLight = 4, baSkyLight = 8, } ; - + /** The per-block strategy to use when merging another block area into this object. See the Merge function for the description of these */ enum eMergeStrategy @@ -56,64 +56,64 @@ public: msDifference, msMask, } ; - + cBlockArea(void); ~cBlockArea(); - + /** Clears the data stored to reclaim memory */ void Clear(void); - + /** Creates a new area of the specified size and contents. Origin is set to all zeroes. BlockTypes are set to air, block metas to zero, blocklights to zero and skylights to full light. */ void Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes = baTypes | baMetas); - + /** Creates a new area of the specified size and contents. Origin is set to all zeroes. BlockTypes are set to air, block metas to zero, blocklights to zero and skylights to full light. */ void Create(const Vector3i & a_Size, int a_DataTypes = baTypes | baMetas); - + /** Resets the origin. No other changes are made, contents are untouched. */ void SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ); - + /** Resets the origin. No other changes are made, contents are untouched. */ void SetOrigin(const Vector3i & a_Origin); - + /** Reads an area of blocks specified. Returns true if successful. All coords are inclusive. */ bool Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes = baTypes | baMetas); - + /** Reads an area of blocks specified. Returns true if successful. The bounds are included in the read area. */ bool Read(cForEachChunkProvider * a_ForEachChunkProvider, const cCuboid & a_Bounds, int a_DataTypes = baTypes | baMetas); - + /** Reads an area of blocks specified. Returns true if successful. The bounds are included in the read area. */ bool Read(cForEachChunkProvider * a_ForEachChunkProvider, const Vector3i & a_Point1, const Vector3i & a_Point2, int a_DataTypes = baTypes | baMetas); - + // TODO: Write() is not too good an interface: if it fails, there's no way to repeat only for the parts that didn't write // A better way may be to return a list of cBlockAreas for each part that didn't succeed writing, so that the caller may try again - + /** Writes the area back into cWorld at the coords specified. Returns true if successful in all chunks, false if only partially / not at all */ bool Write(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes = baTypes | baMetas); - + /** Writes the area back into cWorld at the coords specified. Returns true if successful in all chunks, false if only partially / not at all */ bool Write(cForEachChunkProvider * a_ForEachChunkProvider, const Vector3i & a_MinCoords, int a_DataTypes = baTypes | baMetas); - + /** Copies this object's contents into the specified BlockArea. */ void CopyTo(cBlockArea & a_Into) const; - + /** Copies the contents from the specified BlockArea into this object. */ void CopyFrom(const cBlockArea & a_From); - + /** For testing purposes only, dumps the area into a file. */ void DumpToRawFile(const AString & a_FileName); - + /** Crops the internal contents by the specified amount of blocks from each border. */ void Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ); - + /** Expands the internal contents by the specified amount of blocks from each border */ void Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ); - + /** Merges another block area into this one, using the specified block combinating strategy This function combines another BlockArea into the current object. The strategy parameter specifies how individual blocks are combined together, using the table below. @@ -125,7 +125,7 @@ public: | A | air | air | A | A | | air | B | B | B | B | | A | B | B | A | B | - + So to sum up: - msOverwrite completely overwrites all blocks with the Src's blocks - msFillAir overwrites only those blocks that were air @@ -147,7 +147,7 @@ public: | mycelium | stone | stone | ... and mycelium | A | stone | A | ... but nothing else | A | * | A | Everything else is left as it is - + msSpongePrint: Used for most generators, it allows carving out air pockets, too, and uses the Sponge as the NOP block | area block | | @@ -155,7 +155,7 @@ public: +----------+--------+--------+ | A | sponge | A | Sponge is the NOP block | * | B | B | Everything else overwrites anything - + msMask: Combines two areas, the blocks that are the same are kept, differing ones are reset to air | area block | | @@ -166,68 +166,68 @@ public: */ void Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy); - + /** Merges another block area into this one, using the specified block combinating strategy. See Merge() above for details. */ void Merge(const cBlockArea & a_Src, const Vector3i & a_RelMinCoords, eMergeStrategy a_Strategy); - + /** Fills the entire block area with the specified data */ void Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f); - + /** Fills a cuboid inside the block area with the specified data */ void FillRelCuboid(int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f ); - + /** Fills a cuboid inside the block area with the specified data. a_Cuboid must be sorted. */ void FillRelCuboid(const cCuboid & a_RelCuboid, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f ); - + /** Draws a line from between two points with the specified data */ void RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int a_RelY2, int a_RelZ2, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f ); - + /** Draws a line from between two points with the specified data */ void RelLine(const Vector3i & a_Point1, const Vector3i & a_Point2, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f ); - + /** Rotates the entire area counter-clockwise around the Y axis */ void RotateCCW(void); - + /** Rotates the entire area clockwise around the Y axis */ void RotateCW(void); - + /** Mirrors the entire area around the XY plane */ void MirrorXY(void); - + /** Mirrors the entire area around the XZ plane */ void MirrorXZ(void); - + /** Mirrors the entire area around the YZ plane */ void MirrorYZ(void); - + /** Rotates the entire area counter-clockwise around the Y axis, doesn't use blockhandlers for block meta */ void RotateCCWNoMeta(void); - + /** Rotates the entire area clockwise around the Y axis, doesn't use blockhandlers for block meta */ void RotateCWNoMeta(void); - + /** Mirrors the entire area around the XY plane, doesn't use blockhandlers for block meta */ void MirrorXYNoMeta(void); - + /** Mirrors the entire area around the XZ plane, doesn't use blockhandlers for block meta */ void MirrorXZNoMeta(void); - + /** Mirrors the entire area around the YZ plane, doesn't use blockhandlers for block meta */ void MirrorYZNoMeta(void); - + // Setters: void SetRelBlockType (int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType); void SetBlockType (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType); @@ -253,80 +253,80 @@ public: void SetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); - + // tolua_end - + // These need manual exporting, tolua generates the binding as requiring 2 extra input params void GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; void GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; - + // GetSize() is already exported manually to return 3 numbers, can't auto-export const Vector3i & GetSize(void) const { return m_Size; } - + // GetOrigin() is already exported manually to return 3 numbers, can't auto-export const Vector3i & GetOrigin(void) const { return m_Origin; } - + // tolua_begin - + int GetSizeX(void) const { return m_Size.x; } int GetSizeY(void) const { return m_Size.y; } int GetSizeZ(void) const { return m_Size.z; } - + /** Returns the volume of the area, as number of blocks */ int GetVolume(void) const { return m_Size.x * m_Size.y * m_Size.z; } - + int GetOriginX(void) const { return m_Origin.x; } int GetOriginY(void) const { return m_Origin.y; } int GetOriginZ(void) const { return m_Origin.z; } - + /** Returns the datatypes that are stored in the object (bitmask of baXXX values) */ int GetDataTypes(void) const; - + bool HasBlockTypes (void) const { return (m_BlockTypes != NULL); } bool HasBlockMetas (void) const { return (m_BlockMetas != NULL); } bool HasBlockLights (void) const { return (m_BlockLight != NULL); } bool HasBlockSkyLights(void) const { return (m_BlockSkyLight != NULL); } - + // tolua_end - + // Clients can use these for faster access to all blocktypes. Be careful though! /** Returns the internal pointer to the block types */ BLOCKTYPE * GetBlockTypes (void) const { return m_BlockTypes; } NIBBLETYPE * GetBlockMetas (void) const { return m_BlockMetas; } // NOTE: one byte per block! NIBBLETYPE * GetBlockLight (void) const { return m_BlockLight; } // NOTE: one byte per block! NIBBLETYPE * GetBlockSkyLight(void) const { return m_BlockSkyLight; } // NOTE: one byte per block! - size_t GetBlockCount(void) const { return (size_t)(m_Size.x * m_Size.y * m_Size.z); } + size_t GetBlockCount(void) const { return static_cast(m_Size.x * m_Size.y * m_Size.z); } int MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const; protected: friend class cChunkDesc; friend class cSchematicFileSerializer; - + class cChunkReader : public cChunkDataCallback { public: cChunkReader(cBlockArea & a_Area); - + protected: cBlockArea & m_Area; Vector3i m_Origin; int m_CurrentChunkX; int m_CurrentChunkZ; - + void CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLETYPE * a_ChunkSrc); - + // cChunkDataCallback overrides: virtual bool Coords(int a_ChunkX, int a_ChunkZ) override; virtual void ChunkData(const cChunkData & a_BlockTypes) override; } ; - + typedef NIBBLETYPE * NIBBLEARRAY; - - + + Vector3i m_Origin; Vector3i m_Size; - + /** An extra data value sometimes stored in the .schematic file. Used mainly by the WorldEdit plugin. cBlockArea doesn't use this value in any way. */ Vector3i m_WEOffset; @@ -335,10 +335,10 @@ protected: NIBBLETYPE * m_BlockMetas; // Each meta is stored as a separate byte for faster access NIBBLETYPE * m_BlockLight; // Each light value is stored as a separate byte for faster access NIBBLETYPE * m_BlockSkyLight; // Each light value is stored as a separate byte for faster access - + /** Clears the data stored and prepares a fresh new block area with the specified dimensions */ bool SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes); - + // Basic Setters: void SetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Value, NIBBLETYPE * a_Array); void SetNibble (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Value, NIBBLETYPE * a_Array); @@ -346,11 +346,11 @@ protected: // Basic Getters: NIBBLETYPE GetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE * a_Array) const; NIBBLETYPE GetNibble (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE * a_Array) const; - + // Crop helpers: void CropBlockTypes(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ); void CropNibbles (NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ); - + // Expand helpers: void ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ); void ExpandNibbles (NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ); @@ -361,13 +361,9 @@ protected: int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight ); - + template void MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy, const NIBBLETYPE * SrcMetas, NIBBLETYPE * DstMetas); // tolua_begin } ; // tolua_end - - - - diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp index 02f45a097..de23f7e79 100644 --- a/src/BlockEntities/BeaconEntity.cpp +++ b/src/BlockEntities/BeaconEntity.cpp @@ -227,9 +227,9 @@ void cBeaconEntity::GiveEffects(void) virtual bool Item(cPlayer * a_Player) { Vector3d PlayerPosition = Vector3d(a_Player->GetPosition()); - if (PlayerPosition.y > (double)m_PosY) + if (PlayerPosition.y > static_cast(m_PosY)) { - PlayerPosition.y = (double)m_PosY; + PlayerPosition.y = static_cast(m_PosY); } // TODO: Vanilla minecraft uses an AABB check instead of a radius one @@ -255,7 +255,7 @@ void cBeaconEntity::GiveEffects(void) , m_PrimaryEffect(a_PrimaryEffect) , m_SecondaryEffect(a_SecondaryEffect) , m_EffectLevel(a_EffectLevel) - {}; + {} } PlayerCallback(Radius, m_PosX, m_PosY, m_PosZ, m_PrimaryEffect, SecondaryEffect, EffectLevel); GetWorld()->ForEachPlayer(PlayerCallback); @@ -288,7 +288,7 @@ void cBeaconEntity::UsedBy(cPlayer * a_Player) OpenWindow(new cBeaconWindow(m_PosX, m_PosY, m_PosZ, this)); Window = GetWindow(); } - + if (Window != NULL) { // if (a_Player->GetWindow() != Window) @@ -307,7 +307,3 @@ void cBeaconEntity::SendTo(cClientHandle & a_Client) { a_Client.SendUpdateBlockEntity(*this); } - - - - diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index aea854dc2..157862bd1 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -105,7 +105,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) { double MobX = 0.5 + (DispX + DispChunk->GetPosX() * cChunkDef::Width); double MobZ = 0.5 + (DispZ + DispChunk->GetPosZ() * cChunkDef::Width); - if (m_World->SpawnMob(MobX, DispY, MobZ, (eMonsterType)m_Contents.GetSlot(a_SlotNum).m_ItemDamage) >= 0) + if (m_World->SpawnMob(MobX, DispY, MobZ, static_cast(m_Contents.GetSlot(a_SlotNum).m_ItemDamage)) >= 0) { m_Contents.ChangeSlotCount(a_SlotNum, -1); } @@ -190,7 +190,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) void cDispenserEntity::SpawnProjectileFromDispenser(int a_BlockX, int a_BlockY, int a_BlockZ, cProjectileEntity::eKind a_Kind, const Vector3d & a_ShootVector) { - m_World->CreateProjectile((double)a_BlockX + 0.5, (double)a_BlockY + 0.5, (double)a_BlockZ + 0.5, a_Kind, NULL, NULL, &a_ShootVector); + m_World->CreateProjectile(static_cast(a_BlockX + 0.5), static_cast(a_BlockY + 0.5), static_cast(a_BlockZ + 0.5), a_Kind, NULL, NULL, &a_ShootVector); } @@ -275,6 +275,3 @@ bool cDispenserEntity::EmptyLiquidBucket(BLOCKTYPE a_BlockInFront, int a_SlotNum m_Contents.AddItem(EmptyBucket); return true; } - - - diff --git a/src/BlockEntities/DropSpenserEntity.cpp b/src/BlockEntities/DropSpenserEntity.cpp index dac951b27..2cbc947dc 100644 --- a/src/BlockEntities/DropSpenserEntity.cpp +++ b/src/BlockEntities/DropSpenserEntity.cpp @@ -61,7 +61,7 @@ void cDropSpenserEntity::DropSpense(cChunk & a_Chunk) { // Pick one of the occupied slots: int OccupiedSlots[9]; - int SlotsCnt = 0; + uint SlotsCnt = 0; for (int i = m_Contents.GetNumSlots() - 1; i >= 0; i--) { if (!m_Contents.GetSlot(i).IsEmpty()) @@ -70,19 +70,19 @@ void cDropSpenserEntity::DropSpense(cChunk & a_Chunk) SlotsCnt++; } } // for i - m_Contents[] - + if (SlotsCnt == 0) { // Nothing in the dropspenser, play the click sound m_World->BroadcastSoundEffect("random.click", m_PosX * 8, m_PosY * 8, m_PosZ * 8, 1.0f, 1.2f); return; } - + int RandomSlot = m_World->GetTickRandomNumber(SlotsCnt - 1); - + // DropSpense the item, using the specialized behavior in the subclasses: DropSpenseFromSlot(a_Chunk, OccupiedSlots[RandomSlot]); - + // Broadcast a smoke and click effects: NIBBLETYPE Meta = a_Chunk.GetMeta(m_RelX, m_PosY, m_RelZ); int SmokeDir = 0; @@ -132,7 +132,7 @@ bool cDropSpenserEntity::Tick(float a_Dt, cChunk & a_Chunk) { return false; } - + m_ShouldDropSpense = false; DropSpense(a_Chunk); return true; @@ -160,7 +160,7 @@ void cDropSpenserEntity::UsedBy(cPlayer * a_Player) OpenWindow(new cDropSpenserWindow(m_PosX, m_PosY, m_PosZ, this)); Window = GetWindow(); } - + if (Window != NULL) { if (a_Player->GetWindow() != Window) @@ -205,7 +205,3 @@ void cDropSpenserEntity::DropFromSlot(cChunk & a_Chunk, int a_SlotNum) m_World->SpawnItemPickups(Pickups, MicroX, MicroY, MicroZ, PickupSpeedX, PickupSpeedY, PickupSpeedZ); } - - - - diff --git a/src/BlockEntities/FlowerPotEntity.cpp b/src/BlockEntities/FlowerPotEntity.cpp index 01560f814..ad7b496cc 100644 --- a/src/BlockEntities/FlowerPotEntity.cpp +++ b/src/BlockEntities/FlowerPotEntity.cpp @@ -28,7 +28,7 @@ void cFlowerPotEntity::UsedBy(cPlayer * a_Player) { return; } - + cItem SelectedItem = a_Player->GetInventory().GetEquippedItem(); if (IsFlower(SelectedItem.m_ItemType, SelectedItem.m_ItemDamage)) { @@ -63,7 +63,7 @@ void cFlowerPotEntity::Destroy(void) cItems Pickups; Pickups.Add(m_Item); m_World->SpawnItemPickups(Pickups, m_PosX + 0.5, m_PosY + 0.5, m_PosZ + 0.5); - + m_Item.Empty(); } } @@ -88,7 +88,7 @@ bool cFlowerPotEntity::IsFlower(short m_ItemType, short m_ItemData) } case E_BLOCK_TALL_GRASS: { - return (m_ItemData == (short) 2); + return (m_ItemData == static_cast(2)); } default: { @@ -96,7 +96,3 @@ bool cFlowerPotEntity::IsFlower(short m_ItemType, short m_ItemData) } } } - - - - diff --git a/src/BlockEntities/FurnaceEntity.cpp b/src/BlockEntities/FurnaceEntity.cpp index 4452fc00a..d165df079 100644 --- a/src/BlockEntities/FurnaceEntity.cpp +++ b/src/BlockEntities/FurnaceEntity.cpp @@ -67,8 +67,8 @@ void cFurnaceEntity::UsedBy(cPlayer * a_Player) if (a_Player->GetWindow() != Window) { a_Player->OpenWindow(Window); - BroadcastProgress(PROGRESSBAR_FUEL, (short)m_LastProgressFuel); - BroadcastProgress(PROGRESSBAR_SMELTING, (short)m_LastProgressCook); + BroadcastProgress(PROGRESSBAR_FUEL, static_cast(m_LastProgressFuel)); + BroadcastProgress(PROGRESSBAR_SMELTING, static_cast(m_LastProgressCook)); } } } @@ -112,16 +112,16 @@ bool cFurnaceEntity::Tick(float a_Dt, cChunk & a_Chunk) FinishOne(); } } - + m_TimeBurned++; if (m_TimeBurned >= m_FuelBurnTime) { // The current fuel has been exhausted, use another one, if possible BurnNewFuel(); } - + UpdateProgressBars(); - + return true; } @@ -166,7 +166,7 @@ void cFurnaceEntity::FinishOne() m_Contents.ChangeSlotCount(fsOutput, m_CurrentRecipe->Out->m_ItemCount); } m_Contents.ChangeSlotCount(fsInput, -m_CurrentRecipe->In->m_ItemCount); - + UpdateIsCooking(); } @@ -186,7 +186,7 @@ void cFurnaceEntity::BurnNewFuel(void) SetIsCooking(false); return; } - + // Is the input and output ready for cooking? if (!CanCookInputToOutput()) { @@ -214,13 +214,13 @@ void cFurnaceEntity::BurnNewFuel(void) void cFurnaceEntity::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) { super::OnSlotChanged(a_ItemGrid, a_SlotNum); - + if (m_World == NULL) { // The furnace isn't initialized yet, do no processing return; } - + ASSERT(a_ItemGrid == &m_Contents); switch (a_SlotNum) { @@ -229,13 +229,13 @@ void cFurnaceEntity::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) UpdateInput(); break; } - + case fsFuel: { UpdateFuel(); break; } - + case fsOutput: { UpdateOutput(); @@ -258,7 +258,7 @@ void cFurnaceEntity::UpdateInput(void) m_TimeCooked = 0; } m_LastInput = m_Contents.GetSlot(fsInput); - + cFurnaceRecipe * FR = cRoot::Get()->GetFurnaceRecipe(); m_CurrentRecipe = FR->GetRecipeFrom(m_Contents.GetSlot(fsInput)); if (!CanCookInputToOutput()) @@ -271,7 +271,7 @@ void cFurnaceEntity::UpdateInput(void) { m_NeedCookTime = m_CurrentRecipe->CookTime; SetIsCooking(true); - + // Start burning new fuel if there's no flame now: if (GetFuelBurnTimeLeft() <= 0) { @@ -292,7 +292,7 @@ void cFurnaceEntity::UpdateFuel(void) // The current fuel is still burning, don't modify anything: return; } - + // The current fuel is spent, try to burn some more: BurnNewFuel(); } @@ -312,7 +312,7 @@ void cFurnaceEntity::UpdateOutput(void) SetIsCooking(false); return; } - + // No need to burn new fuel, the Tick() function will take care of that // Can cook, start cooking if not already underway: @@ -339,7 +339,7 @@ void cFurnaceEntity::UpdateIsCooking(void) m_NeedCookTime = 0; return; } - + SetIsCooking(true); } @@ -355,7 +355,7 @@ bool cFurnaceEntity::CanCookInputToOutput(void) const // This input cannot be cooked return false; } - + const cItem & Slot = m_Contents.GetSlot(fsOutput); if (Slot.IsEmpty()) { @@ -368,13 +368,13 @@ bool cFurnaceEntity::CanCookInputToOutput(void) const // The output slot is blocked with something that cannot be stacked with the recipe's output return false; } - + if (Slot.IsFullStack()) { // Cannot add any more items to the output slot return false; } - + return true; } @@ -387,18 +387,18 @@ void cFurnaceEntity::UpdateProgressBars(void) { // In order to preserve bandwidth, an update is sent only every 10th tick // That's why the comparisons use the division by eight - + int CurFuel = (m_FuelBurnTime > 0) ? (200 - 200 * m_TimeBurned / m_FuelBurnTime) : 0; if ((CurFuel / 8) != (m_LastProgressFuel / 8)) { - BroadcastProgress(PROGRESSBAR_FUEL, (short)CurFuel); + BroadcastProgress(PROGRESSBAR_FUEL, static_cast(CurFuel)); m_LastProgressFuel = CurFuel; } - + int CurCook = (m_NeedCookTime > 0) ? (200 * m_TimeCooked / m_NeedCookTime) : 0; if ((CurCook / 8) != (m_LastProgressCook / 8)) { - BroadcastProgress(PROGRESSBAR_SMELTING, (short)CurCook); + BroadcastProgress(PROGRESSBAR_SMELTING, static_cast(CurCook)); m_LastProgressCook = CurCook; } } @@ -415,11 +415,7 @@ void cFurnaceEntity::SetIsCooking(bool a_IsCooking) } m_IsCooking = a_IsCooking; - + // Light or extinguish the furnace: m_World->FastSetBlock(m_PosX, m_PosY, m_PosZ, m_IsCooking ? E_BLOCK_LIT_FURNACE : E_BLOCK_FURNACE, m_BlockMeta); } - - - - diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 103f516fc..9f64ea148 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -58,7 +58,7 @@ bool cHopperEntity::Tick(float a_Dt, cChunk & a_Chunk) { UNUSED(a_Dt); Int64 CurrentTick = a_Chunk.GetWorld()->GetWorldAge(); - + bool res = false; res = MoveItemsIn (a_Chunk, CurrentTick) || res; res = MovePickupsIn(a_Chunk, CurrentTick) || res; @@ -74,7 +74,7 @@ void cHopperEntity::SendTo(cClientHandle & a_Client) { // The hopper entity doesn't need anything sent to the client when it's created / gets in the viewdistance // All the actual handling is in the cWindow UI code that gets called when the hopper is rclked - + UNUSED(a_Client); } @@ -91,7 +91,7 @@ void cHopperEntity::UsedBy(cPlayer * a_Player) OpenNewWindow(); Window = GetWindow(); } - + // Open the window for the player: if (Window != NULL) { @@ -138,7 +138,7 @@ bool cHopperEntity::MoveItemsIn(cChunk & a_Chunk, Int64 a_CurrentTick) // Too early after the previous transfer return false; } - + // Try moving an item in: bool res = false; switch (a_Chunk.GetBlock(m_RelX, m_PosY + 1, m_RelZ)) @@ -161,17 +161,17 @@ bool cHopperEntity::MoveItemsIn(cChunk & a_Chunk, Int64 a_CurrentTick) case E_BLOCK_DROPPER: case E_BLOCK_HOPPER: { - res = MoveItemsFromGrid(*(cBlockEntityWithItems *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ)); + res = MoveItemsFromGrid(*static_cast(a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ))); break; } } - + // If the item has been moved, reset the last tick: if (res) { m_LastMoveItemsInTick = a_CurrentTick; } - + return res; } @@ -205,12 +205,12 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) } Vector3f EntityPos = a_Entity->GetPosition(); - Vector3f BlockPos(m_Pos.x + 0.5f, (float)m_Pos.y + 1, m_Pos.z + 0.5f); // One block above hopper, and search from center outwards + Vector3f BlockPos(m_Pos.x + 0.5f, static_cast(m_Pos.y) + 1, m_Pos.z + 0.5f); // One block above hopper, and search from center outwards double Distance = (EntityPos - BlockPos).Length(); if (Distance < 0.5) { - if (TrySuckPickupIn((cPickup *)a_Entity)) + if (TrySuckPickupIn(static_cast(a_Entity))) { return false; } @@ -238,9 +238,9 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) m_bFoundPickupsAbove = true; int PreviousCount = m_Contents.GetSlot(i).m_ItemCount; - + Item.m_ItemCount -= m_Contents.ChangeSlotCount(i, Item.m_ItemCount) - PreviousCount; // Set count to however many items were added - + if (Item.IsEmpty()) { a_Pickup->Destroy(); // Kill pickup if all items were added @@ -280,7 +280,7 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick) // Too early after the previous transfer return false; } - + // Get the coords of the block where to output items: int OutX, OutY, OutZ; NIBBLETYPE Meta = a_Chunk.GetMeta(m_RelX, m_PosY, m_RelZ); @@ -294,7 +294,7 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick) // Cannot output below the zero-th block level return false; } - + // Convert coords to relative: int OutRelX = OutX - a_Chunk.GetPosX() * cChunkDef::Width; int OutRelZ = OutZ - a_Chunk.GetPosZ() * cChunkDef::Width; @@ -304,7 +304,7 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick) // The destination chunk has been unloaded, don't tick return false; } - + // Call proper moving function, based on the blocktype present at the coords: bool res = false; switch (DestChunk->GetBlock(OutRelX, OutY, OutRelZ)) @@ -327,7 +327,7 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick) case E_BLOCK_DROPPER: case E_BLOCK_HOPPER: { - cBlockEntityWithItems * BlockEntity = (cBlockEntityWithItems *)DestChunk->GetBlockEntity(OutX, OutY, OutZ); + cBlockEntityWithItems * BlockEntity = static_cast(DestChunk->GetBlockEntity(OutX, OutY, OutZ)); if (BlockEntity == NULL) { LOGWARNING("%s: A block entity was not found where expected at {%d, %d, %d}", __FUNCTION__, OutX, OutY, OutZ); @@ -337,13 +337,13 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick) break; } } - + // If the item has been moved, reset the last tick: if (res) { m_LastMoveItemsOutTick = a_CurrentTick; } - + return res; } @@ -354,7 +354,7 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick) /// Moves items from a chest (dblchest) above the hopper into this hopper. Returns true if contents have changed. bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) { - cChestEntity * MainChest = (cChestEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ); + cChestEntity * MainChest = static_cast(a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ)); if (MainChest == NULL) { LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX, m_PosY + 1, m_PosZ); @@ -365,7 +365,7 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) // Moved the item from the chest directly above the hopper return true; } - + // Check if the chest is a double-chest (chest directly above was empty), if so, try to move from there: static const struct { @@ -395,7 +395,7 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) continue; } - cChestEntity * SideChest = (cChestEntity *)Neighbor->GetBlockEntity(m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z); + cChestEntity * SideChest = static_cast(Neighbor->GetBlockEntity(m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z)); if (SideChest == NULL) { LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z); @@ -409,7 +409,7 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) } return false; } - + // The chest was single and nothing could be moved return false; } @@ -421,13 +421,13 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) /// Moves items from a furnace above the hopper into this hopper. Returns true if contents have changed. bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk) { - cFurnaceEntity * Furnace = (cFurnaceEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ); + cFurnaceEntity * Furnace = static_cast(a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ)); if (Furnace == NULL) { LOGWARNING("%s: A furnace entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX, m_PosY + 1, m_PosZ); return false; } - + // Try move from the output slot: if (MoveItemsFromSlot(*Furnace, cFurnaceEntity::fsOutput, true)) { @@ -435,7 +435,7 @@ bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk) Furnace->SetOutputSlot(NewOutput.AddCount(-1)); return true; } - + // No output moved, check if we can move an empty bucket out of the fuel slot: if (Furnace->GetFuelSlot().m_ItemType == E_ITEM_BUCKET) { @@ -445,7 +445,7 @@ bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk) return true; } } - + // Nothing can be moved return false; } @@ -458,7 +458,7 @@ bool cHopperEntity::MoveItemsFromGrid(cBlockEntityWithItems & a_Entity) { cItemGrid & Grid = a_Entity.GetContents(); int NumSlots = Grid.GetNumSlots(); - + // First try adding items of types already in the hopper: for (int i = 0; i < NumSlots; i++) { @@ -519,7 +519,7 @@ bool cHopperEntity::MoveItemsFromSlot(cBlockEntityWithItems & a_Entity, int a_Sl // Plugin disagrees with the move continue; } - + m_Contents.ChangeSlotCount(i, 1); return true; } @@ -535,7 +535,7 @@ bool cHopperEntity::MoveItemsFromSlot(cBlockEntityWithItems & a_Entity, int a_Sl bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ) { // Try the chest directly connected to the hopper: - cChestEntity * ConnectedChest = (cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ); + cChestEntity * ConnectedChest = static_cast(a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ)); if (ConnectedChest == NULL) { LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, a_BlockX, a_BlockY, a_BlockZ); @@ -578,7 +578,7 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block continue; } - cChestEntity * Chest = (cChestEntity *)Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z); + cChestEntity * Chest = static_cast(Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z)); if (Chest == NULL) { LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d} (%d, %d)", __FUNCTION__, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z, x, z); @@ -590,7 +590,7 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block } return false; } - + // The chest was single and nothing could be moved return false; } @@ -602,7 +602,7 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block /// Moves items to the furnace at the specified coords. Returns true if contents have changed bool cHopperEntity::MoveItemsToFurnace(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_HopperMeta) { - cFurnaceEntity * Furnace = (cFurnaceEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ); + cFurnaceEntity * Furnace = static_cast(a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ)); if (a_HopperMeta == E_META_HOPPER_FACING_YM) { // Feed the input slot of the furnace @@ -684,7 +684,3 @@ bool cHopperEntity::MoveItemsToSlot(cBlockEntityWithItems & a_Entity, int a_DstS return false; } } - - - - diff --git a/src/BlockEntities/JukeboxEntity.cpp b/src/BlockEntities/JukeboxEntity.cpp index bb9b335e0..473526855 100644 --- a/src/BlockEntities/JukeboxEntity.cpp +++ b/src/BlockEntities/JukeboxEntity.cpp @@ -79,7 +79,7 @@ bool cJukeboxEntity::EjectRecord(void) } cItems Drops; - Drops.push_back(cItem(m_Record, 1, 0)); + Drops.push_back(cItem(static_cast(m_Record), 1, 0)); m_Record = 0; m_World->SpawnItemPickups(Drops, m_PosX + 0.5, m_PosY + 1, m_PosZ + 0.5, 8); m_World->BroadcastSoundParticleEffect(1005, m_PosX, m_PosY, m_PosZ, 0); @@ -113,7 +113,3 @@ void cJukeboxEntity::SetRecord(int a_Record) { m_Record = a_Record; } - - - - diff --git a/src/BlockEntities/SignEntity.cpp b/src/BlockEntities/SignEntity.cpp index d048d0218..9a2695b3f 100644 --- a/src/BlockEntities/SignEntity.cpp +++ b/src/BlockEntities/SignEntity.cpp @@ -45,7 +45,7 @@ void cSignEntity::SetLines(const AString & a_Line1, const AString & a_Line2, con void cSignEntity::SetLine(int a_Index, const AString & a_Line) { - if ((a_Index < 0) || (a_Index >= (int)ARRAYCOUNT(m_Line))) + if ((a_Index < 0) || (a_Index >= static_cast(ARRAYCOUNT(m_Line)))) { LOGWARNING("%s: setting a non-existent line %d (value \"%s\"", __FUNCTION__, a_Index, a_Line.c_str()); return; @@ -59,7 +59,7 @@ void cSignEntity::SetLine(int a_Index, const AString & a_Line) AString cSignEntity::GetLine(int a_Index) const { - if ((a_Index < 0) || (a_Index >= (int)ARRAYCOUNT(m_Line))) + if ((a_Index < 0) || (a_Index >= static_cast(ARRAYCOUNT(m_Line)))) { LOGWARNING("%s: requesting a non-existent line %d", __FUNCTION__, a_Index); return ""; @@ -75,7 +75,3 @@ void cSignEntity::SendTo(cClientHandle & a_Client) { a_Client.SendUpdateSign(m_PosX, m_PosY, m_PosZ, m_Line[0], m_Line[1], m_Line[2], m_Line[3]); } - - - - diff --git a/src/ChunkDef.h b/src/ChunkDef.h index f4ed66c4b..6ffe47ffb 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -66,7 +66,7 @@ public: /// The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the highest non-air block in the column typedef HEIGHTTYPE HeightMap[Width * Width]; - + /** The type used for any biomemap operations and storage inside MCServer, using MCServer biomes (need not correspond to client representation!) idx = x + Width * z // Need to verify this with the protocol spec, currently unknown! @@ -95,8 +95,8 @@ public: a_X = a_X - a_ChunkX * Width; a_Z = a_Z - a_ChunkZ * Width; } - - + + /// Converts absolute block coords to chunk coords: inline static void BlockToChunk(int a_X, int a_Z, int & a_ChunkX, int & a_ChunkZ) { @@ -165,15 +165,15 @@ public: ASSERT((a_Z >= 0) && (a_Z < Width)); a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)] = a_Type; } - - + + inline static void SetBlock(BLOCKTYPE * a_BlockTypes, int a_Index, BLOCKTYPE a_Type) { ASSERT((a_Index >= 0) && (a_Index <= NumBlocks)); a_BlockTypes[a_Index] = a_Type; } - - + + inline static BLOCKTYPE GetBlock(const BLOCKTYPE * a_BlockTypes, int a_X, int a_Y, int a_Z) { ASSERT((a_X >= 0) && (a_X < Width)); @@ -181,39 +181,39 @@ public: ASSERT((a_Z >= 0) && (a_Z < Width)); return a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)]; } - - + + inline static BLOCKTYPE GetBlock(const BLOCKTYPE * a_BlockTypes, int a_Idx) { ASSERT((a_Idx >= 0) && (a_Idx < NumBlocks)); return a_BlockTypes[a_Idx]; } - - + + inline static int GetHeight(const HeightMap & a_HeightMap, int a_X, int a_Z) { ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Z >= 0) && (a_Z < Width)); return a_HeightMap[a_X + Width * a_Z]; } - - + + inline static void SetHeight(HeightMap & a_HeightMap, int a_X, int a_Z, unsigned char a_Height) { ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Z >= 0) && (a_Z < Width)); a_HeightMap[a_X + Width * a_Z] = a_Height; } - - + + inline static EMCSBiome GetBiome(const BiomeMap & a_BiomeMap, int a_X, int a_Z) { ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Z >= 0) && (a_Z < Width)); return a_BiomeMap[a_X + Width * a_Z]; } - - + + inline static void SetBiome(BiomeMap & a_BiomeMap, int a_X, int a_Z, EMCSBiome a_Biome) { ASSERT((a_X >= 0) && (a_X < Width)); @@ -226,11 +226,11 @@ public: { if ((a_BlockIdx > -1) && (a_BlockIdx < NumBlocks)) { - if ((size_t)(a_BlockIdx / 2) >= a_Buffer.size()) + if (static_cast((a_BlockIdx / 2)) >= a_Buffer.size()) { return (a_IsSkyLightNibble ? 0xff : 0); } - return (a_Buffer[(size_t)(a_BlockIdx / 2)] >> ((a_BlockIdx & 1) * 4)) & 0x0f; + return (a_Buffer[static_cast(a_BlockIdx / 2)] >> ((a_BlockIdx & 1) * 4)) & 0x0f; } ASSERT(!"cChunkDef::GetNibble(): index out of chunk range!"); return 0; @@ -241,7 +241,7 @@ public: { if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { - size_t Index = (size_t)MakeIndexNoCheck(x, y, z); + size_t Index = static_cast(MakeIndexNoCheck(x, y, z)); if ((Index / 2) >= a_Buffer.size()) { return (a_IsSkyLightNibble ? 0xff : 0); @@ -258,7 +258,7 @@ public: if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { int Index = MakeIndexNoCheck(x, y, z); - return (a_Buffer[(size_t)(Index / 2)] >> ((Index & 1) * 4)) & 0x0f; + return (a_Buffer[static_cast(Index / 2)] >> ((Index & 1) * 4)) & 0x0f; } ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); return 0; @@ -272,11 +272,11 @@ public: ASSERT(!"cChunkDef::SetNibble(): index out of range!"); return; } - if ((size_t)(a_BlockIdx / 2) >= a_Buffer.size()) + if (static_cast(a_BlockIdx / 2) >= a_Buffer.size()) { - a_Buffer.resize((size_t)((a_BlockIdx / 2) + 1)); + a_Buffer.resize(static_cast((a_BlockIdx / 2) + 1)); } - a_Buffer[(size_t)(a_BlockIdx / 2)] = PackNibble(a_Buffer, (size_t)a_BlockIdx, a_Nibble); + a_Buffer[static_cast(a_BlockIdx / 2)] = PackNibble(a_Buffer, static_cast(a_BlockIdx), a_Nibble); } @@ -292,7 +292,7 @@ public: return; } - size_t Index = (size_t)MakeIndexNoCheck(x, y, z); + size_t Index = static_cast(MakeIndexNoCheck(x, y, z)); if ((Index / 2) >= a_Buffer.size()) { a_Buffer.resize(((Index / 2) + 1)); @@ -336,7 +336,7 @@ public: /// Called for clients that are in Chunk1 and not in Chunk2, virtual void Removed(cClientHandle * a_Client) = 0; - + /// Called for clients that are in Chunk2 and not in Chunk1. virtual void Added(cClientHandle * a_Client) = 0; } ; @@ -373,9 +373,9 @@ class cChunkCoords public: int m_ChunkX; int m_ChunkZ; - + cChunkCoords(int a_ChunkX, int a_ChunkZ) : m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ) {} - + bool operator == (const cChunkCoords & a_Other) const { return ((m_ChunkX == a_Other.m_ChunkX) && (m_ChunkZ == a_Other.m_ChunkZ)); @@ -432,12 +432,12 @@ public: int y; int z; X Data; - + cCoordWithData(int a_X, int a_Y, int a_Z) : x(a_X), y(a_Y), z(a_Z), Data() { } - + cCoordWithData(int a_X, int a_Y, int a_Z, const X & a_Data) : x(a_X), y(a_Y), z(a_Z), Data(a_Data) { @@ -478,7 +478,3 @@ public: typedef cCoordWithDoubleData cCoordWithBlockAndBool; typedef std::vector cCoordWithBlockAndBoolVector; - - - - diff --git a/src/Defines.h b/src/Defines.h index 6355b75b4..f1ff911e7 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -39,7 +39,7 @@ enum eBlockFace BLOCK_FACE_YP = 1, // Interacting with the Y+ face of the block BLOCK_FACE_ZM = 2, // Interacting with the Z- face of the block BLOCK_FACE_ZP = 3, // Interacting with the Z+ face of the block - + // Synonyms using the (deprecated) world directions: BLOCK_FACE_BOTTOM = BLOCK_FACE_YM, // Interacting with the bottom face of the block BLOCK_FACE_TOP = BLOCK_FACE_YP, // Interacting with the top face of the block @@ -101,7 +101,7 @@ enum eClickAction caDblClick, // Add new actions here caUnknown = 255, - + // Keep this list in sync with ClickActionToString() function below! } ; @@ -116,14 +116,14 @@ enum eGameMode eGameMode_Creative = 1, eGameMode_Adventure = 2, eGameMode_Spectator = 3, - + // Easier-to-use synonyms: gmNotSet = eGameMode_NotSet, gmSurvival = eGameMode_Survival, gmCreative = eGameMode_Creative, gmAdventure = eGameMode_Adventure, gmSpectator = eGameMode_Spectator, - + // These two are used to check GameMode for validity when converting from integers. gmMax, // Gets automatically assigned gmMin = 0, @@ -138,7 +138,7 @@ enum eWeather eWeather_Sunny = 0, eWeather_Rain = 1, eWeather_ThunderStorm = 2, - + // Easier-to-use synonyms: wSunny = eWeather_Sunny, wRain = eWeather_Rain, @@ -218,7 +218,7 @@ inline const char * ClickActionToString(eClickAction a_ClickAction) case caLeftPaintEnd: return "caLeftPaintEnd"; case caRightPaintEnd: return "caRightPaintEnd"; case caDblClick: return "caDblClick"; - + case caUnknown: return "caUnknown"; } ASSERT(!"Unknown click action"); @@ -472,7 +472,7 @@ inline void AddFaceDirection(int & a_BlockX, unsigned char & a_BlockY, int & a_B { int Y = a_BlockY; AddFaceDirection(a_BlockX, Y, a_BlockZ, a_BlockFace, a_bInverse); - a_BlockY = Clamp((unsigned char)Y, 0, 255); + a_BlockY = Clamp(static_cast(Y), 0, 255); } @@ -556,7 +556,7 @@ enum eMessageType mtPrivateMessage, // Player to player messaging identifier mtJoin, // A player has joined the server mtLeave, // A player has left the server - + // Common aliases: mtFail = mtFailure, mtError = mtFailure, @@ -626,9 +626,9 @@ namespace ItemCategory || (a_ItemID == E_ITEM_GOLD_HOE) || (a_ItemID == E_ITEM_DIAMOND_HOE); } - - - + + + inline bool IsShovel(short a_ItemID) { return (a_ItemID == E_ITEM_WOODEN_SHOVEL) @@ -648,9 +648,9 @@ namespace ItemCategory || IsHoe ( a_ItemID) || IsShovel ( a_ItemID); } - - - + + + inline bool IsHelmet(short a_ItemType) { return ( @@ -700,9 +700,9 @@ namespace ItemCategory (a_ItemType == E_ITEM_DIAMOND_BOOTS) ); } - - - + + + inline bool IsArmor(short a_ItemType) { return ( @@ -715,7 +715,3 @@ namespace ItemCategory } // tolua_end - - - - diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index f0577aba2..858f760ce 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -84,13 +84,13 @@ public: etFloater, etItemFrame, etPainting, - + // Common variations etMob = etMonster, // DEPRECATED, use etMonster instead! } ; - + // tolua_end - + enum eEntityStatus { // TODO: Investiagate 0, 1, and 5 as Wiki.vg is not certain @@ -127,22 +127,22 @@ public: // Informs client to explode a firework based on its metadata esFireworkExploding = 17, } ; - + static const int FIRE_TICKS_PER_DAMAGE = 10; ///< Ticks to wait between damaging an entity when it stands in fire static const int FIRE_DAMAGE = 1; ///< Damage to deal when standing in fire static const int LAVA_TICKS_PER_DAMAGE = 10; ///< Ticks to wait between damaging an entity when it stands in lava static const int LAVA_DAMAGE = 5; ///< Damage to deal when standing in lava static const int BURN_TICKS_PER_DAMAGE = 20; ///< Ticks to wait between damaging an entity when it is burning static const int BURN_DAMAGE = 1; ///< Damage to deal when the entity is burning - + static const int BURN_TICKS = 200; ///< Ticks to keep an entity burning after it has stood in lava / fire - + static const int MAX_AIR_LEVEL = 300; ///< Maximum air an entity can have static const int DROWNING_TICKS = 20; ///< Number of ticks per heart of damage - + static const int VOID_BOUNDARY = -46; ///< Y position to begin applying void damage static const int FALL_DAMAGE_HEIGHT = 4; ///< Y difference after which fall damage is applied - + cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height); virtual ~cEntity(); @@ -151,9 +151,9 @@ public: virtual bool Initialize(cWorld & a_World); // tolua_begin - + eEntityType GetEntityType(void) const { return m_EntityType; } - + bool IsEnderCrystal(void) const { return (m_EntityType == etEnderCrystal); } bool IsPlayer (void) const { return (m_EntityType == etPlayer); } bool IsPickup (void) const { return (m_EntityType == etPickup); } @@ -168,16 +168,16 @@ public: bool IsFloater (void) const { return (m_EntityType == etFloater); } bool IsItemFrame (void) const { return (m_EntityType == etItemFrame); } bool IsPainting (void) const { return (m_EntityType == etPainting); } - + /// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true) virtual bool IsA(const char * a_ClassName) const; - + /// Returns the topmost class name for the object virtual const char * GetClass(void) const; - + // Returns the class name of this class static const char * GetClassStatic(void); - + /// Returns the topmost class's parent class name for the object. cEntity returns an empty string (no parent). virtual const char * GetParentClass(void) const; @@ -200,9 +200,9 @@ public: double GetSpeedY (void) const { return m_Speed.y; } double GetSpeedZ (void) const { return m_Speed.z; } double GetWidth (void) const { return m_Width; } - - int GetChunkX(void) const {return (int)floor(m_Pos.x / cChunkDef::Width); } - int GetChunkZ(void) const {return (int)floor(m_Pos.z / cChunkDef::Width); } + + int GetChunkX(void) const {return static_cast(floor(m_Pos.x / cChunkDef::Width)); } + int GetChunkZ(void) const {return static_cast(floor(m_Pos.z / cChunkDef::Width)); } void SetHeadYaw (double a_HeadYaw); void SetHeight (double a_Height); @@ -219,21 +219,21 @@ public: /** Sets the speed of the entity, measured in m / sec */ void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ); - + /** Sets the speed of the entity, measured in m / sec */ void SetSpeed(const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); } - + /** Sets the speed in the X axis, leaving the other speed components intact. Measured in m / sec. */ void SetSpeedX(double a_SpeedX); - + /** Sets the speed in the Y axis, leaving the other speed components intact. Measured in m / sec. */ void SetSpeedY(double a_SpeedY); - + /** Sets the speed in the Z axis, leaving the other speed components intact. Measured in m / sec. */ void SetSpeedZ(double a_SpeedZ); - + void SetWidth (double a_Width); - + void AddPosX (double a_AddPosX); void AddPosY (double a_AddPosY); void AddPosZ (double a_AddPosZ); @@ -244,7 +244,7 @@ public: void AddSpeedX (double a_AddSpeedX); void AddSpeedY (double a_AddSpeedY); void AddSpeedZ (double a_AddSpeedZ); - + virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways); void SteerVehicle(float a_Forward, float a_Sideways); @@ -256,56 +256,56 @@ public: /// Makes this pawn take damage from an attack by a_Attacker. Damage values are calculated automatically and DoTakeDamage() called void TakeDamage(cEntity & a_Attacker); - + /// Makes this entity take the specified damage. The final damage is calculated using current armor, then DoTakeDamage() called void TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_RawDamage, double a_KnockbackAmount); /// Makes this entity take the specified damage. The values are packed into a TDI, knockback calculated, then sent through DoTakeDamage() void TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_RawDamage, int a_FinalDamage, double a_KnockbackAmount); - + float GetGravity(void) const { return m_Gravity; } - + void SetGravity(float a_Gravity) { m_Gravity = a_Gravity; } - + /// Sets the rotation to match the speed vector (entity goes "face-forward") void SetYawFromSpeed(void); - + /// Sets the pitch to match the speed vector (entity gies "face-forward") void SetPitchFromSpeed(void); - + // tolua_end - + /** Makes this entity take damage specified in the a_TDI. The TDI is sent through plugins first, then applied. If it returns false, the entity hasn't receive any damage. */ virtual bool DoTakeDamage(TakeDamageInfo & a_TDI); - + // tolua_begin /// Returns the hitpoints that this pawn can deal to a_Receiver using its equipped items virtual int GetRawDamageAgainst(const cEntity & a_Receiver); - + /** Returns whether armor will protect against the passed damage type **/ virtual bool ArmorCoversAgainst(eDamageType a_DamageType); - + /// Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover virtual int GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_RawDamage); - + /// Returns the knockback amount that the currently equipped items would cause to a_Receiver on a hit virtual double GetKnockbackAmountAgainst(const cEntity & a_Receiver); - + /// Returns the curently equipped weapon; empty item if none virtual cItem GetEquippedWeapon(void) const { return cItem(); } - + /// Returns the currently equipped helmet; empty item if none virtual cItem GetEquippedHelmet(void) const { return cItem(); } - + /// Returns the currently equipped chestplate; empty item if none virtual cItem GetEquippedChestplate(void) const { return cItem(); } /// Returns the currently equipped leggings; empty item if none virtual cItem GetEquippedLeggings(void) const { return cItem(); } - + /// Returns the currently equipped boots; empty item if none virtual cItem GetEquippedBoots(void) const { return cItem(); } @@ -317,20 +317,20 @@ public: /// Heals the specified amount of HPs virtual void Heal(int a_HitPoints); - + /// Returns the health of this entity int GetHealth(void) const { return m_Health; } - + /// Sets the health of this entity; doesn't broadcast any hurt animation void SetHealth(int a_Health); - + // tolua_end virtual void Tick(float 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); - + /// Updates the state related to this entity being on fire virtual void TickBurning(cChunk & a_Chunk); @@ -341,34 +341,34 @@ public: Returns true if MoveToWorld() was called, false if not */ virtual bool DetectPortal(void); - + /// Handles when the entity is in the void virtual void TickInVoid(cChunk & a_Chunk); /// Called when the entity starts burning virtual void OnStartedBurning(void); - + /// Called when the entity finishes burning virtual void OnFinishedBurning(void); - + // tolua_begin - + /// Sets the maximum value for the health void SetMaxHealth(int a_MaxHealth); int GetMaxHealth(void) const { return m_MaxHealth; } - + /// Sets whether the entity is fireproof void SetIsFireproof(bool a_IsFireproof); - + bool IsFireproof(void) const { return m_IsFireproof; } - + /// Puts the entity on fire for the specified amount of ticks void StartBurning(int a_TicksLeftBurning); - + /// Stops the entity from burning, resets all burning timers void StopBurning(void); - + // tolua_end /** Descendants override this function to send a command to the specified client to spawn the entity on the client. @@ -377,10 +377,10 @@ public: virtual void SpawnOn(cClientHandle & a_Client) = 0; // tolua_begin - + /// Teleports to the entity specified virtual void TeleportToEntity(cEntity & a_Entity); - + /// Teleports to the coordinates specified virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ); @@ -389,7 +389,7 @@ public: /** Moves entity to specified world, taking a world name */ bool MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn = true); - + // tolua_end virtual bool DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn); @@ -399,16 +399,16 @@ public: /** Sets the world the entity will be leaving */ void SetWorldTravellingFrom(cWorld * a_World) { m_WorldTravellingFrom = a_World; } - + /// Updates clients of changes in the entity. virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = NULL); - + /// Attaches to the specified entity; detaches from any previous one first void AttachTo(cEntity * a_AttachTo); - + /// Detaches from the currently attached entity, if any virtual void Detach(void); - + /// Makes sure head yaw is not over the specified range. void WrapHeadYaw(); @@ -417,9 +417,9 @@ public: /// Makes speed is not over 20. Max speed is 20 blocks / second void WrapSpeed(); - + // tolua_begin - + // COMMON metadata flags; descendants may override the defaults: virtual bool IsOnFire (void) const {return (m_TicksLeftBurning > 0); } virtual bool IsCrouched (void) const {return false; } @@ -437,15 +437,15 @@ public: /** Gets number of ticks this entity has existed for */ long int GetTicksAlive(void) const { return m_TicksAlive; } - + /** Gets the invulnerable ticks from the entity */ int GetInvulnerableTicks(void) const { return m_InvulnerableTicks; } /** Set the invulnerable ticks from the entity */ void SetInvulnerableTicks(int a_InvulnerableTicks) { m_InvulnerableTicks = a_InvulnerableTicks; } - + // tolua_end - + /// Called when the specified player right-clicks this entity virtual void OnRightClicked(cPlayer & a_Player) {} @@ -462,38 +462,38 @@ public: protected: static cCriticalSection m_CSCount; static int m_EntityCount; - + /** Measured in meter/second (m/s) */ Vector3d m_Speed; int m_UniqueID; - + int m_Health; int m_MaxHealth; - + /// The entity to which this entity is attached (vehicle), NULL if none cEntity * m_AttachedTo; - + /// The entity which is attached to this entity (rider), NULL if none cEntity * m_Attachee; /** Stores whether head yaw has been set manually */ bool m_bDirtyHead; - + /** Stores whether our yaw/pitch/roll (body orientation) has been set manually */ bool m_bDirtyOrientation; - + /** Stores whether we have sent a Velocity packet with a speed of zero (no speed) to the client Ensures that said packet is sent only once */ bool m_bHasSentNoSpeed; /** Stores if the entity is on the ground */ bool m_bOnGround; - + /** Stores gravity that is applied to an entity every tick For realistic effects, this should be negative. For spaaaaaaace, this can be zero or even positive */ float m_Gravity; - + /** Last position sent to client via the Relative Move or Teleport packets (not Velocity) Only updated if cEntity::BroadcastMovementUpdate() is called! */ Vector3d m_LastPos; @@ -508,31 +508,31 @@ protected: cWorld * m_WorldTravellingFrom; eEntityType m_EntityType; - + cWorld * m_World; - + /// Whether the entity is capable of taking fire or lava damage. bool m_IsFireproof; /// Time, in ticks, since the last damage dealt by being on fire. Valid only if on fire (IsOnFire()) int m_TicksSinceLastBurnDamage; - + /// Time, in ticks, since the last damage dealt by standing in lava. Reset to zero when moving out of lava. int m_TicksSinceLastLavaDamage; - + /// Time, in ticks, since the last damage dealt by standing in fire. Reset to zero when moving out of fire. int m_TicksSinceLastFireDamage; - + /// Time, in ticks, until the entity extinguishes its fire int m_TicksLeftBurning; - + /// Time, in ticks, since the last damage dealt by the void. Reset to zero when moving out of the void. int m_TicksSinceLastVoidDamage; - + /** Does the actual speed-setting. The default implementation just sets the member variable value; overrides can provide further processing, such as forcing players to move at the given speed. */ virtual void DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ); - + virtual void Destroyed(void) {} // Called after the entity has been destroyed /** Applies friction to an entity @@ -543,7 +543,7 @@ protected: /** Called in each tick to handle air-related processing i.e. drowning */ virtual void HandleAir(void); - + /** Called once per tick to set IsSwimming and IsSubmerged */ virtual void SetSwimState(cChunk & a_Chunk); @@ -568,29 +568,29 @@ protected: /** Portal delay timer and cooldown boolean data */ sPortalCooldownData m_PortalCooldownData; - + /** The number of ticks this entity has been alive for */ long int m_TicksAlive; - + private: /** Measured in degrees, [-180, +180) */ double m_HeadYaw; - + /** Measured in degrees, [-180, +180) */ Vector3d m_Rot; - + /** Position of the entity's XZ center and Y bottom */ Vector3d m_Pos; - + /** Measured in meter / second */ Vector3d m_WaterSpeed; - + /** Measured in Kilograms (Kg) */ double m_Mass; - + /** Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. */ double m_Width; - + /** Height of the entity (Y axis) */ double m_Height; @@ -600,7 +600,3 @@ private: } ; // tolua_export typedef std::list cEntityList; - - - - diff --git a/src/Entities/Pickup.h b/src/Entities/Pickup.h index 4d5250819..e3e0f61c7 100644 --- a/src/Entities/Pickup.h +++ b/src/Entities/Pickup.h @@ -19,7 +19,7 @@ class cPickup : public cEntity { typedef cEntity super; - + public: // tolua_end @@ -37,10 +37,10 @@ public: virtual void Tick(float a_Dt, cChunk & a_Chunk) 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 static_cast(m_Timer / 50); } // 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 = static_cast(a_Age * 50); } // tolua_export /** Returns true if the pickup has already been collected */ bool IsCollected(void) const { return m_bCollected; } // tolua_export @@ -59,7 +59,3 @@ private: bool m_bIsPlayerCreated; }; // tolua_export - - - - diff --git a/src/MersenneTwister.h b/src/MersenneTwister.h index 759b8a1ae..e83a470e2 100644 --- a/src/MersenneTwister.h +++ b/src/MersenneTwister.h @@ -19,11 +19,11 @@ // Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, // Copyright (C) 2000 - 2009, Richard J. Wagner // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: -// +// // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // @@ -31,10 +31,10 @@ // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // -// 3. The names of its contributors may not be used to endorse or promote -// products derived from this software without specific prior written +// 3. The names of its contributors may not be used to endorse or promote +// products derived from this software without specific prior written // permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -63,13 +63,13 @@ class MTRand { // Data public: typedef UInt32 uint32; // unsigned integer type, at least 32 bits - + enum { N = 624 }; // length of state vector enum { SAVE = N + 1 }; // length of array for save() protected: enum { M = 397 }; // period parameter - + uint32 state[N]; // internal state uint32 *pNext; // next value to get from state uint32 left; // number of values left before reload needed @@ -80,11 +80,11 @@ public: MTRand( uint32 *const bigSeed, uint32 const seedLength = N ); // or array MTRand(); // auto-initialize with /dev/urandom or time() and clock() MTRand( const MTRand& o ); // copy - + // Do NOT use for CRYPTOGRAPHY without securely hashing several returned // values together, otherwise the generator state can be learned after // reading 624 consecutive values. - + // Access to 32-bit random numbers uint32 randInt(); // integer in [0,2^32-1] uint32 randInt( const uint32 n ); // integer in [0,n] for n < 2^32 @@ -95,18 +95,18 @@ public: double randDblExc(); // real number in (0,1) double randDblExc( const double n ); // real number in (0,n) double operator()(); // same as rand() - + // Access to 53-bit random numbers (capacity of IEEE double precision) double rand53(); // real number in [0,1) - + // Access to nonuniform random number distributions double randNorm( const double mean = 0.0, const double stddev = 1.0 ); - + // Re-seeding functions with same behavior as initializers void seed( const uint32 oneSeed ); void seed( uint32 *const bigSeed, const uint32 seedLength = N ); void seed(); - + // Saving and loading generator state void save( uint32* saveArray ) const; // to array of size SAVE void load( uint32 *const loadArray ); // from such array @@ -136,9 +136,9 @@ inline MTRand::uint32 MTRand::hash( time_t t, clock_t c ) // Get a uint32 from t and c // Better than uint32(x) in case x is floating point in [0,1] // Based on code by Lawrence Kirby (fred@genesis.demon.co.uk) - + static uint32 differ = 0; // guarantee time-based seeds will change - + uint32 h1 = 0; unsigned char *p = (unsigned char *) &t; for( size_t i = 0; i < sizeof(t); ++i ) @@ -185,7 +185,7 @@ inline void MTRand::reload() for( i = M; --i; ++p ) *p = twist( p[MmN], p[0], p[1] ); *p = twist( p[MmN], p[0], state[0] ); - + left = N, pNext = state; } @@ -207,7 +207,7 @@ inline void MTRand::seed( uint32 *const bigSeed, const uint32 seedLength ) initialize(19650218UL); uint32 i = 1; uint32 j = 0; - uint32 k = ( (uint32)N > seedLength ? (uint32)N : seedLength ); + uint32 k = ( static_cast(N) > seedLength ? static_cast(N) : seedLength ); for( ; k; --k ) { state[i] = @@ -235,7 +235,7 @@ inline void MTRand::seed() { // Seed the generator with an array from /dev/urandom if available // Otherwise use a hash of time() and clock() values - + // First try getting an array from /dev/urandom /* // Commented out by FakeTruth because doing this 200 times a tick is SUUUUPEERRR SLOW!!~~!\D5Ne @@ -252,7 +252,7 @@ inline void MTRand::seed() if( success ) { seed( bigSeed, N ); return; } } */ - + // Was not successful, so use time() and clock() instead seed( hash( time(NULL), clock() ) ); } @@ -280,10 +280,10 @@ inline MTRand::uint32 MTRand::randInt() { // Pull a 32-bit integer from the generator state // Every other access function simply transforms the numbers extracted here - + if( left == 0 ) reload(); --left; - + uint32 s1; s1 = *pNext++; s1 ^= (s1 >> 11); @@ -302,7 +302,7 @@ inline MTRand::uint32 MTRand::randInt( const uint32 n ) used |= used >> 4; used |= used >> 8; used |= used >> 16; - + // Draw numbers until one is found in [0,n] uint32 i; do diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 9fd67d67c..f5ae2cb4d 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -35,12 +35,12 @@ public: mfNoSpawn, mfUnhandled, // Nothing. Be sure this is the last and the others are in order } ; - + // tolua_end - + enum MState{ATTACKING, IDLE, CHASING, ESCAPING} m_EMState; enum MPersonality{PASSIVE, AGGRESSIVE, COWARDLY} m_EMPersonality; - + /** Creates the mob object. If a_ConfigName is not empty, the configuration is loaded using GetMonsterConfig() a_MobType is the type of the mob (also used in the protocol ( http://wiki.vg/Entities#Mobs 2012_12_22)) @@ -49,47 +49,47 @@ public: cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height); CLASS_PROTODEF(cMonster) - + virtual void SpawnOn(cClientHandle & a_ClientHandle) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; - + virtual void KilledBy(TakeDamageInfo & a_TDI) override; virtual void OnRightClicked(cPlayer & a_Player) override; virtual void MoveToPosition(const Vector3d & a_Position); // tolua_export virtual bool ReachedDestination(void); - + // tolua_begin eMonsterType GetMobType(void) const {return m_MobType; } eFamily GetMobFamily(void) const; // tolua_end - + virtual void CheckEventSeePlayer(void); virtual void EventSeePlayer(cEntity * a_Player); - + /// Reads the monster configuration for the specified monster name and assigns it to this object. void GetMonsterConfig(const AString & a_Name); - + /** Returns whether this mob is undead (skeleton, zombie, etc.) */ virtual bool IsUndead(void); - + virtual void EventLosePlayer(void); virtual void CheckEventLostPlayer(void); - + virtual void InStateIdle (float a_Dt); virtual void InStateChasing (float a_Dt); virtual void InStateEscaping(float a_Dt); - - int GetAttackRate() { return (int)m_AttackRate; } + + int GetAttackRate() { return static_cast(m_AttackRate); } void SetAttackRate(float a_AttackRate) { m_AttackRate = a_AttackRate; } void SetAttackRange(int a_AttackRange) { m_AttackRange = a_AttackRange; } void SetAttackDamage(int a_AttackDamage) { m_AttackDamage = a_AttackDamage; } void SetSightDistance(int a_SightDistance) { m_SightDistance = a_SightDistance; } - + float GetDropChanceWeapon() { return m_DropChanceWeapon; } float GetDropChanceHelmet() { return m_DropChanceHelmet; } float GetDropChanceChestplate() { return m_DropChanceChestplate; } @@ -102,7 +102,7 @@ public: void SetDropChanceLeggings(float a_DropChanceLeggings) { m_DropChanceLeggings = a_DropChanceLeggings; } void SetDropChanceBoots(float a_DropChanceBoots) { m_DropChanceBoots = a_DropChanceBoots; } void SetCanPickUpLoot(bool a_CanPickUpLoot) { m_CanPickUpLoot = a_CanPickUpLoot; } - + /// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; } @@ -113,7 +113,7 @@ public: virtual bool IsBaby (void) const { return false; } virtual bool IsTame (void) const { return false; } virtual bool IsSitting (void) const { return false; } - + // tolua_begin /** Returns true if the monster has a custom name. */ @@ -135,10 +135,10 @@ public: /// Translates MobType enum to a string, empty string if unknown static AString MobTypeToString(eMonsterType a_MobType); - + /// Translates MobType string to the enum, mtInvalidType if not recognized static eMonsterType StringToMobType(const AString & a_MobTypeName); - + /// Returns the mob family based on the type static eFamily FamilyFromType(eMonsterType a_MobType); @@ -146,7 +146,7 @@ public: static int GetSpawnDelay(cMonster::eFamily a_MobFamily); // tolua_end - + /** Creates a new object of the specified mob. a_MobType is the type of the mob to be created Asserts and returns null if mob type is not specified @@ -154,7 +154,7 @@ public: static cMonster * NewMonsterFromType(eMonsterType a_MobType); protected: - + /* ======= PATHFINDING ======= */ /** A pointer to the entity this mobile is aiming to reach */ @@ -168,7 +168,7 @@ protected: /** Stores if mobile is currently moving towards the ultimate, final destination */ bool m_bMovingToDestination; - + /** Finds the first non-air block position (not the highest, as cWorld::GetHeight does) If current Y is nonsolid, goes down to try to find a solid block, then returns that + 1 If current Y is solid, goes up to find first nonsolid block, and returns that */ @@ -227,14 +227,14 @@ protected: int m_AttackRange; float m_AttackInterval; int m_SightDistance; - + float m_DropChanceWeapon; float m_DropChanceHelmet; float m_DropChanceChestplate; float m_DropChanceLeggings; float m_DropChanceBoots; bool m_CanPickUpLoot; - + void HandleDaylightBurning(cChunk & a_Chunk); bool m_BurnsInDaylight; @@ -242,22 +242,18 @@ protected: /** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops*/ void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); - + /** Adds a item a_Item with the chance of a_Chance (in percent) to itemdrops a_Drops*/ void AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth = 0); - + /** Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel(I-III or custom) to the itemdrop a_Drops*/ void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel); - + /** Adds armor that is equipped with the chance saved in m_DropChance[...] (this will be greter than 1 if piccked up or 0.085 + (0.01 per LootingLevel) if born with) to the drop*/ void AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel); - + /** Adds weapon that is equipped with the chance saved in m_DropChance[...] (this will be greter than 1 if piccked up or 0.085 + (0.01 per LootingLevel) if born with) to the drop*/ void AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel); - - -} ; // tolua_export - - +} ; // tolua_export diff --git a/src/OSSupport/IsThread.h b/src/OSSupport/IsThread.h index 5de5f31c4..5c8d28d2d 100644 --- a/src/OSSupport/IsThread.h +++ b/src/OSSupport/IsThread.h @@ -31,20 +31,20 @@ protected: /// The overriden Execute() method should check this value periodically and terminate if this is true volatile bool m_ShouldTerminate; - + public: cIsThread(const AString & iThreadName); virtual ~cIsThread(); - + /// Starts the thread; returns without waiting for the actual start bool Start(void); - + /// Signals the thread to terminate and waits until it's finished void Stop(void); - + /// Waits for the thread to finish. Doesn't signalize the ShouldTerminate flag bool Wait(void); - + /// Returns the OS-dependent thread ID for the caller's thread static unsigned long GetCurrentID(void); @@ -53,7 +53,7 @@ public: protected: AString m_ThreadName; - + // Value used for "no handle": #ifdef _WIN32 #define NULL_HANDLE NULL @@ -62,34 +62,34 @@ protected: #endif #ifdef _WIN32 - + DWORD m_ThreadID; HANDLE m_Handle; - + static DWORD __stdcall thrExecute(LPVOID a_Param) { // Create a window so that the thread can be identified by 3rd party tools: HWND IdentificationWnd = CreateWindowA("STATIC", ((cIsThread *)a_Param)->m_ThreadName.c_str(), 0, 0, 0, 0, WS_OVERLAPPED, NULL, NULL, NULL, NULL); - + // Run the thread: ((cIsThread *)a_Param)->Execute(); - + // Destroy the identification window: DestroyWindow(IdentificationWnd); - + return 0; } - + #else // _WIN32 - + pthread_t m_Handle; - + static void * thrExecute(void * a_Param) { - ((cIsThread *)a_Param)->Execute(); + (static_cast(a_Param))->Execute(); return NULL; } - + #endif // else _WIN32 } ; @@ -98,7 +98,3 @@ protected: #endif // CISTHREAD_H_INCLUDED - - - - diff --git a/src/World.h b/src/World.h index 90dada259..02d0a92b8 100644 --- a/src/World.h +++ b/src/World.h @@ -84,7 +84,7 @@ class cWorld : public: // tolua_end - + /** A simple RAII locker for the chunkmap - locks the chunkmap in its constructor, unlocks it in the destructor */ class cLock : public cCSLock @@ -94,7 +94,7 @@ public: cLock(cWorld & a_World); } ; - + /** A common ancestor for all tasks queued onto the tick thread */ class cTask { @@ -102,10 +102,10 @@ public: virtual ~cTask() {} virtual void Run(cWorld & a_World) = 0; } ; - + typedef std::vector cTasks; - + class cTaskSaveAllChunks : public cTask { @@ -113,7 +113,7 @@ public: // cTask overrides: virtual void Run(cWorld & a_World) override; } ; - + class cTaskUnloadUnusedChunks : public cTask @@ -142,7 +142,7 @@ public: { return "cWorld"; } - + // tolua_begin int GetTicksUntilWeatherChange(void) const { return m_WeatherInterval; } @@ -159,7 +159,7 @@ public: virtual Int64 GetWorldAge (void) const override { return m_WorldAge; } virtual int GetTimeOfDay(void) const override { return m_TimeOfDay; } - + void SetTicksUntilWeatherChange(int a_WeatherInterval) { m_WeatherInterval = a_WeatherInterval; @@ -168,42 +168,42 @@ public: virtual void SetTimeOfDay(int a_TimeOfDay) override { m_TimeOfDay = a_TimeOfDay; - m_TimeOfDaySecs = (double)a_TimeOfDay / 20.0; + m_TimeOfDaySecs = static_cast(a_TimeOfDay) / 20.0; UpdateSkyDarkness(); BroadcastTimeUpdate(); } - + /** Returns the default weather interval for the specific weather type. Returns -1 for any unknown weather. */ int GetDefaultWeatherInterval(eWeather a_Weather); - + /** Returns the current game mode. Partly OBSOLETE, you should use IsGameModeXXX() functions wherever applicable */ eGameMode GetGameMode(void) const { return m_GameMode; } /** Returns true if the world is in Creative mode */ bool IsGameModeCreative(void) const { return (m_GameMode == gmCreative); } - + /** Returns true if the world is in Survival mode */ bool IsGameModeSurvival(void) const { return (m_GameMode == gmSurvival); } - + /** Returns true if the world is in Adventure mode */ bool IsGameModeAdventure(void) const { return (m_GameMode == gmAdventure); } - + /** Returns true if the world is in Spectator mode */ bool IsGameModeSpectator(void) const { return (m_GameMode == gmSpectator); } - + bool IsPVPEnabled(void) const { return m_bEnabledPVP; } bool IsDeepSnowEnabled(void) const { return m_IsDeepSnowEnabled; } - + bool ShouldLavaSpawnFire(void) const { return m_ShouldLavaSpawnFire; } - + bool VillagersShouldHarvestCrops(void) const { return m_VillagersShouldHarvestCrops; } virtual eDimension GetDimension(void) const { return m_Dimension; } /** Returns the world height at the specified coords; waits for the chunk to get loaded / generated */ virtual int GetHeight(int a_BlockX, int a_BlockZ); - + // tolua_end /** Retrieves the world height at the specified coords; returns false if chunk not loaded / generated */ @@ -258,35 +258,35 @@ public: void BroadcastTimeUpdate (const cClientHandle * a_Exclude = NULL); virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override; void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = NULL); - + virtual cBroadcastInterface & GetBroadcastManager(void) override { return *this; } - + /** If there is a block entity at the specified coords, sends it to the client specified */ void SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle & a_Client); - + void MarkRedstoneDirty(int a_ChunkX, int a_ChunkZ); void MarkChunkDirty (int a_ChunkX, int a_ChunkZ, bool a_MarkRedstoneDirty = false); void MarkChunkSaving(int a_ChunkX, int a_ChunkZ); void MarkChunkSaved (int a_ChunkX, int a_ChunkZ); - + /** Puts the chunk data into a queue to be set into the chunkmap in the tick thread. If the chunk data doesn't contain valid biomes, the biomes are calculated before adding the data into the queue. */ void QueueSetChunkData(const cSetChunkDataPtr & a_SetChunkData); - + void ChunkLighted( int a_ChunkX, int a_ChunkZ, const cChunkDef::BlockNibbles & a_BlockLight, const cChunkDef::BlockNibbles & a_SkyLight ); - + bool GetChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataCallback & a_Callback); - + /** Gets the chunk's blocks, only the block types */ bool GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_BlockTypes); - + /** Returns true iff the chunk is in the loader / generator queue. */ bool IsChunkQueued(int a_ChunkX, int a_ChunkZ) const; @@ -294,10 +294,10 @@ public: bool IsChunkValid(int a_ChunkX, int a_ChunkZ) const; bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const; - + /** Queues a task to unload unused chunks onto the tick thread. The prefferred way of unloading*/ void QueueUnloadUnusedChunks(void); // tolua_export - + void CollectPickupsByPlayer(cPlayer * a_Player); /** Adds the player to the world. @@ -319,21 +319,21 @@ public: /** Finds a player from a partial or complete player name and calls the callback - case-insensitive */ bool FindAndDoWithPlayer(const AString & a_PlayerNameHint, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << - + // TODO: This interface is dangerous - rewrite to DoWithClosestPlayer(pos, sight, action) cPlayer * FindClosestPlayer(const Vector3d & a_Pos, float a_SightLimit, bool a_CheckLineOfSight = true); - + void SendPlayerList(cPlayer * a_DestPlayer); // Sends playerlist to the player /** Adds the entity into its appropriate chunk; takes ownership of the entity ptr. The entity is added lazily - this function only puts it in a queue that is then processed by the Tick thread. */ void AddEntity(cEntity * a_Entity); - + bool HasEntity(int a_UniqueID); - + /** Calls the callback for each entity in the entire world; returns true if all entities processed, false if the callback aborted by returning true */ bool ForEachEntity(cEntityCallback & a_Callback); // Exported in ManualBindings.cpp - + /** Calls the callback for each entity in the specified chunk; returns true if all entities processed, false if the callback aborted by returning true */ bool ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback & a_Callback); // Exported in ManualBindings.cpp @@ -347,36 +347,36 @@ public: /** Compares clients of two chunks, calls the callback accordingly */ void CompareChunkClients(int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, int a_ChunkZ2, cClientDiffCallback & a_Callback); - + /** Adds client to a chunk, if not already present; returns true if added, false if present */ bool AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client); - + /** Removes client from the chunk specified */ void RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client); - + /** Removes the client from all chunks it is present in */ void RemoveClientFromChunks(cClientHandle * a_Client); - + /** Sends the chunk to the client specified, if the client doesn't have the chunk yet. If chunk not valid, the request is postponed (ChunkSender will send that chunk when it becomes valid + lighted). */ void SendChunkTo(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client); - + /** Sends the chunk to the client specified, even if the client already has the chunk. If the chunk's not valid, the request is postponed (ChunkSender will send that chunk when it becomes valid + lighted). */ void ForceSendChunkTo(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client); - + /** Removes client from ChunkSender's queue of chunks to be sent */ void RemoveClientFromChunkSender(cClientHandle * a_Client); - + /** Touches the chunk, causing it to be loaded or generated */ void TouchChunk(int a_ChunkX, int a_ChunkZ); - + /** Marks the chunk as failed-to-load: */ void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ); - + /** Sets the sign text, asking plugins for permission first. a_Player is the player who this change belongs to, may be NULL. Returns true if sign text changed. Same as UpdateSign() */ bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player = NULL); // Exported in ManualBindings.cpp - + /** Sets the sign text, asking plugins for permission first. a_Player is the player who this change belongs to, may be NULL. Returns true if sign text changed. Same as SetSignLines() */ bool UpdateSign(int a_X, int a_Y, int a_Z, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player = NULL); // Exported in ManualBindings.cpp @@ -391,25 +391,25 @@ public: /** Regenerate the given chunk: */ void RegenerateChunk(int a_ChunkX, int a_ChunkZ); // tolua_export - + /** Generates the given chunk */ void GenerateChunk(int a_ChunkX, int a_ChunkZ); // tolua_export - + /** Queues a chunk for lighting; a_Callback is called after the chunk is lighted */ void QueueLightChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback = NULL); - + bool IsChunkLighted(int a_ChunkX, int a_ChunkZ); - + /** Calls the callback for each chunk in the coords specified (all cords are inclusive). Returns true if all chunks have been processed successfully */ virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback) override; // tolua_begin - + /** Sets the block at the specified coords to the specified value. Full processing, incl. updating neighbors, is performed. */ void SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, bool a_SendToClients = true); - + /** Sets the block at the specified coords to the specified value. The replacement doesn't trigger block updates. The replaced blocks aren't checked for block entities (block entity is leaked if it exists at this block) @@ -418,7 +418,7 @@ public: { m_ChunkMap->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); } - + /** Queues a SetBlock() with the specified parameters after the specified number of ticks. Calls SetBlock(), so performs full processing of the replaced block. */ @@ -426,12 +426,12 @@ public: { m_ChunkMap->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, GetWorldAge() + a_TickDelay, a_PreviousBlockType); } - + BLOCKTYPE GetBlock (int a_BlockX, int a_BlockY, int a_BlockZ) { return m_ChunkMap->GetBlock(a_BlockX, a_BlockY, a_BlockZ); } - + NIBBLETYPE GetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ) { return m_ChunkMap->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); @@ -439,37 +439,37 @@ public: void SetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_MetaData); NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ); NIBBLETYPE GetBlockBlockLight(int a_BlockX, int a_BlockY, int a_BlockZ); - + // tolua_end - + bool GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta); // TODO: Exported in ManualBindings.cpp bool GetBlockInfo (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight); // TODO: Exported in ManualBindings.cpp // TODO: NIBBLETYPE GetBlockActualLight(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_begin - + // Vector3i variants: void FastSetBlock(const Vector3i & a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { FastSetBlock( a_Pos.x, a_Pos.y, a_Pos.z, a_BlockType, a_BlockMeta); } BLOCKTYPE GetBlock (const Vector3i & a_Pos) { return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z); } NIBBLETYPE GetBlockMeta(const Vector3i & a_Pos) { return GetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z); } void SetBlockMeta(const Vector3i & a_Pos, NIBBLETYPE a_MetaData) { SetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z, a_MetaData); } // tolua_end - + /** Writes the block area into the specified coords. Returns true if all chunks have been processed. Prefer cBlockArea::Write() instead, this is the internal implementation; cBlockArea does error checking, too. a_DataTypes is a bitmask of cBlockArea::baXXX constants ORed together. */ virtual bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) override; - + // tolua_begin /** Spawns item pickups for each item in the list. May compress pickups if too many entities: */ virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool IsPlayerCreated = false) override; - + /** Spawns item pickups for each item in the list. May compress pickups if too many entities. All pickups get the speed specified: */ virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false) override; - + /** Spawns an falling block entity at the given position. It returns the UniqueID of the spawned falling block. */ int SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NIBBLETYPE BlockMeta); @@ -486,10 +486,10 @@ public: /** Replaces world blocks with a_Blocks, if they are of type a_FilterBlockType */ void ReplaceBlocks(const sSetBlockVector & a_Blocks, BLOCKTYPE a_FilterBlockType); - + /** Retrieves block types of the specified blocks. If a chunk is not loaded, doesn't modify the block. Returns true if all blocks were read. */ bool GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure); - + // tolua_begin bool DigBlock (int a_X, int a_Y, int a_Z); virtual void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player) override; @@ -500,21 +500,21 @@ public: /** Wakes up the simulators for the specified block */ virtual void WakeUpSimulators(int a_BlockX, int a_BlockY, int a_BlockZ) override; - + /** Wakes up the simulators for the specified area of blocks */ void WakeUpSimulatorsInArea(int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ); // tolua_end inline cSimulatorManager * GetSimulatorManager(void) { return m_SimulatorManager; } - + inline cFluidSimulator * GetWaterSimulator(void) { return m_WaterSimulator; } inline cFluidSimulator * GetLavaSimulator (void) { return m_LavaSimulator; } inline cRedstoneSimulator * GetRedstoneSimulator(void) { return m_RedstoneSimulator; } - + /** Calls the callback for each block entity in the specified chunk; returns true if all block entities processed, false if the callback aborted by returning true */ bool ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback & a_Callback); // Exported in ManualBindings.cpp - + /** Calls the callback for each chest in the specified chunk; returns true if all chests processed, false if the callback aborted by returning true */ bool ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback & a_Callback); // Exported in ManualBindings.cpp @@ -529,7 +529,7 @@ public: /** Calls the callback for each furnace in the specified chunk; returns true if all furnaces processed, false if the callback aborted by returning true */ bool ForEachFurnaceInChunk(int a_ChunkX, int a_ChunkZ, cFurnaceCallback & a_Callback); // Exported in ManualBindings.cpp - + /** Does an explosion with the specified strength at the specified coordinate a_SourceData exact type depends on the a_Source: | esOther | void * | @@ -580,29 +580,29 @@ public: /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Exported in ManualBindings.cpp - + /** a_Player is using block entity at [x, y, z], handle that: */ void UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) {m_ChunkMap->UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ); } // tolua_export - + /** Calls the callback for the chunk specified, with ChunkMapCS locked; returns false if the chunk doesn't exist, otherwise returns the same value as the callback */ bool DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback & a_Callback); void GrowTreeImage(const sSetBlockVector & a_Blocks); - + // tolua_begin /** Grows a tree at the specified coords, either from a sapling there, or based on the biome */ void GrowTree (int a_BlockX, int a_BlockY, int a_BlockZ); - + /** Grows a tree at the specified coords, based on the sapling meta provided */ void GrowTreeFromSapling(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_SaplingMeta); - + /** Grows a tree at the specified coords, based on the biome in the place */ void GrowTreeByBiome (int a_BlockX, int a_BlockY, int a_BlockZ); - + /** Grows the plant at the specified block to its ripe stage (bonemeal used); returns false if the block is not growable. If a_IsBonemeal is true, block is not grown if not allowed in world.ini */ bool GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsByBonemeal = false); - + /** Grows a cactus present at the block specified by the amount of blocks specified, up to the max height specified in the config */ void GrowCactus(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow); @@ -611,18 +611,18 @@ public: /** Grows a sugarcane present at the block specified by the amount of blocks specified, up to the max height specified in the config */ void GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow); - + /** Returns the biome at the specified coords. Reads the biome from the chunk, if loaded, otherwise uses the world generator to provide the biome value */ EMCSBiome GetBiomeAt(int a_BlockX, int a_BlockZ); - + /** Sets the biome at the specified coords. Returns true if successful, false if not (chunk not loaded). Doesn't resend the chunk to clients, use ForceSendChunkTo() for that. */ bool SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome); - + /** Sets the biome at the area. Returns true if successful, false if any subarea failed (chunk not loaded). (Re)sends the chunks to their relevant clients if successful. */ bool SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMCSBiome a_Biome); - + /** Sets the biome at the area. Returns true if successful, false if any subarea failed (chunk not loaded). (Re)sends the chunks to their relevant clients if successful. The cuboid needn't be sorted. */ @@ -630,7 +630,7 @@ public: /** Returns the name of the world */ const AString & GetName(void) const { return m_WorldName; } - + /** Returns the name of the world.ini file used by this world */ const AString & GetIniFileName(void) const {return m_IniFileName; } @@ -661,18 +661,18 @@ public: AString GetLinkedOverworldName(void) const { return m_OverworldName; } void SetLinkedOverworldName(const AString & a_Name) { m_OverworldName = a_Name; } - + // tolua_end - + /** Saves all chunks immediately. Dangerous interface, may deadlock, use QueueSaveAllChunks() instead */ void SaveAllChunks(void); - + /** Queues a task to save all chunks onto the tick thread. The prefferred way of saving chunks from external sources */ void QueueSaveAllChunks(void); // tolua_export - + /** Queues a task onto the tick thread. The task object will be deleted once the task is finished */ void QueueTask(cTask * a_Task); // Exported in ManualBindings.cpp - + /** Queues a task onto the tick thread, with the specified delay. The task object will be deleted once the task is finished */ void ScheduleTask(int a_DelayTicks, cTask * a_Task); @@ -690,13 +690,13 @@ public: inline size_t GetStorageSaveQueueLength(void) { return m_Storage.GetSaveQueueLength(); } // tolua_export void InitializeSpawn(void); - + /** Starts threads that belong to this world */ void Start(void); - + /** Stops threads that belong to this world (part of deinit) */ void Stop(void); - + /** Processes the blocks queued for ticking with a delay (m_BlockTickQueue[]) */ void TickQueuedBlocks(void); @@ -714,34 +714,34 @@ public: // tolua_begin /** Casts a thunderbolt at the specified coords */ void CastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ); - + /** Sets the specified weather; resets weather interval; asks and notifies plugins of the change */ void SetWeather(eWeather a_NewWeather); - + /** Forces a weather change in the next game tick */ void ChangeWeather(void); - + /** Returns the current weather. Instead of comparing values directly to the weather constants, use IsWeatherXXX() functions, if possible */ eWeather GetWeather(void) const { return m_Weather; } - + /** Returns true if the current weather is sun */ bool IsWeatherSunny(void) const { return (m_Weather == wSunny); } - + /** Returns true if it is sunny at the specified location. This takes into account biomes. */ bool IsWeatherSunnyAt(int a_BlockX, int a_BlockZ) { return (IsWeatherSunny() || IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); } - + /** Returns true if the current weather is rain */ bool IsWeatherRain(void) const { return (m_Weather == wRain); } - + /** Returns true if it is raining at the specified location. This takes into account biomes. */ bool IsWeatherRainAt(int a_BlockX, int a_BlockZ) { return (IsWeatherRain() && !IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); } - + /** Returns true if the current weather is stormy */ bool IsWeatherStorm(void) const { return (m_Weather == wStorm); } @@ -750,10 +750,10 @@ public: { return (IsWeatherStorm() && !IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); } - + /** Returns true if the current weather has any precipitation - rain, storm or snow */ bool IsWeatherWet(void) const { return !IsWeatherSunny(); } - + /** Returns true if it is raining, stormy or snowing at the specified location. This takes into account biomes. */ virtual bool IsWeatherWetAt(int a_BlockX, int a_BlockZ) { @@ -765,33 +765,33 @@ public: cChunkGenerator & GetGenerator(void) { return m_Generator; } cWorldStorage & GetStorage (void) { return m_Storage; } cChunkMap * GetChunkMap (void) { return m_ChunkMap; } - + /** Sets the blockticking to start at the specified block. Only one blocktick per chunk may be set, second call overwrites the first call */ void SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export - + int GetMaxSugarcaneHeight(void) const { return m_MaxSugarcaneHeight; } // tolua_export int GetMaxCactusHeight (void) const { return m_MaxCactusHeight; } // tolua_export bool IsBlockDirectlyWatered(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export - + /** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */ virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType) override; // tolua_export int SpawnMobFinalize(cMonster* a_Monster); - + /** Creates a projectile of the specified type. Returns the projectile's EntityID if successful, <0 otherwise Item parameter used currently for Fireworks to correctly set entity metadata based on item metadata */ int CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem * a_Item, const Vector3d * a_Speed = NULL); // tolua_export - + /** Returns a random number from the m_TickRand in range [0 .. a_Range]. To be used only in the tick thread! */ - int GetTickRandomNumber(unsigned a_Range) { return (int)(m_TickRand.randInt(a_Range)); } - + int GetTickRandomNumber(unsigned a_Range) { return static_cast(m_TickRand.randInt(a_Range)); } + /** Appends all usernames starting with a_Text (case-insensitive) into Results */ void TabCompleteUserName(const AString & a_Text, AStringVector & a_Results); /** Get the current darkness level based on the time */ NIBBLETYPE GetSkyDarkness() { return m_SkyDarkness; } - + /** Increments (a_AlwaysTicked == true) or decrements (false) the m_AlwaysTicked counter for the specified chunk. If the m_AlwaysTicked counter is greater than zero, the chunk is ticked in the tick-thread regardless of whether it has any clients or not. @@ -802,43 +802,43 @@ public: private: friend class cRoot; - + class cTickThread : public cIsThread { typedef cIsThread super; public: cTickThread(cWorld & a_World); - + protected: cWorld & m_World; - + // cIsThread overrides: virtual void Execute(void) override; } ; - - + + /** Implementation of the callbacks that the ChunkGenerator uses to store new chunks and interface to plugins */ class cChunkGeneratorCallbacks : public cChunkGenerator::cChunkSink, public cChunkGenerator::cPluginInterface { cWorld * m_World; - + // cChunkSink overrides: virtual void OnChunkGenerated (cChunkDesc & a_ChunkDesc) override; virtual bool IsChunkValid (int a_ChunkX, int a_ChunkZ) override; virtual bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) override; virtual bool IsChunkQueued (int a_ChunkX, int a_ChunkZ) override; - + // cPluginInterface overrides: virtual void CallHookChunkGenerating(cChunkDesc & a_ChunkDesc) override; virtual void CallHookChunkGenerated (cChunkDesc & a_ChunkDesc) override; - + public: cChunkGeneratorCallbacks(cWorld & a_World); } ; - + /** A container for tasks that have been scheduled for a specific game tick */ class cScheduledTask @@ -846,14 +846,14 @@ private: public: Int64 m_TargetTick; cTask * m_Task; - + /** Creates a new scheduled task; takes ownership of the task object passed to it. */ cScheduledTask(Int64 a_TargetTick, cTask * a_Task) : m_TargetTick(a_TargetTick), m_Task(a_Task) { } - + virtual ~cScheduledTask() { delete m_Task; @@ -872,15 +872,15 @@ private: AString m_OverworldName; AString m_IniFileName; - + /** Name of the storage schema used to load and save chunks */ AString m_StorageSchema; - + int m_StorageCompressionFactor; - + /** The dimension of the world, used by the client to provide correct lighting scheme */ eDimension m_Dimension; - + /** This random generator is to be used only in the Tick() method, and thus only in the World-Tick-thread (MTRand is not exactly thread-safe) */ MTRand m_TickRand; @@ -909,7 +909,7 @@ private: bool m_IsDeepSnowEnabled; bool m_ShouldLavaSpawnFire; bool m_VillagersShouldHarvestCrops; - + std::vector m_BlockTickQueue; std::vector m_BlockTickQueueCopy; // Second is for safely removing the objects from the queue @@ -919,12 +919,12 @@ private: cFluidSimulator * m_LavaSimulator; cFireSimulator * m_FireSimulator; cRedstoneSimulator * m_RedstoneSimulator; - + cCriticalSection m_CSPlayers; cPlayerList m_Players; cWorldStorage m_Storage; - + unsigned int m_MaxPlayers; cChunkMap * m_ChunkMap; @@ -934,7 +934,7 @@ private: eWeather m_Weather; int m_WeatherInterval; - + int m_MaxCactusHeight; int m_MaxSugarcaneHeight; bool m_IsCactusBonemealable; @@ -951,7 +951,7 @@ private: /** Whether command blocks are enabled or not */ bool m_bCommandBlocksEnabled; - + /** Whether prefixes such as [INFO] are prepended to SendMessageXXX() / BroadcastChatXXX() functions */ bool m_bUseChatPrefixes; @@ -965,43 +965,43 @@ private: /** Name of the end world */ AString m_EndWorldName; - + cChunkGenerator m_Generator; cScoreboard m_Scoreboard; cMapManager m_MapManager; - + /** The callbacks that the ChunkGenerator uses to store new chunks and interface to plugins */ cChunkGeneratorCallbacks m_GeneratorCallbacks; - + cChunkSender m_ChunkSender; cLightingThread m_Lighting; cTickThread m_TickThread; - + /** Guards the m_Tasks */ cCriticalSection m_CSTasks; - + /** Tasks that have been queued onto the tick thread; guarded by m_CSTasks */ cTasks m_Tasks; - + /** Guards the m_ScheduledTasks */ cCriticalSection m_CSScheduledTasks; - + /** Tasks that have been queued to be executed on the tick thread at target tick in the future. Ordered by increasing m_TargetTick. Guarded by m_CSScheduledTasks */ cScheduledTasks m_ScheduledTasks; - + /** Guards m_Clients */ cCriticalSection m_CSClients; - + /** List of clients in this world, these will be ticked by this world */ cClientHandleList m_Clients; - + /** Clients that are scheduled for removal (ticked in another world), waiting for TickClients() to remove them */ cClientHandleList m_ClientsToRemove; - + /** Clients that are scheduled for adding, waiting for TickClients to add them */ cClientHandleList m_ClientsToAdd; @@ -1016,10 +1016,10 @@ private: /** List of players that are scheduled for adding, waiting for the Tick thread to add them. */ cPlayerList m_PlayersToAdd; - + /** CS protecting m_SetChunkDataQueue. */ cCriticalSection m_CSSetChunkDataQueue; - + /** Queue for the chunk data to be set into m_ChunkMap by the tick thread. Protected by m_CSSetChunkDataQueue */ cSetChunkDataPtrs m_SetChunkDataQueue; @@ -1031,16 +1031,16 @@ private: /** Handles the weather in each tick */ void TickWeather(float a_Dt); - + /** Handles the mob spawning/moving/destroying each tick */ void TickMobs(float a_Dt); - + /** Executes all tasks queued onto the tick thread */ void TickQueuedTasks(void); - + /** Executes all tasks queued onto the tick thread */ void TickScheduledTasks(void); - + /** Ticks all clients that are in this world */ void TickClients(float a_Dt); @@ -1076,7 +1076,3 @@ private: void SetChunkData(cSetChunkData & a_SetChunkData); }; // tolua_export - - - - -- cgit v1.2.3