Compute camera ghost mode on demand - simplifies code as each object doesn't propagate ghost mode to its render objects.

colobot2
immibis 2023-11-18 14:01:02 +01:00
parent 72ca4f2d7c
commit ab3c22dce3
8 changed files with 36 additions and 78 deletions

View File

@ -54,23 +54,6 @@ namespace Gfx
const float MOUSE_EDGE_MARGIN = 0.01f;
//! Changes the level of transparency of an object and objects transported (battery & cargo)
static void SetGhostMode(CObject* obj, bool enabled)
{
obj->SetGhostMode(enabled);
if (obj->Implements(ObjectInterfaceType::Slotted))
{
CSlottedObject *slotted = dynamic_cast<CSlottedObject*>(obj);
for(int slot = slotted->GetNumSlots()-1; slot >= 0; slot--)
{
CObject *contained = slotted->GetSlotContainedObject(slot);
if (contained != nullptr)
contained->SetGhostMode(enabled);
}
}
}
CCamera::CCamera()
@ -257,10 +240,7 @@ void CCamera::SetType(CameraType type)
{
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
{
if (IsObjectBeingTransported(obj))
continue;
SetGhostMode(obj, false); // opaque object
obj->m_bCameraGhost = false; // opaque object
}
}
@ -837,7 +817,7 @@ void CCamera::IsCollisionBack()
if (IsObjectBeingTransported(obj))
continue;
SetGhostMode(obj, false); // opaque object
obj->m_bCameraGhost = false; // opaque object
if (obj == m_cameraObj) continue;
@ -897,7 +877,7 @@ void CCamera::IsCollisionBack()
float len = glm::distance(m_actualEye, proj);
if (len > del) continue;
SetGhostMode(obj, true); // ghost mode
obj->m_bCameraGhost = true; // ghost mode
}
}

View File

