Browse Source

framework

Eduardo Bart 10 years ago
parent
commit
b2c61760e5

+ 12
- 12
CMakeLists.txt View File

@@ -51,22 +51,22 @@ ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
51 51
 # find sources
52 52
 SET(SOURCES
53 53
     src/menustate.cpp
54
-    src/framebuffer.cpp
55
-    src/textureloader.cpp
56
-    src/texture.cpp
57
-    src/texturemanager.cpp
58
-    src/configmanager.cpp
59
-    src/resourcemanager.cpp
54
+    src/framework/framebuffer.cpp
55
+    src/framework/textureloader.cpp
56
+    src/framework/texture.cpp
57
+    src/framework/texturemanager.cpp
58
+    src/framework/configmanager.cpp
59
+    src/framework/resourcemanager.cpp
60 60
     src/main.cpp
61
-    src/engine.cpp
62
-    src/graphics.cpp
63
-    src/logger.cpp
64
-    src/util.cpp)
61
+    src/framework/engine.cpp
62
+    src/framework/graphics.cpp
63
+    src/framework/logger.cpp
64
+    src/framework/util.cpp)
65 65
 
66 66
 IF(WIN32)
67
-    SET(SOURCES ${SOURCES} src/win32platform.cpp)
67
+    SET(SOURCES ${SOURCES} src/framework/win32platform.cpp)
68 68
 ELSE(WIN32)
69
-    SET(SOURCES ${SOURCES} src/x11platform.cpp)
69
+    SET(SOURCES ${SOURCES} src/framework/x11platform.cpp)
70 70
 ENDIF(WIN32)
71 71
 
72 72
 # target executable

+ 0
- 21
COPYING View File

@@ -1,21 +0,0 @@
1
-OTClient is made available under the MIT License
2
-
3
-Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
4
-
5
-Permission is hereby granted, free of charge, to any person obtaining a copy
6
-of this software and associated documentation files (the "Software"), to deal
7
-in the Software without restriction, including without limitation the rights
8
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
-copies of the Software, and to permit persons to whom the Software is
10
-furnished to do so, subject to the following conditions:
11
-
12
-The above copyright notice and this permission notice shall be included in
13
-all copies or substantial portions of the Software.
14
-
15
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
-THE SOFTWARE.

src/color.h → src/framework/color.h View File


src/configmanager.cpp → src/framework/configmanager.cpp View File

@@ -58,11 +58,12 @@ bool ConfigManager::load(const std::string& fileName)
58 58
         YAML::Node doc;
59 59
         parser.GetNextDocument(doc);
60 60
 
61
-        for(YAML::Iterator it=doc.begin(); it != doc.end(); ++it) {
61
+        for(YAML::Iterator it = doc.begin(); it != doc.end(); it++) {
62 62
             std::string key, value;
63 63
             it.first() >> key;
64 64
             it.second() >> value;
65 65
             m_confsMap[key] = value;
66
+            dump() << key << value;
66 67
         }
67 68
     } catch (YAML::ParserException& e) {
68 69
         error("Malformed configuration file!");
@@ -93,12 +94,12 @@ void ConfigManager::setValue(const std::string &key, const char *value)
93 94
 
94 95
 void ConfigManager::setValue(const std::string &key, int value)
95 96
 {
96
-    setValue(key, castToString<int>(value));
97
+    setValue(key, boost::lexical_cast<std::string>(value));
97 98
 }
98 99
 
99 100
 void ConfigManager::setValue(const std::string &key, float value)
100 101
 {
101
-    setValue(key, castToString<float>(value));
102
+    setValue(key, boost::lexical_cast<std::string>(value));
102 103
 }
103 104
 
104 105
 void ConfigManager::setValue(const std::string &key, bool value)
@@ -127,7 +128,7 @@ float ConfigManager::getFloat(const std::string &key)
127 128
         warning("Config value %s not found", key.c_str());
128 129
         return 0;
129 130
     }
130
-    return castFromString<float>(iter->second);
131
+    return boost::lexical_cast<float>(iter->second);
131 132
 }
132 133
 
133 134
 bool ConfigManager::getBoolean(const std::string &key)
@@ -137,7 +138,7 @@ bool ConfigManager::getBoolean(const std::string &key)
137 138
         warning("Config value %s not found", key.c_str());
138 139
         return 0;
139 140
     }
140
-    return (iter->second == std::string("true"));
141
+    return (iter->second == "true");
141 142
 }
