mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 03:54:54 +02:00
reorganize modules
This commit is contained in:
@@ -62,7 +62,7 @@ ENDIF(HANDLE_EXCEPTIONS)
|
||||
|
||||
|
||||
IF(WIN32)
|
||||
SET(FRAMEWORK_SOURCES ${FRAMEWORK_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/platform/win32window.cpp)
|
||||
SET(framework_SOURCES ${framework_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/platform/win32window.cpp)
|
||||
SET(ADDITIONAL_LIBRARIES ws2_32 mswsock)
|
||||
|
||||
IF(CMAKE_COMPILER_IS_GNUCXX)
|
||||
@@ -80,7 +80,7 @@ IF(WIN32)
|
||||
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)
|
||||
SET(framework_SOURCES ${framework_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp)
|
||||
ENDIF(WIN32)
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ INCLUDE_DIRECTORIES(
|
||||
"${CMAKE_CURRENT_LIST_DIR}/.."
|
||||
)
|
||||
|
||||
SET(FRAMEWORK_LIBRARIES
|
||||
SET(framework_LIBRARIES
|
||||
${Boost_LIBRARIES}
|
||||
${OPENGL_LIBRARIES}
|
||||
${LUA_LIBRARIES}
|
||||
@@ -105,7 +105,7 @@ SET(FRAMEWORK_LIBRARIES
|
||||
)
|
||||
|
||||
|
||||
SET(FRAMEWORK_SOURCES ${FRAMEWORK_SOURCES}
|
||||
SET(framework_SOURCES ${framework_SOURCES}
|
||||
# framework
|
||||
${CMAKE_CURRENT_LIST_DIR}/application.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp
|
||||
|
@@ -103,33 +103,12 @@ void Application::init(const std::vector<std::string>& args, int appFlags)
|
||||
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");
|
||||
|
||||
g_modules.discoverAndLoadModules();
|
||||
}
|
||||
|
||||
// finally show the window
|
||||
if(m_appFlags & Fw::AppEnableGraphics)
|
||||
g_window.show();
|
||||
|
||||
if(m_appFlags & Fw::AppEnableModules)
|
||||
g_modules.discoverModulesPath();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -54,7 +54,6 @@ protected:
|
||||
virtual void resize(const Size& size);
|
||||
virtual void inputEvent(const InputEvent& event);
|
||||
|
||||
private:
|
||||
std::string m_appName;
|
||||
int m_appFlags;
|
||||
int m_pollCycleDelay;
|
||||
|
@@ -24,13 +24,12 @@
|
||||
#include "resourcemanager.h"
|
||||
|
||||
#include <framework/otml/otml.h>
|
||||
#include <framework/application.h>
|
||||
|
||||
ModuleManager g_modules;
|
||||
|
||||
void ModuleManager::discoverAndLoadModules()
|
||||
void ModuleManager::discoverModules()
|
||||
{
|
||||
std::multimap<int, ModulePtr> m_autoLoadModules;
|
||||
|
||||
auto moduleDirs = g_resources.listDirectoryFiles("/");
|
||||
for(const std::string& moduleDir : moduleDirs) {
|
||||
auto moduleFiles = g_resources.listDirectoryFiles("/" + moduleDir);
|
||||
@@ -42,14 +41,42 @@ void ModuleManager::discoverAndLoadModules()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleManager::autoLoadModules(int maxPriority)
|
||||
{
|
||||
for(auto& pair : m_autoLoadModules) {
|
||||
int priority = pair.first;
|
||||
if(priority > maxPriority)
|
||||
break;
|
||||
ModulePtr module = pair.second;
|
||||
if(!module->isLoaded() && !module->load())
|
||||
logFatal("A required module has failed to load, cannot continue to run.");
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleManager::discoverModulesPath()
|
||||
{
|
||||
// search for modules directory
|
||||
std::string possibleDirs[] = { "modules",
|
||||
g_resources.getBaseDir() + "modules",
|
||||
g_resources.getBaseDir() + "../modules",
|
||||
g_resources.getBaseDir() + "../share/" + g_app->getAppName() + "/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");
|
||||
}
|
||||
|
||||
ModulePtr ModuleManager::discoverModule(const std::string& moduleFile)
|
||||
{
|
||||
ModulePtr module;
|
||||
@@ -70,6 +97,13 @@ ModulePtr ModuleManager::discoverModule(const std::string& moduleFile)
|
||||
return module;
|
||||
}
|
||||
|
||||
void ModuleManager::ensureModuleLoaded(const std::string& moduleName)
|
||||
{
|
||||
ModulePtr module = g_modules.getModule(moduleName);
|
||||
if(!module || !module->load())
|
||||
logFatal("Unable to load '", moduleName, "' module");
|
||||
}
|
||||
|
||||
void ModuleManager::unloadModules()
|
||||
{
|
||||
for(const ModulePtr& module : m_modules)
|
||||
|
@@ -28,14 +28,18 @@
|
||||
class ModuleManager
|
||||
{
|
||||
public:
|
||||
void discoverAndLoadModules();
|
||||
void discoverModulesPath();
|
||||
void discoverModules();
|
||||
void autoLoadModules(int maxPriority);
|
||||
ModulePtr discoverModule(const std::string& moduleFile);
|
||||
void ensureModuleLoaded(const std::string& moduleName);
|
||||
void unloadModules();
|
||||
|
||||
ModulePtr getModule(const std::string& moduleName);
|
||||
|
||||
private:
|
||||
std::vector<ModulePtr> m_modules;
|
||||
std::multimap<int, ModulePtr> m_autoLoadModules;
|
||||
};
|
||||
|
||||
extern ModuleManager g_modules;
|
||||
|
@@ -76,7 +76,7 @@ void Font::renderText(const std::string& text,
|
||||
const Color& color)
|
||||
{
|
||||
// prevent glitches from invalid rects
|
||||
if(!screenCoords.isValid())
|
||||
if(!screenCoords.isValid() || !m_texture)
|
||||
return;
|
||||
|
||||
int textLenght = text.length();
|
||||
|
@@ -27,6 +27,11 @@
|
||||
|
||||
FontManager g_fonts;
|
||||
|
||||
FontManager::FontManager()
|
||||
{
|
||||
m_defaultFont = FontPtr(new Font("emptyfont"));
|
||||
}
|
||||
|
||||
void FontManager::releaseFonts()
|
||||
{
|
||||
m_defaultFont.reset();
|
||||
|
@@ -28,6 +28,8 @@
|
||||
class FontManager
|
||||
{
|
||||
public:
|
||||
FontManager();
|
||||
|
||||
/// Release fonts references, thus making possible to destruct them
|
||||
void releaseFonts();
|
||||
|
||||
|
@@ -8,7 +8,7 @@ ELSE(FORBIDDEN_FUNCTIONS)
|
||||
MESSAGE(STATUS "Lua forbidden functions: OFF")
|
||||
ENDIF(FORBIDDEN_FUNCTIONS)
|
||||
|
||||
SET(OTCLIENT_SOURCES ${OTCLIENT_SOURCES}
|
||||
SET(otclient_SOURCES ${otclient_SOURCES}
|
||||
# otclient
|
||||
${CMAKE_CURRENT_LIST_DIR}/otclient.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp
|
||||
|
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "otclient.h"
|
||||
#include <framework/core/modulemanager.h>
|
||||
|
||||
OTClient::OTClient() : Application(Otc::AppCompactName)
|
||||
{
|
||||
@@ -31,4 +32,10 @@ void OTClient::init(const std::vector<std::string>& args)
|
||||
{
|
||||
logInfo(Otc::AppName, " ", Otc::AppVersion);
|
||||
Application::init(args, Fw::AppEnableAll);
|
||||
|
||||
g_modules.discoverModules();
|
||||
g_modules.autoLoadModules(100);
|
||||
g_modules.ensureModuleLoaded("client");
|
||||
g_modules.ensureModuleLoaded("game");
|
||||
g_modules.autoLoadModules(1000);
|
||||
}
|
||||
|
Reference in New Issue
Block a user