Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,500 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#include "hpl1/engine/game/Game.h"
#include "hpl1/engine/game/ScriptFuncs.h"
#include "hpl1/engine/game/Updater.h"
#include "hpl1/engine/graphics/Graphics.h"
#include "hpl1/engine/graphics/LowLevelGraphics.h"
#include "hpl1/engine/graphics/Renderer3D.h"
#include "hpl1/engine/input/Input.h"
#include "hpl1/engine/input/Mouse.h"
#include "hpl1/engine/resources/Resources.h"
#include "hpl1/engine/system/LogicTimer.h"
#include "hpl1/engine/system/String.h"
#include "hpl1/engine/system/System.h"
#include "hpl1/engine/gui/Gui.h"
#include "hpl1/engine/game/low_level_game_setup.h"
#include "hpl1/engine/system/low_level_system.h"
#include "common/events.h"
#include "hpl1/hpl1.h"
namespace hpl {
//////////////////////////////////////////////////////////////////////////
// FPS COUNTER
//////////////////////////////////////////////////////////////////////////
cFPSCounter::cFPSCounter(LowLevelSystem *apLowLevelSystem) {
mfFPS = 60;
mlFramecounter = 0;
mfFrametimestart = 0;
mfFrametime = 0;
mfUpdateRate = 1;
mpLowLevelSystem = apLowLevelSystem;
mfFrametimestart = ((float)GetApplicationTime()) / 1000.0f;
}
void cFPSCounter::AddFrame() {
mlFramecounter++;
mfFrametime = (((float)GetApplicationTime()) / 1000.0f) - mfFrametimestart;
// update the timer
if (mfFrametime >= mfUpdateRate) {
mfFPS = ((float)mlFramecounter) / mfFrametime;
mlFramecounter = 0;
mfFrametimestart = ((float)GetApplicationTime()) / 1000.0f;
}
}
//////////////////////////////////////////////////////////////////////////
// SETUP VAR CONTAINER
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
cSetupVarContainer::cSetupVarContainer() {
msBlank = "";
}
//-----------------------------------------------------------------------
void cSetupVarContainer::AddString(const tString &asName, const tString &asValue) {
Common::StableMap<tString, tString>::value_type val(asName, asValue);
m_mapVars.insert(val);
}
void cSetupVarContainer::AddInt(const tString &asName, int alValue) {
AddString(asName, cString::ToString(alValue));
}
void cSetupVarContainer::AddFloat(const tString &asName, float afValue) {
AddString(asName, cString::ToString(afValue));
}
void cSetupVarContainer::AddBool(const tString &asName, bool abValue) {
AddString(asName, abValue ? "true" : "false");
}
//-----------------------------------------------------------------------
const tString &cSetupVarContainer::GetString(const tString &asName) {
Common::StableMap<tString, tString>::iterator it = m_mapVars.find(asName);
if (it == m_mapVars.end())
return msBlank;
else
return it->second;
}
float cSetupVarContainer::GetFloat(const tString &asName, float afDefault) {
const tString &sVal = GetString(asName);
if (sVal == "")
return afDefault;
else
return cString::ToFloat(sVal.c_str(), afDefault);
}
int cSetupVarContainer::GetInt(const tString &asName, int alDefault) {
const tString &sVal = GetString(asName);
if (sVal == "")
return alDefault;
else
return cString::ToInt(sVal.c_str(), alDefault);
}
bool cSetupVarContainer::GetBool(const tString &asName, bool abDefault) {
const tString &sVal = GetString(asName);
if (sVal == "")
return abDefault;
else
return cString::ToBool(sVal.c_str(), abDefault);
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
cGame::cGame(LowLevelGameSetup *apGameSetup, cSetupVarContainer &aVars) {
GameInit(apGameSetup, aVars);
}
//-----------------------------------------------------------------------
cGame::cGame(LowLevelGameSetup *apGameSetup, int alWidth, int alHeight, int alBpp, bool abFullscreen,
unsigned int alUpdateRate, int alMultisampling) {
cSetupVarContainer Vars;
Vars.AddInt("ScreenWidth", alWidth);
Vars.AddInt("ScreenHeight", alHeight);
Vars.AddInt("ScreenBpp", alBpp);
Vars.AddBool("Fullscreen", abFullscreen);
Vars.AddInt("Multisampling", alMultisampling);
Vars.AddInt("LogicUpdateRate", alUpdateRate);
GameInit(apGameSetup, Vars);
}
//-----------------------------------------------------------------------
void cGame::GameInit(LowLevelGameSetup *apGameSetup, cSetupVarContainer &aVars) {
mpGameSetup = apGameSetup;
Log("Creating Engine Modules\n");
Log("--------------------------------------------------------\n");
// Create the modules that game connects to and init them!
Log(" Creating graphics module\n");
mpGraphics = mpGameSetup->createGraphics();
Log(" Creating system module\n");
mpSystem = mpGameSetup->createSystem();
Log(" Creating resource module\n");
mpResources = mpGameSetup->createResources(mpGraphics);
Log(" Creating input module\n");
mpInput = mpGameSetup->createInput(mpGraphics);
Log(" Creating sound module\n");
mpSound = mpGameSetup->createSound();
Log(" Creating physics module\n");
mpPhysics = mpGameSetup->createPhysics();
Log(" Creating ai module\n");
mpAI = mpGameSetup->createAi();
Log(" Creating gui module\n");
mpGui = hplNew(cGui, ());
Log(" Creating scene module\n");
mpScene = mpGameSetup->createScene(mpGraphics, mpResources, mpSound, mpPhysics, mpSystem, mpAI);
Log("--------------------------------------------------------\n\n");
// Init the resources
mpResources->Init(mpGraphics, mpSystem, mpSound, mpScene, mpGui);
// Init the graphics
mpGraphics->Init(aVars.GetInt("ScreenWidth", 800),
aVars.GetInt("ScreenHeight", 600),
aVars.GetInt("ScreenBpp", 32),
aVars.GetBool("Fullscreen", false),
aVars.GetInt("Multisampling", 0),
aVars.GetString("WindowCaption"),
mpResources);
// Init Sound
mpSound->Init(mpResources, aVars.GetBool("UseSoundHardware", true),
aVars.GetBool("ForceGeneric", false),
aVars.GetBool("UseEnvironmentalAudio", false),
aVars.GetInt("MaxSoundChannels", 32),
aVars.GetInt("StreamUpdateFreq", 10),
aVars.GetBool("UseSoundThreading", true),
aVars.GetBool("UseVoiceManagement", true),
aVars.GetInt("MaxMonoChannelsHint", 0),
aVars.GetInt("MaxStereoChannelsHint", 0),
aVars.GetInt("StreamBufferSize", 4096),
aVars.GetInt("StreamBufferCount", 8),
aVars.GetBool("LowLevelSoundLogging", false),
aVars.GetString("DeviceName"));
// Init physics
mpPhysics->Init(mpResources);
// Init AI
mpAI->Init();
// Init Gui
mpGui->Init(mpResources, mpGraphics, mpSound, mpScene);
Log("Initializing Game Module\n");
Log("--------------------------------------------------------\n");
// Create the updatehandler
Log(" Adding engine updates\n");
mpUpdater = hplNew(cUpdater, (mpSystem->GetLowLevel()));
// Add some loaded modules to the updater
mpUpdater->AddGlobalUpdate(mpInput);
mpUpdater->AddGlobalUpdate(mpPhysics);
mpUpdater->AddGlobalUpdate(mpScene);
mpUpdater->AddGlobalUpdate(mpSound);
mpUpdater->AddGlobalUpdate(mpAI);
mpUpdater->AddGlobalUpdate(mpGui);
mpUpdater->AddGlobalUpdate(mpResources);
// Setup the "default" updater container
mpUpdater->AddContainer("Default");
mpUpdater->SetContainer("Default");
// Create the logic timer.
mpLogicTimer = mpSystem->CreateLogicTimer(aVars.GetInt("LogicUpdateRate", 800));
// Init some standard script funcs
Log(" Initializing script functions\n");
cScriptFuncs::Init(mpGraphics, mpResources, mpSystem, mpInput, mpScene, mpSound, this);
// Since game is not done:
mbGameIsDone = false;
mfUpdateTime = 0;
mfGameTime = 0;
mbLimitFPS = true;
mpFPSCounter = hplNew(cFPSCounter, (mpSystem->GetLowLevel()));
Log("--------------------------------------------------------\n\n");
Log("User Initialization\n");
Log("--------------------------------------------------------\n");
}
//-----------------------------------------------------------------------
cGame::~cGame() {
Log("--------------------------------------------------------\n\n");
hplDelete(mpLogicTimer);
hplDelete(mpFPSCounter);
hplDelete(mpUpdater);
hplDelete(mpGui);
hplDelete(mpScene);
hplDelete(mpInput);
hplDelete(mpSound);
hplDelete(mpGraphics);
hplDelete(mpResources);
hplDelete(mpPhysics);
hplDelete(mpAI);
hplDelete(mpSystem);
Log(" Deleting game setup provided by user\n");
hplDelete(mpGameSetup);
Log("HPL Exit was successful!\n");
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// PUBLIC METHOD
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
int glClearUpdateCheck = 0;
void cGame::Run() {
double fNumOfTimes = 0;
double fMediumTime = 0;
mpUpdater->OnStart();
mpLogicTimer->Reset();
// Loop the game... fix the var...
unsigned long lTempTime = GetApplicationTime();
mfFrameTime = 0;
unsigned long lTempFrameTime = GetApplicationTime();
bool mbIsUpdated = true;
while (!mbGameIsDone && !g_engine->shouldQuit()) {
//////////////////////////
// Update logic.
while (mpLogicTimer->WantUpdate() && !mbGameIsDone) {
unsigned int lUpdateTime = GetApplicationTime();
mpUpdater->Update(GetStepSize());
unsigned int lDeltaTime = GetApplicationTime() - lUpdateTime;
mfUpdateTime = (float)(lDeltaTime) / 1000.0f;
mbIsUpdated = true;
glClearUpdateCheck++;
mfGameTime += GetStepSize();
}
mpLogicTimer->EndUpdateLoop();
// If not making a single rendering is better to use gpu and
// cpu at the same time and make query checks etc after logic update.
// If any delete has occurred in the update this might crash. so skip it for now.
/*if(mbRenderOnce==false) {
mpGraphics->GetRenderer3D()->FetchOcclusionQueries();
mpUpdater->OnPostBufferSwap();
}*/
// Draw graphics!
if (mbIsUpdated)
mpScene->UpdateRenderList(mfFrameTime);
if (mbLimitFPS == false || mbIsUpdated) {
mbIsUpdated = false;
// Get the the from the last frame.
mfFrameTime = ((float)(GetApplicationTime() - lTempFrameTime)) / 1000;
lTempFrameTime = GetApplicationTime();
// Draw this frame
// unsigned long lFTime = GetApplicationTime();
mpUpdater->OnDraw();
mpScene->Render(mpUpdater, mfFrameTime);
// Update fps counter.
mpFPSCounter->AddFrame();
// Update the screen.
mpGraphics->GetLowLevel()->SwapBuffers();
mpGraphics->GetRenderer3D()->FetchOcclusionQueries();
mpUpdater->OnPostBufferSwap();
fNumOfTimes++;
}
}
Log("--------------------------------------------------------\n\n");
Log("Statistics\n");
Log("--------------------------------------------------------\n");
unsigned long lTime = GetApplicationTime() - lTempTime;
fMediumTime = fNumOfTimes / (((double)lTime) / 1000);
Log(" Medium framerate: %f\n", fMediumTime);
Log("--------------------------------------------------------\n\n");
Log("User Exit\n");
Log("--------------------------------------------------------\n");
mpUpdater->OnExit();
}
//-----------------------------------------------------------------------
void cGame::Exit() {
mbGameIsDone = true;
}
//-----------------------------------------------------------------------
void cGame::ResetLogicTimer() {
mpLogicTimer->Reset();
}
void cGame::SetUpdatesPerSec(int alUpdatesPerSec) {
mpLogicTimer->SetUpdatesPerSec(alUpdatesPerSec);
}
int cGame::GetUpdatesPerSec() {
return mpLogicTimer->GetUpdatesPerSec();
}
float cGame::GetStepSize() {
return mpLogicTimer->GetStepSize();
}
//-----------------------------------------------------------------------
cScene *cGame::GetScene() {
return mpScene;
}
//-----------------------------------------------------------------------
cResources *cGame::GetResources() {
return mpResources;
}
//-----------------------------------------------------------------------
cGraphics *cGame::GetGraphics() {
return mpGraphics;
}
//-----------------------------------------------------------------------
cSystem *cGame::GetSystem() {
return mpSystem;
}
//-----------------------------------------------------------------------
cInput *cGame::GetInput() {
return mpInput;
}
//-----------------------------------------------------------------------
cSound *cGame::GetSound() {
return mpSound;
}
//-----------------------------------------------------------------------
cPhysics *cGame::GetPhysics() {
return mpPhysics;
}
//-----------------------------------------------------------------------
cAI *cGame::GetAI() {
return mpAI;
}
//-----------------------------------------------------------------------
cGui *cGame::GetGui() {
return mpGui;
}
//-----------------------------------------------------------------------
cUpdater *cGame::GetUpdater() {
return mpUpdater;
}
float cGame::GetFPS() {
return mpFPSCounter->mfFPS;
}
//-----------------------------------------------------------------------
void cGame::SetFPSUpdateRate(float afSec) {
mpFPSCounter->mfUpdateRate = afSec;
}
float cGame::GetFPSUpdateRate() {
return mpFPSCounter->mfUpdateRate;
}
//-----------------------------------------------------------------------
} // namespace hpl

View File

@@ -0,0 +1,221 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_GAME_H
#define HPL_GAME_H
#include "hpl1/engine/system/SystemTypes.h"
namespace hpl {
class cUpdater;
class LowLevelGameSetup;
class LowLevelSystem;
class cLogicTimer;
class cSystem;
class cInput;
class cResources;
class cGraphics;
class cScene;
class cSound;
class cPhysics;
class cAI;
class cGui;
class cFPSCounter {
public:
cFPSCounter(LowLevelSystem *apLowLevelSystem);
void AddFrame();
float mfFPS;
float mfUpdateRate;
private:
LowLevelSystem *mpLowLevelSystem;
int mlFramecounter;
float mfFrametimestart;
float mfFrametime;
};
//---------------------------------------------------
class cSetupVarContainer {
public:
cSetupVarContainer();
void AddString(const tString &asName, const tString &asValue);
void AddInt(const tString &asName, int alValue);
void AddFloat(const tString &asName, float afValue);
void AddBool(const tString &asName, bool abValue);
const tString &GetString(const tString &asName);
float GetFloat(const tString &asName, float afDefault);
int GetInt(const tString &asName, int alDefault);
bool GetBool(const tString &asName, bool abDefault);
private:
Common::StableMap<tString, tString> m_mapVars;
tString msBlank;
};
//---------------------------------------------------
class cGame {
public:
cGame(LowLevelGameSetup *apGameSetup, cSetupVarContainer &aVars);
cGame(LowLevelGameSetup *apGameSetup, int alWidth, int alHeight, int alBpp, bool abFullscreen,
unsigned int alUpdateRate = 60, int alMultisampling = 0);
~cGame();
private:
void GameInit(LowLevelGameSetup *apGameSetup, cSetupVarContainer &aVars);
public:
/**
* Starts the game loop. To make stuff run they must be added as updatables..
*/
void Run();
/**
* Exists the game.
* \todo is this a good way to do it? Should game be global. If so, make a singleton.
*/
void Exit();
/**
*
* \return A pointer to Scene
*/
cScene *GetScene();
/**
*
* \return A pointer to Resources
*/
cResources *GetResources();
/**
*
* \return A pointer to the Updater
*/
cUpdater *GetUpdater();
/**
*
* \return A pointer to the System
*/
cSystem *GetSystem();
/**
*
* \return A pointer to the Input
*/
cInput *GetInput();
/**
*
* \return A pointer to the Graphics
*/
cGraphics *GetGraphics();
/**
*
* \return A pointer to the Sound
*/
cSound *GetSound();
/**
*
* \return A pointer to the Physics
*/
cPhysics *GetPhysics();
/**
*
* \return A pointer to the AI
*/
cAI *GetAI();
/**
*
* \return A pointer to the Gui
*/
cGui *GetGui();
void ResetLogicTimer();
void SetUpdatesPerSec(int alUpdatesPerSec);
int GetUpdatesPerSec();
float GetStepSize();
cLogicTimer *GetLogicTimer() { return mpLogicTimer; }
float GetFPS();
void SetFPSUpdateRate(float afSec);
float GetFPSUpdateRate();
float GetFrameTime() { return mfFrameTime; }
float GetUpdateTime() { return mfUpdateTime; }
double GetGameTime() { return mfGameTime; }
void SetLimitFPS(bool abX) { mbLimitFPS = abX; }
bool GetLimitFPS() { return mbLimitFPS; }
private:
bool mbGameIsDone;
float mfFrameTime;
float mfUpdateTime;
double mfGameTime;
LowLevelGameSetup *mpGameSetup;
cUpdater *mpUpdater;
cLogicTimer *mpLogicTimer;
cFPSCounter *mpFPSCounter;
bool mbLimitFPS;
// Modules that Game connnect to:
cResources *mpResources;
cSystem *mpSystem;
cInput *mpInput;
cGraphics *mpGraphics;
cScene *mpScene;
cSound *mpSound;
cPhysics *mpPhysics;
cAI *mpAI;
cGui *mpGui;
};
} // namespace hpl
#endif // HPL_GAME_H

View File

@@ -0,0 +1,57 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#include "hpl1/engine/game/GameTypes.h"
#include "hpl1/engine/system/low_level_system.h"
namespace hpl {
//////////////////////////////////////////////////////////////////////////
// CONSTRCTORS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
cScriptVar::cScriptVar() {
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// SERIALIZE
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
kBeginSerializeBase(cScriptVar)
kSerializeVar(msName, eSerializeType_String)
kSerializeVar(mlVal, eSerializeType_Int32)
kEndSerialize()
//-----------------------------------------------------------------------
} // namespace hpl

View File

@@ -0,0 +1,48 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_GAME_TYPES_H
#define HPL_GAME_TYPES_H
#include "hpl1/engine/system/SerializeClass.h"
#include "common/stablemap.h"
namespace hpl {
class cScriptVar : public iSerializable {
kSerializableClassInit(cScriptVar) public : cScriptVar();
tString msName;
int mlVal;
};
typedef Common::StableMap<tString, cScriptVar> tScriptVarMap;
typedef tScriptVarMap::iterator tScriptVarMapIt;
} // namespace hpl
#endif // HPL_GAME_TYPES_H

View File

@@ -0,0 +1,201 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#include "hpl1/engine/game/SaveGame.h"
#include "hpl1/engine/system/low_level_system.h"
namespace hpl {
//////////////////////////////////////////////////////////////////////////
// SAVE GAME DATA
//////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------
// Serialize iSaveGame
kBeginSerializeBaseVirtual(iSaveData)
kSerializeVar(mlSaveDataId, eSerializeType_Int32)
kEndSerialize()
//------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// SAVE GAME OBJECT
//////////////////////////////////////////////////////////////////////////
int iSaveObject::_mlGlobalIdCount = 0;
//------------------------------------------------------------------------
iSaveObject::iSaveObject() {
mlSaveObjectId = _mlGlobalIdCount++;
if (_mlGlobalIdCount < 0)
_mlGlobalIdCount = 0;
mbIsSaved = true;
}
iSaveObject::~iSaveObject() {
}
//------------------------------------------------------------------------
void iSaveObject::SaveToSaveData(iSaveData *apSaveData) {
apSaveData->mlSaveDataId = mlSaveObjectId;
}
//------------------------------------------------------------------------
void iSaveObject::LoadFromSaveData(iSaveData *apSaveData) {
mlSaveObjectId = apSaveData->mlSaveDataId;
mpSaveData = apSaveData;
}
//------------------------------------------------------------------------
void iSaveObject::SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame) {
}
//------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// SAVE GAME CONTAINER
//////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------
cSaveObjectHandler::cSaveObjectHandler() {
}
cSaveObjectHandler::~cSaveObjectHandler() {
}
//------------------------------------------------------------------------
void cSaveObjectHandler::Add(iSaveObject *pObject) {
m_mapSaveObjects.insert(tSaveObjectMap::value_type(pObject->GetSaveObjectId(), pObject));
}
//------------------------------------------------------------------------
iSaveObject *cSaveObjectHandler::Get(int alId) {
tSaveObjectMapIt it = m_mapSaveObjects.find(alId);
if (it == m_mapSaveObjects.end()) {
Warning("Couldn't find save object with id %d\n", alId);
return NULL;
}
return it->second;
}
//------------------------------------------------------------------------
cSaveObjectIterator cSaveObjectHandler::GetIterator() {
return cSaveObjectIterator(&m_mapSaveObjects);
}
//------------------------------------------------------------------------
void cSaveObjectHandler::SetUpAll(cGame *apGame) {
int lMaxId = 0;
tSaveObjectMapIt it = m_mapSaveObjects.begin();
for (; it != m_mapSaveObjects.end(); ++it) {
iSaveObject *pObject = it->second;
if (pObject->GetSaveObjectId() > lMaxId)
lMaxId = pObject->GetSaveObjectId();
pObject->SaveDataSetup(this, apGame);
}
iSaveObject::_mlGlobalIdCount = lMaxId;
}
//------------------------------------------------------------------------
void cSaveObjectHandler::Clear() {
m_mapSaveObjects.clear();
}
//------------------------------------------------------------------------
size_t cSaveObjectHandler::Size() {
return m_mapSaveObjects.size();
}
//------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// SAVE DATA CONTAINER
//////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------
cSaveDataHandler::cSaveDataHandler() {
}
cSaveDataHandler::~cSaveDataHandler() {
}
//------------------------------------------------------------------------
void cSaveDataHandler::Add(iSaveData *pData) {
m_mapSaveData.insert(tSaveDataMap::value_type(pData->GetSaveCreatePrio(), pData));
}
cSaveDataIterator cSaveDataHandler::GetIterator() {
return cSaveDataIterator(&m_mapSaveData);
}
void cSaveDataHandler::Clear() {
m_mapSaveData.clear();
}
size_t cSaveDataHandler::Size() {
return m_mapSaveData.size();
}
//------------------------------------------------------------------------
void cSaveDataHandler::AddVoidPtr(void **apPtr) {
iSaveData **pDataPtr = (iSaveData **)apPtr;
Add(*pDataPtr);
}
void cSaveDataHandler::AddVoidClass(void *apClass) {
iSaveData *pData = (iSaveData *)(apClass);
Add(pData);
}
iContainerIterator *cSaveDataHandler::CreateIteratorPtr() {
return hplNew(cSaveDataIterator, (&m_mapSaveData));
}
//------------------------------------------------------------------------
} // namespace hpl

View File

@@ -0,0 +1,239 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_SAVE_GAME_H
#define HPL_SAVE_GAME_H
#include "hpl1/engine/system/SerializeClass.h"
#include "hpl1/engine/system/SystemTypes.h"
#include "common/stablemap.h"
#include "common/multimap.h"
class TiXmlElement;
#define kSaveData_LoadFromBegin(aClass) \
super::LoadFromSaveData(apSaveData); \
cSaveData_##aClass *pData = static_cast<cSaveData_##aClass *>(apSaveData); \
assert(pData != nullptr);
#define kSaveData_SaveToBegin(aClass) \
super::SaveToSaveData(apSaveData); \
cSaveData_##aClass *pData = static_cast<cSaveData_##aClass *>(apSaveData); \
assert(pData != nullptr);
#define kSaveData_SetupBegin(aClass) \
super::SaveDataSetup(apSaveObjectHandler, apGame); \
cSaveData_##aClass *pData = static_cast<cSaveData_##aClass *>(mpSaveData); \
assert(pData != nullptr);
#define kSaveData_BaseClass(aClass) class cSaveData_##aClass : public iSaveData
#define kSaveData_ChildClass(aParent, aChild) class cSaveData_##aChild : public cSaveData_##aParent
#define kSaveData_ClassInit(aClass) kSerializableClassInit(cSaveData_##aClass)
//////////////////////////////////////////////
// Helpers to copy data.
#define kSaveData_SaveTo(aVar) pData->aVar = aVar;
#define kSaveData_LoadFrom(aVar) aVar = pData->aVar;
#define kSaveData_SaveObject(aObject, aId) \
if (aObject) \
pData->aId = aObject->GetSaveObjectId(); \
else \
pData->aId = -1;
// Only used in setup:
#define kSaveData_LoadObject(aObject, aId, aClass) \
if (pData->aId == -1) \
aObject = NULL; \
else { \
aObject = static_cast<aClass>(apSaveObjectHandler->Get(pData->aId)); \
}
//////////////////////////////////////////////
// Helpers to copy containers with SaveDataId
#define kSaveData_SaveIdList(aSrcList, aSrcIt, aDestList) \
pData->aDestList.Clear(); \
for (aSrcIt it = aSrcList.begin(); it != aSrcList.end(); ++it) { \
pData->aDestList.Add((*it)->GetSaveObjectId()); \
}
// Only used in setup:
#define kSaveData_LoadIdList(aSrcList, aDestList, aClass) \
{ \
cContainerListIterator<int> it = pData->aDestList.GetIterator(); \
aSrcList.clear(); \
while (it.HasNext()) { \
int lId = it.Next(); \
iSaveObject *pObject = apSaveObjectHandler->Get(lId); \
if (pObject == NULL) { \
continue; \
} \
aSrcList.push_back(static_cast<aClass>(pObject)); \
} \
}
namespace hpl {
//--------------------------------------------------------
class cSaveObjectHandler;
class iSaveObject;
class cGame;
/**
* This is data that is created by a SaveObject and the data can be loaded into the object.
*/
class iSaveData : public iSerializable {
kSerializableClassInit(iSaveData) public : int mlSaveDataId;
/**
* Creates the SaveObject using previously saved objects and the data in this class.
*/
virtual iSaveObject *CreateSaveObject(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame) = 0;
/**
* The lower number the earlier it will be created.
*/
virtual int GetSaveCreatePrio() = 0;
};
//--------------------------------------------------------
/**
* This is class is inherited by object that are to be saved.
*/
class iSaveObject {
friend class cSaveObjectHandler;
public:
iSaveObject();
virtual ~iSaveObject();
/**
* Get a unique id for this object.
*/
int GetSaveObjectId() { return mlSaveObjectId; }
/**
* Save it's data to a SaveData
*/
virtual void SaveToSaveData(iSaveData *apSaveData);
/**
* Load it's data from a SaveData
*/
virtual void LoadFromSaveData(iSaveData *apSaveData);
/**
* Creates the SaveData that this class uses.
*/
virtual iSaveData *CreateSaveData() = 0;
/**
* After all objects have been created, this function is called to enable setup.
*/
virtual void SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame);
void SetIsSaved(bool abX) { mbIsSaved = abX; }
bool IsSaved() { return mbIsSaved; }
protected:
iSaveData *mpSaveData;
private:
int mlSaveObjectId;
bool mbIsSaved;
static int _mlGlobalIdCount;
};
//---------------------------------------------------------
typedef Common::MultiMap<int, iSaveObject *> tSaveObjectMap;
typedef tSaveObjectMap::iterator tSaveObjectMapIt;
typedef cSTLMapIterator<iSaveObject *, tSaveObjectMap, tSaveObjectMapIt> cSaveObjectIterator;
/**
* This store all the SaveObjects created at load time.
*/
class cSaveObjectHandler {
public:
cSaveObjectHandler();
~cSaveObjectHandler();
public:
void Add(iSaveObject *pObject);
iSaveObject *Get(int alId);
cSaveObjectIterator GetIterator();
void SetUpAll(cGame *apGame);
void Clear();
size_t Size();
private:
tSaveObjectMap m_mapSaveObjects;
};
//---------------------------------------------------------
typedef Common::MultiMap<int, iSaveData *> tSaveDataMap;
typedef tSaveDataMap::iterator tSaveDataMapIt;
typedef cSTLMapIterator<iSaveData *, tSaveDataMap, tSaveDataMapIt> cSaveDataIterator;
/**
* Used to keep track of save data.
*/
class cSaveDataHandler : public iContainer {
public:
cSaveDataHandler();
~cSaveDataHandler();
void Add(iSaveData *pData);
cSaveDataIterator GetIterator();
void Clear();
size_t Size();
private:
void AddVoidPtr(void **apPtr);
void AddVoidClass(void *apClass);
iContainerIterator *CreateIteratorPtr();
tSaveDataMap m_mapSaveData;
};
//---------------------------------------------------------
} // namespace hpl
#endif // HPL_SAVE_GAME_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,75 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_SCRIPT_FUNCS_H
#define HPL_SCRIPT_FUNCS_H
#include "hpl1/engine/physics/PhysicsJoint.h"
namespace hpl {
class cGraphics;
class cResources;
class cSystem;
class cSound;
class cScene;
class cInput;
class cGame;
//---------------------------------------
class cScriptJointCallback : public iPhysicsJointCallback {
public:
cScriptJointCallback(cScene *apScene);
void OnMinLimit(iPhysicsJoint *apJoint);
void OnMaxLimit(iPhysicsJoint *apJoint);
bool IsScript() { return true; }
tString msMaxFunc;
tString msMinFunc;
cScene *mpScene;
};
//---------------------------------------
class cScriptFuncs {
public:
static void Init(cGraphics *apGraphics,
cResources *apResources,
cSystem *apSystem,
cInput *apInput,
cScene *apScene,
cSound *apSound,
cGame *apGame);
};
} // namespace hpl
#endif // HPL_SCRIPT_FUNCS_H

View File

@@ -0,0 +1,63 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_UPDATEABLE_H
#define HPL_UPDATEABLE_H
#include "hpl1/engine/system/SystemTypes.h"
namespace hpl {
class iUpdateable {
public:
iUpdateable(const tString &asName) : msName(asName) {}
virtual ~iUpdateable() {}
virtual void OnDraw() {}
virtual void OnPostSceneDraw() {}
virtual void OnPostGUIDraw() {}
virtual void OnPostBufferSwap() {}
virtual void OnStart() {}
virtual void Update(float afTimeStep) {}
virtual void OnExit() {}
virtual void Reset() {}
const tString &GetName() { return msName; }
private:
tString msName;
};
} // namespace hpl
#endif // HPL_UPDATEABLE_H

View File

@@ -0,0 +1,267 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#include "hpl1/engine/game/Updater.h"
#include "hpl1/engine/game/Updateable.h"
#include "hpl1/engine/system/low_level_system.h"
namespace hpl {
//////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
cUpdater::cUpdater(LowLevelSystem *apLowLevelSystem) {
mpCurrentUpdates = NULL;
mpLowLevelSystem = apLowLevelSystem;
}
//-----------------------------------------------------------------------
cUpdater::~cUpdater() {
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// PUBLIC METHOD
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
void cUpdater::OnDraw() {
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
(*it)->OnDraw();
}
if (mpCurrentUpdates) {
for (tUpdateableListIt it = mpCurrentUpdates->begin(); it != mpCurrentUpdates->end(); ++it) {
(*it)->OnDraw();
}
}
}
//-----------------------------------------------------------------------
void cUpdater::OnPostSceneDraw() {
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
(*it)->OnPostSceneDraw();
}
if (mpCurrentUpdates) {
for (tUpdateableListIt it = mpCurrentUpdates->begin(); it != mpCurrentUpdates->end(); ++it) {
(*it)->OnPostSceneDraw();
}
}
}
void cUpdater::OnPostGUIDraw() {
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
(*it)->OnPostGUIDraw();
}
if (mpCurrentUpdates) {
for (tUpdateableListIt it = mpCurrentUpdates->begin(); it != mpCurrentUpdates->end(); ++it) {
(*it)->OnPostGUIDraw();
}
}
}
//-----------------------------------------------------------------------
void cUpdater::OnPostBufferSwap() {
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
(*it)->OnPostBufferSwap();
}
if (mpCurrentUpdates) {
for (tUpdateableListIt it = mpCurrentUpdates->begin(); it != mpCurrentUpdates->end(); ++it) {
(*it)->OnPostBufferSwap();
}
}
}
//-----------------------------------------------------------------------
void cUpdater::OnStart() {
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
(*it)->OnStart();
}
tUpdateContainerMapIt ContIt = m_mapUpdateContainer.begin();
while (ContIt != m_mapUpdateContainer.end()) {
tUpdateableListIt UpIt = ContIt->second.begin();
while (UpIt != ContIt->second.end()) {
(*UpIt)->OnStart();
UpIt++;
}
ContIt++;
}
}
//-----------------------------------------------------------------------
void cUpdater::Reset() {
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
(*it)->Reset();
}
tUpdateContainerMapIt ContIt = m_mapUpdateContainer.begin();
while (ContIt != m_mapUpdateContainer.end()) {
tUpdateableList *pUpdates = &ContIt->second;
tUpdateableListIt UpIt = pUpdates->begin();
while (UpIt != pUpdates->end()) {
iUpdateable *pUpdate = *UpIt;
pUpdate->Reset();
++UpIt;
}
++ContIt;
}
}
//-----------------------------------------------------------------------
void cUpdater::OnExit() {
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
// Log(" Exiting %s\n",(*it)->GetName().c_str());
(*it)->OnExit();
}
tUpdateContainerMapIt ContIt = m_mapUpdateContainer.begin();
while (ContIt != m_mapUpdateContainer.end()) {
tUpdateableListIt UpIt = ContIt->second.begin();
while (UpIt != ContIt->second.end()) {
// Log(" Exiting %s\n",(*UpIt)->GetName().c_str());
(*UpIt)->OnExit();
UpIt++;
}
ContIt++;
}
}
//-----------------------------------------------------------------------
void cUpdater::Update(float afTimeStep) {
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
START_TIMING_EX((*it)->GetName().c_str(), game)
(*it)->Update(afTimeStep);
STOP_TIMING(game)
}
if (mpCurrentUpdates) {
tUpdateableList *pList = mpCurrentUpdates;
for (tUpdateableListIt it = pList->begin(); it != pList->end(); ++it) {
START_TIMING_EX((*it)->GetName().c_str(), game)
(*it)->Update(afTimeStep);
STOP_TIMING(game)
}
}
}
//-----------------------------------------------------------------------
bool cUpdater::SetContainer(tString asContainer) {
tUpdateContainerMapIt it = m_mapUpdateContainer.find(asContainer);
if (it == m_mapUpdateContainer.end())
return false;
msCurrentUpdates = asContainer;
if (msCurrentUpdates == "Default") {
SetUpdateLogActive(true);
} else {
SetUpdateLogActive(false);
}
mpCurrentUpdates = &it->second;
return true;
}
tString cUpdater::GetCurrentContainerName() {
if (mpCurrentUpdates == NULL)
return "";
return msCurrentUpdates;
}
//-----------------------------------------------------------------------
bool cUpdater::AddContainer(tString asName) {
// Create the value for the map with key and Updateable
tUpdateContainerMap::value_type val = tUpdateContainerMap::value_type(
asName, tUpdateableList());
// Add it to the map
m_mapUpdateContainer.insert(val);
return true;
}
//-----------------------------------------------------------------------
bool cUpdater::AddUpdate(tString asContainer, iUpdateable *apUpdate) {
if (apUpdate == NULL) {
Error("Couldn't add NULL updatable!");
return false;
}
// Search the map for the container name
tUpdateContainerMapIt it = m_mapUpdateContainer.find(asContainer);
if (it == m_mapUpdateContainer.end())
return false;
// Add the updatable
it->second.push_back(apUpdate);
return true;
}
//-----------------------------------------------------------------------
bool cUpdater::AddGlobalUpdate(iUpdateable *apUpdate) {
mlstGlobalUpdateableList.push_back(apUpdate);
return true;
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
} // namespace hpl

