make framework more flexible, split cmake files

This commit is contained in:
Eduardo Bart 2011-12-05 04:44:03 -02:00
parent d2d8a0097a
commit ffeb34e0e7
26 changed files with 352 additions and 318 deletions

View File

@ -1,224 +1,35 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(otclient) PROJECT(otclient)
# setup custom cmake modules path INCLUDE(src/framework/CMakeLists.txt)
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") INCLUDE(src/otclient/CMakeLists.txt)
OPTION(USE_PCH "Use precompiled header" ON) OPTION(USE_PCH "Use precompiled header (speed up compile)" ON)
OPTION(NO_CONSOLE "Disable console window on Windows platform" OFF)
OPTION(HANDLE_EXCEPTIONS "Generate crash reports" OFF)
OPTION(FORBIDDEN_FUNCTIONS "Enable forbidden lua functions" ON)
OPTION(USE_OPENGLES2 "Use OpenGL ES 2.0 (for mobiles devices)" OFF)
# find needed packages SET(EXECUTABLE_SOURCES src/main.cpp)
SET(Boost_USE_STATIC_LIBS ON)
SET(Boost_USE_MULTITHREADED OFF)
FIND_PACKAGE(Boost COMPONENTS system REQUIRED)
IF(USE_OPENGLES2)
FIND_PACKAGE(OpenGLES2 REQUIRED)
FIND_PACKAGE(EGL REQUIRED)
SET(OPENGL_INCLUDE_DIR ${OPENGLES_INCLUDE_DIR} ${EGL_INCLUDE_DIR})
SET(OPENGL_LIBRARIES ${OPENGLES_LIBRARY} ${EGL_LIBRARY})
ADD_DEFINITIONS(-DOPENGLES2)
ELSE(USE_OPENGLES2)
FIND_PACKAGE(OpenGL REQUIRED)
ENDIF(USE_OPENGLES2)
FIND_PACKAGE(Lua REQUIRED)
FIND_PACKAGE(PhysFS REQUIRED)
FIND_PACKAGE(GMP REQUIRED)
FIND_PACKAGE(ZLIB REQUIRED)
FIND_PACKAGE(PCHSupport REQUIRED)
# choose a default build type if not specified
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug)
ENDIF(NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "BUILD TYPE: " ${CMAKE_BUILD_TYPE})
# setup compiler options
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable -Wno-switch -Wno-missing-field-initializers")
SET(CMAKE_CXX_FLAGS "-std=gnu++0x -pipe ${CXX_WARNS}")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -ggdb -fno-inline")
SET(CMAKE_CXX_LINK_FLAGS "-static-libgcc -static-libstdc++ -Wl,--as-needed")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
INCLUDE_DIRECTORIES(
${Boost_INCLUDE_DIRS}
${OPENGL_INCLUDE_DIR}
${LUA_INCLUDE_DIR}
${PHYSFS_INCLUDE_DIR}
${GMP_INCLUDE_DIR}
${ZLIB_INCLUDE_DIR}
"${CMAKE_CURRENT_SOURCE_DIR}/src"
)
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
ADD_DEFINITIONS(-D_DEBUG)
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(SOURCES
# main
src/main.cpp
# otclient
src/otclient/otclient.cpp
src/otclient/luafunctions.cpp
# otclient luascript
src/otclient/luascript/luavaluecasts.cpp
# otclient core
src/otclient/core/game.cpp
src/otclient/core/map.cpp
src/otclient/core/thingstype.cpp
src/otclient/core/spritemanager.cpp
src/otclient/core/item.cpp
src/otclient/core/tile.cpp
src/otclient/core/thing.cpp
src/otclient/core/creature.cpp
src/otclient/core/effect.cpp
src/otclient/core/missile.cpp
src/otclient/core/localplayer.cpp
src/otclient/core/outfit.cpp
# otclient ui
src/otclient/ui/uiitem.cpp
src/otclient/ui/uicreature.cpp
src/otclient/ui/uimap.cpp
src/otclient/ui/uigame.cpp
# otclient net
src/otclient/net/protocollogin.cpp
src/otclient/net/protocolgame.cpp
src/otclient/net/protocolgamesend.cpp
src/otclient/net/protocolgameparse.cpp
# framework
src/framework/application.cpp
src/framework/luafunctions.cpp
# framework third party
src/framework/thirdparty/apngloader.cpp
# framework net
src/framework/net/connection.cpp
src/framework/net/inputmessage.cpp
src/framework/net/outputmessage.cpp
src/framework/net/protocol.cpp
src/framework/net/rsa.cpp
src/framework/net/server.cpp
# framework core
src/framework/core/logger.cpp
src/framework/core/clock.cpp
src/framework/core/configmanager.cpp
src/framework/core/resourcemanager.cpp
src/framework/core/eventdispatcher.cpp
src/framework/core/modulemanager.cpp
src/framework/core/module.cpp
src/framework/core/clock.cpp
# framework platform
src/framework/platform/platformwindow.cpp
# framework graphics
src/framework/graphics/font.cpp
src/framework/graphics/fontmanager.cpp
src/framework/graphics/graphics.cpp
src/framework/graphics/texture.cpp
src/framework/graphics/framebuffer.cpp
src/framework/graphics/animatedtexture.cpp
src/framework/graphics/framebuffer.cpp
src/framework/graphics/texturemanager.cpp
src/framework/graphics/borderimage.cpp
src/framework/graphics/image.cpp
# framework otml
src/framework/otml/otmldocument.cpp
src/framework/otml/otmlemitter.cpp
src/framework/otml/otmlnode.cpp
src/framework/otml/otmlparser.cpp
src/framework/otml/otmlexception.cpp
# framework luascript
src/framework/luascript/luainterface.cpp
src/framework/luascript/luaobject.cpp
src/framework/luascript/luaexception.cpp
src/framework/luascript/luavaluecasts.cpp
# framework ui
src/framework/ui/uimanager.cpp
src/framework/ui/uiwidget.cpp
src/framework/ui/uilabel.cpp
src/framework/ui/uibutton.cpp
src/framework/ui/uilineedit.cpp
src/framework/ui/uiwindow.cpp
src/framework/ui/uianchorlayout.cpp
src/framework/ui/uiverticallayout.cpp
src/framework/ui/uilayout.cpp
src/framework/ui/uiprogressbar.cpp
src/framework/ui/uicheckbox.cpp
src/framework/ui/uiframecounter.cpp
src/framework/ui/uitranslator.cpp
)
IF(HANDLE_EXCEPTIONS)
ADD_DEFINITIONS(-DHANDLE_EXCEPTIONS)
ENDIF(HANDLE_EXCEPTIONS)
IF(FORBIDDEN_FUNCTIONS)
ADD_DEFINITIONS(-DFORBIDDEN_FUNCTIONS)
ENDIF(FORBIDDEN_FUNCTIONS)
# add executable icon for win32 platforms
IF(WIN32) IF(WIN32)
SET(SOURCES ${SOURCES} src/framework/platform/win32window.cpp) ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/otcicon.o
SET(ADDITIONAL_LIBRARIES ws2_32 mswsock)
IF(CMAKE_COMPILER_IS_GNUCXX)
ADD_DEFINITIONS(-D_WIN32_WINNT=0x0501)
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
IF(NO_CONSOLE)
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -mwindows")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
ENDIF(NO_CONSOLE)
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/icon.o
COMMAND ${CMAKE_RC_COMPILER} COMMAND ${CMAKE_RC_COMPILER}
-I${CMAKE_CURRENT_SOURCE_DIR}/src/otclient/win32icon -I${CMAKE_CURRENT_SOURCE_DIR}/src
-i${CMAKE_CURRENT_SOURCE_DIR}/src/otclient/win32icon/icon.rc -i${CMAKE_CURRENT_SOURCE_DIR}/src/otcicon.rc
-o ${CMAKE_CURRENT_BINARY_DIR}/icon.o) -o ${CMAKE_CURRENT_BINARY_DIR}/otcicon.o)
SET(SOURCES ${SOURCES} icon.o) SET(${EXECUTABLE_SOURCES} ${EXECUTABLE_SOURCES} otcicon.o)
ELSE(WIN32)
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -rdynamic")
SET(ADDITIONAL_LIBRARIES pthread)
SET(SOURCES ${SOURCES} src/framework/platform/x11window.cpp)
ENDIF(WIN32) ENDIF(WIN32)
# target executable # add otclient executable
ADD_EXECUTABLE(otclient ${SOURCES}) ADD_EXECUTABLE(otclient ${FRAMEWORK_SOURCES} ${OTCLIENT_SOURCES} ${EXECUTABLE_SOURCES})
# target link libraries # target link libraries
TARGET_LINK_LIBRARIES( TARGET_LINK_LIBRARIES(otclient ${FRAMEWORK_LIBRARIES})
otclient
${Boost_LIBRARIES}
${OPENGL_LIBRARIES}
${LUA_LIBRARIES}
${PHYSFS_LIBRARY}
${GMP_LIBRARY}
${ZLIB_LIBRARY}
${ADDITIONAL_LIBRARIES}
)
IF(USE_PCH) IF(USE_PCH)
FIND_PACKAGE(PCHSupport REQUIRED)
ADD_PRECOMPILED_HEADER(otclient ${CMAKE_CURRENT_SOURCE_DIR}/src/framework/pch.h) ADD_PRECOMPILED_HEADER(otclient ${CMAKE_CURRENT_SOURCE_DIR}/src/framework/pch.h)
MESSAGE(STATUS "Use precompiled header: ON")
ELSEIF(USE_PCH)
MESSAGE(STATUS "Use precompiled header: OFF")
ENDIF(USE_PCH) ENDIF(USE_PCH)
# installation # installation