142 143
 
143 144
 int ConfigManager::getInteger(const std::string &key)
@@ -147,5 +148,5 @@ int ConfigManager::getInteger(const std::string &key)
147 148
         warning("Config value %s not found", key.c_str());
148 149
         return 0;
149 150
     }
150
-    return castFromString<int>(iter->second);
151
+    return boost::lexical_cast<int>(iter->second);
151 152
 }

src/configmanager.h → src/framework/configmanager.h View File


src/engine.cpp → src/framework/engine.cpp View File


src/engine.h → src/framework/engine.h View File


src/framebuffer.cpp → src/framework/framebuffer.cpp View File


src/framebuffer.h → src/framework/framebuffer.h View File


src/gamestate.h → src/framework/gamestate.h View File


src/graphics.cpp → src/framework/graphics.cpp View File

@@ -45,6 +45,9 @@ void Graphics::init()
45 45
     glAlphaFunc(GL_GREATER, 0.0f); // default alpha mode
46 46
     glDisable(GL_DEPTH_TEST); // we are rendering 2D only, we don't need it
47 47
     glEnable(GL_TEXTURE_2D); // enable textures by default
48
+    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
49
+    glShadeModel(GL_SMOOTH);
50
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
48 51
 
49 52
     notice("GPU %s", (const char*)glGetString(GL_RENDERER));
50 53
     notice("OpenGL %s", (const char*)glGetString(GL_VERSION));
@@ -157,9 +160,9 @@ void Graphics::drawColoredRect(const Rect& screenCoords, const Color& color)
157 160
 }
158 161
 
159 162
 
