Implemented the changes to ConfigUtility in the client and server

The server's changes were easy. The clients means that the constructors
for each scene have one less argument, and each scene has one less member.
The exception to this is LobbyMenu, where the config is used in multiple
places, so it was easier to have the config's reference as a member.

To replace the config's usage, I added this line in most cases:

ConfigUtility& config = ConfigUtility::GetSingleton();

The only requirement is that ConfigUtility::Create() and
ConfigUtility::Delete() are called from the main() function.
This commit is contained in:
Kayne Ruse
2014-08-03 23:20:39 +10:00
parent c830fa0537
commit fd320767c5
20 changed files with 59 additions and 56 deletions
+9 -7
View File
@@ -22,6 +22,7 @@
#include "client_application.hpp"
#include "serial.hpp"
#include "config_utility.hpp"
#include <stdexcept>
#include <chrono>
@@ -48,6 +49,7 @@ void ClientApplication::Init(int argc, char** argv) {
std::cout << "Beginning " << argv[0] << std::endl;
//load the prerequisites
ConfigUtility& config = ConfigUtility::GetSingleton();
config.Load("rsc\\config.cfg");
//-------------------------
@@ -165,25 +167,25 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
//add scene creation calls here
case SceneList::FIRST:
case SceneList::SPLASHSCREEN:
activeScene = new SplashScreen(&config);
activeScene = new SplashScreen();
break;
case SceneList::MAINMENU:
activeScene = new MainMenu(&config);
activeScene = new MainMenu();
break;
case SceneList::OPTIONSMENU:
activeScene = new OptionsMenu(&config);
activeScene = new OptionsMenu();
break;
case SceneList::LOBBYMENU:
activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex);
activeScene = new LobbyMenu(&network, &clientIndex, &accountIndex);
break;
case SceneList::INWORLD:
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
activeScene = new InWorld(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
break;
case SceneList::INCOMBAT:
activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
activeScene = new InCombat(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
break;
case SceneList::CLEANUP:
activeScene = new CleanUp(&config, &network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
activeScene = new CleanUp(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
break;
default:
throw(std::logic_error("Failed to recognize the scene index"));
-2
View File
@@ -25,7 +25,6 @@
#include "scene_list.hpp"
#include "base_scene.hpp"
#include "config_utility.hpp"
#include "udp_network_utility.hpp"
#include "character.hpp"
@@ -48,7 +47,6 @@ private:
BaseScene* activeScene = nullptr;
//shared parameters
ConfigUtility config;
UDPNetworkUtility network;
int clientIndex = -1;
int accountIndex = -1;
+10
View File
@@ -21,6 +21,9 @@
*/
#include "client_application.hpp"
//singletons
#include "config_utility.hpp"
#include <stdexcept>
#include <iostream>
@@ -28,10 +31,17 @@ using namespace std;
int main(int argc, char** argv) {
try {
//create the singletons
ConfigUtility::Create();
//call the server's routines
ClientApplication app;
app.Init(argc, argv);
app.Proc();
app.Quit();
//delete the singletons
ConfigUtility::Delete();
}
catch(exception& e) {
cerr << "Fatal exception thrown: " << e.what() << endl;
+3 -2
View File
@@ -22,6 +22,7 @@
#include "clean_up.hpp"
#include "channels.hpp"
#include "config_utility.hpp"
#include <stdexcept>
@@ -30,20 +31,20 @@
//-------------------------
CleanUp::CleanUp(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
CharacterMap* argCharacterMap
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex),
characterMap(*argCharacterMap)
{
ConfigUtility& config = ConfigUtility::GetSingleton();
//setup the utility objects
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3);
-3
View File
@@ -31,7 +31,6 @@
#include "button.hpp"
//common
#include "config_utility.hpp"
#include "frame_rate.hpp"
#include "character.hpp"
@@ -46,7 +45,6 @@ class CleanUp : public BaseScene {
public:
//Public access members
CleanUp(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
@@ -70,7 +68,6 @@ protected:
void KeyUp(SDL_KeyboardEvent const&);
//shared parameters
ConfigUtility& config;
UDPNetworkUtility& network;
int& clientIndex;
int& accountIndex;
+1 -2
View File
@@ -23,6 +23,7 @@
#include "channels.hpp"
#include "utility.hpp"
#include "config_utility.hpp"
#include <stdexcept>
@@ -31,14 +32,12 @@
//-------------------------
InCombat::InCombat(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
CharacterMap* argCharacterMap
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex),
-3
View File
@@ -31,7 +31,6 @@
#include "button.hpp"
//common
#include "config_utility.hpp"
#include "frame_rate.hpp"
#include "character.hpp"
@@ -43,7 +42,6 @@ class InCombat : public BaseScene {
public:
//Public access members
InCombat(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
@@ -79,7 +77,6 @@ protected:
void RequestShutdown();
//shared parameters
ConfigUtility& config;
UDPNetworkUtility& network;
int& clientIndex;
int& accountIndex;
+4 -3
View File
@@ -23,6 +23,7 @@
#include "channels.hpp"
#include "utility.hpp"
#include "config_utility.hpp"
#include <stdexcept>
#include <algorithm>
@@ -34,20 +35,20 @@
//-------------------------
InWorld::InWorld(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
CharacterMap* argCharacterMap
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex),
characterMap(*argCharacterMap)
{
ConfigUtility& config = ConfigUtility::GetSingleton();
//setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
buttonImage.SetClipH(buttonImage.GetClipH()/3);
@@ -302,7 +303,7 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
newCharacter.SetHandle(argPacket->handle);
newCharacter.SetAvatar(argPacket->avatar);
newCharacter.GetSprite()->LoadSurface(config["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
newCharacter.GetSprite()->LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
newCharacter.SetOrigin(argPacket->origin);
newCharacter.SetMotion(argPacket->motion);
-3
View File
@@ -35,7 +35,6 @@
#include "tile_sheet.hpp"
//common
#include "config_utility.hpp"
#include "frame_rate.hpp"
#include "character.hpp"
@@ -50,7 +49,6 @@ class InWorld : public BaseScene {
public:
//Public access members
InWorld(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
@@ -94,7 +92,6 @@ protected:
void UpdateMap();
//shared parameters
ConfigUtility& config;
UDPNetworkUtility& network;
int& clientIndex;
int& accountIndex;
-2
View File
@@ -31,12 +31,10 @@
//-------------------------
LobbyMenu::LobbyMenu(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex)
+1 -2
View File
@@ -41,7 +41,6 @@ class LobbyMenu : public BaseScene {
public:
//Public access members
LobbyMenu(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex
@@ -68,7 +67,7 @@ protected:
void HandleJoinResponse(ClientPacket* const);
//shared parameters
ConfigUtility& config;
ConfigUtility& config = ConfigUtility::GetSingleton();
UDPNetworkUtility& network;
int& clientIndex;
int& accountIndex;
+5 -3
View File
@@ -21,13 +21,15 @@
*/
#include "main_menu.hpp"
#include "config_utility.hpp"
//-------------------------
//Public access members
//-------------------------
MainMenu::MainMenu(ConfigUtility* const argConfig):
config(*argConfig)
{
MainMenu::MainMenu() {
ConfigUtility& config = ConfigUtility::GetSingleton();
//setup the utility objects
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3);
+1 -5
View File
@@ -24,7 +24,6 @@
#include "base_scene.hpp"
#include "config_utility.hpp"
#include "image.hpp"
#include "raster_font.hpp"
#include "button.hpp"
@@ -32,7 +31,7 @@
class MainMenu : public BaseScene {
public:
//Public access members
MainMenu(ConfigUtility* const);
MainMenu();
~MainMenu();
protected:
@@ -49,9 +48,6 @@ protected:
void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&);
//shared parameters
ConfigUtility& config;
//members
Image image;
RasterFont font;
+5 -3
View File
@@ -21,13 +21,15 @@
*/
#include "options_menu.hpp"
#include "config_utility.hpp"
//-------------------------
//Public access members
//-------------------------
OptionsMenu::OptionsMenu(ConfigUtility* const argConfig):
config(*argConfig)
{
OptionsMenu::OptionsMenu() {
ConfigUtility& config = ConfigUtility::GetSingleton();
//setup the utility objects
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3);
+1 -5
View File
@@ -24,7 +24,6 @@
#include "base_scene.hpp"
#include "config_utility.hpp"
#include "image.hpp"
#include "raster_font.hpp"
#include "button.hpp"
@@ -33,7 +32,7 @@
class OptionsMenu : public BaseScene {
public:
//Public access members
OptionsMenu(ConfigUtility* const);
OptionsMenu();
~OptionsMenu();
protected:
@@ -50,9 +49,6 @@ protected:
void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&);
//shared parameters
ConfigUtility& config;
//members
Image image;
RasterFont font;
+4 -4
View File
@@ -21,14 +21,14 @@
*/
#include "splash_screen.hpp"
#include "config_utility.hpp"
//-------------------------
//Public access members
//-------------------------
SplashScreen::SplashScreen(ConfigUtility* const argConfig):
config(*argConfig)
{
logo.LoadSurface(config["dir.logos"] + "krstudios.bmp");
SplashScreen::SplashScreen() {
logo.LoadSurface(ConfigUtility::GetSingleton()["dir.logos"] + "krstudios.bmp");
startTick = std::chrono::steady_clock::now();
}
+1 -5
View File
@@ -24,7 +24,6 @@
#include "base_scene.hpp"
#include "config_utility.hpp"
#include "image.hpp"
#include <chrono>
@@ -32,7 +31,7 @@
class SplashScreen : public BaseScene {
public:
//Public access members
SplashScreen(ConfigUtility* const);
SplashScreen();
~SplashScreen();
protected:
@@ -40,9 +39,6 @@ protected:
void Update(double delta);
void Render(SDL_Surface* const);
//shared parameters
ConfigUtility& config;
//members
std::chrono::steady_clock::time_point startTick;
Image logo;
+2
View File
@@ -8,6 +8,8 @@ server.name = local
server.dbname = database.db
#client specific settings
#client.screen.w = 800
#client.screen.h = 600
client.screen.f = false
client.username = Kayne Ruse
+10
View File
@@ -21,6 +21,9 @@
*/
#include "server_application.hpp"
//singletons
#include "config_utility.hpp"
#include <stdexcept>
#include <iostream>
@@ -28,10 +31,17 @@ using namespace std;
int main(int argc, char** argv) {
try {
//create the singletons
ConfigUtility::Create();
//call the server's routines
ServerApplication app;
app.Init(argc, argv);
app.Proc();
app.Quit();
//delete the singletons
ConfigUtility::Delete();
}
catch(exception& e) {
cerr << "Fatal exception thrown: " << e.what() << endl;
+1 -1
View File
@@ -83,7 +83,7 @@ private:
sqlite3* database = nullptr;
lua_State* luaState = nullptr;
UDPNetworkUtility network;
ConfigUtility config;
ConfigUtility& config = ConfigUtility::GetSingleton();
//simple tables
std::map<int, ClientData> clientMap;