From 4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 13 Feb 2012 21:47:03 +0000 Subject: 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 --- source/cPickup.cpp | 99 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 41 deletions(-) (limited to 'source/cPickup.cpp') diff --git a/source/cPickup.cpp b/source/cPickup.cpp index 120fe17aa..b84e07314 100644 --- a/source/cPickup.cpp +++ b/source/cPickup.cpp @@ -54,23 +54,22 @@ cPickup::cPickup(int a_X, int a_Y, int a_Z, const cItem & a_Item, float a_SpeedX //LOG("New pickup: ID(%i) Amount(%i) Health(%i)", m_Item.m_ItemID, m_Item.m_ItemCount, m_Item.m_ItemHealth ); // Spawn it on clients - cPacket_PickupSpawn PickupSpawn; - PickupSpawn.m_UniqueID = m_UniqueID; - PickupSpawn.m_Item = (short)m_Item->m_ItemID; - PickupSpawn.m_Count = m_Item->m_ItemCount; - PickupSpawn.m_Health = m_Item->m_ItemHealth; - PickupSpawn.m_PosX = a_X; - PickupSpawn.m_PosY = a_Y; - PickupSpawn.m_PosZ = a_Z; - PickupSpawn.m_Rotation = (char)(m_Speed->x * 8); - PickupSpawn.m_Pitch = (char)(m_Speed->y * 8); - PickupSpawn.m_Roll = (char)(m_Speed->z * 8); - if(PickupSpawn.m_Item != E_ITEM_EMPTY) - cRoot::Get()->GetServer()->Broadcast( PickupSpawn ); + if (!a_Item.IsEmpty()) + { + std::auto_ptr PickupSpawn(GetSpawnPacket()); + if (PickupSpawn.get() != NULL) + { + cRoot::Get()->GetServer()->Broadcast( PickupSpawn.get() ); + } + } m_EntityType = E_PICKUP; } + + + + cPickup::cPickup(cPacket_PickupSpawn* a_PickupSpawnPacket) : cEntity( ((double)a_PickupSpawnPacket->m_PosX)/32, ((double)a_PickupSpawnPacket->m_PosY)/32, ((double)a_PickupSpawnPacket->m_PosZ)/32 ) , m_Speed( new Vector3f() ) @@ -93,29 +92,43 @@ cPickup::cPickup(cPacket_PickupSpawn* a_PickupSpawnPacket) m_Speed->z = (float)(a_PickupSpawnPacket->m_Roll) / 8; // Spawn it on clients - if(a_PickupSpawnPacket->m_Item != E_ITEM_EMPTY) + if (a_PickupSpawnPacket->m_Item != E_ITEM_EMPTY) + { cRoot::Get()->GetServer()->Broadcast( *a_PickupSpawnPacket ); + } m_EntityType = E_PICKUP; } -void cPickup::SpawnOn( cClientHandle* a_Target ) + + + + +cPacket * cPickup::GetSpawnPacket(void) const { - cPacket_PickupSpawn PickupSpawn; - PickupSpawn.m_UniqueID = m_UniqueID; - PickupSpawn.m_Item = (short)m_Item->m_ItemID; - PickupSpawn.m_Count = m_Item->m_ItemCount; - PickupSpawn.m_Health = m_Item->m_ItemHealth; - PickupSpawn.m_PosX = (int)(m_Pos->x * 32); - PickupSpawn.m_PosY = (int)(m_Pos->y * 32); - PickupSpawn.m_PosZ = (int)(m_Pos->z * 32); - PickupSpawn.m_Rotation = (char)(m_Speed->x * 8); - PickupSpawn.m_Pitch = (char)(m_Speed->y * 8); - PickupSpawn.m_Roll = (char)(m_Speed->z * 8); - if(PickupSpawn.m_Item != E_ITEM_EMPTY) - a_Target->Send( PickupSpawn ); + if (m_Item->IsEmpty()) + { + return NULL; + } + + cPacket_PickupSpawn * PickupSpawn = new cPacket_PickupSpawn; + PickupSpawn->m_UniqueID = m_UniqueID; + PickupSpawn->m_Item = (short)m_Item->m_ItemID; + PickupSpawn->m_Count = m_Item->m_ItemCount; + PickupSpawn->m_Health = m_Item->m_ItemHealth; + PickupSpawn->m_PosX = (int) (m_Pos->x * 32); + PickupSpawn->m_PosY = (int) (m_Pos->y * 32); + PickupSpawn->m_PosZ = (int) (m_Pos->z * 32); + PickupSpawn->m_Rotation = (char)(m_Speed->x * 8); + PickupSpawn->m_Pitch = (char)(m_Speed->y * 8); + PickupSpawn->m_Roll = (char)(m_Speed->z * 8); + return PickupSpawn; } + + + + void cPickup::Tick(float a_Dt) { m_Timer += a_Dt; @@ -142,28 +155,28 @@ void cPickup::Tick(float a_Dt) } if(!m_bCollected) + { HandlePhysics( a_Dt ); + } if( !m_bReplicated || m_bDirtyPosition ) { MoveToCorrectChunk(); m_bReplicated = true; m_bDirtyPosition = false; - cChunk* Chunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ); - if( Chunk ) - { - cPacket_TeleportEntity TeleportEntity( this ); - Chunk->Broadcast( TeleportEntity ); - } + cPacket_TeleportEntity TeleportEntity( this ); + GetWorld()->GetChunk( m_ChunkX, m_ChunkY, m_ChunkZ )->Broadcast( &TeleportEntity ); } - - //printf("YSpeed: %f, OnGround: %i\n", m_SpeedY, m_bOnGround ); } + + + + void cPickup::HandlePhysics(float a_Dt) { m_ResultingSpeed->Set(0.f, 0.f, 0.f); - cWorld* World = GetWorld(); + cWorld * World = GetWorld(); if( m_bOnGround ) // check if it's still on the ground { @@ -273,14 +286,14 @@ void cPickup::HandlePhysics(float a_Dt) *m_Pos += *m_ResultingSpeed * a_Dt; } } - - //Usable for debugging //SetPosition(m_Pos->x, m_Pos->y, m_Pos->z); - - } + + + + bool cPickup::CollectedBy( cPlayer* a_Dest ) { if(m_bCollected) return false; // It's already collected! @@ -303,3 +316,7 @@ bool cPickup::CollectedBy( cPlayer* a_Dest ) return false; } + + + + -- cgit v1.2.3