mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
framework
This commit is contained in:
@@ -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<int>(value));
|
||||
setValue(key, boost::lexical_cast<std::string>(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)
|
||||
@@ -127,7 +128,7 @@ float ConfigManager::getFloat(const std::string &key)
|
||||
warning("Config value %s not found", key.c_str());
|
||||
return 0;
|
||||
}
|
||||
return castFromString<float>(iter->second);
|
||||
return boost::lexical_cast<float>(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<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
|
||||
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();
|
||||
|
@@ -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;
|
@@ -23,7 +23,6 @@
|
||||
|
||||
|
||||
#include "logger.h"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
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 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 {
|
||||
return TPoint<T>(x - other.x, y - other.y).getLength();
|
@@ -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 <stdint.h>
|
||||
|
||||
typedef unsigned char uchar;
|
||||
@@ -47,35 +45,51 @@ typedef int32_t int32;
|
||||
typedef int16_t int16;
|
||||
typedef int8_t int8;
|
||||
|
||||
// c headers
|
||||
#include <cassert>
|
||||
// C headers
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <cstring>
|
||||
#include <cstdarg>
|
||||
#include <cassert>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <csignal>
|
||||
|
||||
// stl headers
|
||||
// STL headers
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#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
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
// utilities
|
||||
// internal logger
|
||||
#include "logger.h"
|
||||
|
||||
// additional utilities
|
||||
#include "util.h"
|
||||
|
||||
#endif // PREREQUISITES_H
|
@@ -27,7 +27,6 @@
|
||||
|
||||
#include "prerequisites.h"
|
||||
#include "size.h"
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
class TextureManager;
|
||||
|
@@ -26,8 +26,6 @@
|
||||
#include "resourcemanager.h"
|
||||
#include "textureloader.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
TextureManager g_textures;
|
||||
|
||||
TextureManager::TextureManager()
|
@@ -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:
|
@@ -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<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
|
12
src/main.cpp
12
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 <csignal>
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
/// Catches signals so we can exit nicely
|
||||
void signal_handler(int sig)
|
||||
{
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user