summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-07-01 22:59:22 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-07-01 22:59:22 +0200
commitd9c5a439d09211ec210195709d275596c6c3c9ba (patch)
treeb536721f8ac5f42649345eeb836259bbf6a887e3 /src/app
parent9bd4ec03b272e7925b11c3efc2bd8460894ea589 (diff)
downloadcolobot-d9c5a439d09211ec210195709d275596c6c3c9ba.tar.gz
colobot-d9c5a439d09211ec210195709d275596c6c3c9ba.tar.bz2
colobot-d9c5a439d09211ec210195709d275596c6c3c9ba.zip
CGLDevice implementation
- extended Gfx::CDevice interface - written OpenGL implementation in Gfx::CGLDevice - rewrote color and light module - added Gfx::VertexCol - added array casts to Math::Vector, Math::Matrix and Gfx::Color
Diffstat (limited to 'src/app')
-rw-r--r--src/app/app.cpp95
-rw-r--r--src/app/app.h23
-rw-r--r--src/app/main.cpp5
3 files changed, 93 insertions, 30 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 2e1948f..b73adee 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -85,6 +85,7 @@ CApplication::CApplication()
m_eventQueue = new CEventQueue(m_iMan);
m_engine = NULL;
+ m_device = NULL;
m_robotMain = NULL;
m_sound = NULL;
@@ -118,6 +119,8 @@ CApplication::~CApplication()
delete m_iMan;
m_iMan = NULL;
+
+ m_appInstance = NULL;
}
Error CApplication::ParseArguments(int argc, char *argv[])
@@ -142,14 +145,14 @@ bool CApplication::Create()
// Temporarily -- only in windowed mode
m_private->deviceConfig.fullScreen = false;
- // Create the 3D engine.
+ // Create the 3D engine
m_engine = new Gfx::CEngine(m_iMan, this);
-
- // Initialize the app's custom scene stuff
- if (! m_engine->OneTimeSceneInit())
+ // Initialize the app's custom scene stuff, but before initializing the graphics device
+ if (! m_engine->BeforeCreateInit())
{
- SystemDialog(SDT_ERROR, "COLOBOT - Error", m_engine->RetError());
+ SystemDialog(SDT_ERROR, "COLOBOT - Error", std::string("Error in CEngine::BeforeCreateInit() :\n") +
+ std::string(m_engine->GetError()) );
return false;
}
@@ -168,14 +171,16 @@ bool CApplication::Create()
if (SDL_Init(initFlags) < 0)
{
- SystemDialog( SDT_ERROR, "COLOBOT - Error", "SDL initialization error:\n" + std::string(SDL_GetError()) );
+ SystemDialog( SDT_ERROR, "COLOBOT - Error", "SDL initialization error:\n" +
+ std::string(SDL_GetError()) );
return false;
}
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (videoInfo == NULL)
{
- SystemDialog( SDT_ERROR, "COLOBOT - Error", "SDL error while getting video info:\n " + std::string(SDL_GetError()) );
+ SystemDialog( SDT_ERROR, "COLOBOT - Error", "SDL error while getting video info:\n " +
+ std::string(SDL_GetError()) );
return false;
}
@@ -243,8 +248,30 @@ bool CApplication::Create()
// For now, enable joystick for testing
SetJoystickEnabled(true);
- // TODO ...
+ // The video is ready, we can create and initalize the graphics device
+ m_device = new Gfx::CGLDevice();
+ if (! m_device->Create() )
+ {
+ SystemDialog( SDT_ERROR, "COLOBT - Error", std::string("Error in CDevice::Create() :\n") +
+ std::string(m_device->GetError()) );
+ return false;
+ }
+
+ m_engine->SetDevice(m_device);
+ if (! m_engine->Create() )
+ {
+ SystemDialog( SDT_ERROR, "COLOBT - Error", std::string("Error in CEngine::Create() :\n") +
+ std::string(m_engine->GetError()) );
+ return false;
+ }
+
+ if (! m_engine->AfterDeviceSetInit() )
+ {
+ SystemDialog( SDT_ERROR, "COLOBT - Error", std::string("Error in CEngine::AfterDeviceSetInit() :\n") +
+ std::string(m_engine->GetError()) );
+ return false;
+ }
// The app is ready to go
@@ -255,8 +282,35 @@ bool CApplication::Create()
void CApplication::Destroy()
{
- delete m_engine;
- m_engine = NULL;
+ /*if (m_robotMain != NULL)
+ {
+ delete m_robotMain;
+ m_robotMain = NULL;
+ }
+
+ if (m_sound != NULL)
+ {
+ delete m_sound;
+ m_sound = NULL;
+ }*/
+
+ if (m_engine != NULL)
+ {
+ if (m_engine->GetWasInit())
+ m_engine->Destroy();
+
+ delete m_engine;
+ m_engine = NULL;
+ }
+
+ if (m_device != NULL)
+ {
+ if (m_device->GetWasInit())
+ m_device->Destroy();
+
+ delete m_device;
+ m_device = NULL;
+ }
if (m_private->joystick != NULL)
{
@@ -264,8 +318,11 @@ void CApplication::Destroy()
m_private->joystick = NULL;
}
- SDL_FreeSurface(m_private->surface);
- m_private->surface = NULL;
+ if (m_private->surface != NULL)
+ {
+ SDL_FreeSurface(m_private->surface);
+ m_private->surface = NULL;
+ }
IMG_Quit();
@@ -299,8 +356,8 @@ void CApplication::CloseJoystick()
Uint32 JoystickTimerCallback(Uint32 interval, void *)
{
- CApplication *app = CApplication::RetInstance();
- if ((app == NULL) || (! app->RetJoystickEnabled()))
+ CApplication *app = CApplication::GetInstance();
+ if ((app == NULL) || (! app->GetJoystickEnabled()))
return 0; // don't run the timer again
app->UpdateJoystick();
@@ -597,7 +654,7 @@ void CApplication::SetShowStat(bool show)
m_showStats = show;
}
-bool CApplication::RetShowStat()
+bool CApplication::GetShowStat()
{
return m_showStats;
}
@@ -607,12 +664,12 @@ void CApplication::SetDebugMode(bool mode)
m_debugMode = mode;
}
-bool CApplication::RetDebugMode()
+bool CApplication::GetDebugMode()
{
return m_debugMode;
}
-bool CApplication::RetSetupMode()
+bool CApplication::GetSetupMode()
{
return m_setupMode;
}
@@ -632,7 +689,7 @@ void CApplication::SetKey(int keyRank, int option, int key)
// TODO
}
-int CApplication::RetKey(int keyRank, int option)
+int CApplication::GetKey(int keyRank, int option)
{
// TODO
return 0;
@@ -665,7 +722,7 @@ void CApplication::SetJoystickEnabled(bool enable)
}
}
-bool CApplication::RetJoystickEnabled()
+bool CApplication::GetJoystickEnabled()
{
return m_joystickEnabled;
}
diff --git a/src/app/app.h b/src/app/app.h
index 4cb6976..098f0ad 100644
--- a/src/app/app.h
+++ b/src/app/app.h
@@ -21,6 +21,7 @@
#include "common/misc.h"
+#include "graphics/common/device.h"
#include "graphics/common/engine.h"
#include <string>
@@ -75,7 +76,7 @@ public:
~CApplication();
//! Returns the only CApplication instance
- static CApplication* RetInstance()
+ static CApplication* GetInstance()
{ return m_appInstance; }
public:
@@ -83,6 +84,8 @@ public:
Error ParseArguments(int argc, char *argv[]);
//! Initializes the application
bool Create();
+ //! Cleans up before exit
+ void Destroy();
//! Main event loop
int Run();
@@ -96,33 +99,31 @@ public:
void UpdateJoystick();
void SetShowStat(bool show);
- bool RetShowStat();
+ bool GetShowStat();
void SetDebugMode(bool mode);
- bool RetDebugMode();
+ bool GetDebugMode();
- bool RetSetupMode();
+ bool GetSetupMode();
void SetJoystickEnabled(bool enable);
- bool RetJoystickEnabled();
+ bool GetJoystickEnabled();
void FlushPressKey();
void ResetKey();
void SetKey(int keyRank, int option, int key);
- int RetKey(int keyRank, int option);
+ int GetKey(int keyRank, int option);
void SetMouseType(Gfx::MouseType type);
void SetMousePos(Math::Point pos);
//? void SetNiceMouse(bool nice);
- //? bool RetNiceMouse();
- //? bool RetNiceMouseCap();
+ //? bool GetNiceMouse();
+ //? bool GetNiceMouseCap();
bool WriteScreenShot(char *filename, int width, int height);
protected:
- //! Cleans up before exit
- void Destroy();
//! Processes an SDL event to Event struct
void ParseEvent();
//! Handles some incoming events
@@ -163,6 +164,8 @@ protected:
CEventQueue* m_eventQueue;
//! Graphics engine
Gfx::CEngine* m_engine;
+ //! Graphics device
+ Gfx::CDevice* m_device;
//! Sound subsystem
CSound* m_sound;
//! Main class of the proper game engine
diff --git a/src/app/main.cpp b/src/app/main.cpp
index 54d305e..1e102d7 100644
--- a/src/app/main.cpp
+++ b/src/app/main.cpp
@@ -35,7 +35,10 @@ int main(int argc, char *argv[])
}
if (! app.Create())
- return 0;
+ {
+ app.Destroy(); // ensure a clean exit
+ return 1;
+ }
return app.Run();
}