mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 05:53:26 +02:00
new script engine, and things maybe be bugged for a while
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <global.h>
|
||||
|
||||
struct ConfigValueProxy {
|
||||
ConfigValueProxy(const std::string& v) : value(v) { }
|
||||
operator std::string() const { return convert<std::string>(value); }
|
||||
operator float() const { return convert<float>(value); }
|
||||
operator int() const { return convert<int>(value); }
|
||||
@@ -20,7 +21,7 @@ public:
|
||||
template<class T>
|
||||
void set(const std::string& key, const T& value) { m_confsMap[key] = convert<std::string>(value); }
|
||||
|
||||
ConfigValueProxy get(const std::string& key) { return ConfigValueProxy{m_confsMap[key]}; }
|
||||
ConfigValueProxy get(const std::string& key) { return ConfigValueProxy(m_confsMap[key]); }
|
||||
|
||||
private:
|
||||
std::string m_fileName;
|
||||
|
@@ -29,12 +29,12 @@ void Dispatcher::poll()
|
||||
}
|
||||
}
|
||||
|
||||
void Dispatcher::scheduleTask(const boost::function<void()>& callback, int delay)
|
||||
void Dispatcher::scheduleTask(const std::function<void()>& callback, int delay)
|
||||
{
|
||||
m_scheduledTaskList.push(new ScheduledTask(g_engine.getCurrentFrameTicks() + delay, callback));
|
||||
}
|
||||
|
||||
void Dispatcher::addTask(const boost::function<void()>& callback, bool pushFront)
|
||||
void Dispatcher::addTask(const std::function<void()>& callback, bool pushFront)
|
||||
{
|
||||
if(pushFront)
|
||||
m_taskList.push_front(callback);
|
||||
|
@@ -4,15 +4,12 @@
|
||||
#include <global.h>
|
||||
#include <queue>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
||||
struct ScheduledTask {
|
||||
ScheduledTask(const boost::function<void()>& _callback) : ticks(0), callback(_callback) { }
|
||||
ScheduledTask(int _ticks, const boost::function<void()>& _callback) : ticks(_ticks), callback(_callback) { }
|
||||
ScheduledTask(const std::function<void()>& _callback) : ticks(0), callback(_callback) { }
|
||||
ScheduledTask(int _ticks, const std::function<void()>& _callback) : ticks(_ticks), callback(_callback) { }
|
||||
bool operator<(const ScheduledTask& other) const { return ticks > other.ticks; }
|
||||
int ticks;
|
||||
boost::function<void()> callback;
|
||||
std::function<void()> callback;
|
||||
};
|
||||
|
||||
struct lessScheduledTask : public std::binary_function<ScheduledTask*&, ScheduledTask*&, bool> {
|
||||
@@ -31,13 +28,13 @@ public:
|
||||
void poll();
|
||||
|
||||
/// Add an event
|
||||
void addTask(const boost::function<void()>& callback, bool pushFront = false);
|
||||
void addTask(const std::function<void()>& callback, bool pushFront = false);
|
||||
|
||||
/// Schedula an event
|
||||
void scheduleTask(const boost::function<void()>& callback, int delay);
|
||||
void scheduleTask(const std::function<void()>& callback, int delay);
|
||||
|
||||
private:
|
||||
std::list<boost::function<void()>> m_taskList;
|
||||
std::list<std::function<void()>> m_taskList;
|
||||
std::priority_queue<ScheduledTask*, std::vector<ScheduledTask*>, lessScheduledTask> m_scheduledTaskList;
|
||||
};
|
||||
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#include <graphics/textures.h>
|
||||
#include <ui/uicontainer.h>
|
||||
#include <ui/uiskins.h>
|
||||
#include <script/scriptcontext.h>
|
||||
#include <script/luainterface.h>
|
||||
#include <net/connection.h>
|
||||
|
||||
Engine g_engine;
|
||||
@@ -113,7 +113,7 @@ void Engine::stop()
|
||||
|
||||
void Engine::onClose()
|
||||
{
|
||||
g_dispatcher.addTask(boost::bind(&ScriptContext::callModuleField, &g_lua, "App", "onClose"));
|
||||
g_lua.getGlobal("onClose")->call("onClose");
|
||||
}
|
||||
|
||||
void Engine::onResize(const Size& size)
|
||||
|
@@ -1,2 +0,0 @@
|
||||
#include "modules.h"
|
||||
|
@@ -1,8 +0,0 @@
|
||||
#ifndef MODULES_H
|
||||
#define MODULES_H
|
||||
|
||||
class Modules
|
||||
{
|
||||
};
|
||||
|
||||
#endif // MODULES_H
|
29
src/framework/core/packages.cpp
Normal file
29
src/framework/core/packages.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "packages.h"
|
||||
|
||||
#include <core/resources.h>
|
||||
#include <script/luainterface.h>
|
||||
|
||||
Packages g_packages;
|
||||
|
||||
void Packages::loadPackages()
|
||||
{
|
||||
std::list<std::string> packages = g_resources.listDirectoryFiles("modules");
|
||||
foreach(const std::string& package, packages) {
|
||||
std::string dir = make_string("modules/", package);
|
||||
g_resources.pushCurrentPath(dir);
|
||||
|
||||
std::list<std::string> packagesFiles = g_resources.listDirectoryFiles();
|
||||
foreach(const std::string& packageFile, packagesFiles) {
|
||||
if(boost::ends_with(packageFile, ".lua")) {
|
||||
g_lua.runScript(packageFile);
|
||||
}
|
||||
}
|
||||
|
||||
g_resources.popCurrentPath();
|
||||
}
|
||||
}
|
||||
|
||||
void Packages::terminate()
|
||||
{
|
||||
|
||||
}
|
15
src/framework/core/packages.h
Normal file
15
src/framework/core/packages.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef PACKAGES_H
|
||||
#define PACKAGES_H
|
||||
|
||||
#include <global.h>
|
||||
|
||||
class Packages
|
||||
{
|
||||
public:
|
||||
void loadPackages();
|
||||
void terminate();
|
||||
};
|
||||
|
||||
extern Packages g_packages;
|
||||
|
||||
#endif // MODULES_H
|
@@ -2,7 +2,6 @@
|
||||
#include "resources.h"
|
||||
#include "platform.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <physfs.h>
|
||||
|
||||
Resources g_resources;
|
||||
@@ -148,12 +147,15 @@ std::list<std::string> Resources::listDirectoryFiles(const std::string& director
|
||||
|
||||
void Resources::pushCurrentPath(const std::string ¤tPath)
|
||||
{
|
||||
//logTraceDebug(currentPath);
|
||||
m_currentPaths.push(currentPath);
|
||||
}
|
||||
|
||||
void Resources::popCurrentPath()
|
||||
{
|
||||
m_currentPaths.pop();
|
||||
//if(!m_currentPaths.empty())
|
||||
// logTraceDebug(m_currentPaths.top());
|
||||
}
|
||||
|
||||
std::string Resources::resolvePath(const std::string& path)
|
||||
|
Reference in New Issue
Block a user