add a new folder structure redesign organized by packages

This commit is contained in:
Eduardo Bart
2011-07-17 08:52:20 -03:00
parent b1a881eb06
commit ab7394f357
56 changed files with 586 additions and 212 deletions

View File

@@ -20,7 +20,7 @@ bool Configs::load(const std::string& fileName)
OTMLParser parser(fin, fileName);
parser.getDocument()->read(&m_confsMap);
} catch(OTMLException e) {
error("ERROR: Malformed config file: ", e.what());
logError("ERROR: Malformed config file: ", e.what());
return false;
}

View File

@@ -53,7 +53,7 @@ void Engine::run()
// check if root container has elements
const UIContainerPtr& rootContainer = UIContainer::getRoot();
if(rootContainer->getChildCount() == 0)
fatal("FATAL ERROR: no ui loaded at all, no reason to continue running");
logFatal("FATAL ERROR: no ui loaded at all, no reason to continue running");
std::string fpsText;
Size fpsTextSize;

View File

@@ -24,20 +24,20 @@ void Resources::init(const char *argv0)
bool found = false;
foreach(dir, possibleDirs) {
if(g_resources.addToSearchPath(dir)) {
info("Using data directory: ", dir.c_str());
logInfo("Using data directory: ", dir.c_str());
found = true;
break;
}
}
if(!found)
fatal("ERROR: could not find data directory");
logFatal("ERROR: could not find data directory");
// setup write directory
dir = Platform::getAppUserDir();
if(g_resources.setWriteDir(dir))
g_resources.addToSearchPath(dir);
else
error("ERROR: could not setup write directory");
logError("ERROR: could not setup write directory");
}
void Resources::terminate()
@@ -84,7 +84,7 @@ bool Resources::loadFile(const std::string& fileName, std::iostream& out)
out.clear(std::ios::goodbit);
PHYSFS_file *file = PHYSFS_openRead(fullPath.c_str());
if(!file) {
error("ERROR: Failed to load file '", fullPath.c_str(), "': ", PHYSFS_getLastError());
logError("ERROR: Failed to load file '", fullPath.c_str(), "': ", PHYSFS_getLastError());
out.clear(std::ios::failbit);
return false;
} else {
@@ -106,7 +106,7 @@ bool Resources::saveFile(const std::string &fileName, const uchar *data, uint si
{
PHYSFS_file *file = PHYSFS_openWrite(resolvePath(fileName).c_str());
if(!file) {
error("ERROR: Failed to save file '",fileName,"': ",PHYSFS_getLastError());
logError("ERROR: Failed to save file '",fileName,"': ",PHYSFS_getLastError());
return false;
}

View File

@@ -71,7 +71,7 @@ bool Font::load(const std::string& file)
{
std::stringstream fin;
if(!g_resources.loadFile(file, fin)) {
error("ERROR: Coult not load font file '",file,"'");
logError("ERROR: Coult not load font file '",file,"'");
return false;
}
@@ -93,7 +93,7 @@ bool Font::load(const std::string& file)
// load texture
m_texture = g_textures.get(textureName);
if(!m_texture) {
error("ERROR: Failed to load image for font file '",file,"'");
logError("ERROR: Failed to load image for font file '",file,"'");
return false;
}
@@ -117,7 +117,7 @@ bool Font::load(const std::string& file)
m_glyphHeight);
}
} catch(OTMLException e) {
error("ERROR: Malformed font file \"", file.c_str(), "\":\n ", e.what());
logError("ERROR: Malformed font file \"", file.c_str(), "\":\n ", e.what());
return false;
}

View File

@@ -57,7 +57,7 @@ FontPtr Fonts::get(const std::string& fontName)
return font;
}
fatal("ERROR: Font '",fontName,"' not found");
logFatal("ERROR: Font '",fontName,"' not found");
return FontPtr();
}

View File

@@ -40,8 +40,8 @@ void Graphics::init()
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
info("GPU ", glGetString(GL_RENDERER));
info("OpenGL ", glGetString(GL_VERSION));
logInfo("GPU ", glGetString(GL_RENDERER));
logInfo("OpenGL ", glGetString(GL_VERSION));
}
void Graphics::terminate()

