Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Core/GameEngine/Include/Common/GameUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
// For miscellaneous game utility functions.

class Player;
typedef Int PlayerIndex;

namespace rts
{

Bool localPlayerIsObserving();
Player* getObservedOrLocalPlayer(); ///< Get the current observed or local player. Is never null.
Player* getObservedOrLocalPlayer_Safe(); ///< Get the current observed or local player. Is never null, except when the application does not have players.
PlayerIndex getObservedOrLocalPlayerIndex_Safe(); ///< Get the current observed or local player index. Returns 0 when the application does not have players.

void changeLocalPlayer(Player* player); //< Change local player during game
void changeObservedPlayer(Player* player); ///< Change observed player during game
Expand Down
26 changes: 26 additions & 0 deletions Core/GameEngine/Source/Common/GameUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,38 @@ Bool localPlayerIsObserving()

Player* getObservedOrLocalPlayer()
{
DEBUG_ASSERTCRASH(TheControlBar != NULL, ("TheControlBar is NULL"));
Player* player = TheControlBar->getObservedPlayer();
if (player == NULL)
{
DEBUG_ASSERTCRASH(ThePlayerList != NULL, ("ThePlayerList is NULL"));
player = ThePlayerList->getLocalPlayer();
}
return player;
Comment thread
Skyaero42 marked this conversation as resolved.
}

Player* getObservedOrLocalPlayer_Safe()
Comment thread
Skyaero42 marked this conversation as resolved.
{
Player* player = NULL;

if (TheControlBar != NULL)
player = TheControlBar->getObservedPlayer();

if (player == NULL)
if (ThePlayerList != NULL)
player = ThePlayerList->getLocalPlayer();

return player;
}

PlayerIndex getObservedOrLocalPlayerIndex_Safe()
{
if (Player* player = getObservedOrLocalPlayer_Safe())
return player->getPlayerIndex();

return 0;
Comment thread
Skyaero42 marked this conversation as resolved.
}

void changeLocalPlayer(Player* player)
{
ThePlayerList->setLocalPlayer(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ void RTS3DScene::renderSpecificDrawables(RenderInfoClass &rinfo, Int numDrawable
#ifdef DIRTY_CONDITION_FLAGS
StDrawableDirtyStuffLocker lockDirtyStuff;
#endif
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();
RefRenderObjListIterator it(&UpdateList);
// loop through all render objects in the list:
for (it.First(&RenderList); !it.Is_Done();)
Expand Down Expand Up @@ -1041,7 +1041,7 @@ void RTS3DScene::Customized_Render( RenderInfoClass &rinfo )
m_translucentObjectsCount = 0; //start of new frame so no translucent objects
m_occludedObjectsCount = 0;

const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();

#define USE_LIGHT_ENV 1

Expand Down Expand Up @@ -1292,7 +1292,7 @@ void RTS3DScene::flushOccludedObjectsIntoStencil(RenderInfoClass & rinfo)
//Assume no player colors are visible and all stencil bits are free for use by shadows.
TheW3DShadowManager->setStencilShadowMask(0);

const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();

if (m_numPotentialOccludees && m_numPotentialOccluders)
{
Expand Down Expand Up @@ -1470,7 +1470,7 @@ void RTS3DScene::flushOccludedObjects(RenderInfoClass & rinfo)

if (m_occludedObjectsCount)
{
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();

if (DX8Wrapper::Has_Stencil()) //just in case we have shadows, disable them over occluded pixels.
{
Expand Down Expand Up @@ -1540,7 +1540,7 @@ void RTS3DScene::flushTranslucentObjects(RenderInfoClass & rinfo)

if (m_translucentObjectsCount)
{
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();

for (Int i=0; i<m_translucentObjectsCount; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ static void drawablePostDraw( Drawable *draw, void *userData )
return;

Object* obj = draw->getObject();
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();
#if ENABLE_CONFIGURABLE_SHROUD
ObjectShroudStatus ss = (!obj || !TheGlobalData->m_shroudOn) ? OBJECTSHROUD_CLEAR : obj->getShroudedStatus(localPlayerIndex);
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void W3DPropBuffer::drawProps(RenderInfoClass &rinfo)
m_props[i].ss = OBJECTSHROUD_CLEAR;
}
if (m_props[i].ss == OBJECTSHROUD_INVALID) {
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();
m_props[i].ss = ThePartitionManager->getPropShroudStatusForPlayer(localPlayerIndex, &m_props[i].location);
}
if (m_props[i].ss >= OBJECTSHROUD_SHROUDED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ void RTS3DScene::renderSpecificDrawables(RenderInfoClass &rinfo, Int numDrawable
#ifdef DIRTY_CONDITION_FLAGS
StDrawableDirtyStuffLocker lockDirtyStuff;
#endif
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();
RefRenderObjListIterator it(&UpdateList);
// loop through all render objects in the list:
for (it.First(&RenderList); !it.Is_Done();)
Expand Down Expand Up @@ -1089,7 +1089,7 @@ void RTS3DScene::Customized_Render( RenderInfoClass &rinfo )
m_translucentObjectsCount = 0; //start of new frame so no translucent objects
m_occludedObjectsCount = 0;

const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();

#define USE_LIGHT_ENV 1

Expand Down Expand Up @@ -1339,7 +1339,7 @@ void RTS3DScene::flushOccludedObjectsIntoStencil(RenderInfoClass & rinfo)
//Assume no player colors are visible and all stencil bits are free for use by shadows.
TheW3DShadowManager->setStencilShadowMask(0);

const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();

if (m_numPotentialOccludees && m_numPotentialOccluders)
{
Expand Down Expand Up @@ -1533,7 +1533,7 @@ void RTS3DScene::flushOccludedObjects(RenderInfoClass & rinfo)

if (m_occludedObjectsCount)
{
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();

if (DX8Wrapper::Has_Stencil()) //just in case we have shadows, disable them over occluded pixels.
{
Expand Down Expand Up @@ -1603,7 +1603,7 @@ void RTS3DScene::flushTranslucentObjects(RenderInfoClass & rinfo)

if (m_translucentObjectsCount)
{
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();

for (Int i=0; i<m_translucentObjectsCount; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,7 @@ void W3DTreeBuffer::updateTopplingTree(TTree *tree, Real timeScale)
return;

const W3DTreeDrawModuleData* d = m_treeTypes[tree->treeType].m_data;
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();
Coord3D pos;
pos.set(tree->location.X, tree->location.Y, tree->location.Z);
ObjectShroudStatus ss = ThePartitionManager->getPropShroudStatusForPlayer(localPlayerIndex, &pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ static void drawablePostDraw( Drawable *draw, void *userData )
return;

Object* obj = draw->getObject();
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();
#if ENABLE_CONFIGURABLE_SHROUD
ObjectShroudStatus ss = (!obj || !TheGlobalData->m_shroudOn) ? OBJECTSHROUD_CLEAR : obj->getShroudedStatus(localPlayerIndex);
#else
Expand Down
Loading