Search for statics within rooms is now recursive

Statics can now be in hierarchies in rooms instead of expecting meshes hanging directly from the room.
This commit is contained in:
lawnjelly 2019-09-17 09:32:18 +01:00 committed by GitHub
parent d3eadcbfa5
commit 5969d06e08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 105 additions and 45 deletions

View File

@ -97,6 +97,41 @@ int LRoomConverter::FindRoom_ByName(String szName) const
return -1;
}
void LRoomConverter::Convert_Room_FindObjects_Recursive(Node * pParent, LRoom &lroom, LAABB &bb_room)
{
int nChildren = pParent->get_child_count();
for (int n=0; n<nChildren; n++)
{
Node * pChild = pParent->get_child(n);
VisualInstance * pVI = Object::cast_to<VisualInstance>(pChild);
if (pVI)
{
print("\t\tFound VI : " + pVI->get_name());
// update bound to find centre of room roughly
AABB bb = pVI->get_transformed_aabb();
bb_room.ExpandToEnclose(bb);
// store some info about the static object for use at runtime
LSob sob;
sob.m_ID = pVI->get_instance_id();
sob.m_aabb = bb;
lroom.m_SOBs.push_back(sob);
}
else
{
// not visual instances
}
// does it have further children?
Convert_Room_FindObjects_Recursive(pChild, lroom, bb_room);
}
}
bool LRoomConverter::Convert_Room(Spatial * pNode, int lroomID)
{
// get the room part of the name
@ -120,33 +155,8 @@ bool LRoomConverter::Convert_Room(Spatial * pNode, int lroomID)
LAABB bb_room;
bb_room.SetToMaxOpposite();
int nChildren = pNode->get_child_count();
for (int n=0; n<nChildren; n++)
{
Node * pChild = pNode->get_child(n);
VisualInstance * pVI = Object::cast_to<VisualInstance>(pChild);
if (pVI)
{
print("\t\tFound VI : " + pVI->get_name());
// update bound to find centre of room roughly
AABB bb = pVI->get_transformed_aabb();
bb_room.ExpandToEnclose(bb);
// store some info about the static object for use at runtime
LSob sob;
sob.m_ID = pVI->get_instance_id();
sob.m_aabb = bb;
lroom.m_SOBs.push_back(sob);
}
else
{
// not visual instances NYI
}
}
// recursively find statics
Convert_Room_FindObjects_Recursive(pNode, lroom, bb_room);
// store the lroom centre and bound
lroom.m_ptCentre = bb_room.FindCentre();

View File

@ -63,6 +63,8 @@ private:
void Convert_Rooms();
bool Convert_Room(Spatial * pNode, int lroomID);
void Convert_Room_FindObjects_Recursive(Node * pParent, LRoom &lroom, LAABB &bb_room);
void Convert_Portals();

View File

@ -119,13 +119,13 @@ LRoom * LRoomManager::GetRoomFromDOB(Node * pNode)
}
void LRoomManager::dob_register(Node * pDOB, float radius)
bool LRoomManager::dob_register(Node * pDOB, float radius)
{
print_line("register_dob " + pDOB->get_name());
Spatial * pSpat = Object::cast_to<Spatial>(pDOB);
if (!pSpat)
return;
return false;
Vector3 pt = pSpat->get_global_transform().origin;
@ -133,11 +133,11 @@ void LRoomManager::dob_register(Node * pDOB, float radius)
print_line("register_dob closest room " + itos(iRoomNum));
if (iRoomNum == -1)
return;
return false;
LRoom * pRoom = GetRoom(iRoomNum);
if (!pRoom)
return;
return false;
LDob dob;
dob.m_ID = pSpat->get_instance_id();
@ -147,19 +147,20 @@ void LRoomManager::dob_register(Node * pDOB, float radius)
// save the room ID on the dob metadata
Obj_SetRoomNum(pSpat, iRoomNum);
return true;
}
bool LRoomManager::dob_update(Node * pDOB)
int LRoomManager::dob_update(Node * pDOB)
{
// find the room the object is attached to
LRoom * pRoom = GetRoomFromDOB(pDOB);
if (!pRoom)
return false;
return -1;
Spatial * pSpat = Object::cast_to<Spatial>(pDOB);
if (!pSpat)
return false;
return -1;
LRoom * pNewRoom = pRoom->DOB_Update(*this, pSpat);
@ -184,29 +185,69 @@ bool LRoomManager::dob_update(Node * pDOB)
// save the room ID on the dob metadata
Obj_SetRoomNum(pSpat, iRoomNum);
return true;
// new room number
return iRoomNum;
}
return false;
// still in the same room
return pRoom->m_RoomID;
}
// not tested...
bool LRoomManager::dob_teleport(Node * pDOB)
{
Spatial * pSpat = Object::cast_to<Spatial>(pDOB);
if (!pSpat)
return false;
// old room
LRoom * pOldRoom = GetRoomFromDOB(pDOB);
if (!pOldRoom)
return false;
Vector3 pt = pSpat->get_global_transform().origin;
int iRoomNum = FindClosestRoom(pt);
//print_line("dob_teleport closest room " + itos(iRoomNum));
if (iRoomNum == -1)
return false;
LRoom * pNewRoom = GetRoom(iRoomNum);
if (!pNewRoom)
return false;
// detach from old room, add to new room
// get dob data to move to new room
unsigned int dob_id = pOldRoom->DOB_Find(pDOB);
assert (dob_id != -1);
// copy across data before removing
const LDob &data = pOldRoom->DOB_Get(dob_id);
pNewRoom->DOB_Add(data);
// remove from old room
pOldRoom->DOB_Remove(dob_id);
// save the room ID on the dob metadata
Obj_SetRoomNum(pSpat, iRoomNum);
return true;
}
void LRoomManager::dob_unregister(Node * pDOB)
bool LRoomManager::dob_unregister(Node * pDOB)
{
LRoom * pRoom = GetRoomFromDOB(pDOB);
if (pRoom)
{
unsigned int dob_id = pRoom->DOB_Find(pDOB);
assert (dob_id != -1);
pRoom->DOB_Remove(dob_id);
return pRoom->DOB_Remove(dob_id);
}
return false;
}
int LRoomManager::dob_get_room_id(Node * pDOB)

View File

@ -69,19 +69,26 @@ public:
// normally this will be your main camera, but you can choose another for debugging
void rooms_set_camera(Node * pCam);
// get the Godot room that is associated with an LPortal room
// (can be used to find the name etc of a room ID returned by dob_update)
Node * rooms_get_room(int room_id);
// Dynamic objects .. cameras, players, boxes etc
// These are defined by their ability to move from room to room.
// You can still move static objects within the same room (e.g. elevators, moving platforms)
// as these don't require checks for changing rooms.
void dob_register(Node * pDOB, float radius);
void dob_unregister(Node * pDOB);
bool dob_update(Node * pDOB);
bool dob_register(Node * pDOB, float radius);
bool dob_unregister(Node * pDOB);
// returns the room ID within
int dob_update(Node * pDOB);
// if we are moving the DOB possibly through multiple rooms, then teleport rather than detect
// portal crossings
bool dob_teleport(Node * pDOB);
// supplementary functions available from script
// helper func, not needed usually as dob_update returns the room
int dob_get_room_id(Node * pDOB);
Node * rooms_get_room(int room_id);
protected:
static void _bind_methods();