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

@ -24,19 +24,18 @@
#include "sharedstate.h"
#include "eventthread.h"
#include "filesystem.h"
#include "util.h"
#include "debugwriter.h"
#include "./ruby/include/ruby.h"
#include "./ruby/include/ruby/encoding.h"
#include <ruby.h>
#include <ruby/encoding.h>
#include <string>
#include <zlib.h>
#include <SDL_filesystem.h>
#include <QFile>
#include <QByteArray>
#include <QDebug>
extern const char module_rpg[];
static void mriBindingExecute();
@ -102,9 +101,9 @@ static void mriBindingInit()
}
static void
showMsg(const QByteArray &msg)
showMsg(const std::string &msg)
{
shState->eThread().showMessageBox(msg.constData());
shState->eThread().showMessageBox(msg.c_str());
}
RB_METHOD(mkxpPuts)
@ -114,7 +113,7 @@ RB_METHOD(mkxpPuts)
const char *str;
rb_get_args(argc, argv, "z", &str RB_ARG_END);
qDebug() << str;
Debug() << str;
return Qnil;
}
@ -174,49 +173,45 @@ RB_METHOD(mriDataDirectory)
static void runCustomScript(const char *filename)
{
QFile scriptFile(filename);
if (!scriptFile.open(QFile::ReadOnly))
std::string scriptData("#encoding:utf-8\n");
if (!readFile(filename, scriptData))
{
showMsg(QByteArray("Unable to open '") + filename + "'");
showMsg(std::string("Unable to open '") + filename + "'");
return;
}
QByteArray scriptData = scriptFile.readAll();
scriptFile.close();
scriptData.prepend("#encoding:utf-8\n");
rb_eval_string_protect(scriptData.constData(), 0);
rb_eval_string_protect(scriptData.c_str(), 0);
}
VALUE kernelLoadDataInt(const char *filename);
struct Script
{
QByteArray name;
QByteArray encData;
std::string name;
std::string encData;
uint32_t unknown;
QByteArray decData;
std::string decData;
};
static void runRMXPScripts()
{
const QByteArray &scriptPack = shState->rtData().config.game.scripts;
const std::string &scriptPack = shState->rtData().config.game.scripts;
if (scriptPack.isEmpty())
if (scriptPack.empty())
{
showMsg("No game scripts specified (missing Game.ini?)");
return;
}
if (!shState->fileSystem().exists(scriptPack.constData()))
if (!shState->fileSystem().exists(scriptPack.c_str()))
{
showMsg("Unable to open '" + scriptPack + "'");
return;
}
VALUE scriptArray = kernelLoadDataInt(scriptPack.constData());
VALUE scriptArray = kernelLoadDataInt(scriptPack.c_str());
if (rb_type(scriptArray) != RUBY_T_ARRAY)
{
@ -226,7 +221,7 @@ static void runRMXPScripts()
size_t scriptCount = RARRAY_LEN(scriptArray);
QByteArray decodeBuffer;
std::string decodeBuffer;
decodeBuffer.resize(0x1000);
std::vector<Script> encScripts(scriptCount);
@ -246,7 +241,7 @@ static void runRMXPScripts()
Script &sc = encScripts[i];
sc.name = RSTRING_PTR(scriptName);
sc.encData = QByteArray(RSTRING_PTR(scriptString), RSTRING_LEN(scriptString));
sc.encData = std::string(RSTRING_PTR(scriptString), RSTRING_LEN(scriptString));
sc.unknown = FIX2UINT(scriptUnknown);
}
@ -260,9 +255,9 @@ static void runRMXPScripts()
while (true)
{
unsigned char *bufferPtr =
reinterpret_cast<unsigned char*>(const_cast<char*>(decodeBuffer.constData()));
reinterpret_cast<unsigned char*>(const_cast<char*>(decodeBuffer.c_str()));
const unsigned char *sourcePtr =
reinterpret_cast<const unsigned char*>(sc.encData.constData());
reinterpret_cast<const unsigned char*>(sc.encData.c_str());
bufferLen = decodeBuffer.length();
@ -282,21 +277,25 @@ static void runRMXPScripts()
static char buffer[256];
/* FIXME: '%zu' apparently gcc only? */
snprintf(buffer, sizeof(buffer), "Error decoding script %zu: '%s'",
i, sc.name.constData());
i, sc.name.c_str());
showMsg(buffer);
break;
}
sc.decData = QByteArray(decodeBuffer.constData(), bufferLen);
sc.decData.prepend("#encoding:utf-8\n");
/* Store encoding header + the decoded script
* in 'sc.decData' */
sc.decData = "#encoding:utf-8\n";
size_t hdSize = sc.decData.size();
sc.decData.resize(hdSize + bufferLen);
memcpy(&sc.decData[hdSize], decodeBuffer.c_str(), bufferLen);
ruby_script(sc.name.constData());
ruby_script(sc.name.c_str());
rb_gc_start();
/* Execute code */
rb_eval_string_protect(sc.decData.constData(), 0);
rb_eval_string_protect(sc.decData.c_str(), 0);
VALUE exc = rb_gv_get("$!");
if (rb_type(exc) != RUBY_T_NIL)
@ -314,23 +313,23 @@ static void mriBindingExecute()
mriBindingInit();
QByteArray &customScript = shState->rtData().config.customScript;
if (!customScript.isEmpty())
runCustomScript(customScript.constData());
std::string &customScript = shState->rtData().config.customScript;
if (!customScript.empty())
runCustomScript(customScript.c_str());
else
runRMXPScripts();
VALUE exc = rb_gv_get("$!");
if (rb_type(exc) != RUBY_T_NIL && !rb_eql(rb_obj_class(exc), rb_eSystemExit))
{
qDebug() << "Had exception:" << rb_class2name(rb_obj_class(exc));
Debug() << "Had exception:" << rb_class2name(rb_obj_class(exc));
VALUE bt = rb_funcall(exc, rb_intern("backtrace"), 0);
rb_p(bt);
VALUE msg = rb_funcall(exc, rb_intern("message"), 0);
if (RSTRING_LEN(msg) < 256)
showMsg(RSTRING_PTR(msg));
else
qDebug() << (RSTRING_PTR(msg));
Debug() << (RSTRING_PTR(msg));
}
ruby_cleanup(0);

