Transition from QtCore to stdc++ / STL / boost

This looks like a pretty major change, but in reality,
80% of it is just renames of types and corresponding
methods.

The config parsing code has been completely replaced
with a boost::program_options based version. This
means that the config file format slightly changed
(checkout the updated README).

I still expect there to be bugs / unforseen events.
Those should be fixed in follow up commits.

Also, finally reverted back to using pkg-config to
locate and link libruby. Yay for less hacks!
This commit is contained in:
Jonas Kulla 2013-12-11 20:46:54 +01:00
parent 01529c5741
commit 2adf8ab265
40 changed files with 722 additions and 456 deletions

View file

@ -30,11 +30,11 @@
#include <mruby/proc.h>
#include <mruby/dump.h>
#include "binding-util.h"
#include <stdio.h>
#include <zlib.h>
#include <string>
#include <SDL_messagebox.h>
#include <SDL_rwops.h>
#include <SDL_timer.h>
@ -45,6 +45,7 @@
#include "filesystem.h"
#include "exception.h"
#include "binding-util.h"
#include "binding-types.h"
#include "mrb-ext/marshal.h"
@ -180,9 +181,9 @@ checkException(mrb_state *mrb)
static void
showError(const QByteArray &msg)
showError(const std::string &msg)
{
shState->eThread().showMessageBox(msg.constData());
shState->eThread().showMessageBox(msg.c_str());
}
static void
@ -245,17 +246,17 @@ runMrbFile(mrb_state *mrb, const char *filename)
static void
runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
{
const QByteArray &scriptPack = shState->rtData().config.game.scripts;
const std::string &scriptPack = shState->rtData().config.game.scripts;
if (scriptPack.isEmpty())
if (scriptPack.empty())
{
showError("No game scripts specified (missing Game.ini?)");
return;
}
if (!shState->fileSystem().exists(scriptPack.constData()))
if (!shState->fileSystem().exists(scriptPack.c_str()))
{
showError("Unable to open '" + scriptPack + "'");
showError(std::string("Unable to open '") + scriptPack + "'");
return;
}
@ -263,10 +264,10 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
mrb_state *scriptMrb = mrb_open();
SDL_RWops ops;
shState->fileSystem().openRead(ops, scriptPack.constData());
shState->fileSystem().openRead(ops, scriptPack.c_str());
mrb_value scriptArray = mrb_nil_value();
QByteArray readError;
std::string readError;
try
{
@ -275,22 +276,22 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
catch (const Exception &e)
{
char buffer[512];
snprintf(buffer, sizeof(buffer), e.fmt.constData(), e.arg1.constData(), e.arg2.constData());
readError = QByteArray(": ") + QByteArray(buffer);
snprintf(buffer, sizeof(buffer), e.fmt.c_str(), e.arg1.c_str(), e.arg2.c_str());
readError = std::string(": ") + std::string(buffer);
}
SDL_RWclose(&ops);
if (!mrb_array_p(scriptArray))
{
showError(QByteArray("Failed to read script data") + readError);
showError(std::string("Failed to read script data") + readError);
mrb_close(scriptMrb);
return;
}
int scriptCount = mrb_ary_len(scriptMrb, scriptArray);
QByteArray decodeBuffer;
std::string decodeBuffer;
decodeBuffer.resize(0x1000);
for (int i = 0; i < scriptCount; ++i)
@ -309,7 +310,7 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
while (true)
{
unsigned char *bufferPtr =
reinterpret_cast<unsigned char*>(const_cast<char*>(decodeBuffer.constData()));
reinterpret_cast<unsigned char*>(const_cast<char*>(decodeBuffer.c_str()));
unsigned char *sourcePtr =
reinterpret_cast<unsigned char*>(RSTRING_PTR(scriptString));
@ -342,7 +343,7 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
int ai = mrb_gc_arena_save(mrb);
/* Execute code */
mrb_load_nstring_cxt(mrb, decodeBuffer.constData(), bufferLen, ctx);
mrb_load_nstring_cxt(mrb, decodeBuffer.c_str(), bufferLen, ctx);
mrb_gc_arena_restore(mrb, ai);
@ -370,14 +371,15 @@ static void mrbBindingExecute()
mrbc_context *ctx = mrbc_context_new(mrb);
ctx->capture_errors = 1;
Config &conf = shState->rtData().config;
QByteArray &customScript = conf.customScript;
QByteArray mrbFile = conf.bindingConf.value("mrbFile").toByteArray();
const Config &conf = shState->rtData().config;
const std::string &customScript = conf.customScript;
// const std::string &mrbFile = conf.mrbFile;
(void) runMrbFile; // FIXME mrbFile support on ice for now
if (!customScript.isEmpty())
runCustomScript(mrb, ctx, customScript.constData());
else if (!mrbFile.isEmpty())
runMrbFile(mrb, mrbFile.constData());
if (!customScript.empty())
runCustomScript(mrb, ctx, customScript.c_str());
// else if (!mrbFile.empty())
// runMrbFile(mrb, mrbFile.c_str());
else
runRMXPScripts(mrb, ctx);

View file

@ -26,8 +26,6 @@
#include "binding-util.h"
#include "binding-types.h"
#include <QDebug>
#define DISP_CLASS_NAME "bitmap"
DEF_TYPE(Bitmap);

View file

@ -25,6 +25,8 @@
#include "disposable.h"
#include "binding-util.h"
#include <string.h>
template<class C>
MRB_METHOD(disposableDispose)
{

View file

@ -24,8 +24,6 @@
#include "binding-types.h"
#include "serializable-binding.h"
#include <QDebug>
#define ATTR_RW(Type, attr, arg_type, mrb_val, arg_t_s) \
MRB_METHOD(Type##Get_##attr) \
{ \

View file

@ -21,6 +21,8 @@
#include "file.h"
#include "debugwriter.h"
#include "../binding-util.h"
#include <mruby/string.h>
#include <mruby/array.h>
@ -36,8 +38,6 @@
#include <vector>
#include <QDebug>
extern mrb_value timeFromSecondsInt(mrb_state *mrb, time_t seconds);
static void
@ -87,7 +87,7 @@ getOpenMode(const char *mode)
STR_CASE("a", Write)
STR_CASE("a+", ReadWrite)
qDebug() << "getOpenMode failed for:" << mode;
Debug() << "getOpenMode failed for:" << mode;
return 0;
}
@ -225,7 +225,7 @@ MRB_FUNCTION(fileExpandPath)
// FIXME No idea how to integrate 'default_dir' right now
if (defDir)
qDebug() << "FIXME: File.expand_path: default_dir not implemented";
Debug() << "FIXME: File.expand_path: default_dir not implemented";
char buffer[512];
char *unused = realpath(path, buffer);
@ -457,7 +457,7 @@ MRB_METHOD(fileReadLines)
const char *rs = "\n"; (void) rs;
if (mrb->c->ci->argc > 0)
{
qDebug() << "FIXME: File.readlines: rs not implemented";
Debug() << "FIXME: File.readlines: rs not implemented";
if (mrb_string_p(arg))
rs = RSTRING_PTR(arg);

View file

@ -36,8 +36,6 @@
#include "filesystem.h"
#include "binding.h"
#include <QDebug>
void mrbBindingTerminate();
MRB_FUNCTION(kernelEval)

View file

@ -38,14 +38,11 @@
#include "file.h"
#include "rwmem.h"
#include "exception.h"
#include "boost-hash.h"
#include "debugwriter.h"
#include <SDL_timer.h>
#include <QHash>
#include <QByteArray>
#include <QDebug>
#define MARSHAL_MAJOR 4
#define MARSHAL_MINOR 8
@ -76,9 +73,9 @@
// FIXME make these dynamically allocatd, per MarshalContext
static char gpbuffer[512];
inline uint qHash(mrb_value key)
inline size_t hash_value(mrb_value key)
{
return qHash(key.value.p);
return boost::hash_value(key.value.p);
}
inline bool operator==(mrb_value v1, mrb_value v2)
@ -109,7 +106,7 @@ template<typename T>
struct LinkBuffer
{
/* Key: val, Value: idx in vec */
QHash<T, int> hash;
BoostHash<T, int> hash;
std::vector<T> vec;
bool contains(T value)
@ -551,9 +548,8 @@ read_value(MarshalContext *ctx)
break;
default :
qDebug() << "Value type" << (char)type << "not supported!";
throw Exception(Exception::MKXPError, "Marshal.load: unsupported value type '%s'",
QByteArray(1, (char)type));
std::string(1, (char)type));
}
mrb_gc_arena_restore(mrb, arena);
@ -973,7 +969,7 @@ MRB_FUNCTION(marshalLoad)
}
else
{
qDebug() << "FIXME: Marshal.load: generic IO port not implemented";
Debug() << "FIXME: Marshal.load: generic IO port not implemented";
return mrb_nil_value();
}

View file

@ -24,8 +24,6 @@
#include "binding-types.h"
#include "serializable-binding.h"
#include <QDebug>
DEF_TYPE(Table);
MRB_METHOD(tableInitialize)