too many changes to list, many regressions were made, master will be UNSTABLE for a few days

This commit is contained in:
Eduardo Bart
2011-12-03 19:41:37 -02:00
parent 19eb56997d
commit f548825faf
80 changed files with 1881 additions and 1843 deletions

View File

@@ -22,14 +22,18 @@
#include "clock.h"
// for usleep
#include <unistd.h>
Clock g_clock;
Clock::Clock()
{
m_startupTime = std::chrono::high_resolution_clock::now();
m_currentTicks = 0;
}
int Clock::updateTicks()
ticks_t Clock::updateTicks()
{
auto timeNow = std::chrono::high_resolution_clock::now();
m_currentTicks = std::chrono::duration_cast<std::chrono::milliseconds>(timeNow - m_startupTime).count();

View File

@@ -30,15 +30,15 @@ class Clock
public:
Clock();
int updateTicks();
ticks_t updateTicks();
void sleep(int ms);
int ticks() { return m_currentTicks; }
int ticksElapsed(int prevTicks) { return ticks() - prevTicks; }
int ticksFor(int delay) { return ticks() + delay; }
ticks_t ticks() { return m_currentTicks; }
ticks_t ticksElapsed(long prevTicks) { return ticks() - prevTicks; }
ticks_t ticksFor(int delay) { return ticks() + delay; }
private:
int m_currentTicks;
ticks_t m_currentTicks;
std::chrono::system_clock::time_point m_startupTime;
};

View File

@@ -1,24 +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.
*/
#include "engine.h"

View File

@@ -26,9 +26,9 @@
#include "declarations.h"
struct ScheduledEvent {
ScheduledEvent(int ticks, const SimpleCallback& callback) : ticks(ticks), callback(callback) { }
ScheduledEvent(ticks_t ticks, const SimpleCallback& callback) : ticks(ticks), callback(callback) { }
bool operator<(const ScheduledEvent& other) const { return ticks > other.ticks; }
int ticks;
ticks_t ticks;
SimpleCallback callback;
};

View File

