Skip to content

Commit 4a0d7fd

Browse files
committed
All of my various changes and merges over time, mostly from other forks and pull requests, but including my BGM fade changes
1 parent 711f9a4 commit 4a0d7fd

34 files changed

+1248
-207
lines changed

assets/icon.png

60.9 KB
Loading

binding/audio-binding.cpp

+29-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,32 @@
2424
#include "binding-util.h"
2525
#include "exception.h"
2626

27+
#define DEF_PLAY_STOP_POS_FADE(entity) \
28+
RB_METHOD_GUARD(audio_##entity##Play) \
29+
{ \
30+
RB_UNUSED_PARAM; \
31+
const char *filename; \
32+
int volume = 100; \
33+
int pitch = 100; \
34+
double pos = 0.0; \
35+
bool fade = true; \
36+
rb_get_args(argc, argv, "z|iifb", &filename, &volume, &pitch, &pos, &fade RB_ARG_END); \
37+
GUARD_EXC( shState->audio().entity##Play(filename, volume, pitch, pos, fade); ) \
38+
return Qnil; \
39+
} \
40+
RB_METHOD_GUARD_END \
41+
RB_METHOD(audio_##entity##Stop) \
42+
{ \
43+
RB_UNUSED_PARAM; \
44+
shState->audio().entity##Stop(); \
45+
return Qnil; \
46+
} \
47+
RB_METHOD(audio_##entity##Pos) \
48+
{ \
49+
RB_UNUSED_PARAM; \
50+
return rb_float_new(shState->audio().entity##Pos()); \
51+
}
52+
2753
#define DEF_PLAY_STOP_POS(entity) \
2854
RB_METHOD_GUARD(audio_##entity##Play) \
2955
{ \
@@ -96,9 +122,10 @@ RB_METHOD_GUARD(audio_bgmPlay)
96122
int volume = 100;
97123
int pitch = 100;
98124
double pos = 0.0;
125+
bool fade = true;
99126
VALUE track = Qnil;
100-
rb_get_args(argc, argv, "z|iifo", &filename, &volume, &pitch, &pos, &track RB_ARG_END);
101-
shState->audio().bgmPlay(filename, volume, pitch, pos, MAYBE_NIL_TRACK(track));
127+
rb_get_args(argc, argv, "z|iifbo", &filename, &volume, &pitch, &pos, &fade, &track RB_ARG_END);
128+
shState->audio().bgmPlay(filename, volume, pitch, pos, fade, MAYBE_NIL_TRACK(track));
102129
return Qnil;
103130
}
104131
RB_METHOD_GUARD_END

binding/bitmap-binding.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,8 @@ RB_METHOD_GUARD(bitmapAddFrame){
639639
rb_scan_args(argc, argv, "11", &srcBitmap, &position);
640640

641641
Bitmap *src = getPrivateDataCheck<Bitmap>(srcBitmap, BitmapType);
642-
if (!src)
643-
raiseDisposedAccess(srcBitmap);
642+
//if (!src)
643+
// raiseDisposedAccess(srcBitmap);
644644

645645
Bitmap *b = getPrivateData<Bitmap>(self);
646646

binding/font-binding.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ RB_METHOD(fontInitialize) {
103103

104104
wrapProperty(self, &f->getColor(), "color", ColorType);
105105

106-
if (rgssVer >= 3)
106+
//if (rgssVer >= 3)
107107
wrapProperty(self, &f->getOutColor(), "out_color", ColorType);
108108

109109
return self;
@@ -125,7 +125,7 @@ RB_METHOD(fontInitializeCopy) {
125125

126126
wrapProperty(self, &f->getColor(), "color", ColorType);
127127

128-
if (rgssVer >= 3)
128+
//if (rgssVer >= 3)
129129
wrapProperty(self, &f->getOutColor(), "out_color", ColorType);
130130

131131
return self;
@@ -270,7 +270,7 @@ void fontBindingInit() {
270270

271271
rb_iv_set(klass, "default_name", defNamesObj);
272272

273-
if (rgssVer >= 3)
273+
//if (rgssVer >= 3)
274274
wrapProperty(klass, &Font::getDefaultOutColor(), "default_out_color",
275275
ColorType);
276276

@@ -280,14 +280,14 @@ void fontBindingInit() {
280280
INIT_KLASS_PROP_BIND(Font, DefaultItalic, "default_italic");
281281
INIT_KLASS_PROP_BIND(Font, DefaultColor, "default_color");
282282

283-
if (rgssVer >= 2) {
283+
//if (rgssVer >= 2) {
284284
INIT_KLASS_PROP_BIND(Font, DefaultShadow, "default_shadow");
285-
}
285+
//}
286286

287-
if (rgssVer >= 3) {
287+
//if (rgssVer >= 3) {
288288
INIT_KLASS_PROP_BIND(Font, DefaultOutline, "default_outline");
289289
INIT_KLASS_PROP_BIND(Font, DefaultOutColor, "default_out_color");
290-
}
290+
//}
291291

292292
rb_define_class_method(klass, "exist?", fontDoesExist);
293293

@@ -300,12 +300,12 @@ void fontBindingInit() {
300300
INIT_PROP_BIND(Font, Italic, "italic");
301301
INIT_PROP_BIND(Font, Color, "color");
302302

303-
if (rgssVer >= 2) {
303+
//if (rgssVer >= 2) {
304304
INIT_PROP_BIND(Font, Shadow, "shadow");
305-
}
305+
//}
306306

307-
if (rgssVer >= 3) {
307+
//if (rgssVer >= 3) {
308308
INIT_PROP_BIND(Font, Outline, "outline");
309309
INIT_PROP_BIND(Font, OutColor, "out_color");
310-
}
310+
//}
311311
}

binding/input-binding.cpp

+140
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,32 @@ static int getControllerButtonArg(VALUE *argv) {
9595
return btn;
9696
}
9797

98+
const char* prefixButton = "pad_";
99+
const char* prefixAxis = "axis_";
100+
101+
static VALUE sourceDescToRubyString(SourceDesc input) {
102+
VALUE inputValue;
103+
switch(input.type) {
104+
case Key:
105+
inputValue = rb_str_new_cstr(SDL_GetScancodeName(input.d.scan));
106+
break;
107+
case CButton:
108+
// Concatenate button prefix to name
109+
inputValue = rb_str_new_cstr(prefixButton);
110+
rb_str_concat(inputValue, rb_str_new_cstr(SDL_GameControllerGetStringForButton(input.d.cb)));
111+
break;
112+
case CAxis:
113+
// Concatenate axis prefix to name
114+
inputValue = rb_str_new_cstr(prefixAxis);
115+
rb_str_concat(inputValue, rb_str_new_cstr(SDL_GameControllerGetStringForAxis(input.d.ca.axis)));
116+
rb_str_concat(inputValue, rb_str_new_cstr(input.d.ca.dir == Negative ? "-" : "+"));
117+
break;
118+
default:
119+
inputValue = Qnil;
120+
}
121+
return inputValue;
122+
}
123+
98124
RB_METHOD(inputPress) {
99125
RB_UNUSED_PARAM;
100126

@@ -358,6 +384,113 @@ RB_METHOD(inputControllerPowerLevel) {
358384
return ret;
359385
}
360386

387+
RB_METHOD(inputGetBindings) {
388+
RB_UNUSED_PARAM;
389+
390+
rb_check_argc(argc, 1);
391+
392+
VALUE button;
393+
rb_scan_args(argc, argv, "1", &button);
394+
// Convert Input symbol to the enum used by buttonCodeHash
395+
int num = getButtonArg(&button);
396+
397+
VALUE bindings = rb_ary_new();
398+
399+
BDescVec binds;
400+
shState->rtData().bindingUpdateMsg.get(binds);
401+
402+
for (size_t i = 0; i < binds.size(); ++i)
403+
{
404+
if(binds[i].target != num) continue;
405+
406+
VALUE binding = sourceDescToRubyString(binds[i].src);
407+
rb_ary_push(bindings, binding);
408+
}
409+
410+
return bindings;
411+
}
412+
413+
RB_METHOD(inputApplyBindings) {
414+
RB_UNUSED_PARAM;
415+
416+
rb_check_argc(argc, 2);
417+
418+
VALUE button, inputArray;
419+
rb_scan_args(argc, argv, "11", &button, &inputArray);
420+
421+
// Convert Input symbol to the enum used by buttonCodeHash
422+
Input::ButtonCode num = (Input::ButtonCode) getButtonArg(&button);
423+
424+
BDescVec binds;
425+
shState->rtData().bindingUpdateMsg.get(binds);
426+
427+
// Clear existing bindings for this input
428+
binds.erase(std::remove_if(binds.begin(), binds.end(), [num](BindingDesc x) { return x.target == num; }), binds.end());
429+
430+
// Add new bindings
431+
long length = rb_array_len(inputArray);
432+
for(long i = 0; i < length; i++)
433+
{
434+
VALUE binding = rb_ary_entry(inputArray, i);
435+
BindingDesc newBinding;
436+
newBinding.target = num;
437+
438+
char* bindingString = RSTRING_PTR(binding);
439+
if(strncmp(prefixAxis, bindingString, strlen(prefixAxis)) == 0) {
440+
newBinding.src.type = CAxis;
441+
// Treat last character as direction
442+
size_t len = strlen(bindingString);
443+
newBinding.src.d.ca.dir = (AxisDir) (bindingString[len - 1] == '-' ? Negative : Positive);
444+
// Cut out the direction character
445+
bindingString[len - 1] = '\0';
446+
// Skip the prefix, leaving behind the SDL-compatible axis name
447+
newBinding.src.d.ca.axis = SDL_GameControllerGetAxisFromString(bindingString + strlen(prefixAxis));
448+
// Restore the original direction character in case someone wants to use the information fed into this
449+
bindingString[len - 1] = newBinding.src.d.ca.dir == Negative ? '-' : '+';
450+
} else if(strncmp(prefixButton, bindingString, strlen(prefixButton)) == 0) {
451+
// Gamepad Input
452+
newBinding.src.type = CButton;
453+
// Skip the prefix, leaving behind the SDL-compatible button name
454+
newBinding.src.d.cb = SDL_GameControllerGetButtonFromString(bindingString + strlen(prefixButton));
455+
} else {
456+
// No prefix, assume regular key
457+
newBinding.src.type = Key;
458+
newBinding.src.d.scan = SDL_GetScancodeFromName(bindingString);
459+
}
460+
binds.push_back(newBinding);
461+
}
462+
463+
// Update the bindings in memory
464+
shState->rtData().bindingUpdateMsg.post(binds);
465+
466+
return Qnil;
467+
}
468+
469+
RB_METHOD(inputSaveBindings) {
470+
BDescVec binds;
471+
shState->rtData().bindingUpdateMsg.get(binds);
472+
storeBindings(binds, shState->config());
473+
return Qnil;
474+
}
475+
476+
RB_METHOD(inputResetBindings) {
477+
BDescVec binds = genDefaultBindings(shState->config());
478+
shState->rtData().bindingUpdateMsg.post(binds);
479+
return Qnil;
480+
}
481+
482+
RB_METHOD(inputClearLast) {
483+
shState->eThread().clearLastInput();
484+
return Qnil;
485+
}
486+
487+
RB_METHOD(inputLast) {
488+
RB_UNUSED_PARAM;
489+
490+
SourceDesc lastInput = shState->eThread().getLastInput();
491+
return sourceDescToRubyString(lastInput);
492+
}
493+
361494
#define AXISFUNC(n, ax1, ax2) \
362495
RB_METHOD(inputControllerGet##n##Axis) {\
363496
RB_UNUSED_PARAM;\
@@ -620,6 +753,13 @@ void inputBindingInit() {
620753

621754
_rb_define_module_function(module, "clipboard", inputGetClipboard);
622755
_rb_define_module_function(module, "clipboard=", inputSetClipboard);
756+
757+
_rb_define_module_function(module, "last", inputLast);
758+
_rb_define_module_function(module, "clear_last", inputClearLast);
759+
_rb_define_module_function(module, "bindings", inputGetBindings);
760+
_rb_define_module_function(module, "apply_bindings", inputApplyBindings);
761+
_rb_define_module_function(module, "save_bindings", inputSaveBindings);
762+
_rb_define_module_function(module, "reset_bindings", inputResetBindings);
623763

624764
if (rgssVer >= 3) {
625765
VALUE symHash = rb_hash_new();

mkxp.json

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
// 2: Bicubic
8585
// 3: Lanczos3
8686
// 4: xBRZ
87+
// 5: Area
8788
// (default: 0)
8889
//
8990
// "smoothScaling": 0,

0 commit comments

Comments
 (0)