From 17d5d86aee1f22f06b450380a221937d7217757a Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Mon, 2 May 2011 14:37:04 +0100 Subject: [PATCH] Code tidy --- src/Main.cpp | 32 ++++++++++++++++---------------- src/ScreenManager.cpp | 20 ++++++++++---------- src/ScreenManager.hpp | 8 ++++---- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index b6d8f48..1e5b257 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -39,23 +39,23 @@ namespace CF { #include namespace { - MainMenu* menu = NULL; - Game* game = NULL; + MainMenu* menu = NULL; + Game* game = NULL; HighScores* scores = NULL; - Options* options = NULL; + Options* options = NULL; +} - void DestroyScreens() - { - ScreenManager::GetInstance().RemoveAllScreens(); - if (menu) - delete menu; - if (game) - delete game; - if (scores) - delete scores; - if (options) - delete options; - } +static void DestroyScreens() +{ + ScreenManager::GetInstance().RemoveAllScreens(); + if (menu) + delete menu; + if (game) + delete game; + if (scores) + delete scores; + if (options) + delete options; } // @@ -194,7 +194,7 @@ string LocateResource(const string& file) cfBase = CFStringCreateWithCString(NULL, copy, kCFStringEncodingASCII); cfExt = CFStringCreateWithCString(NULL, ext, kCFStringEncodingASCII); - free(copy); + free(copy); mainBundle = CFBundleGetMainBundle(); diff --git a/src/ScreenManager.cpp b/src/ScreenManager.cpp index 545bcf2..875e9df 100644 --- a/src/ScreenManager.cpp +++ b/src/ScreenManager.cpp @@ -1,6 +1,6 @@ // // Screen.cpp - Implementation of the ScreenManager class. -// Copyright (C) 2006 Nick Gasson +// Copyright (C) 2006, 2011 Nick Gasson // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -42,19 +42,19 @@ ScreenManager& ScreenManager::GetInstance() return sm; } -void ScreenManager::AddScreen(const char* id, Screen* ptr) +void ScreenManager::AddScreen(const string& id, Screen* ptr) { - if (screens.find(string(id)) != screens.end()) - throw runtime_error("Screen already registered: " + string(id)); + if (screens.find(id) != screens.end()) + throw runtime_error("Screen already registered: " + id); ScreenData sd; sd.loaded = false; sd.ptr = ptr; - screens[string(id)] = sd; + screens[id] = sd; } -void ScreenManager::SelectScreen(const string id) +void ScreenManager::SelectScreen(const string& id) { ScreenMapIt it = screens.find(id); @@ -71,13 +71,13 @@ void ScreenManager::SelectScreen(const string id) OpenGL::GetInstance().SkipDisplay(); } -Screen* ScreenManager::GetScreenById(const char* id) const +Screen* ScreenManager::GetScreenById(const string& id) const { ScreenMap::const_iterator it; - it = screens.find(string(id)); + it = screens.find(id); if (it == screens.end()) - throw runtime_error("Screen " + string(id) + " does not exist"); + throw runtime_error("Screen " + id + " does not exist"); else return (*it).second.ptr; } @@ -92,7 +92,7 @@ void ScreenManager::Process() void ScreenManager::Display() { - if (active.ptr != NULL) { + if (active.ptr != NULL) { assert(active.loaded); active.ptr->Display(); } diff --git a/src/ScreenManager.hpp b/src/ScreenManager.hpp index 898bc40..4aa05d0 100644 --- a/src/ScreenManager.hpp +++ b/src/ScreenManager.hpp @@ -1,6 +1,6 @@ // // Screens.hpp - Definition of abstract class to represent game screens. -// Copyright (C) 2006 Nick Gasson +// Copyright (C) 2006, 2011 Nick Gasson // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -43,12 +43,12 @@ class ScreenManager { public: static ScreenManager& GetInstance(); - void AddScreen(const char* id, Screen* ptr); - void SelectScreen(const string id); + void AddScreen(const string& id, Screen* ptr); + void SelectScreen(const string& id); void Process(); void Display(); void RemoveAllScreens(); - Screen* GetScreenById(const char* id) const; + Screen* GetScreenById(const string& id) const; private: ScreenManager(); -- 2.39.2