mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-04-21 21:52:04 +02:00
Remove mruby and null bindings
This commit is contained in:
parent
4e6613d0e1
commit
2ec1e444c0
67 changed files with 29 additions and 8271 deletions
|
@ -9,7 +9,7 @@ This is a work-in-progress fork of mkxp that is intended to run as similarly to
|
||||||
mkxp primarily targets technically versed users that are comfortable with Ruby / RGSS, and ideally know how to compile the project themselves. The reason for this is that for most games, due to Win32-API usage, mkxp is simply not a plug-and-play solution, but a building block with which a fully cross-platform version can be created in time.
|
mkxp primarily targets technically versed users that are comfortable with Ruby / RGSS, and ideally know how to compile the project themselves. The reason for this is that for most games, due to Win32-API usage, mkxp is simply not a plug-and-play solution, but a building block with which a fully cross-platform version can be created in time.
|
||||||
|
|
||||||
## Bindings
|
## Bindings
|
||||||
Bindings provide the glue code for an interpreted language environment to run game scripts in. Although mkxp-z still contains all pre-existing bindings at the moment, mkxp-z focuses on Ruby 1.8 and as such it isn't unlikely that the other bindings may even be removed completely. Please see the original README for more details.
|
Bindings provide the glue code for an interpreted language environment to run game scripts in. mkxp-z focuses on Ruby 1.8 and as such the mruby and null bindings are not included. The original MRI bindings remain for the time being. Please see the original README for more details.
|
||||||
|
|
||||||
### MRI
|
### MRI
|
||||||
Website: https://www.ruby-lang.org/en/
|
Website: https://www.ruby-lang.org/en/
|
||||||
|
@ -21,7 +21,7 @@ http://stackoverflow.com/questions/21574/what-is-the-difference-between-ruby-1-8
|
||||||
|
|
||||||
This binding supports RGSS1, RGSS2 and RGSS3.
|
This binding supports RGSS1, RGSS2 and RGSS3.
|
||||||
|
|
||||||
> Note: Support for Ruby 1.8 has been added, but the binding is unfinished and experimental. I have made sure that a game (Ao Oni) starts, but I have not tested anything extensively.
|
> Note: Support for Ruby 1.8 has been added, but the binding is unfinished and experimental.
|
||||||
|
|
||||||
## Dependencies / Building
|
## Dependencies / Building
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ This binding supports RGSS1, RGSS2 and RGSS3.
|
||||||
* SDL2*
|
* SDL2*
|
||||||
* SDL2_image
|
* SDL2_image
|
||||||
* SDL2_ttf
|
* SDL2_ttf
|
||||||
* [my SDL_sound fork](https://github.com/Ancurio/SDL_sound)
|
* [Ancurio's SDL_sound fork](https://github.com/Ancurio/SDL_sound)
|
||||||
* vorbisfile
|
* vorbisfile
|
||||||
* pixman
|
* pixman
|
||||||
* zlib (only ruby bindings)
|
* zlib (only ruby bindings)
|
||||||
|
@ -43,7 +43,7 @@ This binding supports RGSS1, RGSS2 and RGSS3.
|
||||||
|
|
||||||
(* For the F1 menu to work correctly under Linux/X11, you need latest hg + [this patch](https://bugzilla.libsdl.org/show_bug.cgi?id=2745))
|
(* For the F1 menu to work correctly under Linux/X11, you need latest hg + [this patch](https://bugzilla.libsdl.org/show_bug.cgi?id=2745))
|
||||||
|
|
||||||
mkxp employs Qt's qmake build system, so you'll need to install that beforehand. Alternatively, you can build with cmake (FIXME: mkxp-z significantly altered the build system, fix everything in this section).
|
mkxp employs Qt's qmake build system, so you'll need to install that beforehand. Alternatively, you can build with cmake (*FIXME: mkxp-z significantly altered the build system, fix everything in this section*).
|
||||||
|
|
||||||
qmake will use pkg-config to locate the respective include/library paths. If you installed any dependencies into non-standard prefixes, make sure to adjust your `PKG_CONFIG_PATH` variable accordingly.
|
qmake will use pkg-config to locate the respective include/library paths. If you installed any dependencies into non-standard prefixes, make sure to adjust your `PKG_CONFIG_PATH` variable accordingly.
|
||||||
|
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
/*
|
|
||||||
** audio-binding.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "audio.h"
|
|
||||||
#include "sharedstate.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "exception.h"
|
|
||||||
|
|
||||||
#define DEF_PLAY_STOP(entity) \
|
|
||||||
MRB_FUNCTION(audio_##entity##Play) \
|
|
||||||
{ \
|
|
||||||
char *filename; \
|
|
||||||
mrb_int volume = 100; \
|
|
||||||
mrb_int pitch = 100; \
|
|
||||||
mrb_get_args(mrb, "z|ii", &filename, &volume, &pitch); \
|
|
||||||
GUARD_EXC( shState->audio().entity##Play(filename, volume, pitch); ) \
|
|
||||||
return mrb_nil_value(); \
|
|
||||||
} \
|
|
||||||
MRB_FUNCTION(audio_##entity##Stop) \
|
|
||||||
{ \
|
|
||||||
MRB_FUN_UNUSED_PARAM; \
|
|
||||||
shState->audio().entity##Stop(); \
|
|
||||||
return mrb_nil_value(); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEF_FADE(entity) \
|
|
||||||
MRB_FUNCTION(audio_##entity##Fade) \
|
|
||||||
{ \
|
|
||||||
mrb_int time; \
|
|
||||||
mrb_get_args(mrb, "i", &time); \
|
|
||||||
shState->audio().entity##Fade(time); \
|
|
||||||
return mrb_nil_value(); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEF_PLAY_STOP_FADE(entity) \
|
|
||||||
DEF_PLAY_STOP(entity) \
|
|
||||||
DEF_FADE(entity)
|
|
||||||
|
|
||||||
DEF_PLAY_STOP_FADE( bgm )
|
|
||||||
DEF_PLAY_STOP_FADE( bgs )
|
|
||||||
DEF_PLAY_STOP_FADE( me )
|
|
||||||
|
|
||||||
DEF_PLAY_STOP( se )
|
|
||||||
|
|
||||||
|
|
||||||
#define BIND_PLAY_STOP(entity) \
|
|
||||||
mrb_define_module_function(mrb, module, #entity "_play", audio_##entity##Play, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(2)); \
|
|
||||||
mrb_define_module_function(mrb, module, #entity "_stop", audio_##entity##Stop, MRB_ARGS_NONE());
|
|
||||||
|
|
||||||
#define BIND_FADE(entity) \
|
|
||||||
mrb_define_module_function(mrb, module, #entity "_fade", audio_##entity##Fade, MRB_ARGS_REQ(1));
|
|
||||||
|
|
||||||
#define BIND_PLAY_STOP_FADE(entity) \
|
|
||||||
BIND_PLAY_STOP(entity) \
|
|
||||||
BIND_FADE(entity)
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
audioBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
RClass *module = mrb_define_module(mrb, "Audio");
|
|
||||||
|
|
||||||
BIND_PLAY_STOP_FADE( bgm )
|
|
||||||
BIND_PLAY_STOP_FADE( bgs )
|
|
||||||
BIND_PLAY_STOP_FADE( me )
|
|
||||||
|
|
||||||
BIND_PLAY_STOP( se )
|
|
||||||
}
|
|
|
@ -1,416 +0,0 @@
|
||||||
/*
|
|
||||||
** binding-mruby.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "binding.h"
|
|
||||||
|
|
||||||
#include <mruby.h>
|
|
||||||
#include <mruby/string.h>
|
|
||||||
#include <mruby/array.h>
|
|
||||||
#include <mruby/class.h>
|
|
||||||
#include <mruby/irep.h>
|
|
||||||
#include <mruby/compile.h>
|
|
||||||
#include <mruby/proc.h>
|
|
||||||
#include <mruby/dump.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <zlib.h>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <SDL_messagebox.h>
|
|
||||||
#include <SDL_rwops.h>
|
|
||||||
#include <SDL_timer.h>
|
|
||||||
|
|
||||||
#include "sharedstate.h"
|
|
||||||
#include "texpool.h"
|
|
||||||
#include "eventthread.h"
|
|
||||||
#include "filesystem.h"
|
|
||||||
#include "exception.h"
|
|
||||||
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
|
||||||
#include "mrb-ext/marshal.h"
|
|
||||||
|
|
||||||
static void mrbBindingExecute();
|
|
||||||
static void mrbBindingTerminate();
|
|
||||||
static void mrbBindingReset();
|
|
||||||
|
|
||||||
ScriptBinding scriptBindingImpl =
|
|
||||||
{
|
|
||||||
mrbBindingExecute,
|
|
||||||
mrbBindingTerminate,
|
|
||||||
mrbBindingReset
|
|
||||||
};
|
|
||||||
|
|
||||||
ScriptBinding *scriptBinding = &scriptBindingImpl;
|
|
||||||
|
|
||||||
|
|
||||||
void fileBindingInit(mrb_state *);
|
|
||||||
void timeBindingInit(mrb_state *);
|
|
||||||
void marshalBindingInit(mrb_state *);
|
|
||||||
void kernelBindingInit(mrb_state *);
|
|
||||||
|
|
||||||
void tableBindingInit(mrb_state *);
|
|
||||||
void etcBindingInit(mrb_state *);
|
|
||||||
void fontBindingInit(mrb_state *);
|
|
||||||
void bitmapBindingInit(mrb_state *);
|
|
||||||
void spriteBindingInit(mrb_state *);
|
|
||||||
void planeBindingInit(mrb_state *);
|
|
||||||
void viewportBindingInit(mrb_state *);
|
|
||||||
void windowBindingInit(mrb_state *);
|
|
||||||
void tilemapBindingInit(mrb_state *);
|
|
||||||
|
|
||||||
void inputBindingInit(mrb_state *);
|
|
||||||
void audioBindingInit(mrb_state *);
|
|
||||||
void graphicsBindingInit(mrb_state *);
|
|
||||||
|
|
||||||
/* From module_rpg.c */
|
|
||||||
extern const uint8_t mrbModuleRPG[];
|
|
||||||
|
|
||||||
static void mrbBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
int arena = mrb_gc_arena_save(mrb);
|
|
||||||
|
|
||||||
/* Init standard classes */
|
|
||||||
fileBindingInit(mrb);
|
|
||||||
timeBindingInit(mrb);
|
|
||||||
marshalBindingInit(mrb);
|
|
||||||
kernelBindingInit(mrb);
|
|
||||||
|
|
||||||
/* Init RGSS classes */
|
|
||||||
tableBindingInit(mrb);
|
|
||||||
etcBindingInit(mrb);
|
|
||||||
fontBindingInit(mrb);
|
|
||||||
bitmapBindingInit(mrb);
|
|
||||||
spriteBindingInit(mrb);
|
|
||||||
planeBindingInit(mrb);
|
|
||||||
viewportBindingInit(mrb);
|
|
||||||
windowBindingInit(mrb);
|
|
||||||
tilemapBindingInit(mrb);
|
|
||||||
|
|
||||||
/* Init RGSS modules */
|
|
||||||
inputBindingInit(mrb);
|
|
||||||
audioBindingInit(mrb);
|
|
||||||
graphicsBindingInit(mrb);
|
|
||||||
|
|
||||||
/* Load RPG module */
|
|
||||||
mrb_load_irep(mrb, mrbModuleRPG);
|
|
||||||
|
|
||||||
/* Load global constants */
|
|
||||||
mrb_define_global_const(mrb, "MKXP", mrb_true_value());
|
|
||||||
|
|
||||||
mrb_value debug = rb_bool_new(shState->config().editor.debug);
|
|
||||||
if (rgssVer == 1)
|
|
||||||
mrb_define_global_const(mrb, "DEBUG", debug);
|
|
||||||
else if (rgssVer >= 2)
|
|
||||||
mrb_define_global_const(mrb, "TEST", debug);
|
|
||||||
|
|
||||||
mrb_define_global_const(mrb, "BTEST", mrb_bool_value(shState->config().editor.battleTest));
|
|
||||||
|
|
||||||
mrb_gc_arena_restore(mrb, arena);
|
|
||||||
}
|
|
||||||
|
|
||||||
static mrb_value
|
|
||||||
mkxpTimeOp(mrb_state *mrb, mrb_value)
|
|
||||||
{
|
|
||||||
mrb_int iterations = 1;
|
|
||||||
const char *opName = "";
|
|
||||||
mrb_value block;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "|iz&", &iterations, &opName, &block);
|
|
||||||
|
|
||||||
Uint64 start = SDL_GetPerformanceCounter();
|
|
||||||
|
|
||||||
for (int i = 0; i < iterations; ++i)
|
|
||||||
mrb_yield(mrb, block, mrb_nil_value());
|
|
||||||
|
|
||||||
Uint64 diff = SDL_GetPerformanceCounter() - start;
|
|
||||||
double avg = (double) diff / iterations;
|
|
||||||
|
|
||||||
double sec = avg / SDL_GetPerformanceFrequency();
|
|
||||||
float ms = sec * 1000;
|
|
||||||
|
|
||||||
printf("<%s> [%f ms]\n", opName, ms);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
return mrb_float_value(mrb, ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *
|
|
||||||
mrbValueString(mrb_value value)
|
|
||||||
{
|
|
||||||
return mrb_string_p(value) ? RSTRING_PTR(value) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
showExcMessageBox(mrb_state *mrb, mrb_value exc)
|
|
||||||
{
|
|
||||||
/* Display actual exception in a message box */
|
|
||||||
mrb_value mesg = mrb_funcall(mrb, exc, "message", 0);
|
|
||||||
mrb_value line = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "line"));
|
|
||||||
mrb_value file = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "file"));
|
|
||||||
const char *excClass = mrb_class_name(mrb, mrb_class(mrb, exc));
|
|
||||||
|
|
||||||
char msgBoxText[512];
|
|
||||||
snprintf(msgBoxText, sizeof(msgBoxText), "Script '%s' line %d: %s occured.\n\n%s",
|
|
||||||
mrbValueString(file), mrb_fixnum(line), excClass, mrbValueString(mesg));
|
|
||||||
|
|
||||||
shState->eThread().showMessageBox(msgBoxText, SDL_MESSAGEBOX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
checkException(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
if (!mrb->exc)
|
|
||||||
return;
|
|
||||||
|
|
||||||
mrb_value exc = mrb_obj_value(mrb->exc);
|
|
||||||
MrbData &mrbData = *getMrbData(mrb);
|
|
||||||
|
|
||||||
/* Check if an actual exception occured, or just a shutdown was called */
|
|
||||||
if (mrb_obj_class(mrb, exc) != mrbData.exc[Shutdown])
|
|
||||||
showExcMessageBox(mrb, exc);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
showError(const std::string &msg)
|
|
||||||
{
|
|
||||||
shState->eThread().showMessageBox(msg.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
runCustomScript(mrb_state *mrb, mrbc_context *ctx, const char *filename)
|
|
||||||
{
|
|
||||||
/* Execute custom script */
|
|
||||||
FILE *f = fopen(filename, "rb");
|
|
||||||
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
static char buffer[256];
|
|
||||||
snprintf(buffer, sizeof(buffer), "Unable to open script '%s'", filename);
|
|
||||||
showError(buffer);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->filename = strdup(filename);
|
|
||||||
ctx->lineno = 1;
|
|
||||||
|
|
||||||
/* Run code */
|
|
||||||
mrb_load_file_cxt(mrb, f, ctx);
|
|
||||||
|
|
||||||
free(ctx->filename);
|
|
||||||
fclose(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
runMrbFile(mrb_state *mrb, const char *filename)
|
|
||||||
{
|
|
||||||
/* Execute compiled script */
|
|
||||||
FILE *f = fopen(filename, "rb");
|
|
||||||
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
static char buffer[256];
|
|
||||||
snprintf(buffer, sizeof(buffer), "Unable to open compiled script '%s'", filename);
|
|
||||||
showError(buffer);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mrb_irep *irep = mrb_read_irep_file(mrb, f);
|
|
||||||
|
|
||||||
if (!irep)
|
|
||||||
{
|
|
||||||
static char buffer[256];
|
|
||||||
snprintf(buffer, sizeof(buffer), "Unable to read compiled script '%s'", filename);
|
|
||||||
showError(buffer);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
RProc *proc = mrb_proc_new(mrb, irep);
|
|
||||||
mrb_run(mrb, proc, mrb_top_self(mrb));
|
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
|
|
||||||
{
|
|
||||||
const std::string &scriptPack = shState->rtData().config.game.scripts;
|
|
||||||
|
|
||||||
if (scriptPack.empty())
|
|
||||||
{
|
|
||||||
showError("No game scripts specified (missing Game.ini?)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!shState->fileSystem().exists(scriptPack.c_str()))
|
|
||||||
{
|
|
||||||
showError(std::string("Unable to open '") + scriptPack + "'");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We use a secondary util state to unmarshal the scripts */
|
|
||||||
mrb_state *scriptMrb = mrb_open();
|
|
||||||
SDL_RWops ops;
|
|
||||||
|
|
||||||
shState->fileSystem().openReadRaw(ops, scriptPack.c_str());
|
|
||||||
|
|
||||||
mrb_value scriptArray = mrb_nil_value();
|
|
||||||
std::string readError;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
scriptArray = marshalLoadInt(scriptMrb, &ops);
|
|
||||||
}
|
|
||||||
catch (const Exception &e)
|
|
||||||
{
|
|
||||||
readError = std::string(": ") + e.msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_RWclose(&ops);
|
|
||||||
|
|
||||||
if (!mrb_array_p(scriptArray))
|
|
||||||
{
|
|
||||||
showError(std::string("Failed to read script data") + readError);
|
|
||||||
mrb_close(scriptMrb);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scriptCount = mrb_ary_len(scriptMrb, scriptArray);
|
|
||||||
|
|
||||||
std::string decodeBuffer;
|
|
||||||
decodeBuffer.resize(0x1000);
|
|
||||||
|
|
||||||
for (int i = 0; i < scriptCount; ++i)
|
|
||||||
{
|
|
||||||
mrb_value script = mrb_ary_entry(scriptArray, i);
|
|
||||||
|
|
||||||
mrb_value scriptChksum = mrb_ary_entry(script, 0);
|
|
||||||
mrb_value scriptName = mrb_ary_entry(script, 1);
|
|
||||||
mrb_value scriptString = mrb_ary_entry(script, 2);
|
|
||||||
|
|
||||||
(void) scriptChksum;
|
|
||||||
|
|
||||||
int result = Z_OK;
|
|
||||||
unsigned long bufferLen;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
unsigned char *bufferPtr =
|
|
||||||
reinterpret_cast<unsigned char*>(const_cast<char*>(decodeBuffer.c_str()));
|
|
||||||
unsigned char *sourcePtr =
|
|
||||||
reinterpret_cast<unsigned char*>(RSTRING_PTR(scriptString));
|
|
||||||
|
|
||||||
bufferLen = decodeBuffer.length();
|
|
||||||
|
|
||||||
result = uncompress(bufferPtr, &bufferLen,
|
|
||||||
sourcePtr, RSTRING_LEN(scriptString));
|
|
||||||
|
|
||||||
bufferPtr[bufferLen] = '\0';
|
|
||||||
|
|
||||||
if (result != Z_BUF_ERROR)
|
|
||||||
break;
|
|
||||||
|
|
||||||
decodeBuffer.resize(decodeBuffer.size()*2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != Z_OK)
|
|
||||||
{
|
|
||||||
static char buffer[256];
|
|
||||||
snprintf(buffer, sizeof(buffer), "Error decoding script %d: '%s'",
|
|
||||||
i, RSTRING_PTR(scriptName));
|
|
||||||
|
|
||||||
showError(buffer);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->filename = RSTRING_PTR(scriptName);
|
|
||||||
ctx->lineno = 1;
|
|
||||||
|
|
||||||
int ai = mrb_gc_arena_save(mrb);
|
|
||||||
|
|
||||||
/* Execute code */
|
|
||||||
mrb_load_nstring_cxt(mrb, decodeBuffer.c_str(), bufferLen, ctx);
|
|
||||||
|
|
||||||
mrb_gc_arena_restore(mrb, ai);
|
|
||||||
|
|
||||||
if (mrb->exc)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
mrb_close(scriptMrb);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mrbBindingExecute()
|
|
||||||
{
|
|
||||||
mrb_state *mrb = mrb_open();
|
|
||||||
|
|
||||||
shState->setBindingData(mrb);
|
|
||||||
|
|
||||||
MrbData mrbData(mrb);
|
|
||||||
mrb->ud = &mrbData;
|
|
||||||
|
|
||||||
mrb_define_module_function(mrb, mrb->kernel_module, "time_op",
|
|
||||||
mkxpTimeOp, MRB_ARGS_OPT(2) | MRB_ARGS_BLOCK());
|
|
||||||
|
|
||||||
mrbBindingInit(mrb);
|
|
||||||
|
|
||||||
mrbc_context *ctx = mrbc_context_new(mrb);
|
|
||||||
ctx->capture_errors = 1;
|
|
||||||
|
|
||||||
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.empty())
|
|
||||||
runCustomScript(mrb, ctx, customScript.c_str());
|
|
||||||
// else if (!mrbFile.empty())
|
|
||||||
// runMrbFile(mrb, mrbFile.c_str());
|
|
||||||
else
|
|
||||||
runRMXPScripts(mrb, ctx);
|
|
||||||
|
|
||||||
checkException(mrb);
|
|
||||||
|
|
||||||
shState->rtData().rqTermAck.set();
|
|
||||||
shState->texPool().disable();
|
|
||||||
|
|
||||||
mrbc_context_free(mrb, ctx);
|
|
||||||
mrb_close(mrb);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mrbBindingTerminate()
|
|
||||||
{
|
|
||||||
mrb_state *mrb = static_cast<mrb_state*>(shState->bindingData());
|
|
||||||
MrbData *data = static_cast<MrbData*>(mrb->ud);
|
|
||||||
|
|
||||||
mrb_raise(mrb, data->exc[Shutdown], "");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mrbBindingReset()
|
|
||||||
{
|
|
||||||
// No idea how to do this with mruby yet
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
/*
|
|
||||||
** binding-types.h
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BINDINGTYPES_H
|
|
||||||
#define BINDINGTYPES_H
|
|
||||||
|
|
||||||
#include "binding-util.h"
|
|
||||||
|
|
||||||
DECL_TYPE(Table);
|
|
||||||
DECL_TYPE(Rect);
|
|
||||||
DECL_TYPE(Color);
|
|
||||||
DECL_TYPE(Tone);
|
|
||||||
DECL_TYPE(Font);
|
|
||||||
|
|
||||||
DECL_TYPE(Bitmap);
|
|
||||||
DECL_TYPE(Sprite);
|
|
||||||
DECL_TYPE(Plane);
|
|
||||||
DECL_TYPE(Viewport);
|
|
||||||
DECL_TYPE(Tilemap);
|
|
||||||
DECL_TYPE(Window);
|
|
||||||
|
|
||||||
#endif // BINDINGTYPES_H
|
|
|
@ -1,170 +0,0 @@
|
||||||
/*
|
|
||||||
** binding-util.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "util.h"
|
|
||||||
#include "exception.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define SYMD(symbol) { CS##symbol, #symbol }
|
|
||||||
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
CommonSymbol ind;
|
|
||||||
const char *str;
|
|
||||||
} static const symData[] =
|
|
||||||
{
|
|
||||||
SYMD(font),
|
|
||||||
SYMD(viewport),
|
|
||||||
SYMD(bitmap),
|
|
||||||
SYMD(color),
|
|
||||||
SYMD(out_color),
|
|
||||||
SYMD(tone),
|
|
||||||
SYMD(rect),
|
|
||||||
SYMD(src_rect),
|
|
||||||
SYMD(tilemap),
|
|
||||||
SYMD(tileset),
|
|
||||||
SYMD(autotiles),
|
|
||||||
SYMD(map_data),
|
|
||||||
SYMD(flash_data),
|
|
||||||
SYMD(priorities),
|
|
||||||
SYMD(windowskin),
|
|
||||||
SYMD(contents),
|
|
||||||
SYMD(cursor_rect),
|
|
||||||
SYMD(path),
|
|
||||||
SYMD(array),
|
|
||||||
SYMD(default_color),
|
|
||||||
SYMD(default_out_color),
|
|
||||||
SYMD(children),
|
|
||||||
SYMD(_mkxp_dispose_alias)
|
|
||||||
};
|
|
||||||
|
|
||||||
static elementsN(symData);
|
|
||||||
|
|
||||||
struct MrbExcData
|
|
||||||
{
|
|
||||||
MrbException ind;
|
|
||||||
const char *str;
|
|
||||||
};
|
|
||||||
|
|
||||||
static const MrbExcData excData[] =
|
|
||||||
{
|
|
||||||
{ Shutdown, "SystemExit" },
|
|
||||||
{ PHYSFS, "PHYSFSError" },
|
|
||||||
{ SDL, "SDLError" },
|
|
||||||
{ MKXP, "MKXPError" },
|
|
||||||
{ IO, "IOError" }
|
|
||||||
};
|
|
||||||
|
|
||||||
static elementsN(excData);
|
|
||||||
|
|
||||||
#define ENO(id) { Errno##id, #id }
|
|
||||||
|
|
||||||
static const MrbExcData enoExcData[] =
|
|
||||||
{
|
|
||||||
ENO(E2BIG),
|
|
||||||
ENO(EACCES),
|
|
||||||
ENO(EAGAIN),
|
|
||||||
ENO(EBADF),
|
|
||||||
ENO(ECHILD),
|
|
||||||
ENO(EDEADLOCK),
|
|
||||||
ENO(EDOM),
|
|
||||||
ENO(EEXIST),
|
|
||||||
ENO(EINVAL),
|
|
||||||
ENO(EMFILE),
|
|
||||||
ENO(ENOENT),
|
|
||||||
ENO(ENOEXEC),
|
|
||||||
ENO(ENOMEM),
|
|
||||||
ENO(ENOSPC),
|
|
||||||
ENO(ERANGE),
|
|
||||||
ENO(EXDEV)
|
|
||||||
};
|
|
||||||
|
|
||||||
static elementsN(enoExcData);
|
|
||||||
|
|
||||||
MrbData::MrbData(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
int arena = mrb_gc_arena_save(mrb);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < excDataN; ++i)
|
|
||||||
exc[excData[i].ind] = mrb_define_class(mrb, excData[i].str, mrb->eException_class);
|
|
||||||
|
|
||||||
exc[RGSS] = mrb_define_class(mrb, "RGSSError", mrb->eStandardError_class);
|
|
||||||
|
|
||||||
RClass *errnoMod = mrb_define_module(mrb, "Errno");
|
|
||||||
|
|
||||||
for (size_t i = 0; i < enoExcDataN; ++i)
|
|
||||||
exc[enoExcData[i].ind] =
|
|
||||||
mrb_define_class_under(mrb, errnoMod, enoExcData[i].str, mrb->eStandardError_class);
|
|
||||||
|
|
||||||
exc[TypeError] = mrb_class_get(mrb, "TypeError");
|
|
||||||
exc[ArgumentError] = mrb_class_get(mrb, "ArgumentError");
|
|
||||||
|
|
||||||
for (size_t i = 0; i < symDataN; ++i)
|
|
||||||
symbols[symData[i].ind] = mrb_intern_cstr(mrb, symData[i].str);
|
|
||||||
|
|
||||||
mrb_gc_arena_restore(mrb, arena);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Indexed with Exception::Type */
|
|
||||||
static const MrbException excToMrbExc[] =
|
|
||||||
{
|
|
||||||
RGSS, /* RGSSError */
|
|
||||||
ErrnoENOENT, /* NoFileError */
|
|
||||||
IO,
|
|
||||||
|
|
||||||
TypeError,
|
|
||||||
ArgumentError,
|
|
||||||
|
|
||||||
PHYSFS, /* PHYSFSError */
|
|
||||||
SDL, /* SDLError */
|
|
||||||
MKXP /* MKXPError */
|
|
||||||
};
|
|
||||||
|
|
||||||
void raiseMrbExc(mrb_state *mrb, const Exception &exc)
|
|
||||||
{
|
|
||||||
MrbData *data = getMrbData(mrb);
|
|
||||||
RClass *excClass = data->exc[excToMrbExc[exc.type]];
|
|
||||||
|
|
||||||
mrb_raise(mrb, excClass, exc.msg.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
raiseDisposedAccess(mrb_state *mrb, mrb_value self)
|
|
||||||
{
|
|
||||||
const char *klassName = DATA_TYPE(self)->struct_name;
|
|
||||||
char buf[32];
|
|
||||||
|
|
||||||
strncpy(buf, klassName, sizeof(buf));
|
|
||||||
buf[0] = tolower(buf[0]);
|
|
||||||
|
|
||||||
mrb_raisef(mrb, getMrbData(mrb)->exc[RGSS],
|
|
||||||
"disposed %S", mrb_str_new_cstr(mrb, buf));
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD_PUB(inspectObject)
|
|
||||||
{
|
|
||||||
static char buffer[64];
|
|
||||||
snprintf(buffer, sizeof(buffer), "#<%s:%p>", DATA_TYPE(self)->struct_name, DATA_PTR(self));
|
|
||||||
|
|
||||||
return mrb_str_new_cstr(mrb, buffer);
|
|
||||||
}
|
|
|
@ -1,369 +0,0 @@
|
||||||
/*
|
|
||||||
** binding-util.h
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BINDINGUTIL_H
|
|
||||||
#define BINDINGUTIL_H
|
|
||||||
|
|
||||||
#include "exception.h"
|
|
||||||
|
|
||||||
#include <mruby.h>
|
|
||||||
#include <mruby/data.h>
|
|
||||||
#include <mruby/variable.h>
|
|
||||||
#include <mruby/class.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
|
|
||||||
enum CommonSymbol
|
|
||||||
{
|
|
||||||
CSfont = 0,
|
|
||||||
CSviewport,
|
|
||||||
CSbitmap,
|
|
||||||
CScolor,
|
|
||||||
CSout_color,
|
|
||||||
CStone,
|
|
||||||
CSrect,
|
|
||||||
CSsrc_rect,
|
|
||||||
CStilemap,
|
|
||||||
CStileset,
|
|
||||||
CSautotiles,
|
|
||||||
CSmap_data,
|
|
||||||
CSflash_data,
|
|
||||||
CSpriorities,
|
|
||||||
CSwindowskin,
|
|
||||||
CScontents,
|
|
||||||
CScursor_rect,
|
|
||||||
CSpath,
|
|
||||||
CSarray,
|
|
||||||
CSdefault_color,
|
|
||||||
CSdefault_out_color,
|
|
||||||
CSchildren,
|
|
||||||
CS_mkxp_dispose_alias,
|
|
||||||
|
|
||||||
CommonSymbolsMax
|
|
||||||
};
|
|
||||||
|
|
||||||
enum MrbException
|
|
||||||
{
|
|
||||||
Shutdown = 0,
|
|
||||||
RGSS,
|
|
||||||
PHYSFS,
|
|
||||||
SDL,
|
|
||||||
MKXP,
|
|
||||||
|
|
||||||
ErrnoE2BIG,
|
|
||||||
ErrnoEACCES,
|
|
||||||
ErrnoEAGAIN,
|
|
||||||
ErrnoEBADF,
|
|
||||||
ErrnoECHILD,
|
|
||||||
ErrnoEDEADLOCK,
|
|
||||||
ErrnoEDOM,
|
|
||||||
ErrnoEEXIST,
|
|
||||||
ErrnoEINVAL,
|
|
||||||
ErrnoEMFILE,
|
|
||||||
ErrnoENOENT,
|
|
||||||
ErrnoENOEXEC,
|
|
||||||
ErrnoENOMEM,
|
|
||||||
ErrnoENOSPC,
|
|
||||||
ErrnoERANGE,
|
|
||||||
ErrnoEXDEV,
|
|
||||||
|
|
||||||
IO,
|
|
||||||
|
|
||||||
TypeError,
|
|
||||||
ArgumentError,
|
|
||||||
|
|
||||||
MrbExceptionsMax
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MrbData
|
|
||||||
{
|
|
||||||
RClass *exc[MrbExceptionsMax];
|
|
||||||
/* I'll leave the usage of these syms to later,
|
|
||||||
* so I can measure how much of a speed difference they make */
|
|
||||||
mrb_sym symbols[CommonSymbolsMax];
|
|
||||||
|
|
||||||
mrb_value buttoncodeHash;
|
|
||||||
|
|
||||||
MrbData(mrb_state *mrb);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Exception;
|
|
||||||
|
|
||||||
void
|
|
||||||
raiseMrbExc(mrb_state *mrb, const Exception &exc);
|
|
||||||
|
|
||||||
inline MrbData*
|
|
||||||
getMrbData(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
return static_cast<MrbData*>(mrb->ud);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline RClass*
|
|
||||||
defineClass(mrb_state *mrb, const char *name)
|
|
||||||
{
|
|
||||||
RClass *klass = mrb_define_class(mrb, name, mrb->object_class);
|
|
||||||
MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA);
|
|
||||||
|
|
||||||
return klass;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define GUARD_EXC(exp) \
|
|
||||||
{ try { exp } catch (Exception &exc) { raiseMrbExc(mrb, exc); } }
|
|
||||||
|
|
||||||
#define DECL_TYPE(_Type) \
|
|
||||||
extern const mrb_data_type _Type##Type
|
|
||||||
|
|
||||||
#define DEF_TYPE(_Type) \
|
|
||||||
extern const mrb_data_type _Type##Type = \
|
|
||||||
{ \
|
|
||||||
#_Type, \
|
|
||||||
freeInstance<_Type> \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define MRB_METHOD_PUB(name) \
|
|
||||||
mrb_value name(mrb_state *mrb, mrb_value self)
|
|
||||||
|
|
||||||
#define MRB_METHOD(name) static MRB_METHOD_PUB(name)
|
|
||||||
|
|
||||||
#define MRB_FUNCTION(name) \
|
|
||||||
static mrb_value name(mrb_state *mrb, mrb_value)
|
|
||||||
|
|
||||||
#define MRB_UNUSED_PARAM \
|
|
||||||
{ (void) mrb; (void) self; }
|
|
||||||
|
|
||||||
#define MRB_FUN_UNUSED_PARAM { (void) mrb; }
|
|
||||||
|
|
||||||
/* Object property which is copied by value, not reference */
|
|
||||||
#define DEF_PROP_OBJ_VAL(Klass, PropKlass, PropName, prop_iv) \
|
|
||||||
MRB_METHOD(Klass##Get##PropName) \
|
|
||||||
{ \
|
|
||||||
checkDisposed<Klass>(mrb, self); \
|
|
||||||
return getProperty(mrb, self, prop_iv); \
|
|
||||||
} \
|
|
||||||
MRB_METHOD(Klass##Set##PropName) \
|
|
||||||
{ \
|
|
||||||
Klass *k = getPrivateData<Klass>(mrb, self); \
|
|
||||||
mrb_value propObj; \
|
|
||||||
PropKlass *prop; \
|
|
||||||
mrb_get_args(mrb, "o", &propObj); \
|
|
||||||
prop = getPrivateDataCheck<PropKlass>(mrb, propObj, PropKlass##Type); \
|
|
||||||
GUARD_EXC( k->set##PropName(*prop); ) \
|
|
||||||
return propObj; \
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Object property which is copied by reference, with allowed NIL */
|
|
||||||
#define DEF_PROP_OBJ_REF(Klass, PropKlass, PropName, prop_iv) \
|
|
||||||
MRB_METHOD(Klass##Get##PropName) \
|
|
||||||
{ \
|
|
||||||
return getProperty(mrb, self, prop_iv); \
|
|
||||||
} \
|
|
||||||
MRB_METHOD(Klass##Set##PropName) \
|
|
||||||
{ \
|
|
||||||
Klass *k = getPrivateData<Klass>(mrb, self); \
|
|
||||||
mrb_value propObj; \
|
|
||||||
PropKlass *prop; \
|
|
||||||
mrb_get_args(mrb, "o", &propObj); \
|
|
||||||
if (mrb_nil_p(propObj)) \
|
|
||||||
prop = 0; \
|
|
||||||
else \
|
|
||||||
prop = getPrivateDataCheck<PropKlass>(mrb, propObj, PropKlass##Type); \
|
|
||||||
GUARD_EXC( k->set##PropName(prop); ) \
|
|
||||||
setProperty(mrb, self, prop_iv, propObj); \
|
|
||||||
return mrb_nil_value(); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEF_PROP(Klass, mrb_type, PropName, arg_type, conv_t) \
|
|
||||||
MRB_METHOD(Klass##Get##PropName) \
|
|
||||||
{ \
|
|
||||||
Klass *k = getPrivateData<Klass>(mrb, self); \
|
|
||||||
mrb_type value = 0; \
|
|
||||||
GUARD_EXC( value = k->get##PropName(); ) \
|
|
||||||
return mrb_##conv_t##_value(value); \
|
|
||||||
} \
|
|
||||||
MRB_METHOD(Klass##Set##PropName) \
|
|
||||||
{ \
|
|
||||||
Klass *k = getPrivateData<Klass>(mrb, self); \
|
|
||||||
mrb_type value; \
|
|
||||||
mrb_get_args(mrb, arg_type, &value); \
|
|
||||||
GUARD_EXC( k->set##PropName(value); ) \
|
|
||||||
return mrb_##conv_t##_value(value); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEF_PROP_I(Klass, PropName) \
|
|
||||||
DEF_PROP(Klass, mrb_int, PropName, "i", fixnum)
|
|
||||||
|
|
||||||
#define DEF_PROP_F(Klass, PropName) \
|
|
||||||
DEF_PROP(Klass, mrb_float, PropName, "f", _float)
|
|
||||||
|
|
||||||
#define DEF_PROP_B(Klass, PropName) \
|
|
||||||
DEF_PROP(Klass, mrb_bool, PropName, "b", bool)
|
|
||||||
|
|
||||||
#define INITCOPY_FUN(Klass) \
|
|
||||||
MRB_METHOD(Klass##InitializeCopy) \
|
|
||||||
{ \
|
|
||||||
mrb_value origObj; \
|
|
||||||
mrb_get_args(mrb, "o", &origObj); \
|
|
||||||
Klass *orig = getPrivateData<Klass>(mrb, origObj); \
|
|
||||||
Klass *k = 0; \
|
|
||||||
GUARD_EXC( k = new Klass(*orig); ) \
|
|
||||||
setPrivateData(self, k, Klass##Type); \
|
|
||||||
return self; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define MARSH_LOAD_FUN(Klass) \
|
|
||||||
MRB_METHOD(Klass##Load) \
|
|
||||||
{ \
|
|
||||||
return objectLoad<Klass>(mrb, self, Klass##Type); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define INIT_PROP_BIND(Klass, PropName, prop_name_s) \
|
|
||||||
{ \
|
|
||||||
mrb_define_method(mrb, klass, prop_name_s, Klass##Get##PropName, MRB_ARGS_NONE()); \
|
|
||||||
mrb_define_method(mrb, klass, prop_name_s "=", Klass##Set##PropName, MRB_ARGS_REQ(1)); \
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline mrb_value
|
|
||||||
mrb__float_value(mrb_float f)
|
|
||||||
{
|
|
||||||
mrb_value v;
|
|
||||||
|
|
||||||
SET_FLOAT_VALUE(0, v, f);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline mrb_sym
|
|
||||||
getSym(mrb_state *mrb, CommonSymbol sym)
|
|
||||||
{
|
|
||||||
return getMrbData(mrb)->symbols[sym];
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
raiseDisposedAccess(mrb_state *mrb, mrb_value self);
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
inline C *
|
|
||||||
getPrivateData(mrb_state *, mrb_value self)
|
|
||||||
{
|
|
||||||
C *c = static_cast<C*>(DATA_PTR(self));
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline T *
|
|
||||||
getPrivateDataCheck(mrb_state *mrb, mrb_value obj, const mrb_data_type &type)
|
|
||||||
{
|
|
||||||
void *ptr = mrb_check_datatype(mrb, obj, &type);
|
|
||||||
return static_cast<T*>(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void
|
|
||||||
setPrivateData(mrb_value self, void *p, const mrb_data_type &type)
|
|
||||||
{
|
|
||||||
DATA_PTR(self) = p;
|
|
||||||
DATA_TYPE(self) = &type;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline mrb_value
|
|
||||||
wrapObject(mrb_state *mrb, void *p, const mrb_data_type &type)
|
|
||||||
{
|
|
||||||
RClass *klass = mrb_class_get(mrb, type.struct_name);
|
|
||||||
RData *data = mrb_data_object_alloc(mrb, klass, p, &type);
|
|
||||||
mrb_value obj = mrb_obj_value(data);
|
|
||||||
|
|
||||||
setPrivateData(obj, p, type);
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline mrb_value
|
|
||||||
wrapProperty(mrb_state *mrb, mrb_value self,
|
|
||||||
void *prop, CommonSymbol iv, const mrb_data_type &type)
|
|
||||||
{
|
|
||||||
mrb_value propObj = wrapObject(mrb, prop, type);
|
|
||||||
|
|
||||||
mrb_obj_iv_set(mrb,
|
|
||||||
mrb_obj_ptr(self),
|
|
||||||
getSym(mrb, iv),
|
|
||||||
propObj);
|
|
||||||
|
|
||||||
return propObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline mrb_value
|
|
||||||
getProperty(mrb_state *mrb, mrb_value self, CommonSymbol iv)
|
|
||||||
{
|
|
||||||
return mrb_obj_iv_get(mrb,
|
|
||||||
mrb_obj_ptr(self),
|
|
||||||
getSym(mrb, iv));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void
|
|
||||||
setProperty(mrb_state *mrb, mrb_value self,
|
|
||||||
CommonSymbol iv, mrb_value propObject)
|
|
||||||
{
|
|
||||||
mrb_obj_iv_set(mrb,
|
|
||||||
mrb_obj_ptr(self),
|
|
||||||
getSym(mrb, iv),
|
|
||||||
propObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void
|
|
||||||
freeInstance(mrb_state *, void *instance)
|
|
||||||
{
|
|
||||||
delete static_cast<T*>(instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline mrb_value
|
|
||||||
mrb_bool_value(bool value)
|
|
||||||
{
|
|
||||||
return value ? mrb_true_value() : mrb_false_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
_mrb_bool(mrb_value o)
|
|
||||||
{
|
|
||||||
return mrb_test(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
inline mrb_value
|
|
||||||
objectLoad(mrb_state *mrb, mrb_value self, const mrb_data_type &type)
|
|
||||||
{
|
|
||||||
RClass *klass = mrb_class_ptr(self);
|
|
||||||
char *data;
|
|
||||||
int data_len;
|
|
||||||
mrb_get_args(mrb, "s", &data, &data_len);
|
|
||||||
|
|
||||||
C *c = C::deserialize(data, data_len);
|
|
||||||
|
|
||||||
RData *obj = mrb_data_object_alloc(mrb, klass, c, &type);
|
|
||||||
mrb_value obj_value = mrb_obj_value(obj);
|
|
||||||
|
|
||||||
return obj_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD_PUB(inspectObject);
|
|
||||||
|
|
||||||
#endif // BINDINGUTIL_H
|
|
|
@ -1,334 +0,0 @@
|
||||||
/*
|
|
||||||
** bitmap-binding.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "bitmap.h"
|
|
||||||
#include "font.h"
|
|
||||||
#include "exception.h"
|
|
||||||
#include "sharedstate.h"
|
|
||||||
#include "disposable-binding.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
|
||||||
|
|
||||||
DEF_TYPE(Bitmap);
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapInitialize)
|
|
||||||
{
|
|
||||||
Bitmap *b = 0;
|
|
||||||
|
|
||||||
if (mrb->c->ci->argc == 1)
|
|
||||||
{
|
|
||||||
char *filename;
|
|
||||||
mrb_get_args(mrb, "z", &filename);
|
|
||||||
|
|
||||||
GUARD_EXC( b = new Bitmap(filename); )
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mrb_int width, height;
|
|
||||||
mrb_get_args(mrb, "ii", &width, &height);
|
|
||||||
|
|
||||||
GUARD_EXC( b = new Bitmap(width, height); )
|
|
||||||
}
|
|
||||||
|
|
||||||
setPrivateData(self, b, BitmapType);
|
|
||||||
|
|
||||||
/* Wrap properties */
|
|
||||||
Font *font = new Font();
|
|
||||||
b->setInitFont(font);
|
|
||||||
font->initDynAttribs();
|
|
||||||
|
|
||||||
mrb_value fontProp = wrapProperty(mrb, self, font, CSfont, FontType);
|
|
||||||
|
|
||||||
wrapProperty(mrb, fontProp, &font->getColor(), CScolor, ColorType);
|
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
|
||||||
wrapProperty(mrb, fontProp, &font->getOutColor(), CSout_color, ColorType);
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapWidth)
|
|
||||||
{
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(mrb, self);
|
|
||||||
|
|
||||||
mrb_int value = 0;
|
|
||||||
GUARD_EXC( value = b->width(); )
|
|
||||||
|
|
||||||
return mrb_fixnum_value(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapHeight)
|
|
||||||
{
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(mrb, self);
|
|
||||||
|
|
||||||
mrb_int value = 0;
|
|
||||||
GUARD_EXC( value = b->height(); )
|
|
||||||
|
|
||||||
return mrb_fixnum_value(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapRect)
|
|
||||||
{
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(mrb, self);
|
|
||||||
|
|
||||||
IntRect rect;
|
|
||||||
GUARD_EXC( rect = b->rect(); )
|
|
||||||
|
|
||||||
Rect *r = new Rect(rect);
|
|
||||||
|
|
||||||
return wrapObject(mrb, r, RectType);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapBlt)
|
|
||||||
{
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(mrb, self);
|
|
||||||
|
|
||||||
mrb_int x, y;
|
|
||||||
mrb_value srcObj;
|
|
||||||
mrb_value srcRectObj;
|
|
||||||
mrb_int opacity = 255;
|
|
||||||
|
|
||||||
Bitmap *src;
|
|
||||||
Rect *srcRect;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "iioo|i", &x, &y, &srcObj, &srcRectObj, &opacity);
|
|
||||||
|
|
||||||
src = getPrivateDataCheck<Bitmap>(mrb, srcObj, BitmapType);
|
|
||||||
srcRect = getPrivateDataCheck<Rect>(mrb, srcRectObj, RectType);
|
|
||||||
|
|
||||||
GUARD_EXC( b->blt(x, y, *src, srcRect->toIntRect(), opacity); )
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapStretchBlt)
|
|
||||||
{
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(mrb, self);
|
|
||||||
|
|
||||||
mrb_value destRectObj;
|
|
||||||
mrb_value srcObj;
|
|
||||||
mrb_value srcRectObj;
|
|
||||||
mrb_int opacity = 255;
|
|
||||||
|
|
||||||
Bitmap *src;
|
|
||||||
Rect *destRect, *srcRect;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "ooo|i", &destRectObj, &srcObj, &srcRectObj);
|
|
||||||
|
|
||||||
src = getPrivateDataCheck<Bitmap>(mrb, srcObj, BitmapType);
|
|
||||||
destRect = getPrivateDataCheck<Rect>(mrb, destRectObj, RectType);
|
|
||||||
srcRect = getPrivateDataCheck<Rect>(mrb, srcRectObj, RectType);
|
|
||||||
|
|
||||||
GUARD_EXC( b->stretchBlt(destRect->toIntRect(), *src, srcRect->toIntRect(), opacity); )
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapFillRect)
|
|
||||||
{
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(mrb, self);
|
|
||||||
|
|
||||||
mrb_value colorObj;
|
|
||||||
Color *color;
|
|
||||||
|
|
||||||
if (mrb->c->ci->argc == 2)
|
|
||||||
{
|
|
||||||
mrb_value rectObj;
|
|
||||||
Rect *rect;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "oo", &rectObj, &colorObj);
|
|
||||||
|
|
||||||
rect = getPrivateDataCheck<Rect>(mrb, rectObj, RectType);
|
|
||||||
color = getPrivateDataCheck<Color>(mrb, colorObj, ColorType);
|
|
||||||
|
|
||||||
GUARD_EXC( b->fillRect(rect->toIntRect(), color->norm); )
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mrb_int x, y, width, height;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "iiiio", &x, &y, &width, &height, &colorObj);
|
|
||||||
|
|
||||||
color = getPrivateDataCheck<Color>(mrb, colorObj, ColorType);
|
|
||||||
|
|
||||||
GUARD_EXC( b->fillRect(x, y, width, height, color->norm); )
|
|
||||||
}
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapClear)
|
|
||||||
{
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(mrb, self);
|
|
||||||
|
|
||||||
GUARD_EXC( b->clear(); )
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapGetPixel)
|
|
||||||
{
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(mrb, self);
|
|
||||||
|
|
||||||
mrb_int x, y;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "ii", &x, &y);
|
|
||||||
|
|
||||||
Color value;
|
|
||||||
GUARD_EXC( value = b->getPixel(x, y); )
|
|
||||||
|
|
||||||
Color *color = new Color(value);
|
|
||||||
|
|
||||||
return wrapObject(mrb, color, ColorType);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapSetPixel)
|
|
||||||
{
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(mrb, self);
|
|
||||||
|
|
||||||
mrb_int x, y;
|
|
||||||
mrb_value colorObj;
|
|
||||||
|
|
||||||
Color *color;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "iio", &x, &y, &colorObj);
|
|
||||||
|
|
||||||
color = getPrivateDataCheck<Color>(mrb, colorObj, ColorType);
|
|
||||||
|
|
||||||
GUARD_EXC( b->setPixel(x, y, *color); )
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapHueChange)
|
|
||||||
{
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(mrb, self);
|
|
||||||
|
|
||||||
mrb_int hue;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "i", &hue);
|
|
||||||
|
|
||||||
GUARD_EXC( b->hueChange(hue); )
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapDrawText)
|
|
||||||
{
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(mrb, self);
|
|
||||||
|
|
||||||
char *str;
|
|
||||||
mrb_int align = Bitmap::Left;
|
|
||||||
|
|
||||||
int argc = mrb->c->ci->argc;
|
|
||||||
if (argc == 2 || argc == 3)
|
|
||||||
{
|
|
||||||
mrb_value rectObj;
|
|
||||||
Rect *rect;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "oz|i", &rectObj, &str, &align);
|
|
||||||
|
|
||||||
rect = getPrivateDataCheck<Rect>(mrb, rectObj, RectType);
|
|
||||||
|
|
||||||
GUARD_EXC( b->drawText(rect->toIntRect(), str, align); )
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mrb_int x, y, width, height;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "iiiiz|i", &x, &y, &width, &height, &str, &align);
|
|
||||||
|
|
||||||
GUARD_EXC( b->drawText(x, y, width, height, str, align); )
|
|
||||||
}
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapTextSize)
|
|
||||||
{
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(mrb, self);
|
|
||||||
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "z", &str);
|
|
||||||
|
|
||||||
IntRect value;
|
|
||||||
GUARD_EXC( value = b->textSize(str); )
|
|
||||||
|
|
||||||
Rect *rect = new Rect(value);
|
|
||||||
|
|
||||||
return wrapObject(mrb, rect, RectType);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapGetFont)
|
|
||||||
{
|
|
||||||
checkDisposed<Bitmap>(mrb, self);
|
|
||||||
|
|
||||||
return getProperty(mrb, self, CSfont);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(bitmapSetFont)
|
|
||||||
{
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(mrb, self);
|
|
||||||
|
|
||||||
mrb_value fontObj;
|
|
||||||
Font *font;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "o", &fontObj);
|
|
||||||
|
|
||||||
font = getPrivateDataCheck<Font>(mrb, fontObj, FontType);
|
|
||||||
|
|
||||||
GUARD_EXC( b->setFont(*font); )
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
INITCOPY_FUN(Bitmap)
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
bitmapBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
RClass *klass = defineClass(mrb, "Bitmap");
|
|
||||||
|
|
||||||
disposableBindingInit<Bitmap>(mrb, klass);
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "initialize", bitmapInitialize, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(1));
|
|
||||||
mrb_define_method(mrb, klass, "initialize_copy", BitmapInitializeCopy, MRB_ARGS_REQ(1));
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "width", bitmapWidth, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "height", bitmapHeight, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "rect", bitmapRect, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "blt", bitmapBlt, MRB_ARGS_REQ(4) | MRB_ARGS_OPT(1));
|
|
||||||
mrb_define_method(mrb, klass, "stretch_blt", bitmapStretchBlt, MRB_ARGS_REQ(3) | MRB_ARGS_OPT(1));
|
|
||||||
mrb_define_method(mrb, klass, "fill_rect", bitmapFillRect, MRB_ARGS_REQ(2) | MRB_ARGS_OPT(2));
|
|
||||||
mrb_define_method(mrb, klass, "clear", bitmapClear, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "get_pixel", bitmapGetPixel, MRB_ARGS_REQ(2));
|
|
||||||
mrb_define_method(mrb, klass, "set_pixel", bitmapSetPixel, MRB_ARGS_REQ(3));
|
|
||||||
mrb_define_method(mrb, klass, "hue_change", bitmapHueChange, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_method(mrb, klass, "draw_text", bitmapDrawText, MRB_ARGS_REQ(2) | MRB_ARGS_OPT(4));
|
|
||||||
mrb_define_method(mrb, klass, "text_size", bitmapTextSize, MRB_ARGS_REQ(1));
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "font", bitmapGetFont, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "font=", bitmapSetFont, MRB_ARGS_REQ(1));
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE());
|
|
||||||
}
|
|
|
@ -1,117 +0,0 @@
|
||||||
/*
|
|
||||||
** disposable-binding.h
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DISPOSABLEBINDING_H
|
|
||||||
#define DISPOSABLEBINDING_H
|
|
||||||
|
|
||||||
#include "disposable.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
|
|
||||||
#include "mruby/array.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
/* 'Children' are disposables that are disposed together
|
|
||||||
* with their parent. Currently this is only used by Viewport
|
|
||||||
* in RGSS1.
|
|
||||||
* FIXME: Disable this behavior when RGSS2 or 3 */
|
|
||||||
inline void
|
|
||||||
disposableAddChild(mrb_state *mrb, mrb_value disp, mrb_value child)
|
|
||||||
{
|
|
||||||
mrb_sym sym = getMrbData(mrb)->symbols[CSchildren];
|
|
||||||
mrb_value children = mrb_iv_get(mrb, disp, sym);
|
|
||||||
|
|
||||||
if (mrb_nil_p(children))
|
|
||||||
{
|
|
||||||
children = mrb_ary_new(mrb);
|
|
||||||
mrb_iv_set(mrb, disp, sym, children);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Assumes children are never removed until destruction */
|
|
||||||
mrb_ary_push(mrb, children, child);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void
|
|
||||||
disposableDisposeChildren(mrb_state *mrb, mrb_value disp)
|
|
||||||
{
|
|
||||||
MrbData *mrbData = getMrbData(mrb);
|
|
||||||
mrb_value children = mrb_iv_get(mrb, disp, mrbData->symbols[CSchildren]);
|
|
||||||
|
|
||||||
if (mrb_nil_p(children))
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (mrb_int i = 0; i < RARRAY_LEN(children); ++i)
|
|
||||||
mrb_funcall_argv(mrb, mrb_ary_entry(children, i),
|
|
||||||
mrbData->symbols[CS_mkxp_dispose_alias], 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
MRB_METHOD(disposableDispose)
|
|
||||||
{
|
|
||||||
C *d = static_cast<C*>(DATA_PTR(self));
|
|
||||||
|
|
||||||
if (!d)
|
|
||||||
return mrb_nil_value();
|
|
||||||
|
|
||||||
if (d->isDisposed())
|
|
||||||
return mrb_nil_value();
|
|
||||||
|
|
||||||
if (rgssVer == 1)
|
|
||||||
disposableDisposeChildren(mrb, self);
|
|
||||||
|
|
||||||
d->dispose();
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
MRB_METHOD(disposableIsDisposed)
|
|
||||||
{
|
|
||||||
MRB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
C *d = static_cast<C*>(DATA_PTR(self));
|
|
||||||
|
|
||||||
if (!d)
|
|
||||||
return mrb_true_value();
|
|
||||||
|
|
||||||
return mrb_bool_value(d->isDisposed());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
static void disposableBindingInit(mrb_state *mrb, RClass *klass)
|
|
||||||
{
|
|
||||||
mrb_define_method(mrb, klass, "dispose", disposableDispose<C>, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "disposed?", disposableIsDisposed<C>, MRB_ARGS_NONE());
|
|
||||||
|
|
||||||
if (rgssVer == 1)
|
|
||||||
mrb_alias_method(mrb, klass, getMrbData(mrb)->symbols[CS_mkxp_dispose_alias],
|
|
||||||
mrb_intern_lit(mrb, "dispose"));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
inline void
|
|
||||||
checkDisposed(mrb_state *mrb, mrb_value self)
|
|
||||||
{
|
|
||||||
if (mrb_test(disposableIsDisposed<C>(0, self)))
|
|
||||||
raiseDisposedAccess(mrb, self);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // DISPOSABLEBINDING_H
|
|
|
@ -1,205 +0,0 @@
|
||||||
/*
|
|
||||||
** etc-binding.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "etc.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
|
||||||
#include "serializable-binding.h"
|
|
||||||
|
|
||||||
#define ATTR_RW(Type, Attr, arg_type, mrb_val, arg_t_s) \
|
|
||||||
MRB_METHOD(Type##Get##Attr) \
|
|
||||||
{ \
|
|
||||||
Type *p = getPrivateData<Type>(mrb, self); \
|
|
||||||
\
|
|
||||||
return mrb_##mrb_val##_value(p->get##Attr()); \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
MRB_METHOD(Type##Set##Attr) \
|
|
||||||
{ \
|
|
||||||
Type *p = getPrivateData<Type>(mrb, self); \
|
|
||||||
\
|
|
||||||
arg_type arg; \
|
|
||||||
mrb_get_args(mrb, arg_t_s, &arg); \
|
|
||||||
\
|
|
||||||
p->set##Attr(arg); \
|
|
||||||
UPDATE_F \
|
|
||||||
\
|
|
||||||
return mrb_##mrb_val##_value(arg); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define EQUAL_FUN(Typ) \
|
|
||||||
MRB_METHOD(Typ##Equal) \
|
|
||||||
{ \
|
|
||||||
Typ *p = getPrivateData<Typ>(mrb, self); \
|
|
||||||
mrb_value otherObj; \
|
|
||||||
Typ *other; \
|
|
||||||
mrb_get_args(mrb, "o", &otherObj); \
|
|
||||||
RClass *klass = mrb_obj_class(mrb, self); \
|
|
||||||
RClass *otherKlass = mrb_obj_class(mrb, otherObj); \
|
|
||||||
if (klass != otherKlass) \
|
|
||||||
return mrb_false_value(); \
|
|
||||||
other = getPrivateDataCheck<Typ>(mrb, otherObj, Typ##Type); \
|
|
||||||
return mrb_bool_value(*p == *other); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ATTR_FLOAT_RW(Type, attr) ATTR_RW(Type, attr, mrb_float, _float, "f")
|
|
||||||
#define ATTR_INT_RW(Type, attr) ATTR_RW(Type, attr, mrb_int, fixnum, "i")
|
|
||||||
|
|
||||||
#define UPDATE_F p->updateInternal();
|
|
||||||
ATTR_FLOAT_RW(Color, Red)
|
|
||||||
ATTR_FLOAT_RW(Color, Green)
|
|
||||||
ATTR_FLOAT_RW(Color, Blue)
|
|
||||||
ATTR_FLOAT_RW(Color, Alpha)
|
|
||||||
|
|
||||||
ATTR_FLOAT_RW(Tone, Red)
|
|
||||||
ATTR_FLOAT_RW(Tone, Green)
|
|
||||||
ATTR_FLOAT_RW(Tone, Blue)
|
|
||||||
ATTR_FLOAT_RW(Tone, Gray)
|
|
||||||
|
|
||||||
#undef UPDATE_F
|
|
||||||
#define UPDATE_F
|
|
||||||
ATTR_INT_RW(Rect, X)
|
|
||||||
ATTR_INT_RW(Rect, Y)
|
|
||||||
ATTR_INT_RW(Rect, Width)
|
|
||||||
ATTR_INT_RW(Rect, Height)
|
|
||||||
|
|
||||||
EQUAL_FUN(Color)
|
|
||||||
EQUAL_FUN(Tone)
|
|
||||||
EQUAL_FUN(Rect)
|
|
||||||
|
|
||||||
DEF_TYPE(Color);
|
|
||||||
DEF_TYPE(Tone);
|
|
||||||
DEF_TYPE(Rect);
|
|
||||||
|
|
||||||
#define INIT_FUN(Klass, param_type, param_t_s, last_param_def) \
|
|
||||||
MRB_METHOD(Klass##Initialize) \
|
|
||||||
{ \
|
|
||||||
param_type p1, p2, p3, p4 = last_param_def; \
|
|
||||||
mrb_get_args(mrb, param_t_s, &p1, &p2, &p3, &p4); \
|
|
||||||
Klass *k = new Klass(p1, p2, p3, p4); \
|
|
||||||
setPrivateData(self, k, Klass##Type); \
|
|
||||||
return self; \
|
|
||||||
}
|
|
||||||
|
|
||||||
INIT_FUN(Color, mrb_float, "fff|f", 255)
|
|
||||||
INIT_FUN(Tone, mrb_float, "fff|f", 0)
|
|
||||||
INIT_FUN(Rect, mrb_int, "iiii", 0)
|
|
||||||
|
|
||||||
#define SET_FUN(Klass, param_type, param_t_s, last_param_def) \
|
|
||||||
MRB_METHOD(Klass##Set) \
|
|
||||||
{ \
|
|
||||||
param_type p1, p2, p3, p4 = last_param_def; \
|
|
||||||
mrb_get_args(mrb, param_t_s, &p1, &p2, &p3, &p4); \
|
|
||||||
Klass *k = getPrivateData<Klass>(mrb, self); \
|
|
||||||
k->set(p1, p2, p3, p4); \
|
|
||||||
return self; \
|
|
||||||
}
|
|
||||||
|
|
||||||
SET_FUN(Color, mrb_float, "fff|f", 255)
|
|
||||||
SET_FUN(Tone, mrb_float, "fff|f", 0)
|
|
||||||
SET_FUN(Rect, mrb_int, "iiii", 0)
|
|
||||||
|
|
||||||
MRB_METHOD(RectEmpty)
|
|
||||||
{
|
|
||||||
Rect *r = getPrivateData<Rect>(mrb, self);
|
|
||||||
|
|
||||||
r->empty();
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
static char buffer[64];
|
|
||||||
|
|
||||||
MRB_METHOD(ColorStringify)
|
|
||||||
{
|
|
||||||
Color *c = getPrivateData<Color>(mrb, self);
|
|
||||||
|
|
||||||
sprintf(buffer, "(%f, %f, %f, %f)", c->red, c->green, c->blue, c->alpha);
|
|
||||||
|
|
||||||
return mrb_str_new_cstr(mrb, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(ToneStringify)
|
|
||||||
{
|
|
||||||
Tone *t = getPrivateData<Tone>(mrb, self);
|
|
||||||
|
|
||||||
sprintf(buffer, "(%f, %f, %f, %f)", t->red, t->green, t->blue, t->gray);
|
|
||||||
|
|
||||||
return mrb_str_new_cstr(mrb, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(RectStringify)
|
|
||||||
{
|
|
||||||
Rect *r = getPrivateData<Rect>(mrb, self);
|
|
||||||
|
|
||||||
sprintf(buffer, "(%d, %d, %d, %d)", r->x, r->y, r->width, r->height);
|
|
||||||
|
|
||||||
return mrb_str_new_cstr(mrb, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
MARSH_LOAD_FUN(Color)
|
|
||||||
MARSH_LOAD_FUN(Tone)
|
|
||||||
MARSH_LOAD_FUN(Rect)
|
|
||||||
|
|
||||||
INITCOPY_FUN(Tone)
|
|
||||||
INITCOPY_FUN(Color)
|
|
||||||
INITCOPY_FUN(Rect)
|
|
||||||
|
|
||||||
#define MRB_ATTR_R(Class, Attr, sym) mrb_define_method(mrb, klass, sym, Class##Get##Attr, MRB_ARGS_NONE())
|
|
||||||
#define MRB_ATTR_W(Class, Attr, sym) mrb_define_method(mrb, klass, sym "=", Class##Set##Attr, MRB_ARGS_REQ(1))
|
|
||||||
#define MRB_ATTR_RW(Class, Attr, sym) { MRB_ATTR_R(Class, Attr, sym); MRB_ATTR_W(Class, Attr, sym); }
|
|
||||||
|
|
||||||
#define INIT_BIND(Klass) \
|
|
||||||
{ \
|
|
||||||
klass = defineClass(mrb, #Klass); \
|
|
||||||
mrb_define_class_method(mrb, klass, "_load", Klass##Load, MRB_ARGS_REQ(1)); \
|
|
||||||
serializableBindingInit<Klass>(mrb, klass); \
|
|
||||||
mrb_define_method(mrb, klass, "initialize", Klass##Initialize, MRB_ARGS_REQ(3) | MRB_ARGS_OPT(1)); \
|
|
||||||
mrb_define_method(mrb, klass, "initialize_copy", Klass##InitializeCopy, MRB_ARGS_REQ(1)); \
|
|
||||||
mrb_define_method(mrb, klass, "set", Klass##Set, MRB_ARGS_REQ(3) | MRB_ARGS_OPT(1)); \
|
|
||||||
mrb_define_method(mrb, klass, "==", Klass##Equal, MRB_ARGS_REQ(1)); \
|
|
||||||
mrb_define_method(mrb, klass, "to_s", Klass##Stringify, MRB_ARGS_NONE()); \
|
|
||||||
mrb_define_method(mrb, klass, "inspect", Klass##Stringify, MRB_ARGS_NONE()); \
|
|
||||||
}
|
|
||||||
|
|
||||||
void etcBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
RClass *klass;
|
|
||||||
|
|
||||||
INIT_BIND(Color);
|
|
||||||
MRB_ATTR_RW(Color, Red, "red" );
|
|
||||||
MRB_ATTR_RW(Color, Green, "green");
|
|
||||||
MRB_ATTR_RW(Color, Blue, "blue" );
|
|
||||||
MRB_ATTR_RW(Color, Alpha, "alpha");
|
|
||||||
|
|
||||||
INIT_BIND(Tone);
|
|
||||||
MRB_ATTR_RW(Tone, Red, "red" );
|
|
||||||
MRB_ATTR_RW(Tone, Green, "green");
|
|
||||||
MRB_ATTR_RW(Tone, Blue, "blue" );
|
|
||||||
MRB_ATTR_RW(Tone, Gray, "gray" );
|
|
||||||
|
|
||||||
INIT_BIND(Rect);
|
|
||||||
MRB_ATTR_RW(Rect, X, "x" );
|
|
||||||
MRB_ATTR_RW(Rect, Y, "y" );
|
|
||||||
MRB_ATTR_RW(Rect, Width, "width" );
|
|
||||||
MRB_ATTR_RW(Rect, Height, "height");
|
|
||||||
mrb_define_method(mrb, klass, "empty", RectEmpty, MRB_ARGS_NONE());
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
/*
|
|
||||||
** flashable-binding.h
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FLASHABLEBINDING_H
|
|
||||||
#define FLASHABLEBINDING_H
|
|
||||||
|
|
||||||
#include "flashable.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
MRB_METHOD(flashableFlash)
|
|
||||||
{
|
|
||||||
Flashable *f = getPrivateData<C>(mrb, self);
|
|
||||||
|
|
||||||
mrb_value colorObj;
|
|
||||||
mrb_int duration;
|
|
||||||
|
|
||||||
Color *color;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "oi", &colorObj, &duration);
|
|
||||||
|
|
||||||
if (mrb_nil_p(colorObj))
|
|
||||||
{
|
|
||||||
f->flash(0, duration);
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
color = getPrivateDataCheck<Color>(mrb, colorObj, ColorType);
|
|
||||||
|
|
||||||
f->flash(&color->norm, duration);
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
MRB_METHOD(flashableUpdate)
|
|
||||||
{
|
|
||||||
Flashable *f = getPrivateData<C>(mrb, self);
|
|
||||||
|
|
||||||
f->update();
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
static void flashableBindingInit(mrb_state *mrb, RClass *klass)
|
|
||||||
{
|
|
||||||
mrb_define_method(mrb, klass, "flash", flashableFlash<C>, MRB_ARGS_REQ(2));
|
|
||||||
mrb_define_method(mrb, klass, "update", flashableUpdate<C>, MRB_ARGS_NONE());
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // FLASHABLEBINDING_H
|
|
|
@ -1,246 +0,0 @@
|
||||||
/*
|
|
||||||
** font-binding.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "font.h"
|
|
||||||
#include "sharedstate.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
|
||||||
#include "exception.h"
|
|
||||||
|
|
||||||
#include <mruby/string.h>
|
|
||||||
|
|
||||||
DEF_TYPE(Font);
|
|
||||||
|
|
||||||
MRB_FUNCTION(fontDoesExist)
|
|
||||||
{
|
|
||||||
const char *name = 0;
|
|
||||||
mrb_value nameObj;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "o", &nameObj);
|
|
||||||
|
|
||||||
if (mrb_string_p(nameObj))
|
|
||||||
name = mrb_string_value_cstr(mrb, &nameObj);
|
|
||||||
|
|
||||||
return mrb_bool_value(Font::doesExist(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(fontInitialize)
|
|
||||||
{
|
|
||||||
char *name = 0;
|
|
||||||
mrb_int size = 0;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "|zi", &name, &size);
|
|
||||||
|
|
||||||
Font *f = new Font(name, size);
|
|
||||||
|
|
||||||
setPrivateData(self, f, FontType);
|
|
||||||
|
|
||||||
/* Wrap property objects */
|
|
||||||
f->initDynAttribs();
|
|
||||||
|
|
||||||
wrapProperty(mrb, self, &f->getColor(), CScolor, ColorType);
|
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
|
||||||
wrapProperty(mrb, self, &f->getOutColor(), CSout_color, ColorType);
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(fontInitializeCopy)
|
|
||||||
{
|
|
||||||
mrb_value origObj;
|
|
||||||
mrb_get_args(mrb, "o", &origObj);
|
|
||||||
|
|
||||||
Font *orig = getPrivateData<Font>(mrb, origObj);
|
|
||||||
Font *f = new Font(*orig);
|
|
||||||
setPrivateData(self, f, FontType);
|
|
||||||
|
|
||||||
/* Wrap property objects */
|
|
||||||
f->initDynAttribs();
|
|
||||||
|
|
||||||
wrapProperty(mrb, self, &f->getColor(), CScolor, ColorType);
|
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
|
||||||
wrapProperty(mrb, self, &f->getOutColor(), CSout_color, ColorType);
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(FontGetName)
|
|
||||||
{
|
|
||||||
Font *f = getPrivateData<Font>(mrb, self);
|
|
||||||
|
|
||||||
return mrb_str_new_cstr(mrb, f->getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(FontSetName)
|
|
||||||
{
|
|
||||||
Font *f = getPrivateData<Font>(mrb, self);
|
|
||||||
|
|
||||||
mrb_value name;
|
|
||||||
mrb_get_args(mrb, "S", &name);
|
|
||||||
|
|
||||||
f->setName(RSTRING_PTR(name));
|
|
||||||
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
static void checkDisposed(mrb_state *, mrb_value) {}
|
|
||||||
|
|
||||||
DEF_PROP_I(Font, Size)
|
|
||||||
DEF_PROP_B(Font, Bold)
|
|
||||||
DEF_PROP_B(Font, Italic)
|
|
||||||
DEF_PROP_B(Font, Outline)
|
|
||||||
DEF_PROP_B(Font, Shadow)
|
|
||||||
DEF_PROP_OBJ_VAL(Font, Color, Color, CScolor)
|
|
||||||
DEF_PROP_OBJ_VAL(Font, Color, OutColor, CSout_color)
|
|
||||||
|
|
||||||
#define DEF_KLASS_PROP(Klass, mrb_type, PropName, arg_type, conv_t) \
|
|
||||||
static mrb_value \
|
|
||||||
Klass##Get##PropName(mrb_state *, mrb_value) \
|
|
||||||
{ \
|
|
||||||
return mrb_##conv_t##_value(Klass::get##PropName()); \
|
|
||||||
} \
|
|
||||||
static mrb_value \
|
|
||||||
Klass##Set##PropName(mrb_state *mrb, mrb_value) \
|
|
||||||
{ \
|
|
||||||
mrb_type value; \
|
|
||||||
mrb_get_args(mrb, arg_type, &value); \
|
|
||||||
Klass::set##PropName(value); \
|
|
||||||
return mrb_##conv_t##_value(value); \
|
|
||||||
}
|
|
||||||
|
|
||||||
DEF_KLASS_PROP(Font, mrb_int, DefaultSize, "i", fixnum)
|
|
||||||
DEF_KLASS_PROP(Font, mrb_bool, DefaultBold, "b", bool)
|
|
||||||
DEF_KLASS_PROP(Font, mrb_bool, DefaultItalic, "b", bool)
|
|
||||||
DEF_KLASS_PROP(Font, mrb_bool, DefaultOutline, "b", bool)
|
|
||||||
DEF_KLASS_PROP(Font, mrb_bool, DefaultShadow, "b", bool)
|
|
||||||
|
|
||||||
MRB_FUNCTION(FontGetDefaultName)
|
|
||||||
{
|
|
||||||
return mrb_str_new_cstr(mrb, Font::getDefaultName());
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(FontSetDefaultName)
|
|
||||||
{
|
|
||||||
mrb_value nameObj;
|
|
||||||
mrb_get_args(mrb, "S", &nameObj);
|
|
||||||
|
|
||||||
Font::setDefaultName(RSTRING_PTR(nameObj));
|
|
||||||
|
|
||||||
return nameObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(FontGetDefaultColor)
|
|
||||||
{
|
|
||||||
return getProperty(mrb, self, CSdefault_color);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(FontSetDefaultColor)
|
|
||||||
{
|
|
||||||
MRB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
mrb_value colorObj;
|
|
||||||
mrb_get_args(mrb, "o", &colorObj);
|
|
||||||
|
|
||||||
Color *c = getPrivateDataCheck<Color>(mrb, colorObj, ColorType);
|
|
||||||
|
|
||||||
Font::setDefaultColor(*c);
|
|
||||||
|
|
||||||
return colorObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(FontGetDefaultOutColor)
|
|
||||||
{
|
|
||||||
return getProperty(mrb, self, CSdefault_out_color);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(FontSetDefaultOutColor)
|
|
||||||
{
|
|
||||||
MRB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
mrb_value colorObj;
|
|
||||||
mrb_get_args(mrb, "o", &colorObj);
|
|
||||||
|
|
||||||
Color *c = getPrivateDataCheck<Color>(mrb, colorObj, ColorType);
|
|
||||||
|
|
||||||
Font::setDefaultOutColor(*c);
|
|
||||||
|
|
||||||
return colorObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define INIT_KLASS_PROP_BIND(Klass, PropName, prop_name_s) \
|
|
||||||
{ \
|
|
||||||
mrb_define_class_method(mrb, klass, prop_name_s, Klass##Get##PropName, MRB_ARGS_NONE()); \
|
|
||||||
mrb_define_class_method(mrb, klass, prop_name_s "=", Klass##Set##PropName, MRB_ARGS_REQ(1)); \
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
fontBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
RClass *klass = defineClass(mrb, "Font");
|
|
||||||
|
|
||||||
Font::initDefaultDynAttribs();
|
|
||||||
wrapProperty(mrb, mrb_obj_value(klass), &Font::getDefaultColor(), CSdefault_color, ColorType);
|
|
||||||
|
|
||||||
mrb_define_class_method(mrb, klass, "exist?", fontDoesExist, MRB_ARGS_REQ(1));
|
|
||||||
|
|
||||||
INIT_KLASS_PROP_BIND(Font, DefaultName, "default_name");
|
|
||||||
INIT_KLASS_PROP_BIND(Font, DefaultSize, "default_size");
|
|
||||||
INIT_KLASS_PROP_BIND(Font, DefaultBold, "default_bold");
|
|
||||||
INIT_KLASS_PROP_BIND(Font, DefaultItalic, "default_italic");
|
|
||||||
INIT_KLASS_PROP_BIND(Font, DefaultColor, "default_color");
|
|
||||||
|
|
||||||
if (rgssVer >= 2)
|
|
||||||
{
|
|
||||||
INIT_KLASS_PROP_BIND(Font, DefaultShadow, "default_shadow");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
|
||||||
{
|
|
||||||
INIT_KLASS_PROP_BIND(Font, DefaultOutline, "default_outline");
|
|
||||||
INIT_KLASS_PROP_BIND(Font, DefaultOutColor, "default_out_color");
|
|
||||||
wrapProperty(mrb, mrb_obj_value(klass), &Font::getDefaultOutColor(), CSdefault_out_color, ColorType);
|
|
||||||
}
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "initialize", fontInitialize, MRB_ARGS_OPT(2));
|
|
||||||
mrb_define_method(mrb, klass, "initialize_copy", fontInitializeCopy, MRB_ARGS_REQ(1));
|
|
||||||
|
|
||||||
INIT_PROP_BIND(Font, Name, "name");
|
|
||||||
INIT_PROP_BIND(Font, Size, "size");
|
|
||||||
INIT_PROP_BIND(Font, Bold, "bold");
|
|
||||||
INIT_PROP_BIND(Font, Italic, "italic");
|
|
||||||
INIT_PROP_BIND(Font, Color, "color");
|
|
||||||
|
|
||||||
if (rgssVer >= 2)
|
|
||||||
{
|
|
||||||
INIT_PROP_BIND(Font, Shadow, "shadow");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
|
||||||
{
|
|
||||||
INIT_PROP_BIND(Font, Outline, "outline");
|
|
||||||
INIT_PROP_BIND(Font, OutColor, "out_color");
|
|
||||||
}
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE());
|
|
||||||
}
|
|
|
@ -1,121 +0,0 @@
|
||||||
/*
|
|
||||||
** graphics-binding.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "graphics.h"
|
|
||||||
#include "sharedstate.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "exception.h"
|
|
||||||
|
|
||||||
MRB_FUNCTION(graphicsUpdate)
|
|
||||||
{
|
|
||||||
MRB_FUN_UNUSED_PARAM;
|
|
||||||
|
|
||||||
shState->graphics().update();
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(graphicsFreeze)
|
|
||||||
{
|
|
||||||
MRB_FUN_UNUSED_PARAM;
|
|
||||||
|
|
||||||
shState->graphics().freeze();
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(graphicsTransition)
|
|
||||||
{
|
|
||||||
mrb_int duration = 8;
|
|
||||||
const char *filename = "";
|
|
||||||
mrb_int vague = 40;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "|izi", &duration, &filename, &vague);
|
|
||||||
|
|
||||||
GUARD_EXC( shState->graphics().transition(duration, filename, vague); )
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(graphicsFrameReset)
|
|
||||||
{
|
|
||||||
MRB_FUN_UNUSED_PARAM;
|
|
||||||
|
|
||||||
shState->graphics().frameReset();
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEF_GRA_PROP_I(PropName) \
|
|
||||||
MRB_FUNCTION(graphics##Get##PropName) \
|
|
||||||
{ \
|
|
||||||
MRB_FUN_UNUSED_PARAM; \
|
|
||||||
return mrb_fixnum_value(shState->graphics().get##PropName()); \
|
|
||||||
} \
|
|
||||||
MRB_FUNCTION(graphics##Set##PropName) \
|
|
||||||
{ \
|
|
||||||
mrb_int value; \
|
|
||||||
mrb_get_args(mrb, "i", &value); \
|
|
||||||
shState->graphics().set##PropName(value); \
|
|
||||||
return mrb_fixnum_value(value); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEF_GRA_PROP_B(PropName) \
|
|
||||||
MRB_FUNCTION(graphics##Get##PropName) \
|
|
||||||
{ \
|
|
||||||
MRB_FUN_UNUSED_PARAM; \
|
|
||||||
return mrb_bool_value(shState->graphics().get##PropName()); \
|
|
||||||
} \
|
|
||||||
MRB_FUNCTION(graphics##Set##PropName) \
|
|
||||||
{ \
|
|
||||||
mrb_bool value; \
|
|
||||||
mrb_get_args(mrb, "b", &value); \
|
|
||||||
shState->graphics().set##PropName(value); \
|
|
||||||
return mrb_bool_value(value); \
|
|
||||||
}
|
|
||||||
|
|
||||||
DEF_GRA_PROP_I(FrameRate)
|
|
||||||
DEF_GRA_PROP_I(FrameCount)
|
|
||||||
|
|
||||||
DEF_GRA_PROP_B(Fullscreen)
|
|
||||||
DEF_GRA_PROP_B(ShowCursor)
|
|
||||||
|
|
||||||
#define INIT_GRA_PROP_BIND(PropName, prop_name_s) \
|
|
||||||
{ \
|
|
||||||
mrb_define_module_function(mrb, module, prop_name_s, graphics##Get##PropName, MRB_ARGS_NONE()); \
|
|
||||||
mrb_define_module_function(mrb, module, prop_name_s "=", graphics##Set##PropName, MRB_ARGS_REQ(1)); \
|
|
||||||
}
|
|
||||||
|
|
||||||
void graphicsBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
RClass *module = mrb_define_module(mrb, "Graphics");
|
|
||||||
|
|
||||||
mrb_define_module_function(mrb, module, "update", graphicsUpdate, MRB_ARGS_NONE());
|
|
||||||
mrb_define_module_function(mrb, module, "freeze", graphicsFreeze, MRB_ARGS_NONE());
|
|
||||||
mrb_define_module_function(mrb, module, "transition", graphicsTransition, MRB_ARGS_OPT(3));
|
|
||||||
mrb_define_module_function(mrb, module, "frame_reset", graphicsFrameReset, MRB_ARGS_NONE());
|
|
||||||
|
|
||||||
INIT_GRA_PROP_BIND( FrameRate, "frame_rate" );
|
|
||||||
INIT_GRA_PROP_BIND( FrameCount, "frame_count" );
|
|
||||||
|
|
||||||
INIT_GRA_PROP_BIND( Fullscreen, "fullscreen" );
|
|
||||||
INIT_GRA_PROP_BIND( ShowCursor, "show_cursor" );
|
|
||||||
}
|
|
|
@ -1,210 +0,0 @@
|
||||||
/*
|
|
||||||
** input-binding.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "input.h"
|
|
||||||
#include "sharedstate.h"
|
|
||||||
#include "exception.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "util.h"
|
|
||||||
|
|
||||||
#include <mruby/hash.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
MRB_FUNCTION(inputUpdate)
|
|
||||||
{
|
|
||||||
MRB_FUN_UNUSED_PARAM;
|
|
||||||
|
|
||||||
shState->input().update();
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
static mrb_int getButtonArg(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
mrb_int num;
|
|
||||||
mrb_value arg;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "o", &arg);
|
|
||||||
|
|
||||||
if (mrb_fixnum_p(arg))
|
|
||||||
{
|
|
||||||
num = mrb_fixnum(arg);
|
|
||||||
}
|
|
||||||
else if (mrb_symbol_p(arg) && rgssVer >= 3)
|
|
||||||
{
|
|
||||||
mrb_value symHash = getMrbData(mrb)->buttoncodeHash;
|
|
||||||
mrb_value numVal = mrb_hash_fetch(mrb, symHash, arg,
|
|
||||||
mrb_fixnum_value(Input::None));
|
|
||||||
num = mrb_fixnum(numVal);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// FIXME: RMXP allows only few more types that
|
|
||||||
// don't make sense (symbols in pre 3, floats)
|
|
||||||
num = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(inputPress)
|
|
||||||
{
|
|
||||||
MRB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
mrb_int num = getButtonArg(mrb);
|
|
||||||
|
|
||||||
return mrb_bool_value(shState->input().isPressed(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(inputTrigger)
|
|
||||||
{
|
|
||||||
MRB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
mrb_int num = getButtonArg(mrb);
|
|
||||||
|
|
||||||
return mrb_bool_value(shState->input().isTriggered(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(inputRepeat)
|
|
||||||
{
|
|
||||||
MRB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
mrb_int num = getButtonArg(mrb);
|
|
||||||
|
|
||||||
return mrb_bool_value(shState->input().isRepeated(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(inputDir4)
|
|
||||||
{
|
|
||||||
MRB_FUN_UNUSED_PARAM;
|
|
||||||
|
|
||||||
return mrb_fixnum_value(shState->input().dir4Value());
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(inputDir8)
|
|
||||||
{
|
|
||||||
MRB_FUN_UNUSED_PARAM;
|
|
||||||
|
|
||||||
return mrb_fixnum_value(shState->input().dir8Value());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Non-standard extensions */
|
|
||||||
MRB_FUNCTION(inputMouseX)
|
|
||||||
{
|
|
||||||
MRB_FUN_UNUSED_PARAM;
|
|
||||||
|
|
||||||
return mrb_fixnum_value(shState->input().mouseX());
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(inputMouseY)
|
|
||||||
{
|
|
||||||
MRB_FUN_UNUSED_PARAM;
|
|
||||||
|
|
||||||
return mrb_fixnum_value(shState->input().mouseY());
|
|
||||||
}
|
|
||||||
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
const char *str;
|
|
||||||
Input::ButtonCode val;
|
|
||||||
}
|
|
||||||
static buttonCodes[] =
|
|
||||||
{
|
|
||||||
{ "DOWN", Input::Down },
|
|
||||||
{ "LEFT", Input::Left },
|
|
||||||
{ "RIGHT", Input::Right },
|
|
||||||
{ "UP", Input::Up },
|
|
||||||
|
|
||||||
{ "A", Input::A },
|
|
||||||
{ "B", Input::B },
|
|
||||||
{ "C", Input::C },
|
|
||||||
{ "X", Input::X },
|
|
||||||
{ "Y", Input::Y },
|
|
||||||
{ "Z", Input::Z },
|
|
||||||
{ "L", Input::L },
|
|
||||||
{ "R", Input::R },
|
|
||||||
|
|
||||||
{ "SHIFT", Input::Shift },
|
|
||||||
{ "CTRL", Input::Ctrl },
|
|
||||||
{ "ALT", Input::Alt },
|
|
||||||
|
|
||||||
{ "F5", Input::F5 },
|
|
||||||
{ "F6", Input::F6 },
|
|
||||||
{ "F7", Input::F7 },
|
|
||||||
{ "F8", Input::F8 },
|
|
||||||
{ "F9", Input::F9 },
|
|
||||||
|
|
||||||
{ "MOUSELEFT", Input::MouseLeft },
|
|
||||||
{ "MOUSEMIDDLE", Input::MouseMiddle },
|
|
||||||
{ "MOUSERIGHT", Input::MouseRight }
|
|
||||||
};
|
|
||||||
|
|
||||||
static elementsN(buttonCodes);
|
|
||||||
|
|
||||||
void
|
|
||||||
inputBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
RClass *module = mrb_define_module(mrb, "Input");
|
|
||||||
|
|
||||||
mrb_define_module_function(mrb, module, "update", inputUpdate, MRB_ARGS_NONE());
|
|
||||||
mrb_define_module_function(mrb, module, "press?", inputPress, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_module_function(mrb, module, "trigger?", inputTrigger, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_module_function(mrb, module, "repeat?", inputRepeat, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_module_function(mrb, module, "dir4", inputDir4, MRB_ARGS_NONE());
|
|
||||||
mrb_define_module_function(mrb, module, "dir8", inputDir8, MRB_ARGS_NONE());
|
|
||||||
|
|
||||||
mrb_define_module_function(mrb, module, "mouse_x", inputMouseX, MRB_ARGS_NONE());
|
|
||||||
mrb_define_module_function(mrb, module, "mouse_y", inputMouseY, MRB_ARGS_NONE());
|
|
||||||
|
|
||||||
mrb_value modVal = mrb_obj_value(module);
|
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
|
||||||
{
|
|
||||||
mrb_value symHash = mrb_hash_new_capa(mrb, buttonCodesN);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < buttonCodesN; ++i)
|
|
||||||
{
|
|
||||||
const char *str = buttonCodes[i].str;
|
|
||||||
mrb_sym sym = mrb_intern_static(mrb, str, strlen(str));
|
|
||||||
mrb_value symVal = mrb_symbol_value(sym);
|
|
||||||
mrb_value val = mrb_fixnum_value(buttonCodes[i].val);
|
|
||||||
|
|
||||||
/* In RGSS3 all Input::XYZ constants are equal to :XYZ symbols,
|
|
||||||
* to be compatible with the previous convention */
|
|
||||||
mrb_const_set(mrb, modVal, sym, symVal);
|
|
||||||
mrb_hash_set(mrb, symHash, symVal, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
mrb_iv_set(mrb, modVal, mrb_intern_lit(mrb, "buttoncodes"), symHash);
|
|
||||||
getMrbData(mrb)->buttoncodeHash = symHash;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < buttonCodesN; ++i)
|
|
||||||
{
|
|
||||||
const char *str = buttonCodes[i].str;
|
|
||||||
mrb_sym sym = mrb_intern_static(mrb, str, strlen(str));
|
|
||||||
mrb_value val = mrb_fixnum_value(buttonCodes[i].val);
|
|
||||||
|
|
||||||
mrb_const_set(mrb, modVal, sym, val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
# mruby support in cmake wasn't finished, I assume it wouldn't be
|
|
||||||
# here either -- it can be done later
|
|
||||||
|
|
||||||
warning('mruby support in meson needs to be finished')
|
|
||||||
|
|
||||||
mruby = meson.get_compiler('cpp').find_library('mruby')
|
|
||||||
add_languages('c')
|
|
||||||
|
|
||||||
binding_dependencies = [mruby]
|
|
||||||
|
|
||||||
binding_headers = files(
|
|
||||||
'binding-util.h',
|
|
||||||
'disposable-binding.h',
|
|
||||||
'flashable-binding.h',
|
|
||||||
'binding-types.h',
|
|
||||||
'sceneelement-binding.h',
|
|
||||||
'viewportelement-binding.h',
|
|
||||||
'serializable-binding.h',
|
|
||||||
'mrb-ext/file.h',
|
|
||||||
'mrb-ext/rwmem.h',
|
|
||||||
'mrb-ext/marshal.h'
|
|
||||||
)
|
|
||||||
|
|
||||||
binding_source = files(
|
|
||||||
'binding-mruby.cpp',
|
|
||||||
'binding-util.cpp',
|
|
||||||
'window-binding.cpp',
|
|
||||||
'bitmap-binding.cpp',
|
|
||||||
'sprite-binding.cpp',
|
|
||||||
'font-binding.cpp',
|
|
||||||
'viewport-binding.cpp',
|
|
||||||
'plane-binding.cpp',
|
|
||||||
'audio-binding.cpp',
|
|
||||||
'tilemap-binding.cpp',
|
|
||||||
'etc-binding.cpp',
|
|
||||||
'graphics-binding.cpp',
|
|
||||||
'input-binding.cpp',
|
|
||||||
'table-binding.cpp',
|
|
||||||
'module_rpg.c',
|
|
||||||
'mrb-ext/file.cpp',
|
|
||||||
'mrb-ext/marshal.cpp',
|
|
||||||
'mrb-ext/rwmem.cpp',
|
|
||||||
'mrb-ext/kernel.cpp',
|
|
||||||
'mrb-ext/time.cpp'
|
|
||||||
)
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,604 +0,0 @@
|
||||||
/*
|
|
||||||
** file.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "file.h"
|
|
||||||
|
|
||||||
#include "debugwriter.h"
|
|
||||||
|
|
||||||
#include "../binding-util.h"
|
|
||||||
#include <mruby/string.h>
|
|
||||||
#include <mruby/array.h>
|
|
||||||
#include <mruby/class.h>
|
|
||||||
|
|
||||||
#include <SDL_rwops.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <libgen.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
extern mrb_value timeFromSecondsInt(mrb_state *mrb, time_t seconds);
|
|
||||||
|
|
||||||
static void
|
|
||||||
checkValid(mrb_state *mrb, FileImpl *p, int rwMode = FileImpl::ReadWrite)
|
|
||||||
{
|
|
||||||
MrbData *data = getMrbData(mrb);
|
|
||||||
|
|
||||||
if (p->closed)
|
|
||||||
mrb_raise(mrb, data->exc[IO], "closed stream");
|
|
||||||
|
|
||||||
if (!(p->mode & rwMode))
|
|
||||||
{
|
|
||||||
const char *errorMsg = 0;
|
|
||||||
|
|
||||||
switch (rwMode)
|
|
||||||
{
|
|
||||||
case FileImpl::Read :
|
|
||||||
errorMsg = "not openend for reading"; break;
|
|
||||||
case FileImpl::Write :
|
|
||||||
errorMsg = "not openend for writing"; break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
|
|
||||||
mrb_raise(mrb, data->exc[IO], errorMsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern const mrb_data_type FileType =
|
|
||||||
{
|
|
||||||
"File",
|
|
||||||
freeInstance<FileImpl>
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
|
||||||
getOpenMode(const char *mode)
|
|
||||||
{
|
|
||||||
#define STR_CASE(cs, ret) else if (!strcmp(mode, cs)) { return FileImpl:: ret; }
|
|
||||||
|
|
||||||
if (!strcmp(mode, "r"))
|
|
||||||
return FileImpl::Read;
|
|
||||||
STR_CASE("rb", Read)
|
|
||||||
STR_CASE("r+", ReadWrite)
|
|
||||||
STR_CASE("w", Write)
|
|
||||||
STR_CASE("wb", Write)
|
|
||||||
STR_CASE("w+", ReadWrite)
|
|
||||||
STR_CASE("rw", ReadWrite)
|
|
||||||
STR_CASE("a", Write)
|
|
||||||
STR_CASE("a+", ReadWrite)
|
|
||||||
|
|
||||||
Debug() << "getOpenMode failed for:" << mode;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void handleErrno(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
MrbException exc;
|
|
||||||
const char *msg;
|
|
||||||
mrb_value arg1;
|
|
||||||
|
|
||||||
#define ENO(_eno, _msg) \
|
|
||||||
case _eno: { exc = Errno##_eno; msg = _msg; break; }
|
|
||||||
|
|
||||||
switch (errno)
|
|
||||||
{
|
|
||||||
ENO(EACCES, "");
|
|
||||||
ENO(EBADF, "");
|
|
||||||
ENO(EEXIST, "");
|
|
||||||
ENO(EINVAL, "");
|
|
||||||
ENO(EMFILE, "");
|
|
||||||
ENO(ENOMEM, "");
|
|
||||||
ENO(ERANGE, "");
|
|
||||||
default:
|
|
||||||
exc = IO; msg = "Unknown Errno: %S";
|
|
||||||
arg1 = mrb_any_to_s(mrb, mrb_fixnum_value(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef ENO
|
|
||||||
|
|
||||||
mrb_raisef(mrb, getMrbData(mrb)->exc[exc], msg, arg1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define GUARD_ERRNO(stmnt) \
|
|
||||||
{ \
|
|
||||||
errno = 0; \
|
|
||||||
{ stmnt } \
|
|
||||||
if (errno != 0) \
|
|
||||||
handleErrno(mrb); \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static char *
|
|
||||||
findLastDot(char *str)
|
|
||||||
{
|
|
||||||
char *find = 0;
|
|
||||||
char *ptr = str;
|
|
||||||
|
|
||||||
/* Dot in front is not considered */
|
|
||||||
if (*ptr == '.')
|
|
||||||
ptr++;
|
|
||||||
|
|
||||||
for (; *ptr; ++ptr)
|
|
||||||
{
|
|
||||||
/* Dot in dirpath is not considered */
|
|
||||||
if (*ptr == '/')
|
|
||||||
{
|
|
||||||
ptr++;
|
|
||||||
if (*ptr == '.')
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*ptr == '.')
|
|
||||||
find = ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return find;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* File class methods */
|
|
||||||
MRB_FUNCTION(fileBasename)
|
|
||||||
{
|
|
||||||
mrb_value filename;
|
|
||||||
const char *suffix = 0;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "S|z", &filename, &suffix);
|
|
||||||
|
|
||||||
char *_filename = RSTRING_PTR(filename);
|
|
||||||
char *base = basename(_filename);
|
|
||||||
|
|
||||||
char *ext = 0;
|
|
||||||
|
|
||||||
if (suffix)
|
|
||||||
{
|
|
||||||
ext = findLastDot(base);
|
|
||||||
if (ext && !strcmp(ext, suffix))
|
|
||||||
*ext = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
mrb_value str = mrb_str_new_cstr(mrb, base);
|
|
||||||
|
|
||||||
/* Restore param string */
|
|
||||||
if (ext)
|
|
||||||
*ext = '.';
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(fileDelete)
|
|
||||||
{
|
|
||||||
mrb_int argc;
|
|
||||||
mrb_value *argv;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "*", &argv, &argc);
|
|
||||||
|
|
||||||
for (int i = 0; i < argc; ++i)
|
|
||||||
{
|
|
||||||
mrb_value &v = argv[i];
|
|
||||||
|
|
||||||
if (!mrb_string_p(v))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const char *filename = RSTRING_PTR(v);
|
|
||||||
GUARD_ERRNO( unlink(filename); )
|
|
||||||
}
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(fileDirname)
|
|
||||||
{
|
|
||||||
mrb_value filename;
|
|
||||||
mrb_get_args(mrb, "S", &filename);
|
|
||||||
|
|
||||||
char *_filename = RSTRING_PTR(filename);
|
|
||||||
char *dir = dirname(_filename);
|
|
||||||
|
|
||||||
return mrb_str_new_cstr(mrb, dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(fileExpandPath)
|
|
||||||
{
|
|
||||||
const char *path;
|
|
||||||
const char *defDir = 0;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "z|z", &path, &defDir);
|
|
||||||
|
|
||||||
// FIXME No idea how to integrate 'default_dir' right now
|
|
||||||
if (defDir)
|
|
||||||
Debug() << "FIXME: File.expand_path: default_dir not implemented";
|
|
||||||
|
|
||||||
char buffer[PATH_MAX];
|
|
||||||
char *unused = realpath(path, buffer);
|
|
||||||
(void) unused;
|
|
||||||
|
|
||||||
return mrb_str_new_cstr(mrb, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(fileExtname)
|
|
||||||
{
|
|
||||||
mrb_value filename;
|
|
||||||
mrb_get_args(mrb, "S", &filename);
|
|
||||||
|
|
||||||
char *ext = findLastDot(RSTRING_PTR(filename));
|
|
||||||
|
|
||||||
return mrb_str_new_cstr(mrb, ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(fileOpen)
|
|
||||||
{
|
|
||||||
mrb_value path;
|
|
||||||
const char *mode = "r";
|
|
||||||
mrb_value block = mrb_nil_value();
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "S|z&", &path, &mode, &block);
|
|
||||||
|
|
||||||
/* We manually check errno because we're supplying the
|
|
||||||
* filename on ENOENT */
|
|
||||||
errno = 0;
|
|
||||||
FILE *f = fopen(RSTRING_PTR(path), mode);
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
if (errno == ENOENT)
|
|
||||||
mrb_raisef(mrb, getMrbData(mrb)->exc[ErrnoENOENT],
|
|
||||||
"No such file or directory - %S", path);
|
|
||||||
else
|
|
||||||
handleErrno(mrb);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_RWops *ops = SDL_RWFromFP(f, SDL_TRUE);
|
|
||||||
FileImpl *p = new FileImpl(ops, getOpenMode(mode));
|
|
||||||
|
|
||||||
mrb_value obj = wrapObject(mrb, p, FileType);
|
|
||||||
setProperty(mrb, obj, CSpath, path);
|
|
||||||
|
|
||||||
if (mrb_type(block) == MRB_TT_PROC)
|
|
||||||
{
|
|
||||||
// FIXME inquire how GC behaviour works here for obj
|
|
||||||
mrb_value ret = mrb_yield(mrb, block, obj);
|
|
||||||
p->close();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(fileRename)
|
|
||||||
{
|
|
||||||
const char *from, *to;
|
|
||||||
mrb_get_args(mrb, "zz", &from, &to);
|
|
||||||
|
|
||||||
GUARD_ERRNO( rename(from, to); )
|
|
||||||
|
|
||||||
return mrb_fixnum_value(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MRB_FUNCTION(mrbNoop)
|
|
||||||
{
|
|
||||||
MRB_FUN_UNUSED_PARAM;
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* File instance methods */
|
|
||||||
MRB_METHOD(fileClose)
|
|
||||||
{
|
|
||||||
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
|
|
||||||
checkValid(mrb, p);
|
|
||||||
|
|
||||||
GUARD_ERRNO( p->close(); )
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
readLine(FILE *f, std::vector<char> &buffer)
|
|
||||||
{
|
|
||||||
buffer.clear();
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (feof(f))
|
|
||||||
break;
|
|
||||||
|
|
||||||
int c = fgetc(f);
|
|
||||||
|
|
||||||
if (c == '\n' || c == EOF)
|
|
||||||
break;
|
|
||||||
|
|
||||||
buffer.push_back(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(fileEachLine)
|
|
||||||
{
|
|
||||||
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
|
|
||||||
checkValid(mrb, p, FileImpl::Read);
|
|
||||||
FILE *f = p->fp();
|
|
||||||
|
|
||||||
mrb_value block;
|
|
||||||
mrb_get_args(mrb, "&", &block);
|
|
||||||
|
|
||||||
(void) f;
|
|
||||||
std::vector<char> buffer;
|
|
||||||
|
|
||||||
mrb_value str = mrb_str_buf_new(mrb, 0);
|
|
||||||
|
|
||||||
while (feof(f) == 0)
|
|
||||||
{
|
|
||||||
GUARD_ERRNO( readLine(f, buffer); )
|
|
||||||
|
|
||||||
if (buffer.empty() && feof(f) != 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
size_t lineLen = buffer.size();
|
|
||||||
mrb_str_resize(mrb, str, lineLen);
|
|
||||||
memcpy(RSTRING_PTR(str), &buffer[0], lineLen);
|
|
||||||
|
|
||||||
mrb_yield(mrb, block, str);
|
|
||||||
}
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(fileEachByte)
|
|
||||||
{
|
|
||||||
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
|
|
||||||
checkValid(mrb, p, FileImpl::Read);
|
|
||||||
FILE *f = p->fp();
|
|
||||||
|
|
||||||
mrb_value block;
|
|
||||||
mrb_get_args(mrb, "&", &block);
|
|
||||||
|
|
||||||
GUARD_ERRNO(
|
|
||||||
while (feof(f) == 0)
|
|
||||||
{
|
|
||||||
mrb_int byte = fgetc(f);
|
|
||||||
|
|
||||||
if (byte == -1)
|
|
||||||
break;
|
|
||||||
|
|
||||||
mrb_yield(mrb, block, mrb_fixnum_value(byte));
|
|
||||||
})
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(fileIsEof)
|
|
||||||
{
|
|
||||||
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
|
|
||||||
checkValid(mrb, p);
|
|
||||||
FILE *f = p->fp();
|
|
||||||
|
|
||||||
bool isEof;
|
|
||||||
GUARD_ERRNO( isEof = feof(f) != 0; )
|
|
||||||
|
|
||||||
return mrb_bool_value(isEof);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(fileSetPos)
|
|
||||||
{
|
|
||||||
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
|
|
||||||
checkValid(mrb, p);
|
|
||||||
FILE *f = p->fp();
|
|
||||||
|
|
||||||
mrb_int pos;
|
|
||||||
mrb_get_args(mrb, "i", &pos);
|
|
||||||
|
|
||||||
GUARD_ERRNO( fseek(f, pos, SEEK_SET); )
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(fileGetPos)
|
|
||||||
{
|
|
||||||
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
|
|
||||||
checkValid(mrb, p);
|
|
||||||
FILE *f = p->fp();
|
|
||||||
|
|
||||||
long pos;
|
|
||||||
GUARD_ERRNO( pos = ftell(f); )
|
|
||||||
|
|
||||||
return mrb_fixnum_value(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(fileRead)
|
|
||||||
{
|
|
||||||
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
|
|
||||||
checkValid(mrb, p, FileImpl::Read);
|
|
||||||
FILE *f = p->fp();
|
|
||||||
|
|
||||||
long cur, size;
|
|
||||||
GUARD_ERRNO( cur = ftell(f); )
|
|
||||||
GUARD_ERRNO( fseek(f, 0, SEEK_END); )
|
|
||||||
GUARD_ERRNO( size = ftell(f); )
|
|
||||||
GUARD_ERRNO( fseek(f, cur, SEEK_SET); )
|
|
||||||
|
|
||||||
mrb_int length = size - cur;
|
|
||||||
mrb_get_args(mrb, "|i", &length);
|
|
||||||
|
|
||||||
mrb_value str = mrb_str_new(mrb, 0, 0);
|
|
||||||
mrb_str_resize(mrb, str, length);
|
|
||||||
|
|
||||||
GUARD_ERRNO( int unused = fread(RSTRING_PTR(str), 1, length, f); (void) unused; )
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME this function always splits on newline right now,
|
|
||||||
// to make rs fully work, I'll have to use some strrstr magic I guess
|
|
||||||
MRB_METHOD(fileReadLines)
|
|
||||||
{
|
|
||||||
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
|
|
||||||
checkValid(mrb, p, FileImpl::Read);
|
|
||||||
FILE *f = p->fp();
|
|
||||||
|
|
||||||
mrb_value arg;
|
|
||||||
mrb_get_args(mrb, "|o", &arg);
|
|
||||||
|
|
||||||
const char *rs = "\n"; (void) rs;
|
|
||||||
if (mrb->c->ci->argc > 0)
|
|
||||||
{
|
|
||||||
Debug() << "FIXME: File.readlines: rs not implemented";
|
|
||||||
|
|
||||||
if (mrb_string_p(arg))
|
|
||||||
rs = RSTRING_PTR(arg);
|
|
||||||
else if (mrb_nil_p(arg))
|
|
||||||
rs = "\n";
|
|
||||||
else
|
|
||||||
mrb_raise(mrb, getMrbData(mrb)->exc[TypeError], "Expected string or nil"); // FIXME add "got <> instead" remark
|
|
||||||
}
|
|
||||||
|
|
||||||
mrb_value ary = mrb_ary_new(mrb);
|
|
||||||
std::vector<char> buffer;
|
|
||||||
|
|
||||||
while (feof(f) == 0)
|
|
||||||
{
|
|
||||||
GUARD_ERRNO( readLine(f, buffer); )
|
|
||||||
|
|
||||||
if (buffer.empty() && feof(f) != 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
mrb_value str = mrb_str_new(mrb, &buffer[0], buffer.size());
|
|
||||||
mrb_ary_push(mrb, ary, str);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ary;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(fileWrite)
|
|
||||||
{
|
|
||||||
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
|
|
||||||
checkValid(mrb, p, FileImpl::Write);
|
|
||||||
FILE *f = p->fp();
|
|
||||||
|
|
||||||
mrb_value str;
|
|
||||||
mrb_get_args(mrb, "S", &str);
|
|
||||||
|
|
||||||
size_t count;
|
|
||||||
GUARD_ERRNO( count = fwrite(RSTRING_PTR(str), 1, RSTRING_LEN(str), f); )
|
|
||||||
|
|
||||||
return mrb_fixnum_value(count);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(fileGetPath)
|
|
||||||
{
|
|
||||||
FileImpl *p = getPrivateData<FileImpl>(mrb, self);
|
|
||||||
checkValid(mrb, p);
|
|
||||||
|
|
||||||
return getProperty(mrb, self, CSpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
getFileStat(mrb_state *mrb, struct stat &fileStat)
|
|
||||||
{
|
|
||||||
const char *filename;
|
|
||||||
mrb_get_args(mrb, "z", &filename);
|
|
||||||
|
|
||||||
stat(filename, &fileStat);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(fileGetMtime)
|
|
||||||
{
|
|
||||||
mrb_value path = getProperty(mrb, self, CSpath);
|
|
||||||
|
|
||||||
struct stat fileStat;
|
|
||||||
stat(RSTRING_PTR(path), &fileStat);
|
|
||||||
|
|
||||||
return timeFromSecondsInt(mrb, fileStat.st_mtim.tv_sec);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FileTest module functions */
|
|
||||||
MRB_FUNCTION(fileTestDoesExist)
|
|
||||||
{
|
|
||||||
const char *filename;
|
|
||||||
mrb_get_args(mrb, "z", &filename);
|
|
||||||
|
|
||||||
int result = access(filename, F_OK);
|
|
||||||
|
|
||||||
return mrb_bool_value(result == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(fileTestIsFile)
|
|
||||||
{
|
|
||||||
struct stat fileStat;
|
|
||||||
getFileStat(mrb, fileStat);
|
|
||||||
|
|
||||||
return mrb_bool_value(S_ISREG(fileStat.st_mode));
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(fileTestIsDirectory)
|
|
||||||
{
|
|
||||||
struct stat fileStat;
|
|
||||||
getFileStat(mrb, fileStat);
|
|
||||||
|
|
||||||
return mrb_bool_value(S_ISDIR(fileStat.st_mode));
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(fileTestSize)
|
|
||||||
{
|
|
||||||
struct stat fileStat;
|
|
||||||
getFileStat(mrb, fileStat);
|
|
||||||
|
|
||||||
return mrb_fixnum_value(fileStat.st_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
fileBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
mrb_define_method(mrb, mrb->kernel_module, "open", fileOpen, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(1) | MRB_ARGS_BLOCK());
|
|
||||||
|
|
||||||
RClass *klass = defineClass(mrb, "IO");
|
|
||||||
klass = mrb_define_class(mrb, "File", klass);
|
|
||||||
|
|
||||||
mrb_define_class_method(mrb, klass, "basename", fileBasename, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(1));
|
|
||||||
mrb_define_class_method(mrb, klass, "delete", fileDelete, MRB_ARGS_REQ(1) | MRB_ARGS_ANY());
|
|
||||||
mrb_define_class_method(mrb, klass, "dirname", fileDirname, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_class_method(mrb, klass, "expand_path", fileExpandPath, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(1));
|
|
||||||
mrb_define_class_method(mrb, klass, "extname", fileExtname, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_class_method(mrb, klass, "open", fileOpen, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(1) | MRB_ARGS_BLOCK());
|
|
||||||
mrb_define_class_method(mrb, klass, "rename", fileRename, MRB_ARGS_REQ(2));
|
|
||||||
|
|
||||||
/* IO */
|
|
||||||
mrb_define_method(mrb, klass, "binmode", mrbNoop, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "close", fileClose, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "each_line", fileEachLine, MRB_ARGS_BLOCK());
|
|
||||||
mrb_define_method(mrb, klass, "each_byte", fileEachByte, MRB_ARGS_BLOCK());
|
|
||||||
mrb_define_method(mrb, klass, "eof?", fileIsEof, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "pos", fileGetPos, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "pos=", fileSetPos, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_method(mrb, klass, "read", fileRead, MRB_ARGS_OPT(1));
|
|
||||||
mrb_define_method(mrb, klass, "readlines", fileReadLines, MRB_ARGS_OPT(1));
|
|
||||||
mrb_define_method(mrb, klass, "write", fileWrite, MRB_ARGS_REQ(1));
|
|
||||||
|
|
||||||
/* File */
|
|
||||||
mrb_define_method(mrb, klass, "mtime", fileGetMtime, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "path", fileGetPath, MRB_ARGS_NONE());
|
|
||||||
|
|
||||||
/* FileTest */
|
|
||||||
RClass *module = mrb_define_module(mrb, "FileTest");
|
|
||||||
mrb_define_module_function(mrb, module, "exist?", fileTestDoesExist, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_module_function(mrb, module, "directory?", fileTestIsDirectory, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_module_function(mrb, module, "file?", fileTestIsFile, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_module_function(mrb, module, "size", fileTestSize, MRB_ARGS_REQ(1));
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
/*
|
|
||||||
** file.h
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BINDING_FILE_H
|
|
||||||
#define BINDING_FILE_H
|
|
||||||
|
|
||||||
#include "../binding-util.h"
|
|
||||||
|
|
||||||
#include <SDL_rwops.h>
|
|
||||||
|
|
||||||
struct FileImpl
|
|
||||||
{
|
|
||||||
SDL_RWops *ops;
|
|
||||||
bool closed;
|
|
||||||
|
|
||||||
enum OpenMode
|
|
||||||
{
|
|
||||||
Read = 1 << 0,
|
|
||||||
Write = 1 << 1,
|
|
||||||
ReadWrite = Read | Write
|
|
||||||
};
|
|
||||||
|
|
||||||
int mode;
|
|
||||||
|
|
||||||
FileImpl(SDL_RWops *ops, int mode)
|
|
||||||
: ops(ops),
|
|
||||||
closed(false),
|
|
||||||
mode(mode)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void close()
|
|
||||||
{
|
|
||||||
if (closed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
SDL_RWclose(ops);
|
|
||||||
closed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE *fp()
|
|
||||||
{
|
|
||||||
return ops->hidden.stdio.fp;
|
|
||||||
}
|
|
||||||
|
|
||||||
~FileImpl()
|
|
||||||
{
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
DECL_TYPE(File);
|
|
||||||
|
|
||||||
#endif // BINDING_FILE_H
|
|
|
@ -1,235 +0,0 @@
|
||||||
/*
|
|
||||||
** kernel.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <mruby.h>
|
|
||||||
#include <mruby/string.h>
|
|
||||||
#include <mruby/compile.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#include <SDL_messagebox.h>
|
|
||||||
|
|
||||||
#include "../binding-util.h"
|
|
||||||
#include "marshal.h"
|
|
||||||
#include "sharedstate.h"
|
|
||||||
#include "eventthread.h"
|
|
||||||
#include "exception.h"
|
|
||||||
#include "filesystem.h"
|
|
||||||
#include "binding.h"
|
|
||||||
|
|
||||||
void mrbBindingTerminate();
|
|
||||||
|
|
||||||
MRB_FUNCTION(kernelEval)
|
|
||||||
{
|
|
||||||
const char *exp;
|
|
||||||
mrb_int expLen;
|
|
||||||
mrb_get_args(mrb, "s", &exp, &expLen);
|
|
||||||
|
|
||||||
return mrb_load_nstring(mrb, exp, expLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void printP(mrb_state *mrb,
|
|
||||||
const char *conv, const char *sep)
|
|
||||||
{
|
|
||||||
mrb_int argc;
|
|
||||||
mrb_value *argv;
|
|
||||||
mrb_get_args(mrb, "*", &argv, &argc);
|
|
||||||
|
|
||||||
mrb_value buffer = mrb_str_buf_new(mrb, 128);
|
|
||||||
mrb_value arg;
|
|
||||||
|
|
||||||
for (int i = 0; i < argc; ++i)
|
|
||||||
{
|
|
||||||
arg = argv[i];
|
|
||||||
arg = mrb_funcall(mrb, arg, conv, 0);
|
|
||||||
|
|
||||||
mrb_str_buf_append(mrb, buffer, arg);
|
|
||||||
|
|
||||||
if (i < argc)
|
|
||||||
mrb_str_buf_cat(mrb, buffer, sep, strlen(sep));
|
|
||||||
}
|
|
||||||
|
|
||||||
shState->eThread().showMessageBox(RSTRING_PTR(buffer), SDL_MESSAGEBOX_INFORMATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(kernelP)
|
|
||||||
{
|
|
||||||
printP(mrb, "inspect", "\n");
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(kernelPrint)
|
|
||||||
{
|
|
||||||
printP(mrb, "to_s", "");
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME store this in kernel module
|
|
||||||
static int currentSeed = 1;
|
|
||||||
bool srandCalled = false;
|
|
||||||
|
|
||||||
static void
|
|
||||||
srandCurrentTime(int *currentSeed)
|
|
||||||
{
|
|
||||||
timeval tv;
|
|
||||||
gettimeofday(&tv, 0);
|
|
||||||
|
|
||||||
// FIXME could check how MRI does this
|
|
||||||
*currentSeed = tv.tv_sec * tv.tv_usec;
|
|
||||||
|
|
||||||
srand(*currentSeed);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(kernelRand)
|
|
||||||
{
|
|
||||||
if (!srandCalled)
|
|
||||||
{
|
|
||||||
srandCurrentTime(¤tSeed);
|
|
||||||
srandCalled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
mrb_value arg;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "o", &arg);
|
|
||||||
|
|
||||||
if (mrb_fixnum_p(arg) && mrb_fixnum(arg) != 0)
|
|
||||||
{
|
|
||||||
return mrb_fixnum_value(rand() % mrb_fixnum(arg));
|
|
||||||
}
|
|
||||||
else if ((mrb_fixnum_p(arg) && mrb_fixnum(arg) == 0) || mrb_nil_p(arg))
|
|
||||||
{
|
|
||||||
return mrb_float_value(mrb, (float) rand() / RAND_MAX);
|
|
||||||
}
|
|
||||||
else if (mrb_float_p(arg))
|
|
||||||
{
|
|
||||||
return mrb_float_value(mrb, (float) rand() / RAND_MAX);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mrb_raisef(mrb, E_TYPE_ERROR, "Expected Fixnum or Float, got %S",
|
|
||||||
mrb_str_new_cstr(mrb, mrb_class_name(mrb, mrb_class(mrb, arg))));
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(kernelSrand)
|
|
||||||
{
|
|
||||||
srandCalled = true;
|
|
||||||
|
|
||||||
if (mrb->c->ci->argc == 1)
|
|
||||||
{
|
|
||||||
mrb_int seed;
|
|
||||||
mrb_get_args(mrb, "i", &seed);
|
|
||||||
srand(seed);
|
|
||||||
|
|
||||||
int oldSeed = currentSeed;
|
|
||||||
currentSeed = seed;
|
|
||||||
|
|
||||||
return mrb_fixnum_value(oldSeed);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int oldSeed = currentSeed;
|
|
||||||
srandCurrentTime(¤tSeed);
|
|
||||||
|
|
||||||
return mrb_fixnum_value(oldSeed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(kernelExit)
|
|
||||||
{
|
|
||||||
MRB_FUN_UNUSED_PARAM;
|
|
||||||
|
|
||||||
scriptBinding->terminate();
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(kernelLoadData)
|
|
||||||
{
|
|
||||||
const char *filename;
|
|
||||||
mrb_get_args(mrb, "z", &filename);
|
|
||||||
|
|
||||||
SDL_RWops ops;
|
|
||||||
GUARD_EXC( shState->fileSystem().openRead(ops, filename); )
|
|
||||||
|
|
||||||
mrb_value obj;
|
|
||||||
try { obj = marshalLoadInt(mrb, &ops); }
|
|
||||||
catch (const Exception &e)
|
|
||||||
{
|
|
||||||
SDL_RWclose(&ops);
|
|
||||||
raiseMrbExc(mrb, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_RWclose(&ops);
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(kernelSaveData)
|
|
||||||
{
|
|
||||||
mrb_value obj;
|
|
||||||
const char *filename;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "oz", &obj, &filename);
|
|
||||||
|
|
||||||
SDL_RWops *ops = SDL_RWFromFile(filename, "w");
|
|
||||||
if (!ops)
|
|
||||||
mrb_raise(mrb, getMrbData(mrb)->exc[SDL], SDL_GetError());
|
|
||||||
|
|
||||||
try { marshalDumpInt(mrb, ops, obj); }
|
|
||||||
catch (const Exception &e)
|
|
||||||
{
|
|
||||||
SDL_RWclose(ops);
|
|
||||||
raiseMrbExc(mrb, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_RWclose(ops);
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(kernelInteger)
|
|
||||||
{
|
|
||||||
mrb_value obj;
|
|
||||||
mrb_get_args(mrb, "o", &obj);
|
|
||||||
|
|
||||||
return mrb_to_int(mrb, obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
void kernelBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
RClass *module = mrb->kernel_module;
|
|
||||||
|
|
||||||
mrb_define_module_function(mrb, module, "eval", kernelEval, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_module_function(mrb, module, "p", kernelP, MRB_ARGS_REQ(1) | MRB_ARGS_REST());
|
|
||||||
mrb_define_module_function(mrb, module, "print", kernelPrint, MRB_ARGS_REQ(1) | MRB_ARGS_REST());
|
|
||||||
mrb_define_module_function(mrb, module, "rand", kernelRand, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_module_function(mrb, module, "srand", kernelSrand, MRB_ARGS_OPT(1));
|
|
||||||
mrb_define_module_function(mrb, module, "exit", kernelExit, MRB_ARGS_NONE());
|
|
||||||
mrb_define_module_function(mrb, module, "load_data", kernelLoadData, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_module_function(mrb, module, "save_data", kernelSaveData, MRB_ARGS_REQ(2));
|
|
||||||
mrb_define_module_function(mrb, module, "exit", kernelExit, MRB_ARGS_NONE());
|
|
||||||
mrb_define_module_function(mrb, module, "Integer", kernelInteger, MRB_ARGS_REQ(1));
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,31 +0,0 @@
|
||||||
/*
|
|
||||||
** marshal.h
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MARSHAL_H
|
|
||||||
#define MARSHAL_H
|
|
||||||
|
|
||||||
#include <mruby.h>
|
|
||||||
#include <SDL_rwops.h>
|
|
||||||
|
|
||||||
void marshalDumpInt(mrb_state *, SDL_RWops *, mrb_value);
|
|
||||||
mrb_value marshalLoadInt(mrb_state *, SDL_RWops *);
|
|
||||||
|
|
||||||
#endif // MARSHAL_H
|
|
|
@ -1,108 +0,0 @@
|
||||||
/*
|
|
||||||
** rwmem.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "rwmem.h"
|
|
||||||
#include "util.h"
|
|
||||||
|
|
||||||
#include <SDL_rwops.h>
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
typedef std::vector<char> ByteVec;
|
|
||||||
|
|
||||||
static inline ByteVec *
|
|
||||||
getRWPrivate(SDL_RWops *ops)
|
|
||||||
{
|
|
||||||
return static_cast<ByteVec*>(ops->hidden.unknown.data1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Sint64 SDL_RWopsSize(SDL_RWops *ops)
|
|
||||||
{
|
|
||||||
ByteVec *v = getRWPrivate(ops);
|
|
||||||
|
|
||||||
return v->size();
|
|
||||||
}
|
|
||||||
|
|
||||||
static Sint64 SDL_RWopsSeek(SDL_RWops *, Sint64, int)
|
|
||||||
{
|
|
||||||
/* No need for implementation */
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t SDL_RWopsRead(SDL_RWops *, void *, size_t, size_t)
|
|
||||||
{
|
|
||||||
/* No need for implementation */
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t SDL_RWopsWrite(SDL_RWops *ops, const void *buffer, size_t size, size_t num)
|
|
||||||
{
|
|
||||||
ByteVec *v = getRWPrivate(ops);
|
|
||||||
|
|
||||||
size_t writeBytes = size * num;
|
|
||||||
|
|
||||||
if (writeBytes == 1)
|
|
||||||
{
|
|
||||||
char byte = *static_cast<const char*>(buffer);
|
|
||||||
v->push_back(byte);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t writeInd = v->size();
|
|
||||||
v->resize(writeInd + writeBytes);
|
|
||||||
|
|
||||||
memcpy(&(*v)[writeInd], buffer, writeBytes);
|
|
||||||
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int SDL_RWopsClose(SDL_RWops *ops)
|
|
||||||
{
|
|
||||||
ByteVec *v = getRWPrivate(ops);
|
|
||||||
|
|
||||||
delete v;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RWMemOpen(SDL_RWops *ops)
|
|
||||||
{
|
|
||||||
ByteVec *v = new ByteVec;
|
|
||||||
ops->hidden.unknown.data1 = v;
|
|
||||||
|
|
||||||
ops->size = SDL_RWopsSize;
|
|
||||||
ops->seek = SDL_RWopsSeek;
|
|
||||||
ops->read = SDL_RWopsRead;
|
|
||||||
ops->write = SDL_RWopsWrite;
|
|
||||||
ops->close = SDL_RWopsClose;
|
|
||||||
}
|
|
||||||
|
|
||||||
int RWMemGetData(SDL_RWops *ops, void *buffer)
|
|
||||||
{
|
|
||||||
ByteVec *v = getRWPrivate(ops);
|
|
||||||
|
|
||||||
if (buffer)
|
|
||||||
memcpy(buffer, dataPtr(*v), v->size());
|
|
||||||
|
|
||||||
return v->size();
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
/*
|
|
||||||
** rwmem.h
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef RWMEM_H
|
|
||||||
#define RWMEM_H
|
|
||||||
|
|
||||||
struct SDL_RWops;
|
|
||||||
|
|
||||||
void RWMemOpen(SDL_RWops *ops);
|
|
||||||
|
|
||||||
int RWMemGetData(SDL_RWops *ops, void *buffer);
|
|
||||||
|
|
||||||
#endif // RWMEM_H
|
|
|
@ -1,218 +0,0 @@
|
||||||
/*
|
|
||||||
** time.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "../binding-util.h"
|
|
||||||
|
|
||||||
#include <mruby/string.h>
|
|
||||||
#include <mruby/array.h>
|
|
||||||
#include <mruby/class.h>
|
|
||||||
|
|
||||||
#include "time.h"
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
|
|
||||||
struct TimeImpl
|
|
||||||
{
|
|
||||||
struct tm _tm;
|
|
||||||
struct timeval _tv;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern const mrb_data_type TimeType =
|
|
||||||
{
|
|
||||||
"Time",
|
|
||||||
freeInstance<TimeImpl>
|
|
||||||
};
|
|
||||||
|
|
||||||
extern mrb_value
|
|
||||||
timeFromSecondsInt(mrb_state *mrb, time_t seconds)
|
|
||||||
{
|
|
||||||
TimeImpl *p = new TimeImpl;
|
|
||||||
|
|
||||||
p->_tv.tv_sec = seconds;
|
|
||||||
p->_tm = *localtime(&p->_tv.tv_sec);
|
|
||||||
|
|
||||||
mrb_value obj = wrapObject(mrb, p, TimeType);
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(timeAt)
|
|
||||||
{
|
|
||||||
mrb_int seconds;
|
|
||||||
mrb_get_args(mrb, "i", &seconds);
|
|
||||||
|
|
||||||
return timeFromSecondsInt(mrb, seconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_FUNCTION(timeNow)
|
|
||||||
{
|
|
||||||
TimeImpl *p = new TimeImpl;
|
|
||||||
|
|
||||||
gettimeofday(&p->_tv, 0);
|
|
||||||
p->_tm = *localtime(&p->_tv.tv_sec);
|
|
||||||
|
|
||||||
mrb_value obj = wrapObject(mrb, p, TimeType);
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
static mrb_value
|
|
||||||
secondsAdded(mrb_state *mrb, TimeImpl *p, mrb_int seconds)
|
|
||||||
{
|
|
||||||
TimeImpl *newP = new TimeImpl;
|
|
||||||
*newP = *p;
|
|
||||||
|
|
||||||
newP->_tv.tv_sec += seconds;
|
|
||||||
p->_tm = *localtime(&p->_tv.tv_sec);
|
|
||||||
|
|
||||||
return wrapObject(mrb, newP, TimeType);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(timePlus)
|
|
||||||
{
|
|
||||||
mrb_int seconds;
|
|
||||||
mrb_get_args(mrb, "i", &seconds);
|
|
||||||
|
|
||||||
TimeImpl *p = getPrivateData<TimeImpl>(mrb, self);
|
|
||||||
|
|
||||||
TimeImpl *newP = new TimeImpl;
|
|
||||||
*newP = *p;
|
|
||||||
|
|
||||||
newP->_tv.tv_sec += seconds;
|
|
||||||
p->_tm = *localtime(&p->_tv.tv_sec);
|
|
||||||
|
|
||||||
return wrapObject(mrb, newP, TimeType);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(timeMinus)
|
|
||||||
{
|
|
||||||
mrb_value minuent;
|
|
||||||
mrb_get_args(mrb, "o", &minuent);
|
|
||||||
|
|
||||||
TimeImpl *p = getPrivateData<TimeImpl>(mrb, self);
|
|
||||||
|
|
||||||
if (mrb_fixnum_p(minuent))
|
|
||||||
{
|
|
||||||
mrb_int seconds = mrb_fixnum(minuent);
|
|
||||||
|
|
||||||
return secondsAdded(mrb, p, -seconds);
|
|
||||||
}
|
|
||||||
else if (mrb_type(minuent) == MRB_TT_OBJECT)
|
|
||||||
{
|
|
||||||
TimeImpl *o = getPrivateDataCheck<TimeImpl>(mrb, minuent, TimeType);
|
|
||||||
|
|
||||||
return mrb_float_value(mrb, p->_tv.tv_sec - o->_tv.tv_sec);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mrb_raisef(mrb, E_TYPE_ERROR, "Expected Fixnum or Time, got %S",
|
|
||||||
mrb_str_new_cstr(mrb, mrb_class_name(mrb, mrb_class(mrb, minuent))));
|
|
||||||
}
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(timeCompare)
|
|
||||||
{
|
|
||||||
mrb_value cmpTo;
|
|
||||||
mrb_get_args(mrb, "o", &cmpTo);
|
|
||||||
|
|
||||||
mrb_int cmpToS = 0;
|
|
||||||
|
|
||||||
if (mrb_fixnum_p(cmpTo))
|
|
||||||
{
|
|
||||||
cmpToS = mrb_fixnum(cmpTo);
|
|
||||||
}
|
|
||||||
else if (mrb_type(cmpTo) == MRB_TT_OBJECT)
|
|
||||||
{
|
|
||||||
TimeImpl *cmpToP = getPrivateDataCheck<TimeImpl>(mrb, cmpTo, TimeType);
|
|
||||||
cmpToS = cmpToP->_tv.tv_sec;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mrb_raisef(mrb, E_TYPE_ERROR, "Expected Fixnum or Time, got %S",
|
|
||||||
mrb_str_new_cstr(mrb, mrb_class_name(mrb, mrb_class(mrb, cmpTo))));
|
|
||||||
}
|
|
||||||
|
|
||||||
TimeImpl *p = getPrivateData<TimeImpl>(mrb, self);
|
|
||||||
mrb_int selfS = p->_tv.tv_sec;
|
|
||||||
|
|
||||||
if (selfS < cmpToS)
|
|
||||||
return mrb_fixnum_value(-1);
|
|
||||||
else if (selfS == cmpToS)
|
|
||||||
return mrb_fixnum_value(0);
|
|
||||||
else
|
|
||||||
return mrb_fixnum_value(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(timeStrftime)
|
|
||||||
{
|
|
||||||
const char *format;
|
|
||||||
mrb_get_args(mrb, "z", &format);
|
|
||||||
|
|
||||||
TimeImpl *p = getPrivateData<TimeImpl>(mrb, self);
|
|
||||||
|
|
||||||
static char buffer[512];
|
|
||||||
strftime(buffer, sizeof(buffer), format, &p->_tm);
|
|
||||||
|
|
||||||
return mrb_str_new_cstr(mrb, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TIME_ATTR(attr) \
|
|
||||||
MRB_METHOD(timeGet_##attr) \
|
|
||||||
{ \
|
|
||||||
TimeImpl *p = getPrivateData<TimeImpl>(mrb, self); \
|
|
||||||
return mrb_fixnum_value(p->_tm.tm_##attr); \
|
|
||||||
}
|
|
||||||
|
|
||||||
TIME_ATTR(sec)
|
|
||||||
TIME_ATTR(min)
|
|
||||||
TIME_ATTR(hour)
|
|
||||||
TIME_ATTR(mday)
|
|
||||||
TIME_ATTR(mon)
|
|
||||||
TIME_ATTR(year)
|
|
||||||
TIME_ATTR(wday)
|
|
||||||
|
|
||||||
#define TIME_BIND_ATTR(attr) \
|
|
||||||
{ mrb_define_method(mrb, klass, #attr, timeGet_##attr, MRB_ARGS_NONE()); }
|
|
||||||
|
|
||||||
void
|
|
||||||
timeBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
RClass *klass = defineClass(mrb, "Time");
|
|
||||||
mrb_include_module(mrb, klass, mrb_module_get(mrb, "Comparable"));
|
|
||||||
|
|
||||||
mrb_define_class_method(mrb, klass, "now", timeNow, MRB_ARGS_NONE());
|
|
||||||
mrb_define_class_method(mrb, klass, "at", timeAt, MRB_ARGS_REQ(1));
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "+", timePlus, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_method(mrb, klass, "-", timeMinus, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_method(mrb, klass, "<=>", timeCompare, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_method(mrb, klass, "strftime", timeStrftime, MRB_ARGS_REQ(1));
|
|
||||||
|
|
||||||
TIME_BIND_ATTR(sec);
|
|
||||||
TIME_BIND_ATTR(min);
|
|
||||||
TIME_BIND_ATTR(hour);
|
|
||||||
TIME_BIND_ATTR(mday);
|
|
||||||
TIME_BIND_ATTR(mon);
|
|
||||||
TIME_BIND_ATTR(year);
|
|
||||||
TIME_BIND_ATTR(wday);
|
|
||||||
}
|
|
|
@ -1,78 +0,0 @@
|
||||||
/*
|
|
||||||
** plane-binding.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "plane.h"
|
|
||||||
#include "disposable-binding.h"
|
|
||||||
#include "viewportelement-binding.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
|
||||||
|
|
||||||
DEF_TYPE(Plane);
|
|
||||||
|
|
||||||
MRB_METHOD(planeInitialize)
|
|
||||||
{
|
|
||||||
Plane *p = viewportElementInitialize<Plane>(mrb, self);
|
|
||||||
|
|
||||||
setPrivateData(self, p, PlaneType);
|
|
||||||
|
|
||||||
p->initDynAttribs();
|
|
||||||
|
|
||||||
wrapProperty(mrb, self, &p->getColor(), CScolor, ColorType);
|
|
||||||
wrapProperty(mrb, self, &p->getTone(), CStone, ToneType);
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEF_PROP_OBJ_REF(Plane, Bitmap, Bitmap, CSbitmap)
|
|
||||||
DEF_PROP_OBJ_VAL(Plane, Color, Color, CScolor)
|
|
||||||
DEF_PROP_OBJ_VAL(Plane, Tone, Tone, CStone)
|
|
||||||
|
|
||||||
DEF_PROP_I(Plane, OX)
|
|
||||||
DEF_PROP_I(Plane, OY)
|
|
||||||
DEF_PROP_I(Plane, Opacity)
|
|
||||||
DEF_PROP_I(Plane, BlendType)
|
|
||||||
|
|
||||||
DEF_PROP_F(Plane, ZoomX)
|
|
||||||
DEF_PROP_F(Plane, ZoomY)
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
planeBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
RClass *klass = defineClass(mrb, "Plane");
|
|
||||||
|
|
||||||
disposableBindingInit<Plane> (mrb, klass);
|
|
||||||
viewportElementBindingInit<Plane>(mrb, klass);
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "initialize", planeInitialize, MRB_ARGS_OPT(1));
|
|
||||||
|
|
||||||
INIT_PROP_BIND( Plane, Bitmap, "bitmap" );
|
|
||||||
INIT_PROP_BIND( Plane, OX, "ox" );
|
|
||||||
INIT_PROP_BIND( Plane, OY, "oy" );
|
|
||||||
INIT_PROP_BIND( Plane, ZoomX, "zoom_x" );
|
|
||||||
INIT_PROP_BIND( Plane, ZoomY, "zoom_y" );
|
|
||||||
INIT_PROP_BIND( Plane, Opacity, "opacity" );
|
|
||||||
INIT_PROP_BIND( Plane, BlendType, "blend_type" );
|
|
||||||
INIT_PROP_BIND( Plane, Color, "color" );
|
|
||||||
INIT_PROP_BIND( Plane, Tone, "tone" );
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE());
|
|
||||||
}
|
|
|
@ -1,90 +0,0 @@
|
||||||
/*
|
|
||||||
** sceneelement-binding.h
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SCENEELEMENTBINDING_H
|
|
||||||
#define SCENEELEMENTBINDING_H
|
|
||||||
|
|
||||||
#include "scene.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
MRB_METHOD(sceneElementGetZ)
|
|
||||||
{
|
|
||||||
SceneElement *se = getPrivateData<C>(mrb, self);
|
|
||||||
|
|
||||||
mrb_int value = 0;
|
|
||||||
GUARD_EXC( value = se->getZ(); )
|
|
||||||
|
|
||||||
return mrb_fixnum_value(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
MRB_METHOD(sceneElementSetZ)
|
|
||||||
{
|
|
||||||
SceneElement *se = getPrivateData<C>(mrb, self);
|
|
||||||
|
|
||||||
mrb_int z;
|
|
||||||
mrb_get_args(mrb, "i", &z);
|
|
||||||
|
|
||||||
GUARD_EXC( se->setZ(z); )
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
MRB_METHOD(sceneElementGetVisible)
|
|
||||||
{
|
|
||||||
SceneElement *se = getPrivateData<C>(mrb, self);
|
|
||||||
|
|
||||||
bool value = false;
|
|
||||||
GUARD_EXC( value = se->getVisible(); )
|
|
||||||
|
|
||||||
return mrb_bool_value(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
MRB_METHOD(sceneElementSetVisible)
|
|
||||||
{
|
|
||||||
SceneElement *se = getPrivateData<C>(mrb, self);
|
|
||||||
|
|
||||||
mrb_value visibleObj;
|
|
||||||
bool visible;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "o", &visibleObj);
|
|
||||||
|
|
||||||
visible = mrb_test(visibleObj);
|
|
||||||
|
|
||||||
GUARD_EXC( se->setVisible(visible); )
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
void
|
|
||||||
sceneElementBindingInit(mrb_state *mrb, RClass *klass)
|
|
||||||
{
|
|
||||||
mrb_define_method(mrb, klass, "z", sceneElementGetZ<C>, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "z=", sceneElementSetZ<C>, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_method(mrb, klass, "visible", sceneElementGetVisible<C>, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "visible=", sceneElementSetVisible<C>, MRB_ARGS_REQ(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // SCENEELEMENTBINDING_H
|
|
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
** serializable-binding.h
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SERIALIZABLEBINDING_H
|
|
||||||
#define SERIALIZABLEBINDING_H
|
|
||||||
|
|
||||||
#include "serializable.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
|
|
||||||
#include <mruby/string.h>
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
MRB_METHOD(serializableDump)
|
|
||||||
{
|
|
||||||
Serializable *s = getPrivateData<C>(mrb, self);
|
|
||||||
|
|
||||||
int dataSize = s->serialSize();
|
|
||||||
|
|
||||||
mrb_value data = mrb_str_new(mrb, 0, dataSize);
|
|
||||||
|
|
||||||
s->serialize(RSTRING_PTR(data));
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
void
|
|
||||||
serializableBindingInit(mrb_state *mrb, RClass *klass)
|
|
||||||
{
|
|
||||||
mrb_define_method(mrb, klass, "_dump", serializableDump<C>, MRB_ARGS_NONE());
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // SERIALIZABLEBINDING_H
|
|
|
@ -1,130 +0,0 @@
|
||||||
/*
|
|
||||||
** sprite-binding.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "sprite.h"
|
|
||||||
#include "sharedstate.h"
|
|
||||||
#include "disposable-binding.h"
|
|
||||||
#include "flashable-binding.h"
|
|
||||||
#include "sceneelement-binding.h"
|
|
||||||
#include "viewportelement-binding.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
|
|
||||||
DEF_TYPE(Sprite);
|
|
||||||
|
|
||||||
MRB_METHOD(spriteInitialize)
|
|
||||||
{
|
|
||||||
Sprite *s = viewportElementInitialize<Sprite>(mrb, self);
|
|
||||||
|
|
||||||
setPrivateData(self, s, SpriteType);
|
|
||||||
|
|
||||||
/* Wrap property objects */
|
|
||||||
s->initDynAttribs();
|
|
||||||
|
|
||||||
wrapProperty(mrb, self, &s->getSrcRect(), CSsrc_rect, RectType);
|
|
||||||
wrapProperty(mrb, self, &s->getColor(), CScolor, ColorType);
|
|
||||||
wrapProperty(mrb, self, &s->getTone(), CStone, ToneType);
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEF_PROP_OBJ_REF(Sprite, Bitmap, Bitmap, CSbitmap)
|
|
||||||
DEF_PROP_OBJ_VAL(Sprite, Rect, SrcRect, CSsrc_rect)
|
|
||||||
DEF_PROP_OBJ_VAL(Sprite, Color, Color, CScolor)
|
|
||||||
DEF_PROP_OBJ_VAL(Sprite, Tone, Tone, CStone)
|
|
||||||
|
|
||||||
DEF_PROP_I(Sprite, X)
|
|
||||||
DEF_PROP_I(Sprite, Y)
|
|
||||||
DEF_PROP_I(Sprite, OX)
|
|
||||||
DEF_PROP_I(Sprite, OY)
|
|
||||||
DEF_PROP_I(Sprite, BushDepth)
|
|
||||||
DEF_PROP_I(Sprite, Opacity)
|
|
||||||
DEF_PROP_I(Sprite, BlendType)
|
|
||||||
DEF_PROP_I(Sprite, WaveAmp)
|
|
||||||
DEF_PROP_I(Sprite, WaveLength)
|
|
||||||
DEF_PROP_I(Sprite, WaveSpeed)
|
|
||||||
|
|
||||||
DEF_PROP_F(Sprite, ZoomX)
|
|
||||||
DEF_PROP_F(Sprite, ZoomY)
|
|
||||||
DEF_PROP_F(Sprite, Angle)
|
|
||||||
DEF_PROP_F(Sprite, WavePhase)
|
|
||||||
|
|
||||||
DEF_PROP_B(Sprite, Mirror)
|
|
||||||
|
|
||||||
MRB_METHOD(spriteWidth)
|
|
||||||
{
|
|
||||||
Sprite *s = getPrivateData<Sprite>(mrb, self);
|
|
||||||
|
|
||||||
int value = 0;
|
|
||||||
GUARD_EXC( value = s->getWidth(); )
|
|
||||||
|
|
||||||
return mrb_fixnum_value(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(spriteHeight)
|
|
||||||
{
|
|
||||||
Sprite *s = getPrivateData<Sprite>(mrb, self);
|
|
||||||
|
|
||||||
int value = 0;
|
|
||||||
GUARD_EXC( value = s->getHeight(); )
|
|
||||||
|
|
||||||
return mrb_fixnum_value(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
spriteBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
RClass *klass = defineClass(mrb, "Sprite");
|
|
||||||
|
|
||||||
disposableBindingInit <Sprite>(mrb, klass);
|
|
||||||
flashableBindingInit <Sprite>(mrb, klass);
|
|
||||||
viewportElementBindingInit<Sprite>(mrb, klass);
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "initialize", spriteInitialize, MRB_ARGS_OPT(1));
|
|
||||||
|
|
||||||
INIT_PROP_BIND( Sprite, Bitmap, "bitmap" );
|
|
||||||
INIT_PROP_BIND( Sprite, SrcRect, "src_rect" );
|
|
||||||
INIT_PROP_BIND( Sprite, X, "x" );
|
|
||||||
INIT_PROP_BIND( Sprite, Y, "y" );
|
|
||||||
INIT_PROP_BIND( Sprite, OX, "ox" );
|
|
||||||
INIT_PROP_BIND( Sprite, OY, "oy" );
|
|
||||||
INIT_PROP_BIND( Sprite, ZoomX, "zoom_x" );
|
|
||||||
INIT_PROP_BIND( Sprite, ZoomY, "zoom_y" );
|
|
||||||
INIT_PROP_BIND( Sprite, Angle, "angle" );
|
|
||||||
INIT_PROP_BIND( Sprite, Mirror, "mirror" );
|
|
||||||
INIT_PROP_BIND( Sprite, BushDepth, "bush_depth" );
|
|
||||||
INIT_PROP_BIND( Sprite, Opacity, "opacity" );
|
|
||||||
INIT_PROP_BIND( Sprite, BlendType, "blend_type" );
|
|
||||||
INIT_PROP_BIND( Sprite, Color, "color" );
|
|
||||||
INIT_PROP_BIND( Sprite, Tone, "tone" );
|
|
||||||
|
|
||||||
if (rgssVer >= 2)
|
|
||||||
{
|
|
||||||
mrb_define_method(mrb, klass, "width", spriteWidth, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "height", spriteHeight, MRB_ARGS_NONE());
|
|
||||||
|
|
||||||
INIT_PROP_BIND( Sprite, WaveAmp, "wave_amp" );
|
|
||||||
INIT_PROP_BIND( Sprite, WaveLength, "wave_length" );
|
|
||||||
INIT_PROP_BIND( Sprite, WaveSpeed, "wave_speed" );
|
|
||||||
INIT_PROP_BIND( Sprite, WavePhase, "wave_phase" );
|
|
||||||
}
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE());
|
|
||||||
}
|
|
|
@ -1,165 +0,0 @@
|
||||||
/*
|
|
||||||
** table-binding.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "table.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
|
||||||
#include "serializable-binding.h"
|
|
||||||
|
|
||||||
DEF_TYPE(Table);
|
|
||||||
|
|
||||||
MRB_METHOD(tableInitialize)
|
|
||||||
{
|
|
||||||
mrb_int x, y, z;
|
|
||||||
x = y = z = 1;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "i|ii", &x, &y, &z);
|
|
||||||
|
|
||||||
Table *t = new Table(x, y, z);
|
|
||||||
|
|
||||||
setPrivateData(self, t, TableType);
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TABLE_SIZE(d, D) \
|
|
||||||
MRB_METHOD(table##D##Size) \
|
|
||||||
{ \
|
|
||||||
Table *t = getPrivateData<Table>(mrb, self); \
|
|
||||||
return mrb_fixnum_value((mrb_int)t->d##Size()); \
|
|
||||||
}
|
|
||||||
|
|
||||||
TABLE_SIZE(x, X)
|
|
||||||
TABLE_SIZE(y, Y)
|
|
||||||
TABLE_SIZE(z, Z)
|
|
||||||
|
|
||||||
MRB_METHOD(tableResize)
|
|
||||||
{
|
|
||||||
Table *t = getPrivateData<Table>(mrb, self);
|
|
||||||
|
|
||||||
mrb_int x, y, z;
|
|
||||||
mrb_get_args(mrb, "i|ii", &x, &y, &z);
|
|
||||||
|
|
||||||
switch (mrb->c->ci->argc)
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
case 1:
|
|
||||||
t->resize(x);
|
|
||||||
return mrb_nil_value();
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
t->resize(x, y);
|
|
||||||
return mrb_nil_value();
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
t->resize(x, y, z);
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(tableGetAt)
|
|
||||||
{
|
|
||||||
Table *t = getPrivateData<Table>(mrb, self);
|
|
||||||
|
|
||||||
mrb_int x, y, z;
|
|
||||||
x = y = z = 0;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "i|ii", &x, &y, &z);
|
|
||||||
|
|
||||||
if (x < 0 || x >= t->xSize()
|
|
||||||
|| y < 0 || y >= t->ySize()
|
|
||||||
|| z < 0 || z >= t->zSize())
|
|
||||||
{
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
mrb_int result = t->get(x, y, z);
|
|
||||||
|
|
||||||
return mrb_fixnum_value(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define fix(x) mrb_fixnum(x)
|
|
||||||
|
|
||||||
MRB_METHOD(tableSetAt)
|
|
||||||
{
|
|
||||||
Table *t = getPrivateData<Table>(mrb, self);
|
|
||||||
|
|
||||||
int argc;
|
|
||||||
mrb_value* argv;
|
|
||||||
mrb_int x, y, z, value;
|
|
||||||
x = y = z = 0;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "*", &argv, &argc);
|
|
||||||
|
|
||||||
if (argc < 2)
|
|
||||||
mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
|
|
||||||
|
|
||||||
switch (argc)
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
case 2 :
|
|
||||||
x = fix(argv[0]);
|
|
||||||
value = fix(argv[1]);
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 3 :
|
|
||||||
x = fix(argv[0]);
|
|
||||||
y = fix(argv[1]);
|
|
||||||
value = fix(argv[2]);
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 4 :
|
|
||||||
x = fix(argv[0]);
|
|
||||||
y = fix(argv[1]);
|
|
||||||
z = fix(argv[2]);
|
|
||||||
value = fix(argv[3]);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
t->set(value, x, y, z);
|
|
||||||
|
|
||||||
return mrb_fixnum_value(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
MARSH_LOAD_FUN(Table)
|
|
||||||
INITCOPY_FUN(Table)
|
|
||||||
|
|
||||||
void
|
|
||||||
tableBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
RClass *klass = defineClass(mrb, "Table");
|
|
||||||
|
|
||||||
mrb_define_class_method(mrb, klass, "_load", TableLoad, MRB_ARGS_REQ(1));
|
|
||||||
serializableBindingInit<Table>(mrb, klass);
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "initialize", tableInitialize, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(2));
|
|
||||||
mrb_define_method(mrb, klass, "initialize_copy", TableInitializeCopy, MRB_ARGS_REQ(1));
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "resize", tableResize, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(2));
|
|
||||||
mrb_define_method(mrb, klass, "xsize", tableXSize, MRB_ARGS_NONE() );
|
|
||||||
mrb_define_method(mrb, klass, "ysize", tableYSize, MRB_ARGS_NONE() );
|
|
||||||
mrb_define_method(mrb, klass, "zsize", tableZSize, MRB_ARGS_NONE() );
|
|
||||||
mrb_define_method(mrb, klass, "[]", tableGetAt, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(2));
|
|
||||||
mrb_define_method(mrb, klass, "[]=", tableSetAt, MRB_ARGS_REQ(2) | MRB_ARGS_OPT(2));
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE());
|
|
||||||
}
|
|
|
@ -1,173 +0,0 @@
|
||||||
/*
|
|
||||||
** tilemap-binding.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "tilemap.h"
|
|
||||||
#include "viewport.h"
|
|
||||||
#include "bitmap.h"
|
|
||||||
#include "table.h"
|
|
||||||
|
|
||||||
#include "disposable-binding.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
|
||||||
|
|
||||||
#include <mruby/array.h>
|
|
||||||
|
|
||||||
static const mrb_data_type TilemapAutotilesType =
|
|
||||||
{
|
|
||||||
"TilemapAutotiles",
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
MRB_METHOD(tilemapAutotilesSet)
|
|
||||||
{
|
|
||||||
Tilemap::Autotiles *a = getPrivateData<Tilemap::Autotiles>(mrb, self);
|
|
||||||
|
|
||||||
mrb_int i;
|
|
||||||
mrb_value bitmapObj;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "io", &i, &bitmapObj);
|
|
||||||
|
|
||||||
Bitmap *bitmap = getPrivateDataCheck<Bitmap>(mrb, bitmapObj, BitmapType);
|
|
||||||
|
|
||||||
a->set(i, bitmap);
|
|
||||||
|
|
||||||
mrb_value ary = mrb_iv_get(mrb, self, getMrbData(mrb)->symbols[CSarray]);
|
|
||||||
mrb_ary_set(mrb, ary, i, bitmapObj);
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(tilemapAutotilesGet)
|
|
||||||
{
|
|
||||||
mrb_int i;
|
|
||||||
|
|
||||||
mrb_get_args (mrb, "i", &i);
|
|
||||||
|
|
||||||
if (i < 0 || i > 6)
|
|
||||||
return mrb_nil_value();
|
|
||||||
|
|
||||||
mrb_value ary = mrb_iv_get(mrb, self, getMrbData(mrb)->symbols[CSarray]);
|
|
||||||
|
|
||||||
return mrb_ary_entry(ary, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
DEF_TYPE(Tilemap);
|
|
||||||
|
|
||||||
MRB_METHOD(tilemapInitialize)
|
|
||||||
{
|
|
||||||
Tilemap *t;
|
|
||||||
|
|
||||||
/* Get parameters */
|
|
||||||
mrb_value viewportObj = mrb_nil_value();
|
|
||||||
Viewport *viewport = 0;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "|o", &viewportObj);
|
|
||||||
|
|
||||||
if (!mrb_nil_p(viewportObj))
|
|
||||||
viewport = getPrivateDataCheck<Viewport>(mrb, viewportObj, ViewportType);
|
|
||||||
|
|
||||||
/* Construct object */
|
|
||||||
t = new Tilemap(viewport);
|
|
||||||
|
|
||||||
setPrivateData(self, t, TilemapType);
|
|
||||||
|
|
||||||
setProperty(mrb, self, CSviewport, viewportObj);
|
|
||||||
|
|
||||||
wrapProperty(mrb, self, &t->getAutotiles(), CSautotiles, TilemapAutotilesType);
|
|
||||||
|
|
||||||
MrbData &mrbData = *getMrbData(mrb);
|
|
||||||
mrb_value autotilesObj = mrb_iv_get(mrb, self, mrbData.symbols[CSautotiles]);
|
|
||||||
|
|
||||||
mrb_value ary = mrb_ary_new_capa(mrb, 7);
|
|
||||||
for (int i = 0; i < 7; ++i)
|
|
||||||
mrb_ary_push(mrb, ary, mrb_nil_value());
|
|
||||||
|
|
||||||
mrb_iv_set(mrb, autotilesObj, mrbData.symbols[CSarray], ary);
|
|
||||||
|
|
||||||
/* Circular reference so both objects are always
|
|
||||||
* alive at the same time */
|
|
||||||
mrb_iv_set(mrb, autotilesObj, mrbData.symbols[CStilemap], self);
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(tilemapGetAutotiles)
|
|
||||||
{
|
|
||||||
checkDisposed<Tilemap>(mrb, self);
|
|
||||||
|
|
||||||
return getProperty(mrb, self, CSautotiles);
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(tilemapUpdate)
|
|
||||||
{
|
|
||||||
Tilemap *t = getPrivateData<Tilemap>(mrb, self);
|
|
||||||
|
|
||||||
t->update();
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(tilemapGetViewport)
|
|
||||||
{
|
|
||||||
checkDisposed<Tilemap>(mrb, self);
|
|
||||||
|
|
||||||
return getProperty(mrb, self, CSviewport);
|
|
||||||
}
|
|
||||||
|
|
||||||
DEF_PROP_OBJ_REF(Tilemap, Bitmap, Tileset, CStileset)
|
|
||||||
DEF_PROP_OBJ_REF(Tilemap, Table, MapData, CSmap_data)
|
|
||||||
DEF_PROP_OBJ_REF(Tilemap, Table, FlashData, CSflash_data)
|
|
||||||
DEF_PROP_OBJ_REF(Tilemap, Table, Priorities, CSpriorities)
|
|
||||||
|
|
||||||
DEF_PROP_B(Tilemap, Visible)
|
|
||||||
|
|
||||||
DEF_PROP_I(Tilemap, OX)
|
|
||||||
DEF_PROP_I(Tilemap, OY)
|
|
||||||
|
|
||||||
void
|
|
||||||
tilemapBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
RClass *klass = defineClass(mrb, "TilemapAutotiles");
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "[]=", tilemapAutotilesSet, MRB_ARGS_REQ(2));
|
|
||||||
mrb_define_method(mrb, klass, "[]", tilemapAutotilesGet, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE());
|
|
||||||
|
|
||||||
klass = defineClass(mrb, "Tilemap");
|
|
||||||
|
|
||||||
disposableBindingInit<Tilemap>(mrb, klass);
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "initialize", tilemapInitialize, MRB_ARGS_OPT(1));
|
|
||||||
mrb_define_method(mrb, klass, "autotiles", tilemapGetAutotiles, MRB_ARGS_NONE());
|
|
||||||
mrb_define_method(mrb, klass, "update", tilemapUpdate, MRB_ARGS_NONE());
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "viewport", tilemapGetViewport, MRB_ARGS_NONE());
|
|
||||||
|
|
||||||
INIT_PROP_BIND( Tilemap, Tileset, "tileset" );
|
|
||||||
INIT_PROP_BIND( Tilemap, MapData, "map_data" );
|
|
||||||
INIT_PROP_BIND( Tilemap, FlashData, "flash_data" );
|
|
||||||
INIT_PROP_BIND( Tilemap, Priorities, "priorities" );
|
|
||||||
INIT_PROP_BIND( Tilemap, Visible, "visible" );
|
|
||||||
INIT_PROP_BIND( Tilemap, OX, "ox" );
|
|
||||||
INIT_PROP_BIND( Tilemap, OY, "oy" );
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE());
|
|
||||||
}
|
|
|
@ -1,95 +0,0 @@
|
||||||
/*
|
|
||||||
** viewport-binding.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "viewport.h"
|
|
||||||
#include "disposable-binding.h"
|
|
||||||
#include "flashable-binding.h"
|
|
||||||
#include "sceneelement-binding.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
|
||||||
|
|
||||||
DEF_TYPE(Viewport);
|
|
||||||
|
|
||||||
MRB_METHOD(viewportInitialize)
|
|
||||||
{
|
|
||||||
Viewport *v;
|
|
||||||
|
|
||||||
if (mrb->c->ci->argc == 1)
|
|
||||||
{
|
|
||||||
/* The rect arg is only used to init the viewport,
|
|
||||||
* and does NOT replace its 'rect' property */
|
|
||||||
mrb_value rectObj;
|
|
||||||
Rect *rect;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "o", &rectObj);
|
|
||||||
|
|
||||||
rect = getPrivateDataCheck<Rect>(mrb, rectObj, RectType);
|
|
||||||
|
|
||||||
v = new Viewport(rect);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mrb_int x, y, width, height;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "iiii", &x, &y, &width, &height);
|
|
||||||
|
|
||||||
v = new Viewport(x, y, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
setPrivateData(self, v, ViewportType);
|
|
||||||
|
|
||||||
/* Wrap property objects */
|
|
||||||
v->initDynAttribs();
|
|
||||||
|
|
||||||
wrapProperty(mrb, self, &v->getRect(), CSrect, RectType);
|
|
||||||
wrapProperty(mrb, self, &v->getColor(), CScolor, ColorType);
|
|
||||||
wrapProperty(mrb, self, &v->getTone(), CStone, ToneType);
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEF_PROP_OBJ_VAL(Viewport, Rect, Rect, CSrect)
|
|
||||||
DEF_PROP_OBJ_VAL(Viewport, Color, Color, CScolor)
|
|
||||||
DEF_PROP_OBJ_VAL(Viewport, Tone, Tone, CStone)
|
|
||||||
|
|
||||||
DEF_PROP_I(Viewport, OX)
|
|
||||||
DEF_PROP_I(Viewport, OY)
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
viewportBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
RClass *klass = defineClass(mrb, "Viewport");
|
|
||||||
|
|
||||||
disposableBindingInit <Viewport>(mrb, klass);
|
|
||||||
flashableBindingInit <Viewport>(mrb, klass);
|
|
||||||
sceneElementBindingInit<Viewport>(mrb, klass);
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "initialize", viewportInitialize, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(3));
|
|
||||||
|
|
||||||
INIT_PROP_BIND( Viewport, Rect, "rect" );
|
|
||||||
INIT_PROP_BIND( Viewport, OX, "ox" );
|
|
||||||
INIT_PROP_BIND( Viewport, OY, "oy" );
|
|
||||||
INIT_PROP_BIND( Viewport, Color, "color" );
|
|
||||||
INIT_PROP_BIND( Viewport, Tone, "tone" );
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE());
|
|
||||||
}
|
|
|
@ -1,76 +0,0 @@
|
||||||
/*
|
|
||||||
** viewportelement-binding.h
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef VIEWPORTELEMENTBINDING_H
|
|
||||||
#define VIEWPORTELEMENTBINDING_H
|
|
||||||
|
|
||||||
#include "viewport.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
|
||||||
|
|
||||||
#include "sceneelement-binding.h"
|
|
||||||
#include "disposable-binding.h"
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
MRB_METHOD(viewportElementGetViewport)
|
|
||||||
{
|
|
||||||
checkDisposed<C>(mrb, self);
|
|
||||||
|
|
||||||
return getProperty(mrb, self, CSviewport);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
static C *
|
|
||||||
viewportElementInitialize(mrb_state *mrb, mrb_value self)
|
|
||||||
{
|
|
||||||
/* Get parameters */
|
|
||||||
mrb_value viewportObj = mrb_nil_value();
|
|
||||||
Viewport *viewport = 0;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "|o", &viewportObj);
|
|
||||||
|
|
||||||
if (!mrb_nil_p(viewportObj))
|
|
||||||
{
|
|
||||||
viewport = getPrivateDataCheck<Viewport>(mrb, viewportObj, ViewportType);
|
|
||||||
|
|
||||||
if (rgssVer == 1)
|
|
||||||
disposableAddChild(mrb, viewportObj, self);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Construct object */
|
|
||||||
C *ve = new C(viewport);
|
|
||||||
|
|
||||||
/* Set property objects */
|
|
||||||
setProperty(mrb, self, CSviewport, viewportObj);
|
|
||||||
|
|
||||||
return ve;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class C>
|
|
||||||
void
|
|
||||||
viewportElementBindingInit(mrb_state *mrb, RClass *klass)
|
|
||||||
{
|
|
||||||
sceneElementBindingInit<C>(mrb, klass);
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "viewport", viewportElementGetViewport<C>, MRB_ARGS_NONE());
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // VIEWPORTELEMENTBINDING_H
|
|
|
@ -1,97 +0,0 @@
|
||||||
/*
|
|
||||||
** window-binding.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "window.h"
|
|
||||||
#include "disposable-binding.h"
|
|
||||||
#include "viewportelement-binding.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
|
|
||||||
DEF_TYPE(Window);
|
|
||||||
|
|
||||||
MRB_METHOD(windowInitialize)
|
|
||||||
{
|
|
||||||
Window *w = viewportElementInitialize<Window>(mrb, self);
|
|
||||||
|
|
||||||
setPrivateData(self, w, WindowType);
|
|
||||||
|
|
||||||
w->initDynAttribs();
|
|
||||||
wrapProperty(mrb, self, &w->getCursorRect(), CScursor_rect, RectType);
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
MRB_METHOD(windowUpdate)
|
|
||||||
{
|
|
||||||
Window *w = getPrivateData<Window>(mrb, self);
|
|
||||||
|
|
||||||
w->update();
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
DEF_PROP_OBJ_REF(Window, Bitmap, Windowskin, CSwindowskin)
|
|
||||||
DEF_PROP_OBJ_REF(Window, Bitmap, Contents, CScontents)
|
|
||||||
DEF_PROP_OBJ_VAL(Window, Rect, CursorRect, CScursor_rect)
|
|
||||||
|
|
||||||
DEF_PROP_B(Window, Stretch)
|
|
||||||
DEF_PROP_B(Window, Active)
|
|
||||||
DEF_PROP_B(Window, Pause)
|
|
||||||
|
|
||||||
DEF_PROP_I(Window, X)
|
|
||||||
DEF_PROP_I(Window, Y)
|
|
||||||
DEF_PROP_I(Window, Width)
|
|
||||||
DEF_PROP_I(Window, Height)
|
|
||||||
DEF_PROP_I(Window, OX)
|
|
||||||
DEF_PROP_I(Window, OY)
|
|
||||||
DEF_PROP_I(Window, Opacity)
|
|
||||||
DEF_PROP_I(Window, BackOpacity)
|
|
||||||
DEF_PROP_I(Window, ContentsOpacity)
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
windowBindingInit(mrb_state *mrb)
|
|
||||||
{
|
|
||||||
RClass *klass = defineClass(mrb, "Window");
|
|
||||||
|
|
||||||
disposableBindingInit <Window>(mrb, klass);
|
|
||||||
viewportElementBindingInit<Window>(mrb, klass);
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "initialize", windowInitialize, MRB_ARGS_REQ(1));
|
|
||||||
mrb_define_method(mrb, klass, "update", windowUpdate, MRB_ARGS_NONE());
|
|
||||||
|
|
||||||
INIT_PROP_BIND( Window, Windowskin, "windowskin" );
|
|
||||||
INIT_PROP_BIND( Window, Contents, "contents" );
|
|
||||||
INIT_PROP_BIND( Window, Stretch, "stretch" );
|
|
||||||
INIT_PROP_BIND( Window, CursorRect, "cursor_rect" );
|
|
||||||
INIT_PROP_BIND( Window, Active, "active" );
|
|
||||||
INIT_PROP_BIND( Window, Pause, "pause" );
|
|
||||||
INIT_PROP_BIND( Window, X, "x" );
|
|
||||||
INIT_PROP_BIND( Window, Y, "y" );
|
|
||||||
INIT_PROP_BIND( Window, Width, "width" );
|
|
||||||
INIT_PROP_BIND( Window, Height, "height" );
|
|
||||||
INIT_PROP_BIND( Window, OX, "ox" );
|
|
||||||
INIT_PROP_BIND( Window, OY, "oy" );
|
|
||||||
INIT_PROP_BIND( Window, Opacity, "opacity" );
|
|
||||||
INIT_PROP_BIND( Window, BackOpacity, "back_opacity" );
|
|
||||||
INIT_PROP_BIND( Window, ContentsOpacity, "contents_opacity" );
|
|
||||||
|
|
||||||
mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE());
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
/*
|
|
||||||
** binding-null.cpp
|
|
||||||
**
|
|
||||||
** This file is part of mkxp.
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
||||||
**
|
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
|
||||||
** it under the terms of the GNU General Public License as published by
|
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
|
||||||
** (at your option) any later version.
|
|
||||||
**
|
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
** GNU General Public License for more details.
|
|
||||||
**
|
|
||||||
** You should have received a copy of the GNU General Public License
|
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "binding.h"
|
|
||||||
#include "sharedstate.h"
|
|
||||||
#include "eventthread.h"
|
|
||||||
#include "debugwriter.h"
|
|
||||||
|
|
||||||
static void nullBindingExecute()
|
|
||||||
{
|
|
||||||
Debug() << "The null binding doesn't do anything, so we're done!";
|
|
||||||
shState->rtData().rqTermAck.set();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void nullBindingTerminate()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void nullBindingReset()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ScriptBinding scriptBindingImpl =
|
|
||||||
{
|
|
||||||
nullBindingExecute,
|
|
||||||
nullBindingTerminate,
|
|
||||||
nullBindingReset
|
|
||||||
};
|
|
||||||
|
|
||||||
ScriptBinding *scriptBinding = &scriptBindingImpl;
|
|
|
@ -1,5 +0,0 @@
|
||||||
binding_headers = []
|
|
||||||
binding_dependencies = []
|
|
||||||
binding_source = files(
|
|
||||||
'binding-null.cpp'
|
|
||||||
)
|
|
|
@ -80,7 +80,9 @@ void graphicsBindingInit();
|
||||||
|
|
||||||
void fileIntBindingInit();
|
void fileIntBindingInit();
|
||||||
|
|
||||||
|
#ifdef OLD_RUBY
|
||||||
void MiniDLBindingInit();
|
void MiniDLBindingInit();
|
||||||
|
#endif
|
||||||
|
|
||||||
RB_METHOD(mriPrint);
|
RB_METHOD(mriPrint);
|
||||||
RB_METHOD(mriP);
|
RB_METHOD(mriP);
|
||||||
|
@ -120,7 +122,9 @@ static void mriBindingInit()
|
||||||
|
|
||||||
fileIntBindingInit();
|
fileIntBindingInit();
|
||||||
|
|
||||||
|
#ifdef OLD_RUBY
|
||||||
MiniDLBindingInit();
|
MiniDLBindingInit();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
if (rgssVer >= 3)
|
||||||
{
|
{
|
|
@ -2,17 +2,17 @@
|
||||||
ver = get_option('mri_version')
|
ver = get_option('mri_version')
|
||||||
binding_dependencies = []
|
binding_dependencies = []
|
||||||
if ver.version_compare('>1.8') == true
|
if ver.version_compare('>1.8') == true
|
||||||
mri = dependency('ruby-' + ver)
|
binding_dependencies += dependency('ruby-' + ver)
|
||||||
binding_dependencies += mri
|
|
||||||
else
|
else
|
||||||
lib = get_option('ruby_lib')
|
lib = get_option('ruby_lib')
|
||||||
mri = meson.get_compiler('cpp').find_library(lib)
|
binding_dependencies += meson.get_compiler('cpp').find_library(lib)
|
||||||
if lib.endswith('-static')
|
if host_system == 'windows'
|
||||||
if host_system == 'windows'
|
if lib.endswith('-static')
|
||||||
binding_dependencies += meson.get_compiler('cpp').find_library('wsock32')
|
binding_dependencies += meson.get_compiler('cpp').find_library('wsock32')
|
||||||
endif
|
endif
|
||||||
|
else
|
||||||
|
binding_dependencies += meson.get_compiler('cpp').find_library('dl')
|
||||||
endif
|
endif
|
||||||
binding_dependencies += [mri]
|
|
||||||
add_project_arguments('-DOLD_RUBY', language: 'cpp')
|
add_project_arguments('-DOLD_RUBY', language: 'cpp')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ binding_headers = files(
|
||||||
'flashable-binding.h',
|
'flashable-binding.h',
|
||||||
)
|
)
|
||||||
|
|
||||||
binding_source = files(
|
binding_source = [files(
|
||||||
'binding-mri.cpp',
|
'binding-mri.cpp',
|
||||||
'binding-util.cpp',
|
'binding-util.cpp',
|
||||||
'table-binding.cpp',
|
'table-binding.cpp',
|
||||||
|
@ -45,7 +45,10 @@ binding_source = files(
|
||||||
'filesystem-binding.cpp',
|
'filesystem-binding.cpp',
|
||||||
'windowvx-binding.cpp',
|
'windowvx-binding.cpp',
|
||||||
'tilemapvx-binding.cpp',
|
'tilemapvx-binding.cpp',
|
||||||
'minidl-binding.cpp'
|
)]
|
||||||
)
|
|
||||||
|
if ver.version_compare('<=1.8') == true
|
||||||
|
binding_source += files('minidl-binding.cpp')
|
||||||
|
endif
|
||||||
|
|
||||||
bindings = [binding_headers, binding_source]
|
bindings = [binding_headers, binding_source]
|
|
@ -14,24 +14,18 @@ RUN apt-get install curl \
|
||||||
#--------------------
|
#--------------------
|
||||||
RUN mkdir /source
|
RUN mkdir /source
|
||||||
|
|
||||||
# Install stock Ruby (2.5 for bionic)
|
# Install Ruby 1.8
|
||||||
RUN apt-get install ruby ruby-dev -y
|
RUN git clone --single-branch --branch ruby_1_8_7 https://github.com/inori-z/ruby /source/ruby
|
||||||
|
RUN (cd /source/ruby && autoconf && ./configure --disable-install-doc --enable-shared && make -j`nproc` && make install)
|
||||||
# Install stock mruby
|
RUN mkdir -p /usr/local/include/ruby; cp -r /source/ruby/*.h /usr/local/include/ruby
|
||||||
RUN apt-get install mruby libmruby-dev
|
|
||||||
|
|
||||||
# Install stock Ruby 1.8
|
|
||||||
RUN curl https://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7.tar.bz2 | tar xj -C /source
|
|
||||||
RUN (cd /source/ruby-1.8.7 && autoconf && ./configure --disable-install-doc --enable-shared && make && make install)
|
|
||||||
RUN mkdir -p /usr/local/include/ruby; cp -r /source/ruby-1.8.7/*.h /usr/local/include/ruby
|
|
||||||
|
|
||||||
# Install PhysFS
|
# Install PhysFS
|
||||||
RUN git clone https://github.com/criptych/physfs /source/physfs
|
RUN git clone https://github.com/criptych/physfs /source/physfs
|
||||||
RUN mkdir /source/physfs/build; (cd /source/physfs/build && cmake .. && make && make install)
|
RUN mkdir /source/physfs/build; (cd /source/physfs/build && cmake .. && make -j`nproc` && make install)
|
||||||
|
|
||||||
# Install SDL_Sound
|
# Install SDL_Sound
|
||||||
RUN git clone https://github.com/Ancurio/SDL_Sound /source/SDL_Sound
|
RUN git clone https://github.com/Ancurio/SDL_Sound /source/SDL_Sound
|
||||||
RUN (cd /source/SDL_Sound && ./bootstrap && ./configure && make install)
|
RUN (cd /source/SDL_Sound && ./bootstrap && ./configure && make -j`nproc` install)
|
||||||
|
|
||||||
RUN rm -rf /source/*
|
RUN rm -rf /source/*
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,19 @@
|
||||||
project('mkxpz', 'cpp', version: '1.0')
|
project('mkxpz', 'cpp', version: '1.0')
|
||||||
|
|
||||||
xxd = find_program('xxd')
|
xxd = find_program('xxd')
|
||||||
binding_dir = 'binding-' + get_option('binding')
|
|
||||||
host_system = host_machine.system()
|
host_system = host_machine.system()
|
||||||
|
|
||||||
if get_option('workdir_current') == true
|
if get_option('workdir_current') == true
|
||||||
add_project_arguments('-DWORKDIR_CURRENT', language: 'cpp')
|
add_project_arguments('-DWORKDIR_CURRENT', language: 'cpp')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
add_project_arguments('-DBINDING_' + get_option('binding').to_upper(), language: 'cpp')
|
|
||||||
|
|
||||||
subdir('src')
|
subdir('src')
|
||||||
subdir(binding_dir)
|
subdir('binding')
|
||||||
subdir('shader')
|
subdir('shader')
|
||||||
subdir('assets')
|
subdir('assets')
|
||||||
|
|
||||||
all_sources = [main, bindings, processed_shaders, processed_assets]
|
all_sources = [main, bindings, processed_shaders, processed_assets]
|
||||||
include_dirs = [include_directories('src', binding_dir)]
|
include_dirs = [include_directories('src', 'binding')]
|
||||||
|
|
||||||
linker_args = []
|
linker_args = []
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
option('shared_fluid', type: 'boolean', value: false, description: 'Dynamically link fluidsynth at build time')
|
option('shared_fluid', type: 'boolean', value: false, description: 'Dynamically link fluidsynth at build time')
|
||||||
option('binding', type: 'combo', value: 'mri', choices: ['mri', 'mruby', 'null'], description: 'Binding type')
|
option('mri_version', type: 'string', value: '1.8', description: 'Version of MRI to link with')
|
||||||
option('mri_version', type: 'string', value: '2.5', description: 'Version of MRI to link with')
|
|
||||||
option('workdir_current', type: 'boolean', value: false, description: 'Keep current directory on startup')
|
option('workdir_current', type: 'boolean', value: false, description: 'Keep current directory on startup')
|
||||||
option('ruby_lib', type: 'string', value: 'ruby', description: 'Name of legacy Ruby library')
|
option('ruby_lib', type: 'string', value: 'ruby', description: 'Name of legacy Ruby library')
|
Loading…
Add table
Reference in a new issue