SBSPSS/source/system/gstate.cpp

198 lines
4.8 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-12-20 23:46:12 +01:00
#ifndef __MEMORY_HEADER__
#include "mem\memory.h"
#endif
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-07-25 21:34:06 +02:00
#ifndef __PAD_PADS_H__
#include "pad\pads.h"
#endif
#ifndef __PAD_VIBE_H__
#include "pad\vibe.h"
#endif
2000-12-20 23:46:12 +01:00
/*****************************************************************************/
// Use click counter or vbl counter
2000-12-21 16:50:53 +01:00
//#define USE_CLICK_COUNTER
2000-12-20 23:46:12 +01:00
#ifdef USE_CLICK_COUNTER
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
#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;
2000-12-20 23:46:12 +01:00
#ifdef USE_CLICK_COUNTER
2000-10-05 16:16:09 +02:00
static CClickCount s_clickCounter;
2000-12-20 23:46:12 +01:00
#endif
int GameState::s_framesSinceLast=1;
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
{
2001-01-05 22:33:06 +01:00
SYSTEM_DBGMSG("GameState: Closing down scene '%s'..",s_currentScene->getSceneName());
2000-11-24 22:08:03 +01:00
#ifdef __VERSION_DEBUG__
int gain;
gain=MainRam.RamUsed-s_baseSceneMemory;
if(gain)
{
2001-01-05 22:33:06 +01:00
SYSTEM_DBGMSG("Scene '%s' allocated an extra %d bytes after init()",s_currentScene->getSceneName(),gain);
2000-11-24 22:08:03 +01:00
}
#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();
2001-07-25 21:34:06 +02:00
CPadVibrationManager::stopAllVibration();
PadUpdate();
2000-11-24 22:08:03 +01:00
#ifdef __VERSION_DEBUG__
int loss;
loss=MainRam.RamUsed-s_baseMemory;
if(loss)
{
2001-01-05 22:33:06 +01:00
SYSTEM_DBGMSG("MEMORY HAS CHANGED BY %d BYTES DURING SCENE '%s'!",loss,s_currentScene->getSceneName());
2001-05-25 19:01:49 +02:00
ASSERT(!"MEMORY CHANGED!");
2000-11-24 22:08:03 +01:00
s_baseMemory=0;
}
#endif
2001-01-05 22:33:06 +01:00
s_currentScene=NULL;
2000-10-26 18:50:54 +02:00
}
}
if(!s_currentScene)
{
2001-01-05 22:33:06 +01:00
s_currentScene=s_pendingScene;
2000-11-24 22:08:03 +01:00
#ifdef __VERSION_DEBUG__
if(s_baseMemory==0)
{
s_baseMemory=MainRam.RamUsed;
}
2001-01-05 22:33:06 +01:00
SYSTEM_DBGMSG("GameState: Opening new scene '%s' ( with %d bytes used )",s_currentScene->getSceneName(),s_baseMemory);
2000-11-24 22:08:03 +01:00
#endif
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;
2001-01-05 22:33:06 +01:00
SYSTEM_DBGMSG("GameState: Scene '%s' has used %d bytes during init()",s_currentScene->getSceneName(),s_baseSceneMemory-s_baseMemory);
2000-11-24 22:08:03 +01:00
#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
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-07-13 17:42:58 +02:00
// Define this to make the game go to the scene selecter after every scene
//#define _ALWAYS_GO_BACK_TO_THE_SCENE_SELECTER_
#ifdef _ALWAYS_GO_BACK_TO_THE_SCENE_SELECTER_
#include "paul\scenesel.h"
#endif
2000-08-29 21:54:22 +02:00
void GameState::setNextScene( CScene *_nextScene )
{
ASSERT(!s_pendingScene);
2001-07-13 17:42:58 +02:00
#ifdef _ALWAYS_GO_BACK_TO_THE_SCENE_SELECTER_
if(s_currentScene!=&SceneSelector)
{
_nextScene=&SceneSelector;
}
#endif
2000-08-29 21:54:22 +02:00
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
/*****************************************************************************/
void GameState::updateTimer()
{
2000-12-20 23:46:12 +01:00
#ifdef USE_CLICK_COUNTER
s_framesSinceLast=(s_clickCounter.timeSinceLast()>>12)/4+1;
#else
s_framesSinceLast=VidGetVblsThisFrame();
#endif
2000-08-29 21:54:22 +02:00
}
/*===========================================================================
end */