diff --git a/CMakeLists.txt b/CMakeLists.txt index b156d73c..230c90fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,22 +51,22 @@ ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") # find sources SET(SOURCES src/menustate.cpp - src/framebuffer.cpp - src/textureloader.cpp - src/texture.cpp - src/texturemanager.cpp - src/configmanager.cpp - src/resourcemanager.cpp + src/framework/framebuffer.cpp + src/framework/textureloader.cpp + src/framework/texture.cpp + src/framework/texturemanager.cpp + src/framework/configmanager.cpp + src/framework/resourcemanager.cpp src/main.cpp - src/engine.cpp - src/graphics.cpp - src/logger.cpp - src/util.cpp) + src/framework/engine.cpp + src/framework/graphics.cpp + src/framework/logger.cpp + src/framework/util.cpp) IF(WIN32) - SET(SOURCES ${SOURCES} src/win32platform.cpp) + SET(SOURCES ${SOURCES} src/framework/win32platform.cpp) ELSE(WIN32) - SET(SOURCES ${SOURCES} src/x11platform.cpp) + SET(SOURCES ${SOURCES} src/framework/x11platform.cpp) ENDIF(WIN32) # target executable diff --git a/COPYING b/COPYING deleted file mode 100644 index 826ee55b..00000000 --- a/COPYING +++ /dev/null @@ -1,21 +0,0 @@ -OTClient is made available under the MIT License - -Copyright (c) 2010 OTClient, https://github.com/edubart/otclient - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/src/color.h b/src/framework/color.h similarity index 100% rename from src/color.h rename to src/framework/color.h diff --git a/src/configmanager.cpp b/src/framework/configmanager.cpp similarity index 91% rename from src/configmanager.cpp rename to src/framework/configmanager.cpp index f0f77e02..818a6b3a 100644 --- a/src/configmanager.cpp +++ b/src/framework/configmanager.cpp @@ -58,11 +58,12 @@ bool ConfigManager::load(const std::string& fileName) YAML::Node doc; parser.GetNextDocument(doc); - for(YAML::Iterator it=doc.begin(); it != doc.end(); ++it) { + for(YAML::Iterator it = doc.begin(); it != doc.end(); it++) { std::string key, value; it.first() >> key; it.second() >> value; m_confsMap[key] = value; + dump() << key << value; } } catch (YAML::ParserException& e) { error("Malformed configuration file!"); @@ -93,12 +94,12 @@ void ConfigManager::setValue(const std::string &key, const char *value) void ConfigManager::setValue(const std::string &key, int value) { - setValue(key, castToString(value)); + setValue(key, boost::lexical_cast(value)); } void ConfigManager::setValue(const std::string &key, float value) { - setValue(key, castToString(value)); + setValue(key, boost::lexical_cast(value)); } void ConfigManager::setValue(const std::string &key, bool value) @@ -127,7 +128,7 @@ float ConfigManager::getFloat(const std::string &key) warning("Config value %s not found", key.c_str()); return 0; } - return castFromString(iter->second); + return boost::lexical_cast(iter->second); } bool ConfigManager::getBoolean(const std::string &key) @@ -137,7 +138,7 @@ bool ConfigManager::getBoolean(const std::string &key) warning("Config value %s not found", key.c_str()); return 0; } - return (iter->second == std::string("true")); + return (iter->second == "true"); } int ConfigManager::getInteger(const std::string &key) @@ -147,5 +148,5 @@ int ConfigManager::getInteger(const std::string &key) warning("Config value %s not found", key.c_str()); return 0; } - return castFromString(iter->second); + return boost::lexical_cast(iter->second); } diff --git a/src/configmanager.h b/src/framework/configmanager.h similarity index 100% rename from src/configmanager.h rename to src/framework/configmanager.h diff --git a/src/engine.cpp b/src/framework/engine.cpp similarity index 100% rename from src/engine.cpp rename to src/framework/engine.cpp diff --git a/src/engine.h b/src/framework/engine.h similarity index 100% rename from src/engine.h rename to src/framework/engine.h diff --git a/src/framebuffer.cpp b/src/framework/framebuffer.cpp similarity index 100% rename from src/framebuffer.cpp rename to src/framework/framebuffer.cpp diff --git a/src/framebuffer.h b/src/framework/framebuffer.h similarity index 100% rename from src/framebuffer.h rename to src/framework/framebuffer.h diff --git a/src/gamestate.h b/src/framework/gamestate.h similarity index 100% rename from src/gamestate.h rename to src/framework/gamestate.h diff --git a/src/graphics.cpp b/src/framework/graphics.cpp similarity index 84% rename from src/graphics.cpp rename to src/framework/graphics.cpp index 47dc63e1..cf3ee40a 100644 --- a/src/graphics.cpp +++ b/src/framework/graphics.cpp @@ -45,6 +45,9 @@ void Graphics::init() glAlphaFunc(GL_GREATER, 0.0f); // default alpha mode glDisable(GL_DEPTH_TEST); // we are rendering 2D only, we don't need it glEnable(GL_TEXTURE_2D); // enable textures by default + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + glShadeModel(GL_SMOOTH); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); notice("GPU %s", (const char*)glGetString(GL_RENDERER)); notice("OpenGL %s", (const char*)glGetString(GL_VERSION)); @@ -157,9 +160,9 @@ void Graphics::drawColoredRect(const Rect& screenCoords, const Color& color) } -void Graphics::drawBoundingRect(const Rect& screenCoords, const Color& color, int lineWidth) +void Graphics::drawBoundingRect(const Rect& screenCoords, const Color& color, int innerLineWidth) { - if(2*lineWidth > screenCoords.height()) + if(2*innerLineWidth > screenCoords.height()) return; glDisable(GL_TEXTURE_2D); @@ -176,27 +179,27 @@ void Graphics::drawBoundingRect(const Rect& screenCoords, const Color& color, in // top line glVertex2i(left, top); - glVertex2i(left, top+lineWidth); - glVertex2i(right, top+lineWidth); + glVertex2i(left, top+innerLineWidth); + glVertex2i(right, top+innerLineWidth); glVertex2i(right, top); // left - glVertex2i(left, screenCoords.top()+lineWidth); - glVertex2i(left, bottom-lineWidth); - glVertex2i(left+lineWidth, bottom-lineWidth); - glVertex2i(left+lineWidth, screenCoords.top()+lineWidth); + glVertex2i(left, screenCoords.top()+innerLineWidth); + glVertex2i(left, bottom-innerLineWidth); + glVertex2i(left+innerLineWidth, bottom-innerLineWidth); + glVertex2i(left+innerLineWidth, screenCoords.top()+innerLineWidth); // bottom line glVertex2i(left, bottom); - glVertex2i(left, bottom-lineWidth); - glVertex2i(right, bottom-lineWidth); + glVertex2i(left, bottom-innerLineWidth); + glVertex2i(right, bottom-innerLineWidth); glVertex2i(right, bottom); // right line - glVertex2i(right, top+lineWidth); - glVertex2i(right, bottom-lineWidth); - glVertex2i(right-lineWidth, bottom-lineWidth); - glVertex2i(right-lineWidth, top+lineWidth); + glVertex2i(right, top+innerLineWidth); + glVertex2i(right, bottom-innerLineWidth); + glVertex2i(right-innerLineWidth, bottom-innerLineWidth); + glVertex2i(right-innerLineWidth, top+innerLineWidth); glEnd(); diff --git a/src/graphics.h b/src/framework/graphics.h similarity index 98% rename from src/graphics.h rename to src/framework/graphics.h index d3f1b4ff..ea544be8 100644 --- a/src/graphics.h +++ b/src/framework/graphics.h @@ -54,9 +54,10 @@ public: void endRender(); const Size& getScreenSize() const { return m_screenSize; } + void drawTexturedRect(const Rect& screenCoords, const Texture *texture, const Rect& texCoords = Rect()); void drawColoredRect(const Rect& screenCoords, const Color& color); - void drawBoundingRect(const Rect& screenCoords, const Color& color, int lineWidth); + void drawBoundingRect(const Rect& screenCoords, const Color& color, int innerLineWidth); private: Size m_screenSize; diff --git a/src/input.h b/src/framework/input.h similarity index 100% rename from src/input.h rename to src/framework/input.h diff --git a/src/logger.cpp b/src/framework/logger.cpp similarity index 98% rename from src/logger.cpp rename to src/framework/logger.cpp index 1e622547..6188e826 100644 --- a/src/logger.cpp +++ b/src/framework/logger.cpp @@ -23,7 +23,6 @@ #include "logger.h" -#include void Logger::log(int level, const char *trace, const char *format, ...) { diff --git a/src/logger.h b/src/framework/logger.h similarity index 100% rename from src/logger.h rename to src/framework/logger.h diff --git a/src/platform.h b/src/framework/platform.h similarity index 100% rename from src/platform.h rename to src/framework/platform.h diff --git a/src/point.h b/src/framework/point.h similarity index 98% rename from src/point.h rename to src/framework/point.h index ae85e719..52a75832 100644 --- a/src/point.h +++ b/src/framework/point.h @@ -65,6 +65,7 @@ public: inline bool operator!=(const TPoint& other) const { return other.x!=x || other.y!=y; } inline float length() const { return sqrtf((float)(x*x + y*y)); } + inline T manhattanLength() const { return std::abs(x) + std::abs(y); } inline float distanceFrom(const TPoint& other) const { return TPoint(x - other.x, y - other.y).getLength(); diff --git a/src/prerequisites.h b/src/framework/prerequisites.h similarity index 82% rename from src/prerequisites.h rename to src/framework/prerequisites.h index bff39a95..b081fc77 100644 --- a/src/prerequisites.h +++ b/src/framework/prerequisites.h @@ -25,14 +25,12 @@ #ifndef PREREQUISITES_H #define PREREQUISITES_H -// app name +// app name and version #define APP_NAME "OTClient" #define APP_LONGNAME APP_NAME " " APP_VERSION - -// app version #define APP_VERSION "0.1.0" -// int types +// easy typing #include typedef unsigned char uchar; @@ -47,35 +45,51 @@ typedef int32_t int32; typedef int16_t int16; typedef int8_t int8; -// c headers -#include +// C headers #include #include -#include #include #include +#include +#include #include -#include -#include +#include + +// STL headers #include +#include #include - -// stl headers +#include #include #include #include #include #include +#include + +// additional string algorithms +#include + +// easy casting +#include + +// smart pointers +#include + +// foreach +#include +#define foreach BOOST_FOREACH // GL stuff #define GL_GLEXT_PROTOTYPES - #include #include #include -// utilities +// internal logger #include "logger.h" + +// additional utilities #include "util.h" #endif // PREREQUISITES_H \ No newline at end of file diff --git a/src/rect.h b/src/framework/rect.h similarity index 100% rename from src/rect.h rename to src/framework/rect.h diff --git a/src/resourcemanager.cpp b/src/framework/resourcemanager.cpp similarity index 100% rename from src/resourcemanager.cpp rename to src/framework/resourcemanager.cpp diff --git a/src/resourcemanager.h b/src/framework/resourcemanager.h similarity index 100% rename from src/resourcemanager.h rename to src/framework/resourcemanager.h diff --git a/src/size.h b/src/framework/size.h similarity index 100% rename from src/size.h rename to src/framework/size.h diff --git a/src/texture.cpp b/src/framework/texture.cpp similarity index 100% rename from src/texture.cpp rename to src/framework/texture.cpp diff --git a/src/texture.h b/src/framework/texture.h similarity index 98% rename from src/texture.h rename to src/framework/texture.h index 3742ece7..e8720f9b 100644 --- a/src/texture.h +++ b/src/framework/texture.h @@ -27,7 +27,6 @@ #include "prerequisites.h" #include "size.h" -#include class TextureManager; diff --git a/src/textureloader.cpp b/src/framework/textureloader.cpp similarity index 100% rename from src/textureloader.cpp rename to src/framework/textureloader.cpp diff --git a/src/textureloader.h b/src/framework/textureloader.h similarity index 100% rename from src/textureloader.h rename to src/framework/textureloader.h diff --git a/src/texturemanager.cpp b/src/framework/texturemanager.cpp similarity index 98% rename from src/texturemanager.cpp rename to src/framework/texturemanager.cpp index b8718c84..93d65213 100644 --- a/src/texturemanager.cpp +++ b/src/framework/texturemanager.cpp @@ -26,8 +26,6 @@ #include "resourcemanager.h" #include "textureloader.h" -#include - TextureManager g_textures; TextureManager::TextureManager() diff --git a/src/texturemanager.h b/src/framework/texturemanager.h similarity index 94% rename from src/texturemanager.h rename to src/framework/texturemanager.h index 457e3658..ed4b427a 100644 --- a/src/texturemanager.h +++ b/src/framework/texturemanager.h @@ -34,7 +34,7 @@ public: TextureManager(); ~TextureManager(); - /// Load a texture from file, if it was already loaded a cached one will be retrieved + /// Load a texture from file, if it was already loaded it will be retrieved from cache TexturePtr get(const std::string& textureFile); private: diff --git a/src/util.cpp b/src/framework/util.cpp similarity index 100% rename from src/util.cpp rename to src/framework/util.cpp diff --git a/src/util.h b/src/framework/util.h similarity index 79% rename from src/util.h rename to src/framework/util.h index eea8ba33..1e82ff77 100644 --- a/src/util.h +++ b/src/framework/util.h @@ -33,21 +33,4 @@ std::string vformat(const char *format, va_list args); /// Formatting like printf for std::string std::string format(const char *format, ...); -/// Convert int/float like types to std::string -template -inline std::string castToString(const T& x) { - std::ostringstream ss; - ss << x; - return ss.str(); -} - -/// Convert std:;string to int/float like types -template -inline T castFromString(const std::string& s) { - std::istringstream ss(s); - T x = 0; - ss >> x; - return x; -} - #endif \ No newline at end of file diff --git a/src/x11platform.cpp b/src/framework/x11platform.cpp similarity index 100% rename from src/x11platform.cpp rename to src/framework/x11platform.cpp diff --git a/src/main.cpp b/src/main.cpp index 60c347b1..9f8fcd5a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,16 +22,12 @@ */ -#include "engine.h" -#include "configmanager.h" -#include "resourcemanager.h" -#include "platform.h" +#include "framework/engine.h" +#include "framework/configmanager.h" +#include "framework/resourcemanager.h" +#include "framework/platform.h" #include "menustate.h" -#include - -#include - /// Catches signals so we can exit nicely void signal_handler(int sig) { diff --git a/src/menustate.cpp b/src/menustate.cpp index 4de6c19c..69b81e3b 100644 --- a/src/menustate.cpp +++ b/src/menustate.cpp @@ -23,12 +23,12 @@ #include "menustate.h" -#include "framebuffer.h" -#include "graphics.h" -#include "texturemanager.h" -#include "logger.h" -#include "engine.h" -#include "rect.h" +#include "framework/framebuffer.h" +#include "framework/graphics.h" +#include "framework/texturemanager.h" +#include "framework/logger.h" +#include "framework/engine.h" +#include "framework/rect.h" TexturePtr background; @@ -66,7 +66,7 @@ void MenuState::render() { static Size minTexCoordsSize(1240, 880); const Size& screenSize = g_graphics.getScreenSize(); - Size texSize = m_background->getSize(); + const Size& texSize = m_background->getSize(); Size texCoordsSize = screenSize; if(texCoordsSize < minTexCoordsSize) diff --git a/src/menustate.h b/src/menustate.h index 5722f171..e86f85ce 100644 --- a/src/menustate.h +++ b/src/menustate.h @@ -25,9 +25,8 @@ #ifndef MENUSTATE_H #define MENUSTATE_H -#include "prerequisites.h" -#include "gamestate.h" -#include "texture.h" +#include "framework/gamestate.h" +#include "framework/texture.h" class MenuState : public GameState {