new logger

scripts are now more error prone
This commit is contained in:
Eduardo Bart
2011-04-22 15:48:02 -03:00
parent e611734396
commit 96e0b1e909
30 changed files with 181 additions and 178 deletions

View File

@@ -54,7 +54,7 @@ bool Configs::load(const std::string& fileName)
m_confsMap[key] = value;
}
} catch (YAML::Exception& e) {
logError("Malformed config file: %s", e.what());
flogError("ERROR: Malformed config file: %s", e.what());
return false;
}
@@ -102,7 +102,7 @@ const std::string &Configs::getString(const std::string &key) const
{
auto it = m_confsMap.find(key);
if(it == m_confsMap.end()) {
logWarning("Config value %s not found", key.c_str());
flogWarning("WARNING: Config value %s not found", key.c_str());
static std::string emptystr;
return emptystr;
}
@@ -113,7 +113,7 @@ float Configs::getFloat(const std::string &key) const
{
auto it = m_confsMap.find(key);
if(it == m_confsMap.end()) {
logWarning("Config value %s not found", key.c_str());
flogWarning("WARNING: Config value %s not found", key.c_str());
return 0;
}
return convertType<float, std::string>(it->second);
@@ -123,7 +123,7 @@ bool Configs::getBoolean(const std::string &key) const
{
auto it = m_confsMap.find(key);
if(it == m_confsMap.end()) {
logWarning("Config value %s not found", key.c_str());
flogWarning("WARNING: Config value %s not found", key.c_str());
return 0;
}
return (it->second == "true");
@@ -133,7 +133,7 @@ int Configs::getInteger(const std::string &key) const
{
auto it = m_confsMap.find(key);
if(it == m_confsMap.end()) {
logWarning("Config value %s not found", key.c_str());
flogWarning("WARNING: Config value %s not found", key.c_str());
return 0;
}
return convertType<int, std::string>(it->second);

View File

@@ -41,12 +41,12 @@ void Dispatcher::poll()
}
}
void Dispatcher::scheduleTask(const Callback& callback, int delay)
void Dispatcher::scheduleTask(const SimpleCallback& callback, int delay)
{
m_taskList.push(new Task(g_engine.getCurrentFrameTicks() + delay, callback));
}
void Dispatcher::addTask(const Callback& callback)
void Dispatcher::addTask(const SimpleCallback& callback)
{
m_taskList.push(new Task(callback));
}

View File

@@ -29,11 +29,11 @@
class Task {
public:
inline Task(const Callback& _callback) : ticks(0), callback(_callback) { }
inline Task(int _ticks, const Callback& _callback) : ticks(_ticks), callback(_callback) { }
inline Task(const SimpleCallback& _callback) : ticks(0), callback(_callback) { }
inline Task(int _ticks, const SimpleCallback& _callback) : ticks(_ticks), callback(_callback) { }
inline bool operator<(const Task& other) const { return ticks > other.ticks; }
int ticks;
Callback callback;
SimpleCallback callback;
};
class lessTask : public std::binary_function<Task*&, Task*&, bool> {
@@ -50,10 +50,10 @@ public:
void poll();
/// Add an event
void addTask(const Callback& callback);
void addTask(const SimpleCallback& callback);
/// Schedula an event
void scheduleTask(const Callback& callback, int delay);
void scheduleTask(const SimpleCallback& callback, int delay);
private:
std::priority_queue<Task*, std::vector<Task*>, lessTask> m_taskList;

View File

@@ -87,7 +87,7 @@ void Engine::run()
frameCount = 0;
// update fps text
fpsText = format("FPS: %d", fps);
fpsText = f("FPS: %d", fps);
fpsTextSize = defaultFont->calculateTextRectSize(fpsText);
}
}

View File

@@ -63,7 +63,7 @@ public:
/// Return the current ticks on this frame
int getCurrentFrameTicks() const { return m_lastFrameTicks; }
void setOnClose(Callback onCloseCallback) { m_onCloseCallback = onCloseCallback; }
void setOnClose(SimpleCallback onCloseCallback) { m_onCloseCallback = onCloseCallback; }
private:
bool m_stopping;
@@ -72,7 +72,7 @@ private:
int m_lastFrameTicks;
Callback m_onCloseCallback;
SimpleCallback m_onCloseCallback;
};
extern Engine g_engine;

View File

@@ -44,14 +44,14 @@ bool Resources::setWriteDir(const std::string& path)
bool ret = (bool)PHYSFS_setWriteDir(path.c_str());
if(!ret)
logError("Could not set the path \"%s\" as write directory, file write will not work correctly.", path.c_str());
flogError("ERROR: Could not set the path \"%s\" as write directory, file write will not work correctly.", path.c_str());
return ret;
}
bool Resources::addToSearchPath(const std::string& path, bool insertInFront /*= true*/)
{
if(!PHYSFS_addToSearchPath(path.c_str(), insertInFront ? 0 : 1)) {
logError("Error while adding \"%s\" to resources search path: %s", path.c_str(), PHYSFS_getLastError());
flogError("ERROR: Error while adding \"%s\" to resources search path: %s", path.c_str() % PHYSFS_getLastError());
return false;
}
return true;
@@ -66,7 +66,7 @@ uchar *Resources::loadFile(const std::string& fileName, uint *fileSize)
{
PHYSFS_file *file = PHYSFS_openRead(fileName.c_str());
if(!file) {
logError("Failed to load file \"%s\": %s", fileName.c_str(), PHYSFS_getLastError());
flogError("ERROR: Failed to load file \"%s\": %s", fileName.c_str() % PHYSFS_getLastError());
*fileSize = 0;
return NULL;
}
@@ -95,7 +95,7 @@ bool Resources::saveFile(const std::string &fileName, const uchar *data, uint si
{
PHYSFS_file *file = PHYSFS_openWrite(fileName.c_str());
if(!file) {
logError("Failed to save file \"%s\": %s", fileName.c_str(), PHYSFS_getLastError());
flogError("ERROR: Failed to save file \"%s\": %s", fileName.c_str() % PHYSFS_getLastError());
return false;
}