View File

@ -6,11 +6,8 @@ function OTClient.init()
g_window.resize({ width=800, height=600 }) g_window.resize({ width=800, height=600 })
g_window.setTitle('OTClient') g_window.setTitle('OTClient')
g_window.setIcon('otcicon.png') g_window.setIcon('otcicon.png')
addEvent(g_window.show)
return true return true
end end
function OTClient.terminate() function OTClient.terminate()
g_window.hide()
end end

View File

@ -0,0 +1,176 @@
# add framework cmake modules
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake;${CMAKE_MODULE_PATH}")
MESSAGE(STATUS ${CMAKE_MODULE_PATH})
# framework options
OPTION(NO_CONSOLE "Disables console window on Windows platform" OFF)
OPTION(HANDLE_EXCEPTIONS "Generate crash reports" OFF)
OPTION(USE_OPENGL_ES2 "Use OpenGL ES 2.0 (for mobiles devices)" OFF)
# set debug as default build type
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug)
ENDIF(NOT CMAKE_BUILD_TYPE)
# find needed libraries
SET(Boost_USE_STATIC_LIBS ON)
SET(Boost_USE_MULTITHREADED OFF)
FIND_PACKAGE(Boost COMPONENTS system REQUIRED)
IF(USE_OPENGL_ES2)
FIND_PACKAGE(OpenGLES2 REQUIRED)
FIND_PACKAGE(EGL REQUIRED)
SET(OPENGL_INCLUDE_DIR ${OPENGLES_INCLUDE_DIR} ${EGL_INCLUDE_DIR})
SET(OPENGL_LIBRARIES ${OPENGLES_LIBRARY} ${EGL_LIBRARY})
ADD_DEFINITIONS(-DOPENGL_ES2)
ELSE(USE_OPENGL_ES2)
FIND_PACKAGE(OpenGL REQUIRED)
ENDIF(USE_OPENGL_ES2)
FIND_PACKAGE(Lua REQUIRED)
FIND_PACKAGE(PhysFS REQUIRED)
FIND_PACKAGE(GMP REQUIRED)
FIND_PACKAGE(ZLIB REQUIRED)
# setup compiler options
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable -Wno-switch -Wno-missing-field-initializers")
SET(CMAKE_CXX_FLAGS "-std=gnu++0x -pipe ${CXX_WARNS}")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -ggdb -fno-inline")
SET(CMAKE_CXX_LINK_FLAGS "-static-libgcc -static-libstdc++ -Wl,--as-needed")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
ADD_DEFINITIONS(-D_DEBUG)
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
IF(USE_OPENGL_ES2)
MESSAGE(STATUS "Renderer: OpenGL ES 2")
ELSE(USE_OPENGL_ES2)
MESSAGE(STATUS "Renderer: OpenGL")
ENDIF(USE_OPENGL_ES2)
IF(HANDLE_EXCEPTIONS)
ADD_DEFINITIONS(-DHANDLE_EXCEPTIONS)
MESSAGE(STATUS "Generate crash reports: ON")
ELSE(HANDLE_EXCEPTIONS)
MESSAGE(STATUS "Generate crash reports: OFF")
ENDIF(HANDLE_EXCEPTIONS)
IF(WIN32)
SET(FRAMEWORK_SOURCES ${FRAMEWORK_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/platform/win32window.cpp)
SET(ADDITIONAL_LIBRARIES ws2_32 mswsock)
IF(CMAKE_COMPILER_IS_GNUCXX)
ADD_DEFINITIONS(-D_WIN32_WINNT=0x0501)
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
IF(NO_CONSOLE)
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -mwindows")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
MESSAGE(STATUS "Disable windows console: ON")
ELSE(NO_CONSOLE)
MESSAGE(STATUS "Disable windows console: OFF")
ENDIF(NO_CONSOLE)
ELSE(WIN32)
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -rdynamic")
SET(ADDITIONAL_LIBRARIES pthread)
SET(FRAMEWORK_SOURCES ${FRAMEWORK_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp)
ENDIF(WIN32)
INCLUDE_DIRECTORIES(
${Boost_INCLUDE_DIRS}
${OPENGL_INCLUDE_DIR}
${LUA_INCLUDE_DIR}
${PHYSFS_INCLUDE_DIR}
${GMP_INCLUDE_DIR}
${ZLIB_INCLUDE_DIR}
"${CMAKE_CURRENT_LIST_DIR}/.."
)
SET(FRAMEWORK_LIBRARIES
${Boost_LIBRARIES}
${OPENGL_LIBRARIES}
${LUA_LIBRARIES}
${PHYSFS_LIBRARY}
${GMP_LIBRARY}
${ZLIB_LIBRARY}
${ADDITIONAL_LIBRARIES}
)
SET(FRAMEWORK_SOURCES ${FRAMEWORK_SOURCES}
# framework
${CMAKE_CURRENT_LIST_DIR}/application.cpp
${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp
# framework core
${CMAKE_CURRENT_LIST_DIR}/core/logger.cpp
${CMAKE_CURRENT_LIST_DIR}/core/clock.cpp
${CMAKE_CURRENT_LIST_DIR}/core/configmanager.cpp
${CMAKE_CURRENT_LIST_DIR}/core/resourcemanager.cpp
${CMAKE_CURRENT_LIST_DIR}/core/eventdispatcher.cpp
${CMAKE_CURRENT_LIST_DIR}/core/modulemanager.cpp
${CMAKE_CURRENT_LIST_DIR}/core/module.cpp
${CMAKE_CURRENT_LIST_DIR}/core/clock.cpp
# framework net
${CMAKE_CURRENT_LIST_DIR}/net/connection.cpp
${CMAKE_CURRENT_LIST_DIR}/net/inputmessage.cpp
${CMAKE_CURRENT_LIST_DIR}/net/outputmessage.cpp
${CMAKE_CURRENT_LIST_DIR}/net/protocol.cpp
${CMAKE_CURRENT_LIST_DIR}/net/rsa.cpp
${CMAKE_CURRENT_LIST_DIR}/net/server.cpp
# framework platform
${CMAKE_CURRENT_LIST_DIR}/platform/platformwindow.cpp
# framework graphics
${CMAKE_CURRENT_LIST_DIR}/graphics/font.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/fontmanager.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/graphics.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/texture.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/framebuffer.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/animatedtexture.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/framebuffer.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/texturemanager.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/borderimage.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/image.cpp
# framework otml
${CMAKE_CURRENT_LIST_DIR}/otml/otmldocument.cpp
${CMAKE_CURRENT_LIST_DIR}/otml/otmlemitter.cpp
${CMAKE_CURRENT_LIST_DIR}/otml/otmlnode.cpp
${CMAKE_CURRENT_LIST_DIR}/otml/otmlparser.cpp
${CMAKE_CURRENT_LIST_DIR}/otml/otmlexception.cpp
# framework luascript
${CMAKE_CURRENT_LIST_DIR}/luascript/luainterface.cpp
${CMAKE_CURRENT_LIST_DIR}/luascript/luaobject.cpp
${CMAKE_CURRENT_LIST_DIR}/luascript/luaexception.cpp
${CMAKE_CURRENT_LIST_DIR}/luascript/luavaluecasts.cpp
# framework ui
${CMAKE_CURRENT_LIST_DIR}/ui/uimanager.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uiwidget.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uilabel.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uibutton.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uilineedit.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uiwindow.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uianchorlayout.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uiverticallayout.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uilayout.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uiprogressbar.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uicheckbox.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uiframecounter.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uitranslator.cpp
# framework third party
${CMAKE_CURRENT_LIST_DIR}/thirdparty/apngloader.cpp
)

View File

@ -33,6 +33,8 @@
#include <framework/graphics/graphics.h> #include <framework/graphics/graphics.h>
#include <framework/luascript/luainterface.h> #include <framework/luascript/luainterface.h>
Application *g_app = nullptr;
void exitSignalHandler(int sig) void exitSignalHandler(int sig)
{ {
static bool signaled = false; static bool signaled = false;
@ -41,18 +43,28 @@ void exitSignalHandler(int sig)
case SIGINT: case SIGINT:
if(!signaled) { if(!signaled) {
signaled = true; signaled = true;
g_dispatcher.addEvent(std::bind(&Application::close, &g_app)); g_dispatcher.addEvent(std::bind(&Application::close, g_app));
} }
break; break;
} }
} }
void Application::init(const std::string& appName, const std::vector<std::string>& args) Application::Application(const std::string& appName)
{ {
logInfo("Starting application..."); g_app = this;
m_pollCycleDelay = POLL_CYCLE_DELAY;
m_appName = appName; m_appName = appName;
m_pollCycleDelay = POLL_CYCLE_DELAY;
}
Application::~Application()
{
g_app = nullptr;
}
void Application::init(const std::vector<std::string>& args, int appFlags)
{
m_appFlags = appFlags;
logInfo("Starting application...");
// capture exit signals // capture exit signals
signal(SIGTERM, exitSignalHandler); signal(SIGTERM, exitSignalHandler);
@ -65,14 +77,20 @@ void Application::init(const std::string& appName, const std::vector<std::string
// initialize resources // initialize resources
g_resources.init(args[0].c_str()); g_resources.init(args[0].c_str());
// loads user configuration if(m_appFlags & Fw::AppEnableConfigs) {
// setup configs write directory
if(!g_resources.setupWriteDir(m_appName))
logError("Could not setup write directory");
// load configs
if(!g_configs.load("config.otml")) if(!g_configs.load("config.otml"))
logInfo("Using default configurations."); logInfo("Using default configurations.");
}
// initialize the ui
g_ui.init();
// setup platform window // setup platform window
if(m_appFlags & Fw::AppEnableGraphics) {
g_ui.init();
g_window.init(); g_window.init();
g_window.setOnResize(std::bind(&Application::resize, this, _1)); g_window.setOnResize(std::bind(&Application::resize, this, _1));
g_window.setOnInputEvent(std::bind(&Application::inputEvent, this, _1)); g_window.setOnInputEvent(std::bind(&Application::inputEvent, this, _1));
@ -83,18 +101,46 @@ void Application::init(const std::string& appName, const std::vector<std::string
// fire first resize // fire first resize
resize(g_window.getSize()); resize(g_window.getSize());
}
if(m_appFlags & Fw::AppEnableModules) {
// search for modules directory
std::string baseDir = g_resources.getBaseDir();
std::string possibleDirs[] = { "modules",
baseDir + "modules",
baseDir + "../modules",
baseDir + "../share/" + m_appName + "/modules",
"" };
bool found = false;
for(const std::string& dir : possibleDirs) {
// try to add module directory
if(g_resources.addToSearchPath(dir)) {
logInfo("Using modules directory '", dir.c_str(), "'");
found = true;
break;
}
}
if(!found)
logFatal("Could not find modules directory");
// auto load lua modules
g_modules.discoverAndLoadModules(); g_modules.discoverAndLoadModules();
}
// finally show the window
if(m_appFlags & Fw::AppEnableGraphics)
g_window.show();
} }
void Application::terminate() void Application::terminate()
{ {
// hide the window because there is no render anymore // hide the window because there is no render anymore
if(m_appFlags & Fw::AppEnableGraphics)
g_window.hide(); g_window.hide();
// run modules unload events // run modules unload events
if(m_appFlags & Fw::AppEnableModules)
g_modules.unloadModules(); g_modules.unloadModules();
// release remaining lua object references // release remaining lua object references
@ -103,19 +149,21 @@ void Application::terminate()
// poll remaining events // poll remaining events
poll(); poll();
// terminate ui
g_ui.terminate();
// terminate network // terminate network
Connection::terminate(); Connection::terminate();
// terminate graphics
if(m_appFlags & Fw::AppEnableGraphics) {
g_ui.terminate();
g_graphics.terminate();
g_window.terminate();
}
// flush remaining dispatcher events // flush remaining dispatcher events
g_dispatcher.flush(); g_dispatcher.flush();
// terminate graphics
g_graphics.terminate();
// save configurations // save configurations
if(m_appFlags & Fw::AppEnableConfigs)
g_configs.save(); g_configs.save();
// release resources // release resources
@ -124,9 +172,6 @@ void Application::terminate()
// terminate script environment // terminate script environment
g_lua.terminate(); g_lua.terminate();
// release platform window
g_window.terminate();
logInfo("Application ended successfully."); logInfo("Application ended successfully.");
} }
@ -139,11 +184,6 @@ void Application::run()
// run the first poll // run the first poll
poll(); poll();
if(g_ui.getRootWidget()->getChildCount() == 0) {
logError("There is no root widgets to display, the app will close");
m_stopping = true;
}
while(!m_stopping) { while(!m_stopping) {
g_clock.updateTicks(); g_clock.updateTicks();
@ -154,7 +194,7 @@ void Application::run()
lastPollTicks = g_clock.ticks(); lastPollTicks = g_clock.ticks();
} }
if(g_window.isVisible()) { if(m_appFlags & Fw::AppEnableGraphics && g_window.isVisible()) {
g_graphics.beginRender(); g_graphics.beginRender();
render(); render();
g_graphics.endRender(); g_graphics.endRender();
@ -180,6 +220,7 @@ void Application::exit()
void Application::poll() void Application::poll()
{ {
// poll input events // poll input events
if(m_appFlags & Fw::AppEnableGraphics)
g_window.poll(); g_window.poll();
// poll network events // poll network events

View File

@ -32,7 +32,10 @@ class Application
}; };
public: public:
virtual void init(const std::string& appName, const std::vector<std::string>& args); Application(const std::string& appName);
~Application();
virtual void init(const std::vector<std::string>& args, int appFlags);
virtual void registerLuaFunctions(); virtual void registerLuaFunctions();
virtual void terminate(); virtual void terminate();
virtual void run(); virtual void run();
@ -53,12 +56,13 @@ protected:
private: private:
std::string m_appName; std::string m_appName;
int m_appFlags;
int m_pollCycleDelay; int m_pollCycleDelay;
Boolean<false> m_running; Boolean<false> m_running;
Boolean<false> m_stopping; Boolean<false> m_stopping;
}; };
extern Application& g_app; extern Application *g_app;
#endif #endif

View File

@ -271,6 +271,13 @@ namespace Fw
//LastState, //LastState,
//AlternateState //AlternateState
}; };
enum AppicationFlags {
AppEnableModules = 1,
AppEnableGraphics = 2,
AppEnableConfigs = 4,
AppEnableAll = AppEnableModules | AppEnableGraphics | AppEnableConfigs
};
} }
#endif #endif

