reorganize modules

This commit is contained in:
Eduardo Bart 2011-12-05 16:27:07 -02:00
parent ffeb34e0e7
commit cf0aab6d4d
90 changed files with 186 additions and 181 deletions

4
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "modules/tibiafiles"]
path = modules/tibiafiles
[submodule "modules/client_tibiafiles"]
path = modules/client_tibiafiles
url = git://github.com/Baxnie/otclient-tibiafiles.git

View File

@ -6,7 +6,7 @@ INCLUDE(src/otclient/CMakeLists.txt)
OPTION(USE_PCH "Use precompiled header (speed up compile)" ON)
SET(EXECUTABLE_SOURCES src/main.cpp)
SET(executable_SOURCES src/main.cpp)
# add executable icon for win32 platforms
IF(WIN32)
@ -15,14 +15,14 @@ IF(WIN32)
-I${CMAKE_CURRENT_SOURCE_DIR}/src
-i${CMAKE_CURRENT_SOURCE_DIR}/src/otcicon.rc
-o ${CMAKE_CURRENT_BINARY_DIR}/otcicon.o)
SET(${EXECUTABLE_SOURCES} ${EXECUTABLE_SOURCES} otcicon.o)
SET(executable_SOURCES ${executable_SOURCES} otcicon.o)
ENDIF(WIN32)
# add otclient executable
ADD_EXECUTABLE(otclient ${FRAMEWORK_SOURCES} ${OTCLIENT_SOURCES} ${EXECUTABLE_SOURCES})
ADD_EXECUTABLE(otclient ${framework_SOURCES} ${otclient_SOURCES} ${executable_SOURCES})
# target link libraries
TARGET_LINK_LIBRARIES(otclient ${FRAMEWORK_LIBRARIES})
TARGET_LINK_LIBRARIES(otclient ${framework_LIBRARIES})
IF(USE_PCH)
FIND_PACKAGE(PCHSupport REQUIRED)

1
TODO
View File

@ -29,3 +29,4 @@ bind every global lua function in a static class
use metatable for Point,Rect,Color,Size lua classes
lua binder generator
restore win32 platform
set special types for g_configs like lists/point/size

View File

@ -3,7 +3,11 @@ Module
description: Console for executing lua functions
author: OTClient team
website: https://github.com/edubart/otclient
// console can be loaded after core
autoLoad: true
autoLoadPriority: 20
dependencies:
- core

View File

@ -0,0 +1 @@
-- place any code for testing purposes here

View File

@ -1,9 +1,6 @@
Module
name: playground
autoLoad: true
dependencies:
- core
onLoad: |
require 'playground'
return true

View File

@ -1,13 +1,13 @@
OTClient = { }
Client = { }
-- TODO: load and save configurations
function OTClient.init()
function Client.init()
g_window.move({ x=220, y=220 })
g_window.resize({ width=800, height=600 })
g_window.setTitle('OTClient')
g_window.setIcon('otcicon.png')
g_window.setIcon('clienticon.png')
return true
end
function OTClient.terminate()
function Client.terminate()
end

View File

@ -0,0 +1,22 @@
Module
name: client
description: Load all other otclient dependecies
author: OTClient team
website: https://github.com/edubart/otclient
// NOTE: order does matter
dependencies:
- client_background
- client_topmenu
- client_tibiafiles
- client_about
- client_options
- client_entergame
- game
onLoad: |
require 'client'
return Client.init()
onUnload: |
Client.terminate()

View File

Before

Width:  |  Height:  |  Size: 518 B

After

Width:  |  Height:  |  Size: 518 B

View File

@ -1,16 +1,16 @@
About = {}
-- private variables
local about
local aboutWindow
-- public functions
function About.create()
about = UI.display('about.otui', { locked = true })
aboutWindow = UI.display('about.otui', { locked = true })
end
function About.destroy()
about:destroy()
about = nil
aboutWindow:destroy()
aboutWindow = nil
end
function About.openWebpage()

View File

@ -1,10 +1,8 @@
Module
name: about
name: client_about
description: Create the about window
author: OTClient team
website: https://github.com/edubart/otclient
dependencies:
- core
onLoad: |
require 'about'

View File

@ -1,10 +1,8 @@
Module
name: background
name: client_background
description: Handles the background of the login screen
author: OTClient team
website: https://github.com/edubart/otclient
dependencies:
- core
onLoad: |
require 'background'

View File

@ -1,7 +1,7 @@
Panel
id: background
image:
source: /background/background.png
source: /client_background/background.png
smooth: true
fixed ratio: true
anchors.top: topMenu.bottom