@@ -20,14 +20,20 @@
* THE SOFTWARE.
*/
#ifndef ENGINE_H
#define ENGINE_H
#ifndef INPUTEVENT_H
#define INPUTEVENT_H
#include "declarations.h"
class Engine
{
struct InputEvent {
Fw::InputEventType type;
Fw::MouseWheelDirection wheelDirection;
Fw::MouseButton mouseButton;
int keyboardModifiers;
std::string keyText;
Fw::Key keyCode;
Point mousePos;
Point mouseMoved;
};
#endif

View File

@@ -22,7 +22,6 @@
#include "logger.h"
#include "eventdispatcher.h"
#include <framework/platform/platform.h>
Logger g_logger;

View File

@@ -70,4 +70,4 @@ extern Logger g_logger;
#define logTraceWarning(...) g_logger.logFunc(Fw::LogWarning, Fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
#define logTraceError(...) g_logger.logFunc(Fw::LogError, Fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
#endif
#endif

View File

@@ -26,6 +26,11 @@
#include <framework/otml/otml.h>
#include <framework/luascript/luainterface.h>
Module::Module(const std::string& name)
{
m_name = name;
}
void Module::discover(const OTMLNodePtr& moduleNode)
{
const static std::string none = "none";
@@ -34,6 +39,7 @@ void Module::discover(const OTMLNodePtr& moduleNode)
m_website = moduleNode->valueAt("website", none);
m_version = moduleNode->valueAt("version", none);
m_autoLoad = moduleNode->valueAt<bool>("autoLoad", false);
m_autoLoadPriority = moduleNode->valueAt<int>("autoLoadPriority", 100);
if(OTMLNodePtr node = moduleNode->get("dependencies")) {
for(const OTMLNodePtr& tmp : node->children())
@@ -57,6 +63,9 @@ void Module::discover(const OTMLNodePtr& moduleNode)
bool Module::load()
{
if(m_loaded)
return true;
for(const std::string& depName : m_dependencies) {
ModulePtr dep = g_modules.getModule(depName);
if(!dep) {

View File

@@ -30,7 +30,7 @@
class Module
{
public:
Module(const std::string& name) : m_loaded(false), m_autoLoad(false), m_name(name) { }
Module(const std::string& name);
void discover(const OTMLNodePtr& moduleNode);
bool load();
@@ -43,11 +43,13 @@ public:
std::string getAuthor() { return m_author; }
std::string getWebsite() { return m_website; }
std::string getVersion() { return m_version; }
bool autoLoad() { return m_autoLoad; }
bool isAutoLoad() { return m_autoLoad; }
int getAutoLoadPriority() { return m_autoLoadPriority; }
private:
bool m_loaded;
bool m_autoLoad;
Boolean<false> m_loaded;
Boolean<false> m_autoLoad;
int m_autoLoadPriority;
std::string m_name;
std::string m_description;
std::string m_author;

View File

@@ -29,29 +29,32 @@ ModuleManager g_modules;
void ModuleManager::discoverAndLoadModules()
{
std::multimap<int, ModulePtr> m_autoLoadModules;
auto moduleDirs = g_resources.listDirectoryFiles("/");
for(const std::string& moduleDir : moduleDirs) {
auto moduleFiles = g_resources.listDirectoryFiles("/" + moduleDir);
for(const std::string& file : moduleFiles) {
if(boost::ends_with(file, ".otmod"))
discoverModule("/" + moduleDir + "/" + file);
for(const std::string& moduleFile : moduleFiles) {
if(boost::ends_with(moduleFile, ".otmod")) {
ModulePtr module = discoverModule("/" + moduleDir + "/" + moduleFile);
if(module && module->isAutoLoad())
m_autoLoadModules.insert(make_pair(module->getAutoLoadPriority(), module));
}
}
}
// auto load modules
for(const ModulePtr& module : m_modules) {
if(!module->isLoaded() && module->autoLoad()) {
if(!module->load())
logFatal("A required module has failed to load, cannot continue to run.");
}
for(auto& pair : m_autoLoadModules) {
ModulePtr module = pair.second;
if(!module->isLoaded() && !module->load())
logFatal("A required module has failed to load, cannot continue to run.");
}
}
bool ModuleManager::discoverModule(const std::string& file)
ModulePtr ModuleManager::discoverModule(const std::string& moduleFile)
{
ModulePtr module;
try {
OTMLDocumentPtr doc = OTMLDocument::parse(file);
OTMLDocumentPtr doc = OTMLDocument::parse(moduleFile);
OTMLNodePtr moduleNode = doc->at("Module");
std::string name = moduleNode->valueAt("name");
@@ -62,10 +65,9 @@ bool ModuleManager::discoverModule(const std::string& file)
module->discover(moduleNode);
m_modules.push_back(module);
} catch(Exception& e) {
logError("Unable to discover module from file '", file, "': ", e.what());
return false;
logError("Unable to discover module from file '", moduleFile, "': ", e.what());
}
return true;
return module;
}
void ModuleManager::unloadModules()

View File

@@ -29,7 +29,7 @@ class ModuleManager
{
public:
void discoverAndLoadModules();
bool discoverModule(const std::string& file);
ModulePtr discoverModule(const std::string& moduleFile);
void unloadModules();
ModulePtr getModule(const std::string& moduleName);

View File

@@ -22,24 +22,28 @@
#include "resourcemanager.h"
#include <framework/platform/platform.h>
#include <framework/application.h>
#include <framework/luascript/luainterface.h>
#include <physfs.h>
ResourceManager g_resources;
void ResourceManager::init(const char* argv0, const char *appName)
void ResourceManager::init(const char *argv0)
{
PHYSFS_init(argv0);
// try to find modules directory, all data lives there
std::string baseDir = PHYSFS_getBaseDir();
// 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/" + appName + "/otclient/modules",
baseDir + "../share/" + g_app.getAppName() + "/otclient/modules",
"" };
bool found = false;
@@ -52,14 +56,7 @@ void ResourceManager::init(const char* argv0, const char *appName)
}
if(!found)
logFatal("Could not find modules directory.");
// setup write directory
std::string dir = g_platform.getAppUserDir();
if(g_resources.setWriteDir(dir))
g_resources.addToSearchPath(dir);
else
logError("could not setup write directory");
logFatal("Could not find modules directory");
}
void ResourceManager::terminate()
@@ -67,10 +64,22 @@ void ResourceManager::terminate()
PHYSFS_deinit();
}
bool ResourceManager::setWriteDir(const std::string& path)
bool ResourceManager::setupWriteDir()
{
if(!PHYSFS_setWriteDir(path.c_str()))
return false;
std::string userDir = PHYSFS_getUserDir();
std::string dirName = Fw::mkstr(".", g_app.getAppName());
std::string writeDir = userDir + dirName;
if(!PHYSFS_setWriteDir(writeDir.c_str())) {
if(!PHYSFS_setWriteDir(userDir.c_str()))
return false;
if(!PHYSFS_mkdir(dirName.c_str())) {
PHYSFS_setWriteDir(NULL);
return false;
}
if(!PHYSFS_setWriteDir(writeDir.c_str()))
return false;
}
addToSearchPath(writeDir);
return true;
}
@@ -97,7 +106,7 @@ bool ResourceManager::fileExists(const std::string& fileName)
bool ResourceManager::directoryExists(const std::string& directoryName)
{
return (PHYSFS_exists(resolvePath(directoryName).c_str()) && PHYSFS_isDirectory(resolvePath(directoryName).c_str()));
return (PHYSFS_isDirectory(resolvePath(directoryName).c_str()));
}
void ResourceManager::loadFile(const std::string& fileName, std::iostream& out)

View File

@@ -28,11 +28,10 @@
class ResourceManager
{
public:
void init(const char* argv0, const char *appName);
void init(const char *argv0);
void terminate();
/// Set output files directory
bool setWriteDir(const std::string& path);
bool setupWriteDir();
/// Add an package or directory to the search path
bool addToSearchPath(const std::string& path, bool insertInFront = true);
@@ -55,6 +54,7 @@ public:
std::list<std::string> listDirectoryFiles(const std::string& directoryPath = "");
std::string resolvePath(const std::string& path);
std::string getAppUserPath();
};
extern ResourceManager g_resources;