View file

@ -26,8 +26,7 @@
#include "util.h"
#include <stdarg.h>
#include <QDebug>
#include <assert.h>
void initType(rb_data_type_struct &type,
const char *name,
@ -244,7 +243,7 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)
}
}
#ifndef QT_NO_DEBUG
#ifndef NDEBUG
/* Pop remaining arg pointers off
* the stack to check for RB_ARG_END */
@ -288,8 +287,8 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)
/* Verify correct termination */
void *argEnd = va_arg(ap, void*);
Q_UNUSED(argEnd);
Q_ASSERT(argEnd == RB_ARG_END_VAL);
(void) argEnd;
assert(argEnd == RB_ARG_END_VAL);
#endif

View file

@ -22,7 +22,7 @@
#ifndef BINDING_UTIL_H
#define BINDING_UTIL_H
#include "./ruby/ruby.h"
#include <ruby.h>
enum RbException
{
@ -134,7 +134,7 @@ int
rb_get_args(int argc, VALUE *argv, const char *format, ...);
/* Always terminate 'rb_get_args' with this */
#ifndef QT_NO_DEBUG
#ifndef NDEBUG
# define RB_ARG_END_VAL ((void*) -1)
# define RB_ARG_END ,RB_ARG_END_VAL
#else

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

@ -23,8 +23,6 @@
#include "binding-util.h"
#include "serializable-binding.h"
#include <QDebug>
DEF_TYPE(Color);
DEF_TYPE(Tone);
DEF_TYPE(Rect);

View file

@ -27,8 +27,6 @@
#include "ruby/encoding.h"
#include "ruby/intern.h"
#include <QDebug>
DEF_TYPE(FileInt);
static VALUE