@ -57,6 +57,11 @@
#include "math/geometry.h"
#include "object/object.h"
#include "object/old_object.h"
#include "object/interface/transportable_object.h"
#include "sound/sound.h"
#include "ui/controls/interface.h"
@ -825,7 +830,7 @@ void CEngine::DebugObject(int objRank)
l->Debug(" type = %d\n", m_objects[objRank].type);
l->Debug(" distance = %f\n", m_objects[objRank].distance);
l->Debug(" shadowRank = %d\n", m_objects[objRank].shadowRank);
l->Debug(" ghost = %s\n", m_objects[objRank].ghost ? "true" : "false");
l->Debug(" gameObject = %p\n", m_objects[objRank].gameObject);
l->Debug(" baseObj:\n");
int baseObjRank = m_objects[objRank].baseObjRank;
@ -989,13 +994,6 @@ void CEngine::SetObjectDrawFront(int objRank, bool draw)
m_objects[objRank].drawFront = draw;
}
void CEngine::SetObjectGhostMode(int objRank, bool enabled)
{
assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
m_objects[objRank].ghost = enabled;
}
void CEngine::GetObjectBBox(int objRank, glm::vec3& min, glm::vec3& max)
{
assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
@ -2790,6 +2788,27 @@ void CEngine::Render()
m_device->EndScene();
}
bool CEngine::IsGhostObject(int objRank)
{
CObject *gameObject = m_objects[objRank].gameObject;
if (!gameObject)
return false; // terrain
if (gameObject->GetType() == OBJECT_BASE && objRank != dynamic_cast<COldObject&>(*gameObject).GetObjectRank(9))
return false; // Special case: only part 9 (the central pillar) of the spaceship turns translucent
while (gameObject->Implements(ObjectInterfaceType::Transportable))
{
CObject *transporter = dynamic_cast<CTransportableObject&>(*gameObject).GetTransporter();
if (transporter)
gameObject = transporter;
else
break;
}
return gameObject->m_bCameraGhost;
}
void CEngine::Draw3DScene()
{
if (!m_worldCaptured)
@ -2968,7 +2987,7 @@ void CEngine::Draw3DScene()
for (auto& data : p1.next)
{
if (m_objects[objRank].ghost) // transparent ?
if (IsGhostObject(objRank)) // transparent ?
{
transparent = true;
continue;
@ -3050,7 +3069,7 @@ void CEngine::Draw3DScene()
if (! m_objects[objRank].drawWorld)
continue;
if (!m_objects[objRank].ghost)
if (!IsGhostObject(objRank))
continue;
auto combinedMatrix = projectionViewMatrix * m_objects[objRank].transform;
@ -4943,12 +4962,6 @@ const glm::mat4& CEngine::GetStaticMeshWorldMatrix(int meshHandle)
return m_objects[objRank].transform;
}
void CEngine::SetStaticMeshGhostMode(int meshHandle, bool enabled)
{
int objRank = meshHandle;
SetObjectGhostMode(objRank, enabled);
}
void CEngine::SetDebugLights(bool debugLights)
{
m_debugLights = debugLights;

View File

@ -137,8 +137,6 @@ struct EngineObject
float distance = 0.0f;
//! Rank of the associated shadow
int shadowRank = -1;
//! Ghost mode
bool ghost = false;
//! Team
int team = 0;
//! Associated game object, if any. Null for terrain.
@ -544,9 +542,6 @@ public:
//! Returns static mesh world matrix
const glm::mat4& GetStaticMeshWorldMatrix(int meshHandle);
//! Sets transparency for static mesh
void SetStaticMeshGhostMode(int meshHandle, bool enabled);
/* *************** Object management *************** */
@ -603,8 +598,8 @@ public:
//! Sets drawFront for given object
void SetObjectDrawFront(int objRank, bool draw);
//! Sets the transparency level for given object
void SetObjectGhostMode(int objRank, bool enabled);
//! Check if object is transparent to prevent blocking the camera view
bool IsGhostObject(int objRank);
//! Sets team for given object
void SetObjectTeam(int objRank, int team);

View File

@ -162,8 +162,8 @@ public:
// TODO: remove from here once no longer necessary
void SetCameraCollisionSphere(const Math::Sphere& sphere);
//! Sets object's ghost mode
virtual void SetGhostMode(bool enabled) = 0;
//! Is the object translucent to prevent blocking the camera view?
bool m_bCameraGhost = false;
//! Sets flag controlling animation effect on level reset
void SetAnimateOnReset(bool animateOnReset);

View File

@ -2662,27 +2662,6 @@ float COldObject::GetReactorRange()
}
// Management of transparency of the object.
void COldObject::SetGhostMode(bool enabled)
{
int i;
for ( i=0 ; i<m_totalPart ; i++ )
{
if ( m_objectPart[i].bUsed )
{
if ( m_type == OBJECT_BASE )
{
if ( i != 9 ) continue; // no central pillar?
}
m_engine->SetObjectGhostMode(m_objectPart[i].object, enabled);
}
}
}
// Pushes an object.
bool COldObject::JostleObject(float force)

View File

@ -206,8 +206,6 @@ public:
void SetReactorRange(float reactorRange) override;
float GetReactorRange() override;
void SetGhostMode(bool enabled) override;
Math::Sphere GetJostlingSphere() const override;
bool JostleObject(float force) override;

View File

@ -103,11 +103,6 @@ void CStaticObject::TransformCameraCollisionSphere(Math::Sphere& collisionSphere
Math::Transform(worldMatrix, collisionSphere.pos);
}
void CStaticObject::SetGhostMode(bool enabled)
{
m_engine->SetStaticMeshGhostMode(m_meshHandle, enabled);
}
bool CStaticObject::IsStaticObject(ObjectType type)
{
return m_staticModelNames.count(type) > 0;

View File

@ -53,8 +53,6 @@ public:
void Read(CLevelParserLine* line) override;
void Write(CLevelParserLine* line) override;
void SetGhostMode(bool enabled) override;
public:
static bool IsStaticObject(ObjectType type);