Merge branch 'dev' into dev-char
This commit is contained in:
+5
-5
@@ -25,7 +25,7 @@
|
|||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
#include "utilities.hpp"
|
#include "utilities.hpp"
|
||||||
#include "defines.hpp"
|
#include "defines.hpp"
|
||||||
#include "service_locator.hpp"
|
#include "singleton.hpp"
|
||||||
#include "packet_type.hpp"
|
#include "packet_type.hpp"
|
||||||
#include "network_queue.hpp"
|
#include "network_queue.hpp"
|
||||||
#include "information_manager.hpp"
|
#include "information_manager.hpp"
|
||||||
@@ -68,10 +68,10 @@ protected:
|
|||||||
void HandleDisconnection(::Disconnect&);
|
void HandleDisconnection(::Disconnect&);
|
||||||
|
|
||||||
//services
|
//services
|
||||||
ConfigUtility* configUtil = ServiceLocator<ConfigUtility>::Get();
|
ConfigUtility* configUtil = Singleton<ConfigUtility>::Get();
|
||||||
SurfaceManager* surfaceMgr = ServiceLocator<SurfaceManager>::Get();
|
SurfaceManager* surfaceMgr = Singleton<SurfaceManager>::Get();
|
||||||
UDPNetworkUtility* netUtil = ServiceLocator<UDPNetworkUtility>::Get();
|
UDPNetworkUtility* netUtil = Singleton<UDPNetworkUtility>::Get();
|
||||||
InformationManager* infoMgr = ServiceLocator<InformationManager>::Get();
|
InformationManager* infoMgr = Singleton<InformationManager>::Get();
|
||||||
|
|
||||||
//members
|
//members
|
||||||
RasterFont font;
|
RasterFont font;
|
||||||
|
|||||||
+5
-5
@@ -25,7 +25,7 @@
|
|||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
#include "utilities.hpp"
|
#include "utilities.hpp"
|
||||||
#include "defines.hpp"
|
#include "defines.hpp"
|
||||||
#include "service_locator.hpp"
|
#include "singleton.hpp"
|
||||||
#include "packet_type.hpp"
|
#include "packet_type.hpp"
|
||||||
#include "network_queue.hpp"
|
#include "network_queue.hpp"
|
||||||
#include "information_manager.hpp"
|
#include "information_manager.hpp"
|
||||||
@@ -72,10 +72,10 @@ protected:
|
|||||||
void BeginGame(JoinResponse&);
|
void BeginGame(JoinResponse&);
|
||||||
|
|
||||||
//services
|
//services
|
||||||
ConfigUtility* configUtil = ServiceLocator<ConfigUtility>::Get();
|
ConfigUtility* configUtil = Singleton<ConfigUtility>::Get();
|
||||||
SurfaceManager* surfaceMgr = ServiceLocator<SurfaceManager>::Get();
|
SurfaceManager* surfaceMgr = Singleton<SurfaceManager>::Get();
|
||||||
UDPNetworkUtility* netUtil = ServiceLocator<UDPNetworkUtility>::Get();
|
UDPNetworkUtility* netUtil = Singleton<UDPNetworkUtility>::Get();
|
||||||
InformationManager* infoMgr = ServiceLocator<InformationManager>::Get();
|
InformationManager* infoMgr = Singleton<InformationManager>::Get();
|
||||||
|
|
||||||
//members
|
//members
|
||||||
Button refreshButton;
|
Button refreshButton;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#define MAINMENU_HPP_
|
#define MAINMENU_HPP_
|
||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
#include "service_locator.hpp"
|
#include "singleton.hpp"
|
||||||
|
|
||||||
#include "surface_manager.hpp"
|
#include "surface_manager.hpp"
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
@@ -47,7 +47,7 @@ protected:
|
|||||||
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||||
void KeyDown(SDL_KeyboardEvent const&);
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
SurfaceManager* surfaceMgr = ServiceLocator<SurfaceManager>::Get();
|
SurfaceManager* surfaceMgr = Singleton<SurfaceManager>::Get();
|
||||||
|
|
||||||
Button startButton;
|
Button startButton;
|
||||||
Button optionsButton;
|
Button optionsButton;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#define OPTIONSCREEN_HPP_
|
#define OPTIONSCREEN_HPP_
|
||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
#include "service_locator.hpp"
|
#include "singleton.hpp"
|
||||||
|
|
||||||
#include "surface_manager.hpp"
|
#include "surface_manager.hpp"
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
@@ -44,7 +44,7 @@ protected:
|
|||||||
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||||
void KeyDown(SDL_KeyboardEvent const&);
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
SurfaceManager* surfaceMgr = ServiceLocator<SurfaceManager>::Get();
|
SurfaceManager* surfaceMgr = Singleton<SurfaceManager>::Get();
|
||||||
Button backButton;
|
Button backButton;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ SceneManager::~SceneManager() {
|
|||||||
* operations.
|
* operations.
|
||||||
* Important things to note:
|
* Important things to note:
|
||||||
* The APIs are initiated here.
|
* The APIs are initiated here.
|
||||||
* The global objects are created here.
|
* The global objects are initialized here.
|
||||||
* The game's screen is created here, based on information loaded from the config file.
|
* The game's screen is created here, based on information loaded from the config file.
|
||||||
* The ConfigUtility's call to Load() also ensures that the "rsc\" folder is in the directory. It's easy to forget it.
|
* The ConfigUtility's call to Load() also ensures that the "rsc\" folder is in the directory. It's easy to forget it.
|
||||||
*/
|
*/
|
||||||
@@ -62,7 +62,6 @@ SceneManager::~SceneManager() {
|
|||||||
void SceneManager::Init() {
|
void SceneManager::Init() {
|
||||||
//load the config file
|
//load the config file
|
||||||
try {
|
try {
|
||||||
configUtil = ServiceLocator<ConfigUtility>::Set(new ConfigUtility());
|
|
||||||
configUtil->Load("rsc/config.cfg");
|
configUtil->Load("rsc/config.cfg");
|
||||||
}
|
}
|
||||||
catch(std::runtime_error& e) {
|
catch(std::runtime_error& e) {
|
||||||
@@ -89,12 +88,7 @@ void SceneManager::Init() {
|
|||||||
SDL_GetVideoInfo()->vfmt->BitsPerPixel,
|
SDL_GetVideoInfo()->vfmt->BitsPerPixel,
|
||||||
flags);
|
flags);
|
||||||
|
|
||||||
//instanciate the remaining services
|
//initiate the remaining singletons
|
||||||
surfaceMgr = ServiceLocator<SurfaceManager>::Set(new SurfaceManager());
|
|
||||||
netUtil = ServiceLocator<UDPNetworkUtility>::Set(new UDPNetworkUtility());
|
|
||||||
infoMgr = ServiceLocator<InformationManager>::Set(new InformationManager());
|
|
||||||
|
|
||||||
//initiate the remaining services
|
|
||||||
netUtil->Open(0, sizeof(Packet));
|
netUtil->Open(0, sizeof(Packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,16 +131,10 @@ void SceneManager::Proc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SceneManager::Quit() {
|
void SceneManager::Quit() {
|
||||||
//clean up the services
|
//clean up the singletons
|
||||||
netUtil->Close();
|
netUtil->Close();
|
||||||
surfaceMgr->FreeAll();
|
surfaceMgr->FreeAll();
|
||||||
|
|
||||||
//delete the services
|
|
||||||
configUtil = ServiceLocator<ConfigUtility>::Set(nullptr);
|
|
||||||
surfaceMgr = ServiceLocator<SurfaceManager>::Set(nullptr);
|
|
||||||
netUtil = ServiceLocator<UDPNetworkUtility>::Set(nullptr);
|
|
||||||
infoMgr = ServiceLocator<InformationManager>::Set(nullptr);
|
|
||||||
|
|
||||||
//clean up the scene
|
//clean up the scene
|
||||||
UnloadScene();
|
UnloadScene();
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include "scene_list.hpp"
|
#include "scene_list.hpp"
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
#include "service_locator.hpp"
|
#include "singleton.hpp"
|
||||||
#include "packet_type.hpp"
|
#include "packet_type.hpp"
|
||||||
#include "information_manager.hpp"
|
#include "information_manager.hpp"
|
||||||
|
|
||||||
@@ -51,10 +51,10 @@ private:
|
|||||||
|
|
||||||
BaseScene* activeScene = nullptr;
|
BaseScene* activeScene = nullptr;
|
||||||
|
|
||||||
ConfigUtility* configUtil = nullptr;
|
ConfigUtility* configUtil = Singleton<ConfigUtility>::Get();
|
||||||
SurfaceManager* surfaceMgr = nullptr;
|
SurfaceManager* surfaceMgr = Singleton<SurfaceManager>::Get();
|
||||||
UDPNetworkUtility* netUtil = nullptr;
|
UDPNetworkUtility* netUtil = Singleton<UDPNetworkUtility>::Get();
|
||||||
InformationManager* infoMgr = nullptr;
|
InformationManager* infoMgr = Singleton<InformationManager>::Get();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#define SPLASHSCREEN_HPP_
|
#define SPLASHSCREEN_HPP_
|
||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
#include "service_locator.hpp"
|
#include "singleton.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
#include "surface_manager.hpp"
|
#include "surface_manager.hpp"
|
||||||
@@ -44,8 +44,8 @@ protected:
|
|||||||
void LoadResources();
|
void LoadResources();
|
||||||
|
|
||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
ConfigUtility* configUtil = ServiceLocator<ConfigUtility>::Get();
|
ConfigUtility* configUtil = Singleton<ConfigUtility>::Get();
|
||||||
SurfaceManager* surfaceMgr = ServiceLocator<SurfaceManager>::Get();
|
SurfaceManager* surfaceMgr = Singleton<SurfaceManager>::Get();
|
||||||
Image logo;
|
Image logo;
|
||||||
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#include "network_queue.hpp"
|
#include "network_queue.hpp"
|
||||||
#include "service_locator.hpp"
|
#include "singleton.hpp"
|
||||||
|
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ static std::deque<Packet> queue;
|
|||||||
static bool running = false;
|
static bool running = false;
|
||||||
|
|
||||||
static int networkQueue(void*) {
|
static int networkQueue(void*) {
|
||||||
UDPNetworkUtility* netUtil = ServiceLocator<UDPNetworkUtility>::Get();
|
UDPNetworkUtility* netUtil = Singleton<UDPNetworkUtility>::Get();
|
||||||
while(running) {
|
while(running) {
|
||||||
SDL_SemWait(lock);
|
SDL_SemWait(lock);
|
||||||
while(netUtil->Receive()) {
|
while(netUtil->Receive()) {
|
||||||
@@ -102,7 +102,7 @@ Packet popNetworkPacket() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void flushNetworkQueue() {
|
void flushNetworkQueue() {
|
||||||
UDPNetworkUtility* netUtil = ServiceLocator<UDPNetworkUtility>::Get();
|
UDPNetworkUtility* netUtil = Singleton<UDPNetworkUtility>::Get();
|
||||||
SDL_SemWait(lock);
|
SDL_SemWait(lock);
|
||||||
while(netUtil->Receive());
|
while(netUtil->Receive());
|
||||||
queue.clear();
|
queue.clear();
|
||||||
|
|||||||
@@ -19,24 +19,20 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef SERVICELOCATOR_HPP_
|
#ifndef SINGLETON_HPP_
|
||||||
#define SERVICELOCATOR_HPP_
|
#define SINGLETON_HPP_
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ServiceLocator {
|
class Singleton {
|
||||||
public:
|
public:
|
||||||
static T* Set(T* t) {
|
|
||||||
delete service;
|
|
||||||
return service = t;
|
|
||||||
}
|
|
||||||
static T* Get() {
|
static T* Get() {
|
||||||
return service;
|
return &instance;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
static T* service;
|
static T instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T* ServiceLocator<T>::service = nullptr;
|
T Singleton<T>::instance;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -44,14 +44,13 @@ ServerApplication::~ServerApplication() {
|
|||||||
* operations.
|
* operations.
|
||||||
* Important things to note:
|
* Important things to note:
|
||||||
* The APIs are initiated here.
|
* The APIs are initiated here.
|
||||||
* The global objects are created here.
|
* The global objects are initialized here.
|
||||||
* The ConfigUtility's call to Load() also ensures that the "rsc\" folder is in the directory. It's easy to forget it.
|
* The ConfigUtility's call to Load() also ensures that the "rsc\" folder is in the directory. It's easy to forget it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void ServerApplication::Init() {
|
void ServerApplication::Init() {
|
||||||
//load the config file
|
//load the config file
|
||||||
try {
|
try {
|
||||||
configUtil = ServiceLocator<ConfigUtility>::Set(new ConfigUtility());
|
|
||||||
configUtil->Load("rsc/config.cfg");
|
configUtil->Load("rsc/config.cfg");
|
||||||
}
|
}
|
||||||
catch(std::runtime_error& e) {
|
catch(std::runtime_error& e) {
|
||||||
@@ -70,10 +69,7 @@ void ServerApplication::Init() {
|
|||||||
throw(runtime_error("Failed to initialize SDL_net"));
|
throw(runtime_error("Failed to initialize SDL_net"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//instanciate the remaining services
|
//initiate the remaining singletons
|
||||||
netUtil = ServiceLocator<UDPNetworkUtility>::Set(new UDPNetworkUtility());
|
|
||||||
|
|
||||||
//initiate the remaining services
|
|
||||||
netUtil->Open(configUtil->Int("server.port"), sizeof(Packet));
|
netUtil->Open(configUtil->Int("server.port"), sizeof(Packet));
|
||||||
|
|
||||||
//create the threads
|
//create the threads
|
||||||
@@ -107,13 +103,9 @@ void ServerApplication::Quit() {
|
|||||||
//close the threads
|
//close the threads
|
||||||
endQueueThread();
|
endQueueThread();
|
||||||
|
|
||||||
//clean up the services
|
//clean up the singletons
|
||||||
netUtil->Close();
|
netUtil->Close();
|
||||||
|
|
||||||
//delete the services
|
|
||||||
configUtil = ServiceLocator<ConfigUtility>::Set(nullptr);
|
|
||||||
netUtil = ServiceLocator<UDPNetworkUtility>::Set(nullptr);
|
|
||||||
|
|
||||||
//deinitialize the APIs
|
//deinitialize the APIs
|
||||||
SDLNet_Quit();
|
SDLNet_Quit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include "utilities.hpp"
|
#include "utilities.hpp"
|
||||||
#include "packet_type.hpp"
|
#include "packet_type.hpp"
|
||||||
#include "service_locator.hpp"
|
#include "singleton.hpp"
|
||||||
#include "network_queue.hpp"
|
#include "network_queue.hpp"
|
||||||
|
|
||||||
#include "config_Utility.hpp"
|
#include "config_Utility.hpp"
|
||||||
@@ -79,8 +79,8 @@ private:
|
|||||||
void HandleDisconnection(Disconnect&);
|
void HandleDisconnection(Disconnect&);
|
||||||
|
|
||||||
//services
|
//services
|
||||||
ConfigUtility* configUtil = nullptr;
|
ConfigUtility* configUtil = Singleton<ConfigUtility>::Get();
|
||||||
UDPNetworkUtility* netUtil = nullptr;
|
UDPNetworkUtility* netUtil = Singleton<UDPNetworkUtility>::Get();
|
||||||
|
|
||||||
//members
|
//members
|
||||||
Clock::time_point lastTick = Clock::now();
|
Clock::time_point lastTick = Clock::now();
|
||||||
|
|||||||
+1
-5
@@ -1,5 +1 @@
|
|||||||
#include "service_locator.hpp"
|
#include "foobar.hpp"
|
||||||
|
|
||||||
int FooBar() {
|
|
||||||
return *ServiceLocator<int>::Get();
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user