reorganize sources
This commit is contained in:
parent
4e03b15b27
commit
d8cc37afdb
|
@ -40,7 +40,7 @@ INCLUDE_DIRECTORIES(
|
||||||
${PHYSFS_INCLUDE_DIR}
|
${PHYSFS_INCLUDE_DIR}
|
||||||
${GMP_INCLUDE_DIR}
|
${GMP_INCLUDE_DIR}
|
||||||
${ZLIB_INCLUDE_DIR}
|
${ZLIB_INCLUDE_DIR}
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/framework"
|
"${CMAKE_CURRENT_SOURCE_DIR}/src"
|
||||||
)
|
)
|
||||||
|
|
||||||
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
@ -48,23 +48,29 @@ IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
|
||||||
SET(SOURCES
|
SET(SOURCES
|
||||||
|
# main
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/otclient.cpp
|
|
||||||
src/otclientluafunctions.cpp
|
|
||||||
|
|
||||||
src/game.cpp
|
# otclient
|
||||||
src/map.cpp
|
src/otclient/otclient.cpp
|
||||||
src/protocollogin.cpp
|
src/otclient/otclientluafunctions.cpp
|
||||||
src/protocolgame.cpp
|
|
||||||
src/protocolgamesend.cpp
|
# otclient core
|
||||||
src/protocolgameparse.cpp
|
src/otclient/core/game.cpp
|
||||||
src/tibiadat.cpp
|
src/otclient/core/map.cpp
|
||||||
src/tibiaspr.cpp
|
src/otclient/core/tibiadat.cpp
|
||||||
src/item.cpp
|
src/otclient/core/tibiaspr.cpp
|
||||||
src/tile.cpp
|
src/otclient/core/item.cpp
|
||||||
src/thing.cpp
|
src/otclient/core/tile.cpp
|
||||||
src/creature.cpp
|
src/otclient/core/thing.cpp
|
||||||
src/effect.cpp
|
src/otclient/core/creature.cpp
|
||||||
|
src/otclient/core/effect.cpp
|
||||||
|
|
||||||
|
# otclient net
|
||||||
|
src/otclient/net/protocollogin.cpp
|
||||||
|
src/otclient/net/protocolgame.cpp
|
||||||
|
src/otclient/net/protocolgamesend.cpp
|
||||||
|
src/otclient/net/protocolgameparse.cpp
|
||||||
|
|
||||||
# framework third party
|
# framework third party
|
||||||
src/framework/thirdparty/apngloader.cpp
|
src/framework/thirdparty/apngloader.cpp
|
||||||
|
@ -126,7 +132,7 @@ SET(SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
IF(WIN32)
|
IF(WIN32)
|
||||||
SET(SOURCES ${SOURCES} src/framework/core/win32platform.cpp)
|
SET(SOURCES ${SOURCES} src/framework/platform/win32platform.cpp)
|
||||||
SET(ADDITIONAL_LIBRARIES ws2_32)
|
SET(ADDITIONAL_LIBRARIES ws2_32)
|
||||||
IF(CMAKE_COMPILER_IS_GNUCXX)
|
IF(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -mwindows")
|
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -mwindows")
|
||||||
|
@ -134,7 +140,7 @@ IF(WIN32)
|
||||||
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
|
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
ADD_DEFINITIONS(-DWIN32_NO_CONSOLE)
|
ADD_DEFINITIONS(-DWIN32_NO_CONSOLE)
|
||||||
ELSE(WIN32)
|
ELSE(WIN32)
|
||||||
SET(SOURCES ${SOURCES} src/framework/core/x11platform.cpp)
|
SET(SOURCES ${SOURCES} src/framework/platform/x11platform.cpp)
|
||||||
ENDIF(WIN32)
|
ENDIF(WIN32)
|
||||||
|
|
||||||
# target executable
|
# target executable
|
||||||
|
@ -153,7 +159,7 @@ TARGET_LINK_LIBRARIES(
|
||||||
)
|
)
|
||||||
|
|
||||||
IF(USE_PCH)
|
IF(USE_PCH)
|
||||||
ADD_PRECOMPILED_HEADER(otclient ${CMAKE_CURRENT_SOURCE_DIR}/src/framework/pch.h)
|
ADD_PRECOMPILED_HEADER(otclient ${CMAKE_CURRENT_SOURCE_DIR}/src/pch.h)
|
||||||
ENDIF(USE_PCH)
|
ENDIF(USE_PCH)
|
||||||
|
|
||||||
# installation
|
# installation
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
#include "creature.h"
|
|
||||||
#include "tibiadat.h"
|
|
||||||
#include "graphics/graphics.h"
|
|
||||||
#include <graphics/framebuffer.h>
|
|
||||||
#include "game.h"
|
|
||||||
|
|
||||||
#include <GL/gl.h>
|
|
||||||
#include <GL/glu.h>
|
|
||||||
#include <GL/glext.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// OW BART TEM COMO USAR 2 FRAMEBUFFER?
|
|
||||||
// SERIA O IDEAL PARA DESENHAR A COR DOS BONEQUIN.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Creature::Creature()
|
|
||||||
{
|
|
||||||
m_type = Thing::TYPE_CREATURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ThingAttributes *Creature::getAttributes()
|
|
||||||
{
|
|
||||||
return g_tibiaDat.getCreatureAttributes(m_outfit.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Creature::draw(int x, int y)
|
|
||||||
{
|
|
||||||
//ThingAttributes *creatureAttributes = getAttributes();
|
|
||||||
int anim = 0;
|
|
||||||
|
|
||||||
// draw outfit
|
|
||||||
internalDraw(x, y, 0, m_direction, 0, 0, anim);
|
|
||||||
|
|
||||||
// draw addons
|
|
||||||
//for(int a = 0; a < m_outfit.addons; ++a) {
|
|
||||||
//internalDraw(x, y, 0, m_direction, m_outfit.addons & (1 << a), 0, anim);
|
|
||||||
//}
|
|
||||||
//glPushAttrib(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT);
|
|
||||||
|
|
||||||
//glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
|
|
||||||
//Color colors[4] = {Color::yellow, Color::red, Color::green, Color::blue};
|
|
||||||
|
|
||||||
//for(int i = 0; i < 4; ++i) {
|
|
||||||
|
|
||||||
|
|
||||||
/*g_graphics.bindColor(colors[i]);
|
|
||||||
internalDraw(creatureAttributes->width*32 - 32, creatureAttributes->height*32 - 32, 1, m_direction, 0, 0, 0);
|
|
||||||
framebuffer.unbind();
|
|
||||||
|
|
||||||
|
|
||||||
g_graphics.bindColor(Color::green);*/
|
|
||||||
//framebuffer.draw(x, y, creatureAttributes->width*32, creatureAttributes->height*32);
|
|
||||||
//}
|
|
||||||
//glPopAttrib();
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
#ifndef CREATURE_H
|
|
||||||
#define CREATURE_H
|
|
||||||
|
|
||||||
#include <global.h>
|
|
||||||
#include "thing.h"
|
|
||||||
|
|
||||||
struct Outfit
|
|
||||||
{
|
|
||||||
uint16 type;
|
|
||||||
uint8 head;
|
|
||||||
uint8 body;
|
|
||||||
uint8 legs;
|
|
||||||
uint8 feet;
|
|
||||||
uint8 addons;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Creature;
|
|
||||||
typedef std::shared_ptr<Creature> CreaturePtr;
|
|
||||||
|
|
||||||
class Creature : public Thing
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Creature();
|
|
||||||
|
|
||||||
virtual ThingAttributes *getAttributes();
|
|
||||||
void draw(int x, int y);
|
|
||||||
|
|
||||||
void setName(const std::string& name) { m_name = name; }
|
|
||||||
std::string getName() { return m_name; }
|
|
||||||
|
|
||||||
void setHealthPercent(uint8 healthPercent) { m_healthPercent = healthPercent; }
|
|
||||||
uint8 getHealthPercent() { return m_healthPercent; }
|
|
||||||
|
|
||||||
void setDirection(Direction direction) { m_direction = direction; }
|
|
||||||
Direction getDirection() { return m_direction; }
|
|
||||||
|
|
||||||
void setOutfit(const Outfit& outfit) { m_outfit = outfit; }
|
|
||||||
Outfit getOutfit() { return m_outfit; }
|
|
||||||
|
|
||||||
virtual Creature *getCreature() { return this; }
|
|
||||||
virtual const Creature *getCreature() const { return this; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string m_name;
|
|
||||||
uint8 m_healthPercent;
|
|
||||||
Direction m_direction;
|
|
||||||
Outfit m_outfit;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CREATURE_H
|
|
|
@ -1,18 +0,0 @@
|
||||||
#include "effect.h"
|
|
||||||
#include "tibiadat.h"
|
|
||||||
|
|
||||||
Effect::Effect()
|
|
||||||
{
|
|
||||||
m_type = Thing::TYPE_EFFECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
ThingAttributes *Effect::getAttributes()
|
|
||||||
{
|
|
||||||
return g_tibiaDat.getEffectAttributes(m_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Effect::draw(int x, int y)
|
|
||||||
{
|
|
||||||
int anim = 0;
|
|
||||||
internalDraw(x, y, 0, 0, 0, 0, anim);
|
|
||||||
}
|
|
21
src/effect.h
21
src/effect.h
|
@ -1,21 +0,0 @@
|
||||||
#ifndef EFFECT_H
|
|
||||||
#define EFFECT_H
|
|
||||||
|
|
||||||
#include <global.h>
|
|
||||||
#include "thing.h"
|
|
||||||
|
|
||||||
class Effect;
|
|
||||||
typedef std::shared_ptr<Effect> EffectPtr;
|
|
||||||
|
|
||||||
class Effect : public Thing
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Effect();
|
|
||||||
|
|
||||||
virtual ThingAttributes *getAttributes();
|
|
||||||
void draw(int x, int y);
|
|
||||||
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // EFFECT_H
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef CONST_H
|
#ifndef FRAMEWORK_CONST_H
|
||||||
#define CONST_H
|
#define FRAMEWORK_CONST_H
|
||||||
|
|
||||||
//namespace Fw {
|
//namespace fw {
|
||||||
|
|
||||||
enum AlignmentFlag {
|
enum AlignmentFlag {
|
||||||
AlignLeft = 1,
|
AlignLeft = 1,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "configmanager.h"
|
#include "configmanager.h"
|
||||||
#include "resourcemanager.h"
|
#include "resourcemanager.h"
|
||||||
|
|
||||||
#include <otml/otml.h>
|
#include <framework/otml/otml.h>
|
||||||
|
|
||||||
ConfigManager g_configs;
|
ConfigManager g_configs;
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#ifndef CONFIGMANAGER_H
|
#ifndef CONFIGMANAGER_H
|
||||||
#define CONFIGMANAGER_H
|
#define CONFIGMANAGER_H
|
||||||
|
|
||||||
#include <global.h>
|
#include "declarations.h"
|
||||||
|
|
||||||
struct ConfigValueProxy {
|
struct ConfigValueProxy {
|
||||||
ConfigValueProxy(const std::string& v) : value(v) { }
|
ConfigValueProxy(const std::string& v) : value(v) { }
|
||||||
operator std::string() const { return aux::unsafe_cast<std::string>(value); }
|
operator std::string() const { return fw::unsafe_cast<std::string>(value); }
|
||||||
operator float() const { return aux::unsafe_cast<float>(value); }
|
operator float() const { return fw::unsafe_cast<float>(value); }
|
||||||
operator int() const { return aux::unsafe_cast<int>(value); }
|
operator int() const { return fw::unsafe_cast<int>(value); }
|
||||||
operator bool() const { return aux::unsafe_cast<bool>(value); }
|
operator bool() const { return fw::unsafe_cast<bool>(value); }
|
||||||
std::string value;
|
std::string value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ public:
|
||||||
bool save();
|
bool save();
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void set(const std::string& key, const T& value) { m_confsMap[key] = aux::unsafe_cast<std::string>(value); }
|
void set(const std::string& key, const T& value) { m_confsMap[key] = fw::unsafe_cast<std::string>(value); }
|
||||||
|
|
||||||
ConfigValueProxy get(const std::string& key) { return ConfigValueProxy(m_confsMap[key]); }
|
ConfigValueProxy get(const std::string& key) { return ConfigValueProxy(m_confsMap[key]); }
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef FRAMEWORK_CORE_DECLARATIONS_H
|
||||||
|
#define FRAMEWORK_CORE_DECLARATIONS_H
|
||||||
|
|
||||||
|
#include <framework/global.h>
|
||||||
|
|
||||||
|
class Module;
|
||||||
|
typedef std::shared_ptr<Module> ModulePtr;
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,5 +1,6 @@
|
||||||
#include "eventdispatcher.h"
|
#include "eventdispatcher.h"
|
||||||
#include <core/platform.h>
|
|
||||||
|
#include <framework/platform/platform.h>
|
||||||
|
|
||||||
EventDispatcher g_dispatcher;
|
EventDispatcher g_dispatcher;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef EVENTDISPATCHER_H
|
#ifndef EVENTDISPATCHER_H
|
||||||
#define EVENTDISPATCHER_H
|
#define EVENTDISPATCHER_H
|
||||||
|
|
||||||
#include <global.h>
|
#include "declarations.h"
|
||||||
|
|
||||||
struct ScheduledEvent {
|
struct ScheduledEvent {
|
||||||
ScheduledEvent(int ticks, const SimpleCallback& callback) : ticks(ticks), callback(callback) { }
|
ScheduledEvent(int ticks, const SimpleCallback& callback) : ticks(ticks), callback(callback) { }
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
|
||||||
#include <otml/otml.h>
|
|
||||||
#include <luascript/luainterface.h>
|
|
||||||
#include "modulemanager.h"
|
#include "modulemanager.h"
|
||||||
|
|
||||||
|
#include <framework/otml/otml.h>
|
||||||
|
#include <framework/luascript/luainterface.h>
|
||||||
|
|
||||||
void Module::discover(const OTMLNodePtr& moduleNode)
|
void Module::discover(const OTMLNodePtr& moduleNode)
|
||||||
{
|
{
|
||||||
m_description = moduleNode->readAt<std::string>("description");
|
m_description = moduleNode->readAt<std::string>("description");
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
#ifndef MODULE_H
|
#ifndef MODULE_H
|
||||||
#define MODULE_H
|
#define MODULE_H
|
||||||
|
|
||||||
#include <otml/otmldeclarations.h>
|
#include "declarations.h"
|
||||||
|
|
||||||
class Module;
|
#include <framework/otml/declarations.h>
|
||||||
typedef std::shared_ptr<Module> ModulePtr;
|
|
||||||
|
|
||||||
class Module
|
class Module
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "modulemanager.h"
|
#include "modulemanager.h"
|
||||||
#include "resourcemanager.h"
|
#include "resourcemanager.h"
|
||||||
#include <otml/otml.h>
|
|
||||||
|
#include <framework/otml/otml.h>
|
||||||
|
|
||||||
ModuleManager g_modules;
|
ModuleManager g_modules;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "resourcemanager.h"
|
#include "resourcemanager.h"
|
||||||
|
|
||||||
#include <core/platform.h>
|
#include <framework/platform/platform.h>
|
||||||
#include <luascript/luainterface.h>
|
#include <framework/luascript/luainterface.h>
|
||||||
|
|
||||||
#include <physfs.h>
|
#include <physfs.h>
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ void ResourceManager::loadFile(const std::string& fileName, std::iostream& out)
|
||||||
PHYSFS_file* file = PHYSFS_openRead(fullPath.c_str());
|
PHYSFS_file* file = PHYSFS_openRead(fullPath.c_str());
|
||||||
if(!file) {
|
if(!file) {
|
||||||
out.clear(std::ios::failbit);
|
out.clear(std::ios::failbit);
|
||||||
throw std::runtime_error(aux::make_string("failed to load file '", fullPath.c_str(), "': ", PHYSFS_getLastError()));
|
throw std::runtime_error(fw::mkstr("failed to load file '", fullPath.c_str(), "': ", PHYSFS_getLastError()));
|
||||||
} else {
|
} else {
|
||||||
int fileSize = PHYSFS_fileLength(file);
|
int fileSize = PHYSFS_fileLength(file);
|
||||||
if(fileSize > 0) {
|
if(fileSize > 0) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef RESOURCES_H
|
#ifndef RESOURCES_H
|
||||||
#define RESOURCES_H
|
#define RESOURCES_H
|
||||||
|
|
||||||
#include <global.h>
|
#include "declarations.h"
|
||||||
|
|
||||||
class ResourceManager
|
class ResourceManager
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef GLOBAL_H
|
#ifndef FRAMEWORK_GLOBAL_H
|
||||||
#define GLOBAL_H
|
#define FRAMEWORK_GLOBAL_H
|
||||||
|
|
||||||
// common C headers
|
// common C headers
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
@ -28,23 +28,22 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
// boost utilities
|
// boost utilities
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
// constants
|
// global constants
|
||||||
#include <const.h>
|
#include "const.h"
|
||||||
|
|
||||||
// additional utilities
|
// additional utilities
|
||||||
#include <util/types.h>
|
#include "util/types.h"
|
||||||
#include <util/auxiliary.h>
|
#include "util/tools.h"
|
||||||
#include <util/logger.h>
|
#include "util/logger.h"
|
||||||
#include <util/translator.h>
|
#include "util/translator.h"
|
||||||
|
#include "util/point.h"
|
||||||
// custom types
|
#include "util/color.h"
|
||||||
#include <util/point.h>
|
#include "util/rect.h"
|
||||||
#include <util/color.h>
|
#include "util/size.h"
|
||||||
#include <util/rect.h>
|
|
||||||
#include <util/size.h>
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include "animatedtexture.h"
|
#include "animatedtexture.h"
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
#include <core/platform.h>
|
|
||||||
#include <core/eventdispatcher.h>
|
#include <framework/platform/platform.h>
|
||||||
|
#include <framework/core/eventdispatcher.h>
|
||||||
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "texturemanager.h"
|
#include "texturemanager.h"
|
||||||
|
|
||||||
#include <otml/otml.h>
|
#include <framework/otml/otml.h>
|
||||||
|
|
||||||
BorderImage::BorderImage(TexturePtr texture,
|
BorderImage::BorderImage(TexturePtr texture,
|
||||||
const Rect& left,
|
const Rect& left,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef GRAPHICSDECLARATIONS_H
|
#ifndef FRAMEWORK_GRAPHICS_DECLARATIONS_H
|
||||||
#define GRAPHICSDECLARATIONS_H
|
#define FRAMEWORK_GRAPHICS_DECLARATIONS_H
|
||||||
|
|
||||||
#include <global.h>
|
#include <framework/global.h>
|
||||||
|
|
||||||
class Texture;
|
class Texture;
|
||||||
class Font;
|
class Font;
|
|
@ -2,7 +2,7 @@
|
||||||
#include "texturemanager.h"
|
#include "texturemanager.h"
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
|
|
||||||
#include <otml/otml.h>
|
#include <framework/otml/otml.h>
|
||||||
|
|
||||||
void Font::load(const OTMLNodePtr& fontNode)
|
void Font::load(const OTMLNodePtr& fontNode)
|
||||||
{
|
{
|
||||||
|
@ -24,7 +24,7 @@ void Font::load(const OTMLNodePtr& fontNode)
|
||||||
// read custom widths
|
// read custom widths
|
||||||
if(OTMLNodePtr node = fontNode->get("glyph widths")) {
|
if(OTMLNodePtr node = fontNode->get("glyph widths")) {
|
||||||
for(const OTMLNodePtr& child : node->childNodes())
|
for(const OTMLNodePtr& child : node->childNodes())
|
||||||
m_glyphsSize[aux::safe_cast<int>(child->tag())].setWidth(child->read<int>());
|
m_glyphsSize[fw::safe_cast<int>(child->tag())].setWidth(child->read<int>());
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate glyphs texture coords
|
// calculate glyphs texture coords
|
||||||
|
@ -130,8 +130,6 @@ void Font::renderText(const std::string& text,
|
||||||
}
|
}
|
||||||
|
|
||||||
g_graphics.stopDrawing();
|
g_graphics.stopDrawing();
|
||||||
|
|
||||||
g_graphics.bindColor(Color::white);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Point>& Font::calculateGlyphsPositions(const std::string& text,
|
const std::vector<Point>& Font::calculateGlyphsPositions(const std::string& text,
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#ifndef FONT_H
|
#ifndef FONT_H
|
||||||
#define FONT_H
|
#define FONT_H
|
||||||
|
|
||||||
#include "graphicsdeclarations.h"
|
#include "declarations.h"
|
||||||
#include <otml/otmldeclarations.h>
|
|
||||||
|
#include <framework/otml/declarations.h>
|
||||||
|
|
||||||
class Font
|
class Font
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "fontmanager.h"
|
#include "fontmanager.h"
|
||||||
|
|
||||||
#include <core/resourcemanager.h>
|
#include <framework/core/resourcemanager.h>
|
||||||
#include <otml/otml.h>
|
#include <framework/otml/otml.h>
|
||||||
|
|
||||||
FontManager g_fonts;
|
FontManager g_fonts;
|
||||||
|
|
||||||
|
@ -64,6 +64,6 @@ FontPtr FontManager::getDefaultFont()
|
||||||
{
|
{
|
||||||
// default font should always exists, otherwise the app may crash
|
// default font should always exists, otherwise the app may crash
|
||||||
if(!m_defaultFont)
|
if(!m_defaultFont)
|
||||||
throw std::runtime_error("no default font to display, cannot continue to run");
|
logFatal("FATAL ERROR: no default font to display, cannot continue to run");
|
||||||
return m_defaultFont;
|
return m_defaultFont;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,10 @@
|
||||||
class FontManager
|
class FontManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Release fonts references, thus making possible to destruct them
|
/// Release fonts references, thus making possible to destruct them
|
||||||
void releaseFonts();
|
void releaseFonts();
|
||||||
|
|
||||||
|
/// Import a font from .otfont file
|
||||||
bool importFont(std::string fontFile);
|
bool importFont(std::string fontFile);
|
||||||
|
|
||||||
bool fontExists(const std::string& fontName);
|
bool fontExists(const std::string& fontName);
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#include "framebuffer.h"
|
#include "framebuffer.h"
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
#include <core/platform.h>
|
#include "texture.h"
|
||||||
|
|
||||||
|
#include <framework/platform/platform.h>
|
||||||
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
#include <GL/glext.h>
|
#include <GL/glext.h>
|
||||||
|
@ -14,22 +17,13 @@ PFNGLCHECKFRAMEBUFFERSTATUSPROC oglCheckFramebufferStatus = 0;
|
||||||
FrameBuffer::FrameBuffer(int width, int height)
|
FrameBuffer::FrameBuffer(int width, int height)
|
||||||
{
|
{
|
||||||
m_fbo = 0;
|
m_fbo = 0;
|
||||||
m_width = width;
|
|
||||||
m_height = height;
|
|
||||||
|
|
||||||
// create FBO texture
|
// create FBO texture
|
||||||
glGenTextures(1, &m_fboTexture);
|
m_texture = TexturePtr(new Texture(width, height, 4));
|
||||||
glBindTexture(GL_TEXTURE_2D, m_fboTexture);
|
m_texture->enableBilinearFilter();
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
|
|
||||||
// we want bilinear filtering (for a smooth framebuffer)
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
|
|
||||||
// use FBO ext only if supported
|
// use FBO ext only if supported
|
||||||
if(g_graphics.isExtensionSupported("GL_ARB_framebuffer_object")) {
|
if(false && g_graphics.isExtensionSupported("GL_ARB_framebuffer_object")) {
|
||||||
m_fallbackOldImp = false;
|
m_fallbackOldImp = false;
|
||||||
if(!oglGenFramebuffers) {
|
if(!oglGenFramebuffers) {
|
||||||
oglGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)g_platform.getExtensionProcAddress("glGenFramebuffers");
|
oglGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)g_platform.getExtensionProcAddress("glGenFramebuffers");
|
||||||
|
@ -44,7 +38,7 @@ FrameBuffer::FrameBuffer(int width, int height)
|
||||||
oglBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo);
|
oglBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo);
|
||||||
|
|
||||||
// attach 2D texture to this FBO
|
// attach 2D texture to this FBO
|
||||||
oglFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_fboTexture, 0);
|
oglFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_texture->getId(), 0);
|
||||||
|
|
||||||
GLenum status = oglCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
|
GLenum status = oglCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
|
||||||
switch(status) {
|
switch(status) {
|
||||||
|
@ -58,6 +52,8 @@ FrameBuffer::FrameBuffer(int width, int height)
|
||||||
|
|
||||||
// restore back buffer
|
// restore back buffer
|
||||||
oglBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
|
oglBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
|
||||||
|
glDrawBuffer(GL_BACK);
|
||||||
|
glReadBuffer(GL_BACK);
|
||||||
} else {
|
} else {
|
||||||
// otherwise fallback to copy texture from screen implementation
|
// otherwise fallback to copy texture from screen implementation
|
||||||
m_fallbackOldImp = true;
|
m_fallbackOldImp = true;
|
||||||
|
@ -66,7 +62,6 @@ FrameBuffer::FrameBuffer(int width, int height)
|
||||||
|
|
||||||
FrameBuffer::~FrameBuffer()
|
FrameBuffer::~FrameBuffer()
|
||||||
{
|
{
|
||||||
glDeleteTextures(1, &m_fboTexture);
|
|
||||||
if(m_fbo)
|
if(m_fbo)
|
||||||
oglDeleteFramebuffers(1, &m_fbo);
|
oglDeleteFramebuffers(1, &m_fbo);
|
||||||
}
|
}
|
||||||
|
@ -79,10 +74,10 @@ void FrameBuffer::bind()
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup framebuffer viewport
|
// setup framebuffer viewport
|
||||||
glViewport(0, 0, m_width, m_height);
|
glViewport(0, 0, m_texture->getWidth(), m_texture->getHeight());
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluOrtho2D(0.0f, m_width, 0, m_height);
|
gluOrtho2D(0.0f, m_texture->getWidth(), 0, m_texture->getHeight());
|
||||||
|
|
||||||
// back to model view
|
// back to model view
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
@ -105,8 +100,8 @@ void FrameBuffer::unbind()
|
||||||
g_graphics.restoreViewport();
|
g_graphics.restoreViewport();
|
||||||
} else {
|
} else {
|
||||||
// copy screen to texture
|
// copy screen to texture
|
||||||
glBindTexture(GL_TEXTURE_2D, m_fboTexture);
|
glBindTexture(GL_TEXTURE_2D, m_texture->getId());
|
||||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_width, m_height);
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_texture->getWidth(), m_texture->getHeight());
|
||||||
|
|
||||||
// restore graphics viewport
|
// restore graphics viewport
|
||||||
g_graphics.restoreViewport();
|
g_graphics.restoreViewport();
|
||||||
|
@ -117,14 +112,7 @@ void FrameBuffer::unbind()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameBuffer::draw(int x, int y, int width, int height)
|
void FrameBuffer::draw(const Rect& screenCoords, const Rect& framebufferCoords)
|
||||||
{
|
{
|
||||||
glColor4ubv(Color::white.rgbaPtr());
|
g_graphics.drawTexturedRect(screenCoords, m_texture ,framebufferCoords);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_fboTexture);
|
|
||||||
glBegin(GL_QUADS);
|
|
||||||
glTexCoord2i(0, 0); glVertex2i(x, y);
|
|
||||||
glTexCoord2i(0, 1); glVertex2i(x, y+height);
|
|
||||||
glTexCoord2i(1, 1); glVertex2i(x+width, y+height);
|
|
||||||
glTexCoord2i(1, 0); glVertex2i(x+width, y);
|
|
||||||
glEnd();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef FRAMEBUFFER_H
|
#ifndef FRAMEBUFFER_H
|
||||||
#define FRAMEBUFFER_H
|
#define FRAMEBUFFER_H
|
||||||
|
|
||||||
#include "graphicsdeclarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
class FrameBuffer
|
class FrameBuffer
|
||||||
{
|
{
|
||||||
|
@ -9,21 +9,21 @@ public:
|
||||||
FrameBuffer(int width, int height);
|
FrameBuffer(int width, int height);
|
||||||
virtual ~FrameBuffer();
|
virtual ~FrameBuffer();
|
||||||
|
|
||||||
/// Bind the framebuffer, everything rendered will be draw on it
|
/// Binds the framebuffer, by switching render buffer to itself, everything rendered will be draw on it
|
||||||
void bind();
|
void bind();
|
||||||
|
|
||||||
/// Unbind the framebuffer, render on back buffer again
|
/// Unbinds the framebuffer (switch render buffer to back buffer again)
|
||||||
void unbind();
|
void unbind();
|
||||||
|
|
||||||
/// Draw framebuffer
|
/// Draws framebuffer texture
|
||||||
void draw(int x, int y, int width, int height);
|
void draw(const Rect& screenCoords, const Rect& framebufferCoords = Rect());
|
||||||
|
|
||||||
|
TexturePtr getTexture() { return m_texture; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint m_fboTexture;
|
TexturePtr m_texture;
|
||||||
uint m_fbo;
|
uint m_fbo;
|
||||||
bool m_fallbackOldImp;
|
bool m_fallbackOldImp;
|
||||||
int m_width;
|
|
||||||
int m_height;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include <graphics/graphics.h>
|
|
||||||
#include <graphics/texture.h>
|
|
||||||
#include "fontmanager.h"
|
#include "fontmanager.h"
|
||||||
|
|
||||||
|
#include <framework/graphics/graphics.h>
|
||||||
|
#include <framework/graphics/texture.h>
|
||||||
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
#include <GL/glext.h>
|
#include <GL/glext.h>
|
||||||
|
@ -109,7 +110,7 @@ void Graphics::drawTexturedRect(const Rect& screenCoords,
|
||||||
const TexturePtr& texture,
|
const TexturePtr& texture,
|
||||||
const Rect& textureCoords)
|
const Rect& textureCoords)
|
||||||
{
|
{
|
||||||
if(screenCoords.isEmpty() || textureCoords.isEmpty())
|
if(screenCoords.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// rect correction for opengl
|
// rect correction for opengl
|
||||||
|
@ -119,12 +120,17 @@ void Graphics::drawTexturedRect(const Rect& screenCoords,
|
||||||
int left = screenCoords.left();
|
int left = screenCoords.left();
|
||||||
const Size& textureSize = texture->getGlSize();
|
const Size& textureSize = texture->getGlSize();
|
||||||
|
|
||||||
float textureRight = 0.0f;
|
float textureRight;
|
||||||
float textureBottom = 1.0f;
|
float textureBottom;
|
||||||
float textureTop = 0.0f;
|
float textureTop;
|
||||||
float textureLeft = 1.0f;
|
float textureLeft;
|
||||||
|
|
||||||
if(!textureCoords.isEmpty()) {
|
if(textureCoords.isEmpty()) {
|
||||||
|
textureRight = 1.0f;
|
||||||
|
textureBottom = 1.0f;
|
||||||
|
textureTop = 0.0f;
|
||||||
|
textureLeft = 0.0f;
|
||||||
|
} else {
|
||||||
textureRight = (float)(textureCoords.right() + 1) / textureSize.width();
|
textureRight = (float)(textureCoords.right() + 1) / textureSize.width();
|
||||||
textureBottom = (float)(textureCoords.bottom() + 1) / textureSize.height();
|
textureBottom = (float)(textureCoords.bottom() + 1) / textureSize.height();
|
||||||
textureTop = (float)textureCoords.top() / textureSize.height();
|
textureTop = (float)textureCoords.top() / textureSize.height();
|
||||||
|
@ -222,7 +228,7 @@ void Graphics::drawBoundingRect(const Rect& screenCoords,
|
||||||
{
|
{
|
||||||
assert(!m_drawing);
|
assert(!m_drawing);
|
||||||
|
|
||||||
if(2 * innerLineWidth > screenCoords.height() || screenCoords.isEmpty())
|
if(screenCoords.isEmpty() || 2 * innerLineWidth > screenCoords.height())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// rect correction for opengl
|
// rect correction for opengl
|
||||||
|
@ -274,7 +280,7 @@ void Graphics::bindColor(const Color& color)
|
||||||
|
|
||||||
void Graphics::bindTexture(const TexturePtr& texture)
|
void Graphics::bindTexture(const TexturePtr& texture)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, texture->getTextureId());
|
glBindTexture(GL_TEXTURE_2D, texture->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::startDrawing()
|
void Graphics::startDrawing()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef GRAPHICS_H
|
#ifndef GRAPHICS_H
|
||||||
#define GRAPHICS_H
|
#define GRAPHICS_H
|
||||||
|
|
||||||
#include "graphicsdeclarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
class Graphics
|
class Graphics
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
#include "texturemanager.h"
|
#include "texturemanager.h"
|
||||||
|
|
||||||
#include <otml/otml.h>
|
#include <framework/otml/otml.h>
|
||||||
|
|
||||||
Image::Image(TexturePtr texture, Rect textureCoords)
|
Image::Image(TexturePtr texture, Rect textureCoords)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#ifndef IMAGE_H
|
#ifndef IMAGE_H
|
||||||
#define IMAGE_H
|
#define IMAGE_H
|
||||||
|
|
||||||
#include "graphicsdeclarations.h"
|
#include "declarations.h"
|
||||||
#include <otml/otmldeclarations.h>
|
|
||||||
|
#include <framework/otml/declarations.h>
|
||||||
|
|
||||||
class Image
|
class Image
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,7 +11,9 @@ Texture::Texture(int width, int height, int channels, uchar *pixels)
|
||||||
|
|
||||||
uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int height)
|
uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int height)
|
||||||
{
|
{
|
||||||
// get smax texture size supported by the driver
|
m_size.setSize(width, height);
|
||||||
|
|
||||||
|
// gets max texture size supported by the driver
|
||||||
static GLint maxTexSize = -1;
|
static GLint maxTexSize = -1;
|
||||||
if(maxTexSize == -1)
|
if(maxTexSize == -1)
|
||||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
|
||||||
|
@ -28,7 +30,6 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int
|
||||||
GLuint id;
|
GLuint id;
|
||||||
glGenTextures(1, &id);
|
glGenTextures(1, &id);
|
||||||
glBindTexture(GL_TEXTURE_2D, id);
|
glBindTexture(GL_TEXTURE_2D, id);
|
||||||
m_size.setSize(width, height);
|
|
||||||
bool mustFree = false;
|
bool mustFree = false;
|
||||||
|
|
||||||
// old opengl drivers only accept power of two dimensions
|
// old opengl drivers only accept power of two dimensions
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef TEXTURE_H
|
#ifndef TEXTURE_H
|
||||||
#define TEXTURE_H
|
#define TEXTURE_H
|
||||||
|
|
||||||
#include "graphicsdeclarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
class Texture : public std::enable_shared_from_this<Texture>
|
class Texture : public std::enable_shared_from_this<Texture>
|
||||||
{
|
{
|
||||||
|
@ -14,12 +14,14 @@ public:
|
||||||
virtual void enableBilinearFilter();
|
virtual void enableBilinearFilter();
|
||||||
|
|
||||||
/// Get OpenGL texture id
|
/// Get OpenGL texture id
|
||||||
virtual uint getTextureId() const { return m_textureId; }
|
virtual uint getId() const { return m_textureId; }
|
||||||
|
|
||||||
/// Copy pixels from OpenGL texture
|
/// Copy pixels from OpenGL texture
|
||||||
uchar* getPixels();
|
uchar* getPixels();
|
||||||
|
|
||||||
const Size& getSize() const { return m_size; }
|
int getWidth() const { return m_size.width(); }
|
||||||
|
int getHeight() const { return m_size.height(); }
|
||||||
|
const Size getSize() const { return m_size; }
|
||||||
const Size& getGlSize() const { return m_glSize; }
|
const Size& getGlSize() const { return m_glSize; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include "texturemanager.h"
|
#include "texturemanager.h"
|
||||||
#include "animatedtexture.h"
|
#include "animatedtexture.h"
|
||||||
#include <core/resourcemanager.h>
|
|
||||||
#include <thirdparty/apngloader.h>
|
#include <framework/core/resourcemanager.h>
|
||||||
|
#include <framework/thirdparty/apngloader.h>
|
||||||
|
|
||||||
TextureManager g_textures;
|
TextureManager g_textures;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#ifndef LUADECLARATIONS_H
|
#ifndef FRAMEWORK_LUA_DECLARATIONS_H
|
||||||
#define LUADECLARATIONS_H
|
#define FRAMEWORK_LUA_DECLARATIONS_H
|
||||||
|
|
||||||
#include <global.h>
|
#include <framework/global.h>
|
||||||
|
|
||||||
class LuaInterface;
|
class LuaInterface;
|
||||||
class LuaObject;
|
class LuaObject;
|
||||||
|
|
||||||
typedef std::function<int(LuaInterface*)> LuaCppFunction;
|
typedef std::function<int(LuaInterface*)> LuaCppFunction;
|
||||||
typedef std::unique_ptr<LuaCppFunction> LuaCppFunctionPtr;
|
typedef std::unique_ptr<LuaCppFunction> LuaCppFunctionPtr;
|
||||||
typedef std::shared_ptr<LuaObject> LuaObjectPtr;
|
typedef std::shared_ptr<LuaObject> LuaObjectPtr;
|
|
@ -11,21 +11,21 @@ void LuaException::generateLuaErrorMessage(const std::string& error, int traceLe
|
||||||
{
|
{
|
||||||
// append trace level to error message
|
// append trace level to error message
|
||||||
if(traceLevel >= 0)
|
if(traceLevel >= 0)
|
||||||
m_what = aux::make_string("LUA ERROR: ", g_lua.traceback(error, traceLevel));
|
m_what = fw::mkstr("LUA ERROR: ", g_lua.traceback(error, traceLevel));
|
||||||
else
|
else
|
||||||
m_what = aux::make_string("LUA ERROR: ", error);
|
m_what = fw::mkstr("LUA ERROR: ", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaBadNumberOfArgumentsException::LuaBadNumberOfArgumentsException(int expected, int got)
|
LuaBadNumberOfArgumentsException::LuaBadNumberOfArgumentsException(int expected, int got)
|
||||||
{
|
{
|
||||||
std::string error = "attempt to call a function with wrong number of arguments";
|
std::string error = "attempt to call a function with wrong number of arguments";
|
||||||
if(expected >= 0 && got >= 0)
|
if(expected >= 0 && got >= 0)
|
||||||
error = aux::make_string(error, " (expected ", expected, ", but got ", got, ")");
|
error = fw::mkstr(error, " (expected ", expected, ", but got ", got, ")");
|
||||||
generateLuaErrorMessage(error, 1);
|
generateLuaErrorMessage(error, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaBadValueCastException::LuaBadValueCastException(const std::string& luaTypeName, const std::string& cppTypeName)
|
LuaBadValueCastException::LuaBadValueCastException(const std::string& luaTypeName, const std::string& cppTypeName)
|
||||||
{
|
{
|
||||||
std::string error = aux::make_string("attempt to cast a '", luaTypeName, "' lua value to '", cppTypeName, "'");
|
std::string error = fw::mkstr("attempt to cast a '", luaTypeName, "' lua value to '", cppTypeName, "'");
|
||||||
generateLuaErrorMessage(error, 0);
|
generateLuaErrorMessage(error, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef LUAEXCEPTION_H
|
#ifndef LUAEXCEPTION_H
|
||||||
#define LUAEXCEPTION_H
|
#define LUAEXCEPTION_H
|
||||||
|
|
||||||
#include "luadeclarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
class LuaException : public std::exception
|
class LuaException : public std::exception
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "luainterface.h"
|
#include "luainterface.h"
|
||||||
#include <graphics/fontmanager.h>
|
#include <framework/graphics/fontmanager.h>
|
||||||
#include <ui/ui.h>
|
#include <framework/ui/ui.h>
|
||||||
#include <net/protocol.h>
|
#include <framework/net/protocol.h>
|
||||||
#include <core/eventdispatcher.h>
|
#include <framework/core/eventdispatcher.h>
|
||||||
|
|
||||||
void LuaInterface::registerFunctions()
|
void LuaInterface::registerFunctions()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "luainterface.h"
|
#include "luainterface.h"
|
||||||
#include "luaobject.h"
|
#include "luaobject.h"
|
||||||
|
|
||||||
#include <core/resourcemanager.h>
|
#include <framework/core/resourcemanager.h>
|
||||||
#include <lua.hpp>
|
#include <lua.hpp>
|
||||||
|
|
||||||
LuaInterface g_lua;
|
LuaInterface g_lua;
|
||||||
|
@ -20,7 +20,7 @@ void LuaInterface::init()
|
||||||
createLuaState();
|
createLuaState();
|
||||||
|
|
||||||
// check if demangle_type is working as expected
|
// check if demangle_type is working as expected
|
||||||
assert(aux::demangle_type<LuaObject>() == "LuaObject");
|
assert(fw::demangle_type<LuaObject>() == "LuaObject");
|
||||||
|
|
||||||
// register LuaObject, the base of all other objects
|
// register LuaObject, the base of all other objects
|
||||||
registerClass<LuaObject>();
|
registerClass<LuaObject>();
|
||||||
|
@ -125,12 +125,12 @@ void LuaInterface::registerClassMemberField(const std::string& className,
|
||||||
|
|
||||||
if(getFunction) {
|
if(getFunction) {
|
||||||
pushCppFunction(getFunction);
|
pushCppFunction(getFunction);
|
||||||
setField(aux::make_string("get_", field));
|
setField(fw::mkstr("get_", field));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(setFunction) {
|
if(setFunction) {
|
||||||
pushCppFunction(setFunction);
|
pushCppFunction(setFunction);
|
||||||
setField(aux::make_string("set_", field));
|
setField(fw::mkstr("set_", field));
|
||||||
}
|
}
|
||||||
|
|
||||||
pop();
|
pop();
|
||||||
|
@ -273,7 +273,7 @@ void LuaInterface::loadFunction(const std::string& buffer, const std::string& so
|
||||||
// gets the function contained in that buffer
|
// gets the function contained in that buffer
|
||||||
if(boost::starts_with(buffer, "function")) {
|
if(boost::starts_with(buffer, "function")) {
|
||||||
// evaluate the function
|
// evaluate the function
|
||||||
std::string buf = aux::make_string("__func = ", buffer);
|
std::string buf = fw::mkstr("__func = ", buffer);
|
||||||
loadBuffer(buf, source);
|
loadBuffer(buf, source);
|
||||||
safeCall();
|
safeCall();
|
||||||
|
|
||||||
|
@ -295,7 +295,7 @@ void LuaInterface::evaluateExpression(const std::string& expression, const std::
|
||||||
{
|
{
|
||||||
// evaluates the expression
|
// evaluates the expression
|
||||||
if(!expression.empty()) {
|
if(!expression.empty()) {
|
||||||
std::string buffer = aux::make_string("__exp = (", expression, ")");
|
std::string buffer = fw::mkstr("__exp = (", expression, ")");
|
||||||
loadBuffer(buffer, source);
|
loadBuffer(buffer, source);
|
||||||
safeCall();
|
safeCall();
|
||||||
|
|
||||||
|
@ -898,7 +898,7 @@ void LuaInterface::pushObject(const LuaObjectPtr& obj)
|
||||||
new(newUserdata(sizeof(LuaObjectPtr))) LuaObjectPtr(obj);
|
new(newUserdata(sizeof(LuaObjectPtr))) LuaObjectPtr(obj);
|
||||||
|
|
||||||
// set the userdata metatable
|
// set the userdata metatable
|
||||||
getGlobal(aux::make_string(obj->getLuaObjectName(), "_mt"));
|
getGlobal(fw::mkstr(obj->getLuaObjectName(), "_mt"));
|
||||||
assert(!isNil());
|
assert(!isNil());
|
||||||
setMetatable();
|
setMetatable();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef LUAINTERFACE_H
|
#ifndef LUAINTERFACE_H
|
||||||
#define LUAINTERFACE_H
|
#define LUAINTERFACE_H
|
||||||
|
|
||||||
#include "luadeclarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
struct lua_State;
|
struct lua_State;
|
||||||
typedef int (*LuaCFunction) (lua_State *L);
|
typedef int (*LuaCFunction) (lua_State *L);
|
||||||
|
@ -41,24 +41,24 @@ public:
|
||||||
// register shortcuts using templates
|
// register shortcuts using templates
|
||||||
template<class C, class B = LuaObject>
|
template<class C, class B = LuaObject>
|
||||||
void registerClass() {
|
void registerClass() {
|
||||||
registerClass(aux::demangle_type<C>(), aux::demangle_type<B>());
|
registerClass(fw::demangle_type<C>(), fw::demangle_type<B>());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class C>
|
template<class C>
|
||||||
void registerClassStaticFunction(const std::string& functionName, const LuaCppFunction& function) {
|
void registerClassStaticFunction(const std::string& functionName, const LuaCppFunction& function) {
|
||||||
registerClassStaticFunction(aux::demangle_type<C>(), functionName, function);
|
registerClassStaticFunction(fw::demangle_type<C>(), functionName, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class C>
|
template<class C>
|
||||||
void registerClassMemberFunction(const std::string& functionName, const LuaCppFunction& function) {
|
void registerClassMemberFunction(const std::string& functionName, const LuaCppFunction& function) {
|
||||||
registerClassMemberFunction(aux::demangle_type<C>(), functionName, function);
|
registerClassMemberFunction(fw::demangle_type<C>(), functionName, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class C>
|
template<class C>
|
||||||
void registerClassMemberField(const std::string& field,
|
void registerClassMemberField(const std::string& field,
|
||||||
const LuaCppFunction& getFunction,
|
const LuaCppFunction& getFunction,
|
||||||
const LuaCppFunction& setFunction) {
|
const LuaCppFunction& setFunction) {
|
||||||
registerClassMemberField(aux::demangle_type<C>(), field, getFunction, setFunction);
|
registerClassMemberField(fw::demangle_type<C>(), field, getFunction, setFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// methods for binding functions
|
// methods for binding functions
|
||||||
|
@ -322,7 +322,7 @@ template<class T>
|
||||||
T LuaInterface::castValue(int index) {
|
T LuaInterface::castValue(int index) {
|
||||||
T o;
|
T o;
|
||||||
if(!luavalue_cast(index, o))
|
if(!luavalue_cast(index, o))
|
||||||
throw LuaBadValueCastException(typeName(index), aux::demangle_type<T>());
|
throw LuaBadValueCastException(typeName(index), fw::demangle_type<T>());
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#ifndef LUAOBJECT_H
|
#ifndef LUAOBJECT_H
|
||||||
#define LUAOBJECT_H
|
#define LUAOBJECT_H
|
||||||
|
|
||||||
#include "luadeclarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
/// LuaObject, all script-able classes have it as base
|
/// LuaObject, all script-able classes have it as base
|
||||||
class LuaObject : public std::enable_shared_from_this<LuaObject>
|
class LuaObject : public std::enable_shared_from_this<LuaObject>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LuaObject();
|
LuaObject();
|
||||||
virtual ~LuaObject() ;
|
virtual ~LuaObject();
|
||||||
|
|
||||||
/// Calls a function or table of functions stored in a lua field, results are pushed onto the stack,
|
/// Calls a function or table of functions stored in a lua field, results are pushed onto the stack,
|
||||||
/// if any lua error occurs, it will be reported to stdout and return 0 results
|
/// if any lua error occurs, it will be reported to stdout and return 0 results
|
||||||
|
@ -40,7 +40,7 @@ public:
|
||||||
/// Returns the class name used in Lua
|
/// Returns the class name used in Lua
|
||||||
virtual std::string getLuaObjectName() const {
|
virtual std::string getLuaObjectName() const {
|
||||||
// this could later be cached for more performance
|
// this could later be cached for more performance
|
||||||
return aux::demangle_name(typeid(*this).name());
|
return fw::demangle_name(typeid(*this).name());
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaObjectPtr asLuaObject() { return shared_from_this(); }
|
LuaObjectPtr asLuaObject() { return shared_from_this(); }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
|
|
||||||
#include <core/eventdispatcher.h>
|
#include <framework/core/eventdispatcher.h>
|
||||||
|
|
||||||
static asio::io_service ioService;
|
static asio::io_service ioService;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ void Connection::connect(const std::string& host, uint16 port, const ConnectCall
|
||||||
{
|
{
|
||||||
m_connectCallback = connectCallback;
|
m_connectCallback = connectCallback;
|
||||||
|
|
||||||
asio::ip::tcp::resolver::query query(host, aux::unsafe_cast<std::string>(port));
|
asio::ip::tcp::resolver::query query(host, fw::unsafe_cast<std::string>(port));
|
||||||
m_resolver.async_resolve(query, std::bind(&Connection::onResolve, shared_from_this(), std::placeholders::_1, std::placeholders::_2));
|
m_resolver.async_resolve(query, std::bind(&Connection::onResolve, shared_from_this(), std::placeholders::_1, std::placeholders::_2));
|
||||||
|
|
||||||
m_timer.expires_from_now(boost::posix_time::seconds(2));
|
m_timer.expires_from_now(boost::posix_time::seconds(2));
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#ifndef CONNECTION_H
|
#ifndef CONNECTION_H
|
||||||
#define CONNECTION_H
|
#define CONNECTION_H
|
||||||
|
|
||||||
#include "netdeclarations.h"
|
#include "declarations.h"
|
||||||
|
#include <boost/asio.hpp>
|
||||||
|
|
||||||
class Connection : public std::enable_shared_from_this<Connection>, boost::noncopyable
|
class Connection : public std::enable_shared_from_this<Connection>, boost::noncopyable
|
||||||
{
|
{
|
||||||
|
@ -11,7 +12,7 @@ class Connection : public std::enable_shared_from_this<Connection>, boost::nonco
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Connection();
|
Connection();
|
||||||
~Connection();
|
virtual ~Connection();
|
||||||
|
|
||||||
static void poll();
|
static void poll();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef FRAMEWORK_NET_DECLARATIONS_H
|
||||||
|
#define FRAMEWORK_NET_DECLARATIONS_H
|
||||||
|
|
||||||
|
#include <framework/global.h>
|
||||||
|
#include <boost/asio.hpp>
|
||||||
|
|
||||||
|
namespace asio = boost::asio;
|
||||||
|
|
||||||
|
class Connection;
|
||||||
|
class InputMessage;
|
||||||
|
class OutputMessage;
|
||||||
|
class Protocol;
|
||||||
|
|
||||||
|
typedef std::shared_ptr<Connection> ConnectionPtr;
|
||||||
|
typedef std::shared_ptr<Protocol> ProtocolPtr;
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef INPUTMESSAGE_H
|
#ifndef INPUTMESSAGE_H
|
||||||
#define INPUTMESSAGE_H
|
#define INPUTMESSAGE_H
|
||||||
|
|
||||||
#include "netdeclarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
class InputMessage
|
class InputMessage
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
#ifndef NETDECLARATIONS_H
|
|
||||||
#define NETDECLARATIONS_H
|
|
||||||
|
|
||||||
#include <global.h>
|
|
||||||
#include <boost/asio.hpp>
|
|
||||||
|
|
||||||
namespace asio = boost::asio;
|
|
||||||
|
|
||||||
class Connection;
|
|
||||||
class InputMessage;
|
|
||||||
class OutputMessage;
|
|
||||||
class Protocol;
|
|
||||||
|
|
||||||
typedef std::shared_ptr<Connection> ConnectionPtr;
|
|
||||||
typedef std::shared_ptr<Protocol> ProtocolPtr;
|
|
||||||
|
|
||||||
#define CIPSOFT_PUBLIC_RSA "1321277432058722840622950990822933849527763264961655079678763618" \
|
|
||||||
"4334395343554449668205332383339435179772895415509701210392836078" \
|
|
||||||
"6959821132214473291575712138800495033169914814069637740318278150" \
|
|
||||||
"2907336840325241747827401343576296990629870233111328210165697754" \
|
|
||||||
"88792221429527047321331896351555606801473202394175817"
|
|
||||||
|
|
||||||
|
|
||||||
#define OTSERV_PUBLIC_RSA "1091201329673994292788609605089955415282375029027981291234687579" \
|
|
||||||
"3726629149257644633073969600111060390723088861007265581882535850" \
|
|
||||||
"3429057592827629436413108566029093628212635953836686562675849720" \
|
|
||||||
"6207862794310902180176810615217550567108238764764442605581471797" \
|
|
||||||
"07119674283982419152118103759076030616683978566631413"
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include <net/outputmessage.h>
|
#include <framework/net/outputmessage.h>
|
||||||
|
|
||||||
OutputMessage::OutputMessage()
|
OutputMessage::OutputMessage()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef OUTPUTMESSAGE_H
|
#ifndef OUTPUTMESSAGE_H
|
||||||
#define OUTPUTMESSAGE_H
|
#define OUTPUTMESSAGE_H
|
||||||
|
|
||||||
#include "netdeclarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
class OutputMessage
|
class OutputMessage
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#ifndef PROTOCOL_H
|
#ifndef PROTOCOL_H
|
||||||
#define PROTOCOL_H
|
#define PROTOCOL_H
|
||||||
|
|
||||||
#include "netdeclarations.h"
|
#include "declarations.h"
|
||||||
#include "inputmessage.h"
|
#include "inputmessage.h"
|
||||||
#include "outputmessage.h"
|
#include "outputmessage.h"
|
||||||
|
|
||||||
#include <luascript/luaobject.h>
|
#include <framework/luascript/luaobject.h>
|
||||||
|
|
||||||
class Protocol : public LuaObject
|
class Protocol : public LuaObject
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef RSA_H
|
#ifndef RSA_H
|
||||||
#define RSA_H
|
#define RSA_H
|
||||||
|
|
||||||
#include <global.h>
|
#include <framework/global.h>
|
||||||
#include <gmp.h>
|
#include <gmp.h>
|
||||||
|
|
||||||
class Rsa
|
class Rsa
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef OTMLDECLARATIONS_H
|
#ifndef FRAMEWORK_OTML_DECLARATIONS_H
|
||||||
#define OTMLDECLARATIONS_H
|
#define FRAMEWORK_OTML_DECLARATIONS_H
|
||||||
|
|
||||||
#include <global.h>
|
#include <framework/global.h>
|
||||||
|
|
||||||
class OTMLNode;
|
class OTMLNode;
|
||||||
class OTMLDocument;
|
class OTMLDocument;
|
|
@ -2,7 +2,7 @@
|
||||||
#include "otmlparser.h"
|
#include "otmlparser.h"
|
||||||
#include "otmlemitter.h"
|
#include "otmlemitter.h"
|
||||||
|
|
||||||
#include <core/resourcemanager.h>
|
#include <framework/core/resourcemanager.h>
|
||||||
|
|
||||||
OTMLDocumentPtr OTMLDocument::create()
|
OTMLDocumentPtr OTMLDocument::create()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef OTMLEMITTER_H
|
#ifndef OTMLEMITTER_H
|
||||||
#define OTMLEMITTER_H
|
#define OTMLEMITTER_H
|
||||||
|
|
||||||
#include "otmldeclarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
class OTMLEmitter
|
class OTMLEmitter
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef OTMLEXCEPTION_H
|
#ifndef OTMLEXCEPTION_H
|
||||||
#define OTMLEXCEPTION_H
|
#define OTMLEXCEPTION_H
|
||||||
|
|
||||||
#include "otmldeclarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
/// All OTML errors throw this exception
|
/// All OTML errors throw this exception
|
||||||
class OTMLException : public std::exception
|
class OTMLException : public std::exception
|
||||||
|
|
|
@ -16,7 +16,7 @@ std::string OTMLNode::value() const
|
||||||
{
|
{
|
||||||
// ~ is an alias for no value
|
// ~ is an alias for no value
|
||||||
if(m_value == "~")
|
if(m_value == "~")
|
||||||
return aux::empty_string;
|
return fw::empty_string;
|
||||||
return m_value;
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ OTMLNodePtr OTMLNode::at(const std::string& childTag)
|
||||||
if(child->tag() == childTag)
|
if(child->tag() == childTag)
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
throw OTMLException(shared_from_this(), aux::make_string("child node with tag '", childTag, "' not found"));
|
throw OTMLException(shared_from_this(), fw::mkstr("child node with tag '", childTag, "' not found"));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ OTMLNodePtr OTMLNode::at(int childIndex)
|
||||||
{
|
{
|
||||||
if(childIndex < size() && childIndex >= 0)
|
if(childIndex < size() && childIndex >= 0)
|
||||||
return m_childNodes[childIndex];
|
return m_childNodes[childIndex];
|
||||||
throw OTMLException(shared_from_this(), aux::make_string("child node at index '", childIndex, "' not found"));
|
throw OTMLException(shared_from_this(), fw::mkstr("child node at index '", childIndex, "' not found"));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef OTMLNODE_H
|
#ifndef OTMLNODE_H
|
||||||
#define OTMLNODE_H
|
#define OTMLNODE_H
|
||||||
|
|
||||||
#include "otmldeclarations.h"
|
#include "declarations.h"
|
||||||
#include "otmlexception.h"
|
#include "otmlexception.h"
|
||||||
|
|
||||||
class OTMLNode : public std::enable_shared_from_this<OTMLNode>
|
class OTMLNode : public std::enable_shared_from_this<OTMLNode>
|
||||||
|
@ -90,7 +90,7 @@ T OTMLNode::read() {
|
||||||
T v;
|
T v;
|
||||||
if(!from_otmlnode(shared_from_this(), v))
|
if(!from_otmlnode(shared_from_this(), v))
|
||||||
throw OTMLException(shared_from_this(),
|
throw OTMLException(shared_from_this(),
|
||||||
aux::make_string("failed to cast node value to type '", aux::demangle_type<T>(), "'"));
|
fw::mkstr("failed to cast node value to type '", fw::demangle_type<T>(), "'"));
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ void OTMLNode::writeIn(const T& v) {
|
||||||
// templates for casting a node to another type
|
// templates for casting a node to another type
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool from_otmlnode(OTMLNodePtr node, T& v) {
|
bool from_otmlnode(OTMLNodePtr node, T& v) {
|
||||||
return aux::cast(node->value(), v);
|
return fw::cast(node->value(), v);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -169,7 +169,7 @@ template <typename K, typename T>
|
||||||
bool from_otmlnode(OTMLNodePtr node, std::map<K, T>& m) {
|
bool from_otmlnode(OTMLNodePtr node, std::map<K, T>& m) {
|
||||||
for(int i=0;i<node->size();++i) {
|
for(int i=0;i<node->size();++i) {
|
||||||
K k;
|
K k;
|
||||||
if(!aux::cast(node->at(i)->tag(), k))
|
if(!fw::cast(node->at(i)->tag(), k))
|
||||||
return false;
|
return false;
|
||||||
m[k] = node->at(i)->read<T>();
|
m[k] = node->at(i)->read<T>();
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ bool from_otmlnode(OTMLNodePtr node, std::map<K, T>& m) {
|
||||||
// templates for casting a type to a node
|
// templates for casting a type to a node
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void to_otmlnode(OTMLNodePtr node, const T& v) {
|
void to_otmlnode(OTMLNodePtr node, const T& v) {
|
||||||
node->setValue(aux::unsafe_cast<std::string>(v));
|
node->setValue(fw::unsafe_cast<std::string>(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -203,7 +203,7 @@ void to_otmlnode(OTMLNodePtr node, const std::list<T>& v) {
|
||||||
template <typename K, typename T>
|
template <typename K, typename T>
|
||||||
void to_otmlnode(OTMLNodePtr node, const std::map<K, T>& m) {
|
void to_otmlnode(OTMLNodePtr node, const std::map<K, T>& m) {
|
||||||
for(auto it = m.begin(); it != m.end(); ++it) {
|
for(auto it = m.begin(); it != m.end(); ++it) {
|
||||||
std::string k = aux::unsafe_cast<std::string>(it->first);
|
std::string k = fw::unsafe_cast<std::string>(it->first);
|
||||||
OTMLNodePtr newNode(new OTMLNode);
|
OTMLNodePtr newNode(new OTMLNode);
|
||||||
newNode->setTag(k);
|
newNode->setTag(k);
|
||||||
newNode->setUnique();
|
newNode->setUnique();
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
#ifndef OTMLNODEEXT_H
|
|
||||||
#define OTMLNODEEXT_H
|
|
||||||
|
|
||||||
#include <util/point.h>
|
|
||||||
#include <util/color.h>
|
|
||||||
#include <util/rect.h>
|
|
||||||
#include <util/size.h>
|
|
||||||
|
|
||||||
//inline bool from_otmlnode(const OTMLNodePtr& node, Color& color)
|
|
||||||
//{
|
|
||||||
//int r, g, b, a;
|
|
||||||
//r = node->readAt<int>(0);
|
|
||||||
//g = node->readAt<int>(1);
|
|
||||||
//b = node->readAt<int>(2);
|
|
||||||
//a = 255;
|
|
||||||
//if(node->hasChild(3))
|
|
||||||
//a = node->readAt<int>(3);
|
|
||||||
//return true;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//template <class T>
|
|
||||||
//bool from_otmlnode(const OTMLNodePtr& node, TPoint<T>& point)
|
|
||||||
//{
|
|
||||||
//point.x = node->readAt<T>(0);
|
|
||||||
//point.y = node->readAt<T>(1);
|
|
||||||
//return true;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//template <class T>
|
|
||||||
//bool from_otmlnode(const OTMLNodePtr& node, TSize<T>& size)
|
|
||||||
//{
|
|
||||||
//size.setSize(node->readAt<T>(0), node->readAt<T>(1));
|
|
||||||
//return true;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//template <class T>
|
|
||||||
//bool from_otmlnode(const OTMLNodePtr& node, TRect<T>& rect)
|
|
||||||
//{
|
|
||||||
//rect.setRect(node->readAt<int>(0),
|
|
||||||
//node->readAt<int>(1),
|
|
||||||
//node->readAt<int>(2),
|
|
||||||
//node->readAt<int>(3));
|
|
||||||
//return true;
|
|
||||||
//}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -154,7 +154,7 @@ void OTMLParser::parseNode(const std::string& data)
|
||||||
node->setUnique(dotsPos != std::string::npos);
|
node->setUnique(dotsPos != std::string::npos);
|
||||||
node->setTag(tag);
|
node->setTag(tag);
|
||||||
node->setValue(value);
|
node->setValue(value);
|
||||||
node->setSource(doc->source() + ":" + aux::safe_cast<std::string>(currentLine));
|
node->setSource(doc->source() + ":" + fw::safe_cast<std::string>(currentLine));
|
||||||
currentParent->addChild(node);
|
currentParent->addChild(node);
|
||||||
previousNode = node;
|
previousNode = node;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef OTMLPARSER_H
|
#ifndef OTMLPARSER_H
|
||||||
#define OTMLPARSER_H
|
#define OTMLPARSER_H
|
||||||
|
|
||||||
#include "otmldeclarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
class OTMLParser
|
class OTMLParser
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
#ifndef PCH_H
|
|
||||||
#define PCH_H
|
|
||||||
|
|
||||||
#include "global.h"
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef PLATFORM_H
|
#ifndef PLATFORM_H
|
||||||
#define PLATFORM_H
|
#define PLATFORM_H
|
||||||
|
|
||||||
#include <global.h>
|
#include <framework/global.h>
|
||||||
|
|
||||||
class PlatformListener;
|
class PlatformListener;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef INPUTEVENT_H
|
#ifndef INPUTEVENT_H
|
||||||
#define INPUTEVENT_H
|
#define INPUTEVENT_H
|
||||||
|
|
||||||
#include <global.h>
|
#include <framework/global.h>
|
||||||
|
|
||||||
enum InputKeyCode {
|
enum InputKeyCode {
|
||||||
KC_UNKNOWN = 0x00,
|
KC_UNKNOWN = 0x00,
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef PLATFORMLISTENER_H
|
#ifndef PLATFORMLISTENER_H
|
||||||
#define PLATFORMLISTENER_H
|
#define PLATFORMLISTENER_H
|
||||||
|
|
||||||
#include "inputevent.h"
|
#include "platformevent.h"
|
||||||
|
|
||||||
class PlatformListener
|
class PlatformListener
|
||||||
{
|
{
|
|
@ -0,0 +1,50 @@
|
||||||
|
#ifndef FRAMEWORK_UI_CONST_H
|
||||||
|
#define FRAMEWORK_UI_CONST_H
|
||||||
|
|
||||||
|
// namespace ui {
|
||||||
|
|
||||||
|
enum UIWidgetType {
|
||||||
|
UITypeWidget = 0,
|
||||||
|
UITypeLabel,
|
||||||
|
UITypeButton,
|
||||||
|
UITypeLineEdit,
|
||||||
|
UITypeWindow,
|
||||||
|
UITypeList
|
||||||
|
};
|
||||||
|
|
||||||
|
enum FocusReason {
|
||||||
|
MouseFocusReason = 0,
|
||||||
|
TabFocusReason,
|
||||||
|
ActiveFocusReason,
|
||||||
|
OtherFocusReason
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MouseButton {
|
||||||
|
MouseNoButton = 0,
|
||||||
|
MouseLeftButton,
|
||||||
|
MouseRightButton,
|
||||||
|
MouseMidButton
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MouseWheelDirection {
|
||||||
|
MouseNoWheel = 0,
|
||||||
|
MouseWheelUp,
|
||||||
|
MouseWheelDown
|
||||||
|
};
|
||||||
|
|
||||||
|
enum KeyboardModifier {
|
||||||
|
KeyboardNoModifier = 0,
|
||||||
|
KeyboardCtrlModifier = 1,
|
||||||
|
KeyboardAltModifier = 2,
|
||||||
|
KeyboardShiftModifier = 4
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ButtonState {
|
||||||
|
ButtonUp = 0,
|
||||||
|
ButtonDown,
|
||||||
|
ButtonHover
|
||||||
|
};
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef FRAMEWORK_UI_DECLARATIONS_H
|
||||||
|
#define FRAMEWORK_UI_DECLARATIONS_H
|
||||||
|
|
||||||
|
#include <framework/global.h>
|
||||||
|
#include "const.h"
|
||||||
|
|
||||||
|
class UIManager;
|
||||||
|
class UILayout;
|
||||||
|
class UIAnchorLayout;
|
||||||
|
class UIStyle;
|
||||||
|
class UIWidget;
|
||||||
|
class UILabel;
|
||||||
|
class UIButton;
|
||||||
|
class UILineEdit;
|
||||||
|
class UIWindow;
|
||||||
|
|
||||||
|
typedef std::shared_ptr<UIWidget> UIWidgetPtr;
|
||||||
|
typedef std::weak_ptr<UIWidget> UIWidgetWeakPtr;
|
||||||
|
typedef std::deque<UIWidgetPtr> UIWidgetList;
|
||||||
|
|
||||||
|
typedef std::shared_ptr<UILayout> UILayoutPtr;
|
||||||
|
typedef std::shared_ptr<UIAnchorLayout> UIAnchorLayoutPtr;
|
||||||
|
typedef std::shared_ptr<UIStyle> UIStylePtr;
|
||||||
|
typedef std::shared_ptr<UILabel> UILabelPtr;
|
||||||
|
typedef std::shared_ptr<UIButton> UIButtonPtr;
|
||||||
|
typedef std::shared_ptr<UILineEdit> UILineEditPtr;
|
||||||
|
typedef std::shared_ptr<UIWindow> UIWindowPtr;
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef UIANCHOR_H
|
#ifndef UIANCHOR_H
|
||||||
#define UIANCHOR_H
|
#define UIANCHOR_H
|
||||||
|
|
||||||
#include "uideclarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
struct AnchorLine {
|
struct AnchorLine {
|
||||||
AnchorLine(std::string widgetId, AnchorPoint edge) : widgetId(widgetId), edge(edge) { }
|
AnchorLine(std::string widgetId, AnchorPoint edge) : widgetId(widgetId), edge(edge) { }
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "uibutton.h"
|
#include "uibutton.h"
|
||||||
#include <graphics/borderimage.h>
|
#include <framework/graphics/borderimage.h>
|
||||||
#include <graphics/font.h>
|
#include <framework/graphics/font.h>
|
||||||
#include <otml/otmlnode.h>
|
#include <framework/otml/otmlnode.h>
|
||||||
#include <luascript/luainterface.h>
|
#include <framework/luascript/luainterface.h>
|
||||||
|
|
||||||
UIButton::UIButton(): UIWidget(UITypeButton)
|
UIButton::UIButton(): UIWidget(UITypeButton)
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,7 @@ void UIButton::loadStyleFromOTML(const OTMLNodePtr& styleNode)
|
||||||
if(OTMLNodePtr node = styleNode->get("state.down"))
|
if(OTMLNodePtr node = styleNode->get("state.down"))
|
||||||
loadStateStyle(m_statesStyle[ButtonDown], node);
|
loadStateStyle(m_statesStyle[ButtonDown], node);
|
||||||
|
|
||||||
m_text = styleNode->readAt("text", aux::empty_string);
|
m_text = styleNode->readAt("text", fw::empty_string);
|
||||||
|
|
||||||
if(OTMLNodePtr node = styleNode->get("onClick")) {
|
if(OTMLNodePtr node = styleNode->get("onClick")) {
|
||||||
g_lua.loadFunction(node->read<std::string>(), "@" + node->source() + "[" + node->tag() + "]");
|
g_lua.loadFunction(node->read<std::string>(), "@" + node->source() + "[" + node->tag() + "]");
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
#ifndef UIDECLARATIONS_H
|
|
||||||
#define UIDECLARATIONS_H
|
|
||||||
|
|
||||||
#include <global.h>
|
|
||||||
|
|
||||||
class UIManager;
|
|
||||||
class UILayout;
|
|
||||||
class UIAnchorLayout;
|
|
||||||
class UIStyle;
|
|
||||||
class UIWidget;
|
|
||||||
class UILabel;
|
|
||||||
class UIButton;
|
|
||||||
class UILineEdit;
|
|
||||||
class UIWindow;
|
|
||||||
|
|
||||||
typedef std::shared_ptr<UIWidget> UIWidgetPtr;
|
|
||||||
typedef std::weak_ptr<UIWidget> UIWidgetWeakPtr;
|
|
||||||
typedef std::deque<UIWidgetPtr> UIWidgetList;
|
|
||||||
|
|
||||||
typedef std::shared_ptr<UILayout> UILayoutPtr;
|
|
||||||
typedef std::shared_ptr<UIAnchorLayout> UIAnchorLayoutPtr;
|
|
||||||
typedef std::shared_ptr<UIStyle> UIStylePtr;
|
|
||||||
typedef std::shared_ptr<UILabel> UILabelPtr;
|
|
||||||
typedef std::shared_ptr<UIButton> UIButtonPtr;
|
|
||||||
typedef std::shared_ptr<UILineEdit> UILineEditPtr;
|
|
||||||
typedef std::shared_ptr<UIWindow> UIWindowPtr;
|
|
||||||
|
|
||||||
enum UIWidgetType {
|
|
||||||
UITypeWidget = 0,
|
|
||||||
UITypeLabel,
|
|
||||||
UITypeButton,
|
|
||||||
UITypeLineEdit,
|
|
||||||
UITypeWindow,
|
|
||||||
UITypeList
|
|
||||||
};
|
|
||||||
|
|
||||||
enum FocusReason {
|
|
||||||
MouseFocusReason = 0,
|
|
||||||
TabFocusReason,
|
|
||||||
ActiveFocusReason,
|
|
||||||
OtherFocusReason
|
|
||||||
};
|
|
||||||
|
|
||||||
enum MouseButton {
|
|
||||||
MouseNoButton = 0,
|
|
||||||
MouseLeftButton,
|
|
||||||
MouseRightButton,
|
|
||||||
MouseMidButton
|
|
||||||
};
|
|
||||||
|
|
||||||
enum MouseWheelDirection {
|
|
||||||
MouseNoWheel = 0,
|
|
||||||
MouseWheelUp,
|
|
||||||
MouseWheelDown
|
|
||||||
};
|
|
||||||
|
|
||||||
enum KeyboardModifier {
|
|
||||||
KeyboardNoModifier = 0,
|
|
||||||
KeyboardCtrlModifier = 1,
|
|
||||||
KeyboardAltModifier = 2,
|
|
||||||
KeyboardShiftModifier = 4
|
|
||||||
};
|
|
||||||
|
|
||||||
enum ButtonState {
|
|
||||||
ButtonUp = 0,
|
|
||||||
ButtonDown,
|
|
||||||
ButtonHover
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef UIEVENT_H
|
#ifndef UIEVENT_H
|
||||||
#define UIEVENT_H
|
#define UIEVENT_H
|
||||||
|
|
||||||
#include <core/inputevent.h>
|
#include <framework/platform/platformevent.h>
|
||||||
#include "uideclarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
class UIEvent
|
class UIEvent
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "uilabel.h"
|
#include "uilabel.h"
|
||||||
#include <graphics/font.h>
|
#include <framework/graphics/font.h>
|
||||||
#include <otml/otmlnode.h>
|
#include <framework/otml/otmlnode.h>
|
||||||
|
|
||||||
UILabel::UILabel() : UIWidget(UITypeLabel)
|
UILabel::UILabel() : UIWidget(UITypeLabel)
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,7 @@ void UILabel::loadStyleFromOTML(const OTMLNodePtr& styleNode)
|
||||||
m_text = styleNode->readAt("text", m_text);
|
m_text = styleNode->readAt("text", m_text);
|
||||||
|
|
||||||
if(styleNode->hasChild("align"))
|
if(styleNode->hasChild("align"))
|
||||||
m_align = parseAlignment(styleNode->readAt<std::string>("align"));
|
m_align = fw::translateAlignment(styleNode->readAt<std::string>("align"));
|
||||||
|
|
||||||
// auto resize if no size supplied
|
// auto resize if no size supplied
|
||||||
if(!m_text.empty() && !getGeometry().isValid())
|
if(!m_text.empty() && !getGeometry().isValid())
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef UILAYOUT_H
|
#ifndef UILAYOUT_H
|
||||||
#define UILAYOUT_H
|
#define UILAYOUT_H
|
||||||
|
|
||||||
#include "uideclarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
class UILayout
|
class UILayout
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "uilineedit.h"
|
#include "uilineedit.h"
|
||||||
#include <graphics/font.h>
|
#include <framework/graphics/font.h>
|
||||||
#include <graphics/graphics.h>
|
#include <framework/graphics/graphics.h>
|
||||||
#include <core/platform.h>
|
#include <framework/platform/platform.h>
|
||||||
#include <otml/otmlnode.h>
|
#include <framework/otml/otmlnode.h>
|
||||||
|
|
||||||
UILineEdit::UILineEdit() : UIWidget(UITypeLabel)
|
UILineEdit::UILineEdit() : UIWidget(UITypeLabel)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
#include "uilist.h"
|
||||||
|
|
||||||
|
UIList::UIList() : UIWidget(UITypeList)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIList::loadStyleFromOTML(const OTMLNodePtr& styleNode)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIList::render()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIList::onKeyPress(UIKeyEvent& event)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIList::onMousePress(UIMouseEvent& event)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIList::onMouseMove(UIMouseEvent& event)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef UILIST_H
|
||||||
|
#define UILIST_H
|
||||||
|
|
||||||
|
#include "uiwidget.h"
|
||||||
|
|
||||||
|
class UIList : public UIWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UIList();
|
||||||
|
|
||||||
|
virtual void loadStyleFromOTML(const OTMLNodePtr& styleNode);
|
||||||
|
virtual void render();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void onKeyPress(UIKeyEvent& event);
|
||||||
|
virtual void onMousePress(UIMouseEvent& event);
|
||||||
|
virtual void onMouseMove(UIMouseEvent& event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::list<std::string> m_items;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -2,8 +2,8 @@
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "uianchorlayout.h"
|
#include "uianchorlayout.h"
|
||||||
|
|
||||||
#include <otml/otml.h>
|
#include <framework/otml/otml.h>
|
||||||
#include <graphics/graphics.h>
|
#include <framework/graphics/graphics.h>
|
||||||
|
|
||||||
UIManager g_ui;
|
UIManager g_ui;
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ OTMLNodePtr UIManager::getStyle(const std::string& styleName)
|
||||||
|
|
||||||
auto it = m_styles.find(styleName);
|
auto it = m_styles.find(styleName);
|
||||||
if(it == m_styles.end())
|
if(it == m_styles.end())
|
||||||
throw std::logic_error(aux::make_string("style '", styleName, "' is not a defined style"));
|
throw std::logic_error(fw::mkstr("style '", styleName, "' is not a defined style"));
|
||||||
return m_styles[styleName];
|
return m_styles[styleName];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef UIMANAGER_H
|
#ifndef UIMANAGER_H
|
||||||
#define UIMANAGER_H
|
#define UIMANAGER_H
|
||||||
|
|
||||||
#include "uideclarations.h"
|
#include "declarations.h"
|
||||||
#include <core/inputevent.h>
|
#include <framework/platform/platformevent.h>
|
||||||
#include <otml/otmldeclarations.h>
|
#include <framework/otml/declarations.h>
|
||||||
|
|
||||||
class UIManager
|
class UIManager
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
#include "uilayout.h"
|
#include "uilayout.h"
|
||||||
#include "uianchorlayout.h"
|
#include "uianchorlayout.h"
|
||||||
|
|
||||||
#include <core/eventdispatcher.h>
|
#include <framework/core/eventdispatcher.h>
|
||||||
#include <graphics/image.h>
|
#include <framework/graphics/image.h>
|
||||||
#include <graphics/borderimage.h>
|
#include <framework/graphics/borderimage.h>
|
||||||
#include <graphics/fontmanager.h>
|
#include <framework/graphics/fontmanager.h>
|
||||||
#include <otml/otmlnode.h>
|
#include <framework/otml/otmlnode.h>
|
||||||
#include <graphics/graphics.h>
|
#include <framework/graphics/graphics.h>
|
||||||
|
|
||||||
UIWidget::UIWidget(UIWidgetType type)
|
UIWidget::UIWidget(UIWidgetType type)
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,7 @@ UIWidget::UIWidget(UIWidgetType type)
|
||||||
|
|
||||||
// generate an unique id, this is need because anchored layouts find widgets by id
|
// generate an unique id, this is need because anchored layouts find widgets by id
|
||||||
static unsigned long id = 1;
|
static unsigned long id = 1;
|
||||||
m_id = aux::make_string("widget", id++);
|
m_id = fw::mkstr("widget", id++);
|
||||||
}
|
}
|
||||||
|
|
||||||
UIWidget::~UIWidget()
|
UIWidget::~UIWidget()
|
||||||
|
@ -172,7 +172,7 @@ void UIWidget::loadStyleFromOTML(const OTMLNodePtr& styleNode)
|
||||||
} else if(what == "centerIn") {
|
} else if(what == "centerIn") {
|
||||||
centerIn(node->value());
|
centerIn(node->value());
|
||||||
} else {
|
} else {
|
||||||
AnchorPoint myEdge = parseAnchorPoint(what);
|
AnchorPoint myEdge = fw::translateAnchorPoint(what);
|
||||||
|
|
||||||
std::string anchorDescription = node->value();
|
std::string anchorDescription = node->value();
|
||||||
std::vector<std::string> split;
|
std::vector<std::string> split;
|
||||||
|
@ -181,7 +181,7 @@ void UIWidget::loadStyleFromOTML(const OTMLNodePtr& styleNode)
|
||||||
throw OTMLException(node, "invalid anchor description");
|
throw OTMLException(node, "invalid anchor description");
|
||||||
|
|
||||||
std::string target = split[0];
|
std::string target = split[0];
|
||||||
AnchorPoint targetEdge = parseAnchorPoint(split[1]);
|
AnchorPoint targetEdge = fw::translateAnchorPoint(split[1]);
|
||||||
|
|
||||||
if(myEdge == AnchorNone)
|
if(myEdge == AnchorNone)
|
||||||
throw OTMLException(node, "invalid anchor edge");
|
throw OTMLException(node, "invalid anchor edge");
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#ifndef UIWIDGET_H
|
#ifndef UIWIDGET_H
|
||||||
#define UIWIDGET_H
|
#define UIWIDGET_H
|
||||||
|
|
||||||
#include "uideclarations.h"
|
#include "declarations.h"
|
||||||
#include "uievent.h"
|
#include "uievent.h"
|
||||||
#include <luascript/luaobject.h>
|
#include <framework/luascript/luaobject.h>
|
||||||
#include <graphics/graphicsdeclarations.h>
|
#include <framework/graphics/declarations.h>
|
||||||
#include <otml/otmldeclarations.h>
|
#include <framework/otml/declarations.h>
|
||||||
|
|
||||||
class UIWidget : public LuaObject
|
class UIWidget : public LuaObject
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "uiwindow.h"
|
#include "uiwindow.h"
|
||||||
#include <graphics/borderimage.h>
|
#include <framework/graphics/borderimage.h>
|
||||||
#include <graphics/font.h>
|
#include <framework/graphics/font.h>
|
||||||
#include <otml/otml.h>
|
#include <framework/otml/otml.h>
|
||||||
|
|
||||||
UIWindow::UIWindow(): UIWidget(UITypeWindow)
|
UIWindow::UIWindow(): UIWidget(UITypeWindow)
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,7 @@ void UIWindow::loadStyleFromOTML(const OTMLNodePtr& styleNode)
|
||||||
m_headImage = BorderImage::loadFromOTML(node);
|
m_headImage = BorderImage::loadFromOTML(node);
|
||||||
m_headHeight = headNode->readAt("height", m_headImage->getDefaultSize().height());
|
m_headHeight = headNode->readAt("height", m_headImage->getDefaultSize().height());
|
||||||
m_headMargin = headNode->readAt("margin", 0);
|
m_headMargin = headNode->readAt("margin", 0);
|
||||||
m_titleAlign = parseAlignment(headNode->readAt("text align", std::string("center")));
|
m_titleAlign = fw::translateAlignment(headNode->readAt("text align", std::string("center")));
|
||||||
} else {
|
} else {
|
||||||
m_headHeight = 0;
|
m_headHeight = 0;
|
||||||
m_headMargin = 0;
|
m_headMargin = 0;
|
||||||
|
@ -37,7 +37,7 @@ void UIWindow::loadStyleFromOTML(const OTMLNodePtr& styleNode)
|
||||||
m_bodyImage = BorderImage::loadFromOTML(node);
|
m_bodyImage = BorderImage::loadFromOTML(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_title = styleNode->readAt("title", aux::empty_string);
|
m_title = styleNode->readAt("title", fw::empty_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWindow::render()
|
void UIWindow::render()
|
||||||
|
|
|
@ -1,194 +0,0 @@
|
||||||
#ifndef AUXILIARY_H
|
|
||||||
#define AUXILIARY_H
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <sstream>
|
|
||||||
#include <exception>
|
|
||||||
#include <cxxabi.h>
|
|
||||||
|
|
||||||
/// Namespace that contains auxiliary functions and templates
|
|
||||||
namespace aux {
|
|
||||||
/// Fill an ostream by concatenating args
|
|
||||||
/// Usage:
|
|
||||||
/// aux::fill_ostream(stream, a1, a2, ..., aN);
|
|
||||||
inline void fill_ostream(std::ostringstream&) { }
|
|
||||||
template<class T, class... Args>
|
|
||||||
void fill_ostream(std::ostringstream& stream, const T& first, const Args&... rest) {
|
|
||||||
stream << first;
|
|
||||||
fill_ostream(stream, rest...);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Makes a std::string by concatenating args
|
|
||||||
/// Usage:
|
|
||||||
/// std::string str = aux::make_string(a1, a2, ..., aN);
|
|
||||||
template<class... T>
|
|
||||||
std::string make_string(const T&... args) {
|
|
||||||
std::ostringstream buf;
|
|
||||||
fill_ostream(buf, args...);
|
|
||||||
return buf.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
// used by dumper
|
|
||||||
struct dump_util {
|
|
||||||
~dump_util() { std::cout << std::endl; }
|
|
||||||
template<class T>
|
|
||||||
dump_util& operator<<(const T& v) {
|
|
||||||
std::cout << v << " ";
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Utility for dumping variables
|
|
||||||
/// Usage:
|
|
||||||
/// aux::dump << v1, v2, ..., vN;
|
|
||||||
static const struct dumper {
|
|
||||||
dumper() { }
|
|
||||||
template<class T>
|
|
||||||
dump_util operator<<(const T& v) const {
|
|
||||||
dump_util d;
|
|
||||||
d << v;
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
} dump;
|
|
||||||
|
|
||||||
/// Utility for printing messages into stdout
|
|
||||||
/// Usage:
|
|
||||||
/// aux::print(v1, v2, ..., vN);
|
|
||||||
template<class... T>
|
|
||||||
void print(const T&... args) {
|
|
||||||
std::ostringstream buf;
|
|
||||||
fill_ostream(buf, args...);
|
|
||||||
std::cout << buf.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Same as aux::print but adds a new line at the end
|
|
||||||
template<class... T>
|
|
||||||
void println(const T&... args) {
|
|
||||||
print(args...);
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Demangle names for GNU g++ compiler
|
|
||||||
inline std::string demangle_name(const char* name) {
|
|
||||||
size_t len;
|
|
||||||
int status;
|
|
||||||
std::string ret;
|
|
||||||
char* demangled = abi::__cxa_demangle(name, 0, &len, &status);
|
|
||||||
if(demangled) {
|
|
||||||
ret = demangled;
|
|
||||||
free(demangled);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the name of a type
|
|
||||||
/// e.g. aux::demangle_type<Foo*>() returns a string containing 'Foo*'
|
|
||||||
template<typename T>
|
|
||||||
std::string demangle_type() {
|
|
||||||
return demangle_name(typeid(T).name());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Cast a type to another type
|
|
||||||
/// @return whether the conversion was successful or not
|
|
||||||
template<typename T, typename R>
|
|
||||||
bool cast(const T& in, R& out) {
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << in;
|
|
||||||
ss >> out;
|
|
||||||
return !!ss && ss.eof();
|
|
||||||
}
|
|
||||||
|
|
||||||
// cast a type to string
|
|
||||||
template<typename T>
|
|
||||||
bool cast(const T& in, std::string& out) {
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << in;
|
|
||||||
out = ss.str();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// cast string to string
|
|
||||||
template<>
|
|
||||||
inline bool cast(const std::string& in, std::string& out) {
|
|
||||||
out = in;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// special cast from string to boolean
|
|
||||||
template<>
|
|
||||||
inline bool cast(const std::string& in, bool& b) {
|
|
||||||
static std::string validNames[2][4] = {{"true","yes","on","1"}, {"false","no","off","0"}};
|
|
||||||
bool ret = false;
|
|
||||||
for(int i=0;i<4;++i) {
|
|
||||||
if(in == validNames[0][i]) {
|
|
||||||
b = true;
|
|
||||||
ret = true;
|
|
||||||
break;
|
|
||||||
} else if(in == validNames[1][i]) {
|
|
||||||
b = false;
|
|
||||||
ret = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// special cast from boolean to string
|
|
||||||
template<>
|
|
||||||
inline bool cast(const bool& in, std::string& out) {
|
|
||||||
out = (in ? "true" : "false");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// used by safe_cast
|
|
||||||
class bad_cast : public std::bad_cast {
|
|
||||||
public:
|
|
||||||
virtual ~bad_cast() throw() { }
|
|
||||||
template<class T, class R>
|
|
||||||
void setWhat() {
|
|
||||||
m_what = make_string("failed to cast value of type '", demangle_type<T>(),
|
|
||||||
"' to type '", demangle_type<R>(), "'");
|
|
||||||
}
|
|
||||||
virtual const char* what() { return m_what.c_str(); }
|
|
||||||
private:
|
|
||||||
std::string m_what;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Cast a type to another type, any error throws a aux::bad_cast_exception
|
|
||||||
/// Usage:
|
|
||||||
/// R r = aux::safe_cast<R>(t);
|
|
||||||
template<typename R, typename T>
|
|
||||||
R safe_cast(const T& t) {
|
|
||||||
R r;
|
|
||||||
if(!cast(t, r)) {
|
|
||||||
bad_cast e;
|
|
||||||
e.setWhat<T,R>();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Cast a type to another type, cast errors are ignored
|
|
||||||
/// Usage:
|
|
||||||
/// R r = aux::unsafe_cast<R>(t);
|
|
||||||
template<typename R, typename T>
|
|
||||||
R unsafe_cast(const T& t) {
|
|
||||||
R r;
|
|
||||||
try {
|
|
||||||
r = safe_cast<R,T>(t);
|
|
||||||
} catch(bad_cast& e) {
|
|
||||||
println(e.what());
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
// an empty string to use anywhere needed
|
|
||||||
const static std::string empty_string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// shortcut for aux::dump
|
|
||||||
const static aux::dumper& dump = aux::dump;
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,8 +1,9 @@
|
||||||
#ifndef LOGGER_H
|
#ifndef LOGGER_H
|
||||||
#define LOGGER_H
|
#define LOGGER_H
|
||||||
|
|
||||||
#include "auxiliary.h"
|
#include "tools.h"
|
||||||
|
|
||||||
|
//TODO: a real logger
|
||||||
class Logger
|
class Logger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -17,16 +18,16 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
// specialized logging
|
// specialized logging
|
||||||
#define logDebug(...) Logger::log(Logger::LogDebug, aux::make_string(__VA_ARGS__))
|
#define logDebug(...) Logger::log(Logger::LogDebug, fw::mkstr(__VA_ARGS__))
|
||||||
#define logInfo(...) Logger::log(Logger::LogInfo, aux::make_string(__VA_ARGS__))
|
#define logInfo(...) Logger::log(Logger::LogInfo, fw::mkstr(__VA_ARGS__))
|
||||||
#define logWarning(...) Logger::log(Logger::LogWarning, aux::make_string(__VA_ARGS__))
|
#define logWarning(...) Logger::log(Logger::LogWarning, fw::mkstr(__VA_ARGS__))
|
||||||
#define logError(...) Logger::log(Logger::LogError, aux::make_string(__VA_ARGS__))
|
#define logError(...) Logger::log(Logger::LogError, fw::mkstr(__VA_ARGS__))
|
||||||
#define logFatal(...) Logger::log(Logger::LogFatal, aux::make_string(__VA_ARGS__))
|
#define logFatal(...) Logger::log(Logger::LogFatal, fw::mkstr(__VA_ARGS__))
|
||||||
|
|
||||||
#define logTrace() Logger::log(Logger::LogDebug, "", __PRETTY_FUNCTION__)
|
#define logTrace() Logger::log(Logger::LogDebug, "", __PRETTY_FUNCTION__)
|
||||||
#define logTraceDebug(...) Logger::log(Logger::LogDebug, aux::make_string(__VA_ARGS__), __PRETTY_FUNCTION__)
|
#define logTraceDebug(...) Logger::log(Logger::LogDebug, fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
|
||||||
#define logTraceInfo(...) Logger::log(Logger::LogInfo, aux::make_string(__VA_ARGS__), __PRETTY_FUNCTION__)
|
#define logTraceInfo(...) Logger::log(Logger::LogInfo, fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
|
||||||
#define logTraceWarning(...) log(Logger::LogWarning, aux::make_string(__VA_ARGS__), __PRETTY_FUNCTION__)
|
#define logTraceWarning(...) log(Logger::LogWarning, fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
|
||||||
#define logTraceError(...) Logger::log(Logger::LogError, aux::make_string(__VA_ARGS__), __PRETTY_FUNCTION__)
|
#define logTraceError(...) Logger::log(Logger::LogError, fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -58,8 +58,7 @@ typedef TPoint<float> PointF;
|
||||||
template<class T>
|
template<class T>
|
||||||
std::ostream& operator<<(std::ostream& out, const TPoint<T>& point)
|
std::ostream& operator<<(std::ostream& out, const TPoint<T>& point)
|
||||||
{
|
{
|
||||||
out << "Point(" << point.x << ","
|
out << point.x << " " << point.y;
|
||||||
<< point.y << ")";
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,195 @@
|
||||||
|
#ifndef TOOLS_H
|
||||||
|
#define TOOLS_H
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include <exception>
|
||||||
|
#include <cxxabi.h>
|
||||||
|
|
||||||
|
namespace fw {
|
||||||
|
|
||||||
|
/// Fill an ostream by concatenating args
|
||||||
|
/// Usage:
|
||||||
|
/// fw::fill_ostream(stream, a1, a2, ..., aN);
|
||||||
|
inline void fill_ostream(std::ostringstream&) { }
|
||||||
|
template<class T, class... Args>
|
||||||
|
void fill_ostream(std::ostringstream& stream, const T& first, const Args&... rest) {
|
||||||
|
stream << first;
|
||||||
|
fill_ostream(stream, rest...);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Makes a std::string by concatenating args
|
||||||
|
/// Usage:
|
||||||
|
/// std::string str = fw::mkstr(a1, a2, ..., aN);
|
||||||
|
template<class... T>
|
||||||
|
std::string mkstr(const T&... args) {
|
||||||
|
std::ostringstream buf;
|
||||||
|
fill_ostream(buf, args...);
|
||||||
|
return buf.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
// used by dumper
|
||||||
|
struct dump_util {
|
||||||
|
~dump_util() { std::cout << std::endl; }
|
||||||
|
template<class T>
|
||||||
|
dump_util& operator<<(const T& v) {
|
||||||
|
std::cout << v << " ";
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Utility for dumping variables
|
||||||
|
/// Usage:
|
||||||
|
/// fw::dump << v1, v2, ..., vN;
|
||||||
|
struct dumper {
|
||||||
|
dumper() { }
|
||||||
|
template<class T>
|
||||||
|
dump_util operator<<(const T& v) const {
|
||||||
|
dump_util d;
|
||||||
|
d << v;
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Utility for printing messages into stdout
|
||||||
|
/// Usage:
|
||||||
|
/// fw::print(v1, v2, ..., vN);
|
||||||
|
template<class... T>
|
||||||
|
void print(const T&... args) {
|
||||||
|
std::ostringstream buf;
|
||||||
|
fill_ostream(buf, args...);
|
||||||
|
std::cout << buf.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Same as fw::print but adds a new line at the end
|
||||||
|
template<class... T>
|
||||||
|
void println(const T&... args) {
|
||||||
|
print(args...);
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Demangle names for GNU g++ compiler
|
||||||
|
inline std::string demangle_name(const char* name) {
|
||||||
|
size_t len;
|
||||||
|
int status;
|
||||||
|
std::string ret;
|
||||||
|
char* demangled = abi::__cxa_demangle(name, 0, &len, &status);
|
||||||
|
if(demangled) {
|
||||||
|
ret = demangled;
|
||||||
|
free(demangled);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the name of a type
|
||||||
|
/// e.g. fw::demangle_type<Foo*>() returns a string containing 'Foo*'
|
||||||
|
template<typename T>
|
||||||
|
std::string demangle_type() {
|
||||||
|
return demangle_name(typeid(T).name());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cast a type to another type
|
||||||
|
/// @return whether the conversion was successful or not
|
||||||
|
template<typename T, typename R>
|
||||||
|
bool cast(const T& in, R& out) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << in;
|
||||||
|
ss >> out;
|
||||||
|
return !!ss && ss.eof();
|
||||||
|
}
|
||||||
|
|
||||||
|
// cast a type to string
|
||||||
|
template<typename T>
|
||||||
|
bool cast(const T& in, std::string& out) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << in;
|
||||||
|
out = ss.str();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cast string to string
|
||||||
|
template<>
|
||||||
|
inline bool cast(const std::string& in, std::string& out) {
|
||||||
|
out = in;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// special cast from string to boolean
|
||||||
|
template<>
|
||||||
|
inline bool cast(const std::string& in, bool& b) {
|
||||||
|
static std::string validNames[2][4] = {{"true","yes","on","1"}, {"false","no","off","0"}};
|
||||||
|
bool ret = false;
|
||||||
|
for(int i=0;i<4;++i) {
|
||||||
|
if(in == validNames[0][i]) {
|
||||||
|
b = true;
|
||||||
|
ret = true;
|
||||||
|
break;
|
||||||
|
} else if(in == validNames[1][i]) {
|
||||||
|
b = false;
|
||||||
|
ret = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// special cast from boolean to string
|
||||||
|
template<>
|
||||||
|
inline bool cast(const bool& in, std::string& out) {
|
||||||
|
out = (in ? "true" : "false");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// used by safe_cast
|
||||||
|
class bad_cast : public std::bad_cast {
|
||||||
|
public:
|
||||||
|
virtual ~bad_cast() throw() { }
|
||||||
|
template<class T, class R>
|
||||||
|
void setWhat() {
|
||||||
|
m_what = mkstr("failed to cast value of type '", demangle_type<T>(),
|
||||||
|
"' to type '", demangle_type<R>(), "'");
|
||||||
|
}
|
||||||
|
virtual const char* what() { return m_what.c_str(); }
|
||||||
|
private:
|
||||||
|
std::string m_what;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Cast a type to another type, any error throws a fw::bad_cast_exception
|
||||||
|
/// Usage:
|
||||||
|
/// R r = fw::safe_cast<R>(t);
|
||||||
|
template<typename R, typename T>
|
||||||
|
R safe_cast(const T& t) {
|
||||||
|
R r;
|
||||||
|
if(!cast(t, r)) {
|
||||||
|
bad_cast e;
|
||||||
|
e.setWhat<T,R>();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cast a type to another type, cast errors are ignored
|
||||||
|
/// Usage:
|
||||||
|
/// R r = fw::unsafe_cast<R>(t);
|
||||||
|
template<typename R, typename T>
|
||||||
|
R unsafe_cast(const T& t) {
|
||||||
|
R r;
|
||||||
|
try {
|
||||||
|
r = safe_cast<R,T>(t);
|
||||||
|
} catch(bad_cast& e) {
|
||||||
|
println(e.what());
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
// an empty string to use anywhere needed
|
||||||
|
const static std::string empty_string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// shortcut for fw::dump
|
||||||
|
const static fw::dumper dump;
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,7 +1,7 @@
|
||||||
#include "translator.h"
|
#include "translator.h"
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
AlignmentFlag parseAlignment(std::string aligment)
|
AlignmentFlag fw::translateAlignment(std::string aligment)
|
||||||
{
|
{
|
||||||
boost::to_lower(aligment);
|
boost::to_lower(aligment);
|
||||||
boost::erase_all(aligment, " ");
|
boost::erase_all(aligment, " ");
|
||||||
|
@ -25,7 +25,7 @@ AlignmentFlag parseAlignment(std::string aligment)
|
||||||
return AlignCenter;
|
return AlignCenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
AnchorPoint parseAnchorPoint(const std::string& anchorPoint)
|
AnchorPoint fw::translateAnchorPoint(const std::string& anchorPoint)
|
||||||
{
|
{
|
||||||
if(anchorPoint == "left")
|
if(anchorPoint == "left")
|
||||||
return AnchorLeft;
|
return AnchorLeft;
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
#ifndef TRANSLATOR_H
|
#ifndef TRANSLATOR_H
|
||||||
#define TRANSLATOR_H
|
#define TRANSLATOR_H
|
||||||
|
|
||||||
#include <const.h>
|
#include "../const.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
AlignmentFlag parseAlignment(std::string aligment);
|
namespace fw {
|
||||||
AnchorPoint parseAnchorPoint(const std::string& anchorPoint);
|
|
||||||
|
AlignmentFlag translateAlignment(std::string aligment);
|
||||||
|
AnchorPoint translateAnchorPoint(const std::string& anchorPoint);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
#include "game.h"
|
|
||||||
|
|
||||||
Game g_game;
|
|
||||||
|
|
||||||
Game::Game()
|
|
||||||
{
|
|
||||||
m_online = false;
|
|
||||||
}
|
|
33
src/game.h
33
src/game.h
|
@ -1,33 +0,0 @@
|
||||||
#ifndef GAME_H
|
|
||||||
#define GAME_H
|
|
||||||
|
|
||||||
#include <global.h>
|
|
||||||
#include "map.h"
|
|
||||||
#include "player.h"
|
|
||||||
#include "protocolgame.h"
|
|
||||||
|
|
||||||
class Game
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Game();
|
|
||||||
|
|
||||||
void setProtocol(ProtocolGamePtr protocolGame) { m_protocolGame = protocolGame; }
|
|
||||||
ProtocolGamePtr getProtocol() { return m_protocolGame; }
|
|
||||||
|
|
||||||
Map *getMap() { return &m_map; }
|
|
||||||
Player *getPlayer() { return &m_player; }
|
|
||||||
|
|
||||||
void setOnline(bool online) { m_online = online; }
|
|
||||||
bool getOnline() { return m_online; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Map m_map;
|
|
||||||
Player m_player;
|
|
||||||
ProtocolGamePtr m_protocolGame;
|
|
||||||
bool m_online;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
extern Game g_game;
|
|
||||||
|
|
||||||
#endif // GAME_H
|
|
35
src/item.cpp
35
src/item.cpp
|
@ -1,35 +0,0 @@
|
||||||
#include "item.h"
|
|
||||||
#include "tibiadat.h"
|
|
||||||
#include "tibiaspr.h"
|
|
||||||
#include <graphics/graphics.h>
|
|
||||||
#include "thing.h"
|
|
||||||
|
|
||||||
Item::Item()
|
|
||||||
{
|
|
||||||
m_type = Thing::TYPE_ITEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
ThingAttributes *Item::getAttributes()
|
|
||||||
{
|
|
||||||
return g_tibiaDat.getItemAttributes(m_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Item::draw(int x, int y)
|
|
||||||
{
|
|
||||||
ThingAttributes *itemAttributes = getAttributes();
|
|
||||||
|
|
||||||
int xdiv = 0, ydiv = 0, zdiv = 0, anim = 0;
|
|
||||||
|
|
||||||
if(itemAttributes->group == THING_GROUP_SPLASH || itemAttributes->group == THING_GROUP_FLUID || itemAttributes->stackable) {
|
|
||||||
//cDivX = subType % itemAttributes->xdiv;
|
|
||||||
//cDivY = subType / itemAttributes->xdiv;
|
|
||||||
}
|
|
||||||
else if(!itemAttributes->moveable) {
|
|
||||||
xdiv = m_position.x % itemAttributes->xdiv;
|
|
||||||
ydiv = m_position.y % itemAttributes->ydiv;
|
|
||||||
zdiv = m_position.z % itemAttributes->zdiv;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int b = 0; b < itemAttributes->blendframes; b++)
|
|
||||||
internalDraw(x, y, b, xdiv, ydiv, zdiv, anim);
|
|
||||||
}
|
|
27
src/item.h
27
src/item.h
|
@ -1,27 +0,0 @@
|
||||||
#ifndef ITEM_H
|
|
||||||
#define ITEM_H
|
|
||||||
|
|
||||||
#include <global.h>
|
|
||||||
#include "thing.h"
|
|
||||||
|
|
||||||
class Item;
|
|
||||||
typedef std::shared_ptr<Item> ItemPtr;
|
|
||||||
|
|
||||||
class Item : public Thing
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Item();
|
|
||||||
|
|
||||||
virtual ThingAttributes *getAttributes();
|
|
||||||
void draw(int x, int y);
|
|
||||||
|
|
||||||
void setCount(uint8 count) { m_count = count; }
|
|
||||||
|
|
||||||
virtual Item* getItem() { return this; }
|
|
||||||
virtual const Item* getItem() const { return this; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint8 m_count;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // ITEM_H
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include "otclient.h"
|
#include <otclient/otclient.h>
|
||||||
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <core/eventdispatcher.h>
|
#include <framework/core/eventdispatcher.h>
|
||||||
|
|
||||||
void signal_handler(int sig)
|
void signal_handler(int sig)
|
||||||
{
|
{
|
||||||
|
|
75
src/map.cpp
75
src/map.cpp
|
@ -1,75 +0,0 @@
|
||||||
#include "map.h"
|
|
||||||
#include "game.h"
|
|
||||||
#include <graphics/graphics.h>
|
|
||||||
#include <graphics/framebuffer.h>
|
|
||||||
|
|
||||||
void Map::draw(int x, int y)
|
|
||||||
{
|
|
||||||
if(!m_framebuffer)
|
|
||||||
m_framebuffer = FrameBufferPtr(new FrameBuffer(15*32, 11*32));
|
|
||||||
|
|
||||||
g_graphics.bindColor(Color::white);
|
|
||||||
m_framebuffer->bind();
|
|
||||||
|
|
||||||
Position *playerPos = g_game.getPlayer()->getPosition();
|
|
||||||
|
|
||||||
// player is above 7
|
|
||||||
if(playerPos->z <= 7) {
|
|
||||||
|
|
||||||
// player pos it 8-6. check if we can draw upper floors.
|
|
||||||
bool draw = true;
|
|
||||||
for(int jz = 6; jz >= 0; --jz) {
|
|
||||||
Position coverPos = Position(playerPos->x-(6-jz), playerPos->y-(6-jz), jz);
|
|
||||||
if(m_tiles[coverPos]) {
|
|
||||||
if(m_tiles[coverPos]->getStackSize() > 0 && jz < playerPos->z) {
|
|
||||||
draw = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int iz = 7; iz > 0; --iz) {
|
|
||||||
|
|
||||||
// +1 in draws cause 64x64 items may affect view.
|
|
||||||
for(int ix = -7; ix < + 8+7; ++ix) {
|
|
||||||
for(int iy = -5; iy < + 6+7; ++iy) {
|
|
||||||
Position itemPos = Position(playerPos->x + ix, playerPos->y + iy, iz);
|
|
||||||
//Position drawPos = Position(ix + 8, iy - playerPos->y + 6, iz);
|
|
||||||
//logDebug("x: ", relativePos.x, " y: ", relativePos.y, " z: ", (int)relativePos.z);
|
|
||||||
if(m_tiles[itemPos])
|
|
||||||
m_tiles[itemPos]->draw((ix + 7 - (7-iz))*32, (iy + 5 - (7-iz))*32);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!draw)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// draw effects
|
|
||||||
for(auto it = m_effects.begin(), end = m_effects.end(); it != end; ++it) {
|
|
||||||
Position *effectPos = (*it)->getPosition();
|
|
||||||
(*it)->draw((effectPos->x - playerPos->x + 7) * 32, (effectPos->y - playerPos->y + 5) * 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
// debug draws
|
|
||||||
g_graphics.drawBoundingRect(Rect(7*32, 5*32, 32, 32), Color::red);
|
|
||||||
|
|
||||||
m_framebuffer->unbind();
|
|
||||||
|
|
||||||
m_framebuffer->draw(x, y, g_graphics.getScreenSize().width(), g_graphics.getScreenSize().height());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Map::addThing(ThingPtr thing, uint8 stackpos)
|
|
||||||
{
|
|
||||||
if(thing->getType() == Thing::TYPE_ITEM || thing->getType() == Thing::TYPE_CREATURE) {
|
|
||||||
if(!m_tiles[*thing->getPosition()]) {
|
|
||||||
m_tiles[*thing->getPosition()] = TilePtr(new Tile());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_tiles[*thing->getPosition()]->addThing(thing, stackpos);
|
|
||||||
}
|
|
||||||
else if(thing->getType() == Thing::TYPE_EFFECT) {
|
|
||||||
m_effects.push_back(thing);
|
|
||||||
}
|
|
||||||
}
|
|
26
src/map.h
26
src/map.h
|
@ -1,26 +0,0 @@
|
||||||
#ifndef MAP_H
|
|
||||||
#define MAP_H
|
|
||||||
|
|
||||||
#include "position.h"
|
|
||||||
#include "tile.h"
|
|
||||||
#include "effect.h"
|
|
||||||
#include <graphics/graphicsdeclarations.h>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
class Map
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void addThing(ThingPtr thing, uint8 stackpos = 0);
|
|
||||||
|
|
||||||
void draw(int x, int y);
|
|
||||||
|
|
||||||
FrameBufferPtr getFramebuffer() { return m_framebuffer; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unordered_map<Position, TilePtr, PositionHash> m_tiles;
|
|
||||||
std::list<ThingPtr> m_effects;
|
|
||||||
|
|
||||||
FrameBufferPtr m_framebuffer;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
278
src/otclient.cpp
278
src/otclient.cpp
|
@ -1,278 +0,0 @@
|
||||||
#include "otclient.h"
|
|
||||||
|
|
||||||
#include <core/modulemanager.h>
|
|
||||||
#include <core/configmanager.h>
|
|
||||||
#include <core/resourcemanager.h>
|
|
||||||
#include <core/eventdispatcher.h>
|
|
||||||
#include <luascript/luainterface.h>
|
|
||||||
#include <core/platform.h>
|
|
||||||
#include <graphics/graphics.h>
|
|
||||||
#include <graphics/fontmanager.h>
|
|
||||||
#include <ui/uimanager.h>
|
|
||||||
#include <ui/uiwidget.h>
|
|
||||||
#include <net/connection.h>
|
|
||||||
|
|
||||||
#include "protocolgame.h"
|
|
||||||
#include "game.h"
|
|
||||||
#include "map.h"
|
|
||||||
|
|
||||||
#define POLL_CYCLE_DELAY 10
|
|
||||||
|
|
||||||
OTClient g_client;
|
|
||||||
|
|
||||||
void OTClient::init(std::vector<std::string> args)
|
|
||||||
{
|
|
||||||
m_running = false;
|
|
||||||
m_stopping = false;
|
|
||||||
|
|
||||||
// print client information
|
|
||||||
logInfo("OTClient 0.2.0");
|
|
||||||
|
|
||||||
// initialize platform related stuff
|
|
||||||
g_platform.init(this, "OTClient");
|
|
||||||
|
|
||||||
// initialize script environment
|
|
||||||
g_lua.init();
|
|
||||||
|
|
||||||
// register otclient lua functions
|
|
||||||
registerLuaFunctions();
|
|
||||||
|
|
||||||
// initialize resources
|
|
||||||
g_resources.init(args[0].c_str());
|
|
||||||
|
|
||||||
// load configurations
|
|
||||||
loadConfigurations();
|
|
||||||
|
|
||||||
// create the client window
|
|
||||||
g_platform.createWindow(g_configs.get("window x"), g_configs.get("window y"),
|
|
||||||
g_configs.get("window width"), g_configs.get("window height"),
|
|
||||||
550, 450,
|
|
||||||
g_configs.get("window maximized"));
|
|
||||||
g_platform.setWindowTitle("OTClient");
|
|
||||||
|
|
||||||
// initialize graphics
|
|
||||||
g_graphics.init();
|
|
||||||
|
|
||||||
// initialize event dispatcher
|
|
||||||
g_dispatcher.init();
|
|
||||||
|
|
||||||
// initialize network
|
|
||||||
//g_network.init();
|
|
||||||
|
|
||||||
// initialize the ui
|
|
||||||
g_ui.init();
|
|
||||||
|
|
||||||
// discover and load modules
|
|
||||||
g_modules.discoverAndLoadModules();
|
|
||||||
|
|
||||||
// now that everything is initialized, setup configurations
|
|
||||||
setupConfigurations();
|
|
||||||
|
|
||||||
// now that everything is loaded, show the window
|
|
||||||
g_platform.showWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OTClient::run()
|
|
||||||
{
|
|
||||||
std::string fpsText;
|
|
||||||
Size fpsTextSize;
|
|
||||||
FontPtr defaultFont = g_fonts.getDefaultFont();
|
|
||||||
int frameTicks = g_platform.getTicks();
|
|
||||||
int lastFpsTicks = frameTicks;
|
|
||||||
int lastPollTicks = frameTicks;
|
|
||||||
int frameCount = 0;
|
|
||||||
|
|
||||||
m_stopping = false;
|
|
||||||
m_running = true;
|
|
||||||
|
|
||||||
if(g_ui.getRootWidget()->getChildCount() == 0) {
|
|
||||||
logError("ERROR: there is no root widgets to display, the app will close");
|
|
||||||
m_stopping = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// run the first poll
|
|
||||||
poll();
|
|
||||||
|
|
||||||
while(!m_stopping) {
|
|
||||||
frameTicks = g_platform.getTicks();
|
|
||||||
|
|
||||||
// calculate fps
|
|
||||||
frameCount++;
|
|
||||||
if(frameTicks - lastFpsTicks >= 1000) {
|
|
||||||
fpsText = aux::make_string("FPS: ", frameCount);
|
|
||||||
fpsTextSize = defaultFont->calculateTextRectSize(fpsText);
|
|
||||||
frameCount = 0;
|
|
||||||
lastFpsTicks = frameTicks;
|
|
||||||
}
|
|
||||||
|
|
||||||
// poll events every POLL_CYCLE_DELAY
|
|
||||||
// this delay exists to avoid massive polling thus increasing framerate
|
|
||||||
if(frameTicks - lastPollTicks >= POLL_CYCLE_DELAY) {
|
|
||||||
poll();
|
|
||||||
lastPollTicks = frameTicks;
|
|
||||||
}
|
|
||||||
|
|
||||||
// only render when the windows is visible
|
|
||||||
if(g_platform.isWindowVisible()) {
|
|
||||||
// render begin
|
|
||||||
g_graphics.beginRender();
|
|
||||||
|
|
||||||
// render everything
|
|
||||||
render();
|
|
||||||
|
|
||||||
// render fps
|
|
||||||
defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - fpsTextSize.width() - 10, 10));
|
|
||||||
|
|
||||||
// render end
|
|
||||||
g_graphics.endRender();
|
|
||||||
|
|
||||||
// swap the old buffer with the new rendered
|
|
||||||
g_platform.swapBuffers();
|
|
||||||
} else {
|
|
||||||
// sleeps until next poll to avoid massive cpu usage
|
|
||||||
g_platform.sleep(POLL_CYCLE_DELAY+1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_stopping = false;
|
|
||||||
m_running = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OTClient::terminate()
|
|
||||||
{
|
|
||||||
// hide the window because there is no render anymore
|
|
||||||
g_platform.hideWindow();
|
|
||||||
|
|
||||||
// run modules unload event
|
|
||||||
g_modules.unloadModules();
|
|
||||||
|
|
||||||
// terminate ui
|
|
||||||
g_ui.terminate();
|
|
||||||
|
|
||||||
// release remaining lua object references
|
|
||||||
g_lua.collectGarbage();
|
|
||||||
|
|
||||||
// poll remaining events
|
|
||||||
poll();
|
|
||||||
|
|
||||||
// terminate network
|
|
||||||
//g_network.terminate();
|
|
||||||
|
|
||||||
// terminate dispatcher
|
|
||||||
g_dispatcher.terminate();
|
|
||||||
|
|
||||||
// terminate graphics
|
|
||||||
g_graphics.terminate();
|
|
||||||
|
|
||||||
// save configurations
|
|
||||||
saveConfigurations();
|
|
||||||
|
|
||||||
// release resources
|
|
||||||
g_resources.terminate();
|
|
||||||
|
|
||||||
// terminate script environment
|
|
||||||
g_lua.terminate();
|
|
||||||
|
|
||||||
// end platform related stuff
|
|
||||||
g_platform.terminate();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void OTClient::exit()
|
|
||||||
{
|
|
||||||
// stops the main loop
|
|
||||||
m_stopping = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OTClient::poll()
|
|
||||||
{
|
|
||||||
// poll platform events
|
|
||||||
g_platform.poll();
|
|
||||||
|
|
||||||
// poll network events
|
|
||||||
//g_network.poll();
|
|
||||||
Connection::poll();
|
|
||||||
|
|
||||||
// poll dispatcher events
|
|
||||||
g_dispatcher.poll();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OTClient::render()
|
|
||||||
{
|
|
||||||
if(g_game.getOnline())
|
|
||||||
g_game.getMap()->draw(0, 0);
|
|
||||||
|
|
||||||
// everything is rendered by UI components
|
|
||||||
g_ui.render();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OTClient::loadConfigurations()
|
|
||||||
{
|
|
||||||
// default window size
|
|
||||||
int defWidth = 550;
|
|
||||||
int defHeight = 450;
|
|
||||||
|
|
||||||
// sets default window configuration
|
|
||||||
g_configs.set("window x", (g_platform.getDisplayWidth() - defWidth)/2);
|
|
||||||
g_configs.set("window y", (g_platform.getDisplayHeight() - defHeight)/2);
|
|
||||||
g_configs.set("window width", defWidth);
|
|
||||||
g_configs.set("window height", defHeight);
|
|
||||||
g_configs.set("window maximized", false);
|
|
||||||
g_configs.set("vsync", true);
|
|
||||||
|
|
||||||
// loads user configuration
|
|
||||||
if(!g_configs.load("config.otml"))
|
|
||||||
logInfo("Using default configurations.");
|
|
||||||
}
|
|
||||||
|
|
||||||
void OTClient::setupConfigurations()
|
|
||||||
{
|
|
||||||
// activate vertical synchronization?
|
|
||||||
g_platform.setVerticalSync(g_configs.get("vsync"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void OTClient::saveConfigurations()
|
|
||||||
{
|
|
||||||
g_configs.set("window x", g_platform.getWindowX());
|
|
||||||
g_configs.set("window y", g_platform.getWindowY());
|
|
||||||
g_configs.set("window width", g_platform.getWindowWidth());
|
|
||||||
g_configs.set("window height", g_platform.getWindowHeight());
|
|
||||||
g_configs.set("window maximized", g_platform.isWindowMaximized());
|
|
||||||
|
|
||||||
// saves user configuration
|
|
||||||
if(!g_configs.save())
|
|
||||||
logError("ERROR: configurations are lost because it couldn't be saved");
|
|
||||||
}
|
|
||||||
|
|
||||||
void OTClient::onClose()
|
|
||||||
{
|
|
||||||
if(m_onCloseCallback)
|
|
||||||
m_onCloseCallback();
|
|
||||||
else
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OTClient::onResize(const Size& size)
|
|
||||||
{
|
|
||||||
g_graphics.resize(size);
|
|
||||||
g_ui.resize(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OTClient::onInputEvent(const InputEvent& event)
|
|
||||||
{
|
|
||||||
g_ui.inputEvent(event);
|
|
||||||
|
|
||||||
ProtocolGamePtr protocol = g_game.getProtocol();
|
|
||||||
if(protocol) {
|
|
||||||
if(event.type == EventKeyDown) {
|
|
||||||
if(event.keycode == KC_UP)
|
|
||||||
protocol->sendWalkNorth();
|
|
||||||
if(event.keycode == KC_RIGHT)
|
|
||||||
protocol->sendWalkEast();
|
|
||||||
if(event.keycode == KC_DOWN)
|
|
||||||
protocol->sendWalkSouth();
|
|
||||||
if(event.keycode == KC_LEFT)
|
|
||||||
protocol->sendWalkWest();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
#ifndef OTCLIENT_H
|
|
||||||
#define OTCLIENT_H
|
|
||||||
|
|
||||||
#include <core/platformlistener.h>
|
|
||||||
|
|
||||||
class OTClient : public PlatformListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/// Where everything begins...
|
|
||||||
void init(std::vector<std::string> args);
|
|
||||||
/// Main loop
|
|
||||||
void run();
|
|
||||||
/// Called when the client is terminating
|
|
||||||
void terminate();
|
|
||||||
|
|
||||||
/// Stop running
|
|
||||||
void exit();
|
|
||||||
/// Poll platform, dispatcher and network events
|
|
||||||
void poll();
|
|
||||||
/// Render each frame
|
|
||||||
void render();
|
|
||||||
|
|
||||||
/// Fired when user tryes to close the window
|
|
||||||
void onClose();
|
|
||||||
/// Fired when user resize the window
|
|
||||||
void onResize(const Size& size);
|
|
||||||
/// Fired on an user input event
|
|
||||||
void onInputEvent(const InputEvent& event);
|
|
||||||
|
|
||||||
bool isRunning() const { return m_running; }
|
|
||||||
|
|
||||||
void setOnClose(const SimpleCallback& onCloseCallback) { m_onCloseCallback = onCloseCallback; }
|
|
||||||
SimpleCallback getOnClose() const { return m_onCloseCallback; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
/// Set default configurations and load the user configurations
|
|
||||||
void loadConfigurations();
|
|
||||||
/// Use the loaded configurations to setup other classes
|
|
||||||
void setupConfigurations();
|
|
||||||
void saveConfigurations();
|
|
||||||
|
|
||||||
void registerLuaFunctions();
|
|
||||||
|
|
||||||
bool m_running;
|
|
||||||
bool m_stopping;
|
|
||||||
|
|
||||||
SimpleCallback m_onCloseCallback;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern OTClient g_client;
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,25 +0,0 @@
|
||||||
#include "otclient.h"
|
|
||||||
#include <luascript/luainterface.h>
|
|
||||||
|
|
||||||
#include "tibiadat.h"
|
|
||||||
#include "tibiaspr.h"
|
|
||||||
#include "protocollogin.h"
|
|
||||||
#include "protocolgame.h"
|
|
||||||
|
|
||||||
void OTClient::registerLuaFunctions()
|
|
||||||
{
|
|
||||||
// easy typing _1, _2, ...
|
|
||||||
using namespace std::placeholders;
|
|
||||||
|
|
||||||
g_lua.bindGlobalFunction("exit", std::bind(&OTClient::exit, &g_client));
|
|
||||||
g_lua.bindGlobalFunction("setOnClose", std::bind(&OTClient::setOnClose, &g_client, _1));
|
|
||||||
g_lua.bindGlobalFunction("importDat", std::bind(&TibiaDat::load, &g_tibiaDat, _1));
|
|
||||||
g_lua.bindGlobalFunction("importSpr", std::bind(&TibiaSpr::load, &g_tibiaSpr, _1));
|
|
||||||
|
|
||||||
g_lua.registerClass<ProtocolLogin, Protocol>();
|
|
||||||
g_lua.bindClassStaticFunction<ProtocolLogin>("create", &ProtocolLogin::create);
|
|
||||||
g_lua.bindClassMemberFunction("login", &ProtocolLogin::login);
|
|
||||||
g_lua.bindClassMemberFunction("cancel", &ProtocolLogin::cancel);
|
|
||||||
|
|
||||||
g_lua.registerClass<ProtocolGame, Protocol>();
|
|
||||||
}
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef PCH_H
|
||||||
|
#define PCH_H
|
||||||
|
|
||||||
|
#include "framework/global.h"
|
||||||
|
#include "otclient/global.h"
|
||||||
|
|
||||||
|
#endif
|
22
src/player.h
22
src/player.h
|
@ -1,22 +0,0 @@
|
||||||
#ifndef PLAYER_H
|
|
||||||
#define PLAYER_H
|
|
||||||
|
|
||||||
#include "creature.h"
|
|
||||||
|
|
||||||
class Player : public Creature
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void setDrawSpeed(uint16 drawSpeed) { m_drawSpeed = drawSpeed; }
|
|
||||||
uint16 getDrawSpeed() { return m_drawSpeed; }
|
|
||||||
|
|
||||||
void setCanReportBugs(uint8 canReportBugs) { m_canReportBugs = (canReportBugs != 0); }
|
|
||||||
bool getCanReportBugs() { return m_canReportBugs; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
uint16 m_drawSpeed;
|
|
||||||
bool m_canReportBugs;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,38 +0,0 @@
|
||||||
#ifndef POSITION_H
|
|
||||||
#define POSITION_H
|
|
||||||
|
|
||||||
#include <global.h>
|
|
||||||
|
|
||||||
enum Direction
|
|
||||||
{
|
|
||||||
DIRECTION_NORTH,
|
|
||||||
DIRECTION_EAST,
|
|
||||||
DIRECTION_SOUTH,
|
|
||||||
DIRECTION_WEST
|
|
||||||
};
|
|
||||||
|
|
||||||
class Position
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Position(uint16 x = 0, uint16 y = 0, uint8 z = 0) {
|
|
||||||
this->x = x;
|
|
||||||
this->y = y;
|
|
||||||
this->z = z;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const Position& other) const { return other.x == x && other.y == y && other.z == z; }
|
|
||||||
const Position operator+(const Position& other) const { return Position(other.x + x, other.y + y, other.z + z); }
|
|
||||||
const Position operator-(const Position& other) const { return Position(other.x - x, other.y - y, other.z - z); }
|
|
||||||
|
|
||||||
uint16 x, y;
|
|
||||||
uint8 z;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PositionHash : public std::unary_function<Position, size_t>
|
|
||||||
{
|
|
||||||
size_t operator()(const Position& pos) const {
|
|
||||||
return ((((pos.x * 65536) + pos.y) * 15) + pos.z) % (1 * 1000000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,99 +0,0 @@
|
||||||
#include "protocolgame.h"
|
|
||||||
#include "game.h"
|
|
||||||
#include <net/rsa.h>
|
|
||||||
|
|
||||||
ProtocolGame::ProtocolGame()
|
|
||||||
{
|
|
||||||
m_checksumEnabled = false;
|
|
||||||
g_game.setProtocol(ProtocolGamePtr(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
ProtocolGame::~ProtocolGame()
|
|
||||||
{
|
|
||||||
sendLogout();
|
|
||||||
g_game.setProtocol(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProtocolGame::login(const std::string& accountName, const std::string& accountPassword, uint32 ip, uint16 port, const std::string& characterName)
|
|
||||||
{
|
|
||||||
if(accountName.empty() || accountPassword.empty()) {
|
|
||||||
callLuaField("onError", "You must enter an account name and password.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_accountName = accountName;
|
|
||||||
m_accountPassword = accountPassword;
|
|
||||||
m_characterName = characterName;
|
|
||||||
|
|
||||||
char host[16];
|
|
||||||
sprintf(host, "%d.%d.%d.%d", (uint8)ip, (uint8)(ip >> 8), (uint8)(ip >> 16), (uint8)(ip >> 24));
|
|
||||||
|
|
||||||
connect(host, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProtocolGame::onConnect()
|
|
||||||
{
|
|
||||||
recv();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProtocolGame::sendLoginPacket(uint32 timestamp, uint8 unknown)
|
|
||||||
{
|
|
||||||
OutputMessage oMsg;
|
|
||||||
|
|
||||||
oMsg.addU8(0x0A); // Protocol id
|
|
||||||
oMsg.addU16(0x02); // OS
|
|
||||||
oMsg.addU16(862); // Client version
|
|
||||||
|
|
||||||
oMsg.addU8(0); // First RSA byte must be 0x00 // 1
|
|
||||||
|
|
||||||
// Generete xtea key.
|
|
||||||
m_xteaKey[0] = 432324;
|
|
||||||
m_xteaKey[1] = 24324;
|
|
||||||
m_xteaKey[2] = 423432;
|
|
||||||
m_xteaKey[3] = 234324;
|
|
||||||
|
|
||||||
// Add xtea key
|
|
||||||
oMsg.addU32(m_xteaKey[0]); // 5
|
|
||||||
oMsg.addU32(m_xteaKey[1]); // 9
|
|
||||||
oMsg.addU32(m_xteaKey[2]); // 13
|
|
||||||
oMsg.addU32(m_xteaKey[3]); // 17
|
|
||||||
|
|
||||||
oMsg.addU8(0); // is gm set?
|
|
||||||
oMsg.addString(m_accountName); // Account Name // 20
|
|
||||||
oMsg.addString(m_characterName); // Character Name // 22
|
|
||||||
oMsg.addString(m_accountPassword); // Password // 24
|
|
||||||
|
|
||||||
oMsg.addU32(timestamp); // 28
|
|
||||||
oMsg.addU8(unknown); // 29
|
|
||||||
|
|
||||||
// Packet data must have since byte 0, start, 128 bytes
|
|
||||||
oMsg.addPaddingBytes(128 - (29 + m_accountName.length() + m_characterName.length() + m_accountPassword.length()));
|
|
||||||
|
|
||||||
// Encrypt msg with RSA
|
|
||||||
if(!Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, OTSERV_PUBLIC_RSA))
|
|
||||||
return;
|
|
||||||
|
|
||||||
send(oMsg);
|
|
||||||
|
|
||||||
m_xteaEncryptionEnabled = true;
|
|
||||||
|
|
||||||
recv();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProtocolGame::onRecv(InputMessage& inputMessage)
|
|
||||||
{
|
|
||||||
static bool firstRecv = true;
|
|
||||||
if(firstRecv) {
|
|
||||||
inputMessage.skipBytes(3);
|
|
||||||
uint32 timestamp = inputMessage.getU32();
|
|
||||||
uint8 unknown = inputMessage.getU8();
|
|
||||||
|
|
||||||
m_checksumEnabled = true;
|
|
||||||
sendLoginPacket(timestamp, unknown);
|
|
||||||
|
|
||||||
firstRecv = false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
parseMessage(inputMessage);
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue