Continuing conversion to sob list

This commit is contained in:
lawnjelly 2019-09-25 12:54:53 +01:00 committed by GitHub
parent 02184f2022
commit 561aa566b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 106 additions and 85 deletions

View File

@ -596,6 +596,24 @@ void LRoomManager::FrameUpdate_FrustumOnly()
// NYI
}
void LRoomManager::FrameUpdate_Prepare()
{
if (m_bDebugPlanes)
m_DebugPlanes.clear();
// clear the visible room list to write to each frame
m_pCurr_VisibleRoomList->clear();
m_RenderList_SOBs.clear();
m_BF_render_SOBs.Blank();
m_BF_visible_SOBs.Blank();
// as we hit visible rooms we will mark them in a bitset, so we can hide any rooms
// that are showing that haven't been hit this frame
m_BF_visible_rooms.Blank();
// reset the planes pool for another frame
m_Pool.Reset();
}
void LRoomManager::FrameUpdate()
{
if (Engine::get_singleton()->is_editor_hint())
@ -615,19 +633,12 @@ void LRoomManager::FrameUpdate()
return;
}
if (m_bDebugPlanes)
m_DebugPlanes.clear();
// we keep a frame counter to prevent visiting things multiple times on the same frame in recursive functions
m_uiFrameCounter++;
LPRINT(5, "\nFRAME " + itos(m_uiFrameCounter));
// clear the visible room list to write to each frame
m_pCurr_VisibleRoomList->clear();
m_RenderList_SOBs.clear();
m_BF_render_SOBs.Blank();
m_BF_visible_SOBs.Blank();
FrameUpdate_Prepare();
// get the camera desired and make into lcamera
Camera * pCamera = 0;
@ -653,17 +664,11 @@ void LRoomManager::FrameUpdate()
return;
}
// as we hit visible rooms we will mark them in a bitset, so we can hide any rooms
// that are showing that haven't been hit this frame
m_BF_visible_rooms.Blank();
// lcamera contains the info needed for culling
LCamera cam;
cam.m_ptPos = Vector3(0, 0, 0);
cam.m_ptDir = Vector3 (-1, 0, 0);
// reset the planes pool for another frame
m_Pool.Reset();
// the first set of planes are allocated and filled with the view frustum planes
// Note that the visual server doesn't actually need to do view frustum culling as a result...
@ -687,6 +692,21 @@ void LRoomManager::FrameUpdate()
// rendering through any portals in view into other rooms, etc etc
pRoom->DetermineVisibility_Recursive(*this, 0, cam, planes);
// finally hide all the rooms that are currently visible but not in the visible bitfield as having been hit
FrameUpdate_FinalizeRooms();
// set soft visibility of objects within visible rooms
FrameUpdate_FinalizeVisibility_WithinRooms();
// draw debug
FrameUpdate_DrawDebug(cam, *pRoom);
// when running, emit less debugging output so as not to choke the IDE
Lawn::LDebug::m_bRunning = true;
}
void LRoomManager::FrameUpdate_FinalizeRooms()
{
// finally hide all the rooms that are currently visible but not in the visible bitfield as having been hit
// to get started
@ -713,8 +733,10 @@ void LRoomManager::FrameUpdate()
}
}
}
void LRoomManager::FrameUpdate_FinalizeVisibility_WithinRooms()
{
// and hide all the dobs that are in visible rooms that haven't been made visible
// if (m_pCurr_VisibleRoomList->size() == 0)
// print_line("WARNING : vis room list size is 0");
@ -730,14 +752,6 @@ void LRoomManager::FrameUpdate()
m_pCurr_VisibleRoomList = m_pPrev_VisibleRoomList;
m_pPrev_VisibleRoomList = pTemp;
// hide all the DOB
// draw debug
FrameUpdate_DrawDebug(cam, *pRoom);
// when running, emit less debugging output so as not to choke the IDE
Lawn::LDebug::m_bRunning = true;
}

View File

