From fcc968511f201b4514c91a6f20adbeddf5a01da3 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 16 Jun 2010 23:03:02 +0200 Subject: [PATCH] Fixed: #985 Crash when opening a door --- code/nel/include/nel/pacs/u_move_primitive.h | 2 +- code/ryzom/client/src/door_manager.cpp | 36 ++++++++++++++++---- code/ryzom/client/src/door_manager.h | 3 ++ code/ryzom/client/src/entity_cl.cpp | 9 ++++- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/code/nel/include/nel/pacs/u_move_primitive.h b/code/nel/include/nel/pacs/u_move_primitive.h index a5b116d2f..074a29f5d 100644 --- a/code/nel/include/nel/pacs/u_move_primitive.h +++ b/code/nel/include/nel/pacs/u_move_primitive.h @@ -46,7 +46,7 @@ public: /// Type of the collision mask. typedef uint32 TCollisionMask; - typedef uint64 TUserData; + typedef uint64 TUserData; //typedef uintptr_t TUserData; /// Primitive mode diff --git a/code/ryzom/client/src/door_manager.cpp b/code/ryzom/client/src/door_manager.cpp index eac9310b2..24bb04ff9 100644 --- a/code/ryzom/client/src/door_manager.cpp +++ b/code/ryzom/client/src/door_manager.cpp @@ -22,6 +22,7 @@ #include "pacs_client.h" #include "time_client.h" #include "entity_cl.h" +#include "entities.h" #include "nel/pacs/u_primitive_block.h" #include "nel/pacs/u_move_container.h" @@ -39,6 +40,10 @@ CIGDoorAddedCallback IGDoorCallback; CDoorManager *CDoorManager::_Instance = NULL; +extern CEntityManager EntitiesMngr; + +uint32 CDoorManager::s_nextId = 0; + // *************************************************************************** void CDoorManager::releaseInstance() { @@ -308,7 +313,7 @@ void CDoorManager::loadedCallback (NL3D::UInstanceGroup *ig) if ((pPrim->UserData&0xffff) == UserDataDoor) { // 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; } - // Retrieve the door pointer - SDoor *pDoor = (SDoor*)((nUserDataDoor >> 16)&0xffffffffff); - // Retrieve the entity pointer - CEntityCL *pEntity = (CEntityCL*)((nUserDataEntity >> 16)&0xffffffffff); + if (rTI.CollisionType != UTriggerInfo::Inside) + continue; - if (rTI.CollisionType == UTriggerInfo::Inside) - pDoor->entityCollide(pEntity); + // 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); + + break; + } + } } } } diff --git a/code/ryzom/client/src/door_manager.h b/code/ryzom/client/src/door_manager.h index f6abab2c0..db140077a 100644 --- a/code/ryzom/client/src/door_manager.h +++ b/code/ryzom/client/src/door_manager.h @@ -28,9 +28,11 @@ class CEntityCL; class CDoorManager : public NL3D::ITransformName { + static uint32 s_nextId; struct SDoor { + uint32 ID; std::string Name; // Name of the door (type_id ie: ma_asc_3portes_02) std::vector Prims;// All collisions prims for that door NL3D::UInstanceGroup *InstanceGroup; // Instance Group where the door is. @@ -51,6 +53,7 @@ class CDoorManager : public NL3D::ITransformName SDoor() { + ID = ++s_nextId; InstanceGroup = NULL; Opened = false; OCState = 0; diff --git a/code/ryzom/client/src/entity_cl.cpp b/code/ryzom/client/src/entity_cl.cpp index 9e303bba3..dd32a9d85 100644 --- a/code/ryzom/client/src/entity_cl.cpp +++ b/code/ryzom/client/src/entity_cl.cpp @@ -849,7 +849,11 @@ bool CEntityCL::initPrimitive(float radius, float height, float length, float wi } _Primitive->setCollisionMask(collisionMask); _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; } else @@ -2881,6 +2885,9 @@ void CEntityCL::dataSetId(CLFECOMMON::TClientDataSetIndex 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 updateIsInTeam(); updateIsUserAnimal();