160
-void Graphics::drawBoundingRect(const Rect& screenCoords, const Color& color, int lineWidth)
163
+void Graphics::drawBoundingRect(const Rect& screenCoords, const Color& color, int innerLineWidth)
161 164
 {
162
-    if(2*lineWidth > screenCoords.height())
165
+    if(2*innerLineWidth > screenCoords.height())
163 166
         return;
164 167
 
165 168
     glDisable(GL_TEXTURE_2D);
@@ -176,27 +179,27 @@ void Graphics::drawBoundingRect(const Rect& screenCoords, const Color& color, in
176 179
 
177 180
     // top line
178 181
     glVertex2i(left,  top);
179
-    glVertex2i(left,  top+lineWidth);
180
-    glVertex2i(right, top+lineWidth);
182
+    glVertex2i(left,  top+innerLineWidth);
183
+    glVertex2i(right, top+innerLineWidth);
181 184
     glVertex2i(right, top);
182 185
 
183 186
     // left
184
-    glVertex2i(left, screenCoords.top()+lineWidth);
185
-    glVertex2i(left, bottom-lineWidth);
186
-    glVertex2i(left+lineWidth, bottom-lineWidth);
187
-    glVertex2i(left+lineWidth, screenCoords.top()+lineWidth);
187
+    glVertex2i(left, screenCoords.top()+innerLineWidth);
188
+    glVertex2i(left, bottom-innerLineWidth);
189
+    glVertex2i(left+innerLineWidth, bottom-innerLineWidth);
190
+    glVertex2i(left+innerLineWidth, screenCoords.top()+innerLineWidth);
188 191
 
189 192
     // bottom line
190 193
     glVertex2i(left,  bottom);
191
-    glVertex2i(left,  bottom-lineWidth);
192
-    glVertex2i(right, bottom-lineWidth);
194
+    glVertex2i(left,  bottom-innerLineWidth);
195
+    glVertex2i(right, bottom-innerLineWidth);
193 196
     glVertex2i(right, bottom);
194 197
 
195 198
     // right line
196
-    glVertex2i(right,           top+lineWidth);
197
-    glVertex2i(right,           bottom-lineWidth);
198
-    glVertex2i(right-lineWidth, bottom-lineWidth);
199
-    glVertex2i(right-lineWidth, top+lineWidth);
199
+    glVertex2i(right,           top+innerLineWidth);
200
+    glVertex2i(right,           bottom-innerLineWidth);
201
+    glVertex2i(right-innerLineWidth, bottom-innerLineWidth);
202
+    glVertex2i(right-innerLineWidth, top+innerLineWidth);
200 203
 
201 204
     glEnd();
202 205
 

src/graphics.h → src/framework/graphics.h View File

@@ -54,9 +54,10 @@ public:
54 54
     void endRender();
55 55
 
56 56
     const Size& getScreenSize() const { return m_screenSize; }
57
+
57 58
     void drawTexturedRect(const Rect& screenCoords, const Texture *texture, const Rect& texCoords = Rect());
58 59
     void drawColoredRect(const Rect& screenCoords, const Color& color);
59
-    void drawBoundingRect(const Rect& screenCoords, const Color& color, int lineWidth);
60
+    void drawBoundingRect(const Rect& screenCoords, const Color& color, int innerLineWidth);
60 61
 
61 62
 private:
62 63
     Size m_screenSize;

src/input.h → src/framework/input.h View File


src/logger.cpp → src/framework/logger.cpp View File

@@ -23,7 +23,6 @@
23 23
 
24 24
 
25 25
 #include "logger.h"
26
-#include <boost/algorithm/string.hpp>
27 26
 
28 27
 void Logger::log(int level, const char *trace, const char *format, ...)
29 28
 {

src/logger.h → src/framework/logger.h View File


src/platform.h → src/framework/platform.h View File


src/point.h → src/framework/point.h View File

@@ -65,6 +65,7 @@ public:
65 65
     inline bool operator!=(const TPoint<T>& other) const { return other.x!=x || other.y!=y; }
66 66
 
67 67
     inline float length() const { return sqrtf((float)(x*x + y*y)); }
68
+    inline T manhattanLength() const { return std::abs(x) + std::abs(y); }
68 69
 
69 70
     inline float distanceFrom(const TPoint<T>& other) const {
70 71
         return TPoint<T>(x - other.x, y - other.y).getLength();

src/prerequisites.h → src/framework/prerequisites.h View File

@@ -25,14 +25,12 @@
25 25
 #ifndef PREREQUISITES_H
26 26
 #define PREREQUISITES_H
27 27
 
28
-// app name
28
+// app name and version
29 29
 #define APP_NAME "OTClient"
30 30
 #define APP_LONGNAME APP_NAME " " APP_VERSION
31
-
32
-// app version
33 31
 #define APP_VERSION "0.1.0"
34 32
 
35
-// int types
33
+// easy typing
36 34
 #include <stdint.h>
37 35
 
38 36
 typedef unsigned char uchar;
@@ -47,35 +45,51 @@ typedef int32_t int32;
47 45
 typedef int16_t int16;
48 46
 typedef int8_t int8;
49 47
 
50
-// c headers
51
-#include <cassert>
48
+// C headers
52 49
 #include <cstdio>
53 50
 #include <cstdlib>
54
-#include <ctime>
55 51
 #include <cstring>
56 52
 #include <cstdarg>
53
+#include <cassert>
54
+#include <ctime>
57 55
 #include <cmath>
58
-#include <algorithm>
59
-#include <fstream>
56
+#include <csignal>
57
+
58
+// STL headers
60 59
 #include <iostream>
60
+#include <fstream>
61 61
 #include <sstream>
62
-
63
-// stl headers
62
+#include <algorithm>
64 63
 #include <string>
65 64
 #include <vector>
66 65
 #include <map>
67 66
 #include <string>
68 67
 #include <list>
68
+#include <tr1/cinttypes>
69
+
70
+// additional string algorithms
71
+#include <boost/algorithm/string.hpp>
72
+
73
+// easy casting
74
+#include <boost/lexical_cast.hpp>
75
+
76
+// smart pointers
77
+#include <boost/smart_ptr.hpp>
78
+
79
+// foreach
80
+#include <boost/foreach.hpp>
81
+#define foreach BOOST_FOREACH
69 82
 
70 83
 // GL stuff
71 84
 #define GL_GLEXT_PROTOTYPES
72
-
73 85
 #include <GL/gl.h>
74 86
 #include <GL/glu.h>
75 87
 #include <GL/glext.h>
76 88
 
77
-// utilities
89
+// internal logger
78 90
 #include "logger.h"
91
+
92
+// additional utilities
79 93
 #include "util.h"
80 94
 
81 95
 #endif // PREREQUISITES_H

src/rect.h → src/framework/rect.h View File


src/resourcemanager.cpp → src/framework/resourcemanager.cpp View File


src/resourcemanager.h → src/framework/resourcemanager.h View File


src/size.h → src/framework/size.h View File


src/texture.cpp → src/framework/texture.cpp View File


src/texture.h → src/framework/texture.h View File

@@ -27,7 +27,6 @@
27 27
 
28 28
 #include "prerequisites.h"
29 29
 #include "size.h"
30
-#include <boost/shared_ptr.hpp>
31 30
 
32 31
 class TextureManager;
33 32
 

src/textureloader.cpp → src/framework/textureloader.cpp View File


src/textureloader.h → src/framework/textureloader.h View File


src/texturemanager.cpp → src/framework/texturemanager.cpp View File

@@ -26,8 +26,6 @@
26 26
 #include "resourcemanager.h"
27 27
 #include "textureloader.h"
28 28
 
29
-#include <boost/algorithm/string.hpp>
30
-
31 29
 TextureManager g_textures;
32 30
 
33 31
 TextureManager::TextureManager()

src/texturemanager.h → src/framework/texturemanager.h View File

@@ -34,7 +34,7 @@ public:
34 34
     TextureManager();
35 35
     ~TextureManager();
36 36
 
37
-    /// Load a texture from file, if it was already loaded a cached one will be retrieved
37
+    /// Load a texture from file, if it was already loaded it will be retrieved from cache
38 38
     TexturePtr get(const std::string& textureFile);
39 39
 
40 40
 private:

src/util.cpp → src/framework/util.cpp View File


src/util.h → src/framework/util.h View File

@@ -33,21 +33,4 @@ std::string vformat(const char *format, va_list args);
33 33
 /// Formatting like printf for std::string
34 34
 std::string format(const char *format, ...);
35 35
 
36
-/// Convert int/float like types to std::string
37
-template<typename T>
38
-inline std::string castToString(const T& x) {
39
-    std::ostringstream ss;
40
-    ss << x;
41
-    return ss.str();
42
-}
43
-
44
-/// Convert std:;string to int/float like types
45
-template<typename T>
46
-inline T castFromString(const std::string& s) {
47
-    std::istringstream ss(s);
48
-    T x = 0;
49
-    ss >> x;
50
-    return x;
51
-}
52
-
53 36
 #endif

src/x11platform.cpp → src/framework/x11platform.cpp View File


+ 4
- 8
src/main.cpp View File

@@ -22,16 +22,12 @@
22 22
  */
23 23
 
24 24
 
25
-#include "engine.h"
26
-#include "configmanager.h"
27
-#include "resourcemanager.h"
28
-#include "platform.h"
25
+#include "framework/engine.h"
26
+#include "framework/configmanager.h"
27
+#include "framework/resourcemanager.h"
28
+#include "framework/platform.h"
29 29
 #include "menustate.h"
30 30
 
31
-#include <csignal>
32
-
33
-#include <boost/scoped_ptr.hpp>
34
-
35 31
 /// Catches signals so we can exit nicely
36 32
 void signal_handler(int sig)
37 33
 {

+ 7
- 7
src/menustate.cpp View File

@@ -23,12 +23,12 @@
23 23
 
24 24
 
25 25
 #include "menustate.h"
26
-#include "framebuffer.h"
27
-#include "graphics.h"
28
-#include "texturemanager.h"
29
-#include "logger.h"
30
-#include "engine.h"
31
-#include "rect.h"
26
+#include "framework/framebuffer.h"
27
+#include "framework/graphics.h"
28
+#include "framework/texturemanager.h"
29
+#include "framework/logger.h"
30
+#include "framework/engine.h"
31
+#include "framework/rect.h"
32 32
 
33 33
 TexturePtr background;
34 34
 
@@ -66,7 +66,7 @@ void MenuState::render()
66 66
 {
67 67
     static Size minTexCoordsSize(1240, 880);
68 68
     const Size& screenSize = g_graphics.getScreenSize();
69
-    Size texSize = m_background->getSize();
69
+    const Size& texSize = m_background->getSize();
70 70
 
71 71
     Size texCoordsSize = screenSize;
72 72
     if(texCoordsSize < minTexCoordsSize)

+ 2
- 3
src/menustate.h View File

@@ -25,9 +25,8 @@
25 25
 #ifndef MENUSTATE_H
26 26
 #define MENUSTATE_H
27 27
 
28
-#include "prerequisites.h"
29
-#include "gamestate.h"
30
-#include "texture.h"
28
+#include "framework/gamestate.h"
29
+#include "framework/texture.h"
31 30
 
32 31
 class MenuState : public GameState
33 32
 {

Loading…
Cancel
Save