From 571801ae3904b8efbd1204a312628dc7815474c8 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sat, 16 Jul 2011 21:13:53 -0300 Subject: [PATCH] some refactoring --- CMakeLists.txt | 9 +- src/framework/constants.h | 46 ---- src/framework/core/configs.cpp | 31 +-- src/framework/core/configs.h | 24 -- src/framework/core/dispatcher.cpp | 29 +-- src/framework/core/dispatcher.h | 36 +-- src/framework/core/engine.cpp | 39 +--- src/framework/core/engine.h | 26 +-- src/framework/core/global.cpp | 25 -- src/framework/core/input.h | 27 +-- src/framework/core/modules.cpp | 24 -- src/framework/core/modules.h | 24 -- src/framework/core/platform.h | 24 -- src/framework/core/resources.cpp | 29 +-- src/framework/core/resources.h | 24 -- src/framework/global.h | 2 +- src/framework/graphics/borderedimage.cpp | 94 +++++--- src/framework/graphics/borderedimage.h | 29 +-- src/framework/graphics/font.cpp | 2 +- src/framework/graphics/fonts.cpp | 4 +- src/framework/net/protocol.h | 6 +- src/framework/otml/otml.h | 1 - src/framework/otml/otmlnode.h | 2 +- src/framework/otml/otmlparser.h | 4 +- src/framework/platform/x11platform.cpp | 24 -- src/framework/prerequisites.h | 95 -------- src/framework/script/scriptable.cpp | 78 ------- src/framework/script/scriptable.h | 49 ---- .../{luascript.cpp => scriptcontext.cpp} | 216 ++++++++---------- .../script/{luascript.h => scriptcontext.h} | 46 +--- .../{luafunctions.cpp => scriptfunctions.cpp} | 32 +-- src/framework/script/scriptfunctions.h | 52 +++++ src/framework/script/scriptobject.cpp | 54 +++++ src/framework/script/scriptobject.h | 26 +++ src/framework/ui/uianchorlayout.cpp | 24 -- src/framework/ui/uianchorlayout.h | 24 -- src/framework/ui/uibutton.cpp | 26 +-- src/framework/ui/uibutton.h | 28 +-- src/framework/ui/uibuttonskin.cpp | 71 ++---- src/framework/ui/uibuttonskin.h | 39 +--- src/framework/ui/uicheckbox.cpp | 24 -- src/framework/ui/uicheckbox.h | 26 +-- src/framework/ui/uicheckboxskin.cpp | 24 -- src/framework/ui/uicheckboxskin.h | 24 -- src/framework/ui/uiconstants.h | 34 +-- src/framework/ui/uicontainer.cpp | 24 -- src/framework/ui/uicontainer.h | 26 +-- src/framework/ui/uielement.cpp | 32 +-- src/framework/ui/uielement.h | 30 +-- src/framework/ui/uielementskin.cpp | 54 +---- src/framework/ui/uielementskin.h | 24 -- src/framework/ui/uilabel.cpp | 24 -- src/framework/ui/uilabel.h | 26 +-- src/framework/ui/uilabelskin.cpp | 24 -- src/framework/ui/uilabelskin.h | 24 -- src/framework/ui/uilayout.h | 24 -- src/framework/ui/uiloader.cpp | 35 +-- src/framework/ui/uiskins.cpp | 2 +- src/framework/ui/uitextedit.h | 2 +- src/framework/ui/uiwindow.h | 2 +- src/framework/{core => util}/allocator.cpp | 24 -- src/framework/{core => util}/allocator.h | 24 -- src/framework/util/logger.cpp | 33 +-- src/framework/util/logger.h | 4 +- src/framework/util/translator.cpp | 1 - src/framework/util/translator.h | 1 - src/framework/util/util.h | 52 ----- src/main.cpp | 7 +- src/protocollogin.cpp | 6 +- src/protocollogin.h | 2 +- 70 files changed, 430 insertions(+), 1654 deletions(-) delete mode 100644 src/framework/constants.h delete mode 100644 src/framework/core/global.cpp delete mode 100644 src/framework/prerequisites.h delete mode 100644 src/framework/script/scriptable.cpp delete mode 100644 src/framework/script/scriptable.h rename src/framework/script/{luascript.cpp => scriptcontext.cpp} (69%) rename src/framework/script/{luascript.h => scriptcontext.h} (67%) rename src/framework/script/{luafunctions.cpp => scriptfunctions.cpp} (86%) create mode 100644 src/framework/script/scriptfunctions.h create mode 100644 src/framework/script/scriptobject.cpp create mode 100644 src/framework/script/scriptobject.h rename src/framework/{core => util}/allocator.cpp (88%) rename src/framework/{core => util}/allocator.h (64%) delete mode 100644 src/framework/util/util.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e142a4d..ec528b12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,13 +52,11 @@ SET(SOURCES src/protocollogin.cpp # framework core - src/framework/core/global.cpp src/framework/core/dispatcher.cpp src/framework/core/configs.cpp src/framework/core/resources.cpp src/framework/core/engine.cpp src/framework/core/modules.cpp - src/framework/core/allocator.cpp # framework otml src/framework/otml/otmlemitter.cpp @@ -66,9 +64,9 @@ SET(SOURCES src/framework/otml/otmlnode.cpp # framework script - src/framework/script/scriptable.cpp - src/framework/script/luascript.cpp - src/framework/script/luafunctions.cpp + src/framework/script/scriptobject.cpp + src/framework/script/scriptcontext.cpp + src/framework/script/scriptfunctions.cpp # framework utilities src/framework/util/color.cpp @@ -76,6 +74,7 @@ SET(SOURCES src/framework/util/convert.cpp src/framework/util/logger.cpp src/framework/util/apngloader.cpp + src/framework/util/allocator.cpp # framework graphics src/framework/graphics/image.cpp diff --git a/src/framework/constants.h b/src/framework/constants.h deleted file mode 100644 index 77b46f37..00000000 --- a/src/framework/constants.h +++ /dev/null @@ -1,46 +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 CONSTANTS_H -#define CONSTANTS_H - -enum AlignmentFlag { - AlignLeft = 1, - AlignRight = 2, - AlignTop = 4, - AlignBottom = 8, - AlignHorizontalCenter = 16, - AlignVerticalCenter = 32, - AlignTopLeft = AlignTop | AlignLeft, - AlignTopRight = AlignTop | AlignRight, - AlignBottomLeft = AlignBottom | AlignLeft, - AlignBottomRight = AlignBottom | AlignRight, - AlignLeftCenter = AlignLeft | AlignVerticalCenter, - AlignRightCenter = AlignRight | AlignVerticalCenter, - AlignTopCenter = AlignTop | AlignHorizontalCenter, - AlignBottomCenter = AlignBottom | AlignHorizontalCenter, - AlignCenter = AlignVerticalCenter | AlignHorizontalCenter -}; - -#endif // CONSTANTS_H diff --git a/src/framework/core/configs.cpp b/src/framework/core/configs.cpp index 591388cf..9f6bc713 100644 --- a/src/framework/core/configs.cpp +++ b/src/framework/core/configs.cpp @@ -1,30 +1,6 @@ -/* 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 -#include -#include +#include "configs.h" +#include "resources.h" + #include Configs g_configs; @@ -59,4 +35,3 @@ void Configs::save() g_resources.saveFile(m_fileName, emitter.emitDocument()); } } - diff --git a/src/framework/core/configs.h b/src/framework/core/configs.h index 048b0629..56164077 100644 --- a/src/framework/core/configs.h +++ b/src/framework/core/configs.h @@ -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. - */ - - #ifndef CONFIGS_H #define CONFIGS_H diff --git a/src/framework/core/dispatcher.cpp b/src/framework/core/dispatcher.cpp index 02b09c08..ed74ad22 100644 --- a/src/framework/core/dispatcher.cpp +++ b/src/framework/core/dispatcher.cpp @@ -1,30 +1,5 @@ -/* 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 -#include -#include +#include "dispatcher.h" +#include "engine.h" Dispatcher g_dispatcher; diff --git a/src/framework/core/dispatcher.h b/src/framework/core/dispatcher.h index 92c45953..49bb6167 100644 --- a/src/framework/core/dispatcher.h +++ b/src/framework/core/dispatcher.h @@ -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. - */ - - #ifndef DISPATCHER_H #define DISPATCHER_H @@ -31,17 +7,15 @@ #include #include -class ScheduledTask { -public: - inline ScheduledTask(const boost::function& _callback) : ticks(0), callback(_callback) { } - inline ScheduledTask(int _ticks, const boost::function& _callback) : ticks(_ticks), callback(_callback) { } - inline bool operator<(const ScheduledTask& other) const { return ticks > other.ticks; } +struct ScheduledTask { + ScheduledTask(const boost::function& _callback) : ticks(0), callback(_callback) { } + ScheduledTask(int _ticks, const boost::function& _callback) : ticks(_ticks), callback(_callback) { } + bool operator<(const ScheduledTask& other) const { return ticks > other.ticks; } int ticks; boost::function callback; }; -class lessScheduledTask : public std::binary_function { -public: +struct lessScheduledTask : public std::binary_function { bool operator()(ScheduledTask*& t1,ScheduledTask*& t2) { return (*t1) < (*t2); } }; diff --git a/src/framework/core/engine.cpp b/src/framework/core/engine.cpp index 508b31c4..b53a9e24 100644 --- a/src/framework/core/engine.cpp +++ b/src/framework/core/engine.cpp @@ -1,38 +1,13 @@ -/* 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 -#include -#include -#include +#include "engine.h" +#include "platform.h" +#include "dispatcher.h" #include #include +#include #include -#include -#include