View File

@@ -0,0 +1,110 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_UPDATER_H
#define HPL_UPDATER_H
#include "common/list.h"
#include "hpl1/engine/system/SystemTypes.h"
#include "common/stablemap.h"
namespace hpl {
class iUpdateable;
class LowLevelSystem;
typedef Common::List<iUpdateable *> tUpdateableList;
typedef tUpdateableList::iterator tUpdateableListIt;
typedef Common::StableMap<tString, tUpdateableList> tUpdateContainerMap;
typedef tUpdateContainerMap::iterator tUpdateContainerMapIt;
class cUpdater {
public:
cUpdater(LowLevelSystem *apLowLevelSystem);
~cUpdater();
void Reset();
void OnDraw();
void OnPostSceneDraw();
void OnPostGUIDraw();
void OnPostBufferSwap();
void OnStart();
void Update(float afTimeStep);
void OnExit();
/**
* Sets the active update container to be used.
* \param asContainer Name of the contianer
* \return
*/
bool SetContainer(tString asContainer);
/**
* Gets the name of the current container in use.
* \return name of current container.
*/
tString GetCurrentContainerName();
/**
* Adds a new container
* \todo change name to state instead of container?
* \param asName Name for the new container.
* \return
*/
bool AddContainer(tString asName);
/**
* Adds a new update in a container.
* \param asContainer Container name
* \param apUpdate pointer to the class that will be updated
* \return
*/
bool AddUpdate(tString asContainer, iUpdateable *apUpdate);
/**
* Adds a global update that runs no matter what container is set
* \param apUpdate
* \return
*/
bool AddGlobalUpdate(iUpdateable *apUpdate);
private:
tString msCurrentUpdates;
tUpdateContainerMap m_mapUpdateContainer;
LowLevelSystem *mpLowLevelSystem;
tUpdateableList *mpCurrentUpdates;
tUpdateableList mlstGlobalUpdateableList;
};
} // namespace hpl
#endif // HPL_UPDATER_H

