mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 05:53:26 +02:00
refactoring paths and includes
This commit is contained in:
139
src/framework/core/configs.cpp
Normal file
139
src/framework/core/configs.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 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 "configs.h"
|
||||
#include "resources.h"
|
||||
|
||||
Configs g_configs;
|
||||
|
||||
bool Configs::load(const std::string& fileName)
|
||||
{
|
||||
m_fileName = fileName;
|
||||
|
||||
if(!g_resources.fileExists(fileName))
|
||||
return false;
|
||||
|
||||
std::string fileContents = g_resources.loadTextFile(fileName);
|
||||
if(fileContents.size() == 0)
|
||||
return false;
|
||||
|
||||
std::istringstream fin(fileContents);
|
||||
|
||||
try {
|
||||
YAML::Parser parser(fin);
|
||||
|
||||
YAML::Node doc;
|
||||
parser.GetNextDocument(doc);
|
||||
|
||||
for(auto it = doc.begin(); it != doc.end(); ++it) {
|
||||
std::string key, value;
|
||||
it.first() >> key;
|
||||
it.second() >> value;
|
||||
m_confsMap[key] = value;
|
||||
}
|
||||
} catch (YAML::ParserException& e) {
|
||||
logError("Malformed configuration file!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Configs::save()
|
||||
{
|
||||
if(!m_fileName.empty()) {
|
||||
YAML::Emitter out;
|
||||
out << m_confsMap;
|
||||
g_resources.saveFile(m_fileName, (const uchar*)out.c_str(), out.size());
|
||||
}
|
||||
}
|
||||
|
||||
void Configs::setValue(const std::string &key, const std::string &value)
|
||||
{
|
||||
m_confsMap[key] = value;
|
||||
}
|
||||
|
||||
void Configs::setValue(const std::string &key, const char *value)
|
||||
{
|
||||
m_confsMap[key] = value;
|
||||
}
|
||||
|
||||
void Configs::setValue(const std::string &key, int value)
|
||||
{
|
||||
setValue(key, convertType<std::string, int>(value));
|
||||
}
|
||||
|
||||
void Configs::setValue(const std::string &key, float value)
|
||||
{
|
||||
setValue(key, convertType<std::string, float>(value));
|
||||
}
|
||||
|
||||
void Configs::setValue(const std::string &key, bool value)
|
||||
{
|
||||
if(value)
|
||||
setValue(key,"true");
|
||||
else
|
||||
setValue(key,"false");
|
||||
}
|
||||
|
||||
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());
|
||||
static std::string emptystr;
|
||||
return emptystr;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
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());
|
||||
return 0;
|
||||
}
|
||||
return convertType<float, std::string>(it->second);
|
||||
}
|
||||
|
||||
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());
|
||||
return 0;
|
||||
}
|
||||
return (it->second == "true");
|
||||
}
|
||||
|
||||
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());
|
||||
return 0;
|
||||
}
|
||||
return convertType<int, std::string>(it->second);
|
||||
}
|
59
src/framework/core/configs.h
Normal file
59
src/framework/core/configs.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CONFIGS_H
|
||||
#define CONFIGS_H
|
||||
|
||||
#include "prerequisites.h"
|
||||
|
||||
class Configs
|
||||
{
|
||||
public:
|
||||
Configs() { }
|
||||
|
||||
/// Read configuration file and parse all settings to memory
|
||||
bool load(const std::string& fileName);
|
||||
|
||||
/// Dump all settings to configuration file
|
||||
void save();
|
||||
|
||||
void setValue(const std::string &key, const std::string &value);
|
||||
void setValue(const std::string &key, const char *value);
|
||||
void setValue(const std::string &key, float value);
|
||||
void setValue(const std::string &key, bool value);
|
||||
void setValue(const std::string &key, int value);
|
||||
|
||||
const std::string &getString(const std::string &key) const;
|
||||
float getFloat(const std::string &key) const;
|
||||
bool getBoolean(const std::string &key) const;
|
||||
int getInteger(const std::string &key) const;
|
||||
|
||||
private:
|
||||
std::string m_fileName;
|
||||
std::map<std::string, std::string> m_confsMap;
|
||||
};
|
||||
|
||||
extern Configs g_configs;
|
||||
|
||||
#endif // CONFIGS_H
|
51
src/framework/core/dispatcher.cpp
Normal file
51
src/framework/core/dispatcher.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 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 "dispatcher.h"
|
||||
#include "platform.h"
|
||||
|
||||
Dispatcher g_dispatcher;
|
||||
|
||||
void Dispatcher::poll(int ticks)
|
||||
{
|
||||
while(!m_taskList.empty()) {
|
||||
Task *task = m_taskList.top();
|
||||
if(ticks < task->ticks)
|
||||
break;
|
||||
|
||||
task->callback();
|
||||
delete task;
|
||||
m_taskList.pop();
|
||||
}
|
||||
}
|
||||
|
||||
void Dispatcher::scheduleTask(const Callback& callback, int delay)
|
||||
{
|
||||
m_taskList.push(new Task(Platform::getTicks() + delay, callback));
|
||||
}
|
||||
|
||||
void Dispatcher::addTask(const Callback& callback)
|
||||
{
|
||||
m_taskList.push(new Task(callback));
|
||||
}
|
68
src/framework/core/dispatcher.h
Normal file
68
src/framework/core/dispatcher.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DISPATCHER_H
|
||||
#define DISPATCHER_H
|
||||
|
||||
#include "prerequisites.h"
|
||||
|
||||
#include <queue>
|
||||
|
||||
typedef std::function<void (void)> Callback;
|
||||
|
||||
class Task {
|
||||
public:
|
||||
inline Task(const Callback& _callback) : ticks(0), callback(_callback) { }
|
||||
inline Task(int _ticks, const Callback& _callback) : ticks(_ticks), callback(_callback) { }
|
||||
inline bool operator<(const Task& other) const { return ticks > other.ticks; }
|
||||
int ticks;
|
||||
Callback callback;
|
||||
};
|
||||
|
||||
class lessTask : public std::binary_function<Task*&, Task*&, bool> {
|
||||
public:
|
||||
bool operator()(Task*& t1,Task*& t2) { return (*t1) < (*t2); }
|
||||
};
|
||||
|
||||
class Dispatcher
|
||||
{
|
||||
public:
|
||||
Dispatcher() { }
|
||||
|
||||
/// Execute scheduled events
|
||||
void poll(int ticks);
|
||||
|
||||
/// Add an event
|
||||
void addTask(const Callback& callback);
|
||||
|
||||
/// Schedula an event
|
||||
void scheduleTask(const Callback& callback, int delay);
|
||||
|
||||
private:
|
||||
std::priority_queue<Task*, std::vector<Task*>, lessTask> m_taskList;
|
||||
};
|
||||
|
||||
extern Dispatcher g_dispatcher;
|
||||
|
||||
#endif // DISPATCHER_H
|
149
src/framework/core/engine.cpp
Normal file
149
src/framework/core/engine.cpp
Normal file
@@ -0,0 +1,149 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 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"
|
||||
#include "graphics/fonts.h"
|
||||
#include "platform.h"
|
||||
#include "graphics/graphics.h"
|
||||
#include "configs.h"
|
||||
#include "dispatcher.h"
|
||||
#include "net/connections.h"
|
||||
#include "ui/uicontainer.h"
|
||||
|
||||
Engine g_engine;
|
||||
|
||||
void Engine::init()
|
||||
{
|
||||
// initialize stuff
|
||||
g_graphics.init();
|
||||
g_fonts.init();
|
||||
}
|
||||
|
||||
void Engine::terminate()
|
||||
{
|
||||
// force last state exit
|
||||
changeState(NULL);
|
||||
|
||||
// terminate stuff
|
||||
g_fonts.terminate();
|
||||
g_graphics.terminate();
|
||||
}
|
||||
|
||||
void Engine::run()
|
||||
{
|
||||
int ticks = Platform::getTicks();
|
||||
int lastFpsTicks = ticks;
|
||||
int frameCount = 0;
|
||||
int fps = 0;
|
||||
m_running = true;
|
||||
|
||||
while(!m_stopping) {
|
||||
// poll platform events
|
||||
Platform::poll();
|
||||
|
||||
// poll network events
|
||||
g_connections.poll();
|
||||
|
||||
ticks = Platform::getTicks();
|
||||
|
||||
// poll diaptcher tasks
|
||||
g_dispatcher.poll(ticks);
|
||||
|
||||
// render only when visible
|
||||
if(Platform::isWindowVisible()) {
|
||||
// calculate and fps
|
||||
if(m_calculateFps) {
|
||||
frameCount++;
|
||||
if(ticks - lastFpsTicks >= 1000) {
|
||||
lastFpsTicks = ticks;
|
||||
fps = frameCount;
|
||||
frameCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
render();
|
||||
|
||||
// render fps
|
||||
if(m_calculateFps) {
|
||||
std::string fpsText = format("FPS: %d", fps);
|
||||
Size textSize = g_defaultFont->calculateTextRectSize(fpsText);
|
||||
g_defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - textSize.width() - 10, 10));
|
||||
}
|
||||
|
||||
// swap buffers
|
||||
Platform::swapBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
m_stopping = false;
|
||||
m_running = false;
|
||||
}
|
||||
|
||||
void Engine::stop()
|
||||
{
|
||||
m_stopping = true;
|
||||
}
|
||||
|
||||
void Engine::changeState(GameState* newState)
|
||||
{
|
||||
if(m_currentState)
|
||||
m_currentState->onLeave();
|
||||
m_currentState = newState;
|
||||
if(m_currentState)
|
||||
m_currentState->onEnter();
|
||||
}
|
||||
|
||||
void Engine::render()
|
||||
{
|
||||
g_graphics.beginRender();
|
||||
if(m_currentState)
|
||||
m_currentState->render();
|
||||
g_ui->render();
|
||||
g_graphics.endRender();
|
||||
}
|
||||
|
||||
void Engine::onClose()
|
||||
{
|
||||
if(m_currentState)
|
||||
m_currentState->onClose();
|
||||
}
|
||||
|
||||
void Engine::onResize(const Size& size)
|
||||
{
|
||||
g_graphics.resize(size);
|
||||
g_ui->setSize(size);
|
||||
|
||||
if(m_currentState)
|
||||
m_currentState->onResize(size);
|
||||
}
|
||||
|
||||
void Engine::onInputEvent(const InputEvent& event)
|
||||
{
|
||||
// inputs goest to gui first
|
||||
if(!g_ui->onInputEvent(event)) {
|
||||
// if gui didnt capture the input then goes to the state
|
||||
if(m_currentState)
|
||||
m_currentState->onInputEvent(event);
|
||||
}
|
||||
}
|
78
src/framework/core/engine.h
Normal file
78
src/framework/core/engine.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ENGINE_H
|
||||
#define ENGINE_H
|
||||
|
||||
#include "prerequisites.h"
|
||||
#include "gamestate.h"
|
||||
|
||||
class Engine
|
||||
{
|
||||
public:
|
||||
Engine() : m_stopping(false),
|
||||
m_running(false),
|
||||
m_calculateFps(false),
|
||||
m_currentState(NULL) { }
|
||||
|
||||
void init();
|
||||
void terminate();
|
||||
|
||||
/// Main loop
|
||||
void run();
|
||||
|
||||
/// Stops main loop
|
||||
void stop();
|
||||
|
||||
/// Change current game state
|
||||
void changeState(GameState *newState);
|
||||
|
||||
bool isRunning() const { return m_running; }
|
||||
bool isStopping() const { return m_stopping; }
|
||||
|
||||
/// Fired by platform on window close
|
||||
void onClose();
|
||||
/// Fired by platform on window resize
|
||||
void onResize(const Size& size);
|
||||
/// Fired by platform on mouse/keyboard input
|
||||
void onInputEvent(const InputEvent& event);
|
||||
|
||||
/// Enable FPS counter on screen
|
||||
void enableFpsCounter(bool enable = true) { m_calculateFps = enable; };
|
||||
|
||||
private:
|
||||
/// Called to render every frame
|
||||
void render();
|
||||
|
||||
bool m_stopping;
|
||||
bool m_running;
|
||||
bool m_calculateFps;
|
||||
|
||||
GameState *m_currentState;
|
||||
};
|
||||
|
||||
extern Engine g_engine;
|
||||
|
||||
#endif // ENGINE_H
|
||||
|
49
src/framework/core/gamestate.h
Normal file
49
src/framework/core/gamestate.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GAMESTATE_H
|
||||
#define GAMESTATE_H
|
||||
|
||||
#include "prerequisites.h"
|
||||
#include "input.h"
|
||||
|
||||
struct InputEvent;
|
||||
|
||||
class GameState
|
||||
{
|
||||
public:
|
||||
GameState() { }
|
||||
virtual ~GameState() { }
|
||||
|
||||
virtual void onEnter() = 0;
|
||||
virtual void onLeave() = 0;
|
||||
|
||||
virtual void onClose() = 0;
|
||||
virtual void onInputEvent(const InputEvent& event) = 0;
|
||||
virtual void onResize(const Size& size) = 0;
|
||||
|
||||
virtual void render() = 0;
|
||||
};
|
||||
|
||||
#endif // GAMESTATE_H
|
203
src/framework/core/input.h
Normal file
203
src/framework/core/input.h
Normal file
@@ -0,0 +1,203 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
|
||||
#include "prerequisites.h"
|
||||
|
||||
enum EKeyCode {
|
||||
KC_UNKNOWN = 0x00,
|
||||
KC_ESCAPE = 0x01,
|
||||
KC_1 = 0x02,
|
||||
KC_2 = 0x03,
|
||||
KC_3 = 0x04,
|
||||
KC_4 = 0x05,
|
||||
KC_5 = 0x06,
|
||||
KC_6 = 0x07,
|
||||
KC_7 = 0x08,
|
||||
KC_8 = 0x09,
|
||||
KC_9 = 0x0A,
|
||||
KC_0 = 0x0B,
|
||||
KC_MINUS = 0x0C, // - on main keyboard
|
||||
KC_EQUALS = 0x0D,
|
||||
KC_BACK = 0x0E, // backspace
|
||||
KC_TAB = 0x0F,
|
||||
KC_Q = 0x10,
|
||||
KC_W = 0x11,
|
||||
KC_E = 0x12,
|
||||
KC_R = 0x13,
|
||||
KC_T = 0x14,
|
||||
KC_Y = 0x15,
|
||||
KC_U = 0x16,
|
||||
KC_I = 0x17,
|
||||
KC_O = 0x18,
|
||||
KC_P = 0x19,
|
||||
KC_LBRACKET = 0x1A,
|
||||
KC_RBRACKET = 0x1B,
|
||||
KC_RETURN = 0x1C, // Enter on main keyboard
|
||||
KC_LCONTROL = 0x1D,
|
||||
KC_A = 0x1E,
|
||||
KC_S = 0x1F,
|
||||
KC_D = 0x20,
|
||||
KC_F = 0x21,
|
||||
KC_G = 0x22,
|
||||
KC_H = 0x23,
|
||||
KC_J = 0x24,
|
||||
KC_K = 0x25,
|
||||
KC_L = 0x26,
|
||||
KC_SEMICOLON = 0x27,
|
||||
KC_APOSTROPHE = 0x28,
|
||||
KC_GRAVE = 0x29, // accent
|
||||
KC_LSHIFT = 0x2A,
|
||||
KC_BACKSLASH = 0x2B,
|
||||
KC_Z = 0x2C,
|
||||
KC_X = 0x2D,
|
||||
KC_C = 0x2E,
|
||||
KC_V = 0x2F,
|
||||
KC_B = 0x30,
|
||||
KC_N = 0x31,
|
||||
KC_M = 0x32,
|
||||
KC_COMMA = 0x33,
|
||||
KC_PERIOD = 0x34, // . on main keyboard
|
||||
KC_SLASH = 0x35, // / on main keyboard
|
||||
KC_RSHIFT = 0x36,
|
||||
KC_MULTIPLY = 0x37, // * on numeric keypad
|
||||
KC_LALT = 0x38, // left Alt
|
||||
KC_SPACE = 0x39,
|
||||
KC_CAPITAL = 0x3A,
|
||||
KC_F1 = 0x3B,
|
||||
KC_F2 = 0x3C,
|
||||
KC_F3 = 0x3D,
|
||||
KC_F4 = 0x3E,
|
||||
KC_F5 = 0x3F,
|
||||
KC_F6 = 0x40,
|
||||
KC_F7 = 0x41,
|
||||
KC_F8 = 0x42,
|
||||
KC_F9 = 0x43,
|
||||
KC_F10 = 0x44,
|
||||
KC_NUMLOCK = 0x45,
|
||||
KC_SCROLL = 0x46, // Scroll Lock
|
||||
KC_NUMPAD7 = 0x47,
|
||||
KC_NUMPAD8 = 0x48,
|
||||
KC_NUMPAD9 = 0x49,
|
||||
KC_SUBTRACT = 0x4A, // - on numeric keypad
|
||||
KC_NUMPAD4 = 0x4B,
|
||||
KC_NUMPAD5 = 0x4C,
|
||||
KC_NUMPAD6 = 0x4D,
|
||||
KC_ADD = 0x4E, // + on numeric keypad
|
||||
KC_NUMPAD1 = 0x4F,
|
||||
KC_NUMPAD2 = 0x50,
|
||||
KC_NUMPAD3 = 0x51,
|
||||
KC_NUMPAD0 = 0x52,
|
||||
KC_DECIMAL = 0x53, // . on numeric keypad
|
||||
KC_OEM_102 = 0x56, // < > | on UK/Germany keyboards
|
||||
KC_F11 = 0x57,
|
||||
KC_F12 = 0x58,
|
||||
KC_F13 = 0x64, // (NEC PC98)
|
||||
KC_F14 = 0x65, // (NEC PC98)
|
||||
KC_F15 = 0x66, // (NEC PC98)
|
||||
KC_KANA = 0x70, // (Japanese keyboard)
|
||||
KC_ABNT_C1 = 0x73, // / ? on Portugese (Brazilian) keyboards
|
||||
KC_CONVERT = 0x79, // (Japanese keyboard)
|
||||
KC_NOCONVERT = 0x7B, // (Japanese keyboard)
|
||||
KC_YEN = 0x7D, // (Japanese keyboard)
|
||||
KC_ABNT_C2 = 0x7E, // Numpad . on Portugese (Brazilian) keyboards
|
||||
KC_NUMPADEQUALS= 0x8D, // = on numeric keypad (NEC PC98)
|
||||
KC_PREVTRACK = 0x90, // Previous Track (KC_CIRCUMFLEX on Japanese keyboard)
|
||||
KC_AT = 0x91, // (NEC PC98)
|
||||
KC_COLON = 0x92, // (NEC PC98)
|
||||
KC_UNDERLINE = 0x93, // (NEC PC98)
|
||||
KC_KANJI = 0x94, // (Japanese keyboard)
|
||||
KC_STOP = 0x95, // (NEC PC98)
|
||||
KC_AX = 0x96, // (Japan AX)
|
||||
KC_UNLABELED = 0x97, // (J3100)
|
||||
KC_NEXTTRACK = 0x99, // Next Track
|
||||
KC_NUMPADENTER = 0x9C, // Enter on numeric keypad
|
||||
KC_RCONTROL = 0x9D,
|
||||
KC_MUTE = 0xA0, // Mute
|
||||
KC_CALCULATOR = 0xA1, // Calculator
|
||||
KC_PLAYPAUSE = 0xA2, // Play / Pause
|
||||
KC_MEDIASTOP = 0xA4, // Media Stop
|
||||
KC_VOLUMEDOWN = 0xAE, // Volume -
|
||||
KC_VOLUMEUP = 0xB0, // Volume +
|
||||
KC_WEBHOME = 0xB2, // Web home
|
||||
KC_NUMPADCOMMA = 0xB3, // , on numeric keypad (NEC PC98)
|
||||
KC_DIVIDE = 0xB5, // / on numeric keypad
|
||||
KC_SYSRQ = 0xB7,
|
||||
KC_RALT = 0xB8, // right Alt
|
||||
KC_PAUSE = 0xC5, // Pause
|
||||
KC_HOME = 0xC7, // Home on arrow keypad
|
||||
KC_UP = 0xC8, // UpArrow on arrow keypad
|
||||
KC_PGUP = 0xC9, // PgUp on arrow keypad
|
||||
KC_LEFT = 0xCB, // LeftArrow on arrow keypad
|
||||
KC_RIGHT = 0xCD, // RightArrow on arrow keypad
|
||||
KC_END = 0xCF, // End on arrow keypad
|
||||
KC_DOWN = 0xD0, // DownArrow on arrow keypad
|
||||
KC_PGDOWN = 0xD1, // PgDn on arrow keypad
|
||||
KC_INSERT = 0xD2, // Insert on arrow keypad
|
||||
KC_DELETE = 0xD3, // Delete on arrow keypad
|
||||
KC_LWIN = 0xDB, // Left Windows key
|
||||
KC_RWIN = 0xDC, // Right Windows key
|
||||
KC_APPS = 0xDD, // AppMenu key
|
||||
KC_POWER = 0xDE, // System Power
|
||||
KC_SLEEP = 0xDF, // System Sleep
|
||||
KC_WAKE = 0xE3, // System Wake
|
||||
KC_WEBSEARCH = 0xE5, // Web Search
|
||||
KC_WEBFAVORITES= 0xE6, // Web Favorites
|
||||
KC_WEBREFRESH = 0xE7, // Web Refresh
|
||||
KC_WEBSTOP = 0xE8, // Web Stop
|
||||
KC_WEBFORWARD = 0xE9, // Web Forward
|
||||
KC_WEBBACK = 0xEA, // Web Back
|
||||
KC_MYCOMPUTER = 0xEB, // My Computer
|
||||
KC_MAIL = 0xEC, // Mail
|
||||
KC_MEDIASELECT = 0xED // Media Select
|
||||
};
|
||||
|
||||
enum EEvent {
|
||||
EV_KEY_DOWN = 0,
|
||||
EV_KEY_UP,
|
||||
EV_TEXT_ENTER,
|
||||
EV_MOUSE_LDOWN,
|
||||
EV_MOUSE_LUP,
|
||||
EV_MOUSE_MDOWN,
|
||||
EV_MOUSE_MUP,
|
||||
EV_MOUSE_RDOWN,
|
||||
EV_MOUSE_RUP,
|
||||
EV_MOUSE_WHEEL_UP,
|
||||
EV_MOUSE_WHEEL_DOWN,
|
||||
EV_MOUSE_MOVE
|
||||
};
|
||||
|
||||
struct InputEvent {
|
||||
EEvent type;
|
||||
Point mousePos;
|
||||
char keychar;
|
||||
uchar keycode;
|
||||
bool ctrl;
|
||||
bool shift;
|
||||
bool alt;
|
||||
};
|
||||
|
||||
#endif // INPUT_H
|
78
src/framework/core/platform.h
Normal file
78
src/framework/core/platform.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PLATFORM_H
|
||||
#define PLATFORM_H
|
||||
|
||||
#include "prerequisites.h"
|
||||
|
||||
namespace Platform
|
||||
{
|
||||
void init(const char *appName);
|
||||
void terminate();
|
||||
|
||||
/// Poll platform input/window events
|
||||
void poll();
|
||||
|
||||
/// Get current time in milliseconds since init
|
||||
int getTicks();
|
||||
/// Sleep in current thread
|
||||
void sleep(ulong miliseconds);
|
||||
|
||||
bool createWindow(int x, int y, int width, int height, int minWidth, int minHeight, bool maximized);
|
||||
void destroyWindow();
|
||||
void showWindow();
|
||||
void setWindowTitle(const char *title);
|
||||
bool isWindowFocused();
|
||||
bool isWindowVisible();
|
||||
int getWindowX();
|
||||
int getWindowY();
|
||||
int getWindowWidth();
|
||||
int getWindowHeight();
|
||||
bool isWindowMaximized();
|
||||
|
||||
int getDisplayHeight();
|
||||
int getDisplayWidth();
|
||||
|
||||
/// Get GL extension function address
|
||||
void *getExtensionProcAddress(const char *ext);
|
||||
/// Check if GL extension is supported
|
||||
bool isExtensionSupported(const char *ext);
|
||||
|
||||
const char *getClipboardText();
|
||||
void setClipboardText(const char *text);
|
||||
|
||||
void hideMouseCursor();
|
||||
void showMouseCursor();
|
||||
|
||||
/// Enable/disable vertical synchronization
|
||||
void setVsync(bool enable = true);
|
||||
/// Swap GL buffers
|
||||
void swapBuffers();
|
||||
|
||||
/// Get the app user directory, the place to save files configurations files
|
||||
std::string getAppUserDir();
|
||||
}
|
||||
|
||||
#endif // PLATFORM_H
|
121
src/framework/core/resources.cpp
Normal file
121
src/framework/core/resources.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 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 "resources.h"
|
||||
|
||||
#include <physfs.h>
|
||||
|
||||
Resources g_resources;
|
||||
|
||||
void Resources::init(const char *argv0)
|
||||
{
|
||||
PHYSFS_init(argv0);
|
||||
}
|
||||
|
||||
void Resources::terminate()
|
||||
{
|
||||
PHYSFS_deinit();
|
||||
}
|
||||
|
||||
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.", 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());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Resources::fileExists(const std::string& filePath)
|
||||
{
|
||||
return PHYSFS_exists(filePath.c_str());
|
||||
}
|
||||
|
||||
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());
|
||||
*fileSize = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*fileSize = PHYSFS_fileLength(file);
|
||||
uchar *buffer = new uchar[*fileSize + 1];
|
||||
PHYSFS_read(file, (void*)buffer, 1, *fileSize);
|
||||
buffer[*fileSize] = 0;
|
||||
PHYSFS_close(file);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::string Resources::loadTextFile(const std::string& fileName)
|
||||
{
|
||||
std::string text;
|
||||
uint fileSize;
|
||||
char *buffer = (char *)loadFile(fileName, &fileSize);
|
||||
if(buffer) {
|
||||
text.assign(buffer);
|
||||
delete[] buffer;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
bool Resources::saveFile(const std::string &fileName, const uchar *data, uint size)
|
||||
{
|
||||
PHYSFS_file *file = PHYSFS_openWrite(fileName.c_str());
|
||||
if(!file) {
|
||||
logError("Failed to save file \"%s\": %s", fileName.c_str(), PHYSFS_getLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
PHYSFS_write(file, (void*)data, size, 1);
|
||||
PHYSFS_close(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Resources::saveTextFile(const std::string &fileName, std::string text)
|
||||
{
|
||||
return saveFile(fileName, (const uchar*)text.c_str(), text.size());
|
||||
}
|
||||
|
||||
std::list<std::string> Resources::getDirectoryFiles(const std::string& directory)
|
||||
{
|
||||
std::list<std::string> files;
|
||||
char **rc = PHYSFS_enumerateFiles(directory.c_str());
|
||||
|
||||
for(char **i = rc; *i != NULL; i++)
|
||||
files.push_back(*i);
|
||||
|
||||
PHYSFS_freeList(rc);
|
||||
return files;
|
||||
}
|
72
src/framework/core/resources.h
Normal file
72
src/framework/core/resources.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef RESOURCES_H
|
||||
#define RESOURCES_H
|
||||
|
||||
#include "prerequisites.h"
|
||||
|
||||
class Resources
|
||||
{
|
||||
public:
|
||||
Resources() { }
|
||||
|
||||
void init(const char *argv0);
|
||||
void terminate();
|
||||
|
||||
/// Sets the write directory
|
||||
bool setWriteDir(const std::string &path);
|
||||
|
||||
/// Adds a directory or zip archive to the search path
|
||||
bool addToSearchPath(const std::string& path, bool insertInFront = true);
|
||||
|
||||
/// Checks whether the given file exists in the search path
|
||||
bool fileExists(const std::string& filePath);
|
||||
|
||||
/// Searches for zip files and adds them to the search path
|
||||
void searchAndAddArchives(const std::string &path,
|
||||
const std::string &ext,
|
||||
const bool append);
|
||||
|
||||
/** Load a file by allocating a buffer and filling it with the file contents
|
||||
* where fileSize will be set to the file size.
|
||||
* The returned buffer must be freed with delete[]. */
|
||||
uchar *loadFile(const std::string &fileName, uint *fileSize);
|
||||
|
||||
/// Loads a text file into a std::string
|
||||
std::string loadTextFile(const std::string &fileName);
|
||||
|
||||
/// Save a file into write directory
|
||||
bool saveFile(const std::string &fileName, const uchar *data, uint size);
|
||||
|
||||
/// Save a text file into write directory
|
||||
bool saveTextFile(const std::string &fileName, std::string text);
|
||||
|
||||
/// Get a list with all files in a directory
|
||||
std::list<std::string> getDirectoryFiles(const std::string& directory);
|
||||
};
|
||||
|
||||
extern Resources g_resources;
|
||||
|
||||
#endif // RESOURCES_H
|
Reference in New Issue
Block a user