Fixed: #985 Crash when opening a door

This commit is contained in:
kervala 2010-06-16 23:03:02 +02:00
parent bad13335a2
commit fcc968511f
4 changed files with 41 additions and 9 deletions

View file

@ -22,6 +22,7 @@
#include "pacs_client.h" #include "pacs_client.h"
#include "time_client.h" #include "time_client.h"
#include "entity_cl.h" #include "entity_cl.h"
#include "entities.h"
#include "nel/pacs/u_primitive_block.h" #include "nel/pacs/u_primitive_block.h"
#include "nel/pacs/u_move_container.h" #include "nel/pacs/u_move_container.h"
@ -39,6 +40,10 @@ CIGDoorAddedCallback IGDoorCallback;
CDoorManager *CDoorManager::_Instance = NULL; CDoorManager *CDoorManager::_Instance = NULL;
extern CEntityManager EntitiesMngr;
uint32 CDoorManager::s_nextId = 0;
// *************************************************************************** // ***************************************************************************
void CDoorManager::releaseInstance() void CDoorManager::releaseInstance()
{ {
@ -308,7 +313,7 @@ void CDoorManager::loadedCallback (NL3D::UInstanceGroup *ig)
if ((pPrim->UserData&0xffff) == UserDataDoor) if ((pPrim->UserData&0xffff) == UserDataDoor)
{ {
// First byte is for type (2 for door 1 for ascensor) // First byte is for type (2 for door 1 for ascensor)
pPrim->UserData |= (((uint64)pDoor) << 16); pPrim->UserData |= ((uint64)pDoor->ID << 16);
} }
} }
@ -488,13 +493,30 @@ void CDoorManager::getPACSTriggers()
nUserDataEntity = rTI.Object0; nUserDataEntity = rTI.Object0;
} }
// Retrieve the door pointer if (rTI.CollisionType != UTriggerInfo::Inside)
SDoor *pDoor = (SDoor*)((nUserDataDoor >> 16)&0xffffffffff); continue;
// Retrieve the entity pointer
CEntityCL *pEntity = (CEntityCL*)((nUserDataEntity >> 16)&0xffffffffff);
if (rTI.CollisionType == UTriggerInfo::Inside) // Retrieve the door pointer
SDoor *pDoor = NULL;
CEntityCL *pEntity = NULL;
uint32 doorId = ((nUserDataDoor >> 16) & 0xffffffff);
uint32 entityId = ((nUserDataEntity >> 16) & 0xffffffff);
for(uint i = 0; i < _Doors.size(); ++i)
{
pDoor = _Doors[i];
if (pDoor && pDoor->ID == doorId)
{
pEntity = EntitiesMngr.getEntityByCompressedIndex(entityId);
if (pEntity)
pDoor->entityCollide(pEntity); pDoor->entityCollide(pEntity);
break;
}
}
} }
} }
} }

View file

@ -28,9 +28,11 @@ class CEntityCL;
class CDoorManager : public NL3D::ITransformName class CDoorManager : public NL3D::ITransformName
{ {
static uint32 s_nextId;
struct SDoor struct SDoor
{ {
uint32 ID;
std::string Name; // Name of the door (type_id ie: ma_asc_3portes_02) std::string Name; // Name of the door (type_id ie: ma_asc_3portes_02)
std::vector<NLPACS::UMovePrimitive *> Prims;// All collisions prims for that door std::vector<NLPACS::UMovePrimitive *> Prims;// All collisions prims for that door
NL3D::UInstanceGroup *InstanceGroup; // Instance Group where the door is. NL3D::UInstanceGroup *InstanceGroup; // Instance Group where the door is.
@ -51,6 +53,7 @@ class CDoorManager : public NL3D::ITransformName
SDoor() SDoor()
{ {
ID = ++s_nextId;
InstanceGroup = NULL; InstanceGroup = NULL;
Opened = false; Opened = false;
OCState = 0; OCState = 0;

View file

@ -849,7 +849,11 @@ bool CEntityCL::initPrimitive(float radius, float height, float length, float wi
} }
_Primitive->setCollisionMask(collisionMask); _Primitive->setCollisionMask(collisionMask);
_Primitive->setObstacle(true); _Primitive->setObstacle(true);
_Primitive->UserData = UserDataEntity + (((uint64)this)<<16); _Primitive->UserData = UserDataEntity;
if (_DataSetId != CLFECOMMON::INVALID_CLIENT_DATASET_INDEX)
_Primitive->UserData += (((uint64)_DataSetId)<<16);
primitiveOk= true; primitiveOk= true;
} }
else else
@ -2881,6 +2885,9 @@ void CEntityCL::dataSetId(CLFECOMMON::TClientDataSetIndex dataSet)
{ {
_DataSetId = dataSet; _DataSetId = dataSet;
if (_Primitive && _Primitive->UserData == UserDataEntity)
_Primitive->UserData |= (((uint64)_DataSetId)<<16);
// additionaly, on a UID change, must check the IsInTeam and IsAniml flags // additionaly, on a UID change, must check the IsInTeam and IsAniml flags
updateIsInTeam(); updateIsInTeam();
updateIsUserAnimal(); updateIsUserAnimal();