View File

Before

Width:  |  Height:  |  Size: 1.9 MiB

After

Width:  |  Height:  |  Size: 1.9 MiB

View File

@ -1,8 +1,9 @@
Module
name: entergame
name: client_entergame
description: Manages enter game and character list windows
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
require 'entergame'
require 'characterlist'

View File

@ -1,8 +1,9 @@
Module
name: options
name: client_options
description: Create the options window
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
require 'options'
return true

@ -0,0 +1 @@
Subproject commit e76fa2786e2a194375a110b700b7e2daa769f960

View File

@ -1,13 +1,8 @@
Module
name: topmenu
name: client_topmenu
description: Create the top menu
author: OTClient team
website: https://github.com/edubart/otclient
dependencies:
- core
- entergame
- options
- about
onLoad: |
require 'topmenu'
@ -16,4 +11,3 @@ Module
onUnload: |
TopMenu.destroy()

View File

@ -3,19 +3,15 @@ Module
description: Contains lua classes, functions and constants used by other modules
author: OTClient team
website: https://github.com/edubart/otclient
// core must be loaded before other modules
autoLoad: true
autoLoadPriority: 10
// NOTE: order does matter
dependencies:
- core_fonts
- core_styles
onLoad: |
require 'ext/table'
require 'ext/string'
require 'constants'
require 'util'
require 'dispatcher'
require 'widget'
require 'ui'
require 'gfx'
return true
- core_scripts
- core_widgets

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

View File

@ -0,0 +1,16 @@
Module
name: core_scripts
description: Contains core lua classes, functions and constants used by other modules
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
require 'ext/table'
require 'ext/string'
require 'constants'
require 'util'
require 'dispatcher'
require 'widget'
require 'ui'
require 'gfx'
return true

View File