View File

@@ -0,0 +1,105 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "hpl1/engine/game/low_level_game_setup.h"
#include "hpl1/engine/impl/LowLevelGraphicsSDL.h"
#include "hpl1/engine/impl/LowLevelPhysicsNewton.h"
#include "hpl1/engine/impl/LowLevelSoundOpenAL.h"
#include "hpl1/engine/impl/low_level_graphics_tgl.h"
#include "hpl1/engine/input/LowLevelInput.h"
#include "hpl1/engine/resources/low_level_resources.h"
#include "hpl1/engine/system/low_level_system.h"
#include "hpl1/graphics.h"
namespace hpl {
static iLowLevelGraphics *createLowLevelGfx() {
#ifdef HPL1_USE_OPENGL
if (Hpl1::useOpenGL())
return hplNew(cLowLevelGraphicsSDL, ());
#endif
#ifdef USE_TINYGL
return hplNew(LowLevelGraphicsTGL, ());
#else
error("Can't find a valid renderer: TinyGL is not supported");
#endif
}
LowLevelGameSetup::LowLevelGameSetup() {
_lowLevelSystem = hplNew(LowLevelSystem, ());
_lowLevelGraphics = createLowLevelGfx();
_lowLevelInput = hplNew(LowLevelInput, (_lowLevelGraphics));
_lowLevelResources = hplNew(LowLevelResources, (_lowLevelGraphics));
_lowLevelSound = hplNew(cLowLevelSoundOpenAL, ());
_lowLevelPhysics = hplNew(cLowLevelPhysicsNewton, ());
}
LowLevelGameSetup::~LowLevelGameSetup() {
Log("Deleting lowlevel stuff.\n");
Log("Physics\n");
hplDelete(_lowLevelPhysics);
Log("Sound\n");
hplDelete(_lowLevelSound);
Log("Input\n");
hplDelete(_lowLevelInput);
Log("Resources\n");
hplDelete(_lowLevelResources);
Log("System\n");
hplDelete(_lowLevelSystem);
Log("Graphics\n");
hplDelete(_lowLevelGraphics);
}
cScene *LowLevelGameSetup::createScene(cGraphics *graphics, cResources *resources, cSound *sound,
cPhysics *physics, cSystem *system, cAI *ai) {
return hplNew(cScene, (graphics, resources, sound, physics, system, ai));
}
cResources *LowLevelGameSetup::createResources(cGraphics *graphics) {
return hplNew(cResources, (_lowLevelResources, _lowLevelGraphics));
}
cInput *LowLevelGameSetup::createInput(cGraphics *graphics) {
return hplNew(cInput, (_lowLevelInput));
}
cSystem *LowLevelGameSetup::createSystem() {
return hplNew(cSystem, (_lowLevelSystem));
}
cGraphics *LowLevelGameSetup::createGraphics() {
return hplNew(cGraphics, (_lowLevelGraphics, _lowLevelResources));
}
cSound *LowLevelGameSetup::createSound() {
return hplNew(cSound, (_lowLevelSound));
}
cPhysics *LowLevelGameSetup::createPhysics() {
return hplNew(cPhysics, (_lowLevelPhysics));
}
cAI *LowLevelGameSetup::createAi() {
return hplNew(cAI, ());
}
} // namespace hpl