View File

@ -32,31 +32,6 @@ ResourceManager g_resources;
void ResourceManager::init(const char *argv0) void ResourceManager::init(const char *argv0)
{ {
PHYSFS_init(argv0); PHYSFS_init(argv0);
// setup write directory
if(!g_resources.setupWriteDir())
logError("Could not setup write directory");
// try to find modules directory, all data lives there
//TODO: move this to Application class
std::string baseDir = PHYSFS_getBaseDir();
std::string possibleDirs[] = { "modules",
baseDir + "modules",
baseDir + "../modules",
baseDir + "../share/" + g_app.getAppName() + "/otclient/modules",
"" };
bool found = false;
for(const std::string& dir : possibleDirs) {
if(g_resources.addToSearchPath(dir)) {
logInfo("Using modules directory '", dir.c_str(), "'");
found = true;
break;
}
}
if(!found)
logFatal("Could not find modules directory");
} }
void ResourceManager::terminate() void ResourceManager::terminate()
@ -64,10 +39,10 @@ void ResourceManager::terminate()
PHYSFS_deinit(); PHYSFS_deinit();
} }
bool ResourceManager::setupWriteDir() bool ResourceManager::setupWriteDir(const std::string& appWriteDirName)
{ {
std::string userDir = PHYSFS_getUserDir(); std::string userDir = PHYSFS_getUserDir();
std::string dirName = Fw::mkstr(".", g_app.getAppName()); std::string dirName = Fw::mkstr(".", appWriteDirName);
std::string writeDir = userDir + dirName; std::string writeDir = userDir + dirName;
if(!PHYSFS_setWriteDir(writeDir.c_str())) { if(!PHYSFS_setWriteDir(writeDir.c_str())) {
if(!PHYSFS_setWriteDir(userDir.c_str())) if(!PHYSFS_setWriteDir(userDir.c_str()))
@ -196,3 +171,9 @@ std::string ResourceManager::resolvePath(const std::string& path)
} }
return fullPath; return fullPath;
} }
std::string ResourceManager::getBaseDir()
{
return PHYSFS_getBaseDir();
}

