Rewritten most of the code for multithreading; still not 100%, but getting there. If this commit proves to be too problematic, we can always undo it.
git-svn-id: http://mc-server.googlecode.com/svn/trunk@251 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
@@ -18,8 +18,12 @@
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
cFurnaceEntity::cFurnaceEntity(int a_X, int a_Y, int a_Z, cChunk* a_Chunk)
|
||||
: cBlockEntity( E_BLOCK_FURNACE, a_X, a_Y, a_Z, a_Chunk )
|
||||
|
||||
|
||||
|
||||
|
||||
cFurnaceEntity::cFurnaceEntity(int a_X, int a_Y, int a_Z, cWorld * a_World)
|
||||
: cBlockEntity( E_BLOCK_FURNACE, a_X, a_Y, a_Z, a_World )
|
||||
, m_Items( new cItem[3] )
|
||||
, m_CookingItem( 0 )
|
||||
, m_CookTime( 0 )
|
||||
@@ -29,6 +33,10 @@ cFurnaceEntity::cFurnaceEntity(int a_X, int a_Y, int a_Z, cChunk* a_Chunk)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cFurnaceEntity::~cFurnaceEntity()
|
||||
{
|
||||
// Tell window its owner is destroyed
|
||||
@@ -44,6 +52,10 @@ cFurnaceEntity::~cFurnaceEntity()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cFurnaceEntity::Destroy()
|
||||
{
|
||||
// Drop items
|
||||
@@ -51,16 +63,17 @@ void cFurnaceEntity::Destroy()
|
||||
{
|
||||
if( !m_Items[i].IsEmpty() )
|
||||
{
|
||||
cPickup* Pickup = new cPickup( m_PosX*32 + 16, m_PosY*32 + 16, m_PosZ*32 + 16, m_Items[i], 0, 1.f, 0 );
|
||||
Pickup->Initialize( m_Chunk->GetWorld() );
|
||||
cPickup* Pickup = new cPickup( m_PosX * 32 + 16, m_PosY * 32 + 16, m_PosZ * 32 + 16, m_Items[i], 0, 1.f, 0 );
|
||||
Pickup->Initialize(m_World);
|
||||
m_Items[i].Empty();
|
||||
}
|
||||
}
|
||||
|
||||
// Remove from tick list
|
||||
GetChunk()->RemoveTickBlockEntity( this );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cFurnaceEntity::UsedBy( cPlayer & a_Player )
|
||||
{
|
||||
LOG("Used a furnace");
|
||||
@@ -84,6 +97,10 @@ void cFurnaceEntity::UsedBy( cPlayer & a_Player )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cFurnaceEntity::Tick( float a_Dt )
|
||||
{
|
||||
//LOG("Time left: %0.1f Time burned: %0.1f Burn time: %0.1f", m_CookTime - m_TimeCooked, m_TimeBurned, m_BurnTime );
|
||||
@@ -173,6 +190,10 @@ bool cFurnaceEntity::Tick( float a_Dt )
|
||||
return ((m_CookingItem != 0) || (m_TimeBurned < m_BurnTime)) && m_BurnTime > 0.f; // Keep on ticking, if there's more to cook, or if it's cooking
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cFurnaceEntity::StartCooking()
|
||||
{
|
||||
cFurnaceRecipe* FR = cRoot::Get()->GetFurnaceRecipe();
|
||||
@@ -200,7 +221,6 @@ bool cFurnaceEntity::StartCooking()
|
||||
m_TimeCooked = 0.f;
|
||||
m_CookTime = R->CookTime;
|
||||
}
|
||||
GetChunk()->AddTickBlockEntity( this );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -208,13 +228,14 @@ bool cFurnaceEntity::StartCooking()
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cFurnaceEntity::ResetCookTimer()
|
||||
{
|
||||
if( m_CookingItem )
|
||||
{
|
||||
delete m_CookingItem;
|
||||
m_CookingItem = 0;
|
||||
}
|
||||
delete m_CookingItem;
|
||||
m_CookingItem = NULL;
|
||||
m_TimeCooked = 0.f;
|
||||
m_CookTime = 0.f;
|
||||
}
|
||||
@@ -290,18 +311,21 @@ bool cFurnaceEntity::LoadFromJson( const Json::Value& a_Value )
|
||||
if( !Item.IsEmpty() )
|
||||
{
|
||||
m_CookingItem = new cItem( Item );
|
||||
GetChunk()->AddTickBlockEntity( this );
|
||||
}
|
||||
}
|
||||
|
||||
m_CookTime = (float)a_Value.get("CookTime", 0).asDouble();
|
||||
m_CookTime = (float)a_Value.get("CookTime", 0).asDouble();
|
||||
m_TimeCooked = (float)a_Value.get("TimeCooked", 0).asDouble();
|
||||
m_BurnTime = (float)a_Value.get("BurnTime", 0).asDouble();
|
||||
m_BurnTime = (float)a_Value.get("BurnTime", 0).asDouble();
|
||||
m_TimeBurned = (float)a_Value.get("TimeBurned", 0).asDouble();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cFurnaceEntity::SaveToJson( Json::Value& a_Value )
|
||||
{
|
||||
a_Value["x"] = m_PosX;
|
||||
@@ -329,4 +353,8 @@ void cFurnaceEntity::SaveToJson( Json::Value& a_Value )
|
||||
a_Value["TimeCooked"] = m_TimeCooked;
|
||||
a_Value["BurnTime"] = m_BurnTime;
|
||||
a_Value["TimeBurned"] = m_TimeBurned;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user