compilation fixes

master
Eduardo Bart 13 years ago
parent 6451e36240
commit 21bcbf9a97

@ -5,7 +5,8 @@ SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
# find needed packages
SET(Boost_USE_STATIC_LIBS ON)
FIND_PACKAGE(Boost COMPONENTS system REQUIRED)
SET(Boost_USE_MULTITHREADED ON)
FIND_PACKAGE(Boost COMPONENTS system regex REQUIRED)
FIND_PACKAGE(OpenGL REQUIRED)
FIND_PACKAGE(Lua51 REQUIRED)
FIND_PACKAGE(YamlCpp REQUIRED)
@ -52,7 +53,7 @@ SET(SOURCES
# game sources
src/main.cpp
src/menustate.cpp
# framework sources
src/framework/framebuffer.cpp
src/framework/font.cpp
@ -72,8 +73,11 @@ SET(SOURCES
IF(WIN32)
SET(SOURCES ${SOURCES} src/framework/win32platform.cpp)
SET(ADDITIONAL_LIBRARIES ws2_32)
ADD_DEFINITIONS(-D_WIN32_WINNT=0x0501)
ELSE(WIN32)
SET(SOURCES ${SOURCES} src/framework/x11platform.cpp)
SET(ADDITIONAL_LIBRARIES pthread GLU)
ENDIF(WIN32)
# target executable
@ -86,4 +90,5 @@ TARGET_LINK_LIBRARIES(otclient
${LUA51_LIBRARY}
${YAMLCPP_LIBRARY}
${PHYSFS_LIBRARY}
${PNG_LIBRARY})
${PNG_LIBRARY}
${ADDITIONAL_LIBRARIES})

@ -53,7 +53,7 @@ bool Configs::load(const std::string& fileName)
m_confsMap[key] = value;
}
} catch (YAML::ParserException& e) {
error("Malformed configuration file!");
logError("Malformed configuration file!");
return false;
}
@ -101,7 +101,7 @@ const std::string &Configs::getString(const std::string &key) const
{
auto it = m_confsMap.find(key);
if(it == m_confsMap.end()) {
warning("Config value %s not found", key.c_str());
logWarning("Config value %s not found", key.c_str());
static std::string emptystr;
return emptystr;
}
@ -112,7 +112,7 @@ float Configs::getFloat(const std::string &key) const
{
auto it = m_confsMap.find(key);
if(it == m_confsMap.end()) {
warning("Config value %s not found", key.c_str());
logWarning("Config value %s not found", key.c_str());
return 0;
}
return convertType<float, std::string>(it->second);
@ -122,7 +122,7 @@ bool Configs::getBoolean(const std::string &key) const
{
auto it = m_confsMap.find(key);
if(it == m_confsMap.end()) {
warning("Config value %s not found", key.c_str());
logWarning("Config value %s not found", key.c_str());
return 0;
}
return (it->second == "true");
@ -132,7 +132,7 @@ int Configs::getInteger(const std::string &key) const
{
auto it = m_confsMap.find(key);
if(it == m_confsMap.end()) {
warning("Config value %s not found", key.c_str());
logWarning("Config value %s not found", key.c_str());
return 0;
}
return convertType<int, std::string>(it->second);

@ -77,7 +77,7 @@ void Engine::run()
Platform::poll();
//poll network events
//debug("%d", g_connections.poll());
//logDebug("%d", g_connections.poll());
// update before redering
ticks = Platform::getTicks();
@ -113,7 +113,7 @@ void Engine::run()
static ConnectionPtr connection = g_connections.createConnection();
if(connection->getLastError()){
error("%s", connection->getLastError().message().c_str());
logError("%s", connection->getLastError().message().c_str());
}
else{
if(!connection->isConnecting() && !connection->isConnected()){
@ -121,7 +121,7 @@ void Engine::run()
}
if(!connection->isConnected()){
debug("still not connected.");
logDebug("still not connected.");
}
}
*/

@ -37,13 +37,13 @@ Font::Font() :
bool Font::load(const std::string& file)
{
if(!g_resources.fileExists(file)) {
error("Font file %s does not exists", file.c_str());
logError("Font file %s does not exists", file.c_str());
return false;
}
std::string fileContents = g_resources.loadTextFile(file);
if(!fileContents.size()) {
error("Empty font file \"%s", file.c_str());
logError("Empty font file \"%s", file.c_str());
return false;
}
@ -70,7 +70,7 @@ bool Font::load(const std::string& file)
m_texture = g_textures.get("fonts/" + textureName);
if(!m_texture) {
error("Failed to load image for font \"%s\"", file.c_str());
logError("Failed to load image for font \"%s\"", file.c_str());
return false;
}
@ -94,7 +94,7 @@ bool Font::load(const std::string& file)
m_glyphsSize[glyph].setWidth(glyphWidth);
}
} catch (YAML::ParserException& e) {
error("Malformed font file \"%s\"", file.c_str());
logError("Malformed font file \"%s\"", file.c_str());
return false;
}

@ -48,7 +48,7 @@ Font* Fonts::get(const std::string& fontName)
if(it != m_fonts.end()) {
return it->second.get();
}
error("Font \"%s\" not found", fontName.c_str());
logError("Font \"%s\" not found", fontName.c_str());
return NULL;
}
@ -58,6 +58,6 @@ Font *Fonts::getDefault()
if(font) {
return font;
}
fatal("Default font not found!");
logFatal("Default font not found!");
return NULL;
}

@ -43,8 +43,8 @@ void Graphics::init()
glShadeModel(GL_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
notice("GPU %s", (const char*)glGetString(GL_RENDERER));
notice("OpenGL %s", (const char*)glGetString(GL_VERSION));
logInfo("GPU %s", (const char*)glGetString(GL_RENDERER));
logInfo("OpenGL %s", (const char*)glGetString(GL_VERSION));
}
void Graphics::terminate()

@ -27,8 +27,9 @@
#include <iostream>
#include <cstdlib>
#include <stdarg.h>
void Logger::log(int level, const char *trace, const char *format, ...)
void Logger::_log(int level, const char *trace, const char *format, ...)
{
va_list args;
std::string strace;

@ -37,23 +37,23 @@ enum ELogLevel {
LDEBUG
};
void log(int level, const char *trace, const char *format, ...);
void _log(int level, const char *trace, const char *format, ...);
}
#define fatal(...) Logger::log(Logger::LFATAL, NULL, __VA_ARGS__)
#define error(...) Logger::log(Logger::LERROR, NULL, __VA_ARGS__)
#define warning(...) Logger::log(Logger::LWARNING, NULL, __VA_ARGS__)
#define debug(...) Logger::log(Logger::LDEBUG, NULL, __VA_ARGS__)
#define notice(...) Logger::log(Logger::LNOTICE, NULL, __VA_ARGS__)
#define logFatal(...) Logger::_log(Logger::LFATAL, NULL, __VA_ARGS__)
#define logError(...) Logger::_log(Logger::LERROR, NULL, __VA_ARGS__)
#define logWarning(...) Logger::_log(Logger::LWARNING, NULL, __VA_ARGS__)
#define logDebug(...) Logger::_log(Logger::LDEBUG, NULL, __VA_ARGS__)
#define logInfo(...) Logger::_log(Logger::LNOTICE, NULL, __VA_ARGS__)
#define trace() Logger::log(Logger::LDEBUG, __PRETTY_FUNCTION__, "")
#define tdebug(...) Logger::log(Logger::LDEBUG, __PRETTY_FUNCTION__, __VA_ARGS__)
#define logTrace() Logger::_log(Logger::LDEBUG, __PRETTY_FUNCTION__, "")
#define logDebugTrace(...) Logger::_log(Logger::LDEBUG, __PRETTY_FUNCTION__, __VA_ARGS__)
struct Dump {
public:
Dump() { }
~Dump() { debug(m_buf.str().c_str()); }
~Dump() { logDebug(m_buf.str().c_str()); }
template<class T> Dump &operator<<(const T &x) { m_buf << x << " "; return *this; }
private:
std::ostringstream m_buf;

@ -23,6 +23,8 @@
#include "connection.h"
#include <boost/bind.hpp>
Connection::Connection(boost::asio::io_service& ioService)
: m_socket(ioService), m_resolver(ioService)
{
@ -44,7 +46,7 @@ void Connection::stop()
void Connection::connect(const std::string& ip, uint16 port)
{
if(m_connecting){
error("Already is connecting.");
logError("Already is connecting.");
return;
}
@ -52,16 +54,16 @@ void Connection::connect(const std::string& ip, uint16 port)
m_ip = ip;
m_port = port;
debug("connecting...");
logDebug("connecting...");
//first resolve dns
boost::asio::ip::tcp::resolver::query query(ip, 80);
boost::asio::ip::tcp::resolver::query query(ip, "80");
m_resolver.async_resolve(query, boost::bind(&Connection::onResolveDns, this, boost::asio::placeholders::error, boost::asio::placeholders::iterator));
}
void Connection::onResolveDns(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
{
debug("resolving dns..");
logDebug("resolving dns..");
if(error){
m_connecting = false;
m_lastError = error;
@ -82,5 +84,5 @@ void Connection::onConnect(const boost::system::error_code& error)
m_connected = true;
notice("Connected on %s.", m_ip.c_str());
logInfo("Connected on %s.", m_ip.c_str());
}

@ -26,6 +26,8 @@
#include "../prerequisites.h"
#include <boost/asio.hpp>
class Connection
{
public:

@ -63,9 +63,6 @@ typedef int8_t int8;
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/foreach.hpp>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#define foreach BOOST_FOREACH
// yaml

@ -43,14 +43,14 @@ bool Resources::setWriteDir(const std::string& path)
bool ret = (bool)PHYSFS_setWriteDir(path.c_str());
if(!ret)
error("Could not set the path \"%s\" as write directory, file write will not work.", path.c_str());
logError("Could not set the path \"%s\" as write directory, file write will not work.", path.c_str());
return ret;
}
bool Resources::addToSearchPath(const std::string& path, bool insertInFront /*= true*/)
{
if(!PHYSFS_addToSearchPath(path.c_str(), insertInFront ? 0 : 1)) {
error("Error while adding \"%s\" to resources search path: %s", path.c_str(), PHYSFS_getLastError());
logError("Error while adding \"%s\" to resources search path: %s", path.c_str(), PHYSFS_getLastError());
return false;
}
return true;
@ -65,7 +65,7 @@ uchar *Resources::loadFile(const std::string& fileName, uint *fileSize)
{
PHYSFS_file *file = PHYSFS_openRead(fileName.c_str());
if(!file) {
error("Failed to load file \"%s\": %s", fileName.c_str(), PHYSFS_getLastError());
logError("Failed to load file \"%s\": %s", fileName.c_str(), PHYSFS_getLastError());
*fileSize = 0;
return NULL;
}
@ -94,7 +94,7 @@ bool Resources::saveFile(const std::string &fileName, const uchar *data, uint si
{
PHYSFS_file *file = PHYSFS_openWrite(fileName.c_str());
if(!file) {
error("Failed to save file \"%s\": %s", fileName.c_str(), PHYSFS_getLastError());
logError("Failed to save file \"%s\": %s", fileName.c_str(), PHYSFS_getLastError());
return false;
}

@ -44,7 +44,7 @@ TexturePtr Textures::get(const std::string& textureFile)
if(!texture) { // load texture
// currently only png textures are supported
if(!boost::ends_with(textureFile, ".png")) {
error("Unable to load texture %s, file format no supported.", textureFile.c_str());
logError("Unable to load texture %s, file format no supported.", textureFile.c_str());
return texture;
}
@ -55,7 +55,7 @@ TexturePtr Textures::get(const std::string& textureFile)
texture = TexturePtr(TextureLoader::loadPNG(textureFileData));
if(!texture)
error("Unable to load texture %s, loading error.", textureFile.c_str());
logError("Unable to load texture %s, loading error.", textureFile.c_str());
delete[] textureFileData;
}

@ -43,7 +43,7 @@ R convertType(T t)
try {
ret = boost::lexical_cast<R>(t);
} catch(boost::bad_lexical_cast bad) {
error("Error converting type: %s", bad.what());
logError("Error converting type: %s", bad.what());
}
return ret;
}

@ -64,7 +64,7 @@ void Platform::init(const char *appName)
wc.lpszClassName = win32.appName.c_str(); // Set The Class Name
if(!RegisterClassA(&wc))
fatal("Failed to register the window class.");
logFatal("Failed to register the window class.");
// force first tick
Platform::getTicks();
@ -79,7 +79,7 @@ void Platform::terminate()
if(win32.instance) {
if(!UnregisterClassA(win32.appName.c_str(), win32.instance))
error("Unregister class failed.");
logError("Unregister class failed.");
win32.instance = NULL;
}
@ -139,7 +139,7 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i
if(!win32.window) {
terminate();
fatal("Window creation error.");
logFatal("Window creation error.");
return false;
}
@ -168,31 +168,31 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i
if(!(win32.hdc = GetDC(win32.window))) {
terminate();
fatal("Can't Create A GL Device Context.");
logFatal("Can't Create A GL Device Context.");
return false;
}
if(!(pixelFormat = ChoosePixelFormat(win32.hdc, &pfd))) {
terminate();
fatal("Can't Find A Suitable PixelFormat.");
logFatal("Can't Find A Suitable PixelFormat.");
return false;
}
if(!SetPixelFormat(win32.hdc, pixelFormat, &pfd)) {
terminate();
fatal("Can't Set The PixelFormat.");
logFatal("Can't Set The PixelFormat.");
return false;
}
if(!(win32.hrc = wglCreateContext(win32.hdc))) {
terminate();
fatal("Can't Create A GL Rendering Context.");
logFatal("Can't Create A GL Rendering Context.");
return false;
}
if(!wglMakeCurrent(win32.hdc, win32.hrc)) {
terminate();
fatal("Can't Activate The GL Rendering Context.");
logFatal("Can't Activate The GL Rendering Context.");
return false;
}
@ -203,24 +203,24 @@ void Platform::destroyWindow()
{
if(win32.hrc) {
if(!wglMakeCurrent(NULL, NULL))
error("Release Of DC And RC Failed.");
logError("Release Of DC And RC Failed.");
if(!wglDeleteContext(win32.hrc))
error("Release Rendering Context Failed.");
logError("Release Rendering Context Failed.");
win32.hrc = NULL;
}
if(win32.hdc) {
if(!ReleaseDC(win32.window, win32.hdc))
error("Release Device Context Failed.");
logError("Release Device Context Failed.");
win32.hdc = NULL;
}
if(win32.window) {
if(!DestroyWindow(win32.window))
error("Destroy window failed.");
logError("Destroy window failed.");
win32.window = NULL;
}
@ -355,7 +355,7 @@ const char *Platform::getAppUserDir()
std::stringstream sdir;
sdir << PHYSFS_getUserDir() << "/." << win32.appName << "/";
if((mkdir(sdir.str().c_str()) != 0) && (errno != EEXIST))
error("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
logError("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
return sdir.str().c_str();
}

@ -233,18 +233,18 @@ void Platform::init(const char *appName)
// open display
x11.display = XOpenDisplay(0);
if(!x11.display)
fatal("Failed to open X display");
logFatal("Failed to open X display");
// check if GLX is supported on this display
if(!glXQueryExtension(x11.display, 0, 0))
fatal("GLX not supported");
logFatal("GLX not supported");
// retrieve GLX version
int glxMajor;
int glxMinor;
if(!glXQueryVersion(x11.display, &glxMajor, &glxMinor))
fatal("Unable to query GLX version");
notice("GLX version %d.%d", glxMajor, glxMinor);
logFatal("Unable to query GLX version");
logInfo("GLX version %d.%d", glxMajor, glxMinor);
// clipboard related atoms
x11.atomClipboard = XInternAtom(x11.display, "CLIPBOARD", False);
@ -346,7 +346,7 @@ void Platform::poll()
keysym != XK_Delete &&
keysym != XK_Escape
) {
//debug("char: %c code: %d", buf[0], (uchar)buf[0]);
//logDebug("char: %c code: %d", buf[0], (uchar)buf[0]);
inputEvent.type = EV_TEXT_ENTER;
inputEvent.key.keychar = buf[0];
inputEvent.key.keycode = KC_UNKNOWN;
@ -491,12 +491,12 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i
// choose OpenGL, RGBA, double buffered, visual
x11.visual = glXChooseVisual(x11.display, DefaultScreen(x11.display), attrList);
if(!x11.visual)
fatal("RGBA/Double buffered visual not supported");
logFatal("RGBA/Double buffered visual not supported");
// create GLX context
x11.glxContext = glXCreateContext(x11.display, x11.visual, 0, GL_TRUE);
if(!x11.glxContext)
fatal("Unable to create GLX context");
logFatal("Unable to create GLX context");
// color map
x11.colormap = XCreateColormap(x11.display,
@ -529,7 +529,7 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i
&wa);
if(!x11.window)
fatal("Unable to create X window");
logFatal("Unable to create X window");
// create input context (to have better key input handling)
if(XSupportsLocale()) {
@ -541,14 +541,14 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i
XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, x11.window, NULL);
if(!x11.xic)
error("Unable to create the input context");
logError("Unable to create the input context");
} else
error("Failed to open an input method");
logError("Failed to open an input method");
} else
error("X11 does not support the current locale");
logError("X11 does not support the current locale");
if(!x11.xic)
warning("Input of special keys maybe messed up because we couldn't create an input context");
logWarning("Input of special keys maybe messed up because we couldn't create an input context");
// set window minimum size
@ -826,6 +826,6 @@ const char *Platform::getAppUserDir()
std::stringstream sdir;
sdir << PHYSFS_getUserDir() << "/." << x11.appName << "/";
if((mkdir(sdir.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && (errno != EEXIST))
error("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
logError("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
return sdir.str().c_str();
}

@ -91,9 +91,9 @@ int main(int argc, const char *argv[])
// load configurations
if(!g_configs.load("config.yml"))
notice("Could not read configuration file, default configurations will be used.");
logInfo("Could not read configuration file, default configurations will be used.");
notice("OTClient 0.1.0");
logInfo("OTClient 0.1.0");
// create the window
Platform::createWindow(g_configs.getInteger("window x"), g_configs.getInteger("window y"),

Loading…
Cancel
Save