- improved Simulator system
-> Manager handles all ticks -> advantage: Much easier to add new simulators, because you only have to register them in the manager - moved sand and gravel simulation to a Simulator-class (cSandSimulator) - Made Squid a little bit more funny and realistic, because it dies now when it´s not in water -Escaping mobs run now faster than normal (They just walked away before :D) git-svn-id: http://mc-server.googlecode.com/svn/trunk@125 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
92e0ba6645
commit
9f77572fb0
@ -257,11 +257,14 @@
|
||||
<ClCompile Include="..\source\cRedstone.cpp" />
|
||||
<ClCompile Include="..\Source\cReferenceManager.cpp" />
|
||||
<ClCompile Include="..\Source\cRoot.cpp" />
|
||||
<ClCompile Include="..\source\cSandSimulator.cpp" />
|
||||
<ClCompile Include="..\Source\cSemaphore.cpp" />
|
||||
<ClCompile Include="..\source\cServer.cpp" />
|
||||
<ClCompile Include="..\source\cSheep.cpp" />
|
||||
<ClCompile Include="..\Source\cSignEntity.cpp" />
|
||||
<ClCompile Include="..\source\cSilverfish.cpp" />
|
||||
<ClCompile Include="..\source\cSimulator.cpp" />
|
||||
<ClCompile Include="..\source\cSimulatorManager.cpp" />
|
||||
<ClCompile Include="..\source\cSkeleton.cpp" />
|
||||
<ClCompile Include="..\source\cSleep.cpp" />
|
||||
<ClCompile Include="..\source\cSlime.cpp" />
|
||||
@ -399,12 +402,15 @@
|
||||
<ClInclude Include="..\source\cRedstone.h" />
|
||||
<ClInclude Include="..\Source\cReferenceManager.h" />
|
||||
<ClInclude Include="..\Source\cRoot.h" />
|
||||
<ClInclude Include="..\source\cSandSimulator.h" />
|
||||
<ClInclude Include="..\Source\cSemaphore.h" />
|
||||
<ClInclude Include="..\source\cServer.h" />
|
||||
<ClInclude Include="..\source\cSheep.h" />
|
||||
<ClInclude Include="..\Source\cSign.h" />
|
||||
<ClInclude Include="..\Source\cSignEntity.h" />
|
||||
<ClInclude Include="..\source\cSilverfish.h" />
|
||||
<ClInclude Include="..\source\cSimulator.h" />
|
||||
<ClInclude Include="..\source\cSimulatorManager.h" />
|
||||
<ClInclude Include="..\source\cSkeleton.h" />
|
||||
<ClInclude Include="..\source\cSleep.h" />
|
||||
<ClInclude Include="..\source\cSlime.h" />
|
||||
|
@ -397,15 +397,6 @@
|
||||
<Filter Include="cChunkGenerator">
|
||||
<UniqueIdentifier>{0d6f822b-71eb-406f-b17a-d188c4924283}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="cFluidSimulator">
|
||||
<UniqueIdentifier>{6f92474b-e2a5-4685-abf1-053b09dbc4f1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="cFluidSimulator\cWaterSimulator">
|
||||
<UniqueIdentifier>{02fd457d-3735-4f4b-aaf2-f7701a7ee7bc}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="cFluidSimulator\cLavaSimulator">
|
||||
<UniqueIdentifier>{b0401fd9-4021-4ab7-bf61-c8de112b4196}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="cEntity\cPawn\cMonster\Personalities">
|
||||
<UniqueIdentifier>{b0f7c883-e2ca-4bba-89e3-c36656c3de39}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@ -424,6 +415,21 @@
|
||||
<Filter Include="cWorldGenerator">
|
||||
<UniqueIdentifier>{72727ea7-779f-439e-8f30-53bd6985c9e7}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="cSimulator">
|
||||
<UniqueIdentifier>{0c205a99-5597-4a79-81d1-5b2f882aecf2}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="cSimulator\cFluidSimulator">
|
||||
<UniqueIdentifier>{6f92474b-e2a5-4685-abf1-053b09dbc4f1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="cSimulator\cFluidSimulator\cWaterSimulator">
|
||||
<UniqueIdentifier>{02fd457d-3735-4f4b-aaf2-f7701a7ee7bc}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="cSimulator\cFluidSimulator\cLavaSimulator">
|
||||
<UniqueIdentifier>{b0401fd9-4021-4ab7-bf61-c8de112b4196}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="cSimulator\SandSimulator">
|
||||
<UniqueIdentifier>{b3ebe846-5722-43f3-af56-e874e8fef7a5}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\source\cServer.cpp">
|
||||
@ -746,7 +752,7 @@
|
||||
<Filter>Packets\cPacket_EntityStatus</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\cWaterSimulator.cpp">
|
||||
<Filter>cFluidSimulator\cWaterSimulator</Filter>
|
||||
<Filter>cSimulator\cFluidSimulator\cWaterSimulator</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\cSocket.cpp">
|
||||
<Filter>Threading\cSocket</Filter>
|
||||
@ -809,7 +815,7 @@
|
||||
<Filter>cPiston</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\cLavaSimulator.cpp">
|
||||
<Filter>cFluidSimulator\cLavaSimulator</Filter>
|
||||
<Filter>cSimulator\cFluidSimulator\cLavaSimulator</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\SquirrelBindings.cpp">
|
||||
<Filter>LuaBindings\SquirrelBindings</Filter>
|
||||
@ -830,7 +836,7 @@
|
||||
<Filter>cChunkGenerator</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\cFluidSimulator.cpp">
|
||||
<Filter>cFluidSimulator</Filter>
|
||||
<Filter>cSimulator\cFluidSimulator</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\cAggressiveMonster.cpp">
|
||||
<Filter>cEntity\cPawn\cMonster\Personalities\Aggressive</Filter>
|
||||
@ -847,6 +853,15 @@
|
||||
<ClCompile Include="..\source\cWorldGenerator.cpp">
|
||||
<Filter>cWorldGenerator</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\cSimulator.cpp">
|
||||
<Filter>cSimulator</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\cSandSimulator.cpp">
|
||||
<Filter>cSimulator\SandSimulator</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\cSimulatorManager.cpp">
|
||||
<Filter>cSimulator</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\source\cServer.h">
|
||||
@ -1201,7 +1216,7 @@
|
||||
<Filter>Packets\cPacket_EntityStatus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\cWaterSimulator.h">
|
||||
<Filter>cFluidSimulator\cWaterSimulator</Filter>
|
||||
<Filter>cSimulator\cFluidSimulator\cWaterSimulator</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\cSocket.h">
|
||||
<Filter>Threading\cSocket</Filter>
|
||||
@ -1267,7 +1282,7 @@
|
||||
<Filter>cPiston</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\cLavaSimulator.h">
|
||||
<Filter>cFluidSimulator\cLavaSimulator</Filter>
|
||||
<Filter>cSimulator\cFluidSimulator\cLavaSimulator</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\SquirrelBindings.h">
|
||||
<Filter>LuaBindings\SquirrelBindings</Filter>
|
||||
@ -1288,7 +1303,7 @@
|
||||
<Filter>cChunkGenerator</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\cFluidSimulator.h">
|
||||
<Filter>cFluidSimulator</Filter>
|
||||
<Filter>cSimulator\cFluidSimulator</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\cAggressiveMonster.h">
|
||||
<Filter>cEntity\cPawn\cMonster\Personalities\Aggressive</Filter>
|
||||
@ -1305,6 +1320,15 @@
|
||||
<ClInclude Include="..\source\cWorldGenerator.h">
|
||||
<Filter>cWorldGenerator</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\cSimulator.h">
|
||||
<Filter>cSimulator</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\cSandSimulator.h">
|
||||
<Filter>cSimulator\SandSimulator</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\cSimulatorManager.h">
|
||||
<Filter>cSimulator</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\source\AllToLua.pkg">
|
||||
|
19
makefile
19
makefile
@ -232,6 +232,9 @@ MCServer : \
|
||||
build/zutil.o\
|
||||
build/iniFile.o\
|
||||
build/cSocket.o\
|
||||
build/cSimulator.o\
|
||||
build/cSimulatorManager.o\
|
||||
build/cSandSimulator.o\
|
||||
build/cFluidSimulator.o\
|
||||
build/cWaterSimulator.o\
|
||||
build/cLavaSimulator.o\
|
||||
@ -431,6 +434,9 @@ MCServer : \
|
||||
build/zutil.o\
|
||||
build/iniFile.o\
|
||||
build/cSocket.o\
|
||||
build/cSimulator.o\
|
||||
build/cSimulatorManager.o\
|
||||
build/cSandSimulator.o\
|
||||
build/cFluidSimulator.o\
|
||||
build/cWaterSimulator.o\
|
||||
build/cLavaSimulator.o\
|
||||
@ -633,6 +639,9 @@ clean :
|
||||
build/zutil.o\
|
||||
build/iniFile.o\
|
||||
build/cSocket.o\
|
||||
build/cSimulator.o\
|
||||
build/cSimulatorManager.o\
|
||||
build/cSandSimulator.o\
|
||||
build/cFluidSimulator.o\
|
||||
build/cWaterSimulator.o\
|
||||
build/cLavaSimulator.o\
|
||||
@ -1447,6 +1456,15 @@ build/cMakeDir.o : source/cMakeDir.cpp
|
||||
|
||||
build/cSocket.o : source/cSocket.cpp
|
||||
$(CC) $(CC_OPTIONS) source/cSocket.cpp -c $(INCLUDE) -o build/cSocket.o
|
||||
|
||||
build/cSimulator.o : source/cSimulator.cpp
|
||||
$(CC) $(CC_OPTIONS) source/cSimulator.cpp -c $(INCLUDE) -o build/cSimulator.o
|
||||
|
||||
build/cSimulatorManager.o : source/cSimulatorManager.cpp
|
||||
$(CC) $(CC_OPTIONS) source/cSimulatorManager.cpp -c $(INCLUDE) -o build/cSimulatorManager.o
|
||||
|
||||
build/cSandSimulator.o : source/cSandSimulator.cpp
|
||||
$(CC) $(CC_OPTIONS) source/cSandSimulator.cpp -c $(INCLUDE) -o build/cSandSimulator.o
|
||||
|
||||
build/cFluidSimulator.o : source/cFluidSimulator.cpp
|
||||
$(CC) $(CC_OPTIONS) source/cFluidSimulator.cpp -c $(INCLUDE) -o build/cFluidSimulator.o
|
||||
@ -1463,5 +1481,4 @@ build/cFileFormatUpdater.o : source/cFileFormatUpdater.cpp
|
||||
build/cItem.o : source/cItem.cpp
|
||||
$(CC) $(CC_OPTIONS) source/cItem.cpp -c $(INCLUDE) -o build/cItem.o
|
||||
|
||||
|
||||
##### END RUN ####
|
||||
|
@ -257,8 +257,7 @@ void cChunk::Tick(float a_Dt)
|
||||
int wX, wY, wZ;
|
||||
PositionToWorldPosition(X, Y, Z, wX, wY, wZ);
|
||||
|
||||
m_World->GetWaterSimulator()->WakeUp( wX, wY, wZ );
|
||||
m_World->GetLavaSimulator()->WakeUp( wX, wY, wZ );
|
||||
m_World->GetSimulatorManager()->WakeUp(wX, wY, wZ);
|
||||
if (isRedstone) {
|
||||
cRedstone Redstone(m_World);
|
||||
Redstone.ChangeRedstone( (X+m_PosX*16), (Y+m_PosY*16), (Z+m_PosZ*16), false );
|
||||
@ -306,30 +305,6 @@ void cChunk::Tick(float a_Dt)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case E_BLOCK_STATIONARY_WATER:
|
||||
case E_BLOCK_WATER:
|
||||
|
||||
break;
|
||||
case E_BLOCK_GRAVEL:
|
||||
case E_BLOCK_SAND:
|
||||
{
|
||||
char BottomBlock = GetBlock( X, Y-1, Z );
|
||||
if( BottomBlock == E_BLOCK_AIR || IsBlockWater(BottomBlock) || IsBlockLava(BottomBlock) )
|
||||
{
|
||||
SetBlock( X, Y, Z, E_BLOCK_AIR, 0 );
|
||||
SetBlock( X, Y-1, Z, BlockID, 0 );
|
||||
|
||||
int wX, wY, wZ;
|
||||
|
||||
PositionToWorldPosition(X, Y, Z, wX, wY, wZ);
|
||||
|
||||
m_World->GetWaterSimulator()->WakeUp( wX, wY, wZ );
|
||||
m_World->GetLavaSimulator()->WakeUp( wX, wY, wZ );
|
||||
m_World->GetWaterSimulator()->WakeUp( wX, wY - 1, wZ );
|
||||
m_World->GetLavaSimulator()->WakeUp( wX, wY - 1, wZ );
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
@ -72,7 +72,7 @@ public:
|
||||
};
|
||||
|
||||
cFluidSimulator::cFluidSimulator( cWorld* a_World )
|
||||
: m_World(a_World)
|
||||
: cSimulator(a_World)
|
||||
, m_Data(0)
|
||||
{
|
||||
m_Data = new FluidData(a_World, this);
|
||||
@ -80,17 +80,7 @@ cFluidSimulator::cFluidSimulator( cWorld* a_World )
|
||||
|
||||
cFluidSimulator::~cFluidSimulator()
|
||||
{
|
||||
}
|
||||
|
||||
void cFluidSimulator::WakeUp( int a_X, int a_Y, int a_Z )
|
||||
{
|
||||
AddBlock( a_X, a_Y, a_Z );
|
||||
AddBlock( a_X-1, a_Y, a_Z );
|
||||
AddBlock( a_X+1, a_Y, a_Z );
|
||||
AddBlock( a_X, a_Y-1, a_Z );
|
||||
AddBlock( a_X, a_Y+1, a_Z );
|
||||
AddBlock( a_X, a_Y, a_Z-1 );
|
||||
AddBlock( a_X, a_Y, a_Z+1 );
|
||||
delete m_Data;
|
||||
}
|
||||
|
||||
void cFluidSimulator::AddBlock( int a_X, int a_Y, int a_Z )
|
||||
@ -99,8 +89,8 @@ void cFluidSimulator::AddBlock( int a_X, int a_Y, int a_Z )
|
||||
std::vector< Vector3i > & ActiveFluid = *m_Data->m_ActiveFluid;
|
||||
for( std::vector< Vector3i >::iterator itr = ActiveFluid.begin(); itr != ActiveFluid.end(); ++itr )
|
||||
{
|
||||
Vector3i & pos = *itr;
|
||||
if( pos.x == a_X && pos.y == a_Y && pos.z == a_Z )
|
||||
Vector3i & Pos = *itr;
|
||||
if( Pos.x == a_X && Pos.y == a_Y && Pos.z == a_Z )
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "cSimulator.h"
|
||||
|
||||
|
||||
//TODO This definitly needs a better naming :D but how?
|
||||
enum Direction
|
||||
@ -15,14 +17,13 @@ enum Direction
|
||||
|
||||
class Vector3i;
|
||||
class cWorld;
|
||||
class cFluidSimulator
|
||||
class cFluidSimulator : public cSimulator
|
||||
{
|
||||
public:
|
||||
cFluidSimulator( cWorld* a_World );
|
||||
~cFluidSimulator();
|
||||
|
||||
virtual void Simulate( float a_Dt );
|
||||
void WakeUp( int a_X, int a_Y, int a_Z );
|
||||
|
||||
//Gets the flowing direction. if a_Over is true also the block over the current block affects the direction (standard)
|
||||
Direction GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a_Over = true);
|
||||
@ -31,12 +32,11 @@ public:
|
||||
virtual inline bool IsPassableForFluid( char a_BlockID ) = 0;
|
||||
|
||||
protected:
|
||||
void AddBlock( int a_X, int a_Y, int a_Z);
|
||||
virtual void AddBlock( int a_X, int a_Y, int a_Z);
|
||||
char GetHighestLevelAround( int a_X, int a_Y, int a_Z );
|
||||
|
||||
|
||||
float m_Timer;
|
||||
cWorld* m_World;
|
||||
|
||||
class FluidData;
|
||||
FluidData* m_Data;
|
||||
|
@ -14,7 +14,8 @@ cPassiveMonster::~cPassiveMonster()
|
||||
void cPassiveMonster::TakeDamage(int a_Damage, cEntity* a_Instigator)
|
||||
{
|
||||
cMonster::TakeDamage(a_Damage, a_Instigator);
|
||||
m_EMState = ESCAPING;
|
||||
if(a_Instigator != this)
|
||||
m_EMState = ESCAPING;
|
||||
}
|
||||
|
||||
void cPassiveMonster::Tick(float a_Dt)
|
||||
|
74
source/cSandSimulator.cpp
Normal file
74
source/cSandSimulator.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
#include "cSandSimulator.h"
|
||||
#include "cWorld.h"
|
||||
#include "Vector3i.h"
|
||||
#include "BlockID.h"
|
||||
#include "Defines.h"
|
||||
#include <vector>
|
||||
|
||||
cSandSimulator::cSandSimulator( cWorld* a_World )
|
||||
: cSimulator(a_World)
|
||||
, m_Blocks(new std::vector <Vector3i *>)
|
||||
, m_Buffer(new std::vector <Vector3i *>)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
cSandSimulator::~cSandSimulator()
|
||||
{
|
||||
delete m_Buffer;
|
||||
delete m_Blocks;
|
||||
}
|
||||
|
||||
void cSandSimulator::Simulate( float a_Dt )
|
||||
{
|
||||
m_Buffer->clear();
|
||||
std::swap( m_Blocks, m_Buffer );
|
||||
|
||||
for( std::vector<Vector3i *>::iterator itr = m_Buffer->begin(); itr != m_Buffer->end(); ++itr )
|
||||
{
|
||||
Vector3i *Pos = *itr;
|
||||
char BlockID = m_World->GetBlock(Pos->x, Pos->y, Pos->z);
|
||||
if(!IsAllowedBlock(BlockID))
|
||||
continue;
|
||||
|
||||
char BottomBlock = m_World->GetBlock( Pos->x, Pos->y - 1, Pos->z );
|
||||
|
||||
if( IsPassable(BottomBlock) )
|
||||
{
|
||||
m_World->SetBlock( Pos->x, Pos->y, Pos->z, E_BLOCK_AIR, 0 );
|
||||
m_World->SetBlock( Pos->x, Pos->y - 1, Pos->z, BlockID, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool cSandSimulator::IsAllowedBlock( char a_BlockID )
|
||||
{
|
||||
return a_BlockID == E_BLOCK_SAND
|
||||
|| a_BlockID == E_BLOCK_GRAVEL;
|
||||
}
|
||||
|
||||
void cSandSimulator::AddBlock(int a_X, int a_Y, int a_Z)
|
||||
{
|
||||
Vector3i *Block = new Vector3i(a_X, a_Y, a_Z);
|
||||
|
||||
//check for duplicates
|
||||
for( std::vector<Vector3i *>::iterator itr = m_Blocks->begin(); itr != m_Blocks->end(); ++itr )
|
||||
{
|
||||
Vector3i *Pos = *itr;
|
||||
if( Pos->x == a_X && Pos->y == a_Y && Pos->z == a_Z )
|
||||
return;
|
||||
}
|
||||
|
||||
m_Blocks->push_back(Block);
|
||||
|
||||
}
|
||||
|
||||
bool cSandSimulator::IsPassable( char a_BlockID )
|
||||
{
|
||||
return a_BlockID == E_BLOCK_AIR
|
||||
|| IsBlockWater(a_BlockID)
|
||||
|| IsBlockLava(a_BlockID);
|
||||
|
||||
}
|
24
source/cSandSimulator.h
Normal file
24
source/cSandSimulator.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "cSimulator.h"
|
||||
#include "cBlockEntity.h"
|
||||
#include "vector"
|
||||
|
||||
class Vector3i;
|
||||
class cWorld;
|
||||
class cSandSimulator : public cSimulator
|
||||
{
|
||||
public:
|
||||
cSandSimulator( cWorld* a_World );
|
||||
~cSandSimulator();
|
||||
|
||||
virtual void Simulate( float a_Dt );
|
||||
|
||||
virtual inline bool IsAllowedBlock( char a_BlockID );
|
||||
virtual inline bool IsPassable( char a_BlockID );
|
||||
|
||||
protected:
|
||||
virtual void AddBlock(int a_X, int a_Y, int a_Z);
|
||||
|
||||
std::vector <Vector3i *> *m_Blocks;
|
||||
std::vector <Vector3i *> *m_Buffer;
|
||||
};
|
27
source/cSimulator.cpp
Normal file
27
source/cSimulator.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "cSimulator.h"
|
||||
#include "cWorld.h"
|
||||
#include "Vector3i.h"
|
||||
#include "BlockID.h"
|
||||
#include "Defines.h"
|
||||
#include <vector>
|
||||
|
||||
cSimulator::cSimulator( cWorld* a_World )
|
||||
: m_World(a_World)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
cSimulator::~cSimulator()
|
||||
{
|
||||
}
|
||||
|
||||
void cSimulator::WakeUp( int a_X, int a_Y, int a_Z )
|
||||
{
|
||||
AddBlock( a_X, a_Y, a_Z );
|
||||
AddBlock( a_X-1, a_Y, a_Z );
|
||||
AddBlock( a_X+1, a_Y, a_Z );
|
||||
AddBlock( a_X, a_Y-1, a_Z );
|
||||
AddBlock( a_X, a_Y+1, a_Z );
|
||||
AddBlock( a_X, a_Y, a_Z-1 );
|
||||
AddBlock( a_X, a_Y, a_Z+1 );
|
||||
}
|
20
source/cSimulator.h
Normal file
20
source/cSimulator.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
class Vector3i;
|
||||
class cWorld;
|
||||
class cSimulator
|
||||
{
|
||||
public:
|
||||
cSimulator( cWorld* a_World );
|
||||
~cSimulator();
|
||||
|
||||
virtual void Simulate( float a_Dt ) = 0;
|
||||
virtual inline void WakeUp( int a_X, int a_Y, int a_Z ); //Used often so inline saves some calls
|
||||
|
||||
virtual inline bool IsAllowedBlock( char a_BlockID ) = 0;
|
||||
|
||||
protected:
|
||||
virtual void AddBlock(int a_X, int a_Y, int a_Z) = 0;
|
||||
|
||||
cWorld *m_World;
|
||||
};
|
38
source/cSimulatorManager.cpp
Normal file
38
source/cSimulatorManager.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "cSimulatorManager.h"
|
||||
#include <vector>
|
||||
|
||||
cSimulatorManager::cSimulatorManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
cSimulatorManager::~cSimulatorManager()
|
||||
{
|
||||
}
|
||||
|
||||
void cSimulatorManager::Simulate( float a_Dt )
|
||||
{
|
||||
m_Ticks++;
|
||||
for( std::vector <std::pair<cSimulator *, short> *>::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr )
|
||||
{
|
||||
|
||||
if(m_Ticks % (*itr)->second == 0)
|
||||
(*itr)->first->Simulate(a_Dt);
|
||||
}
|
||||
}
|
||||
|
||||
void cSimulatorManager::WakeUp(int a_X, int a_Y, int a_Z)
|
||||
{
|
||||
for( std::vector <std::pair<cSimulator *, short> *>::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr )
|
||||
{
|
||||
(*itr)->first->WakeUp(a_X, a_Y, a_Z);
|
||||
}
|
||||
}
|
||||
|
||||
void cSimulatorManager::RegisterSimulator(cSimulator *a_Simulator, short a_Rate)
|
||||
{
|
||||
//TODO needs some checking
|
||||
std::pair<cSimulator *, short> *Pair = new std::pair<cSimulator *, short>(a_Simulator, a_Rate);
|
||||
|
||||
m_Simulators.push_back(Pair);
|
||||
}
|
20
source/cSimulatorManager.h
Normal file
20
source/cSimulatorManager.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "cSimulator.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
class cSimulatorManager
|
||||
{
|
||||
public:
|
||||
cSimulatorManager();
|
||||
~cSimulatorManager();
|
||||
|
||||
void Simulate( float a_Dt );
|
||||
void WakeUp(int a_X, int a_Y, int a_Z);
|
||||
|
||||
void RegisterSimulator(cSimulator *a_Simulator, short a_Rate);
|
||||
|
||||
protected:
|
||||
std::vector <std::pair<cSimulator *, short> *> m_Simulators;
|
||||
long long m_Ticks;
|
||||
};
|
@ -1,13 +1,16 @@
|
||||
#include "cSquid.h"
|
||||
#include "Vector3d.h"
|
||||
|
||||
cSquid::cSquid()
|
||||
{
|
||||
m_MobType = 94;
|
||||
GetMonsterConfig("Squid");
|
||||
m_NoWater = 0.f;
|
||||
}
|
||||
|
||||
cSquid::~cSquid()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool cSquid::IsA( const char* a_EntityType )
|
||||
@ -23,3 +26,25 @@ void cSquid::KilledBy( cEntity* a_Killer )
|
||||
|
||||
cMonster::KilledBy( a_Killer );
|
||||
}
|
||||
|
||||
void cSquid::Tick(float a_Dt)
|
||||
{
|
||||
cPassiveMonster::Tick(a_Dt);
|
||||
|
||||
Vector3d Pos = GetPosition();
|
||||
|
||||
|
||||
//TODO Not a real behavior, but cool :D
|
||||
if(!IsBlockWater(GetWorld()->GetBlock(Pos.x, Pos.y, Pos.z)))
|
||||
{
|
||||
//Die slowly Muhahaha :D (To prevent all this squids on the land :D)
|
||||
m_NoWater += a_Dt;
|
||||
|
||||
if(m_NoWater > 1000.f)
|
||||
{
|
||||
m_NoWater -= 1000.f;
|
||||
TakeDamage(1, this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -8,6 +8,11 @@ public:
|
||||
cSquid();
|
||||
~cSquid();
|
||||
|
||||
virtual void Tick(float a_Dt);
|
||||
|
||||
virtual bool IsA( const char* a_EntityType );
|
||||
virtual void KilledBy( cEntity* a_Killer );
|
||||
|
||||
protected:
|
||||
float m_NoWater;
|
||||
};
|
||||
|
@ -13,8 +13,10 @@
|
||||
#include "cRoot.h"
|
||||
#include "../iniFile/iniFile.h"
|
||||
#include "cChunkMap.h"
|
||||
#include "cSimulatorManager.h"
|
||||
#include "cWaterSimulator.h"
|
||||
#include "cLavaSimulator.h"
|
||||
#include "cSandSimulator.h"
|
||||
#include "cChicken.h"
|
||||
#include "cSpider.h"
|
||||
#include "cCow.h" //cow
|
||||
@ -119,6 +121,8 @@ cWorld::~cWorld()
|
||||
}
|
||||
UnlockEntities();
|
||||
|
||||
delete m_SimulatorManager;
|
||||
delete m_SandSimulator;
|
||||
delete m_WaterSimulator;
|
||||
delete m_LavaSimulator;
|
||||
|
||||
@ -219,8 +223,20 @@ cWorld::cWorld( const char* a_WorldName )
|
||||
m_EntitiesCriticalSection = new cCriticalSection();
|
||||
m_ChunksCriticalSection = new cCriticalSection();
|
||||
|
||||
//Simulators:
|
||||
m_SimulatorManager = new cSimulatorManager();
|
||||
|
||||
m_WaterSimulator = new cWaterSimulator( this );
|
||||
m_SimulatorManager->RegisterSimulator(m_WaterSimulator, 6);
|
||||
|
||||
m_LavaSimulator = new cLavaSimulator( this );
|
||||
m_SimulatorManager->RegisterSimulator(m_LavaSimulator, 12);
|
||||
|
||||
m_SandSimulator = new cSandSimulator(this);
|
||||
|
||||
m_SimulatorManager->RegisterSimulator(m_SandSimulator, 1);
|
||||
|
||||
|
||||
|
||||
memset( g_BlockLightValue, 0x0, 128 );
|
||||
memset( g_BlockSpreadLightFalloff, 0xf, 128 ); // 0xf means total falloff
|
||||
@ -407,10 +423,9 @@ void cWorld::Tick(float a_Dt)
|
||||
}
|
||||
|
||||
m_ChunkMap->Tick(a_Dt);
|
||||
if( CurrentTick % 6 == 0 )
|
||||
m_WaterSimulator->Simulate(a_Dt);
|
||||
if( CurrentTick % 12 == 0 )
|
||||
m_LavaSimulator->Simulate(a_Dt);
|
||||
|
||||
GetSimulatorManager()->Simulate(a_Dt);
|
||||
|
||||
UnlockChunks();
|
||||
|
||||
MTRand r1;
|
||||
@ -700,8 +715,7 @@ cChunk* cWorld::GetChunkOfBlock( int a_X, int a_Y, int a_Z )
|
||||
|
||||
void cWorld::SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta )
|
||||
{
|
||||
m_WaterSimulator->WakeUp( a_X, a_Y, a_Z );
|
||||
m_LavaSimulator->WakeUp( a_X, a_Y, a_Z );
|
||||
this->GetSimulatorManager()->WakeUp(a_X, a_Y, a_Z);
|
||||
|
||||
int ChunkX, ChunkY, ChunkZ;
|
||||
AbsoluteToRelative( a_X, a_Y, a_Z, ChunkX, ChunkY, ChunkZ );
|
||||
@ -785,8 +799,8 @@ bool cWorld::DigBlock( int a_X, int a_Y, int a_Z, cItem & a_PickupItem )
|
||||
if(DestChunk)
|
||||
{
|
||||
DestChunk->SetBlock(PosX, PosY, PosZ, E_BLOCK_AIR, 0 );
|
||||
m_WaterSimulator->WakeUp( a_X, a_Y, a_Z );
|
||||
m_LavaSimulator->WakeUp( a_X, a_Y, a_Z );
|
||||
|
||||
GetSimulatorManager()->WakeUp(a_X, a_Y, a_Z);
|
||||
|
||||
if( !a_PickupItem.IsEmpty() )
|
||||
{
|
||||
|
@ -12,10 +12,13 @@ enum ENUM_ITEM_ID;
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "cSimulatorManager.h"
|
||||
|
||||
class cPacket;
|
||||
class cRedstone;
|
||||
class cWaterSimulator;
|
||||
class cLavaSimulator;
|
||||
class cSandSimulator;
|
||||
class cChunkMap;
|
||||
class cItem;
|
||||
class cCriticalSection;
|
||||
@ -24,6 +27,8 @@ class cClientHandle;
|
||||
class cChunk;
|
||||
class cEntity;
|
||||
class cBlockEntity;
|
||||
|
||||
|
||||
class cWorld //tolua_export
|
||||
{ //tolua_export
|
||||
public:
|
||||
@ -92,8 +97,9 @@ public:
|
||||
const double & GetSpawnY(); //tolua_export
|
||||
const double & GetSpawnZ() { return m_SpawnZ; } //tolua_export
|
||||
|
||||
cWaterSimulator *GetWaterSimulator() { return m_WaterSimulator; }
|
||||
cLavaSimulator *GetLavaSimulator() { return m_LavaSimulator; }
|
||||
inline cSimulatorManager *GetSimulatorManager() { return m_SimulatorManager; }
|
||||
inline cWaterSimulator *GetWaterSimulator() { return m_WaterSimulator; }
|
||||
inline cLavaSimulator *GetLavaSimulator() { return m_LavaSimulator; }
|
||||
|
||||
|
||||
cBlockEntity* GetBlockEntity( int a_X, int a_Y, int a_Z ); //tolua_export
|
||||
@ -173,8 +179,11 @@ private:
|
||||
int m_GameMode;
|
||||
float m_WorldTimeFraction; // When this > 1.f m_WorldTime is incremented by 20
|
||||
|
||||
cSimulatorManager *m_SimulatorManager;
|
||||
cSandSimulator *m_SandSimulator;
|
||||
cWaterSimulator* m_WaterSimulator;
|
||||
cLavaSimulator* m_LavaSimulator;
|
||||
|
||||
|
||||
cCriticalSection* m_ClientHandleCriticalSection;
|
||||
cCriticalSection* m_EntitiesCriticalSection;
|
||||
|
Loading…
Reference in New Issue
Block a user