View File

@@ -37,7 +37,7 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int
GLint texSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
if(width > texSize || height > texSize) {
error("loading texture with size ",width,"x",height," failed, the maximum size is ",texSize,"x",texSize);
logError("loading texture with size ",width,"x",height," failed, the maximum size is ",texSize,"x",texSize);
return 0;
}

View File

@@ -49,14 +49,14 @@ TexturePtr Textures::get(const std::string& textureFile)
if(!texture) {
// currently only png textures are supported
if(!boost::ends_with(textureFile, ".png")) {
error("ERROR: Unable to load texture '",textureFile,"', file format no supported.");
logError("ERROR: Unable to load texture '",textureFile,"', file format no supported.");
return texture;
}
// load texture file data
std::stringstream fin;
if(!g_resources.loadFile(textureFile, fin)) {
error("ERROR: Unable to load texture '",textureFile,"', file could not be read.");
logError("ERROR: Unable to load texture '",textureFile,"', file could not be read.");
return texture;
}
@@ -64,7 +64,7 @@ TexturePtr Textures::get(const std::string& textureFile)
// load the texture
texture = TexturePtr(TextureLoader::loadPNG(fin));
if(!texture)
error("ERROR: Unable to load texture '",textureFile,"'");
logError("ERROR: Unable to load texture '",textureFile,"'");
}
return texture;
}

View File

@@ -87,6 +87,6 @@ std::string InputMessage::getString()
bool InputMessage::canRead(int bytes)
{
if((m_readPos + bytes > m_messageSize) || (m_readPos + bytes > BUFFER_MAXSIZE))
fatal("[InputMessage::canRead()]: Cant read. Message is finished or read position has reached buffer's maximum size.");
logFatal("[InputMessage::canRead()]: Cant read. Message is finished or read position has reached buffer's maximum size.");
return true;
}

View File

@@ -105,6 +105,6 @@ void OutputMessage::addPaddingBytes(int bytes, uint8 byte)
bool OutputMessage::canWrite(int bytes)
{
if(m_writePos + bytes > BUFFER_MAXSIZE)
fatal("[OutputMessage::canWrite()]: Can't write. Write position has reached buffer's maxium size.");
logFatal("[OutputMessage::canWrite()]: Can't write. Write position has reached buffer's maxium size.");
return true;
}

View File

@@ -64,7 +64,7 @@ void Protocol::onRecv(InputMessage *inputMessage)
uint32 checksum = getAdlerChecksum(inputMessage->getBuffer() + InputMessage::DATA_POS, inputMessage->getMessageSize() - InputMessage::CHECKSUM_LENGTH);
if(inputMessage->getU32() != checksum) {
// error
error("Checksum is invalid.");
logError("Checksum is invalid.");
return;
}
@@ -74,7 +74,7 @@ void Protocol::onRecv(InputMessage *inputMessage)
void Protocol::onError(const boost::system::error_code& err)
{
error("PROTOCOL ERROR: ", err.message());
logError("PROTOCOL ERROR: ", err.message());
// invalid hostname
// connection timeouted

View File

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

View File

@@ -213,18 +213,18 @@ void Platform::init(const char *appName)
// open display
x11.display = XOpenDisplay(0);
if(!x11.display)
fatal("FATAL ERROR: Failed to open X display");
logFatal("FATAL ERROR: Failed to open X display");
// check if GLX is supported on this display
if(!glXQueryExtension(x11.display, 0, 0))
fatal("FATAL ERROR: GLX not supported");
logFatal("FATAL ERROR: GLX not supported");
// retrieve GLX version
int glxMajor;
int glxMinor;
if(!glXQueryVersion(x11.display, &glxMajor, &glxMinor))
fatal("FATAL ERROR: Unable to query GLX version");
info("GLX version ",glxMajor,".",glxMinor);
logFatal("FATAL ERROR: Unable to query GLX version");
logInfo("GLX version ",glxMajor,".",glxMinor);
// clipboard related atoms
x11.atomClipboard = XInternAtom(x11.display, "CLIPBOARD", False);
@@ -328,7 +328,7 @@ void Platform::poll()
keysym != XK_Escape &&
(uchar)(buf[0]) >= 32
) {
//debug("char: ", buf[0], " code: ", (uint)buf[0]);
//logDebug("char: ", buf[0], " code: ", (uint)buf[0]);
inputEvent.type = EV_TEXT_ENTER;
inputEvent.keychar = buf[0];
inputEvent.keycode = KC_UNKNOWN;
@@ -476,12 +476,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("FATAL ERROR: RGBA/Double buffered visual not supported");
logFatal("FATAL ERROR: RGBA/Double buffered visual not supported");
// create GLX context
x11.glxContext = glXCreateContext(x11.display, x11.visual, 0, GL_TRUE);
if(!x11.glxContext)
fatal("FATAL ERROR: Unable to create GLX context");
logFatal("FATAL ERROR: Unable to create GLX context");
// color map
x11.colormap = XCreateColormap(x11.display,
@@ -514,7 +514,7 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i
&wa);
if(!x11.window)
fatal("FATAL ERROR: Unable to create X window");
logFatal("FATAL ERROR: Unable to create X window");
// create input context (to have better key input handling)
if(XSupportsLocale()) {
@@ -526,14 +526,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("ERROR: Unable to create the input context");
logError("ERROR: Unable to create the input context");
} else
error("ERROR: Failed to open an input method");
logError("ERROR: Failed to open an input method");
} else
error("ERROR: X11 does not support the current locale");
logError("ERROR: 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
@@ -815,6 +815,6 @@ std::string 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("ERROR: Couldn't create directory for saving configuration file. (",sdir.str(),")");
logError("ERROR: Couldn't create directory for saving configuration file. (",sdir.str(),")");
return sdir.str();
}

