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
+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;