View File

@ -31,7 +31,7 @@ public:
void init(const char *argv0); void init(const char *argv0);
void terminate(); void terminate();
bool setupWriteDir(); bool setupWriteDir(const std::string& appWriteDirName);
/// Add an package or directory to the search path /// Add an package or directory to the search path
bool addToSearchPath(const std::string& path, bool insertInFront = true); bool addToSearchPath(const std::string& path, bool insertInFront = true);
@ -54,7 +54,7 @@ public:
std::list<std::string> listDirectoryFiles(const std::string& directoryPath = ""); std::list<std::string> listDirectoryFiles(const std::string& directoryPath = "");
std::string resolvePath(const std::string& path); std::string resolvePath(const std::string& path);
std::string getAppUserPath(); std::string getBaseDir();
}; };
extern ResourceManager g_resources; extern ResourceManager g_resources;

View File

@ -25,8 +25,9 @@
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
{ {
std::vector<std::string> args(argv, argv + argc); std::vector<std::string> args(argv, argv + argc);
g_otclient.init(args); OTClient otclient;
g_otclient.run(); otclient.init(args);
g_otclient.terminate(); otclient.run();
otclient.terminate();
return 0; return 0;
} }

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

1
src/otcicon.rc Normal file
View File

@ -0,0 +1 @@
IDI_ICON1 ICON DISCARDABLE "otcicon.ico"

