diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-10-13 18:24:50 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-10-13 18:24:50 +0200 |
commit | b4ca06b9d9781214f27f388b1663e4372d7f0667 (patch) | |
tree | cfc9638f2f0221bc17d2d9fd37aea9b73b7a8a04 /source/Simulator | |
parent | Forgotten file (diff) | |
download | cuberite-b4ca06b9d9781214f27f388b1663e4372d7f0667.tar cuberite-b4ca06b9d9781214f27f388b1663e4372d7f0667.tar.gz cuberite-b4ca06b9d9781214f27f388b1663e4372d7f0667.tar.bz2 cuberite-b4ca06b9d9781214f27f388b1663e4372d7f0667.tar.lz cuberite-b4ca06b9d9781214f27f388b1663e4372d7f0667.tar.xz cuberite-b4ca06b9d9781214f27f388b1663e4372d7f0667.tar.zst cuberite-b4ca06b9d9781214f27f388b1663e4372d7f0667.zip |
Diffstat (limited to 'source/Simulator')
-rw-r--r-- | source/Simulator/ClassicFluidSimulator.cpp | 137 | ||||
-rw-r--r-- | source/Simulator/ClassicFluidSimulator.h | 7 | ||||
-rw-r--r-- | source/Simulator/FluidSimulator.cpp | 138 | ||||
-rw-r--r-- | source/Simulator/FluidSimulator.h | 9 | ||||
-rw-r--r-- | source/Simulator/LavaSimulator.cpp | 20 | ||||
-rw-r--r-- | source/Simulator/LavaSimulator.h | 12 | ||||
-rw-r--r-- | source/Simulator/WaterSimulator.cpp | 22 | ||||
-rw-r--r-- | source/Simulator/WaterSimulator.h | 11 |
8 files changed, 145 insertions, 211 deletions
diff --git a/source/Simulator/ClassicFluidSimulator.cpp b/source/Simulator/ClassicFluidSimulator.cpp index a5d463844..70dbd0f6f 100644 --- a/source/Simulator/ClassicFluidSimulator.cpp +++ b/source/Simulator/ClassicFluidSimulator.cpp @@ -470,143 +470,6 @@ void cClassicFluidSimulator::Simulate(float a_Dt) -bool cClassicFluidSimulator::IsPassableForFluid(BLOCKTYPE a_BlockType)
-{
- return a_BlockType == E_BLOCK_AIR
- || a_BlockType == E_BLOCK_FIRE
- || IsAllowedBlock(a_BlockType)
- || CanWashAway(a_BlockType);
-}
-
-
-
-
-
-bool cClassicFluidSimulator::CanWashAway(BLOCKTYPE a_BlockType)
-{
- switch (a_BlockType)
- {
- case E_BLOCK_YELLOW_FLOWER:
- case E_BLOCK_RED_ROSE:
- case E_BLOCK_RED_MUSHROOM:
- case E_BLOCK_BROWN_MUSHROOM:
- case E_BLOCK_CACTUS:
- {
- return true;
- }
- default:
- {
- return false;
- }
- }
-}
-
-
-
-
-
-bool cClassicFluidSimulator::IsSolidBlock( BLOCKTYPE a_BlockType )
-{
- return !(a_BlockType == E_BLOCK_AIR
- || a_BlockType == E_BLOCK_FIRE
- || IsBlockLava(a_BlockType)
- || IsBlockWater(a_BlockType)
- || CanWashAway(a_BlockType));
-}
-
-
-
-
-
-// TODO Not working very well yet :s
-Direction cClassicFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a_Over)
-{
- char BlockID = m_World->GetBlock(a_X, a_Y, a_Z);
- if(!IsAllowedBlock(BlockID)) //No Fluid -> No Flowing direction :D
- return NONE;
-
-
- /*
- Disabled because of causing problems and beeing useless atm
- char BlockBelow = m_World->GetBlock(a_X, a_Y - 1, a_Z); //If there is nothing or fluid below it -> dominating flow is down :D
- if(BlockBelow == E_BLOCK_AIR || IsAllowedBlock(BlockBelow))
- return Y_MINUS;
- */
-
- char LowestPoint = m_World->GetBlockMeta(a_X, a_Y, a_Z); //Current Block Meta so only lower points will be counted
- int X = 0, Y = 0, Z = 0; //Lowest Pos will be stored here
-
- if(IsAllowedBlock(m_World->GetBlock(a_X, a_Y + 1, a_Z)) && a_Over) //check for upper block to flow because this also affects the flowing direction
- {
- return GetFlowingDirection(a_X, a_Y + 1, a_Z, false);
- }
-
- std::vector< Vector3i * > Points;
-
- Points.reserve(4); //Already allocate 4 places :D
-
- //add blocks around the checking pos
- Points.push_back(new Vector3i(a_X - 1, a_Y, a_Z));
- Points.push_back(new Vector3i(a_X + 1, a_Y, a_Z));
- Points.push_back(new Vector3i(a_X, a_Y, a_Z + 1));
- Points.push_back(new Vector3i(a_X, a_Y, a_Z - 1));
-
- for(std::vector<Vector3i *>::iterator it = Points.begin(); it < Points.end(); it++)
- {
- Vector3i *Pos = (*it);
- char BlockID = m_World->GetBlock(Pos->x, Pos->y, Pos->z);
- if(IsAllowedBlock(BlockID))
- {
- char Meta = m_World->GetBlockMeta(Pos->x, Pos->y, Pos->z);
-
- if(Meta > LowestPoint)
- {
- LowestPoint = Meta;
- X = Pos->x;
- Y = Pos->y;
- Z = Pos->z;
- }
- }else if(BlockID == E_BLOCK_AIR)
- {
- LowestPoint = 9; //This always dominates
- X = Pos->x;
- Y = Pos->y;
- Z = Pos->z;
-
- }
- delete Pos;
- }
-
- if(LowestPoint == m_World->GetBlockMeta(a_X, a_Y, a_Z))
- return NONE;
-
- if(a_X - X > 0)
- {
- return X_MINUS;
- }
-
- if(a_X - X < 0)
- {
- return X_PLUS;
- }
-
- if(a_Z - Z > 0)
- {
- return Z_MINUS;
- }
-
- if(a_Z - Z < 0)
- {
- return Z_PLUS;
- }
-
- return NONE;
-}
-
-
-
-
-
bool cClassicFluidSimulator::UniqueSituation(Vector3i a_Pos)
{
bool result = false;
diff --git a/source/Simulator/ClassicFluidSimulator.h b/source/Simulator/ClassicFluidSimulator.h index ebccda487..4b6301b9a 100644 --- a/source/Simulator/ClassicFluidSimulator.h +++ b/source/Simulator/ClassicFluidSimulator.h @@ -27,13 +27,6 @@ public: virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) override;
- // cFluidSimulator overrides:
- virtual Direction GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a_Over = true) override;
-
- bool CanWashAway (BLOCKTYPE a_BlockType);
- bool IsSolidBlock(BLOCKTYPE a_BlockType);
- bool IsPassableForFluid(BLOCKTYPE a_BlockType);
-
protected:
NIBBLETYPE GetHighestLevelAround(int a_BlockX, int a_BlockY, int a_BlockZ);
diff --git a/source/Simulator/FluidSimulator.cpp b/source/Simulator/FluidSimulator.cpp index d352d5d4d..4c867aa79 100644 --- a/source/Simulator/FluidSimulator.cpp +++ b/source/Simulator/FluidSimulator.cpp @@ -2,6 +2,7 @@ #include "Globals.h" #include "FluidSimulator.h" +#include "../World.h" @@ -17,3 +18,140 @@ cFluidSimulator::cFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE + +bool cFluidSimulator::IsPassableForFluid(BLOCKTYPE a_BlockType) +{ + return ( + (a_BlockType == E_BLOCK_AIR) || + (a_BlockType == E_BLOCK_FIRE) || + IsAllowedBlock(a_BlockType) || + CanWashAway(a_BlockType) + ); +} + + + + + +bool cFluidSimulator::CanWashAway(BLOCKTYPE a_BlockType) +{ + switch (a_BlockType) + { + case E_BLOCK_YELLOW_FLOWER: + case E_BLOCK_RED_ROSE: + case E_BLOCK_RED_MUSHROOM: + case E_BLOCK_BROWN_MUSHROOM: + case E_BLOCK_CACTUS: + { + return true; + } + default: + { + return false; + } + } +} + + + + + +bool cFluidSimulator::IsSolidBlock(BLOCKTYPE a_BlockType) +{ + return !IsPassableForFluid(a_BlockType); +} + + + + + +// TODO Not working very well yet :s +Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a_Over) +{ + char BlockID = m_World->GetBlock(a_X, a_Y, a_Z); + if (!IsAllowedBlock(BlockID)) // No Fluid -> No Flowing direction :D + { + return NONE; + } + + + /* + Disabled because of causing problems and being useless atm + char BlockBelow = m_World->GetBlock(a_X, a_Y - 1, a_Z); //If there is nothing or fluid below it -> dominating flow is down :D + if (BlockBelow == E_BLOCK_AIR || IsAllowedBlock(BlockBelow)) + return Y_MINUS; + */ + + NIBBLETYPE LowestPoint = m_World->GetBlockMeta(a_X, a_Y, a_Z); //Current Block Meta so only lower points will be counted + int X = 0, Y = 0, Z = 0; //Lowest Pos will be stored here + + if (IsAllowedBlock(m_World->GetBlock(a_X, a_Y + 1, a_Z)) && a_Over) //check for upper block to flow because this also affects the flowing direction + { + return GetFlowingDirection(a_X, a_Y + 1, a_Z, false); + } + + std::vector< Vector3i * > Points; + + Points.reserve(4); //Already allocate 4 places :D + + //add blocks around the checking pos + Points.push_back(new Vector3i(a_X - 1, a_Y, a_Z)); + Points.push_back(new Vector3i(a_X + 1, a_Y, a_Z)); + Points.push_back(new Vector3i(a_X, a_Y, a_Z + 1)); + Points.push_back(new Vector3i(a_X, a_Y, a_Z - 1)); + + for (std::vector<Vector3i *>::iterator it = Points.begin(); it < Points.end(); it++) + { + Vector3i *Pos = (*it); + char BlockID = m_World->GetBlock(Pos->x, Pos->y, Pos->z); + if(IsAllowedBlock(BlockID)) + { + char Meta = m_World->GetBlockMeta(Pos->x, Pos->y, Pos->z); + + if(Meta > LowestPoint) + { + LowestPoint = Meta; + X = Pos->x; + Y = Pos->y; + Z = Pos->z; + } + }else if(BlockID == E_BLOCK_AIR) + { + LowestPoint = 9; //This always dominates + X = Pos->x; + Y = Pos->y; + Z = Pos->z; + + } + delete Pos; + } + + if (LowestPoint == m_World->GetBlockMeta(a_X, a_Y, a_Z)) + return NONE; + + if (a_X - X > 0) + { + return X_MINUS; + } + + if (a_X - X < 0) + { + return X_PLUS; + } + + if (a_Z - Z > 0) + { + return Z_MINUS; + } + + if (a_Z - Z < 0) + { + return Z_PLUS; + } + + return NONE; +} + + + + diff --git a/source/Simulator/FluidSimulator.h b/source/Simulator/FluidSimulator.h index f0b2b23ba..f90de5e71 100644 --- a/source/Simulator/FluidSimulator.h +++ b/source/Simulator/FluidSimulator.h @@ -30,12 +30,17 @@ class cFluidSimulator : public: cFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid); - // Gets the flowing direction. If a_Over is true also the block over the current block affects the direction (standard) - virtual Direction GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a_Over = true) = 0; + /// Gets the flowing direction. If a_Over is true also the block over the current block affects the direction (standard) + virtual Direction GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a_Over = true); bool IsFluidBlock (BLOCKTYPE a_BlockType) const { return (a_BlockType == m_FluidBlock); } bool IsStationaryFluidBlock(BLOCKTYPE a_BlockType) const { return (a_BlockType == m_StationaryFluidBlock); } + static bool CanWashAway(BLOCKTYPE a_BlockType); + + bool IsSolidBlock (BLOCKTYPE a_BlockType); + bool IsPassableForFluid(BLOCKTYPE a_BlockType); + protected: BLOCKTYPE m_FluidBlock; // The fluid block type that needs simulating BLOCKTYPE m_StationaryFluidBlock; // The fluid block type that indicates no simulation is needed diff --git a/source/Simulator/LavaSimulator.cpp b/source/Simulator/LavaSimulator.cpp deleted file mode 100644 index 726cc37e4..000000000 --- a/source/Simulator/LavaSimulator.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "Globals.h" -#include "LavaSimulator.h" -#include "Defines.h" -#include "World.h" - - -cLavaSimulator::cLavaSimulator(cWorld *a_World) - : cFluidSimulator(a_World) -{ - m_FluidBlock = E_BLOCK_LAVA; - m_StationaryFluidBlock = E_BLOCK_STATIONARY_LAVA; - m_MaxHeight = 6; - m_FlowReduction = 2; -} - - -bool cLavaSimulator::IsAllowedBlock(BLOCKTYPE a_BlockType) -{ - return IsBlockLava(a_BlockType); -}
\ No newline at end of file diff --git a/source/Simulator/LavaSimulator.h b/source/Simulator/LavaSimulator.h deleted file mode 100644 index d85b335b7..000000000 --- a/source/Simulator/LavaSimulator.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -#include "FluidSimulator.h" - -class cLavaSimulator : public cFluidSimulator -{ -public: - cLavaSimulator( cWorld* a_World ); - - virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType ) override; - - -};
\ No newline at end of file diff --git a/source/Simulator/WaterSimulator.cpp b/source/Simulator/WaterSimulator.cpp deleted file mode 100644 index c63135419..000000000 --- a/source/Simulator/WaterSimulator.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "Globals.h" -#include "WaterSimulator.h" -#include "Defines.h" -#include "World.h" - - - -cWaterSimulator::cWaterSimulator(cWorld *a_World) - : cFluidSimulator(a_World) -{ - m_FluidBlock = E_BLOCK_WATER; - m_StationaryFluidBlock = E_BLOCK_STATIONARY_WATER; - m_MaxHeight = 7; - m_FlowReduction = 1; -} - - -bool cWaterSimulator::IsAllowedBlock(BLOCKTYPE a_BlockType) -{ - return IsBlockWater(a_BlockType); -} - diff --git a/source/Simulator/WaterSimulator.h b/source/Simulator/WaterSimulator.h deleted file mode 100644 index 4bc35b8f7..000000000 --- a/source/Simulator/WaterSimulator.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once -#include "FluidSimulator.h" - -class cWaterSimulator : public cFluidSimulator -{ -public: - cWaterSimulator( cWorld* a_World ); - - virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType ) override; - -};
\ No newline at end of file |