View File

@@ -1,75 +0,0 @@
/* The MIT License
*
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef LUAFUNCTIONS_H
#define LUAFUNCTIONS_H
#include <global.h>
#include <script/scriptable.h>
void registerLuaFunctions();
// App
int lua_App_exit();
// UI
int lua_UI_load();
int lua_UI_getRootContainer();
// UIElement
int lua_UIElement_getId();
int lua_UIElement_setId();
int lua_UIElement_isEnabled();
int lua_UIElement_setEnabled();
int lua_UIElement_isVisible();
int lua_UIElement_setVisible();
int lua_UIElement_isFocused();
int lua_UIElement_setFocused();
int lua_UIElement_getParent();
int lua_UIElement_setParent();
int lua_UIElement_setLocked();
int lua_UIElement_destroy();
void lua_UIElement_onLoad();
void lua_UIElement_onDestroy();
// UIContainer
int lua_UIContainer_getChild();
int lua_UIContainer_getChildren();
// UILabel
int lua_UILabel_setText();
int lua_UILabel_getText();
// UITextEdit
int lua_UITextEdit_setText();
int lua_UITextEdit_getText();
// UIButton
void lua_UIButton_onClick();
// UIWindow
int lua_UIWindow_setTitle();
int lua_UIWindow_getTitle();
#endif // LUAFUNCTIONS_H

View File

@@ -12,7 +12,7 @@ void ScriptContext::init()
{
L = luaL_newstate();
if(!L)
fatal("FATAL ERROR: could not create lua context");
logFatal("FATAL ERROR: could not create lua context");
// load lua standard libraries
luaL_openlibs(L);
@@ -48,7 +48,7 @@ bool ScriptContext::loadFile(const std::string& fileName)
if(g_resources.loadFile(fileName, fin))
return loadBuffer(fin.str(), fileName);
else
error("ERROR: script file '", fileName, "' doesn't exist");
logError("ERROR: script file '", fileName, "' doesn't exist");
return false;
}
@@ -81,7 +81,7 @@ void ScriptContext::reportError(const std::string& errorDesc, const char *funcNa
if(funcName)
ss << " in " << funcName << "(): ";
ss << errorDesc;
error(ss.str());
logError(ss.str());
}
void ScriptContext::reportErrorWithTraceback(const std::string& errorDesc, const char* funcName)
@@ -385,7 +385,7 @@ std::string ScriptContext::getFunctionSourcePath(bool functionIsOnStack, int lev
if(source[0] == '@' && pos != std::string::npos)
path = source.substr(1, pos - 1);
} else {
error("no source");
logError("no source");
}
}
return path;

View File

@@ -38,19 +38,19 @@ bool UIAnchorLayout::addAnchor(const UIElementPtr& anchoredElement, AnchorPoint
UIElementPtr anchorLineElement = anchor.getAnchorLineElement();
if(!anchorLineElement) {
error("ERROR: could not find the element to anchor on, wrong id?");
logError("ERROR: could not find the element to anchor on, wrong id?");
return false;
}
// we can never anchor with itself
if(anchoredElement == anchorLineElement) {
error("ERROR: anchoring with itself is not possible");
logError("ERROR: anchoring with itself is not possible");
return false;
}
// we must never anchor to an anchor child
if(hasElementInAnchorTree(anchorLineElement, anchoredElement)) {
error("ERROR: anchors is miss configurated, you must never make anchor chains in loops");
logError("ERROR: anchors is miss configurated, you must never make anchor chains in loops");
return false;
}

View File

@@ -58,7 +58,7 @@ void UIElement::destroyCheck()
UIElementPtr me = asUIElement();
// check for leaks, the number of references must be always 2 here
if(me.use_count() != 2 && me != UIContainer::getRoot()) {
warning("destroyed element with id '",getId(),"', but it still have ",(me.use_count()-2)," references left");
logWarning("destroyed element with id '",getId(),"', but it still have ",(me.use_count()-2)," references left");
}
}
@@ -205,7 +205,7 @@ void UIElement::addAnchor(AnchorPoint anchoredEdge, AnchorLine anchorEdge)
{
UIElementPtr target = backwardsGetElementById(anchorEdge.getElementId());
if(!target)
warning("warning: element id '", anchorEdge.getElementId(), "' doesn't exist while anchoring element '", getId(), "'");
logWarning("warning: element id '", anchorEdge.getElementId(), "' doesn't exist while anchoring element '", getId(), "'");
UIAnchorLayoutPtr layout = boost::dynamic_pointer_cast<UIAnchorLayout>(getLayout());
if(layout)

View File

@@ -101,7 +101,6 @@ public:
/// Get layout size, it always return the absolute position
Rect getRect() const { return m_rect; }
// margins
void setMargin(int top, int right, int bottom, int left) { m_marginLeft = left; m_marginRight = right; m_marginTop = top; m_marginBottom = bottom; getLayout()->recalculateElementLayout(asUIElement()); }
void setMargin(int vertical, int horizontal) { m_marginLeft = m_marginRight = horizontal; m_marginTop = m_marginBottom = vertical; getLayout()->recalculateElementLayout(asUIElement()); }
void setMargin(int margin) { m_marginLeft = m_marginRight = m_marginTop = m_marginBottom = margin; getLayout()->recalculateElementLayout(asUIElement()); }
@@ -115,7 +114,6 @@ public:
int getMarginTop() const { return m_marginTop; }
int getMarginBottom() const { return m_marginBottom; }
// layout related
void centerIn(const std::string& targetId);
void addAnchor(AnchorPoint anchoredEdge, AnchorLine anchorEdge);

View File

@@ -34,7 +34,7 @@ ImagePtr UIElementSkin::loadImage(OTMLNode* node)
if(OTMLNode* cnode = node->at("bordered image")) {
image = BorderedImage::loadFromOTMLNode(cnode, g_uiSkins.getDefaultTexture());
if(!image)
error(node->generateErrorMessage("failed to load bordered image"));
logError(node->generateErrorMessage("failed to load bordered image"));
} else if(OTMLNode* cnode = node->at("image")) {
texture = g_textures.get(cnode->value());
if(texture)
@@ -43,7 +43,7 @@ ImagePtr UIElementSkin::loadImage(OTMLNode* node)
m_defaultSize = texture->getSize();
if(!image)
error(cnode->generateErrorMessage("failed to load image"));
logError(cnode->generateErrorMessage("failed to load image"));
}
if(texture) {

View File

@@ -67,7 +67,7 @@ UIElementPtr UILoader::loadFromFile(std::string filePath, const UIContainerPtr&
// create element interpreting it's id
element = createElementFromId(elementId);
if(!element) {
error(doc->front()->generateErrorMessage("invalid root element type"));
logError(doc->front()->generateErrorMessage("invalid root element type"));
return element;
}
parent->addChild(element);
@@ -82,7 +82,7 @@ UIElementPtr UILoader::loadFromFile(std::string filePath, const UIContainerPtr&
// report onLoad events
element->onLoad();
} catch(OTMLException e) {
error("ERROR: Failed to load ui ",filePath,": ", e.what());
logError("ERROR: Failed to load ui ",filePath,": ", e.what());
}
return element;
@@ -96,7 +96,7 @@ void UILoader::populateContainer(const UIContainerPtr& parent, OTMLNode* node)
if(id[0] == '%') {
UIElementPtr element = createElementFromId(id);
if(!element) {
error(cnode->generateErrorMessage("invalid element type"));
logError(cnode->generateErrorMessage("invalid element type"));
continue;
}
parent->addChild(element);
@@ -184,20 +184,20 @@ void UILoader::loadElementAnchor(const UIElementPtr& anchoredElement, AnchorPoin
std::string anchorDescription = node->value();
if(anchorDescription.empty()) {
error(node->generateErrorMessage("anchor is empty, did you forget to fill it?"));
logError(node->generateErrorMessage("anchor is empty, did you forget to fill it?"));
return;
}
UIAnchorLayoutPtr layout = boost::dynamic_pointer_cast<UIAnchorLayout>(anchoredElement->getLayout());
if(!layout) {
error(node->generateErrorMessage("could not add anchor, because this element does not participate of an anchor layout"));
logError(node->generateErrorMessage("could not add anchor, because this element does not participate of an anchor layout"));
return;
}
std::vector<std::string> split;
boost::split(split, anchorDescription, boost::is_any_of(std::string(".")));
if(split.size() != 2) {
error(node->generateErrorMessage("invalid anchor"));
logError(node->generateErrorMessage("invalid anchor"));
return;
}
@@ -205,12 +205,12 @@ void UILoader::loadElementAnchor(const UIElementPtr& anchoredElement, AnchorPoin
AnchorPoint anchorLineEdge = UIAnchorLayout::parseAnchorPoint(split[1]);
if(anchorLineEdge == AnchorNone) {
error(node->generateErrorMessage("invalid anchor type"));
logError(node->generateErrorMessage("invalid anchor type"));
return;
}
if(!layout->addAnchor(anchoredElement, anchoredEdge, AnchorLine(anchorLineElementId, anchorLineEdge)))
error(node->generateErrorMessage("anchoring failed"));
logError(node->generateErrorMessage("anchoring failed"));
}
void UILoader::loadElementScriptFunction(const UIElementPtr& element, OTMLNode* node)
@@ -225,7 +225,7 @@ void UILoader::loadElementScriptFunction(const UIElementPtr& element, OTMLNode*
if(g_lua.loadBufferAsFunction(node->value(), functionDesc))
g_lua.setScriptObjectField(element, node->tag());
else
error(node->generateErrorMessage("failed to parse inline lua script"));
logError(node->generateErrorMessage("failed to parse inline lua script"));
}
void UILoader::loadButton(const UIButtonPtr& button, OTMLNode* node)

View File

@@ -42,7 +42,7 @@ void UISkins::load(const std::string& skinName)
std::stringstream fin;
if(!g_resources.loadFile(skinName + ".otml", fin))
fatal("FATAL ERROR: Could not load skin '",skinName,"'");
logFatal("FATAL ERROR: Could not load skin '",skinName,"'");
try {
OTMLParser parser(fin, skinName);
@@ -50,7 +50,7 @@ void UISkins::load(const std::string& skinName)
m_defaultFont = g_fonts.get(doc->valueAt("default font"));
if(!m_defaultFont)
fatal("FATAL ERROR: Could not load skin default font");
logFatal("FATAL ERROR: Could not load skin default font");
m_defaultFontColor = doc->readAt("default font color", Color::white);
@@ -81,7 +81,7 @@ void UISkins::load(const std::string& skinName)
}
}
} catch(OTMLException e) {
fatal("FATAL ERROR: Malformed skin file '",skinName,"':\n ",e.what());
logFatal("FATAL ERROR: Malformed skin file '",skinName,"':\n ",e.what());
}
g_resources.popCurrentPath();
@@ -100,6 +100,6 @@ UIElementSkinPtr UISkins::getElementSkin(UI::ElementType elementType, const std:
if(elementType == skin->getElementType() && name == skin->getName())
return skin;
}
warning("Element skin '",name,"' not found");
logWarning("Element skin '",name,"' not found");
return UIElementSkinPtr();
}

View File

@@ -13,22 +13,21 @@ enum LogLevel {
void log(LogLevel level, const std::string& message, std::string prettyFunction = "");
// specialized logging
template<class... T>
void debug(const T&... args) { log(LogInfo, make_string(args...)); }
template<class... T>
void info(const T&... args) { log(LogDebug, make_string(args...)); }
template<class... T>
void warning(const T&... args) { log(LogWarning, make_string(args...)); }
template<class... T>
void error(const T&... args) { log(LogError, make_string(args...)); }
template<class... T>
void fatal(const T&... args) { log(LogFatal, make_string(args...)); }
#define logDebug(...) log(LogDebug, make_string(__VA_ARGS__))
#define logInfo(...) log(LogInfo, make_string(__VA_ARGS__))
#define logWarning(...) log(LogWarning, make_string(__VA_ARGS__))
#define logError(...) log(LogError, make_string(__VA_ARGS__))
#define logFatal(...) log(LogFatal, make_string(__VA_ARGS__))
#define trace() log(LogDebug, "", __PRETTY_FUNCTION__)
#define traceDebug(...) log(LogDebug, make_string(__VA_ARGS__), __PRETTY_FUNCTION__)
#define traceInfo(...) log(LogInfo, make_string(__VA_ARGS__), __PRETTY_FUNCTION__)
#define traceWarning(...) log(LogWarning, make_string(__VA_ARGS__), __PRETTY_FUNCTION__)
#define traceError(...) log(LogError, make_string(__VA_ARGS__), __PRETTY_FUNCTION__)
// dump utility
struct Dump {
~Dump() { debug(s.str().c_str()); }
~Dump() { logDebug(s.str().c_str()); }
template<class T>
Dump& operator<<(const T& v) { s << v << " "; return *this; }
std::ostringstream s;

View File

@@ -1,27 +1,3 @@
/* The MIT License
*
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <global.h>
#include <core/engine.h>
#include <core/configs.h>
@@ -86,7 +62,7 @@ int main(int argc, const char *argv[])
args.push_back(argv[i]);
#endif
info("OTClient 0.2.0");
logInfo("OTClient 0.2.0");
// install exit signal handler
signal(SIGTERM, signal_handler);
@@ -101,7 +77,7 @@ int main(int argc, const char *argv[])
// load configurations
loadDefaultConfigs();
if(!g_configs.load("config.otml"))
info("Could not read configuration file, default configurations will be used.");
logInfo("Could not read configuration file, default configurations will be used.");
// create the window
Platform::createWindow(g_configs.get("window x"), g_configs.get("window y"),

View File

@@ -1,26 +1,3 @@
/* The MIT License
*
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "protocollogin.h"
#include <net/outputmessage.h>
#include <net/rsa.h>
@@ -124,7 +101,7 @@ void ProtocolLogin::onRecv(InputMessage *inputMessage)
while(!inputMessage->end()) {
uint8 opt = inputMessage->getU8();
debug("opt:",(uint)opt);
logDebug("opt:",(uint)opt);
switch(opt) {
case 0x0A:
parseError(inputMessage);
@@ -165,8 +142,8 @@ void ProtocolLogin::parseCharacterList(InputMessage *inputMessage)
uint32 ip = inputMessage->getU32();
uint16 port = inputMessage->getU16();
debug("character: ", name.c_str(), world.c_str(), ip, port);
logDebug("character: ", name.c_str(), world.c_str(), ip, port);
}
uint16 premiumDays = inputMessage->getU16();
debug("prem days: ", premiumDays);
logDebug("prem days: ", premiumDays);
}