diff --git a/client/scene_manager.cpp b/client/scene_manager.cpp index d2651da..01000d7 100644 --- a/client/scene_manager.cpp +++ b/client/scene_manager.cpp @@ -1,5 +1,8 @@ #include "scene_manager.hpp" +#include "singleton.hpp" +#include "config_utility.hpp" + #include //------------------------- @@ -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()->Load("rsc\\config.cfg"); + + //set the screen from the config file + int flags = SDL_HWSURFACE|SDL_DOUBLEBUF; + if (GetSingletonPtr()->Boolean("screen.f")) { + flags |= SDL_FULLSCREEN; + } + BaseScene::SetScreen( + GetSingletonPtr()->Integer("screen.w"), + GetSingletonPtr()->Integer("screen.h"), + 0, + flags + ); } void SceneManager::Proc() { diff --git a/client/singleton.hpp b/client/singleton.hpp new file mode 100644 index 0000000..e741a33 --- /dev/null +++ b/client/singleton.hpp @@ -0,0 +1,31 @@ +#ifndef SINGLETON_HPP_ +#define SINGLETON_HPP_ + +/* +template +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 +T* GetSingletonPtr() { + static T t; + return &t; +} + +#endif diff --git a/client/splash.cpp b/client/splash.cpp index ddd3917..dc6ac12 100644 --- a/client/splash.cpp +++ b/client/splash.cpp @@ -12,58 +12,43 @@ Splash::Splash() { #ifdef DEBUG cout << "entering Splash" << endl; #endif + loaded = false; + start = clock(); + configUtil = GetSingletonPtr(); + surfaceMgr = GetSingletonPtr(); + + 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; +} \ No newline at end of file diff --git a/client/splash.hpp b/client/splash.hpp index 9522c11..6288ecd 100644 --- a/client/splash.hpp +++ b/client/splash.hpp @@ -3,25 +3,29 @@ #include "base_scene.hpp" +#include "singleton.hpp" +#include "config_utility.hpp" +#include "surface_manager.hpp" +#include "image.hpp" + +#include + 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 diff --git a/rsc/config.cfg b/rsc/config.cfg new file mode 100644 index 0000000..9fe6af0 --- /dev/null +++ b/rsc/config.cfg @@ -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 diff --git a/rsc/graphics/fonts/pokemon_dark_font.bmp b/rsc/graphics/fonts/pokemon_dark_font.bmp new file mode 100644 index 0000000..97b23e0 Binary files /dev/null and b/rsc/graphics/fonts/pokemon_dark_font.bmp differ