@ -12,14 +12,18 @@ function createEnvironment()
return env
end
function connect(object, signalsAndSlots)
function connect(object, signalsAndSlots, pushFront)
for signal,slot in pairs(signalsAndSlots) do
if not object[signal] then
object[signal] = slot
elseif type(object[signal]) == 'function' then
object[signal] = { object[signal], slot }
elseif type(object[signal]) == 'table' then
table.insert(object[signal], #object[signal]+1, slot)
if pushFront then
table.insert(object[signal], 1, slot)
else
table.insert(object[signal], #object[signal]+1, slot)
end
end
end
end

View File

@ -3,8 +3,7 @@ Module
description: Contains ui styles used by other modules
author: OTClient team
website: https://github.com/edubart/otclient
dependencies:
- core_fonts
onLoad: |
importStyles 'styles/buttons.otui'
importStyles 'styles/labels.otui'
@ -17,4 +16,3 @@ Module
importStyles 'styles/items.otui'
importStyles 'styles/creatures.otui'
return true

View File

@ -0,0 +1,10 @@
Module
name: core_widgets
description: Contains widgets used by other modules
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
require 'tooltip/tooltip'
require 'messagebox/messagebox'
return true

View File

@ -16,7 +16,7 @@ end
function Game.createInterface()
Background.hide()
CharacterList.destroyLoadBox()
Game.gameUi = UI.display('/game/game.otui')
Game.gameUi = UI.display('game.otui')
UI.root:moveChildToIndex(Game.gameUi, 1)
Game.gameMapPanel = Game.gameUi:getChildById('mapPanel')
Game.gameRightPanel = Game.gameUi:getChildById('rightPanel')
@ -56,5 +56,5 @@ function Game.onConnectionError(message)
errorBox.onOk = CharacterList.show
end
connect(Game, { onLogin = Game.createInterface,
onLogout = Game.destroyInterface })
connect(Game, { onLogin = Game.createInterface }, true)
connect(Game, { onLogout = Game.destroyInterface })

View File

@ -3,6 +3,16 @@ Module
description: Create the game interface, where the ingame stuff starts
author: OTClient team
website: https://github.com/edubart/otclient
dependencies:
- game_healthbar
- game_inventory
- game_skills
- game_textmessage
- game_viplist
- game_chat
- game_outfit
onLoad: |
require 'game'
return true

View File

@ -1,5 +1,5 @@
Module
name: chat
name: game_chat
description: Manage chat window
author: OTClient team
website: https://github.com/edubart/otclient

View File

@ -1,11 +1,11 @@
HealthMana = {}
HealthBar = {}
-- private variables
local healthManaPanel = nil
-- public functions
function HealthMana.create()
healthManaPanel = UI.display('health_mana.otui', { parent = Game.gameRightPanel })
function HealthBar.create()
healthManaPanel = UI.display('healthbar.otui', { parent = Game.gameRightPanel })
local healthBar = UIProgressBar.create()
healthManaPanel:addChild(healthBar)
@ -32,7 +32,7 @@ function HealthMana.create()
healthManaPanel:setHeight(healthBar:getHeight() + manaBar:getHeight() + 4)
end
function HealthMana.destroy()
function HealthBar.destroy()
healthManaPanel:destroy()
healthManaPanel = nil
end
@ -61,5 +61,5 @@ function Game.onManaChange(mana, maxMana)
manaBar:setPercent(percent)
end
connect(Game, { onLogin = HealthMana.create,
onLogout = HealthMana.destroy })
connect(Game, { onLogin = HealthBar.create,
onLogout = HealthBar.destroy })

View File

@ -1,10 +1,10 @@
Module
name: health_mana
name: game_healthbar
description: Displays health and mana points
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
require 'health_mana'
require 'healthbar'
return true

View File

@ -1,5 +1,5 @@
Module
name: inventory
name: game_inventory
description: View local player equipments window
author: OTClient team
website: https://github.com/edubart/otclient

View File

@ -1,5 +1,5 @@
Module
name: outfit
name: game_outfit
description: Change local player outfit
author: OTClient team
website: https://github.com/edubart/otclient

View File

@ -1,5 +1,5 @@
Module
name: skills
name: game_skills
description: Manage skills window
author: OTClient team
website: https://github.com/edubart/otclient

View File

@ -1,7 +1,7 @@
TextMessage = {}
-- require styles
importStyles '/textmessage/textmessage.otui'
importStyles 'textmessage.otui'
-- private variables
local bottomLabelWidget, centerLabelWidget

View File

@ -1,5 +1,5 @@
Module
name: textmessage
name: game_textmessage
description: Manage game text messages
author: OTClient team
website: https://github.com/edubart/otclient

View File

@ -1,5 +1,5 @@
Module
name: viplist
name: game_viplist
description: Manage vip list window
author: OTClient team
website: https://github.com/edubart/otclient

View File

@ -1,12 +0,0 @@
Module
name: messagebox
description: Manages message boxes
author: OTClient team
website: https://github.com/edubart/otclient
autoLoad: true
dependencies:
- core
onLoad: |
require 'messagebox'
return true

View File

@ -1,27 +0,0 @@
Module
name: otclient
description: Load all other otclient modules
author: OTClient team
website: https://github.com/edubart/otclient
autoLoad: true
autoLoadPriority: 10
dependencies:
- core
- background
- topmenu
- game
- health_mana
- inventory
- skills
- viplist
- textmessage
- chat
- outfit
- tibiafiles
onLoad: |
require 'otclient'
return OTClient.init()
onUnload: |
OTClient.terminate()

View File

@ -1,24 +0,0 @@
-- place any code for testing purposes here
function UIItem.onMouseRelease(self, mousePos, mouseButton)
if mouseButton ~= MouseRightButton then return end
local top = self:getY()
local bottom = self:getY() + self:getHeight()
local left = self:getX()
local right = self:getX() + self:getWidth()
if not (mousePos.y >= top and mousePos.y <= bottom and mousePos.x >= left and mousePos.x <= right) then return end
local menuFile = self:getStyle()['popup menu']
if not menuFile then return end
local popupMenu = UI.display(menuFile)
if not popupMenu then return end
popupMenu:moveTo(mousePos)
popupMenu.onMouseRelease = function(self) self:destroy() end
end
local function init()
end
addEvent(init)

@ -1 +0,0 @@
Subproject commit 8bb3b7d6d86e561be4622fbe7dbef208446a0319

View File

@ -1,13 +0,0 @@
Module
name: tooltip
description: Enable tooltips on any button
author: OTClient team
website: https://github.com/edubart/otclient
autoLoad: true
autoLoadPriority: 2
dependencies:
- core
onLoad: |
require 'tooltip'
return true

View File

@ -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

View File

@ -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();
}

View File

@ -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;

View File

@ -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)

View File

@ -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;

View File

@ -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();

View File

@ -27,6 +27,11 @@
FontManager g_fonts;
FontManager::FontManager()
{
m_defaultFont = FontPtr(new Font("emptyfont"));
}
void FontManager::releaseFonts()
{
m_defaultFont.reset();

View File

@ -28,6 +28,8 @@
class FontManager
{
public:
FontManager();
/// Release fonts references, thus making possible to destruct them
void releaseFonts();

View File

@ -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

View File

@ -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);
}