View File

@ -0,0 +1,44 @@
# otclient options
OPTION(FORBIDDEN_FUNCTIONS "Enable forbidden lua functions" ON)
IF(FORBIDDEN_FUNCTIONS)
ADD_DEFINITIONS(-DFORBIDDEN_FUNCTIONS)
MESSAGE(STATUS "Lua forbidden functions: ON")
ELSE(FORBIDDEN_FUNCTIONS)
MESSAGE(STATUS "Lua forbidden functions: OFF")
ENDIF(FORBIDDEN_FUNCTIONS)
SET(OTCLIENT_SOURCES ${OTCLIENT_SOURCES}
# otclient
${CMAKE_CURRENT_LIST_DIR}/otclient.cpp
${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp
# otclient luascript
${CMAKE_CURRENT_LIST_DIR}/luascript/luavaluecasts.cpp
# otclient core
${CMAKE_CURRENT_LIST_DIR}/core/game.cpp
${CMAKE_CURRENT_LIST_DIR}/core/map.cpp
${CMAKE_CURRENT_LIST_DIR}/core/thingstype.cpp
${CMAKE_CURRENT_LIST_DIR}/core/spritemanager.cpp
${CMAKE_CURRENT_LIST_DIR}/core/item.cpp
${CMAKE_CURRENT_LIST_DIR}/core/tile.cpp
${CMAKE_CURRENT_LIST_DIR}/core/thing.cpp
${CMAKE_CURRENT_LIST_DIR}/core/creature.cpp
${CMAKE_CURRENT_LIST_DIR}/core/effect.cpp
${CMAKE_CURRENT_LIST_DIR}/core/missile.cpp
${CMAKE_CURRENT_LIST_DIR}/core/localplayer.cpp
${CMAKE_CURRENT_LIST_DIR}/core/outfit.cpp
# otclient ui
${CMAKE_CURRENT_LIST_DIR}/ui/uiitem.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uicreature.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uimap.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uigame.cpp
# otclient net
${CMAKE_CURRENT_LIST_DIR}/net/protocollogin.cpp
${CMAKE_CURRENT_LIST_DIR}/net/protocolgame.cpp
${CMAKE_CURRENT_LIST_DIR}/net/protocolgamesend.cpp
${CMAKE_CURRENT_LIST_DIR}/net/protocolgameparse.cpp
)

View File

@ -22,7 +22,7 @@ void OTClient::registerLuaFunctions()
{ {
Application::registerLuaFunctions(); Application::registerLuaFunctions();
g_lua.bindGlobalFunction("exit", std::bind(&Application::exit, &g_app)); g_lua.bindGlobalFunction("exit", std::bind(&Application::exit, g_app));
g_lua.bindGlobalFunction("importDat", std::bind(&ThingsType::load, &g_thingsType, _1)); g_lua.bindGlobalFunction("importDat", std::bind(&ThingsType::load, &g_thingsType, _1));
g_lua.bindGlobalFunction("importSpr", std::bind(&SpriteManager::load, &g_sprites, _1)); g_lua.bindGlobalFunction("importSpr", std::bind(&SpriteManager::load, &g_sprites, _1));
g_lua.bindGlobalFunction("getOufitColor", Outfit::getColor); g_lua.bindGlobalFunction("getOufitColor", Outfit::getColor);

View File

@ -22,11 +22,13 @@
#include "otclient.h" #include "otclient.h"
OTClient g_otclient; OTClient::OTClient() : Application(Otc::AppCompactName)
Application& g_app = g_otclient; {
}
void OTClient::init(const std::vector<std::string>& args) void OTClient::init(const std::vector<std::string>& args)
{ {
logInfo(Otc::AppName, " ", Otc::AppVersion); logInfo(Otc::AppName, " ", Otc::AppVersion);
Application::init(Otc::AppCompactName, args); Application::init(args, Fw::AppEnableAll);
} }

View File

@ -29,10 +29,9 @@
class OTClient : public Application class OTClient : public Application
{ {
public: public:
OTClient();
void init(const std::vector<std::string>& args); void init(const std::vector<std::string>& args);
void registerLuaFunctions(); void registerLuaFunctions();
}; };
extern OTClient g_otclient;
#endif #endif

View File

@ -1 +0,0 @@
IDI_ICON1 ICON DISCARDABLE "icon.ico"

View File

@ -1,29 +0,0 @@
/*
* Copyright (c) 2010-2011 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 PCH_H
#define PCH_H
#include "framework/global.h"
#include "otclient/global.h"
#endif