SBSPSS/source/system/gstate.cpp

162 lines
3.9 KiB
C++
Raw Normal View History

2000-08-29 21:54:22 +02:00
/*=========================================================================
gstate.cpp
Author: PKG
Created:
Project: PRLSR
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#include "system\global.h"
#include "system\gstate.h"
2000-10-05 16:16:09 +02:00
#ifndef __SYSTEM_CLICKCOUNT_H__
#include "system\clickcount.h"
#endif
2000-11-24 22:08:03 +01:00
#ifndef __MEMORY_HEADER__
#include "mem\memory.h"
#endif
2000-10-05 16:16:09 +02:00
2000-08-29 21:54:22 +02:00
/*****************************************************************************/
static CScene *s_currentScene;
static CScene *s_pendingScene;
int GameState::s_timeSinceLast;
2000-10-05 16:16:09 +02:00
static CClickCount s_clickCounter;
2000-08-29 21:54:22 +02:00
2000-11-24 22:08:03 +01:00
#ifdef __VERSION_DEBUG__
static int s_baseMemory=0;
static int s_baseSceneMemory=0;
#endif
2000-08-29 21:54:22 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void GameState::initialise()
{
s_currentScene=NULL;
s_pendingScene=NULL;
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void GameState::think()
{
updateTimer();
2000-10-26 18:50:54 +02:00
if(s_pendingScene)
{
if(s_currentScene)
2000-08-29 21:54:22 +02:00
{
2000-10-26 18:50:54 +02:00
if(s_currentScene->readyToShutdown())
2000-08-29 21:54:22 +02:00
{
2000-11-24 21:33:35 +01:00
SYSTEM_DBGMSG("GameState: Closing down scene..");
2000-11-24 22:08:03 +01:00
#ifdef __VERSION_DEBUG__
int gain;
gain=MainRam.RamUsed-s_baseSceneMemory;
if(gain)
{
SYSTEM_DBGMSG("Scene allocated an extra %d bytes after init()",gain);
}
#endif
2000-10-26 18:50:54 +02:00
ASSERT(s_pendingScene); // There really should be a scene pending before you shutdown..!
2000-09-12 01:41:29 +02:00
s_currentScene->shutdown();
2000-10-26 18:50:54 +02:00
s_currentScene=NULL;
2000-11-24 22:08:03 +01:00
#ifdef __VERSION_DEBUG__
int loss;
loss=MainRam.RamUsed-s_baseMemory;
if(loss)
{
SYSTEM_DBGMSG("MEMORY HAS CHANGED BY %d BYTES DURING SCENE!",loss);
ASSERT(0);
s_baseMemory=0;
}
#endif
2000-10-26 18:50:54 +02:00
}
}
if(!s_currentScene)
{
2000-11-24 22:08:03 +01:00
#ifdef __VERSION_DEBUG__
if(s_baseMemory==0)
{
s_baseMemory=MainRam.RamUsed;
}
SYSTEM_DBGMSG("GameState: Opening new scene ( with %d bytes used )",s_baseMemory);
#endif
2000-08-29 21:54:22 +02:00
s_currentScene=s_pendingScene;
2000-09-12 01:41:29 +02:00
s_currentScene->init();
2000-11-24 22:08:03 +01:00
#ifdef __VERSION_DEBUG__
s_baseSceneMemory=MainRam.RamUsed;
SYSTEM_DBGMSG("GameState: Scene has used %d bytes during init()",s_baseSceneMemory-s_baseMemory);
#endif
2000-10-26 18:50:54 +02:00
s_pendingScene=NULL;
2000-08-29 21:54:22 +02:00
}
2000-10-26 18:50:54 +02:00
}
2000-08-29 21:54:22 +02:00
ASSERT(s_currentScene);
2000-10-19 17:40:24 +02:00
s_currentScene->think(getFramesSinceLast());
2000-08-29 21:54:22 +02:00
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void GameState::render()
{
ASSERT(s_currentScene);
2000-09-12 01:41:29 +02:00
s_currentScene->render();
2000-08-29 21:54:22 +02:00
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void GameState::setNextScene( CScene *_nextScene )
{
ASSERT(!s_pendingScene);
s_pendingScene=_nextScene;
}
2000-10-26 16:57:09 +02:00
2000-08-29 21:54:22 +02:00
/*****************************************************************************/
CScene * GameState::getCurrentScene()
{
return s_currentScene;
}
2000-10-26 16:57:09 +02:00
/*****************************************************************************/
CScene * GameState::getPendingScene()
{
return s_pendingScene;
}
2000-08-29 21:54:22 +02:00
/*****************************************************************************/
2000-10-05 16:16:09 +02:00
static int s_timeSpeed = ONE;
2000-08-29 21:54:22 +02:00
void GameState::updateTimer()
{
2000-10-05 16:16:09 +02:00
s_timeSinceLast = (s_clickCounter.timeSinceLast() * s_timeSpeed) >> 12;
if (s_timeSinceLast > 4 * 4096)
{
s_timeSinceLast = 4 * 4096;
2000-10-18 20:36:52 +02:00
SYSTEM_DBGMSG("updateTimer loosing frames!");
2000-10-05 16:16:09 +02:00
}
2000-08-29 21:54:22 +02:00
}
/*===========================================================================
end */