ClientApplication and ServerApplication are now Singletons
This commit is contained in:
@@ -28,18 +28,23 @@
|
|||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
#include "character.hpp"
|
#include "character.hpp"
|
||||||
|
|
||||||
|
#include "singleton.hpp"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class ClientApplication {
|
class ClientApplication: public Singleton<ClientApplication> {
|
||||||
public:
|
public:
|
||||||
ClientApplication() = default;
|
//public methods
|
||||||
~ClientApplication() = default;
|
|
||||||
|
|
||||||
void Init(int argc, char** argv);
|
void Init(int argc, char** argv);
|
||||||
void Proc();
|
void Proc();
|
||||||
void Quit();
|
void Quit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend Singleton<ClientApplication>;
|
||||||
|
|
||||||
|
ClientApplication() = default;
|
||||||
|
~ClientApplication() = default;
|
||||||
|
|
||||||
//Private access members
|
//Private access members
|
||||||
void LoadScene(SceneList sceneIndex);
|
void LoadScene(SceneList sceneIndex);
|
||||||
void UnloadScene();
|
void UnloadScene();
|
||||||
|
|||||||
+3
-1
@@ -32,16 +32,18 @@ using namespace std;
|
|||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
try {
|
try {
|
||||||
//create the singletons
|
//create the singletons
|
||||||
|
ClientApplication::Create();
|
||||||
ConfigUtility::Create();
|
ConfigUtility::Create();
|
||||||
|
|
||||||
//call the server's routines
|
//call the server's routines
|
||||||
ClientApplication app;
|
ClientApplication& app = ClientApplication::GetSingleton();
|
||||||
app.Init(argc, argv);
|
app.Init(argc, argv);
|
||||||
app.Proc();
|
app.Proc();
|
||||||
app.Quit();
|
app.Quit();
|
||||||
|
|
||||||
//delete the singletons
|
//delete the singletons
|
||||||
ConfigUtility::Delete();
|
ConfigUtility::Delete();
|
||||||
|
ClientApplication::Delete();
|
||||||
}
|
}
|
||||||
catch(exception& e) {
|
catch(exception& e) {
|
||||||
cerr << "Fatal exception thrown: " << e.what() << endl;
|
cerr << "Fatal exception thrown: " << e.what() << endl;
|
||||||
|
|||||||
+3
-1
@@ -33,15 +33,17 @@ int main(int argc, char** argv) {
|
|||||||
try {
|
try {
|
||||||
//create the singletons
|
//create the singletons
|
||||||
ConfigUtility::Create();
|
ConfigUtility::Create();
|
||||||
|
ServerApplication::Create();
|
||||||
|
|
||||||
//call the server's routines
|
//call the server's routines
|
||||||
ServerApplication app;
|
ServerApplication& app = ServerApplication::GetSingleton();
|
||||||
app.Init(argc, argv);
|
app.Init(argc, argv);
|
||||||
app.Proc();
|
app.Proc();
|
||||||
app.Quit();
|
app.Quit();
|
||||||
|
|
||||||
//delete the singletons
|
//delete the singletons
|
||||||
ConfigUtility::Delete();
|
ConfigUtility::Delete();
|
||||||
|
ServerApplication::Delete();
|
||||||
}
|
}
|
||||||
catch(exception& e) {
|
catch(exception& e) {
|
||||||
cerr << "Fatal exception thrown: " << e.what() << endl;
|
cerr << "Fatal exception thrown: " << e.what() << endl;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
//common utilities
|
//common utilities
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
|
#include "singleton.hpp"
|
||||||
|
|
||||||
//APIs
|
//APIs
|
||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
@@ -42,17 +43,19 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//The main application class
|
//The main application class
|
||||||
class ServerApplication {
|
class ServerApplication: public Singleton<ServerApplication> {
|
||||||
public:
|
public:
|
||||||
//public methods
|
//public methods
|
||||||
ServerApplication() = default;
|
|
||||||
~ServerApplication() = default;
|
|
||||||
|
|
||||||
void Init(int argc, char** argv);
|
void Init(int argc, char** argv);
|
||||||
void Proc();
|
void Proc();
|
||||||
void Quit();
|
void Quit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend Singleton<ServerApplication>;
|
||||||
|
|
||||||
|
ServerApplication() = default;
|
||||||
|
~ServerApplication() = default;
|
||||||
|
|
||||||
//handle incoming traffic
|
//handle incoming traffic
|
||||||
void HandlePacket(SerialPacket* const);
|
void HandlePacket(SerialPacket* const);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user