diff --git a/Bin/LibD.pro b/Bin/LibD.pro index 17819f7..0077d10 100644 --- a/Bin/LibD.pro +++ b/Bin/LibD.pro @@ -51,7 +51,6 @@ HEADERS += ../src/Actor/Player.h \ ../src/System/Filesystem/FilePackageManager.h \ ../src/System/Filesystem/InputStreamWrapper.h \ ../src/System/Filesystem/MemoryStream.h \ - ../src/System/Filesystem/SCCopyFile.cpp \ ../src/System/Filesystem/Checksum.h \ ../src/Texture/Texture.h \ ../src/Sound/Music.h \ @@ -61,7 +60,6 @@ HEADERS += ../src/Actor/Player.h \ ../src/Sound/SoundEffect.h \ ../src/Actor/Actor.h \ ../src/Animation/AnimimationSequence.h \ - ../src/System/FileReader.h \ ../src/Animation/AnimationSequence.h \ ../src/System/String.h \ ../src/Font/Font.h \ @@ -85,7 +83,9 @@ HEADERS += ../src/Actor/Player.h \ ../src/TMXParser/TmxImage.h \ ../src/TMXParser/Tmx.h \ ../src/TMXParser/base64/base64.h \ - ../src/TMXParser/TmxUtil.h + ../src/TMXParser/TmxUtil.h \ + ../src/System/Filesystem/SCCopyFile.h \ + ../src/System/Filesystem/FileReader.h SOURCES += ../src/Actor/Player.cpp \ ../src/Collision/AABB.cpp \ @@ -120,7 +120,6 @@ SOURCES += ../src/Actor/Player.cpp \ ../src/Actor/NPC.cpp \ ../src/Sound/SoundEffect.cpp \ ../src/Actor/Actor.cpp \ - ../src/System/FileReader.cpp \ ../src/Animation/AnimationSequence.cpp \ ../src/System/String.cpp \ ../src/Font/Font.cpp \ @@ -141,6 +140,7 @@ SOURCES += ../src/Actor/Player.cpp \ ../src/TMXParser/TmxLayer.cpp \ ../src/TMXParser/TmxImage.cpp \ ../src/TMXParser/base64/base64.cpp \ - ../src/TMXParser/TmxUtil.cpp + ../src/TMXParser/TmxUtil.cpp \ + ../src/System/Filesystem/FileReader.cpp QMAKE_CLEAN += LibD Debug.log diff --git a/src/Animation/AnimationSequence.cpp b/src/Animation/AnimationSequence.cpp index 1067168..f38acf1 100644 --- a/src/Animation/AnimationSequence.cpp +++ b/src/Animation/AnimationSequence.cpp @@ -3,6 +3,8 @@ #include "../System/Debug.h" #include "AnimationSequence.h" +using saracraft::util::Debug; + /* * Load and read a sequence file for an animating sprite then * stores the result so you can call the sprites animation at any time. diff --git a/src/Animation/AnimationSequence.h b/src/Animation/AnimationSequence.h index 9077bb4..8be26e3 100644 --- a/src/Animation/AnimationSequence.h +++ b/src/Animation/AnimationSequence.h @@ -2,7 +2,7 @@ #include #include -#include "../System/FileReader.h" +#include "../System/Filesystem/FileReader.h" #include "../System/String.h" #define MAX_FRAMES 16 @@ -10,6 +10,9 @@ #define ENDOFLINE 59 #define SPACE 32 +using saracraft::util::String; +using saracraft::filesystem::FileReader; + struct Animation { String _animationID; int frameBegin; diff --git a/src/BattleSys/Slot.cpp b/src/BattleSys/Slot.cpp index da56a44..ae3c382 100644 --- a/src/BattleSys/Slot.cpp +++ b/src/BattleSys/Slot.cpp @@ -1,5 +1,7 @@ #include "Slot.h" +using saracraft::util::Debug; + Slot::Slot(void) { _triggered = false; _selected = false; diff --git a/src/Font/Font.cpp b/src/Font/Font.cpp index 247ddd5..4907e89 100644 --- a/src/Font/Font.cpp +++ b/src/Font/Font.cpp @@ -3,6 +3,8 @@ #include "../System/Debug.h" #include "Font.h" +using saracraft::util::Debug; + Font::Font(void) { _texture = 0; _spaceWidth = 0; diff --git a/src/IO/Input.cpp b/src/IO/Input.cpp index a983ef2..35651ad 100644 --- a/src/IO/Input.cpp +++ b/src/IO/Input.cpp @@ -1,6 +1,8 @@ #include #include "Input.h" +using saracraft::util::Debug; + static mouse_t mouse; static keyboard_t keyboard; diff --git a/src/Level/Level.cpp b/src/Level/Level.cpp index 73bf1a9..6ccbe4a 100644 --- a/src/Level/Level.cpp +++ b/src/Level/Level.cpp @@ -20,6 +20,8 @@ #endif #endif +using saracraft::util::Debug; + Level::Level(Game* game) { _game = game; _width = 0; diff --git a/src/Level/Warp.h b/src/Level/Warp.h index ed78330..34f276d 100644 --- a/src/Level/Warp.h +++ b/src/Level/Warp.h @@ -3,6 +3,8 @@ #include "../System/String.h" #include "../Math/Vec2.h" +using saracraft::util::String; + class Warp { public: Warp(void); diff --git a/src/Main/Game.cpp b/src/Main/Game.cpp index f60d836..2909a0b 100644 --- a/src/Main/Game.cpp +++ b/src/Main/Game.cpp @@ -21,6 +21,8 @@ #include "Game.h" #include "TitleScreen.h" +using saracraft::util::Debug; + Game::Game(void) { _level = new Level(this); _player = new Player(_level); diff --git a/src/Main/main.cpp b/src/Main/main.cpp index 7490514..34d948b 100644 --- a/src/Main/main.cpp +++ b/src/Main/main.cpp @@ -20,6 +20,8 @@ #include "../Global/Constants.h" #include "../System/Debug.h" +using saracraft::util::Debug; + void Destroy(void) { TTF_Quit(); Mix_CloseAudio(); diff --git a/src/Sound/Music.cpp b/src/Sound/Music.cpp index 9dd2799..d072630 100644 --- a/src/Sound/Music.cpp +++ b/src/Sound/Music.cpp @@ -2,7 +2,7 @@ #include "Music.h" -ResourceManager musicManager; +saracraft::util::ResourceManager musicManager; Music::Music() : Resource() { _music = NULL; diff --git a/src/Sound/Music.h b/src/Sound/Music.h index 5df09e5..fe22160 100644 --- a/src/Sound/Music.h +++ b/src/Sound/Music.h @@ -4,8 +4,8 @@ struct _Mix_Music; -class Music : public Resource { - template friend class ResourceManager; +class Music : public saracraft::util::Resource { + template friend class saracraft::util::ResourceManager; public: Music(); @@ -21,4 +21,4 @@ private: struct _Mix_Music* _music; }; -extern ResourceManager musicManager; +extern saracraft::util::ResourceManager musicManager; diff --git a/src/Sound/SoundEffect.cpp b/src/Sound/SoundEffect.cpp index e72897b..6d77f5c 100644 --- a/src/Sound/SoundEffect.cpp +++ b/src/Sound/SoundEffect.cpp @@ -2,7 +2,7 @@ #include "SoundEffect.h" -ResourceManager sfxManager; +saracraft::util::ResourceManager sfxManager; SoundEffect::SoundEffect() { _chunk = NULL; diff --git a/src/Sound/SoundEffect.h b/src/Sound/SoundEffect.h index c77b8ef..b37ebbc 100644 --- a/src/Sound/SoundEffect.h +++ b/src/Sound/SoundEffect.h @@ -4,8 +4,8 @@ struct Mix_Chunk; -class SoundEffect : public Resource { - template friend class ResourceManager; +class SoundEffect : public saracraft::util::Resource { + template friend class saracraft::util::ResourceManager; public: SoundEffect(); @@ -22,4 +22,4 @@ private: Mix_Chunk* _chunk; }; -extern ResourceManager sfxManager; +extern saracraft::util::ResourceManager sfxManager; diff --git a/src/System/Convert/ConvertType.h b/src/System/Convert/ConvertType.h index ca93ad9..1d4c4f6 100644 --- a/src/System/Convert/ConvertType.h +++ b/src/System/Convert/ConvertType.h @@ -6,7 +6,7 @@ #endif namespace saracraft { -namespace filesystem { +namespace util { template struct ConvertBase { @@ -50,6 +50,5 @@ struct ConvertTo: private ConvertBase { typedef unsigned short uint16_t; -} // Namespaces.... -} - +} // Namespace util. +} // Namespace saracraft. diff --git a/src/System/Convert/str2int.h b/src/System/Convert/str2int.h index 1f6cece..c763287 100644 --- a/src/System/Convert/str2int.h +++ b/src/System/Convert/str2int.h @@ -1,7 +1,12 @@ #pragma once +namespace saracraft { +namespace util { + extern char* int2str(int value); extern int str2int(const char* string); extern int str2int_errno(void); extern char* time2str(int secs); // hh:mm::ss. +} // Namespace util. +} // Namespace saracraft. diff --git a/src/System/Debug.cpp b/src/System/Debug.cpp index d743bbc..7f83f2b 100644 --- a/src/System/Debug.cpp +++ b/src/System/Debug.cpp @@ -8,6 +8,9 @@ using namespace std; +namespace saracraft { +namespace util { + // =================================================================== // The Debug log allows us to display ever piece of data that // populates our class components, anything that is loaded, serialized, @@ -100,3 +103,6 @@ void Debug::closeLog(void) { delete logger; logger = NULL; } + +} // End of namespace util. +} // End of namespace saracraft. diff --git a/src/System/Debug.h b/src/System/Debug.h index e418cae..5699784 100644 --- a/src/System/Debug.h +++ b/src/System/Debug.h @@ -3,6 +3,9 @@ #include #include "string" +namespace saracraft { +namespace util { + class Debug { public: Debug(bool logToFile); @@ -20,4 +23,7 @@ private: std::ofstream _logFile; }; +} // Namespace util. +} // Namespace saracraft. + #endif // _DEBUG_H_ diff --git a/src/System/Filesystem/Checksum.cpp b/src/System/Filesystem/Checksum.cpp index d0381a8..1d4a240 100644 --- a/src/System/Filesystem/Checksum.cpp +++ b/src/System/Filesystem/Checksum.cpp @@ -3,7 +3,8 @@ #include #include -using namespace saracraft; +namespace saracraft { +namespace filesystem { unsigned int Checksum::CountChecksumForFile(const char* filename) { unsigned int chksum = 0; @@ -66,3 +67,5 @@ bool Checksum::CountChecksumForFileImpl(unsigned int* checksum, int* filesize, c } } +} // End of namespace filesystem. +} // End of namespace saracraft. diff --git a/src/System/Filesystem/Checksum.h b/src/System/Filesystem/Checksum.h index 7fce821..6b80e3c 100644 --- a/src/System/Filesystem/Checksum.h +++ b/src/System/Filesystem/Checksum.h @@ -1,5 +1,8 @@ #pragma once +namespace saracraft { +namespace filesystem { + class Checksum { public: static unsigned int CountChecksumForFile(const char* filename); @@ -10,3 +13,5 @@ private: int* filesize, const char* filename); }; +} // Namespace filesystem. +} // Namespace saracraft. diff --git a/src/System/Filesystem/FileList.cpp b/src/System/Filesystem/FileList.cpp index 485b3a9..5850366 100644 --- a/src/System/Filesystem/FileList.cpp +++ b/src/System/Filesystem/FileList.cpp @@ -9,6 +9,7 @@ using namespace boost; namespace saracraft { namespace filesystem { + namespace { struct Dir; @@ -75,6 +76,7 @@ int GetDirNameImpl(const IteratorList& list, string& result, int currentIndex, i string empty; } // Namespace unamed. + struct FileList::Data { bool caseSensitive; DirList dirs; diff --git a/src/System/Filesystem/FilePackageManager.cpp b/src/System/Filesystem/FilePackageManager.cpp index f7226e8..b6514da 100644 --- a/src/System/Filesystem/FilePackageManager.cpp +++ b/src/System/Filesystem/FilePackageManager.cpp @@ -10,12 +10,15 @@ namespace saracraft { namespace filesystem { + namespace { typedef std::multimap > PackageMap; FilePackageManager instance; FilePackageManager* instancePtr = 0; } // Unamed namespace. +using namespace util; + struct FilePackageManagerData { PackageMap packages; bool logNonExisting; diff --git a/src/System/FileReader.cpp b/src/System/Filesystem/FileReader.cpp similarity index 95% rename from src/System/FileReader.cpp rename to src/System/Filesystem/FileReader.cpp index d0c5277..561e94e 100644 --- a/src/System/FileReader.cpp +++ b/src/System/Filesystem/FileReader.cpp @@ -1,9 +1,12 @@ #include #include -#include "Debug.h" +#include "../Debug.h" #include "FileReader.h" +namespace saracraft { +namespace filesystem { + FileReader::FileReader(void) { } @@ -109,3 +112,6 @@ void FileReader::ReadBuffer(const char* buffer, int count) { } } } + +} // Namespace filesystem. +} // Namespace saracraft. diff --git a/src/System/FileReader.h b/src/System/Filesystem/FileReader.h similarity index 81% rename from src/System/FileReader.h rename to src/System/Filesystem/FileReader.h index 6845a16..d10eb4f 100644 --- a/src/System/FileReader.h +++ b/src/System/Filesystem/FileReader.h @@ -2,7 +2,12 @@ #include #include -#include "../System/String.h" +#include "../String.h" + +namespace saracraft { +namespace filesystem { + +using util::String; class FileReader { public: @@ -28,3 +33,6 @@ private: String _filename; String _accessType; }; + +} // Namespace filesystem. +} // Namespace saracraft. diff --git a/src/System/Filesystem/FileTimestampChecker.cpp b/src/System/Filesystem/FileTimestampChecker.cpp index 9c69732..8603467 100644 --- a/src/System/Filesystem/FileTimestampChecker.cpp +++ b/src/System/Filesystem/FileTimestampChecker.cpp @@ -10,7 +10,8 @@ #include "InputStreamWrapper.h" #include "FileTimestampChecker.h" -using namespace saracraft; +namespace saracraft { +namespace filesystem { /*bool FileTimestampChecker::IsFileNewerThanFile(const char* file, const char* secondFile) { assert @@ -80,3 +81,5 @@ int FileTimestampChecker::GetFileTimestamp(const char* file) { return ret; } +} // End of namespace filesystem. +} // End of namespace saracraft. diff --git a/src/System/Filesystem/FileTimestampChecker.h b/src/System/Filesystem/FileTimestampChecker.h index 2c5b7f6..a24ffa3 100644 --- a/src/System/Filesystem/FileTimestampChecker.h +++ b/src/System/Filesystem/FileTimestampChecker.h @@ -1,5 +1,8 @@ #pragma once +namespace saracraft { +namespace filesystem { + class FileTimestampChecker { public: // Check if the given file with given name has been modified after another @@ -15,3 +18,5 @@ public: static int GetFileTimestamp(const char *file); }; +} // Namespace filesystem. +} // Namespace saracraft. diff --git a/src/System/Filesystem/InputStream.cpp b/src/System/Filesystem/InputStream.cpp index c7d6f91..7d2c8a9 100644 --- a/src/System/Filesystem/InputStream.cpp +++ b/src/System/Filesystem/InputStream.cpp @@ -8,7 +8,7 @@ #pragma warning(disable: 444) // I think intel will complain at the base class not being virtual. #endif -BOOST_STATIC_ASSERT(sizeof(saracraft::filesystem::uint16_t) * CHAR_BIT == 16); +BOOST_STATIC_ASSERT(sizeof(saracraft::util::uint16_t) * CHAR_BIT == 16); BOOST_STATIC_ASSERT(CHAR_BIT == 8); namespace saracraft { @@ -17,7 +17,7 @@ namespace { template void ReadFromStream(IInputStreamBuffer& buffer, T& value) { - ConvertTo converter; + util::ConvertTo converter; for(int i = 0; i < converter.GetSize(); ++i) converter.SetByte(i, buffer.PopByte()); @@ -52,7 +52,7 @@ int InputStream::GetSize(void) const { InputStream& InputStream::Read(std::string& value) { assert(_streamBuffer); - uint16_t stringSize = 0; + util::uint16_t stringSize = 0; this->Read(stringSize); value.resize(stringSize); diff --git a/src/System/Filesystem/InputStreamWrapper.cpp b/src/System/Filesystem/InputStreamWrapper.cpp index 0f84b66..bbda110 100644 --- a/src/System/Filesystem/InputStreamWrapper.cpp +++ b/src/System/Filesystem/InputStreamWrapper.cpp @@ -18,6 +18,8 @@ namespace { Tracker tracker; } // Namespace Unamed. +using namespace util; + struct SC_FILE { InputStream stream; diff --git a/src/System/Filesystem/OutputStream.cpp b/src/System/Filesystem/OutputStream.cpp index bd574bc..3176b19 100644 --- a/src/System/Filesystem/OutputStream.cpp +++ b/src/System/Filesystem/OutputStream.cpp @@ -8,7 +8,7 @@ #pragma warning(disable: 444) // I think intel will complain at the base class not being virtual. #endif -BOOST_STATIC_ASSERT(sizeof(saracraft::filesystem::uint16_t) * CHAR_BIT == 16); +BOOST_STATIC_ASSERT(sizeof(saracraft::util::uint16_t) * CHAR_BIT == 16); BOOST_STATIC_ASSERT(CHAR_BIT == 8); namespace saracraft { @@ -17,7 +17,7 @@ namespace { template void SendToStream(IOutputStreamBuffer& buffer, T& value) { - ConvertFrom converter(value); + util::ConvertFrom converter(value); for(int i = 0; i < converter.GetSize(); ++i) buffer.PutByte(converter.GetByte(i)); } @@ -45,7 +45,7 @@ void OutputStream::UseTextStrings(void) { OutputStream& OutputStream::Write(std::string& value) { assert(_streamBuffer); - uint16_t stringSize = 0; + util::uint16_t stringSize = 0; if(!_textStrings) Write(stringSize); diff --git a/src/System/Filesystem/SCCopyFile.cpp b/src/System/Filesystem/SCCopyFile.cpp index c29eda4..20f8605 100644 --- a/src/System/Filesystem/SCCopyFile.cpp +++ b/src/System/Filesystem/SCCopyFile.cpp @@ -5,7 +5,8 @@ #include "SCCopyFile.h" -namespace util { +namespace saracraft { +namespace filesystem { void SCCopyFile::CopyFile(const std::string& from, const std::string& to) { std::fstream out(to.c_str(), std::ios::out); @@ -19,5 +20,6 @@ void SCCopyFile::CopyFile(const std::string& from, const std::string& to) { out.close(); } -} // Namespace util. +} // Namespace filesystem. +} // Namespace saracraft. diff --git a/src/System/Filesystem/SCCopyFile.h b/src/System/Filesystem/SCCopyFile.h index 4c404a1..9d8fda7 100644 --- a/src/System/Filesystem/SCCopyFile.h +++ b/src/System/Filesystem/SCCopyFile.h @@ -1,6 +1,7 @@ #pragma once -namespace util { +namespace saracraft { +namespace filesystem { class SCCopyFile { public: @@ -12,5 +13,5 @@ public: static void CopyFile(const std::string& from, const std::string& to); }; -} // Namespace util. - +} // Namespace filesystem. +} // Namespace saracraft. diff --git a/src/System/ResourceManager.h b/src/System/ResourceManager.h index a5b706e..8104643 100644 --- a/src/System/ResourceManager.h +++ b/src/System/ResourceManager.h @@ -5,6 +5,9 @@ #include "../System/String.h" +namespace saracraft { +namespace util { + class Resource { public: virtual bool Load(const std::string& filename) = 0; @@ -96,3 +99,6 @@ public: private: ResourceMap m_resources; }; + +} // Namespace util. +} // Namespace saracraft. diff --git a/src/System/String.cpp b/src/System/String.cpp index 6a626d3..50978c0 100644 --- a/src/System/String.cpp +++ b/src/System/String.cpp @@ -5,6 +5,9 @@ #include "String.h" #define _CRT_SECURE_NO_WARNINGS +namespace saracraft { +namespace util { + String::String(void) { _string = new char[1]; _string[0] = 0; @@ -150,3 +153,6 @@ String String::operator+(const String& value) const { String::operator const char*() const { return _string; } + +} // End of namespace util. +} // End of namespace saracraft. diff --git a/src/System/String.h b/src/System/String.h index 2465e0b..869548e 100644 --- a/src/System/String.h +++ b/src/System/String.h @@ -1,6 +1,9 @@ #pragma once #define _CRT_SECURE_NO_WARNINGS +namespace saracraft { +namespace util { + class String { public: String(void); @@ -34,3 +37,6 @@ private: char* _string; int _length; }; + +} // Namespace util. +} // Namespace saracraft. diff --git a/src/Texture/Texture.cpp b/src/Texture/Texture.cpp index 1a669e1..502fcfc 100644 --- a/src/Texture/Texture.cpp +++ b/src/Texture/Texture.cpp @@ -11,7 +11,9 @@ using namespace std; #define GL_BGRA_EXT 0x80E1 #endif -ResourceManager textureManager; +using saracraft::util::Debug; + +saracraft::util::ResourceManager textureManager; static GLuint boundTexture = 0; diff --git a/src/Texture/Texture.h b/src/Texture/Texture.h index 9b22a6b..f780969 100644 --- a/src/Texture/Texture.h +++ b/src/Texture/Texture.h @@ -27,8 +27,8 @@ void BindTexture(GLuint texID); #include "../System/ResourceManager.h" -class Texture : public Resource { - template friend class ResourceManager; +class Texture : public saracraft::util::Resource { + template friend class saracraft::util::ResourceManager; public: Texture(); @@ -46,4 +46,4 @@ private: int height; }; -extern ResourceManager textureManager; +extern saracraft::util::ResourceManager textureManager; diff --git a/src/UI/Button.h b/src/UI/Button.h index fbf3152..82f8ce7 100644 --- a/src/UI/Button.h +++ b/src/UI/Button.h @@ -4,6 +4,8 @@ #include "../System/String.h" #include "../Font/Font.h" +using saracraft::util::String; + class Button { public: Button(void);