Implemented the splash screen and config file
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
#include "scene_manager.hpp"
|
#include "scene_manager.hpp"
|
||||||
|
|
||||||
|
#include "singleton.hpp"
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -36,7 +39,19 @@ void SceneManager::Init() {
|
|||||||
if (SDL_Init(SDL_INIT_VIDEO))
|
if (SDL_Init(SDL_INIT_VIDEO))
|
||||||
throw(std::runtime_error("Failed to initialize SDL"));
|
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() {
|
void SceneManager::Proc() {
|
||||||
|
|||||||
@@ -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
@@ -12,58 +12,43 @@ Splash::Splash() {
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "entering Splash" << endl;
|
cout << "entering Splash" << endl;
|
||||||
#endif
|
#endif
|
||||||
|
loaded = false;
|
||||||
|
start = clock();
|
||||||
|
configUtil = GetSingletonPtr<ConfigUtility>();
|
||||||
|
surfaceMgr = GetSingletonPtr<SurfaceManager>();
|
||||||
|
|
||||||
|
logo = new Image(surfaceMgr->Load("logo", configUtil->String("logos") + "/krstudios.bmp"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Splash::~Splash() {
|
Splash::~Splash() {
|
||||||
|
delete logo;
|
||||||
|
surfaceMgr->Free("logo");
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "leaving Splash" << endl;
|
cout << "leaving Splash" << endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
void Splash::RunFrame() {
|
||||||
//Frame loop
|
//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) {
|
if (clock() - start > CLOCKS_PER_SEC*3) {
|
||||||
//
|
SetNextScene(SceneList::MAINMENU);
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Splash::KeyUp(SDL_KeyboardEvent const& key) {
|
void Splash::LoadResources() {
|
||||||
//
|
//load the resources during the splash screen
|
||||||
}
|
//TODO
|
||||||
|
loaded = true;
|
||||||
|
}
|
||||||
+16
-12
@@ -3,25 +3,29 @@
|
|||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
#include "singleton.hpp"
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
#include "surface_manager.hpp"
|
||||||
|
#include "image.hpp"
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
class Splash : public BaseScene {
|
class Splash : public BaseScene {
|
||||||
public:
|
public:
|
||||||
/* Public access members */
|
|
||||||
Splash();
|
Splash();
|
||||||
virtual ~Splash();
|
virtual ~Splash();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/* Frame loop */
|
virtual void RunFrame();
|
||||||
virtual void FrameStart();
|
|
||||||
virtual void FrameEnd();
|
|
||||||
virtual void Update();
|
|
||||||
virtual void Render(SDL_Surface* const);
|
|
||||||
|
|
||||||
/* Event handlers */
|
void LoadResources();
|
||||||
virtual void MouseMotion(SDL_MouseMotionEvent const&);
|
|
||||||
virtual void MouseButtonDown(SDL_MouseButtonEvent const&);
|
bool loaded;
|
||||||
virtual void MouseButtonUp(SDL_MouseButtonEvent const&);
|
time_t start;
|
||||||
virtual void KeyDown(SDL_KeyboardEvent const&);
|
|
||||||
virtual void KeyUp(SDL_KeyboardEvent const&);
|
ConfigUtility* configUtil;
|
||||||
|
SurfaceManager* surfaceMgr;
|
||||||
|
Image* logo;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#configuration of the program
|
||||||
|
ip = 127.0.0.1
|
||||||
|
port = 2000
|
||||||
|
screen.w = 800
|
||||||
|
screen.h = 600
|
||||||
|
screen.f = false
|
||||||
|
|
||||||
|
#directories
|
||||||
|
fonts = rsc\graphics\fonts
|
||||||
|
logos = rsc\graphics\logos
|
||||||
|
sprites = rsc\graphics\sprites
|
||||||
|
tilesets = rsc\graphics\tilesets
|
||||||
|
|
||||||
|
#debugging
|
||||||
|
debug = true
|
||||||
|
avatar = elliot2.bmp
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 65 KiB |
Reference in New Issue
Block a user