framework
This commit is contained in:
parent
3d0b191199
commit
b2c61760e5
|
@ -51,22 +51,22 @@ ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
# find sources
|
# find sources
|
||||||
SET(SOURCES
|
SET(SOURCES
|
||||||
src/menustate.cpp
|
src/menustate.cpp
|
||||||
src/framebuffer.cpp
|
src/framework/framebuffer.cpp
|
||||||
src/textureloader.cpp
|
src/framework/textureloader.cpp
|
||||||
src/texture.cpp
|
src/framework/texture.cpp
|
||||||
src/texturemanager.cpp
|
src/framework/texturemanager.cpp
|
||||||
src/configmanager.cpp
|
src/framework/configmanager.cpp
|
||||||
src/resourcemanager.cpp
|
src/framework/resourcemanager.cpp
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/engine.cpp
|
src/framework/engine.cpp
|
||||||
src/graphics.cpp
|
src/framework/graphics.cpp
|
||||||
src/logger.cpp
|
src/framework/logger.cpp
|
||||||
src/util.cpp)
|
src/framework/util.cpp)
|
||||||
|
|
||||||
IF(WIN32)
|
IF(WIN32)
|
||||||
SET(SOURCES ${SOURCES} src/win32platform.cpp)
|
SET(SOURCES ${SOURCES} src/framework/win32platform.cpp)
|
||||||
ELSE(WIN32)
|
ELSE(WIN32)
|
||||||
SET(SOURCES ${SOURCES} src/x11platform.cpp)
|
SET(SOURCES ${SOURCES} src/framework/x11platform.cpp)
|
||||||
ENDIF(WIN32)
|
ENDIF(WIN32)
|
||||||
|
|
||||||
# target executable
|
# target executable
|
||||||
|
|
21
COPYING
21
COPYING
|
@ -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.
|
|
|
@ -58,11 +58,12 @@ bool ConfigManager::load(const std::string& fileName)
|
||||||
YAML::Node doc;
|
YAML::Node doc;
|
||||||
parser.GetNextDocument(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;
|
std::string key, value;
|
||||||
it.first() >> key;
|
it.first() >> key;
|
||||||
it.second() >> value;
|
it.second() >> value;
|
||||||
m_confsMap[key] = value;
|
m_confsMap[key] = value;
|
||||||
|
dump() << key << value;
|
||||||
}
|
}
|
||||||
} catch (YAML::ParserException& e) {
|
} catch (YAML::ParserException& e) {
|
||||||
error("Malformed configuration file!");
|
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)
|
void ConfigManager::setValue(const std::string &key, int value)
|
||||||
{
|
{
|
||||||
setValue(key, castToString<int>(value));
|
setValue(key, boost::lexical_cast<std::string>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigManager::setValue(const std::string &key, float value)
|
void ConfigManager::setValue(const std::string &key, float value)
|
||||||
{
|
{
|
||||||
setValue(key, castToString<float>(value));
|
setValue(key, boost::lexical_cast<std::string>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigManager::setValue(const std::string &key, bool 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());
|
warning("Config value %s not found", key.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return castFromString<float>(iter->second);
|
return boost::lexical_cast<float>(iter->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigManager::getBoolean(const std::string &key)
|
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());
|
warning("Config value %s not found", key.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return (iter->second == std::string("true"));
|
return (iter->second == "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigManager::getInteger(const std::string &key)
|
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());
|
warning("Config value %s not found", key.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return castFromString<int>(iter->second);
|
return boost::lexical_cast<int>(iter->second);
|
||||||
}
|
}
|
|
@ -45,6 +45,9 @@ void Graphics::init()
|
||||||
glAlphaFunc(GL_GREATER, 0.0f); // default alpha mode
|
glAlphaFunc(GL_GREATER, 0.0f); // default alpha mode
|
||||||
glDisable(GL_DEPTH_TEST); // we are rendering 2D only, we don't need it
|
glDisable(GL_DEPTH_TEST); // we are rendering 2D only, we don't need it
|
||||||
glEnable(GL_TEXTURE_2D); // enable textures by default
|
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("GPU %s", (const char*)glGetString(GL_RENDERER));
|
||||||
notice("OpenGL %s", (const char*)glGetString(GL_VERSION));
|
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;
|
return;
|
||||||
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
@ -176,27 +179,27 @@ void Graphics::drawBoundingRect(const Rect& screenCoords, const Color& color, in
|
||||||
|
|
||||||
// top line
|
// top line
|
||||||
glVertex2i(left, top);
|
glVertex2i(left, top);
|
||||||
glVertex2i(left, top+lineWidth);
|
glVertex2i(left, top+innerLineWidth);
|
||||||
glVertex2i(right, top+lineWidth);
|
glVertex2i(right, top+innerLineWidth);
|
||||||
glVertex2i(right, top);
|
glVertex2i(right, top);
|
||||||
|
|
||||||
// left
|
// left
|
||||||
glVertex2i(left, screenCoords.top()+lineWidth);
|
glVertex2i(left, screenCoords.top()+innerLineWidth);
|
||||||
glVertex2i(left, bottom-lineWidth);
|
glVertex2i(left, bottom-innerLineWidth);
|
||||||
glVertex2i(left+lineWidth, bottom-lineWidth);
|
glVertex2i(left+innerLineWidth, bottom-innerLineWidth);
|
||||||
glVertex2i(left+lineWidth, screenCoords.top()+lineWidth);
|
glVertex2i(left+innerLineWidth, screenCoords.top()+innerLineWidth);
|
||||||
|
|
||||||
// bottom line
|
// bottom line
|
||||||
glVertex2i(left, bottom);
|
glVertex2i(left, bottom);
|
||||||
glVertex2i(left, bottom-lineWidth);
|
glVertex2i(left, bottom-innerLineWidth);
|
||||||
glVertex2i(right, bottom-lineWidth);
|
glVertex2i(right, bottom-innerLineWidth);
|
||||||
glVertex2i(right, bottom);
|
glVertex2i(right, bottom);
|
||||||
|
|
||||||
// right line
|
// right line
|
||||||
glVertex2i(right, top+lineWidth);
|
glVertex2i(right, top+innerLineWidth);
|
||||||
glVertex2i(right, bottom-lineWidth);
|
glVertex2i(right, bottom-innerLineWidth);
|
||||||
glVertex2i(right-lineWidth, bottom-lineWidth);
|
glVertex2i(right-innerLineWidth, bottom-innerLineWidth);
|
||||||
glVertex2i(right-lineWidth, top+lineWidth);
|
glVertex2i(right-innerLineWidth, top+innerLineWidth);
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
|
@ -54,9 +54,10 @@ public:
|
||||||
void endRender();
|
void endRender();
|
||||||
|
|
||||||
const Size& getScreenSize() const { return m_screenSize; }
|
const Size& getScreenSize() const { return m_screenSize; }
|
||||||
|
|
||||||
void drawTexturedRect(const Rect& screenCoords, const Texture *texture, const Rect& texCoords = Rect());
|
void drawTexturedRect(const Rect& screenCoords, const Texture *texture, const Rect& texCoords = Rect());
|
||||||
void drawColoredRect(const Rect& screenCoords, const Color& color);
|
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:
|
private:
|
||||||
Size m_screenSize;
|
Size m_screenSize;
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include <boost/algorithm/string.hpp>
|
|
||||||
|
|
||||||
void Logger::log(int level, const char *trace, const char *format, ...)
|
void Logger::log(int level, const char *trace, const char *format, ...)
|
||||||
{
|
{
|
|
@ -65,6 +65,7 @@ public:
|
||||||
inline bool operator!=(const TPoint<T>& other) const { return other.x!=x || other.y!=y; }
|
inline bool operator!=(const TPoint<T>& other) const { return other.x!=x || other.y!=y; }
|
||||||
|
|
||||||
inline float length() const { return sqrtf((float)(x*x + 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<T>& other) const {
|
inline float distanceFrom(const TPoint<T>& other) const {
|
||||||
return TPoint<T>(x - other.x, y - other.y).getLength();
|
return TPoint<T>(x - other.x, y - other.y).getLength();
|
|
@ -25,14 +25,12 @@
|
||||||
#ifndef PREREQUISITES_H
|
#ifndef PREREQUISITES_H
|
||||||
#define PREREQUISITES_H
|
#define PREREQUISITES_H
|
||||||
|
|
||||||
// app name
|
// app name and version
|
||||||
#define APP_NAME "OTClient"
|
#define APP_NAME "OTClient"
|
||||||
#define APP_LONGNAME APP_NAME " " APP_VERSION
|
#define APP_LONGNAME APP_NAME " " APP_VERSION
|
||||||
|
|
||||||
// app version
|
|
||||||
#define APP_VERSION "0.1.0"
|
#define APP_VERSION "0.1.0"
|
||||||
|
|
||||||
// int types
|
// easy typing
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef unsigned char uchar;
|
typedef unsigned char uchar;
|
||||||
|
@ -47,35 +45,51 @@ typedef int32_t int32;
|
||||||
typedef int16_t int16;
|
typedef int16_t int16;
|
||||||
typedef int8_t int8;
|
typedef int8_t int8;
|
||||||
|
|
||||||
// c headers
|
// C headers
|
||||||
#include <cassert>
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <ctime>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
|
#include <cassert>
|
||||||
|
#include <ctime>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <csignal>
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
// stl headers
|
// STL headers
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <tr1/cinttypes>
|
||||||
|
|
||||||
|
// additional string algorithms
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
|
// easy casting
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
// smart pointers
|
||||||
|
#include <boost/smart_ptr.hpp>
|
||||||
|
|
||||||
|
// foreach
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
#define foreach BOOST_FOREACH
|
||||||
|
|
||||||
// GL stuff
|
// GL stuff
|
||||||
#define GL_GLEXT_PROTOTYPES
|
#define GL_GLEXT_PROTOTYPES
|
||||||
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
#include <GL/glext.h>
|
#include <GL/glext.h>
|
||||||
|
|
||||||
// utilities
|
// internal logger
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
|
// additional utilities
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#endif // PREREQUISITES_H
|
#endif // PREREQUISITES_H
|
|
@ -27,7 +27,6 @@
|
||||||
|
|
||||||
#include "prerequisites.h"
|
#include "prerequisites.h"
|
||||||
#include "size.h"
|
#include "size.h"
|
||||||
#include <boost/shared_ptr.hpp>
|
|
||||||
|
|
||||||
class TextureManager;
|
class TextureManager;
|
||||||
|
|
|
@ -26,8 +26,6 @@
|
||||||
#include "resourcemanager.h"
|
#include "resourcemanager.h"
|
||||||
#include "textureloader.h"
|
#include "textureloader.h"
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
|
||||||
|
|
||||||
TextureManager g_textures;
|
TextureManager g_textures;
|
||||||
|
|
||||||
TextureManager::TextureManager()
|
TextureManager::TextureManager()
|
|
@ -34,7 +34,7 @@ public:
|
||||||
TextureManager();
|
TextureManager();
|
||||||
~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);
|
TexturePtr get(const std::string& textureFile);
|
||||||
|
|
||||||
private:
|
private:
|
|
@ -33,21 +33,4 @@ std::string vformat(const char *format, va_list args);
|
||||||
/// Formatting like printf for std::string
|
/// Formatting like printf for std::string
|
||||||
std::string format(const char *format, ...);
|
std::string format(const char *format, ...);
|
||||||
|
|
||||||
/// Convert int/float like types to std::string
|
|
||||||
template<typename T>
|
|
||||||
inline std::string castToString(const T& x) {
|
|
||||||
std::ostringstream ss;
|
|
||||||
ss << x;
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert std:;string to int/float like types
|
|
||||||
template<typename T>
|
|
||||||
inline T castFromString(const std::string& s) {
|
|
||||||
std::istringstream ss(s);
|
|
||||||
T x = 0;
|
|
||||||
ss >> x;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
12
src/main.cpp
12
src/main.cpp
|
@ -22,16 +22,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "engine.h"
|
#include "framework/engine.h"
|
||||||
#include "configmanager.h"
|
#include "framework/configmanager.h"
|
||||||
#include "resourcemanager.h"
|
#include "framework/resourcemanager.h"
|
||||||
#include "platform.h"
|
#include "framework/platform.h"
|
||||||
#include "menustate.h"
|
#include "menustate.h"
|
||||||
|
|
||||||
#include <csignal>
|
|
||||||
|
|
||||||
#include <boost/scoped_ptr.hpp>
|
|
||||||
|
|
||||||
/// Catches signals so we can exit nicely
|
/// Catches signals so we can exit nicely
|
||||||
void signal_handler(int sig)
|
void signal_handler(int sig)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,12 +23,12 @@
|
||||||
|
|
||||||
|
|
||||||
#include "menustate.h"
|
#include "menustate.h"
|
||||||
#include "framebuffer.h"
|
#include "framework/framebuffer.h"
|
||||||
#include "graphics.h"
|
#include "framework/graphics.h"
|
||||||
#include "texturemanager.h"
|
#include "framework/texturemanager.h"
|
||||||
#include "logger.h"
|
#include "framework/logger.h"
|
||||||
#include "engine.h"
|
#include "framework/engine.h"
|
||||||
#include "rect.h"
|
#include "framework/rect.h"
|
||||||
|
|
||||||
TexturePtr background;
|
TexturePtr background;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ void MenuState::render()
|
||||||
{
|
{
|
||||||
static Size minTexCoordsSize(1240, 880);
|
static Size minTexCoordsSize(1240, 880);
|
||||||
const Size& screenSize = g_graphics.getScreenSize();
|
const Size& screenSize = g_graphics.getScreenSize();
|
||||||
Size texSize = m_background->getSize();
|
const Size& texSize = m_background->getSize();
|
||||||
|
|
||||||
Size texCoordsSize = screenSize;
|
Size texCoordsSize = screenSize;
|
||||||
if(texCoordsSize < minTexCoordsSize)
|
if(texCoordsSize < minTexCoordsSize)
|
||||||
|
|
|
@ -25,9 +25,8 @@
|
||||||
#ifndef MENUSTATE_H
|
#ifndef MENUSTATE_H
|
||||||
#define MENUSTATE_H
|
#define MENUSTATE_H
|
||||||
|
|
||||||
#include "prerequisites.h"
|
#include "framework/gamestate.h"
|
||||||
#include "gamestate.h"
|
#include "framework/texture.h"
|
||||||
#include "texture.h"
|
|
||||||
|
|
||||||
class MenuState : public GameState
|
class MenuState : public GameState
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue