Implemented the splash screen and config file

This commit is contained in:
Kayne Ruse
2013-05-12 02:33:08 +10:00
parent 6a19d0a312
commit cc00129542
6 changed files with 104 additions and 53 deletions
+16 -1
View File
@@ -1,5 +1,8 @@
#include "scene_manager.hpp"
#include "singleton.hpp"
#include "config_utility.hpp"
#include <stdexcept>
//-------------------------
@@ -36,7 +39,19 @@ void SceneManager::Init() {
if (SDL_Init(SDL_INIT_VIDEO))
throw(std::runtime_error("Failed to initialize SDL"));
BaseScene::SetScreen(800, 600);
GetSingletonPtr<ConfigUtility>()->Load("rsc\\config.cfg");
//set the screen from the config file
int flags = SDL_HWSURFACE|SDL_DOUBLEBUF;
if (GetSingletonPtr<ConfigUtility>()->Boolean("screen.f")) {
flags |= SDL_FULLSCREEN;
}
BaseScene::SetScreen(
GetSingletonPtr<ConfigUtility>()->Integer("screen.w"),
GetSingletonPtr<ConfigUtility>()->Integer("screen.h"),
0,
flags
);
}
void SceneManager::Proc() {
+31
View File
@@ -0,0 +1,31 @@
#ifndef SINGLETON_HPP_
#define SINGLETON_HPP_
/*
template<typename T>
class Singleton {
public:
static T* GetSingletonPtr() {
return &singleton;
}
static T& GetSingletonRef() {
return singleton;
}
private:
Singleton();
~Singleton();
Singleton(const Singleton&);
Singleton& operator=(const Singleton&);
Singleton(Singleton&&);
Singleton& operator=(Singleton&&);
static T singleton;
};
*/
template<typename T>
T* GetSingletonPtr() {
static T t;
return &t;
}
#endif
+25 -40
View File
@@ -12,58 +12,43 @@ Splash::Splash() {
#ifdef DEBUG
cout << "entering Splash" << endl;
#endif
loaded = false;
start = clock();
configUtil = GetSingletonPtr<ConfigUtility>();
surfaceMgr = GetSingletonPtr<SurfaceManager>();
logo = new Image(surfaceMgr->Load("logo", configUtil->String("logos") + "/krstudios.bmp"));
}
Splash::~Splash() {
delete logo;
surfaceMgr->Free("logo");
#ifdef DEBUG
cout << "leaving Splash" << endl;
#endif
}
//-------------------------
//Frame loop
//-------------------------
void Splash::RunFrame() {
//skip any event handling here
void Splash::FrameStart() {
//
}
//draw the logo in the middle of the screen
int x = (GetScreen()->w - logo->GetClipW()) / 2;
int y = (GetScreen()->h - logo->GetClipH()) / 2;
void Splash::FrameEnd() {
//
}
logo->DrawTo(GetScreen(),x,y);
SDL_Flip(GetScreen());
void Splash::Update() {
//
}
if (!loaded) {
LoadResources();
}
void Splash::Render(SDL_Surface* const screen) {
//
}
//-------------------------
//Event handlers
//-------------------------
void Splash::MouseMotion(SDL_MouseMotionEvent const& motion) {
//
}
void Splash::MouseButtonDown(SDL_MouseButtonEvent const& button) {
//
}
void Splash::MouseButtonUp(SDL_MouseButtonEvent const& button) {
//
}
void Splash::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE:
QuitEvent();
break;
if (clock() - start > CLOCKS_PER_SEC*3) {
SetNextScene(SceneList::MAINMENU);
}
}
void Splash::KeyUp(SDL_KeyboardEvent const& key) {
//
}
void Splash::LoadResources() {
//load the resources during the splash screen
//TODO
loaded = true;
}
+16 -12
View File
@@ -3,25 +3,29 @@
#include "base_scene.hpp"
#include "singleton.hpp"
#include "config_utility.hpp"
#include "surface_manager.hpp"
#include "image.hpp"
#include <ctime>
class Splash : public BaseScene {
public:
/* Public access members */
Splash();
virtual ~Splash();
protected:
/* Frame loop */
virtual void FrameStart();
virtual void FrameEnd();
virtual void Update();
virtual void Render(SDL_Surface* const);
virtual void RunFrame();
/* Event handlers */
virtual void MouseMotion(SDL_MouseMotionEvent const&);
virtual void MouseButtonDown(SDL_MouseButtonEvent const&);
virtual void MouseButtonUp(SDL_MouseButtonEvent const&);
virtual void KeyDown(SDL_KeyboardEvent const&);
virtual void KeyUp(SDL_KeyboardEvent const&);
void LoadResources();
bool loaded;
time_t start;
ConfigUtility* configUtil;
SurfaceManager* surfaceMgr;
Image* logo;
};
#endif