View File

@@ -0,0 +1,68 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_LOWLEVELGAMESETUP_H
#define HPL_LOWLEVELGAMESETUP_H
#include "hpl1/engine/ai/AI.h"
#include "hpl1/engine/graphics/Graphics.h"
#include "hpl1/engine/input/Input.h"
#include "hpl1/engine/physics/Physics.h"
#include "hpl1/engine/resources/Resources.h"
#include "hpl1/engine/scene/Scene.h"
#include "hpl1/engine/sound/Sound.h"
#include "hpl1/engine/system/System.h"
namespace hpl {
class LowLevelGameSetup {
public:
LowLevelGameSetup();
~LowLevelGameSetup();
cInput *createInput(cGraphics *graphics);
cSystem *createSystem();
cGraphics *createGraphics();
cResources *createResources(cGraphics *graphics);
cScene *createScene(cGraphics *graphics, cResources *resources, cSound *sound,
cPhysics *physics, cSystem *system, cAI *ai);
cSound *createSound();
cPhysics *createPhysics();
cAI *createAi();
private:
LowLevelSystem *_lowLevelSystem;
iLowLevelGraphics *_lowLevelGraphics;
LowLevelInput *_lowLevelInput;
LowLevelResources *_lowLevelResources;
iLowLevelSound *_lowLevelSound;
iLowLevelPhysics *_lowLevelPhysics;
};
} // namespace hpl
#endif // HPL_LOWLEVELGAMESETUP_H