@ -74,9 +74,77 @@ class LRoomManager : public Spatial {
// for debugging, can emulate view frustum culling
bool m_bFrustumOnly;
private:
// lists of rooms and portals, contiguous list so cache friendly
LVector<LRoom> m_Rooms;
LVector<LPortal> m_Portals;
// static objects
LVector<LSob> m_SOBs;
protected:
static void _bind_methods();
void _notification(int p_what);
// The recursive visibility function needs to allocate loads of planes.
// We use a pool for this instead of allocating on the fly.
LPlanesPool m_Pool;
// 0 to 5
int m_iLoggingLevel;
private:
// this is where we do all the culling
void FrameUpdate();
void FrameUpdate_Prepare();
void FrameUpdate_FinalizeRooms();
void FrameUpdate_FinalizeVisibility_WithinRooms();
// debugging emulate view frustum
void FrameUpdate_FrustumOnly();
// draw planes and room hulls
void FrameUpdate_DrawDebug(const LCamera &cam, const LRoom &lroom);
// internal
LRoom &Portal_GetLinkedRoom(const LPortal &port);
bool DobRegister(Spatial * pDOB, float radius, int iRoom);
ObjectID DobRegister_FindVIRecursive(Node * pNode) const;
bool DobTeleport(Spatial * pDOB, int iNewRoomID);
void CreateDebug();
void DobChangeVisibility(Spatial * pDOB, const LRoom * pOld, const LRoom * pNew);
// helper funcs
const LRoom * GetRoom(int i) const;
LRoom * GetRoom(int i);
LRoom * GetRoomFromDOB(Node * pNode);
int FindClosestRoom(const Vector3 &pt) const;
// for DOBs, we need some way of storing the room ID on them, so we use metadata (currently)
// this is pretty gross but hey ho
int Obj_GetRoomNum(Node * pNode) const;
void Obj_SetRoomNum(Node * pNode, int num);
public:
// whether debug planes is switched on
bool m_bDebugPlanes;
bool m_bDebugBounds;
// the planes are shown as a list of lines from the camera to the portal verts
LVector<Vector3> m_DebugPlanes;
private:
ObjectID m_ID_DebugPlanes;
ObjectID m_ID_DebugBounds;
Ref<SpatialMaterial> m_mat_Debug_Planes;
Ref<SpatialMaterial> m_mat_Debug_Bounds;
public:
LRoomManager();
// PUBLIC INTERFACE TO GDSCRIPT
// convert empties and meshes to rooms and portals
void rooms_convert();
@ -121,68 +189,7 @@ public:
// helper func, not needed usually as dob_update returns the room
int dob_get_room_id(Node * pDOB);
protected:
static void _bind_methods();
void _notification(int p_what);
// The recursive visibility function needs to allocate loads of planes.
// We use a pool for this instead of allocating on the fly.
LPlanesPool m_Pool;
// 0 to 5
int m_iLoggingLevel;
private:
// internal
bool DobRegister(Spatial * pDOB, float radius, int iRoom);
ObjectID DobRegister_FindVIRecursive(Node * pNode) const;
bool DobTeleport(Spatial * pDOB, int iNewRoomID);
void CreateDebug();
void DobChangeVisibility(Spatial * pDOB, const LRoom * pOld, const LRoom * pNew);
// helper funcs
const LRoom * GetRoom(int i) const;
LRoom * GetRoom(int i);
LRoom * GetRoomFromDOB(Node * pNode);
int FindClosestRoom(const Vector3 &pt) const;
// for DOBs, we need some way of storing the room ID on them, so we use metadata (currently)
// this is pretty gross but hey ho
int Obj_GetRoomNum(Node * pNode) const;
void Obj_SetRoomNum(Node * pNode, int num);
// this is where we do all the culling
void FrameUpdate();
// debugging emulate view frustum
void FrameUpdate_FrustumOnly();
// draw planes and room hulls
void FrameUpdate_DrawDebug(const LCamera &cam, const LRoom &lroom);
// find which room is linked by a portal
LRoom &Portal_GetLinkedRoom(const LPortal &port);
// lists of rooms and portals, contiguous list so cache friendly
LVector<LRoom> m_Rooms;
LVector<LPortal> m_Portals;
// static objects
LVector<LSob> m_SOBs;
public:
// whether debug planes is switched on
bool m_bDebugPlanes;
bool m_bDebugBounds;
// the planes are shown as a list of lines from the camera to the portal verts
LVector<Vector3> m_DebugPlanes;
private:
ObjectID m_ID_DebugPlanes;
ObjectID m_ID_DebugBounds;
Ref<SpatialMaterial> m_mat_Debug_Planes;
Ref<SpatialMaterial> m_mat_Debug_Bounds;
};
#endif