Skip to content

Commit

Permalink
UPBGE: Use KX_GameObject directly instead of KX_CullingNode.
Browse files Browse the repository at this point in the history
KX_CullingNode is not interesting as is goal was just to offer
a pointer to the game object using it and the SG_CullingNode
API.
This class can be replaced by KX_GameObject in KX_CullingHandler
which still get the culling node, but this time only SG_CullingNode.
  • Loading branch information
panzergame committed Nov 13, 2017
1 parent d45086e commit 5577969
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 103 deletions.
2 changes: 0 additions & 2 deletions source/gameengine/Ketsji/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ set(SRC
KX_ConstraintWrapper.cpp
KX_CubeMap.cpp
KX_CullingHandler.cpp
KX_CullingNode.cpp
KX_EmptyObject.cpp
KX_FontObject.cpp
KX_GameActuator.cpp
Expand Down Expand Up @@ -175,7 +174,6 @@ set(SRC
KX_ConstraintWrapper.h
KX_CubeMap.h
KX_CullingHandler.h
KX_CullingNode.h
KX_EmptyObject.h
KX_FontObject.h
KX_GameActuator.h
Expand Down
12 changes: 7 additions & 5 deletions source/gameengine/Ketsji/KX_CullingHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@

#include "SG_Node.h"

KX_CullingHandler::KX_CullingHandler(KX_CullingNodeList& nodes, const SG_Frustum& frustum)
:m_activeNodes(nodes),
KX_CullingHandler::KX_CullingHandler(std::vector<KX_GameObject *>& objects, const SG_Frustum& frustum)
:m_activeObjects(objects),
m_frustum(frustum)
{
}

void KX_CullingHandler::Process(KX_CullingNode *node)
void KX_CullingHandler::Process(KX_GameObject *object)
{
SG_Node *sgnode = node->GetObject()->GetSGNode();
SG_Node *sgnode = object->GetSGNode();
SG_CullingNode *node = object->GetCullingNode();

const MT_Transform trans = sgnode->GetWorldTransform();
const MT_Vector3 &scale = sgnode->GetWorldScaling();
const SG_BBox& aabb = node->GetAabb();
Expand All @@ -31,6 +33,6 @@ void KX_CullingHandler::Process(KX_CullingNode *node)

node->SetCulled(culled);
if (!culled) {
m_activeNodes.push_back(node);
m_activeObjects.push_back(object);
}
}
16 changes: 9 additions & 7 deletions source/gameengine/Ketsji/KX_CullingHandler.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
#ifndef __KX_CULLING_HANDLER_H__
#define __KX_CULLING_HANDLER_H__

#include "KX_CullingNode.h"
#include "SG_Frustum.h"
#include <vector>

class KX_GameObject;

class KX_CullingHandler
{
private:
/// List of all nodes to render after the culling pass.
KX_CullingNodeList& m_activeNodes;
/// List of all objects to render after the culling pass.
std::vector<KX_GameObject *>& m_activeObjects;
/// The camera frustum data.
const SG_Frustum& m_frustum;

public:
KX_CullingHandler(KX_CullingNodeList& nodes, const SG_Frustum& frustum);
KX_CullingHandler(std::vector<KX_GameObject *>& objects, const SG_Frustum& frustum);
~KX_CullingHandler() = default;

/** Process the culling of a new node, if the culling succeeded the
* node is added in m_activeNodes.
/** Process the culling of a new object, if the culling succeeded the
* object is added in m_activeObjects.
*/
void Process(KX_CullingNode *node);
void Process(KX_GameObject *object);
};

#endif // __KX_CULLING_HANDLER_H__
16 changes: 0 additions & 16 deletions source/gameengine/Ketsji/KX_CullingNode.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions source/gameengine/Ketsji/KX_CullingNode.h

This file was deleted.

7 changes: 2 additions & 5 deletions source/gameengine/Ketsji/KX_GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#include "KX_LodLevel.h"
#include "KX_LodManager.h"
#include "KX_BoundingBox.h"
#include "KX_CullingNode.h"
#include "SG_CullingNode.h"
#include "KX_BatchGroup.h"
#include "KX_CollisionContactPoints.h"

Expand Down Expand Up @@ -125,7 +125,6 @@ KX_GameObject::KX_GameObject(
m_autoUpdateBounds(false),
m_pPhysicsController(nullptr),
m_pGraphicController(nullptr),
m_cullingNode(this),
m_components(nullptr),
m_pInstanceObjects(nullptr),
m_pDupliGroupObject(nullptr),
Expand Down Expand Up @@ -510,8 +509,6 @@ void KX_GameObject::ProcessReplica()
m_pPhysicsController = nullptr;
m_pSGNode = nullptr;

m_cullingNode.SetObject(this);

/* Dupli group and instance list are set later in replication.
* See KX_Scene::DupliGroupRecurse. */
m_pDupliGroupObject = nullptr;
Expand Down Expand Up @@ -1442,7 +1439,7 @@ void KX_GameObject::GetBoundsAabb(MT_Vector3 &aabbMin, MT_Vector3 &aabbMax) cons
m_cullingNode.GetAabb().Get(aabbMin, aabbMax);
}

KX_CullingNode *KX_GameObject::GetCullingNode()
SG_CullingNode *KX_GameObject::GetCullingNode()
{
return &m_cullingNode;
}
Expand Down
6 changes: 3 additions & 3 deletions source/gameengine/Ketsji/KX_GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "EXP_ListValue.h"
#include "SCA_IObject.h"
#include "SG_Node.h"
#include "SG_CullingNode.h"
#include "MT_Transform.h"
#include "KX_Scene.h"
#include "KX_KetsjiEngine.h" /* for m_anim_framerate */
Expand All @@ -54,7 +55,6 @@
struct KX_ClientObjectInfo;
class KX_RayCast;
class KX_LodManager;
class KX_CullingNode;
class KX_PythonComponent;
class RAS_MeshObject;
class RAS_MeshUser;
Expand Down Expand Up @@ -131,7 +131,7 @@ class KX_GameObject : public SCA_IObject
PHY_IPhysicsController* m_pPhysicsController;
PHY_IGraphicController* m_pGraphicController;

KX_CullingNode m_cullingNode;
SG_CullingNode m_cullingNode;
SG_Node* m_pSGNode;

EXP_ListValue<KX_PythonComponent> *m_components;
Expand Down Expand Up @@ -859,7 +859,7 @@ class KX_GameObject : public SCA_IObject
void SetBoundsAabb(MT_Vector3 aabbMin, MT_Vector3 aabbMax);
void GetBoundsAabb(MT_Vector3 &aabbMin, MT_Vector3 &aabbMax) const;

KX_CullingNode *GetCullingNode();
SG_CullingNode *GetCullingNode();

ActivityCullingInfo& GetActivityCullingInfo();
void SetActivityCullingInfo(const ActivityCullingInfo& cullingInfo);
Expand Down
16 changes: 8 additions & 8 deletions source/gameengine/Ketsji/KX_KetsjiEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,9 +879,9 @@ void KX_KetsjiEngine::RenderShadowBuffers(KX_Scene *scene)
/* binds framebuffer object, sets up camera .. */
raslight->BindShadowBuffer(m_canvas, cam, camtrans);

KX_CullingNodeList nodes;
std::vector<KX_GameObject *> objects;
/* update scene */
scene->CalculateVisibleMeshes(nodes, cam, raslight->GetShadowLayer());
scene->CalculateVisibleMeshes(objects, cam, raslight->GetShadowLayer());

m_logger.StartLog(tc_animations, m_kxsystem->GetTimeInSeconds());
UpdateAnimations(scene);
Expand All @@ -890,7 +890,7 @@ void KX_KetsjiEngine::RenderShadowBuffers(KX_Scene *scene)
/* render */
m_rasterizer->Clear(RAS_Rasterizer::RAS_DEPTH_BUFFER_BIT | RAS_Rasterizer::RAS_COLOR_BUFFER_BIT);
// Send a nullptr off screen because the viewport is binding it's using its own private one.
scene->RenderBuckets(nodes, RAS_Rasterizer::RAS_SHADOW, camtrans, m_rasterizer, nullptr);
scene->RenderBuckets(objects, RAS_Rasterizer::RAS_SHADOW, camtrans, m_rasterizer, nullptr);

/* unbind framebuffer object, restore drawmode, free camera */
raslight->UnbindShadowBuffer();
Expand Down Expand Up @@ -1025,11 +1025,11 @@ void KX_KetsjiEngine::RenderCamera(KX_Scene *scene, const CameraRenderData& came

m_logger.StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds());

KX_CullingNodeList nodes;
scene->CalculateVisibleMeshes(nodes, cullingcam, 0);
std::vector<KX_GameObject *> objects;
scene->CalculateVisibleMeshes(objects, cullingcam, 0);

// update levels of detail
scene->UpdateObjectLods(cullingcam, nodes);
scene->UpdateObjectLods(cullingcam, objects);

m_logger.StartLog(tc_animations, m_kxsystem->GetTimeInSeconds());
UpdateAnimations(scene);
Expand All @@ -1038,7 +1038,7 @@ void KX_KetsjiEngine::RenderCamera(KX_Scene *scene, const CameraRenderData& came

RAS_DebugDraw& debugDraw = m_rasterizer->GetDebugDraw(scene);
// Draw debug infos like bouding box, armature ect.. if enabled.
scene->DrawDebug(debugDraw, nodes);
scene->DrawDebug(debugDraw, objects);
// Draw debug camera frustum.
DrawDebugCameraFrustum(scene, debugDraw, cameraFrameData);
DrawDebugShadowFrustum(scene, debugDraw);
Expand All @@ -1049,7 +1049,7 @@ void KX_KetsjiEngine::RenderCamera(KX_Scene *scene, const CameraRenderData& came
scene->RunDrawingCallbacks(KX_Scene::PRE_DRAW, rendercam);
#endif

scene->RenderBuckets(nodes, m_rasterizer->GetDrawingMode(), rendercam->GetWorldToCamera(), m_rasterizer, offScreen);
scene->RenderBuckets(objects, m_rasterizer->GetDrawingMode(), rendercam->GetWorldToCamera(), m_rasterizer, offScreen);

if (scene->GetPhysicsEnvironment())
scene->GetPhysicsEnvironment()->DebugDrawWorld();
Expand Down
33 changes: 16 additions & 17 deletions source/gameengine/Ketsji/KX_Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,24 +1118,23 @@ void KX_Scene::PhysicsCullingCallback(KX_ClientObjectInfo *objectInfo, void *cul

// make object visible
gameobj->SetCulled(false);
info->m_nodes.push_back(gameobj->GetCullingNode());
info->m_objects.push_back(gameobj);
}

void KX_Scene::CalculateVisibleMeshes(KX_CullingNodeList& nodes, KX_Camera *cam, int layer)
void KX_Scene::CalculateVisibleMeshes(std::vector<KX_GameObject *>& objects, KX_Camera *cam, int layer)
{
if (!cam->GetFrustumCulling()) {
for (KX_GameObject *gameobj : m_objectlist) {
KX_CullingNode *node = gameobj->GetCullingNode();
nodes.push_back(gameobj->GetCullingNode());
node->SetCulled(false);
gameobj->GetCullingNode()->SetCulled(false);
objects.push_back(gameobj);
}
return;
}

CalculateVisibleMeshes(nodes, cam->GetFrustum(), layer);
CalculateVisibleMeshes(objects, cam->GetFrustum(), layer);
}

void KX_Scene::CalculateVisibleMeshes(KX_CullingNodeList& nodes, const SG_Frustum& frustum, int layer)
void KX_Scene::CalculateVisibleMeshes(std::vector<KX_GameObject *>& objects, const SG_Frustum& frustum, int layer)
{
m_boundingBoxManager->Update(false);

Expand All @@ -1162,12 +1161,12 @@ void KX_Scene::CalculateVisibleMeshes(KX_CullingNodeList& nodes, const SG_Frustu
const std::array<MT_Vector4, 6>& planes = frustum.GetPlanes();
const MT_Matrix4x4& matrix = frustum.GetMatrix();
const int *viewport = KX_GetActiveEngine()->GetCanvas()->GetViewPort();
CullingInfo info(layer, nodes);
CullingInfo info(layer, objects);

dbvt_culling = m_physicsEnvironment->CullingTest(PhysicsCullingCallback, &info, planes, m_dbvt_occlusion_res, viewport, matrix);
}
if (!dbvt_culling) {
KX_CullingHandler handler(nodes, frustum);
KX_CullingHandler handler(objects, frustum);
for (KX_GameObject *gameobj : m_objectlist) {
if (gameobj->UseCulling() && gameobj->GetVisible() && (layer == 0 || gameobj->GetLayer() & layer)) {
if (gameobj->GetDeformer()) {
Expand All @@ -1180,15 +1179,15 @@ void KX_Scene::CalculateVisibleMeshes(KX_CullingNodeList& nodes, const SG_Frustu
// Update the object bounding volume box.
gameobj->UpdateBounds(false);

handler.Process(gameobj->GetCullingNode());
handler.Process(gameobj);
}
}
}

m_boundingBoxManager->ClearModified();
}

void KX_Scene::DrawDebug(RAS_DebugDraw& debugDraw, const KX_CullingNodeList& nodes)
void KX_Scene::DrawDebug(RAS_DebugDraw& debugDraw, const std::vector<KX_GameObject *>& objects)
{
const KX_DebugOption showBoundingBox = KX_GetActiveEngine()->GetShowBoundingBox();
if (showBoundingBox != KX_DebugOption::DISABLE) {
Expand Down Expand Up @@ -1440,13 +1439,13 @@ RAS_MaterialBucket* KX_Scene::FindBucket(class RAS_IPolyMaterial* polymat, bool



void KX_Scene::RenderBuckets(const KX_CullingNodeList& nodes, RAS_Rasterizer::DrawType drawingMode, const MT_Transform& cameratransform,
void KX_Scene::RenderBuckets(const std::vector<KX_GameObject *>& objects, RAS_Rasterizer::DrawType drawingMode, const MT_Transform& cameratransform,
RAS_Rasterizer *rasty, RAS_OffScreen *offScreen)
{
for (KX_CullingNode *node : nodes) {
for (KX_GameObject *gameobj : objects) {
/* This function update all mesh slot info (e.g culling, color, matrix) from the game object.
* It's done just before the render to be sure of the object color and visibility. */
node->GetObject()->UpdateBuckets();
gameobj->UpdateBuckets();
}

m_bucketmanager->Renderbuckets(drawingMode, cameratransform, rasty, offScreen);
Expand All @@ -1459,13 +1458,13 @@ void KX_Scene::RenderTextureRenderers(KX_TextureRendererManager::RendererCategor
m_rendererManager->Render(category, rasty, offScreen, camera, viewport, area);
}

void KX_Scene::UpdateObjectLods(KX_Camera *cam, const KX_CullingNodeList& nodes)
void KX_Scene::UpdateObjectLods(KX_Camera *cam, const std::vector<KX_GameObject *>& objects)
{
const MT_Vector3& cam_pos = cam->NodeGetWorldPosition();
const float lodfactor = cam->GetLodDistanceFactor();

for (KX_CullingNode *node : nodes) {
node->GetObject()->UpdateLod(cam_pos, lodfactor);
for (KX_GameObject *gameobj : objects) {
gameobj->UpdateLod(cam_pos, lodfactor);
}
}

Expand Down
Loading

0 comments on commit 5577969

Please sign in to comment.