├── src ├── bundledfont.cpp ├── rgssad.h ├── iniconfig.h ├── serializable.h ├── texpool.h ├── settingsmenu.h ├── fluid-fun.cpp ├── gl-debug.h ├── exception.h ├── vertex.h ├── binding.h ├── tileatlasvx.h ├── serial-util.h ├── plane.h ├── debugwriter.h ├── input.h ├── soundemitter.h ├── global-ibo.h ├── tilemapvx.h ├── tilemap.h ├── tilequad.h ├── tileatlas.h ├── vertex.cpp ├── table.h ├── aldatasource.h ├── flashable.h ├── window.h ├── disposable.h ├── viewport.h ├── gl-meta.h ├── audio.h ├── sprite.h ├── gl-debug.cpp ├── filesystem.h ├── windowvx.h ├── graphics.h ├── keybindings.h ├── alstream.h ├── config.h ├── iniconfig.cpp ├── fluid-fun.h ├── intrulist.h ├── glstate.h ├── quadarray.h ├── boost-hash.h ├── sdl-util.h ├── quad.h ├── sdlsoundsource.cpp ├── sharedstate.h ├── glstate.cpp ├── table.cpp ├── font.h ├── sharedmidistate.h └── bitmap.h ├── windows ├── resource.h ├── icon.ico ├── resource.rc └── mkxp.exe.manifest ├── assets ├── icon.png ├── liberation.ttf └── icon.svg ├── .editorconfig ├── shader ├── flatColor.frag ├── simpleColor.frag ├── minimal.vert ├── simple.frag ├── flashMap.frag ├── simpleAlphaUni.frag ├── simpleAlpha.frag ├── common.h ├── sprite.vert ├── simple.vert ├── blur.frag ├── gray.frag ├── simpleMatrix.vert ├── simpleColor.vert ├── transSimple.frag ├── blurH.vert ├── blurV.vert ├── tilemap.vert ├── trans.frag ├── bitmapBlit.frag ├── plane.frag ├── tilemapvx.vert ├── sprite.frag └── hue.frag ├── binding-mri ├── module_rpg.cpp ├── binding-types.h ├── serializable-binding.h ├── flashable-binding.h ├── sceneelement-binding.h ├── plane-binding.cpp ├── viewportelement-binding.h ├── disposable-binding.h ├── viewport-binding.cpp └── window-binding.cpp ├── .gitignore ├── xxd+ ├── xxd+.pro └── main.cpp ├── patches └── ruby │ └── static_zlib.patch ├── binding-mruby ├── mrb-ext │ ├── rwmem.h │ ├── marshal.h │ ├── file.h │ └── rwmem.cpp ├── binding-types.h ├── serializable-binding.h ├── flashable-binding.h ├── viewportelement-binding.h ├── sceneelement-binding.h ├── plane-binding.cpp ├── audio-binding.cpp ├── viewport-binding.cpp ├── window-binding.cpp ├── disposable-binding.h └── graphics-binding.cpp ├── binding-null └── binding-null.cpp ├── steamshim └── steamshim_child.h ├── cmake └── PrepUtils.cmake ├── doc └── extension_doc.md └── sources.def /src/bundledfont.cpp: -------------------------------------------------------------------------------- 1 | #include "liberation.ttf.xxd" 2 | -------------------------------------------------------------------------------- /windows/resource.h: -------------------------------------------------------------------------------- 1 | #define IDI_MANIFEST 1 2 | #define IDI_APPICON 101 3 | -------------------------------------------------------------------------------- /assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ancurio/mkxp-freebird/HEAD/assets/icon.png -------------------------------------------------------------------------------- /windows/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ancurio/mkxp-freebird/HEAD/windows/icon.ico -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root=true 2 | [*] 3 | end_of_line = lf 4 | indent_style = tab 5 | indent_size = 4 6 | -------------------------------------------------------------------------------- /assets/liberation.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ancurio/mkxp-freebird/HEAD/assets/liberation.ttf -------------------------------------------------------------------------------- /shader/flatColor.frag: -------------------------------------------------------------------------------- 1 | 2 | uniform lowp vec4 color; 3 | 4 | void main() 5 | { 6 | gl_FragColor = color; 7 | } 8 | -------------------------------------------------------------------------------- /shader/simpleColor.frag: -------------------------------------------------------------------------------- 1 | 2 | varying lowp vec4 v_color; 3 | 4 | void main() 5 | { 6 | gl_FragColor = v_color; 7 | } 8 | -------------------------------------------------------------------------------- /binding-mri/module_rpg.cpp: -------------------------------------------------------------------------------- 1 | 2 | # include "module_rpg1.rb.xxd" 3 | # include "module_rpg2.rb.xxd" 4 | # include "module_rpg3.rb.xxd" 5 | -------------------------------------------------------------------------------- /shader/minimal.vert: -------------------------------------------------------------------------------- 1 | 2 | uniform mat4 projMat; 3 | attribute vec2 position; 4 | 5 | void main() 6 | { 7 | gl_Position = projMat * vec4(position, 0, 1); 8 | } 9 | -------------------------------------------------------------------------------- /shader/simple.frag: -------------------------------------------------------------------------------- 1 | 2 | uniform sampler2D texture; 3 | 4 | varying vec2 v_texCoord; 5 | 6 | void main() 7 | { 8 | gl_FragColor = texture2D(texture, v_texCoord); 9 | } 10 | -------------------------------------------------------------------------------- /windows/resource.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "resource.h" 4 | 5 | IDI_MANIFEST RT_MANIFEST "mkxp.exe.manifest" 6 | IDI_APPICON ICON "icon.ico" 7 | -------------------------------------------------------------------------------- /shader/flashMap.frag: -------------------------------------------------------------------------------- 1 | 2 | uniform lowp float alpha; 3 | 4 | varying lowp vec4 v_color; 5 | 6 | void main() 7 | { 8 | gl_FragColor = vec4(v_color.rgb * alpha, 1); 9 | } 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.pro.* 3 | *.bak 4 | *.vert.xxd 5 | *.frag.xxd 6 | *.ttf.xxd 7 | 8 | Makefile 9 | 10 | mkxp 11 | xxd+ 12 | 13 | /build 14 | 15 | # Codeblocks 16 | mkxp.layout 17 | mkxp.cbp 18 | 19 | -------------------------------------------------------------------------------- /shader/simpleAlphaUni.frag: -------------------------------------------------------------------------------- 1 | 2 | uniform sampler2D texture; 3 | uniform lowp float alpha; 4 | 5 | varying vec2 v_texCoord; 6 | 7 | void main() 8 | { 9 | gl_FragColor = texture2D(texture, v_texCoord); 10 | gl_FragColor.a *= alpha; 11 | } 12 | -------------------------------------------------------------------------------- /shader/simpleAlpha.frag: -------------------------------------------------------------------------------- 1 | 2 | uniform sampler2D texture; 3 | 4 | varying vec2 v_texCoord; 5 | varying lowp vec4 v_color; 6 | 7 | void main() 8 | { 9 | gl_FragColor = texture2D(texture, v_texCoord); 10 | gl_FragColor.a *= v_color.a; 11 | } 12 | -------------------------------------------------------------------------------- /shader/common.h: -------------------------------------------------------------------------------- 1 | #ifdef GLSLES 2 | 3 | #ifdef FRAGMENT_SHADER 4 | /* Only the fragment shader has no default float precision */ 5 | precision mediump float; 6 | #endif 7 | 8 | #else 9 | 10 | /* Desktop GLSL doesn't know about these */ 11 | #define highp 12 | #define mediump 13 | #define lowp 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /shader/sprite.vert: -------------------------------------------------------------------------------- 1 | 2 | uniform mat4 projMat; 3 | 4 | uniform mat4 spriteMat; 5 | 6 | uniform vec2 texSizeInv; 7 | 8 | attribute vec2 position; 9 | attribute vec2 texCoord; 10 | 11 | varying vec2 v_texCoord; 12 | 13 | void main() 14 | { 15 | gl_Position = projMat * spriteMat * vec4(position, 0, 1); 16 | v_texCoord = texCoord * texSizeInv; 17 | } 18 | -------------------------------------------------------------------------------- /shader/simple.vert: -------------------------------------------------------------------------------- 1 | 2 | uniform mat4 projMat; 3 | 4 | uniform vec2 texSizeInv; 5 | uniform vec2 translation; 6 | 7 | attribute vec2 position; 8 | attribute vec2 texCoord; 9 | 10 | varying vec2 v_texCoord; 11 | 12 | void main() 13 | { 14 | gl_Position = projMat * vec4(position + translation, 0, 1); 15 | 16 | v_texCoord = texCoord * texSizeInv; 17 | } 18 | -------------------------------------------------------------------------------- /xxd+/xxd+.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (2.01a) Sun Aug 18 13:46:33 2013 3 | ###################################################################### 4 | 5 | TEMPLATE = app 6 | TARGET = 7 | DEPENDPATH += . 8 | INCLUDEPATH += . 9 | QT = core 10 | 11 | # Input 12 | SOURCES += main.cpp 13 | -------------------------------------------------------------------------------- /shader/blur.frag: -------------------------------------------------------------------------------- 1 | 2 | uniform sampler2D texture; 3 | 4 | varying vec2 v_texCoord; 5 | varying vec2 v_blurCoord[2]; 6 | 7 | void main() 8 | { 9 | lowp vec4 frag = vec4(0, 0, 0, 0); 10 | 11 | frag += texture2D(texture, v_texCoord); 12 | frag += texture2D(texture, v_blurCoord[0]); 13 | frag += texture2D(texture, v_blurCoord[1]); 14 | 15 | gl_FragColor = frag / 3.0; 16 | } 17 | -------------------------------------------------------------------------------- /shader/gray.frag: -------------------------------------------------------------------------------- 1 | 2 | uniform sampler2D texture; 3 | uniform lowp float gray; 4 | 5 | varying vec2 v_texCoord; 6 | 7 | const vec3 lumaF = vec3(.299, .587, .114); 8 | 9 | void main() 10 | { 11 | /* Sample source color */ 12 | vec4 frag = texture2D(texture, v_texCoord); 13 | 14 | /* Apply gray */ 15 | float luma = dot(frag.rgb, lumaF); 16 | frag.rgb = mix(frag.rgb, vec3(luma), gray); 17 | 18 | gl_FragColor = frag; 19 | } 20 | -------------------------------------------------------------------------------- /shader/simpleMatrix.vert: -------------------------------------------------------------------------------- 1 | 2 | uniform mat4 projMat; 3 | uniform mat4 matrix; 4 | 5 | uniform vec2 texSizeInv; 6 | 7 | attribute vec2 position; 8 | attribute vec2 texCoord; 9 | attribute lowp vec4 color; 10 | 11 | varying vec2 v_texCoord; 12 | varying lowp vec4 v_color; 13 | 14 | void main() 15 | { 16 | gl_Position = projMat * matrix * vec4(position, 0, 1); 17 | 18 | v_texCoord = texCoord * texSizeInv; 19 | v_color = color; 20 | } 21 | -------------------------------------------------------------------------------- /shader/simpleColor.vert: -------------------------------------------------------------------------------- 1 | 2 | uniform mat4 projMat; 3 | 4 | uniform vec2 texSizeInv; 5 | uniform vec2 translation; 6 | 7 | attribute vec2 position; 8 | attribute vec2 texCoord; 9 | attribute lowp vec4 color; 10 | 11 | varying vec2 v_texCoord; 12 | varying lowp vec4 v_color; 13 | 14 | void main() 15 | { 16 | gl_Position = projMat * vec4(position + translation, 0, 1); 17 | 18 | v_texCoord = texCoord * texSizeInv; 19 | v_color = color; 20 | } 21 | -------------------------------------------------------------------------------- /shader/transSimple.frag: -------------------------------------------------------------------------------- 1 | /* Fragment shader that produces a simple 2 | * fade in / fade out type transition */ 3 | 4 | uniform sampler2D frozenScene; 5 | uniform sampler2D currentScene; 6 | uniform float prog; 7 | 8 | varying vec2 v_texCoord; 9 | 10 | void main() 11 | { 12 | vec4 newPixel = texture2D(currentScene, v_texCoord); 13 | vec4 oldPixel = texture2D(frozenScene, v_texCoord); 14 | 15 | gl_FragColor = mix(oldPixel, newPixel, prog); 16 | } 17 | -------------------------------------------------------------------------------- /shader/blurH.vert: -------------------------------------------------------------------------------- 1 | 2 | uniform mat4 projMat; 3 | 4 | uniform vec2 texSizeInv; 5 | 6 | attribute vec2 position; 7 | attribute vec2 texCoord; 8 | 9 | varying vec2 v_texCoord; 10 | varying vec2 v_blurCoord[2]; 11 | 12 | void main() 13 | { 14 | gl_Position = projMat * vec4(position, 0, 1); 15 | 16 | v_texCoord = texCoord * texSizeInv; 17 | v_blurCoord[0] = vec2(texCoord.x-1.0, texCoord.y) * texSizeInv; 18 | v_blurCoord[1] = vec2(texCoord.x+1.0, texCoord.y) * texSizeInv; 19 | } 20 | -------------------------------------------------------------------------------- /shader/blurV.vert: -------------------------------------------------------------------------------- 1 | 2 | uniform mat4 projMat; 3 | 4 | uniform vec2 texSizeInv; 5 | 6 | attribute vec2 position; 7 | attribute vec2 texCoord; 8 | 9 | varying vec2 v_texCoord; 10 | varying vec2 v_blurCoord[2]; 11 | 12 | void main() 13 | { 14 | gl_Position = projMat * vec4(position, 0, 1); 15 | 16 | v_texCoord = texCoord * texSizeInv; 17 | v_blurCoord[0] = vec2(texCoord.x, texCoord.y-1.0) * texSizeInv; 18 | v_blurCoord[1] = vec2(texCoord.x, texCoord.y+1.0) * texSizeInv; 19 | } 20 | -------------------------------------------------------------------------------- /shader/tilemap.vert: -------------------------------------------------------------------------------- 1 | 2 | uniform mat4 projMat; 3 | 4 | uniform vec2 texSizeInv; 5 | uniform vec2 translation; 6 | 7 | uniform float aniIndex; 8 | 9 | attribute vec2 position; 10 | attribute vec2 texCoord; 11 | 12 | varying vec2 v_texCoord; 13 | 14 | const float atAreaW = 96.0; 15 | const float atAreaH = 128.0*7.0; 16 | const float atAniOffset = 32.0*3.0; 17 | 18 | void main() 19 | { 20 | vec2 tex = texCoord; 21 | 22 | lowp float pred = float(tex.x <= atAreaW && tex.y <= atAreaH); 23 | tex.x += aniIndex * atAniOffset * pred; 24 | 25 | gl_Position = projMat * vec4(position + translation, 0, 1); 26 | 27 | v_texCoord = tex * texSizeInv; 28 | } 29 | -------------------------------------------------------------------------------- /shader/trans.frag: -------------------------------------------------------------------------------- 1 | /* Fragment shader dealing with transitions */ 2 | 3 | uniform sampler2D currentScene; 4 | uniform sampler2D frozenScene; 5 | uniform sampler2D transMap; 6 | /* Normalized */ 7 | uniform float prog; 8 | /* Vague [0, 512] normalized */ 9 | uniform float vague; 10 | 11 | varying vec2 v_texCoord; 12 | 13 | void main() 14 | { 15 | float transV = texture2D(transMap, v_texCoord).r; 16 | float cTransV = clamp(transV, prog, prog+vague); 17 | lowp float alpha = (cTransV - prog) / vague; 18 | 19 | vec4 newFrag = texture2D(currentScene, v_texCoord); 20 | vec4 oldFrag = texture2D(frozenScene, v_texCoord); 21 | 22 | gl_FragColor = mix(newFrag, oldFrag, alpha); 23 | } 24 | -------------------------------------------------------------------------------- /windows/mkxp.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | true 10 | 11 | PerMonitorV2 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /shader/bitmapBlit.frag: -------------------------------------------------------------------------------- 1 | /* Shader for approximating the way RMXP does bitmap 2 | * blending via DirectDraw */ 3 | 4 | uniform sampler2D source; 5 | uniform sampler2D destination; 6 | 7 | uniform vec4 subRect; 8 | 9 | uniform lowp float opacity; 10 | 11 | varying vec2 v_texCoord; 12 | 13 | void main() 14 | { 15 | vec2 coor = v_texCoord; 16 | vec2 dstCoor = (coor - subRect.xy) * subRect.zw; 17 | 18 | vec4 srcFrag = texture2D(source, coor); 19 | vec4 dstFrag = texture2D(destination, dstCoor); 20 | 21 | vec4 resFrag; 22 | 23 | float co1 = srcFrag.a * opacity; 24 | float co2 = dstFrag.a * (1.0 - co1); 25 | resFrag.a = co1 + co2; 26 | 27 | if (resFrag.a == 0.0) 28 | resFrag.rgb = srcFrag.rgb; 29 | else 30 | resFrag.rgb = (co1*srcFrag.rgb + co2*dstFrag.rgb) / resFrag.a; 31 | 32 | gl_FragColor = resFrag; 33 | } 34 | -------------------------------------------------------------------------------- /shader/plane.frag: -------------------------------------------------------------------------------- 1 | 2 | uniform sampler2D texture; 3 | 4 | uniform lowp vec4 tone; 5 | 6 | uniform lowp float opacity; 7 | uniform lowp vec4 color; 8 | uniform lowp vec4 flash; 9 | 10 | varying vec2 v_texCoord; 11 | 12 | const vec3 lumaF = vec3(.299, .587, .114); 13 | 14 | void main() 15 | { 16 | /* Sample source color */ 17 | vec4 frag = texture2D(texture, v_texCoord); 18 | 19 | /* Apply gray */ 20 | float luma = dot(frag.rgb, lumaF); 21 | frag.rgb = mix(frag.rgb, vec3(luma), tone.w); 22 | 23 | /* Apply tone */ 24 | frag.rgb += tone.rgb; 25 | 26 | /* Apply opacity */ 27 | frag.a *= opacity; 28 | 29 | /* Apply color */ 30 | frag.rgb = mix(frag.rgb, color.rgb, color.a); 31 | 32 | /* Apply flash */ 33 | frag.rgb = mix(frag.rgb, flash.rgb, flash.a); 34 | 35 | gl_FragColor = frag; 36 | } 37 | -------------------------------------------------------------------------------- /shader/tilemapvx.vert: -------------------------------------------------------------------------------- 1 | 2 | uniform mat4 projMat; 3 | 4 | uniform vec2 texSizeInv; 5 | uniform vec2 translation; 6 | 7 | uniform vec2 aniOffset; 8 | 9 | attribute vec2 position; 10 | attribute vec2 texCoord; 11 | 12 | varying vec2 v_texCoord; 13 | 14 | const vec2 atAreaA = vec2(9.0*32.0, 12.0*32.0); 15 | const float atAreaCX = 12.0*32.0; 16 | const float atAreaCW = 4.0*32.0; 17 | 18 | void main() 19 | { 20 | vec2 tex = texCoord; 21 | lowp float pred; 22 | 23 | /* Type A autotiles shift horizontally */ 24 | pred = float(tex.x <= atAreaA.x && tex.y <= atAreaA.y); 25 | tex.x += aniOffset.x * pred; 26 | 27 | /* Type C autotiles shift vertically */ 28 | pred = float(tex.x >= atAreaCX && tex.x <= (atAreaCX+atAreaCW) && tex.y <= atAreaA.y); 29 | tex.y += aniOffset.y * pred; 30 | 31 | gl_Position = projMat * vec4(position + translation, 0, 1); 32 | 33 | v_texCoord = tex * texSizeInv; 34 | } 35 | -------------------------------------------------------------------------------- /shader/sprite.frag: -------------------------------------------------------------------------------- 1 | 2 | uniform sampler2D texture; 3 | 4 | uniform lowp vec4 tone; 5 | 6 | uniform lowp float opacity; 7 | uniform lowp vec4 color; 8 | 9 | uniform float bushDepth; 10 | uniform lowp float bushOpacity; 11 | 12 | varying vec2 v_texCoord; 13 | 14 | const vec3 lumaF = vec3(.299, .587, .114); 15 | 16 | void main() 17 | { 18 | /* Sample source color */ 19 | vec4 frag = texture2D(texture, v_texCoord); 20 | 21 | /* Apply gray */ 22 | float luma = dot(frag.rgb, lumaF); 23 | frag.rgb = mix(frag.rgb, vec3(luma), tone.w); 24 | 25 | /* Apply tone */ 26 | frag.rgb += tone.rgb; 27 | 28 | /* Apply opacity */ 29 | frag.a *= opacity; 30 | 31 | /* Apply color */ 32 | frag.rgb = mix(frag.rgb, color.rgb, color.a); 33 | 34 | /* Apply bush alpha by mathematical if */ 35 | lowp float underBush = float(v_texCoord.y < bushDepth); 36 | frag.a *= clamp(bushOpacity + underBush, 0.0, 1.0); 37 | 38 | gl_FragColor = frag; 39 | } 40 | -------------------------------------------------------------------------------- /patches/ruby/static_zlib.patch: -------------------------------------------------------------------------------- 1 | --- a/common.mk 2 | +++ b/common.mk 3 | @@ -95,6 +95,7 @@ COMMONOBJS = array.$(OBJEXT) \ 4 | vm_trace.$(OBJEXT) \ 5 | thread.$(OBJEXT) \ 6 | cont.$(OBJEXT) \ 7 | + ext/zlib/zlib.$(OBJEXT) \ 8 | $(BUILTIN_ENCOBJS) \ 9 | $(BUILTIN_TRANSOBJS) \ 10 | $(MISSING) 11 | diff --git a/ruby-2.1.5.orig/configure b/ruby-2.1.5/configure 12 | index d0f1f68..45ab642 100755 13 | --- a/configure 14 | +++ b/configure 15 | @@ -2838,6 +2838,8 @@ ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. 16 | 17 | 18 | 19 | +LIBS="$LIBS -lz" 20 | + 21 | { # environment section 22 | 23 | 24 | --- a/configure.in 25 | +++ b/configure.in 26 | @@ -31,6 +31,8 @@ rm() { 27 | } 28 | ])])]) 29 | 30 | +LIBS="$LIBS -lz" 31 | + 32 | { # environment section 33 | 34 | AC_ARG_WITH(baseruby, 35 | --- a/inits.c 36 | +++ b/inits.c 37 | @@ -61,5 +61,6 @@ rb_call_inits(void) 38 | CALL(Complex); 39 | CALL(version); 40 | CALL(vm_trace); 41 | + CALL(zlib); 42 | } 43 | #undef CALL 44 | -------------------------------------------------------------------------------- /binding-mruby/mrb-ext/rwmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** rwmem.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef RWMEM_H 23 | #define RWMEM_H 24 | 25 | struct SDL_RWops; 26 | 27 | void RWMemOpen(SDL_RWops *ops); 28 | 29 | int RWMemGetData(SDL_RWops *ops, void *buffer); 30 | 31 | #endif // RWMEM_H 32 | -------------------------------------------------------------------------------- /src/rgssad.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** rgssad.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2014 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef RGSSAD_H 23 | #define RGSSAD_H 24 | 25 | #include 26 | 27 | extern const PHYSFS_Archiver RGSS1_Archiver; 28 | extern const PHYSFS_Archiver RGSS2_Archiver; 29 | extern const PHYSFS_Archiver RGSS3_Archiver; 30 | 31 | #endif // RGSSAD_H 32 | -------------------------------------------------------------------------------- /binding-mruby/mrb-ext/marshal.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** marshal.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef MARSHAL_H 23 | #define MARSHAL_H 24 | 25 | #include 26 | #include 27 | 28 | void marshalDumpInt(mrb_state *, SDL_RWops *, mrb_value); 29 | mrb_value marshalLoadInt(mrb_state *, SDL_RWops *); 30 | 31 | #endif // MARSHAL_H 32 | -------------------------------------------------------------------------------- /src/iniconfig.h: -------------------------------------------------------------------------------- 1 | #ifndef INICONFIG_H 2 | #define INICONFIG_H 3 | 4 | #include 5 | #include 6 | 7 | class INIConfiguration 8 | { 9 | class Section 10 | { 11 | friend class INIConfiguration; 12 | 13 | struct Property 14 | { 15 | std::string m_Name; 16 | std::string m_Value; 17 | }; 18 | 19 | typedef std::map property_map; 20 | public: 21 | Section (const Section& s) = default; 22 | Section (Section&& s) = default; 23 | 24 | bool getStringProperty (const std::string& name, std::string& outPropStr) const; 25 | 26 | private: 27 | explicit Section (const std::string& name); 28 | 29 | std::string m_Name; 30 | property_map m_PropertyMap; 31 | }; 32 | 33 | typedef std::map section_map; 34 | public: 35 | bool load (std::istream& inStream); 36 | 37 | std::string getStringProperty(const std::string& sname, const std::string& name, const std::string& def = "") const; 38 | 39 | protected: 40 | void addProperty (const std::string& sname, const std::string& name, const std::string& val); 41 | 42 | private: 43 | section_map m_SectionMap; 44 | }; 45 | 46 | #endif // INICONFIG_H 47 | -------------------------------------------------------------------------------- /src/serializable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** serializable.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef SERIALIZABLE_H 23 | #define SERIALIZABLE_H 24 | 25 | struct Serializable 26 | { 27 | virtual int serialSize() const = 0; 28 | virtual void serialize(char *buffer) const = 0; 29 | }; 30 | 31 | template 32 | C *deserialize(const char *data) 33 | { 34 | return C::deserialize(data); 35 | } 36 | 37 | #endif // SERIALIZABLE_H 38 | -------------------------------------------------------------------------------- /shader/hue.frag: -------------------------------------------------------------------------------- 1 | 2 | uniform sampler2D texture; 3 | uniform mediump float hueAdjust; 4 | 5 | varying vec2 v_texCoord; 6 | 7 | /* Source: gamedev.stackexchange.com/a/59808/24839 */ 8 | vec3 rgb2hsv(vec3 c) 9 | { 10 | const vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); 11 | vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); 12 | vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); 13 | 14 | float d = q.x - min(q.w, q.y); 15 | 16 | /* Avoid divide-by-zero situations by adding a very tiny delta. 17 | * Since we always deal with underlying 8-Bit color values, this 18 | * should never mask a real value */ 19 | const float eps = 1.0e-10; 20 | 21 | return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + eps)), d / (q.x + eps), q.x); 22 | } 23 | 24 | vec3 hsv2rgb(vec3 c) 25 | { 26 | const vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 27 | vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); 28 | return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); 29 | } 30 | 31 | void main () 32 | { 33 | vec4 color = texture2D (texture, v_texCoord.xy); 34 | vec3 hsv = rgb2hsv(color.rgb); 35 | 36 | hsv.x += hueAdjust; 37 | color.rgb = hsv2rgb(hsv); 38 | 39 | gl_FragColor = color; 40 | } 41 | -------------------------------------------------------------------------------- /binding-mri/binding-types.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** binding-types.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef BINDINGTYPES_H 23 | #define BINDINGTYPES_H 24 | 25 | #include "binding-util.h" 26 | 27 | DECL_TYPE(Table); 28 | DECL_TYPE(Rect); 29 | DECL_TYPE(Color); 30 | DECL_TYPE(Tone); 31 | DECL_TYPE(Font); 32 | 33 | DECL_TYPE(Bitmap); 34 | DECL_TYPE(Sprite); 35 | DECL_TYPE(Plane); 36 | DECL_TYPE(Viewport); 37 | DECL_TYPE(Tilemap); 38 | DECL_TYPE(Window); 39 | 40 | #endif // BINDINGTYPES_H 41 | -------------------------------------------------------------------------------- /binding-mruby/binding-types.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** binding-types.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef BINDINGTYPES_H 23 | #define BINDINGTYPES_H 24 | 25 | #include "binding-util.h" 26 | 27 | DECL_TYPE(Table); 28 | DECL_TYPE(Rect); 29 | DECL_TYPE(Color); 30 | DECL_TYPE(Tone); 31 | DECL_TYPE(Font); 32 | 33 | DECL_TYPE(Bitmap); 34 | DECL_TYPE(Sprite); 35 | DECL_TYPE(Plane); 36 | DECL_TYPE(Viewport); 37 | DECL_TYPE(Tilemap); 38 | DECL_TYPE(Window); 39 | 40 | #endif // BINDINGTYPES_H 41 | -------------------------------------------------------------------------------- /src/texpool.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** texpool.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef TEXPOOL_H 23 | #define TEXPOOL_H 24 | 25 | #include "gl-util.h" 26 | 27 | struct TexPoolPrivate; 28 | 29 | class TexPool 30 | { 31 | public: 32 | TexPool(uint32_t maxMemSize = 20000000 /* 20 MB */); 33 | ~TexPool(); 34 | 35 | TEXFBO request(int width, int height); 36 | void release(TEXFBO &obj); 37 | 38 | void disable(); 39 | 40 | private: 41 | TexPoolPrivate *p; 42 | }; 43 | 44 | #endif // TEXPOOL_H 45 | -------------------------------------------------------------------------------- /src/settingsmenu.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** settingsmenu.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2014 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef SETTINGSMENU_H 23 | #define SETTINGSMENU_H 24 | 25 | #include 26 | 27 | struct SettingsMenuPrivate; 28 | struct RGSSThreadData; 29 | union SDL_Event; 30 | 31 | class SettingsMenu 32 | { 33 | public: 34 | SettingsMenu(RGSSThreadData &rtData); 35 | ~SettingsMenu(); 36 | 37 | /* Returns true if the event was consumed */ 38 | bool onEvent(const SDL_Event &event); 39 | void raise(); 40 | bool destroyReq() const; 41 | 42 | private: 43 | SettingsMenuPrivate *p; 44 | }; 45 | 46 | #endif // SETTINGSMENU_H 47 | -------------------------------------------------------------------------------- /src/fluid-fun.cpp: -------------------------------------------------------------------------------- 1 | #include "fluid-fun.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "debugwriter.h" 8 | 9 | #if __LINUX__ || __ANDROID__ 10 | #define FLUID_LIB "libfluidsynth.so.1" 11 | #elif __MACOSX__ 12 | #define FLUID_LIB "libfluidsynth.1.dylib" 13 | #elif __WINDOWS__ 14 | #define FLUID_LIB "fluidsynth.dll" 15 | #else 16 | #error "platform not recognized" 17 | #endif 18 | 19 | struct FluidFunctions fluid; 20 | 21 | static void *so; 22 | 23 | void initFluidFunctions() 24 | { 25 | #ifdef SHARED_FLUID 26 | 27 | #define FLUID_FUN(name, type) \ 28 | fluid.name = fluid_##name; 29 | 30 | #define FLUID_FUN2(name, type, real_name) \ 31 | fluid.name = real_name; 32 | 33 | #else 34 | so = SDL_LoadObject(FLUID_LIB); 35 | 36 | if (!so) 37 | goto fail; 38 | 39 | #define FLUID_FUN(name, type) \ 40 | fluid.name = (type) SDL_LoadFunction(so, "fluid_" #name); \ 41 | if (!fluid.name) \ 42 | goto fail; 43 | 44 | #define FLUID_FUN2(name, type, real_name) \ 45 | fluid.name = (type) SDL_LoadFunction(so, #real_name); \ 46 | if (!fluid.name) \ 47 | goto fail; 48 | #endif 49 | 50 | FLUID_FUNCS 51 | FLUID_FUNCS2 52 | 53 | return; 54 | 55 | #ifndef SHARED_FLUID 56 | fail: 57 | Debug() << "Failed to load " FLUID_LIB ". Midi playback is disabled."; 58 | 59 | memset(&fluid, 0, sizeof(fluid)); 60 | SDL_UnloadObject(so); 61 | so = 0; 62 | #endif 63 | } 64 | -------------------------------------------------------------------------------- /binding-null/binding-null.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** binding-null.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "binding.h" 23 | #include "sharedstate.h" 24 | #include "eventthread.h" 25 | #include "debugwriter.h" 26 | 27 | static void nullBindingExecute() 28 | { 29 | Debug() << "The null binding doesn't do anything, so we're done!"; 30 | shState->rtData().rqTermAck.set(); 31 | } 32 | 33 | static void nullBindingTerminate() 34 | { 35 | 36 | } 37 | 38 | static void nullBindingReset() 39 | { 40 | 41 | } 42 | 43 | ScriptBinding scriptBindingImpl = 44 | { 45 | nullBindingExecute, 46 | nullBindingTerminate, 47 | nullBindingReset 48 | }; 49 | 50 | ScriptBinding *scriptBinding = &scriptBindingImpl; 51 | -------------------------------------------------------------------------------- /src/gl-debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** gl-debug.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef DEBUGLOGGER_H 23 | #define DEBUGLOGGER_H 24 | 25 | #include "gl-fun.h" 26 | 27 | #include 28 | #include 29 | 30 | struct GLDebugLoggerPrivate; 31 | 32 | class GLDebugLogger 33 | { 34 | public: 35 | GLDebugLogger(const char *filename = 0); 36 | ~GLDebugLogger(); 37 | 38 | private: 39 | GLDebugLoggerPrivate *p; 40 | }; 41 | 42 | #define GL_MARKER(format, ...) \ 43 | if (gl.StringMarker) \ 44 | { \ 45 | char buf[128]; \ 46 | int len = snprintf(buf, sizeof(buf), format, ##__VA_ARGS__); \ 47 | gl.StringMarker(std::min(len, sizeof(buf)), buf); \ 48 | } 49 | 50 | 51 | #endif // DEBUGLOGGER_H 52 | -------------------------------------------------------------------------------- /binding-mri/serializable-binding.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** serializable-binding.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef SERIALIZABLEBINDING_H 23 | #define SERIALIZABLEBINDING_H 24 | 25 | #include "serializable.h" 26 | #include "binding-util.h" 27 | #include "exception.h" 28 | 29 | template 30 | static VALUE 31 | serializableDump(int, VALUE *, VALUE self) 32 | { 33 | Serializable *s = getPrivateData(self); 34 | 35 | int dataSize = s->serialSize(); 36 | 37 | VALUE data = rb_str_new(0, dataSize); 38 | 39 | GUARD_EXC( s->serialize(RSTRING_PTR(data)); ); 40 | 41 | return data; 42 | } 43 | 44 | template 45 | void 46 | serializableBindingInit(VALUE klass) 47 | { 48 | _rb_define_method(klass, "_dump", serializableDump); 49 | } 50 | 51 | #endif // SERIALIZABLEBINDING_H 52 | -------------------------------------------------------------------------------- /binding-mruby/serializable-binding.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** serializable-binding.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef SERIALIZABLEBINDING_H 23 | #define SERIALIZABLEBINDING_H 24 | 25 | #include "serializable.h" 26 | #include "binding-util.h" 27 | 28 | #include 29 | 30 | template 31 | MRB_METHOD(serializableDump) 32 | { 33 | Serializable *s = getPrivateData(mrb, self); 34 | 35 | int dataSize = s->serialSize(); 36 | 37 | mrb_value data = mrb_str_new(mrb, 0, dataSize); 38 | 39 | s->serialize(RSTRING_PTR(data)); 40 | 41 | return data; 42 | } 43 | 44 | template 45 | void 46 | serializableBindingInit(mrb_state *mrb, RClass *klass) 47 | { 48 | mrb_define_method(mrb, klass, "_dump", serializableDump, MRB_ARGS_NONE()); 49 | } 50 | 51 | #endif // SERIALIZABLEBINDING_H 52 | -------------------------------------------------------------------------------- /src/exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** exception.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef EXCEPTION_H 23 | #define EXCEPTION_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | struct Exception 30 | { 31 | enum Type 32 | { 33 | RGSSError, 34 | NoFileError, 35 | IOError, 36 | 37 | /* Already defined by ruby */ 38 | TypeError, 39 | ArgumentError, 40 | 41 | /* New types introduced in mkxp */ 42 | PHYSFSError, 43 | SDLError, 44 | MKXPError 45 | }; 46 | 47 | Type type; 48 | std::string msg; 49 | 50 | Exception(Type type, const char *format, ...) 51 | : type(type) 52 | { 53 | va_list ap; 54 | va_start(ap, format); 55 | 56 | msg.resize(512); 57 | vsnprintf(&msg[0], msg.size(), format, ap); 58 | 59 | va_end(ap); 60 | } 61 | }; 62 | 63 | #endif // EXCEPTION_H 64 | -------------------------------------------------------------------------------- /src/vertex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** vertex.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2014 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef VERTEX_H 23 | #define VERTEX_H 24 | 25 | #include "etc-internal.h" 26 | #include "gl-fun.h" 27 | #include "shader.h" 28 | 29 | /* Simple Vertex */ 30 | struct SVertex 31 | { 32 | Vec2 pos; 33 | Vec2 texPos; 34 | }; 35 | 36 | /* Color Vertex */ 37 | struct CVertex 38 | { 39 | Vec2 pos; 40 | Vec4 color; 41 | 42 | CVertex(); 43 | }; 44 | 45 | struct Vertex 46 | { 47 | Vec2 pos; 48 | Vec2 texPos; 49 | Vec4 color; 50 | 51 | Vertex(); 52 | }; 53 | 54 | struct VertexAttribute 55 | { 56 | Shader::Attribute index; 57 | GLint size; 58 | GLenum type; 59 | const GLvoid *offset; 60 | }; 61 | 62 | template 63 | struct VertexTraits 64 | { 65 | static const VertexAttribute *attr; 66 | static const GLsizei attrCount; 67 | }; 68 | 69 | #endif // VERTEX_H 70 | -------------------------------------------------------------------------------- /binding-mruby/mrb-ext/file.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** file.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef BINDING_FILE_H 23 | #define BINDING_FILE_H 24 | 25 | #include "../binding-util.h" 26 | 27 | #include 28 | 29 | struct FileImpl 30 | { 31 | SDL_RWops *ops; 32 | bool closed; 33 | 34 | enum OpenMode 35 | { 36 | Read = 1 << 0, 37 | Write = 1 << 1, 38 | ReadWrite = Read | Write 39 | }; 40 | 41 | int mode; 42 | 43 | FileImpl(SDL_RWops *ops, int mode) 44 | : ops(ops), 45 | closed(false), 46 | mode(mode) 47 | {} 48 | 49 | void close() 50 | { 51 | if (closed) 52 | return; 53 | 54 | SDL_RWclose(ops); 55 | closed = true; 56 | } 57 | 58 | FILE *fp() 59 | { 60 | return ops->hidden.stdio.fp; 61 | } 62 | 63 | ~FileImpl() 64 | { 65 | close(); 66 | } 67 | }; 68 | 69 | DECL_TYPE(File); 70 | 71 | #endif // BINDING_FILE_H 72 | -------------------------------------------------------------------------------- /src/binding.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** binding.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef BINDING_H 23 | #define BINDING_H 24 | 25 | struct ScriptBinding 26 | { 27 | /* Starts the part where the binding takes over, 28 | * loading the compressed scripts and executing them. 29 | * This function returns as soon as the scripts finish 30 | * execution or an error is encountered */ 31 | void (*execute) (void); 32 | 33 | /* Instructs the binding 34 | * to immediately terminate script execution. This 35 | * function will perform a longjmp instead of returning, 36 | * so be careful about any variables with local storage */ 37 | void (*terminate) (void); 38 | 39 | /* Instructs the binding to issue a game reset. 40 | * Same conditions as for terminate apply */ 41 | void (*reset) (void); 42 | }; 43 | 44 | /* VTable defined in the binding source */ 45 | extern ScriptBinding *scriptBinding; 46 | 47 | #endif // BINDING_H 48 | -------------------------------------------------------------------------------- /src/tileatlasvx.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** tileatlasvx.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2014 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef TILEATLASVX_H 23 | #define TILEATLASVX_H 24 | 25 | #include 26 | 27 | struct FloatRect; 28 | struct TEXFBO; 29 | class Bitmap; 30 | class Table; 31 | 32 | #define ATLASVX_W 1024 33 | #define ATLASVX_H 2048 34 | 35 | /* Bitmap indices */ 36 | enum 37 | { 38 | BM_A1 = 0, 39 | BM_A2 = 1, 40 | BM_A3 = 2, 41 | BM_A4 = 3, 42 | BM_A5 = 4, 43 | BM_B = 5, 44 | BM_C = 6, 45 | BM_D = 7, 46 | BM_E = 8, 47 | 48 | BM_COUNT 49 | }; 50 | 51 | namespace TileAtlasVX 52 | { 53 | struct Reader 54 | { 55 | virtual void onQuads(const FloatRect *t, const FloatRect *p, 56 | size_t n, bool overPlayer) = 0; 57 | }; 58 | 59 | void build(TEXFBO &tf, Bitmap *bitmaps[BM_COUNT]); 60 | 61 | void readTiles(Reader &reader, const Table &data, 62 | const Table *flags, int ox, int oy, int w, int h); 63 | } 64 | 65 | #endif // TILEATLASVX_H 66 | -------------------------------------------------------------------------------- /src/serial-util.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** serial-util.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef SERIALUTIL_H 23 | #define SERIALUTIL_H 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #if SDL_BYTEORDER != SDL_LIL_ENDIAN 31 | #error "Non little endian systems not supported" 32 | #endif 33 | 34 | static inline int32_t 35 | readInt32(const char **dataP) 36 | { 37 | int32_t result; 38 | 39 | memcpy(&result, *dataP, 4); 40 | *dataP += 4; 41 | 42 | return result; 43 | } 44 | 45 | static inline double 46 | readDouble(const char **dataP) 47 | { 48 | double result; 49 | 50 | memcpy(&result, *dataP, 8); 51 | *dataP += 8; 52 | 53 | return result; 54 | } 55 | 56 | static inline void 57 | writeInt32(char **dataP, int32_t value) 58 | { 59 | memcpy(*dataP, &value, 4); 60 | *dataP += 4; 61 | } 62 | 63 | static inline void 64 | writeDouble(char **dataP, double value) 65 | { 66 | memcpy(*dataP, &value, 8); 67 | *dataP += 8; 68 | } 69 | 70 | #endif // SERIALUTIL_H 71 | -------------------------------------------------------------------------------- /steamshim/steamshim_child.h: -------------------------------------------------------------------------------- 1 | #ifndef _INCL_STEAMSHIM_CHILD_H_ 2 | #define _INCL_STEAMSHIM_CHILD_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | typedef enum STEAMSHIM_EventType 9 | { 10 | SHIMEVENT_BYE, 11 | SHIMEVENT_STATSRECEIVED, 12 | SHIMEVENT_STATSSTORED, 13 | SHIMEVENT_SETACHIEVEMENT, 14 | SHIMEVENT_GETACHIEVEMENT, 15 | SHIMEVENT_RESETSTATS, 16 | SHIMEVENT_SETSTATI, 17 | SHIMEVENT_GETSTATI, 18 | SHIMEVENT_SETSTATF, 19 | SHIMEVENT_GETSTATF, 20 | SHIMEVENT_GETPERSONANAME, 21 | SHIMEVENT_GETCURRENTGAMELANGUAGE, 22 | } STEAMSHIM_EventType; 23 | 24 | /* not all of these fields make sense in a given event. */ 25 | typedef struct STEAMSHIM_Event 26 | { 27 | STEAMSHIM_EventType type; 28 | int okay; 29 | int ivalue; 30 | float fvalue; 31 | unsigned long long epochsecs; 32 | char name[256]; 33 | } STEAMSHIM_Event; 34 | 35 | int STEAMSHIM_init(void); /* non-zero on success, zero on failure. */ 36 | void STEAMSHIM_deinit(void); 37 | int STEAMSHIM_alive(void); 38 | const STEAMSHIM_Event *STEAMSHIM_pump(void); 39 | void STEAMSHIM_requestStats(void); 40 | void STEAMSHIM_storeStats(void); 41 | void STEAMSHIM_setAchievement(const char *name, const int enable); 42 | void STEAMSHIM_getAchievement(const char *name); 43 | void STEAMSHIM_resetStats(const int bAlsoAchievements); 44 | void STEAMSHIM_setStatI(const char *name, const int _val); 45 | void STEAMSHIM_getStatI(const char *name); 46 | void STEAMSHIM_setStatF(const char *name, const float val); 47 | void STEAMSHIM_getStatF(const char *name); 48 | void STEAMSHIM_getPersonaName(); 49 | void STEAMSHIM_getCurrentGameLanguage(); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif /* include-once blocker */ 56 | 57 | /* end of steamshim_child.h ... */ 58 | -------------------------------------------------------------------------------- /src/plane.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** plane.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef PLANE_H 23 | #define PLANE_H 24 | 25 | #include "disposable.h" 26 | #include "viewport.h" 27 | 28 | class Bitmap; 29 | struct Color; 30 | struct Tone; 31 | 32 | struct PlanePrivate; 33 | 34 | class Plane : public ViewportElement, public Disposable 35 | { 36 | public: 37 | Plane(Viewport *viewport = 0); 38 | ~Plane(); 39 | 40 | DECL_ATTR( Bitmap, Bitmap* ) 41 | DECL_ATTR( OX, int ) 42 | DECL_ATTR( OY, int ) 43 | DECL_ATTR( ZoomX, float ) 44 | DECL_ATTR( ZoomY, float ) 45 | DECL_ATTR( Opacity, int ) 46 | DECL_ATTR( BlendType, int ) 47 | DECL_ATTR( Color, Color& ) 48 | DECL_ATTR( Tone, Tone& ) 49 | 50 | void initDynAttribs(); 51 | 52 | private: 53 | PlanePrivate *p; 54 | 55 | void draw(); 56 | void onGeometryChange(const Scene::Geometry &); 57 | 58 | void releaseResources(); 59 | const char *klassName() const { return "plane"; } 60 | 61 | ABOUT_TO_ACCESS_DISP 62 | }; 63 | 64 | #endif // PLANE_H 65 | -------------------------------------------------------------------------------- /src/debugwriter.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** debugwriter.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef DEBUGWRITER_H 23 | #define DEBUGWRITER_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #ifdef __ANDROID__ 30 | #include 31 | #endif 32 | 33 | 34 | /* A cheap replacement for qDebug() */ 35 | 36 | class Debug 37 | { 38 | public: 39 | Debug() 40 | { 41 | buf << std::boolalpha; 42 | } 43 | 44 | template 45 | Debug &operator<<(const T &t) 46 | { 47 | buf << t; 48 | buf << " "; 49 | 50 | return *this; 51 | } 52 | 53 | template 54 | Debug &operator<<(const std::vector &v) 55 | { 56 | for (size_t i = 0; i < v.size(); ++i) 57 | buf << v[i] << " "; 58 | 59 | return *this; 60 | } 61 | 62 | ~Debug() 63 | { 64 | #ifdef __ANDROID__ 65 | __android_log_write(ANDROID_LOG_DEBUG, "mkxp", buf.str().c_str()); 66 | #else 67 | std::cerr << buf.str() << std::endl; 68 | #endif 69 | } 70 | 71 | private: 72 | std::stringstream buf; 73 | }; 74 | 75 | #endif // DEBUGWRITER_H 76 | -------------------------------------------------------------------------------- /src/input.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** input.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef INPUT_H 23 | #define INPUT_H 24 | 25 | struct InputPrivate; 26 | struct RGSSThreadData; 27 | 28 | class Input 29 | { 30 | public: 31 | enum ButtonCode 32 | { 33 | None = 0, 34 | 35 | Down = 2, Left = 4, Right = 6, Up = 8, 36 | 37 | A = 11, B = 12, C = 13, 38 | X = 14, Y = 15, Z = 16, 39 | L = 17, R = 18, 40 | 41 | Shift = 21, Ctrl = 22, Alt = 23, 42 | 43 | F5 = 25, F6 = 26, F7 = 27, F8 = 28, F9 = 29, 44 | 45 | /* Non-standard extensions */ 46 | MouseLeft = 38, MouseMiddle = 39, MouseRight = 40, 47 | MouseX1 = 41, MouseX2 = 42 48 | }; 49 | 50 | void update(); 51 | 52 | bool isPressed(int button); 53 | bool isTriggered(int button); 54 | bool isRepeated(int button); 55 | 56 | int dir4Value(); 57 | int dir8Value(); 58 | 59 | /* Non-standard extensions */ 60 | int mouseX(); 61 | int mouseY(); 62 | int scrollV(); 63 | 64 | private: 65 | Input(const RGSSThreadData &rtData); 66 | ~Input(); 67 | 68 | friend struct SharedStatePrivate; 69 | 70 | InputPrivate *p; 71 | }; 72 | 73 | #endif // INPUT_H 74 | -------------------------------------------------------------------------------- /cmake/PrepUtils.cmake: -------------------------------------------------------------------------------- 1 | if(APPLE) 2 | function(PostBuildMacBundle target framework_list lib_list) 3 | INCLUDE(BundleUtilities) 4 | GET_TARGET_PROPERTY(_BIN_NAME ${target} LOCATION) 5 | GET_DOTAPP_DIR(${_BIN_NAME} _BUNDLE_DIR) 6 | 7 | set(_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${target}_prep.cmake") 8 | file(WRITE ${_SCRIPT_FILE} 9 | "# Generated Script file\n" 10 | "include(BundleUtilities)\n" 11 | "get_bundle_and_executable(\"\${BUNDLE_APP}\" bundle executable valid)\n" 12 | "if(valid)\n" 13 | " set(framework_dest \"\${bundle}/Contents/Frameworks\")\n" 14 | " foreach(framework_path ${framework_list})\n" 15 | " get_filename_component(framework_name \${framework_path} NAME_WE)\n" 16 | " file(MAKE_DIRECTORY \"\${framework_dest}/\${framework_name}.framework/Versions/A/\")\n" 17 | " copy_resolved_framework_into_bundle(\${framework_path}/Versions/A/\${framework_name} \${framework_dest}/\${framework_name}.framework/Versions/A/\${framework_name})\n" 18 | " endforeach()\n" 19 | " foreach(lib ${lib_list})\n" 20 | " get_filename_component(lib_file \${lib} NAME)\n" 21 | " copy_resolved_item_into_bundle(\${lib} \${framework_dest}/\${lib_file})\n" 22 | " endforeach()\n" 23 | "else()\n" 24 | " message(ERROR \"App Not found? \${BUNDLE_APP}\")\n" 25 | "endif()\n" 26 | "#fixup_bundle(\"\${BUNDLE_APP}\" \"\" \"\${DEP_LIB_DIR}\")\n" 27 | ) 28 | 29 | ADD_CUSTOM_COMMAND(TARGET ${target} 30 | POST_BUILD 31 | COMMAND ${CMAKE_COMMAND} -DBUNDLE_APP="${_BUNDLE_DIR}" -P "${_SCRIPT_FILE}" 32 | ) 33 | endfunction() 34 | else() 35 | function(PostBuildMacBundle target framework_list lib_list) 36 | # noop 37 | endfunction() 38 | endif() -------------------------------------------------------------------------------- /src/soundemitter.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** soundemitter.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2014 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef SOUNDEMITTER_H 23 | #define SOUNDEMITTER_H 24 | 25 | #include "intrulist.h" 26 | #include "al-util.h" 27 | #include "boost-hash.h" 28 | 29 | #include 30 | #include 31 | 32 | struct SoundBuffer; 33 | struct Config; 34 | 35 | struct SoundEmitter 36 | { 37 | typedef BoostHash BufferHash; 38 | 39 | IntruList buffers; 40 | BufferHash bufferHash; 41 | 42 | /* Byte count sum of all cached / playing buffers */ 43 | uint32_t bufferBytes; 44 | 45 | const size_t srcCount; 46 | std::vector alSrcs; 47 | std::vector atchBufs; 48 | 49 | /* Indices of sources, sorted by priority (lowest first) */ 50 | std::vector srcPrio; 51 | 52 | /* Constant premultiplier */ 53 | float configVolume; 54 | 55 | SoundEmitter(const Config &conf); 56 | ~SoundEmitter(); 57 | 58 | void play(const std::string &filename, 59 | int volume, 60 | int pitch); 61 | 62 | void stop(); 63 | 64 | private: 65 | SoundBuffer *allocateBuffer(const std::string &filename); 66 | }; 67 | 68 | #endif // SOUNDEMITTER_H 69 | -------------------------------------------------------------------------------- /binding-mri/flashable-binding.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** flashable-binding.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef FLASHABLEBINDING_H 23 | #define FLASHABLEBINDING_H 24 | 25 | #include "flashable.h" 26 | #include "binding-util.h" 27 | #include "binding-types.h" 28 | 29 | template 30 | RB_METHOD(flashableFlash) 31 | { 32 | Flashable *f = getPrivateData(self); 33 | 34 | VALUE colorObj; 35 | int duration; 36 | 37 | Color *color; 38 | 39 | rb_get_args(argc, argv, "oi", &colorObj, &duration RB_ARG_END); 40 | 41 | if (NIL_P(colorObj)) 42 | { 43 | f->flash(0, duration); 44 | return Qnil; 45 | } 46 | 47 | color = getPrivateDataCheck(colorObj, ColorType); 48 | 49 | f->flash(&color->norm, duration); 50 | 51 | return Qnil; 52 | } 53 | 54 | template 55 | RB_METHOD(flashableUpdate) 56 | { 57 | RB_UNUSED_PARAM; 58 | 59 | Flashable *f = getPrivateData(self); 60 | 61 | f->update(); 62 | 63 | return Qnil; 64 | } 65 | 66 | template 67 | static void flashableBindingInit(VALUE klass) 68 | { 69 | _rb_define_method(klass, "flash", flashableFlash); 70 | _rb_define_method(klass, "update", flashableUpdate); 71 | } 72 | 73 | #endif // FLASHABLEBINDING_H 74 | -------------------------------------------------------------------------------- /src/global-ibo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** global-ibo.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef GLOBALIBO_H 23 | #define GLOBALIBO_H 24 | 25 | #include "gl-util.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | typedef uint16_t index_t; 33 | #define INDEX_T_MAX std::numeric_limits::max() 34 | #define _GL_INDEX_TYPE GL_UNSIGNED_SHORT 35 | 36 | struct GlobalIBO 37 | { 38 | IBO::ID ibo; 39 | std::vector buffer; 40 | 41 | GlobalIBO() 42 | { 43 | ibo = IBO::gen(); 44 | } 45 | 46 | ~GlobalIBO() 47 | { 48 | IBO::del(ibo); 49 | } 50 | 51 | void ensureSize(size_t quadCount) 52 | { 53 | assert(quadCount*6 < INDEX_T_MAX); 54 | 55 | if (buffer.size() >= quadCount*6) 56 | return; 57 | 58 | size_t startInd = buffer.size() / 6; 59 | buffer.reserve(quadCount*6); 60 | 61 | for (size_t i = startInd; i < quadCount; ++i) 62 | { 63 | static const index_t indTemp[] = { 0, 1, 2, 2, 3, 0 }; 64 | 65 | for (size_t j = 0; j < 6; ++j) 66 | buffer.push_back(i * 4 + indTemp[j]); 67 | } 68 | 69 | IBO::bind(ibo); 70 | IBO::uploadData(buffer.size() * sizeof(index_t), dataPtr(buffer)); 71 | IBO::unbind(); 72 | } 73 | }; 74 | 75 | #endif // GLOBALIBO_H 76 | -------------------------------------------------------------------------------- /src/tilemapvx.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** tilemapvx.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2014 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef TILEMAPVX_H 23 | #define TILEMAPVX_H 24 | 25 | #include "disposable.h" 26 | #include "util.h" 27 | 28 | class Viewport; 29 | class Bitmap; 30 | class Table; 31 | 32 | struct TilemapVXPrivate; 33 | 34 | class TilemapVX : public Disposable 35 | { 36 | public: 37 | class BitmapArray 38 | { 39 | public: 40 | void set(int i, Bitmap *bitmap); 41 | Bitmap *get(int i) const; 42 | 43 | private: 44 | BitmapArray() {} 45 | ~BitmapArray() {} 46 | 47 | TilemapVXPrivate *p; 48 | friend class TilemapVX; 49 | friend struct TilemapVXPrivate; 50 | }; 51 | 52 | TilemapVX(Viewport *viewport = 0); 53 | ~TilemapVX(); 54 | 55 | void update(); 56 | 57 | BitmapArray &getBitmapArray(); 58 | 59 | DECL_ATTR( Viewport, Viewport* ) 60 | DECL_ATTR( MapData, Table* ) 61 | DECL_ATTR( FlashData, Table* ) 62 | DECL_ATTR( Flags, Table* ) 63 | DECL_ATTR( Visible, bool ) 64 | DECL_ATTR( OX, int ) 65 | DECL_ATTR( OY, int ) 66 | 67 | private: 68 | TilemapVXPrivate *p; 69 | BitmapArray bmProxy; 70 | 71 | void releaseResources(); 72 | const char *klassName() const { return "tilemap"; } 73 | }; 74 | 75 | #endif // TILEMAPVX_H 76 | -------------------------------------------------------------------------------- /src/tilemap.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** tilemap.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef TILEMAP_H 23 | #define TILEMAP_H 24 | 25 | #include "disposable.h" 26 | 27 | #include "util.h" 28 | 29 | class Viewport; 30 | class Bitmap; 31 | class Table; 32 | 33 | struct TilemapPrivate; 34 | 35 | class Tilemap : public Disposable 36 | { 37 | public: 38 | class Autotiles 39 | { 40 | public: 41 | void set(int i, Bitmap *bitmap); 42 | Bitmap *get(int i) const; 43 | 44 | private: 45 | Autotiles() {} 46 | ~Autotiles() {} 47 | 48 | TilemapPrivate *p; 49 | friend class Tilemap; 50 | friend struct TilemapPrivate; 51 | }; 52 | 53 | Tilemap(Viewport *viewport = 0); 54 | ~Tilemap(); 55 | 56 | void update(); 57 | 58 | Autotiles &getAutotiles(); 59 | Viewport *getViewport() const; 60 | 61 | DECL_ATTR( Tileset, Bitmap* ) 62 | DECL_ATTR( MapData, Table* ) 63 | DECL_ATTR( FlashData, Table* ) 64 | DECL_ATTR( Priorities, Table* ) 65 | DECL_ATTR( Visible, bool ) 66 | DECL_ATTR( OX, int ) 67 | DECL_ATTR( OY, int ) 68 | 69 | private: 70 | TilemapPrivate *p; 71 | Autotiles atProxy; 72 | 73 | void releaseResources(); 74 | const char *klassName() const { return "tilemap"; } 75 | }; 76 | 77 | #endif // TILEMAP_H 78 | -------------------------------------------------------------------------------- /binding-mruby/flashable-binding.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** flashable-binding.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef FLASHABLEBINDING_H 23 | #define FLASHABLEBINDING_H 24 | 25 | #include "flashable.h" 26 | #include "binding-util.h" 27 | #include "binding-types.h" 28 | 29 | template 30 | MRB_METHOD(flashableFlash) 31 | { 32 | Flashable *f = getPrivateData(mrb, self); 33 | 34 | mrb_value colorObj; 35 | mrb_int duration; 36 | 37 | Color *color; 38 | 39 | mrb_get_args(mrb, "oi", &colorObj, &duration); 40 | 41 | if (mrb_nil_p(colorObj)) 42 | { 43 | f->flash(0, duration); 44 | return mrb_nil_value(); 45 | } 46 | 47 | color = getPrivateDataCheck(mrb, colorObj, ColorType); 48 | 49 | f->flash(&color->norm, duration); 50 | 51 | return mrb_nil_value(); 52 | } 53 | 54 | template 55 | MRB_METHOD(flashableUpdate) 56 | { 57 | Flashable *f = getPrivateData(mrb, self); 58 | 59 | f->update(); 60 | 61 | return mrb_nil_value(); 62 | } 63 | 64 | template 65 | static void flashableBindingInit(mrb_state *mrb, RClass *klass) 66 | { 67 | mrb_define_method(mrb, klass, "flash", flashableFlash, MRB_ARGS_REQ(2)); 68 | mrb_define_method(mrb, klass, "update", flashableUpdate, MRB_ARGS_NONE()); 69 | } 70 | 71 | #endif // FLASHABLEBINDING_H 72 | -------------------------------------------------------------------------------- /src/tilequad.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** tilequad.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef TILEQUAD_H 23 | #define TILEQUAD_H 24 | 25 | #include "etc-internal.h" 26 | 27 | /* Tiled Quads 28 | * 29 | * These functions enable drawing a tiled subrectangle 30 | * of a texture, 31 | * but no advanced stuff like rotation, scaling etc. 32 | */ 33 | 34 | #include "quadarray.h" 35 | 36 | namespace TileQuads 37 | { 38 | /* Calculate needed quad counts */ 39 | int oneDimCount(int tileDimension, 40 | int destDimension); 41 | int twoDimCount(int tileW, int tileH, 42 | int destW, int destH); 43 | 44 | /* Build tiling quads */ 45 | int buildH(const IntRect &sourceRect, 46 | int width, int x, int y, 47 | Vertex *verts); 48 | 49 | int buildV(const IntRect &sourceRect, 50 | int height, int ox, int oy, 51 | Vertex *verts); 52 | 53 | int build(const IntRect &sourceRect, 54 | const IntRect &destRect, 55 | Vertex *verts); 56 | 57 | /* Build a quad "frame" (see Window cursor_rect) */ 58 | int buildFrame(const IntRect &rect, 59 | Vertex vert[36]); 60 | 61 | int buildFrameSource(const IntRect &rect, 62 | Vertex vert[36]); 63 | } 64 | 65 | #endif // TILEQUAD_H 66 | -------------------------------------------------------------------------------- /src/tileatlas.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** tileatlas.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef TILEATLAS_H 23 | #define TILEATLAS_H 24 | 25 | #include "etc-internal.h" 26 | 27 | #include 28 | 29 | namespace TileAtlas 30 | { 31 | 32 | /* Abstract definition of a blit 33 | * operation with undefined rect width */ 34 | struct Blit 35 | { 36 | Vec2i src; 37 | Vec2i dst; 38 | int h; 39 | 40 | Blit(int sx, int sy, 41 | int dx, int dy, 42 | int h) 43 | : src(sx, sy), 44 | dst(dx, dy), 45 | h(h) 46 | {} 47 | }; 48 | 49 | typedef std::vector BlitVec; 50 | 51 | /* Calculates the minimum atlas size required to hold 52 | * a tileset of height 'tilesetH'. If the required dimensions 53 | * exceed 'maxAtlasSize', Vec2i(-1, -1) is returned. */ 54 | Vec2i minSize(int tilesetH, int maxAtlasSize); 55 | 56 | /* Calculates a series of blits necessary to fill an atlas 57 | * of size 'atlasSize' with a tileset of height 'tilesetH'. 58 | * Usually fed results from 'minSize()'. */ 59 | BlitVec calcBlits(int tilesetH, const Vec2i &atlasSize); 60 | 61 | /* Translates a tile coordinate (not pixel!) to a physical 62 | * pixel coordinate in the atlas */ 63 | Vec2i tileToAtlasCoor(int tileX, int tileY, int tilesetH, int atlasH); 64 | 65 | } 66 | 67 | #endif // TILEATLAS_H 68 | -------------------------------------------------------------------------------- /src/vertex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** vertex.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2014 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "vertex.h" 23 | #include "util.h" 24 | 25 | #include 26 | 27 | CVertex::CVertex() 28 | : color(1, 1, 1, 1) 29 | {} 30 | 31 | Vertex::Vertex() 32 | : color(1, 1, 1, 1) 33 | {} 34 | 35 | #define o(type, mem) ((const GLvoid*) offsetof(type, mem)) 36 | 37 | static const VertexAttribute SVertexAttribs[] = 38 | { 39 | { Shader::Position, 2, GL_FLOAT, o(SVertex, pos) }, 40 | { Shader::TexCoord, 2, GL_FLOAT, o(SVertex, texPos) } 41 | }; 42 | 43 | static const VertexAttribute CVertexAttribs[] = 44 | { 45 | { Shader::Color, 4, GL_FLOAT, o(CVertex, color) }, 46 | { Shader::Position, 2, GL_FLOAT, o(CVertex, pos) } 47 | }; 48 | 49 | static const VertexAttribute VertexAttribs[] = 50 | { 51 | { Shader::Color, 4, GL_FLOAT, o(Vertex, color) }, 52 | { Shader::Position, 2, GL_FLOAT, o(Vertex, pos) }, 53 | { Shader::TexCoord, 2, GL_FLOAT, o(Vertex, texPos) } 54 | }; 55 | 56 | #define DEF_TRAITS(VertType) \ 57 | template<> \ 58 | const VertexAttribute *VertexTraits::attr = VertType##Attribs; \ 59 | template<> \ 60 | const GLsizei VertexTraits::attrCount = ARRAY_SIZE(VertType##Attribs) 61 | 62 | DEF_TRAITS(SVertex); 63 | DEF_TRAITS(CVertex); 64 | DEF_TRAITS(Vertex); 65 | -------------------------------------------------------------------------------- /src/table.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** table.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef TABLE_H 23 | #define TABLE_H 24 | 25 | #include "serializable.h" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | class Table : public Serializable 32 | { 33 | public: 34 | Table(int x, int y = 1, int z = 1); 35 | /* Clone constructor */ 36 | Table(const Table &other); 37 | virtual ~Table() {} 38 | 39 | int xSize() const { return xs; } 40 | int ySize() const { return ys; } 41 | int zSize() const { return zs; } 42 | 43 | int16_t get(int x, int y = 0, int z = 0) const; 44 | void set(int16_t value, int x, int y = 0, int z = 0); 45 | 46 | void resize(int x, int y, int z); 47 | void resize(int x, int y); 48 | void resize(int x); 49 | 50 | int serialSize() const; 51 | void serialize(char *buffer) const; 52 | static Table *deserialize(const char *data, int len); 53 | 54 | /* modified; 66 | 67 | private: 68 | int xs, ys, zs; 69 | std::vector data; 70 | }; 71 | 72 | #endif // TABLE_H 73 | -------------------------------------------------------------------------------- /assets/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 19 | 23 | 27 | 28 | 29 | 31 | 32 | 34 | image/svg+xml 35 | 37 | 38 | 39 | 40 | 41 | 44 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/aldatasource.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** aldatasource.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2014 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef ALDATASOURCE_H 23 | #define ALDATASOURCE_H 24 | 25 | #include "al-util.h" 26 | 27 | struct ALDataSource 28 | { 29 | enum Status 30 | { 31 | NoError, 32 | EndOfStream, 33 | WrapAround, 34 | Error 35 | }; 36 | 37 | virtual ~ALDataSource() {} 38 | 39 | /* Read/process next chunk of data, and attach it 40 | * to provided AL buffer */ 41 | virtual Status fillBuffer(AL::Buffer::ID alBuffer) = 0; 42 | 43 | virtual int sampleRate() = 0; 44 | 45 | /* If the source doesn't support seeking, it will 46 | * reset back to the beginning */ 47 | virtual void seekToOffset(float seconds) = 0; 48 | 49 | /* The frame count right after wrap around */ 50 | virtual uint32_t loopStartFrames() = 0; 51 | 52 | /* Returns false if not supported */ 53 | virtual bool setPitch(float value) = 0; 54 | }; 55 | 56 | ALDataSource *createSDLSource(SDL_RWops &ops, 57 | const char *extension, 58 | uint32_t maxBufSize, 59 | bool looped); 60 | 61 | ALDataSource *createVorbisSource(SDL_RWops &ops, 62 | bool looped); 63 | 64 | ALDataSource *createMidiSource(SDL_RWops &ops, 65 | bool looped); 66 | 67 | #endif // ALDATASOURCE_H 68 | -------------------------------------------------------------------------------- /doc/extension_doc.md: -------------------------------------------------------------------------------- 1 | 2 | # mkxp extenions for Dancing Dragon Games / Symphony of War 3 | 4 | ## Graphics.resize_window(width, height, recenter) 5 | width: Integer 6 | height: Integer 7 | recenter: Boolean, false by default 8 | returns: nil 9 | 10 | Resizes the game window to width x height. If `recenter` is **true**, also center the window on the current screen. 11 | 12 | ## Graphics.maximize_window() 13 | 14 | Maximizes the game window, ignoring the `winResizable` config option. 15 | 16 | ## Graphics.restore_window() 17 | 18 | Restores the game window from a maximized or minimized state. 19 | 20 | ## Bitmap.write_to_png(filename) 21 | filename: String 22 | returns: self 23 | 24 | Writes the contents of the bitmap to `filename`, in PNG format. 25 | 26 | ## Bitmap.v_flip() / .h_flip() 27 | returns: nil 28 | 29 | Flips the bitmap image vertically / horizontally. 30 | 31 | ## Input.scroll_v() 32 | returns: Integer 33 | 34 | Returns the cumulative amount of scroll events (negative if down, positive if up) inbetween the current and last `Input.update` call. 35 | 36 | ## Input::MOUSEX1 / ::MOUSEX2 37 | 38 | These two constants representing two extra mouse buttons can be passed to the familiar #press?/#trigger?/#repeat? functions. 39 | 40 | ## MKXP.data_directory() 41 | returns: String 42 | 43 | Provides a PC-user-dependant, game-specific path to a writable directory, intended for save states, configuration and similar. 44 | In `mkxp.conf`, both `dataPathOrg` and `dataPathApp` keys need to be set, otherwise it returns a generic directory shared by all mkxp games. It is recommended (though not required) to not put any spaces in the config strings. 45 | Real life example: 46 | ``` 47 | dataPathOrg=dancingdragon 48 | dataPathApp=skyborn 49 | ``` 50 | 51 | ## MKXP.mouse_in_window() 52 | returns: Boolean 53 | 54 | Returns true if the mouse cursor is currently within the game window, false otherwise. 55 | 56 | ## Arbitrary key states 57 | Use `MKXP.raw_key_states` to get the current byte array of keystates, then call `#getbyte(scancode)` with `scancode` being one of the constants defined in `SDL_scancode_map.rb`. **0** means the key is released, **1** that it is pressed. 58 | -------------------------------------------------------------------------------- /src/flashable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** flashable.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef FLASHABLE_H 23 | #define FLASHABLE_H 24 | 25 | #include "etc.h" 26 | #include "etc-internal.h" 27 | 28 | class Flashable 29 | { 30 | public: 31 | Flashable() 32 | : flashColor(0, 0, 0, 0), 33 | flashing(false), 34 | emptyFlashFlag(false) 35 | {} 36 | 37 | virtual ~Flashable() {} 38 | 39 | void flash(const Vec4 *color, int duration) 40 | { 41 | if (duration < 1) 42 | return; 43 | 44 | flashing = true; 45 | this->duration = duration; 46 | counter = 0; 47 | 48 | if (!color) 49 | { 50 | emptyFlashFlag = true; 51 | return; 52 | } 53 | 54 | flashColor = *color; 55 | flashAlpha = flashColor.w; 56 | } 57 | 58 | virtual void update() 59 | { 60 | if (!flashing) 61 | return; 62 | 63 | if (++counter > duration) 64 | { 65 | /* Flash finished. Cleanup */ 66 | flashColor = Vec4(0, 0, 0, 0); 67 | flashing = false; 68 | emptyFlashFlag = false; 69 | return; 70 | } 71 | 72 | /* No need to update flash color on empty flash */ 73 | if (emptyFlashFlag) 74 | return; 75 | 76 | float prog = (float) counter / duration; 77 | flashColor.w = flashAlpha * (1 - prog); 78 | } 79 | 80 | protected: 81 | Vec4 flashColor; 82 | bool flashing; 83 | bool emptyFlashFlag; 84 | private: 85 | float flashAlpha; 86 | int duration; 87 | int counter; 88 | }; 89 | 90 | #endif // FLASHABLE_H 91 | -------------------------------------------------------------------------------- /binding-mruby/viewportelement-binding.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** viewportelement-binding.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef VIEWPORTELEMENTBINDING_H 23 | #define VIEWPORTELEMENTBINDING_H 24 | 25 | #include "viewport.h" 26 | #include "binding-util.h" 27 | #include "binding-types.h" 28 | 29 | #include "sceneelement-binding.h" 30 | #include "disposable-binding.h" 31 | 32 | template 33 | MRB_METHOD(viewportElementGetViewport) 34 | { 35 | checkDisposed(mrb, self); 36 | 37 | return getProperty(mrb, self, CSviewport); 38 | } 39 | 40 | template 41 | static C * 42 | viewportElementInitialize(mrb_state *mrb, mrb_value self) 43 | { 44 | /* Get parameters */ 45 | mrb_value viewportObj = mrb_nil_value(); 46 | Viewport *viewport = 0; 47 | 48 | mrb_get_args(mrb, "|o", &viewportObj); 49 | 50 | if (!mrb_nil_p(viewportObj)) 51 | { 52 | viewport = getPrivateDataCheck(mrb, viewportObj, ViewportType); 53 | 54 | if (rgssVer == 1) 55 | disposableAddChild(mrb, viewportObj, self); 56 | } 57 | 58 | /* Construct object */ 59 | C *ve = new C(viewport); 60 | 61 | /* Set property objects */ 62 | setProperty(mrb, self, CSviewport, viewportObj); 63 | 64 | return ve; 65 | } 66 | 67 | template 68 | void 69 | viewportElementBindingInit(mrb_state *mrb, RClass *klass) 70 | { 71 | sceneElementBindingInit(mrb, klass); 72 | 73 | mrb_define_method(mrb, klass, "viewport", viewportElementGetViewport, MRB_ARGS_NONE()); 74 | } 75 | 76 | #endif // VIEWPORTELEMENTBINDING_H 77 | -------------------------------------------------------------------------------- /src/window.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** window.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef WINDOW_H 23 | #define WINDOW_H 24 | 25 | #include "viewport.h" 26 | #include "disposable.h" 27 | 28 | #include "util.h" 29 | 30 | class Bitmap; 31 | struct Rect; 32 | 33 | struct WindowPrivate; 34 | 35 | class Window : public ViewportElement, public Disposable 36 | { 37 | public: 38 | Window(Viewport *viewport = 0); 39 | ~Window(); 40 | 41 | void update(); 42 | 43 | DECL_ATTR( Windowskin, Bitmap* ) 44 | DECL_ATTR( Contents, Bitmap* ) 45 | DECL_ATTR( Stretch, bool ) 46 | DECL_ATTR( CursorRect, Rect& ) 47 | DECL_ATTR( Active, bool ) 48 | DECL_ATTR( Pause, bool ) 49 | DECL_ATTR( X, int ) 50 | DECL_ATTR( Y, int ) 51 | DECL_ATTR( Width, int ) 52 | DECL_ATTR( Height, int ) 53 | DECL_ATTR( OX, int ) 54 | DECL_ATTR( OY, int ) 55 | DECL_ATTR( Opacity, int ) 56 | DECL_ATTR( BackOpacity, int ) 57 | DECL_ATTR( ContentsOpacity, int ) 58 | 59 | void initDynAttribs(); 60 | 61 | private: 62 | WindowPrivate *p; 63 | 64 | void draw(); 65 | void onGeometryChange(const Scene::Geometry &); 66 | void setZ(int value); 67 | void setVisible(bool value); 68 | 69 | void onViewportChange(); 70 | 71 | void releaseResources(); 72 | const char *klassName() const { return "window"; } 73 | 74 | ABOUT_TO_ACCESS_DISP 75 | }; 76 | 77 | #endif // WINDOW_H 78 | -------------------------------------------------------------------------------- /src/disposable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** disposable.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef DISPOSABLE_H 23 | #define DISPOSABLE_H 24 | 25 | #include "intrulist.h" 26 | #include "exception.h" 27 | #include "sharedstate.h" 28 | #include "graphics.h" 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | class Disposable 35 | { 36 | public: 37 | Disposable() 38 | : disposed(false), 39 | link(this) 40 | { 41 | shState->graphics().addDisposable(this); 42 | } 43 | 44 | virtual ~Disposable() 45 | { 46 | shState->graphics().remDisposable(this); 47 | } 48 | 49 | void dispose() 50 | { 51 | if (disposed) 52 | return; 53 | 54 | releaseResources(); 55 | disposed = true; 56 | wasDisposed(); 57 | } 58 | 59 | bool isDisposed() const 60 | { 61 | return disposed; 62 | } 63 | 64 | sigc::signal wasDisposed; 65 | 66 | protected: 67 | void guardDisposed() const 68 | { 69 | if (isDisposed()) 70 | throw Exception(Exception::RGSSError, 71 | "disposed %s", klassName()); 72 | } 73 | 74 | private: 75 | virtual void releaseResources() = 0; 76 | virtual const char *klassName() const = 0; 77 | 78 | friend class Graphics; 79 | 80 | bool disposed; 81 | IntruListLink link; 82 | }; 83 | 84 | template 85 | inline bool 86 | nullOrDisposed(const C *d) 87 | { 88 | if (!d) 89 | return true; 90 | 91 | if (d->isDisposed()) 92 | return true; 93 | 94 | return false; 95 | } 96 | 97 | #endif // DISPOSABLE_H 98 | -------------------------------------------------------------------------------- /src/viewport.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** viewport.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef VIEWPORT_H 23 | #define VIEWPORT_H 24 | 25 | #include "scene.h" 26 | #include "flashable.h" 27 | #include "disposable.h" 28 | #include "util.h" 29 | 30 | struct ViewportPrivate; 31 | 32 | class Viewport : public Scene, public SceneElement, public Flashable, public Disposable 33 | { 34 | public: 35 | Viewport(int x, int y, int width, int height); 36 | Viewport(Rect *rect); 37 | Viewport(); 38 | ~Viewport(); 39 | 40 | void update(); 41 | 42 | DECL_ATTR( Rect, Rect& ) 43 | DECL_ATTR( OX, int ) 44 | DECL_ATTR( OY, int ) 45 | DECL_ATTR( Color, Color& ) 46 | DECL_ATTR( Tone, Tone& ) 47 | 48 | void initDynAttribs(); 49 | 50 | private: 51 | void initViewport(int x, int y, int width, int height); 52 | void geometryChanged(); 53 | 54 | void composite(); 55 | void draw(); 56 | void onGeometryChange(const Geometry &); 57 | bool isEffectiveViewport(Rect *&, Color *&, Tone *&) const; 58 | 59 | void releaseResources(); 60 | const char *klassName() const { return "viewport"; } 61 | 62 | ABOUT_TO_ACCESS_DISP 63 | 64 | ViewportPrivate *p; 65 | friend struct ViewportPrivate; 66 | 67 | IntruListLink sceneLink; 68 | }; 69 | 70 | class ViewportElement : public SceneElement 71 | { 72 | public: 73 | ViewportElement(Viewport *viewport = 0, int z = 0, int spriteY = 0); 74 | 75 | DECL_ATTR( Viewport, Viewport* ) 76 | 77 | protected: 78 | virtual void onViewportChange() {} 79 | 80 | private: 81 | Viewport *m_viewport; 82 | }; 83 | 84 | #endif // VIEWPORT_H 85 | -------------------------------------------------------------------------------- /src/gl-meta.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** gl-meta.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2014 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef GLMETA_H 23 | #define GLMETA_H 24 | 25 | #include "gl-fun.h" 26 | #include "gl-util.h" 27 | #include "vertex.h" 28 | 29 | #include 30 | 31 | namespace GLMeta 32 | { 33 | 34 | /* EXT_unpack_subimage */ 35 | void subRectImageUpload(GLint srcW, GLint srcX, GLint srcY, 36 | GLint dstX, GLint dstY, GLsizei dstW, GLsizei dstH, 37 | SDL_Surface *src, GLenum format); 38 | void subRectImageEnd(); 39 | 40 | /* ARB_vertex_array_object */ 41 | struct VAO 42 | { 43 | /* Set manually, then call vaoInit() */ 44 | const VertexAttribute *attr; 45 | size_t attrCount; 46 | GLsizei vertSize; 47 | VBO::ID vbo; 48 | IBO::ID ibo; 49 | 50 | /* Don't touch */ 51 | GLuint nativeVAO; 52 | }; 53 | 54 | template 55 | inline void vaoFillInVertexData(VAO &vao) 56 | { 57 | vao.attr = VertexTraits::attr; 58 | vao.attrCount = VertexTraits::attrCount; 59 | vao.vertSize = sizeof(VertexType); 60 | } 61 | 62 | void vaoInit(VAO &vao, bool keepBound = false); 63 | void vaoFini(VAO &vao); 64 | void vaoBind(VAO &vao); 65 | void vaoUnbind(VAO &vao); 66 | 67 | /* EXT_framebuffer_blit */ 68 | void blitBegin(TEXFBO &target); 69 | void blitBeginScreen(const Vec2i &size); 70 | void blitSource(TEXFBO &source); 71 | void blitRectangle(const IntRect &src, const Vec2i &dstPos); 72 | void blitRectangle(const IntRect &src, const IntRect &dst, 73 | bool smooth = false); 74 | void blitEnd(); 75 | 76 | } 77 | 78 | #endif // GLMETA_H 79 | -------------------------------------------------------------------------------- /src/audio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** audio.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef AUDIO_H 23 | #define AUDIO_H 24 | 25 | /* Concerning the 'pos' parameter: 26 | * RGSS3 actually doesn't specify a format for this, 27 | * it's only implied that it is a numerical value 28 | * (must be 0 on invalid cases), and it's not used for 29 | * anything outside passing it back into bgm/bgs_play. 30 | * We use this freedom to define pos to be a float, 31 | * in seconds of playback. (RGSS3 seems to use large 32 | * integers that _look_ like sample offsets but I can't 33 | * quite make out their meaning yet) */ 34 | 35 | struct AudioPrivate; 36 | struct RGSSThreadData; 37 | 38 | class Audio 39 | { 40 | public: 41 | void bgmPlay(const char *filename, 42 | int volume = 100, 43 | int pitch = 100, 44 | float pos = 0); 45 | void bgmStop(); 46 | void bgmFade(int time); 47 | 48 | void bgsPlay(const char *filename, 49 | int volume = 100, 50 | int pitch = 100, 51 | float pos = 0); 52 | void bgsStop(); 53 | void bgsFade(int time); 54 | 55 | void mePlay(const char *filename, 56 | int volume = 100, 57 | int pitch = 100); 58 | void meStop(); 59 | void meFade(int time); 60 | 61 | void sePlay(const char *filename, 62 | int volume = 100, 63 | int pitch = 100); 64 | void seStop(); 65 | 66 | void setupMidi(); 67 | float bgmPos(); 68 | float bgsPos(); 69 | 70 | void reset(); 71 | 72 | private: 73 | Audio(RGSSThreadData &rtData); 74 | ~Audio(); 75 | 76 | friend struct SharedStatePrivate; 77 | 78 | AudioPrivate *p; 79 | }; 80 | 81 | #endif // AUDIO_H 82 | -------------------------------------------------------------------------------- /src/sprite.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** sprite.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef SPRITE_H 23 | #define SPRITE_H 24 | 25 | #include "scene.h" 26 | #include "flashable.h" 27 | #include "disposable.h" 28 | #include "viewport.h" 29 | #include "util.h" 30 | 31 | class Bitmap; 32 | struct Color; 33 | struct Tone; 34 | struct Rect; 35 | 36 | struct SpritePrivate; 37 | 38 | class Sprite : public ViewportElement, public Flashable, public Disposable 39 | { 40 | public: 41 | Sprite(Viewport *viewport = 0); 42 | ~Sprite(); 43 | 44 | int getWidth() const; 45 | int getHeight() const; 46 | 47 | void update(); 48 | 49 | DECL_ATTR( Bitmap, Bitmap* ) 50 | DECL_ATTR( SrcRect, Rect& ) 51 | DECL_ATTR( X, int ) 52 | DECL_ATTR( Y, int ) 53 | DECL_ATTR( OX, int ) 54 | DECL_ATTR( OY, int ) 55 | DECL_ATTR( ZoomX, float ) 56 | DECL_ATTR( ZoomY, float ) 57 | DECL_ATTR( Angle, float ) 58 | DECL_ATTR( Mirror, bool ) 59 | DECL_ATTR( BushDepth, int ) 60 | DECL_ATTR( BushOpacity, int ) 61 | DECL_ATTR( Opacity, int ) 62 | DECL_ATTR( BlendType, int ) 63 | DECL_ATTR( Color, Color& ) 64 | DECL_ATTR( Tone, Tone& ) 65 | DECL_ATTR( WaveAmp, int ) 66 | DECL_ATTR( WaveLength, int ) 67 | DECL_ATTR( WaveSpeed, int ) 68 | DECL_ATTR( WavePhase, float ) 69 | 70 | void initDynAttribs(); 71 | 72 | private: 73 | SpritePrivate *p; 74 | 75 | void draw(); 76 | void onGeometryChange(const Scene::Geometry &); 77 | 78 | void releaseResources(); 79 | const char *klassName() const { return "sprite"; } 80 | 81 | ABOUT_TO_ACCESS_DISP 82 | }; 83 | 84 | #endif // SPRITE_H 85 | -------------------------------------------------------------------------------- /binding-mri/sceneelement-binding.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** sceneelement-binding.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef SCENEELEMENTBINDING_H 23 | #define SCENEELEMENTBINDING_H 24 | 25 | #include "scene.h" 26 | #include "binding-util.h" 27 | 28 | template 29 | RB_METHOD(sceneElementGetZ) 30 | { 31 | RB_UNUSED_PARAM; 32 | 33 | SceneElement *se = getPrivateData(self); 34 | 35 | int value = 0; 36 | GUARD_EXC( value = se->getZ(); ); 37 | 38 | return rb_fix_new(value); 39 | } 40 | 41 | template 42 | RB_METHOD(sceneElementSetZ) 43 | { 44 | SceneElement *se = getPrivateData(self); 45 | 46 | int z; 47 | rb_get_args(argc, argv, "i", &z RB_ARG_END); 48 | 49 | GUARD_EXC( se->setZ(z); ); 50 | 51 | return rb_fix_new(z); 52 | } 53 | 54 | template 55 | RB_METHOD(sceneElementGetVisible) 56 | { 57 | RB_UNUSED_PARAM; 58 | 59 | SceneElement *se = getPrivateData(self); 60 | 61 | bool value = false; 62 | GUARD_EXC( value = se->getVisible(); ); 63 | 64 | return rb_bool_new(value); 65 | } 66 | 67 | template 68 | RB_METHOD(sceneElementSetVisible) 69 | { 70 | SceneElement *se = getPrivateData(self); 71 | 72 | bool visible; 73 | rb_get_args(argc, argv, "b", &visible RB_ARG_END); 74 | 75 | GUARD_EXC( se->setVisible(visible); ); 76 | 77 | return rb_bool_new(visible); 78 | } 79 | 80 | template 81 | void 82 | sceneElementBindingInit(VALUE klass) 83 | { 84 | _rb_define_method(klass, "z", sceneElementGetZ); 85 | _rb_define_method(klass, "z=", sceneElementSetZ); 86 | _rb_define_method(klass, "visible", sceneElementGetVisible); 87 | _rb_define_method(klass, "visible=", sceneElementSetVisible); 88 | } 89 | 90 | #endif // SCENEELEMENTBINDING_H 91 | -------------------------------------------------------------------------------- /src/gl-debug.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** gl-debug.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "gl-debug.h" 23 | #include "debugwriter.h" 24 | 25 | #include 26 | 27 | #include "gl-fun.h" 28 | 29 | struct GLDebugLoggerPrivate 30 | { 31 | std::ostream *stream; 32 | 33 | GLDebugLoggerPrivate(const char *logFilename) 34 | { 35 | (void) logFilename; 36 | 37 | stream = &std::clog; 38 | } 39 | 40 | ~GLDebugLoggerPrivate() 41 | { 42 | } 43 | 44 | void writeTimestamp() 45 | { 46 | // FIXME reintroduce proper time stamps (is this even necessary??) 47 | *stream << "[GLDEBUG] "; 48 | } 49 | 50 | void writeLine(const char *line) 51 | { 52 | *stream << line << "\n"; 53 | stream->flush(); 54 | } 55 | }; 56 | 57 | static void APIENTRY arbDebugFunc(GLenum source, 58 | GLenum type, 59 | GLuint id, 60 | GLenum severity, 61 | GLsizei length, 62 | const GLchar* message, 63 | const void* userParam) 64 | { 65 | GLDebugLoggerPrivate *p = 66 | static_cast(const_cast(userParam)); 67 | 68 | (void) source; 69 | (void) type; 70 | (void) id; 71 | (void) severity; 72 | (void) length; 73 | 74 | p->writeTimestamp(); 75 | p->writeLine(message); 76 | } 77 | 78 | GLDebugLogger::GLDebugLogger(const char *filename) 79 | { 80 | p = new GLDebugLoggerPrivate(filename); 81 | 82 | if (gl.DebugMessageCallback) 83 | gl.DebugMessageCallback(arbDebugFunc, p); 84 | else 85 | Debug() << "DebugLogger: no debug extensions found"; 86 | } 87 | 88 | GLDebugLogger::~GLDebugLogger() 89 | { 90 | delete p; 91 | } 92 | -------------------------------------------------------------------------------- /src/filesystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** filesystem.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef FILESYSTEM_H 23 | #define FILESYSTEM_H 24 | 25 | #include 26 | 27 | struct FileSystemPrivate; 28 | class SharedFontState; 29 | 30 | class FileSystem 31 | { 32 | public: 33 | FileSystem(const char *argv0, 34 | bool allowSymlinks); 35 | ~FileSystem(); 36 | 37 | void addPath(const char *path); 38 | 39 | /* Call these after the last 'addPath()' */ 40 | void createPathCache(); 41 | 42 | /* Scans "Fonts/" and creates inventory of 43 | * available font assets */ 44 | void initFontSets(SharedFontState &sfs); 45 | 46 | struct OpenHandler 47 | { 48 | /* Try to read and interpret data provided from ops. 49 | * If data cannot be parsed, return false, otherwise true. 50 | * Can be called multiple times until a parseable file is found. 51 | * It's the handler's responsibility to close every passed 52 | * ops structure, even when data could not be parsed. 53 | * After this function returns, ops becomes invalid, so don't take 54 | * references to it. Instead, copy the structure without closing 55 | * if you need to further read from it later. */ 56 | virtual bool tryRead(SDL_RWops &ops, const char *ext) = 0; 57 | }; 58 | 59 | void openRead(OpenHandler &handler, 60 | const char *filename); 61 | 62 | /* Circumvents extension supplementing */ 63 | void openReadRaw(SDL_RWops &ops, 64 | const char *filename, 65 | bool freeOnClose = false); 66 | 67 | /* Does not perform extension supplementing */ 68 | bool exists(const char *filename); 69 | 70 | private: 71 | FileSystemPrivate *p; 72 | }; 73 | 74 | extern const Uint32 SDL_RWOPS_PHYSFS; 75 | 76 | #endif // FILESYSTEM_H 77 | -------------------------------------------------------------------------------- /src/windowvx.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** window-vx.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2014 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef WINDOWVX_H 23 | #define WINDOWVX_H 24 | 25 | #include "viewport.h" 26 | #include "disposable.h" 27 | 28 | #include "util.h" 29 | 30 | class Bitmap; 31 | struct Rect; 32 | struct Tone; 33 | 34 | struct WindowVXPrivate; 35 | 36 | class WindowVX : public ViewportElement, public Disposable 37 | { 38 | public: 39 | WindowVX(Viewport *viewport = 0); 40 | WindowVX(int x, int y, int width, int height); 41 | ~WindowVX(); 42 | 43 | void update(); 44 | 45 | void move(int x, int y, int width, int height); 46 | bool isOpen() const; 47 | bool isClosed() const; 48 | 49 | DECL_ATTR( Windowskin, Bitmap* ) 50 | DECL_ATTR( Contents, Bitmap* ) 51 | DECL_ATTR( CursorRect, Rect& ) 52 | DECL_ATTR( Active, bool ) 53 | DECL_ATTR( ArrowsVisible, bool ) 54 | DECL_ATTR( Pause, bool ) 55 | DECL_ATTR( X, int ) 56 | DECL_ATTR( Y, int ) 57 | DECL_ATTR( Width, int ) 58 | DECL_ATTR( Height, int ) 59 | DECL_ATTR( OX, int ) 60 | DECL_ATTR( OY, int ) 61 | DECL_ATTR( Padding, int ) 62 | DECL_ATTR( PaddingBottom, int ) 63 | DECL_ATTR( Opacity, int ) 64 | DECL_ATTR( BackOpacity, int ) 65 | DECL_ATTR( ContentsOpacity, int ) 66 | DECL_ATTR( Openness, int ) 67 | DECL_ATTR( Tone, Tone& ) 68 | 69 | void initDynAttribs(); 70 | 71 | private: 72 | WindowVXPrivate *p; 73 | 74 | void draw(); 75 | void onGeometryChange(const Scene::Geometry &); 76 | 77 | void releaseResources(); 78 | const char *klassName() const { return "window"; } 79 | 80 | ABOUT_TO_ACCESS_DISP 81 | }; 82 | 83 | #endif // WINDOWVX_H 84 | -------------------------------------------------------------------------------- /binding-mri/plane-binding.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** plane-binding.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "plane.h" 23 | #include "disposable-binding.h" 24 | #include "viewportelement-binding.h" 25 | #include "binding-util.h" 26 | #include "binding-types.h" 27 | 28 | DEF_TYPE(Plane); 29 | 30 | RB_METHOD(planeInitialize) 31 | { 32 | Plane *p = viewportElementInitialize(argc, argv, self); 33 | 34 | setPrivateData(self, p); 35 | 36 | p->initDynAttribs(); 37 | 38 | wrapProperty(self, &p->getColor(), "color", ColorType); 39 | wrapProperty(self, &p->getTone(), "tone", ToneType); 40 | 41 | return self; 42 | } 43 | 44 | DEF_PROP_OBJ_REF(Plane, Bitmap, Bitmap, "bitmap") 45 | DEF_PROP_OBJ_VAL(Plane, Color, Color, "color") 46 | DEF_PROP_OBJ_VAL(Plane, Tone, Tone, "tone") 47 | 48 | DEF_PROP_I(Plane, OX) 49 | DEF_PROP_I(Plane, OY) 50 | DEF_PROP_I(Plane, Opacity) 51 | DEF_PROP_I(Plane, BlendType) 52 | 53 | DEF_PROP_F(Plane, ZoomX) 54 | DEF_PROP_F(Plane, ZoomY) 55 | 56 | 57 | void 58 | planeBindingInit() 59 | { 60 | VALUE klass = rb_define_class("Plane", rb_cObject); 61 | rb_define_alloc_func(klass, classAllocate<&PlaneType>); 62 | 63 | disposableBindingInit (klass); 64 | viewportElementBindingInit(klass); 65 | 66 | _rb_define_method(klass, "initialize", planeInitialize); 67 | 68 | INIT_PROP_BIND( Plane, Bitmap, "bitmap" ); 69 | INIT_PROP_BIND( Plane, OX, "ox" ); 70 | INIT_PROP_BIND( Plane, OY, "oy" ); 71 | INIT_PROP_BIND( Plane, ZoomX, "zoom_x" ); 72 | INIT_PROP_BIND( Plane, ZoomY, "zoom_y" ); 73 | INIT_PROP_BIND( Plane, Opacity, "opacity" ); 74 | INIT_PROP_BIND( Plane, BlendType, "blend_type" ); 75 | INIT_PROP_BIND( Plane, Color, "color" ); 76 | INIT_PROP_BIND( Plane, Tone, "tone" ); 77 | } 78 | -------------------------------------------------------------------------------- /src/graphics.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** graphics.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef GRAPHICS_H 23 | #define GRAPHICS_H 24 | 25 | #include "util.h" 26 | 27 | class Scene; 28 | class Bitmap; 29 | class Disposable; 30 | struct RGSSThreadData; 31 | struct GraphicsPrivate; 32 | struct AtomicFlag; 33 | 34 | class Graphics 35 | { 36 | public: 37 | void update(); 38 | void freeze(); 39 | void transition(int duration = 8, 40 | const char *filename = "", 41 | int vague = 40); 42 | void frameReset(); 43 | 44 | DECL_ATTR( FrameRate, int ) 45 | DECL_ATTR( FrameCount, int ) 46 | DECL_ATTR( Brightness, int ) 47 | 48 | void wait(int duration); 49 | void fadeout(int duration); 50 | void fadein(int duration); 51 | 52 | Bitmap *snapToBitmap(); 53 | 54 | int width() const; 55 | int height() const; 56 | void resizeScreen(int width, int height); 57 | void playMovie(const char *filename); 58 | 59 | void reset(); 60 | 61 | /* Non-standard extension */ 62 | DECL_ATTR( Fullscreen, bool ) 63 | DECL_ATTR( ShowCursor, bool ) 64 | 65 | DECL_ATTR( FixedAspectRatio, bool ) 66 | DECL_ATTR( SmoothScaling, bool ) 67 | DECL_ATTR( IntegerScaling, bool ) 68 | DECL_ATTR( LastMileScaling, bool ) 69 | 70 | /* */ 71 | Scene *getScreen() const; 72 | /* Repaint screen with static image until exitCond 73 | * is set. Observes reset flag on top of shutdown 74 | * if "checkReset" */ 75 | void repaintWait(const AtomicFlag &exitCond, 76 | bool checkReset = true); 77 | 78 | private: 79 | Graphics(RGSSThreadData *data); 80 | ~Graphics(); 81 | 82 | void addDisposable(Disposable *); 83 | void remDisposable(Disposable *); 84 | 85 | friend struct SharedStatePrivate; 86 | friend class Disposable; 87 | 88 | GraphicsPrivate *p; 89 | }; 90 | 91 | #endif // GRAPHICS_H 92 | -------------------------------------------------------------------------------- /binding-mruby/sceneelement-binding.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** sceneelement-binding.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef SCENEELEMENTBINDING_H 23 | #define SCENEELEMENTBINDING_H 24 | 25 | #include "scene.h" 26 | #include "binding-util.h" 27 | 28 | template 29 | MRB_METHOD(sceneElementGetZ) 30 | { 31 | SceneElement *se = getPrivateData(mrb, self); 32 | 33 | mrb_int value = 0; 34 | GUARD_EXC( value = se->getZ(); ) 35 | 36 | return mrb_fixnum_value(value); 37 | } 38 | 39 | template 40 | MRB_METHOD(sceneElementSetZ) 41 | { 42 | SceneElement *se = getPrivateData(mrb, self); 43 | 44 | mrb_int z; 45 | mrb_get_args(mrb, "i", &z); 46 | 47 | GUARD_EXC( se->setZ(z); ) 48 | 49 | return mrb_nil_value(); 50 | } 51 | 52 | template 53 | MRB_METHOD(sceneElementGetVisible) 54 | { 55 | SceneElement *se = getPrivateData(mrb, self); 56 | 57 | bool value = false; 58 | GUARD_EXC( value = se->getVisible(); ) 59 | 60 | return mrb_bool_value(value); 61 | } 62 | 63 | template 64 | MRB_METHOD(sceneElementSetVisible) 65 | { 66 | SceneElement *se = getPrivateData(mrb, self); 67 | 68 | mrb_value visibleObj; 69 | bool visible; 70 | 71 | mrb_get_args(mrb, "o", &visibleObj); 72 | 73 | visible = mrb_test(visibleObj); 74 | 75 | GUARD_EXC( se->setVisible(visible); ) 76 | 77 | return mrb_nil_value(); 78 | } 79 | 80 | template 81 | void 82 | sceneElementBindingInit(mrb_state *mrb, RClass *klass) 83 | { 84 | mrb_define_method(mrb, klass, "z", sceneElementGetZ, MRB_ARGS_NONE()); 85 | mrb_define_method(mrb, klass, "z=", sceneElementSetZ, MRB_ARGS_REQ(1)); 86 | mrb_define_method(mrb, klass, "visible", sceneElementGetVisible, MRB_ARGS_NONE()); 87 | mrb_define_method(mrb, klass, "visible=", sceneElementSetVisible, MRB_ARGS_REQ(1)); 88 | } 89 | 90 | #endif // SCENEELEMENTBINDING_H 91 | -------------------------------------------------------------------------------- /sources.def: -------------------------------------------------------------------------------- 1 | SOURCES=( 2 | src/main.cpp 3 | src/audio.cpp 4 | src/bitmap.cpp 5 | src/eventthread.cpp 6 | src/filesystem.cpp 7 | src/font.cpp 8 | src/iniconfig.cpp 9 | src/input.cpp 10 | src/plane.cpp 11 | src/scene.cpp 12 | src/sprite.cpp 13 | src/table.cpp 14 | src/tilequad.cpp 15 | src/viewport.cpp 16 | src/window.cpp 17 | src/texpool.cpp 18 | src/shader.cpp 19 | src/glstate.cpp 20 | src/tilemap.cpp 21 | src/autotiles.cpp 22 | src/graphics.cpp 23 | src/gl-debug.cpp 24 | src/etc.cpp 25 | src/config.cpp 26 | src/settingsmenu.cpp 27 | src/keybindings.cpp 28 | src/tileatlas.cpp 29 | src/sharedstate.cpp 30 | src/gl-fun.cpp 31 | src/gl-meta.cpp 32 | src/vertex.cpp 33 | src/soundemitter.cpp 34 | src/sdlsoundsource.cpp 35 | src/alstream.cpp 36 | src/audiostream.cpp 37 | src/rgssad.cpp 38 | src/bundledfont.cpp 39 | src/vorbissource.cpp 40 | src/windowvx.cpp 41 | src/tilemapvx.cpp 42 | src/tileatlasvx.cpp 43 | src/autotilesvx.cpp 44 | src/midisource.cpp 45 | src/fluid-fun.cpp 46 | ) 47 | 48 | SOURCES_C=( 49 | steamshim/steamshim_child.c 50 | ) 51 | 52 | MRI_SOURCES=( 53 | binding-mri/binding-mri.cpp 54 | binding-mri/binding-util.cpp 55 | binding-mri/table-binding.cpp 56 | binding-mri/etc-binding.cpp 57 | binding-mri/bitmap-binding.cpp 58 | binding-mri/font-binding.cpp 59 | binding-mri/graphics-binding.cpp 60 | binding-mri/input-binding.cpp 61 | binding-mri/sprite-binding.cpp 62 | binding-mri/viewport-binding.cpp 63 | binding-mri/plane-binding.cpp 64 | binding-mri/window-binding.cpp 65 | binding-mri/tilemap-binding.cpp 66 | binding-mri/audio-binding.cpp 67 | binding-mri/module_rpg.cpp 68 | binding-mri/filesystem-binding.cpp 69 | binding-mri/windowvx-binding.cpp 70 | binding-mri/tilemapvx-binding.cpp 71 | ) 72 | 73 | EMBED=( 74 | shader/common.h 75 | shader/transSimple.frag 76 | shader/trans.frag 77 | shader/hue.frag 78 | shader/sprite.frag 79 | shader/plane.frag 80 | shader/gray.frag 81 | shader/bitmapBlit.frag 82 | shader/flatColor.frag 83 | shader/simple.frag 84 | shader/simpleColor.frag 85 | shader/simpleAlpha.frag 86 | shader/simpleAlphaUni.frag 87 | shader/flashMap.frag 88 | shader/minimal.vert 89 | shader/simple.vert 90 | shader/simpleColor.vert 91 | shader/sprite.vert 92 | shader/tilemap.vert 93 | shader/blur.frag 94 | shader/blurH.vert 95 | shader/blurV.vert 96 | shader/simpleMatrix.vert 97 | shader/tilemapvx.vert 98 | assets/liberation.ttf 99 | assets/icon.png 100 | ) 101 | -------------------------------------------------------------------------------- /binding-mruby/plane-binding.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** plane-binding.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "plane.h" 23 | #include "disposable-binding.h" 24 | #include "viewportelement-binding.h" 25 | #include "binding-util.h" 26 | #include "binding-types.h" 27 | 28 | DEF_TYPE(Plane); 29 | 30 | MRB_METHOD(planeInitialize) 31 | { 32 | Plane *p = viewportElementInitialize(mrb, self); 33 | 34 | setPrivateData(self, p, PlaneType); 35 | 36 | p->initDynAttribs(); 37 | 38 | wrapProperty(mrb, self, &p->getColor(), CScolor, ColorType); 39 | wrapProperty(mrb, self, &p->getTone(), CStone, ToneType); 40 | 41 | return self; 42 | } 43 | 44 | DEF_PROP_OBJ_REF(Plane, Bitmap, Bitmap, CSbitmap) 45 | DEF_PROP_OBJ_VAL(Plane, Color, Color, CScolor) 46 | DEF_PROP_OBJ_VAL(Plane, Tone, Tone, CStone) 47 | 48 | DEF_PROP_I(Plane, OX) 49 | DEF_PROP_I(Plane, OY) 50 | DEF_PROP_I(Plane, Opacity) 51 | DEF_PROP_I(Plane, BlendType) 52 | 53 | DEF_PROP_F(Plane, ZoomX) 54 | DEF_PROP_F(Plane, ZoomY) 55 | 56 | 57 | void 58 | planeBindingInit(mrb_state *mrb) 59 | { 60 | RClass *klass = defineClass(mrb, "Plane"); 61 | 62 | disposableBindingInit (mrb, klass); 63 | viewportElementBindingInit(mrb, klass); 64 | 65 | mrb_define_method(mrb, klass, "initialize", planeInitialize, MRB_ARGS_OPT(1)); 66 | 67 | INIT_PROP_BIND( Plane, Bitmap, "bitmap" ); 68 | INIT_PROP_BIND( Plane, OX, "ox" ); 69 | INIT_PROP_BIND( Plane, OY, "oy" ); 70 | INIT_PROP_BIND( Plane, ZoomX, "zoom_x" ); 71 | INIT_PROP_BIND( Plane, ZoomY, "zoom_y" ); 72 | INIT_PROP_BIND( Plane, Opacity, "opacity" ); 73 | INIT_PROP_BIND( Plane, BlendType, "blend_type" ); 74 | INIT_PROP_BIND( Plane, Color, "color" ); 75 | INIT_PROP_BIND( Plane, Tone, "tone" ); 76 | 77 | mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE()); 78 | } 79 | -------------------------------------------------------------------------------- /binding-mruby/audio-binding.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** audio-binding.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "audio.h" 23 | #include "sharedstate.h" 24 | #include "binding-util.h" 25 | #include "exception.h" 26 | 27 | #define DEF_PLAY_STOP(entity) \ 28 | MRB_FUNCTION(audio_##entity##Play) \ 29 | { \ 30 | char *filename; \ 31 | mrb_int volume = 100; \ 32 | mrb_int pitch = 100; \ 33 | mrb_get_args(mrb, "z|ii", &filename, &volume, &pitch); \ 34 | GUARD_EXC( shState->audio().entity##Play(filename, volume, pitch); ) \ 35 | return mrb_nil_value(); \ 36 | } \ 37 | MRB_FUNCTION(audio_##entity##Stop) \ 38 | { \ 39 | MRB_FUN_UNUSED_PARAM; \ 40 | shState->audio().entity##Stop(); \ 41 | return mrb_nil_value(); \ 42 | } 43 | 44 | #define DEF_FADE(entity) \ 45 | MRB_FUNCTION(audio_##entity##Fade) \ 46 | { \ 47 | mrb_int time; \ 48 | mrb_get_args(mrb, "i", &time); \ 49 | shState->audio().entity##Fade(time); \ 50 | return mrb_nil_value(); \ 51 | } 52 | 53 | #define DEF_PLAY_STOP_FADE(entity) \ 54 | DEF_PLAY_STOP(entity) \ 55 | DEF_FADE(entity) 56 | 57 | DEF_PLAY_STOP_FADE( bgm ) 58 | DEF_PLAY_STOP_FADE( bgs ) 59 | DEF_PLAY_STOP_FADE( me ) 60 | 61 | DEF_PLAY_STOP( se ) 62 | 63 | 64 | #define BIND_PLAY_STOP(entity) \ 65 | mrb_define_module_function(mrb, module, #entity "_play", audio_##entity##Play, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(2)); \ 66 | mrb_define_module_function(mrb, module, #entity "_stop", audio_##entity##Stop, MRB_ARGS_NONE()); 67 | 68 | #define BIND_FADE(entity) \ 69 | mrb_define_module_function(mrb, module, #entity "_fade", audio_##entity##Fade, MRB_ARGS_REQ(1)); 70 | 71 | #define BIND_PLAY_STOP_FADE(entity) \ 72 | BIND_PLAY_STOP(entity) \ 73 | BIND_FADE(entity) 74 | 75 | 76 | void 77 | audioBindingInit(mrb_state *mrb) 78 | { 79 | RClass *module = mrb_define_module(mrb, "Audio"); 80 | 81 | BIND_PLAY_STOP_FADE( bgm ) 82 | BIND_PLAY_STOP_FADE( bgs ) 83 | BIND_PLAY_STOP_FADE( me ) 84 | 85 | BIND_PLAY_STOP( se ) 86 | } 87 | -------------------------------------------------------------------------------- /binding-mruby/mrb-ext/rwmem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** rwmem.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "rwmem.h" 23 | #include "util.h" 24 | 25 | #include 26 | 27 | #include 28 | 29 | typedef std::vector ByteVec; 30 | 31 | static inline ByteVec * 32 | getRWPrivate(SDL_RWops *ops) 33 | { 34 | return static_cast(ops->hidden.unknown.data1); 35 | } 36 | 37 | static Sint64 SDL_RWopsSize(SDL_RWops *ops) 38 | { 39 | ByteVec *v = getRWPrivate(ops); 40 | 41 | return v->size(); 42 | } 43 | 44 | static Sint64 SDL_RWopsSeek(SDL_RWops *, Sint64, int) 45 | { 46 | /* No need for implementation */ 47 | 48 | return -1; 49 | } 50 | 51 | static size_t SDL_RWopsRead(SDL_RWops *, void *, size_t, size_t) 52 | { 53 | /* No need for implementation */ 54 | 55 | return 0; 56 | } 57 | 58 | static size_t SDL_RWopsWrite(SDL_RWops *ops, const void *buffer, size_t size, size_t num) 59 | { 60 | ByteVec *v = getRWPrivate(ops); 61 | 62 | size_t writeBytes = size * num; 63 | 64 | if (writeBytes == 1) 65 | { 66 | char byte = *static_cast(buffer); 67 | v->push_back(byte); 68 | return 1; 69 | } 70 | 71 | size_t writeInd = v->size(); 72 | v->resize(writeInd + writeBytes); 73 | 74 | memcpy(&(*v)[writeInd], buffer, writeBytes); 75 | 76 | return num; 77 | } 78 | 79 | static int SDL_RWopsClose(SDL_RWops *ops) 80 | { 81 | ByteVec *v = getRWPrivate(ops); 82 | 83 | delete v; 84 | 85 | return 0; 86 | } 87 | 88 | void RWMemOpen(SDL_RWops *ops) 89 | { 90 | ByteVec *v = new ByteVec; 91 | ops->hidden.unknown.data1 = v; 92 | 93 | ops->size = SDL_RWopsSize; 94 | ops->seek = SDL_RWopsSeek; 95 | ops->read = SDL_RWopsRead; 96 | ops->write = SDL_RWopsWrite; 97 | ops->close = SDL_RWopsClose; 98 | } 99 | 100 | int RWMemGetData(SDL_RWops *ops, void *buffer) 101 | { 102 | ByteVec *v = getRWPrivate(ops); 103 | 104 | if (buffer) 105 | memcpy(buffer, dataPtr(*v), v->size()); 106 | 107 | return v->size(); 108 | } 109 | -------------------------------------------------------------------------------- /src/keybindings.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** keybindings.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2014 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef KEYBINDINGS_H 23 | #define KEYBINDINGS_H 24 | 25 | #include "input.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | enum AxisDir 34 | { 35 | Negative, 36 | Positive 37 | }; 38 | 39 | enum SourceType 40 | { 41 | Invalid, 42 | Key, 43 | JButton, 44 | JAxis, 45 | JHat 46 | }; 47 | 48 | struct SourceDesc 49 | { 50 | SourceType type; 51 | 52 | union Data 53 | { 54 | /* Keyboard scancode */ 55 | SDL_Scancode scan; 56 | /* Joystick button index */ 57 | uint8_t jb; 58 | struct 59 | { 60 | /* Joystick axis index */ 61 | uint8_t axis; 62 | /* Joystick axis direction */ 63 | AxisDir dir; 64 | } ja; 65 | struct 66 | { 67 | /* Joystick axis index */ 68 | uint8_t hat; 69 | /* Joystick axis direction */ 70 | uint8_t pos; 71 | } jh; 72 | } d; 73 | 74 | bool operator==(const SourceDesc &o) const 75 | { 76 | if (type != o.type) 77 | return false; 78 | 79 | switch (type) 80 | { 81 | case Invalid: 82 | return true; 83 | case Key: 84 | return d.scan == o.d.scan; 85 | case JButton: 86 | return d.jb == o.d.jb; 87 | case JAxis: 88 | return (d.ja.axis == o.d.ja.axis) && (d.ja.dir == o.d.ja.dir); 89 | case JHat: 90 | return (d.jh.hat == o.d.jh.hat) && (d.jh.pos == o.d.jh.pos); 91 | default: 92 | assert(!"unreachable"); 93 | return false; 94 | } 95 | } 96 | 97 | bool operator!=(const SourceDesc &o) const 98 | { 99 | return !(*this == o); 100 | } 101 | }; 102 | 103 | #define JAXIS_THRESHOLD 0x4000 104 | 105 | struct BindingDesc 106 | { 107 | SourceDesc src; 108 | Input::ButtonCode target; 109 | }; 110 | 111 | typedef std::vector BDescVec; 112 | struct Config; 113 | 114 | BDescVec genDefaultBindings(const Config &conf); 115 | 116 | void storeBindings(const BDescVec &d, const Config &conf); 117 | BDescVec loadBindings(const Config &conf); 118 | 119 | #endif // KEYBINDINGS_H 120 | -------------------------------------------------------------------------------- /src/alstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** alstream.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2014 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef ALSTREAM_H 23 | #define ALSTREAM_H 24 | 25 | #include "al-util.h" 26 | #include "sdl-util.h" 27 | 28 | #include 29 | #include 30 | 31 | struct ALDataSource; 32 | 33 | #define STREAM_BUFS 3 34 | 35 | /* State-machine like audio playback stream. 36 | * This class is NOT thread safe */ 37 | struct ALStream 38 | { 39 | enum State 40 | { 41 | Closed, 42 | Stopped, 43 | Playing, 44 | Paused 45 | }; 46 | 47 | bool looped; 48 | State state; 49 | 50 | ALDataSource *source; 51 | SDL_Thread *thread; 52 | 53 | std::string threadName; 54 | 55 | SDL_mutex *pauseMut; 56 | bool preemptPause; 57 | 58 | /* When this flag isn't set and alSrc is 59 | * in 'STOPPED' state, stream isn't over 60 | * (it just hasn't started yet) */ 61 | AtomicFlag streamInited; 62 | AtomicFlag sourceExhausted; 63 | 64 | AtomicFlag threadTermReq; 65 | 66 | AtomicFlag needsRewind; 67 | float startOffset; 68 | 69 | float pitch; 70 | 71 | AL::Source::ID alSrc; 72 | AL::Buffer::ID alBuf[STREAM_BUFS]; 73 | 74 | uint64_t procFrames; 75 | AL::Buffer::ID lastBuf; 76 | 77 | SDL_RWops srcOps; 78 | 79 | struct 80 | { 81 | ALenum format; 82 | ALsizei freq; 83 | } stream; 84 | 85 | enum LoopMode 86 | { 87 | Looped, 88 | NotLooped 89 | }; 90 | 91 | ALStream(LoopMode loopMode, 92 | const std::string &threadId); 93 | ~ALStream(); 94 | 95 | void close(); 96 | void open(const std::string &filename); 97 | void stop(); 98 | void play(float offset = 0); 99 | void pause(); 100 | 101 | void setVolume(float value); 102 | void setPitch(float value); 103 | State queryState(); 104 | float queryOffset(); 105 | bool queryNativePitch(); 106 | 107 | private: 108 | void closeSource(); 109 | void openSource(const std::string &filename); 110 | 111 | void stopStream(); 112 | void startStream(float offset); 113 | void pauseStream(); 114 | void resumeStream(); 115 | 116 | void checkStopped(); 117 | 118 | /* thread func */ 119 | void streamData(); 120 | }; 121 | 122 | #endif // ALSTREAM_H 123 | -------------------------------------------------------------------------------- /binding-mruby/viewport-binding.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** viewport-binding.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "viewport.h" 23 | #include "disposable-binding.h" 24 | #include "flashable-binding.h" 25 | #include "sceneelement-binding.h" 26 | #include "binding-util.h" 27 | #include "binding-types.h" 28 | 29 | DEF_TYPE(Viewport); 30 | 31 | MRB_METHOD(viewportInitialize) 32 | { 33 | Viewport *v; 34 | 35 | if (mrb->c->ci->argc == 1) 36 | { 37 | /* The rect arg is only used to init the viewport, 38 | * and does NOT replace its 'rect' property */ 39 | mrb_value rectObj; 40 | Rect *rect; 41 | 42 | mrb_get_args(mrb, "o", &rectObj); 43 | 44 | rect = getPrivateDataCheck(mrb, rectObj, RectType); 45 | 46 | v = new Viewport(rect); 47 | } 48 | else 49 | { 50 | mrb_int x, y, width, height; 51 | 52 | mrb_get_args(mrb, "iiii", &x, &y, &width, &height); 53 | 54 | v = new Viewport(x, y, width, height); 55 | } 56 | 57 | setPrivateData(self, v, ViewportType); 58 | 59 | /* Wrap property objects */ 60 | v->initDynAttribs(); 61 | 62 | wrapProperty(mrb, self, &v->getRect(), CSrect, RectType); 63 | wrapProperty(mrb, self, &v->getColor(), CScolor, ColorType); 64 | wrapProperty(mrb, self, &v->getTone(), CStone, ToneType); 65 | 66 | return self; 67 | } 68 | 69 | DEF_PROP_OBJ_VAL(Viewport, Rect, Rect, CSrect) 70 | DEF_PROP_OBJ_VAL(Viewport, Color, Color, CScolor) 71 | DEF_PROP_OBJ_VAL(Viewport, Tone, Tone, CStone) 72 | 73 | DEF_PROP_I(Viewport, OX) 74 | DEF_PROP_I(Viewport, OY) 75 | 76 | 77 | void 78 | viewportBindingInit(mrb_state *mrb) 79 | { 80 | RClass *klass = defineClass(mrb, "Viewport"); 81 | 82 | disposableBindingInit (mrb, klass); 83 | flashableBindingInit (mrb, klass); 84 | sceneElementBindingInit(mrb, klass); 85 | 86 | mrb_define_method(mrb, klass, "initialize", viewportInitialize, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(3)); 87 | 88 | INIT_PROP_BIND( Viewport, Rect, "rect" ); 89 | INIT_PROP_BIND( Viewport, OX, "ox" ); 90 | INIT_PROP_BIND( Viewport, OY, "oy" ); 91 | INIT_PROP_BIND( Viewport, Color, "color" ); 92 | INIT_PROP_BIND( Viewport, Tone, "tone" ); 93 | 94 | mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE()); 95 | } 96 | -------------------------------------------------------------------------------- /binding-mri/viewportelement-binding.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** viewportelement-binding.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef VIEWPORTELEMENTBINDING_H 23 | #define VIEWPORTELEMENTBINDING_H 24 | 25 | #include "viewport.h" 26 | #include "sharedstate.h" 27 | #include "binding-util.h" 28 | #include "binding-types.h" 29 | 30 | #include "sceneelement-binding.h" 31 | #include "disposable-binding.h" 32 | 33 | template 34 | RB_METHOD(viewportElementGetViewport) 35 | { 36 | RB_UNUSED_PARAM; 37 | 38 | checkDisposed(self); 39 | 40 | return rb_iv_get(self, "viewport"); 41 | } 42 | 43 | template 44 | RB_METHOD(viewportElementSetViewport) 45 | { 46 | RB_UNUSED_PARAM; 47 | 48 | ViewportElement *ve = getPrivateData(self); 49 | 50 | VALUE viewportObj = Qnil; 51 | Viewport *viewport = 0; 52 | 53 | rb_get_args(argc, argv, "o", &viewportObj RB_ARG_END); 54 | 55 | if (!NIL_P(viewportObj)) 56 | viewport = getPrivateDataCheck(viewportObj, ViewportType); 57 | 58 | GUARD_EXC( ve->setViewport(viewport); ); 59 | 60 | rb_iv_set(self, "viewport", viewportObj); 61 | 62 | return viewportObj; 63 | } 64 | 65 | template 66 | static C * 67 | viewportElementInitialize(int argc, VALUE *argv, VALUE self) 68 | { 69 | /* Get parameters */ 70 | VALUE viewportObj = Qnil; 71 | Viewport *viewport = 0; 72 | 73 | rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END); 74 | 75 | if (!NIL_P(viewportObj)) 76 | { 77 | viewport = getPrivateDataCheck(viewportObj, ViewportType); 78 | 79 | if (rgssVer == 1) 80 | disposableAddChild(viewportObj, self); 81 | } 82 | 83 | /* Construct object */ 84 | C *ve = new C(viewport); 85 | 86 | /* Set property objects */ 87 | rb_iv_set(self, "viewport", viewportObj); 88 | 89 | return ve; 90 | } 91 | 92 | template 93 | void 94 | viewportElementBindingInit(VALUE klass) 95 | { 96 | sceneElementBindingInit(klass); 97 | 98 | _rb_define_method(klass, "viewport", viewportElementGetViewport); 99 | 100 | if (rgssVer >= 2) 101 | { 102 | _rb_define_method(klass, "viewport=", viewportElementSetViewport); 103 | } 104 | } 105 | 106 | #endif // VIEWPORTELEMENTBINDING_H 107 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** config.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef CONFIG_H 23 | #define CONFIG_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | struct CropTexture 30 | { 31 | std::string filename; 32 | int w, h; 33 | }; 34 | 35 | struct Config 36 | { 37 | int rgssVersion; 38 | 39 | bool debugMode; 40 | bool printFPS; 41 | 42 | bool winResizable; 43 | bool fullscreen; 44 | bool fixedAspectRatio; 45 | bool smoothScaling; 46 | bool vsync; 47 | 48 | int defScreenW; 49 | int defScreenH; 50 | std::string windowTitle; 51 | 52 | int fixedFramerate; 53 | bool frameSkip; 54 | bool syncToRefreshrate; 55 | 56 | bool solidFonts; 57 | 58 | bool subImageFix; 59 | bool enableBlitting; 60 | int maxTextureSize; 61 | 62 | struct 63 | { 64 | bool active; 65 | bool lastMileScaling; 66 | } integerScaling; 67 | 68 | std::string gameFolder; 69 | bool anyAltToggleFS; 70 | bool enableReset; 71 | bool allowSymlinks; 72 | bool pathCache; 73 | 74 | std::string dataPathOrg; 75 | std::string dataPathApp; 76 | 77 | std::string iconPath; 78 | std::string execName; 79 | std::string titleLanguage; 80 | 81 | struct 82 | { 83 | std::string soundFont; 84 | bool chorus; 85 | bool reverb; 86 | } midi; 87 | 88 | struct 89 | { 90 | int sourceCount; 91 | } SE; 92 | 93 | struct 94 | { 95 | float bgs; 96 | float se; 97 | } volume; 98 | 99 | bool useScriptNames; 100 | 101 | std::string customScript; 102 | std::set preloadScripts; 103 | std::vector rtps; 104 | 105 | std::vector fontSubs; 106 | 107 | std::vector rubyLoadpaths; 108 | 109 | /* Editor flags */ 110 | struct { 111 | bool debug; 112 | bool battleTest; 113 | } editor; 114 | 115 | /* Game INI contents */ 116 | struct { 117 | std::string scripts; 118 | std::string title; 119 | } game; 120 | 121 | /* Internal */ 122 | std::string customDataPath; 123 | std::string commonDataPath; 124 | 125 | std::vector cropTexs; 126 | 127 | Config(); 128 | 129 | void read(int argc, char *argv[]); 130 | void readGameINI(); 131 | }; 132 | 133 | #endif // CONFIG_H 134 | -------------------------------------------------------------------------------- /src/iniconfig.cpp: -------------------------------------------------------------------------------- 1 | #include "iniconfig.h" 2 | 3 | #include 4 | 5 | std::string toLowerCase(const std::string& str) 6 | { 7 | std::string lower = str; 8 | std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); 9 | return lower; 10 | } 11 | 12 | std::string trim(const std::string& str, const std::string& chars = "\t\n\v\f\r ") 13 | { 14 | std::string trimmed = str; 15 | trimmed.erase(trimmed.find_last_not_of(chars) + 1); 16 | trimmed.erase(0, trimmed.find_first_not_of(chars)); 17 | return trimmed; 18 | } 19 | 20 | INIConfiguration::Section::Section (const std::string& sname) : m_Name (sname), m_PropertyMap() 21 | { 22 | } 23 | 24 | bool INIConfiguration::Section::getStringProperty (const std::string& name, std::string& outPropStr) const 25 | { 26 | try 27 | { 28 | outPropStr = m_PropertyMap.at(toLowerCase(name)).m_Value; 29 | return true; 30 | } 31 | catch (std::out_of_range& oorexcept) 32 | { 33 | return false; 34 | } 35 | } 36 | 37 | bool INIConfiguration::load (std::istream& is) 38 | { 39 | if (!is.good()) 40 | { 41 | return false; 42 | } 43 | 44 | std::string currSectionName; 45 | 46 | std::string line; 47 | std::getline (is, line); 48 | 49 | while (!is.eof() && !is.bad()) 50 | { 51 | if (line[0] == '[') 52 | { 53 | currSectionName = line.substr (1, line.find_last_of (']') - 1); 54 | } 55 | else if (line[0] != '#' && line.length() > 2) 56 | { 57 | int crloc = line.length() - 1; 58 | 59 | if (crloc >= 0 && line[crloc] == '\r') //check for Windows-style newline 60 | line.resize (crloc); //and correct 61 | 62 | size_t equalsPos = line.find_first_of ("="); 63 | 64 | if (equalsPos != std::string::npos) 65 | { 66 | std::string key = line.substr (0, equalsPos); 67 | std::string val = line.substr (equalsPos + 1); 68 | 69 | addProperty (currSectionName, key , val); 70 | } 71 | } 72 | 73 | std::getline (is, line); 74 | } 75 | 76 | if (is.bad()) 77 | { 78 | return false; 79 | } 80 | 81 | return true; 82 | } 83 | 84 | 85 | std::string INIConfiguration::getStringProperty(const std::string& sname, const std::string& name, const std::string& def) const 86 | { 87 | auto sectionIt = m_SectionMap.find(toLowerCase(sname)); 88 | 89 | if (sectionIt != m_SectionMap.end()) 90 | { 91 | std::string prop; 92 | 93 | if(sectionIt->second.getStringProperty(name, prop)) 94 | { 95 | return prop; 96 | } 97 | } 98 | 99 | return def; 100 | } 101 | 102 | void INIConfiguration::addProperty (const std::string& sname, const std::string& name, const std::string& val) 103 | { 104 | if (m_SectionMap.find (toLowerCase(sname)) == m_SectionMap.end()) 105 | { 106 | m_SectionMap.emplace (toLowerCase(sname), Section (sname)); 107 | } 108 | 109 | Section::Property p; 110 | p.m_Name = trim(name); 111 | p.m_Value = trim(val); 112 | 113 | m_SectionMap.at (toLowerCase(sname)).m_PropertyMap[toLowerCase(p.m_Name)] = p; 114 | } 115 | -------------------------------------------------------------------------------- /src/fluid-fun.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUIDFUN_H 2 | #define FLUIDFUN_H 3 | 4 | #ifdef SHARED_FLUID 5 | # include 6 | #else 7 | # define FLUIDSYNTH_VERSION_MAJOR 2 8 | #endif 9 | 10 | typedef struct _fluid_hashtable_t fluid_settings_t; 11 | typedef struct _fluid_synth_t fluid_synth_t; 12 | 13 | typedef int (*FLUIDSETTINGSSETNUMPROC)(fluid_settings_t* settings, const char *name, double val); 14 | typedef int (*FLUIDSETTINGSSETSTRPROC)(fluid_settings_t* settings, const char *name, const char *str); 15 | typedef int (*FLUIDSYNTHSFLOADPROC)(fluid_synth_t* synth, const char* filename, int reset_presets); 16 | typedef int (*FLUIDSYNTHSYSTEMRESETPROC)(fluid_synth_t* synth); 17 | typedef int (*FLUIDSYNTHWRITES16PROC)(fluid_synth_t* synth, int len, void* lout, int loff, int lincr, void* rout, int roff, int rincr); 18 | typedef int (*FLUIDSYNTHNOTEONPROC)(fluid_synth_t* synth, int chan, int key, int vel); 19 | typedef int (*FLUIDSYNTHNOTEOFFPROC)(fluid_synth_t* synth, int chan, int key); 20 | typedef int (*FLUIDSYNTHCHANNELPRESSUREPROC)(fluid_synth_t* synth, int chan, int val); 21 | typedef int (*FLUIDSYNTHPITCHBENDPROC)(fluid_synth_t* synth, int chan, int val); 22 | typedef int (*FLUIDSYNTHCCPROC)(fluid_synth_t* synth, int chan, int ctrl, int val); 23 | typedef int (*FLUIDSYNTHPROGRAMCHANGEPROC)(fluid_synth_t* synth, int chan, int program); 24 | 25 | typedef fluid_settings_t* (*NEWFLUIDSETTINGSPROC)(void); 26 | typedef fluid_synth_t* (*NEWFLUIDSYNTHPROC)(fluid_settings_t* settings); 27 | typedef void (*DELETEFLUIDSETTINGSPROC)(fluid_settings_t* settings); 28 | 29 | #if FLUIDSYNTH_VERSION_MAJOR == 1 30 | typedef int (*DELETEFLUIDSYNTHPROC)(fluid_synth_t* synth); 31 | #else 32 | typedef void (*DELETEFLUIDSYNTHPROC)(fluid_synth_t* synth); 33 | #endif 34 | 35 | #define FLUID_FUNCS \ 36 | FLUID_FUN(settings_setnum, FLUIDSETTINGSSETNUMPROC) \ 37 | FLUID_FUN(settings_setstr, FLUIDSETTINGSSETSTRPROC) \ 38 | FLUID_FUN(synth_sfload, FLUIDSYNTHSFLOADPROC) \ 39 | FLUID_FUN(synth_system_reset, FLUIDSYNTHSYSTEMRESETPROC) \ 40 | FLUID_FUN(synth_write_s16, FLUIDSYNTHWRITES16PROC) \ 41 | FLUID_FUN(synth_noteon, FLUIDSYNTHNOTEONPROC) \ 42 | FLUID_FUN(synth_noteoff, FLUIDSYNTHNOTEOFFPROC) \ 43 | FLUID_FUN(synth_channel_pressure, FLUIDSYNTHCHANNELPRESSUREPROC) \ 44 | FLUID_FUN(synth_pitch_bend, FLUIDSYNTHPITCHBENDPROC) \ 45 | FLUID_FUN(synth_cc, FLUIDSYNTHCCPROC) \ 46 | FLUID_FUN(synth_program_change, FLUIDSYNTHPROGRAMCHANGEPROC) 47 | 48 | /* Functions that don't fit into the default prefix naming scheme */ 49 | #define FLUID_FUNCS2 \ 50 | FLUID_FUN2(new_settings, NEWFLUIDSETTINGSPROC, new_fluid_settings) \ 51 | FLUID_FUN2(new_synth, NEWFLUIDSYNTHPROC, new_fluid_synth) \ 52 | FLUID_FUN2(delete_settings, DELETEFLUIDSETTINGSPROC, delete_fluid_settings) \ 53 | FLUID_FUN2(delete_synth, DELETEFLUIDSYNTHPROC, delete_fluid_synth) 54 | 55 | struct FluidFunctions 56 | { 57 | #define FLUID_FUN(name, type) type name; 58 | #define FLUID_FUN2(name, type, rn) type name; 59 | FLUID_FUNCS 60 | FLUID_FUNCS2 61 | #undef FLUID_FUN 62 | #undef FLUID_FUN2 63 | }; 64 | 65 | #define HAVE_FLUID fluid.new_synth 66 | 67 | extern FluidFunctions fluid; 68 | 69 | void initFluidFunctions(); 70 | 71 | #endif // FLUIDFUN_H 72 | -------------------------------------------------------------------------------- /src/intrulist.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** intrulist.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef INTRULIST_H 23 | #define INTRULIST_H 24 | 25 | template 26 | struct IntruListLink 27 | { 28 | IntruListLink *prev; 29 | IntruListLink *next; 30 | T *data; 31 | 32 | IntruListLink(T *data) 33 | : prev(0), 34 | next(0), 35 | data(data) 36 | {} 37 | 38 | ~IntruListLink() 39 | { 40 | if (prev && next) 41 | { 42 | next->prev = prev; 43 | prev->next = next; 44 | } 45 | } 46 | }; 47 | 48 | template 49 | class IntruList 50 | { 51 | IntruListLink root; 52 | int size; 53 | 54 | public: 55 | IntruList() 56 | : root(0), 57 | size(0) 58 | { 59 | root.prev = &root; 60 | root.next = &root; 61 | } 62 | 63 | void prepend(IntruListLink &node) 64 | { 65 | root.next->prev = &node; 66 | node.prev = &root; 67 | node.next = root.next; 68 | root.next = &node; 69 | 70 | size++; 71 | } 72 | 73 | void append(IntruListLink &node) 74 | { 75 | root.prev->next = &node; 76 | node.next = &root; 77 | node.prev = root.prev; 78 | root.prev = &node; 79 | 80 | size++; 81 | } 82 | 83 | void insertBefore(IntruListLink &node, 84 | IntruListLink &prev) 85 | { 86 | node.next = &prev; 87 | node.prev = prev.prev; 88 | prev.prev->next = &node; 89 | prev.prev = &node; 90 | 91 | size++; 92 | } 93 | 94 | void remove(IntruListLink &node) 95 | { 96 | if (!node.next) 97 | return; 98 | 99 | node.prev->next = node.next; 100 | node.next->prev = node.prev; 101 | 102 | node.prev = 0; 103 | node.next = 0; 104 | 105 | size--; 106 | } 107 | 108 | void clear() 109 | { 110 | remove(root); 111 | root.prev = &root; 112 | root.next = &root; 113 | 114 | size = 0; 115 | } 116 | 117 | T *tail() const 118 | { 119 | IntruListLink *node = root.prev; 120 | if (node == &root) 121 | return 0; 122 | 123 | return node->data; 124 | } 125 | 126 | IntruListLink *begin() 127 | { 128 | return root.next; 129 | } 130 | 131 | IntruListLink *end() 132 | { 133 | return &root; 134 | } 135 | 136 | bool isEmpty() const 137 | { 138 | return root.next == &root; 139 | } 140 | 141 | int getSize() const 142 | { 143 | return size; 144 | } 145 | }; 146 | 147 | #endif // INTRULIST_H 148 | -------------------------------------------------------------------------------- /src/glstate.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** glstate.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef GLSTATE_H 23 | #define GLSTATE_H 24 | 25 | #include "etc.h" 26 | 27 | #include 28 | #include 29 | 30 | struct Config; 31 | 32 | template 33 | struct GLProperty 34 | { 35 | ~GLProperty() 36 | { 37 | assert(stack.size() == 0); 38 | } 39 | 40 | void init(const T &value) 41 | { 42 | current = value; 43 | apply(value); 44 | } 45 | 46 | void push() { stack.push(current); } 47 | void pop() { set(stack.top()); stack.pop(); } 48 | const T &get() { return current; } 49 | void set(const T &value) 50 | { 51 | if (value == current) 52 | return; 53 | 54 | init(value); 55 | } 56 | 57 | void pushSet(const T &value) 58 | { 59 | push(); 60 | set(value); 61 | } 62 | 63 | void refresh() 64 | { 65 | apply(current); 66 | } 67 | private: 68 | virtual void apply(const T &value) = 0; 69 | 70 | T current; 71 | std::stack stack; 72 | }; 73 | 74 | 75 | class GLClearColor : public GLProperty 76 | { 77 | void apply(const Vec4 &); 78 | }; 79 | 80 | class GLScissorBox : public GLProperty 81 | { 82 | public: 83 | /* Sets the intersection of the current box with value */ 84 | void setIntersect(const IntRect &value); 85 | 86 | private: 87 | void apply(const IntRect &value); 88 | }; 89 | 90 | class GLScissorTest : public GLProperty 91 | { 92 | void apply(const bool &value); 93 | }; 94 | 95 | class GLBlendMode : public GLProperty 96 | { 97 | void apply(const BlendType &value); 98 | }; 99 | 100 | class GLBlend : public GLProperty 101 | { 102 | void apply(const bool &value); 103 | }; 104 | 105 | class GLViewport : public GLProperty 106 | { 107 | void apply(const IntRect &value); 108 | }; 109 | 110 | class GLProgram : public GLProperty /* GLuint */ 111 | { 112 | void apply(const unsigned int &value); 113 | }; 114 | 115 | 116 | class GLState 117 | { 118 | public: 119 | GLClearColor clearColor; 120 | GLScissorBox scissorBox; 121 | GLScissorTest scissorTest; 122 | GLBlendMode blendMode; 123 | GLBlend blend; 124 | GLViewport viewport; 125 | GLProgram program; 126 | 127 | struct Caps 128 | { 129 | int maxTexSize; 130 | 131 | Caps(); 132 | 133 | } caps; 134 | 135 | GLState(const Config &conf); 136 | }; 137 | 138 | #endif // GLSTATE_H 139 | -------------------------------------------------------------------------------- /src/quadarray.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** quadarray.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef QUADARRAY_H 23 | #define QUADARRAY_H 24 | 25 | #include "vertex.h" 26 | #include "gl-util.h" 27 | #include "gl-meta.h" 28 | #include "sharedstate.h" 29 | #include "global-ibo.h" 30 | #include "shader.h" 31 | 32 | #include 33 | #include 34 | 35 | template 36 | struct QuadArray 37 | { 38 | std::vector vertices; 39 | 40 | VBO::ID vbo; 41 | GLMeta::VAO vao; 42 | 43 | size_t quadCount; 44 | GLsizeiptr vboSize; 45 | 46 | QuadArray() 47 | : quadCount(0), 48 | vboSize(-1) 49 | { 50 | vbo = VBO::gen(); 51 | 52 | GLMeta::vaoFillInVertexData(vao); 53 | vao.vbo = vbo; 54 | vao.ibo = shState->globalIBO().ibo; 55 | 56 | GLMeta::vaoInit(vao); 57 | } 58 | 59 | ~QuadArray() 60 | { 61 | GLMeta::vaoFini(vao); 62 | VBO::del(vbo); 63 | } 64 | 65 | void resize(size_t size) 66 | { 67 | vertices.resize(size * 4); 68 | quadCount = size; 69 | } 70 | 71 | void clear() 72 | { 73 | vertices.clear(); 74 | quadCount = 0; 75 | } 76 | 77 | /* This needs to be called after the final 'append()' call 78 | * and previous to the first 'draw()' call. */ 79 | void commit() 80 | { 81 | VBO::bind(vbo); 82 | 83 | GLsizeiptr size = vertices.size() * sizeof(VertexType); 84 | 85 | if (size > vboSize) 86 | { 87 | /* New data exceeds already allocated size. 88 | * Reallocate VBO. */ 89 | VBO::uploadData(size, dataPtr(vertices), GL_DYNAMIC_DRAW); 90 | vboSize = size; 91 | 92 | shState->ensureQuadIBO(quadCount); 93 | } 94 | else 95 | { 96 | /* New data fits in allocated size */ 97 | VBO::uploadSubData(0, size, dataPtr(vertices)); 98 | } 99 | 100 | VBO::unbind(); 101 | } 102 | 103 | void draw(size_t offset, size_t count) 104 | { 105 | GLMeta::vaoBind(vao); 106 | 107 | const char *_offset = (const char*) 0 + offset * 6 * sizeof(index_t); 108 | gl.DrawElements(GL_TRIANGLES, count * 6, _GL_INDEX_TYPE, _offset); 109 | 110 | GLMeta::vaoUnbind(vao); 111 | } 112 | 113 | void draw() 114 | { 115 | draw(0, quadCount); 116 | } 117 | 118 | size_t count() const 119 | { 120 | return quadCount; 121 | } 122 | }; 123 | 124 | typedef QuadArray ColorQuadArray; 125 | typedef QuadArray SimpleQuadArray; 126 | 127 | #endif // QUADARRAY_H 128 | -------------------------------------------------------------------------------- /binding-mri/disposable-binding.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** disposable-binding.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef DISPOSABLEBINDING_H 23 | #define DISPOSABLEBINDING_H 24 | 25 | #include "disposable.h" 26 | #include "binding-util.h" 27 | 28 | /* 'Children' are disposables that are disposed together 29 | * with their parent. Currently this is only used by Viewport 30 | * in RGSS1. */ 31 | inline void 32 | disposableAddChild(VALUE disp, VALUE child) 33 | { 34 | VALUE children = rb_iv_get(disp, "children"); 35 | 36 | if (NIL_P(children)) 37 | { 38 | children = rb_ary_new(); 39 | rb_iv_set(disp, "children", children); 40 | } 41 | 42 | /* Assumes children are never removed until destruction */ 43 | rb_ary_push(children, child); 44 | } 45 | 46 | inline void 47 | disposableDisposeChildren(VALUE disp) 48 | { 49 | VALUE children = rb_iv_get(disp, "children"); 50 | 51 | if (NIL_P(children)) 52 | return; 53 | 54 | ID dispFun = rb_intern("_mkxp_dispose_alias"); 55 | 56 | for (long i = 0; i < RARRAY_LEN(children); ++i) 57 | rb_funcall2(rb_ary_entry(children, i), dispFun, 0, 0); 58 | } 59 | 60 | template 61 | RB_METHOD(disposableDispose) 62 | { 63 | RB_UNUSED_PARAM; 64 | 65 | C *d = getPrivateData(self); 66 | 67 | if (!d) 68 | return Qnil; 69 | 70 | /* Nothing to do if already disposed */ 71 | if (d->isDisposed()) 72 | return Qnil; 73 | 74 | if (rgssVer == 1) 75 | disposableDisposeChildren(self); 76 | 77 | d->dispose(); 78 | 79 | return Qnil; 80 | } 81 | 82 | template 83 | RB_METHOD(disposableIsDisposed) 84 | { 85 | RB_UNUSED_PARAM; 86 | 87 | C *d = getPrivateData(self); 88 | 89 | if (!d) 90 | return Qtrue; 91 | 92 | return rb_bool_new(d->isDisposed()); 93 | } 94 | 95 | template 96 | static void disposableBindingInit(VALUE klass) 97 | { 98 | _rb_define_method(klass, "dispose", disposableDispose); 99 | _rb_define_method(klass, "disposed?", disposableIsDisposed); 100 | 101 | /* Make sure we always have access to the original method, even 102 | * if it is overridden by user scripts */ 103 | if (rgssVer == 1) 104 | rb_define_alias(klass, "_mkxp_dispose_alias", "dispose"); 105 | } 106 | 107 | template 108 | inline void 109 | checkDisposed(VALUE self) 110 | { 111 | if (disposableIsDisposed(0, 0, self) == Qtrue) 112 | raiseDisposedAccess(self); 113 | } 114 | 115 | #endif // DISPOSABLEBINDING_H 116 | -------------------------------------------------------------------------------- /src/boost-hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** boost-hash.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef BOOSTHASH_H 23 | #define BOOSTHASH_H 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | /* Wrappers around the boost unordered template classes, 31 | * exposing an interface similar to Qt's QHash/QSet */ 32 | 33 | template 34 | class BoostHash 35 | { 36 | private: 37 | typedef boost::unordered_map BoostType; 38 | typedef std::pair PairType; 39 | BoostType p; 40 | 41 | public: 42 | typedef typename BoostType::const_iterator const_iterator; 43 | 44 | inline bool contains(const K &key) const 45 | { 46 | const_iterator iter = p.find(key); 47 | 48 | return (iter != p.cend()); 49 | } 50 | 51 | inline void insert(const K &key, const V &value) 52 | { 53 | p.insert(PairType(key, value)); 54 | } 55 | 56 | inline void remove(const K &key) 57 | { 58 | p.erase(key); 59 | } 60 | 61 | inline const V value(const K &key) const 62 | { 63 | const_iterator iter = p.find(key); 64 | 65 | if (iter == p.cend()) 66 | return V(); 67 | 68 | return iter->second; 69 | } 70 | 71 | inline const V value(const K &key, const V &defaultValue) const 72 | { 73 | const_iterator iter = p.find(key); 74 | 75 | if (iter == p.cend()) 76 | return defaultValue; 77 | 78 | return iter->second; 79 | } 80 | 81 | inline V &operator[](const K &key) 82 | { 83 | return p[key]; 84 | } 85 | 86 | inline const_iterator cbegin() const 87 | { 88 | return p.cbegin(); 89 | } 90 | 91 | inline const_iterator cend() const 92 | { 93 | return p.cend(); 94 | } 95 | }; 96 | 97 | template 98 | class BoostSet 99 | { 100 | private: 101 | typedef boost::unordered_set BoostType; 102 | BoostType p; 103 | 104 | public: 105 | typedef typename BoostType::const_iterator const_iterator; 106 | 107 | inline bool contains(const K &key) 108 | { 109 | const_iterator iter = p.find(key); 110 | 111 | return (iter != p.cend()); 112 | } 113 | 114 | inline void insert(const K &key) 115 | { 116 | p.insert(key); 117 | } 118 | 119 | inline void remove(const K &key) 120 | { 121 | p.erase(key); 122 | } 123 | 124 | inline const_iterator cbegin() const 125 | { 126 | return p.cbegin(); 127 | } 128 | 129 | inline const_iterator cend() const 130 | { 131 | return p.cend(); 132 | } 133 | }; 134 | 135 | #endif // BOOSTHASH_H 136 | -------------------------------------------------------------------------------- /binding-mri/viewport-binding.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** viewport-binding.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "viewport.h" 23 | #include "sharedstate.h" 24 | #include "disposable-binding.h" 25 | #include "flashable-binding.h" 26 | #include "sceneelement-binding.h" 27 | #include "binding-util.h" 28 | #include "binding-types.h" 29 | 30 | DEF_TYPE(Viewport); 31 | 32 | RB_METHOD(viewportInitialize) 33 | { 34 | Viewport *v; 35 | 36 | if (argc == 0 && rgssVer >= 3) 37 | { 38 | v = new Viewport(); 39 | } 40 | else if (argc == 1) 41 | { 42 | /* The rect arg is only used to init the viewport, 43 | * and does NOT replace its 'rect' property */ 44 | VALUE rectObj; 45 | Rect *rect; 46 | 47 | rb_get_args(argc, argv, "o", &rectObj RB_ARG_END); 48 | 49 | rect = getPrivateDataCheck(rectObj, RectType); 50 | 51 | v = new Viewport(rect); 52 | } 53 | else 54 | { 55 | int x, y, width, height; 56 | 57 | rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END); 58 | 59 | v = new Viewport(x, y, width, height); 60 | } 61 | 62 | setPrivateData(self, v); 63 | 64 | /* Wrap property objects */ 65 | v->initDynAttribs(); 66 | 67 | wrapProperty(self, &v->getRect(), "rect", RectType); 68 | wrapProperty(self, &v->getColor(), "color", ColorType); 69 | wrapProperty(self, &v->getTone(), "tone", ToneType); 70 | 71 | /* 'elements' holds all SceneElements that become children 72 | * of this viewport, so we can dispose them when the viewport 73 | * is disposed */ 74 | rb_iv_set(self, "elements", rb_ary_new()); 75 | 76 | return self; 77 | } 78 | 79 | DEF_PROP_OBJ_VAL(Viewport, Rect, Rect, "rect") 80 | DEF_PROP_OBJ_VAL(Viewport, Color, Color, "color") 81 | DEF_PROP_OBJ_VAL(Viewport, Tone, Tone, "tone") 82 | 83 | DEF_PROP_I(Viewport, OX) 84 | DEF_PROP_I(Viewport, OY) 85 | 86 | 87 | void 88 | viewportBindingInit() 89 | { 90 | VALUE klass = rb_define_class("Viewport", rb_cObject); 91 | rb_define_alloc_func(klass, classAllocate<&ViewportType>); 92 | 93 | disposableBindingInit (klass); 94 | flashableBindingInit (klass); 95 | sceneElementBindingInit(klass); 96 | 97 | _rb_define_method(klass, "initialize", viewportInitialize); 98 | 99 | INIT_PROP_BIND( Viewport, Rect, "rect" ); 100 | INIT_PROP_BIND( Viewport, OX, "ox" ); 101 | INIT_PROP_BIND( Viewport, OY, "oy" ); 102 | INIT_PROP_BIND( Viewport, Color, "color" ); 103 | INIT_PROP_BIND( Viewport, Tone, "tone" ); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /src/sdl-util.h: -------------------------------------------------------------------------------- 1 | #ifndef SDLUTIL_H 2 | #define SDLUTIL_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | struct AtomicFlag 12 | { 13 | AtomicFlag() 14 | { 15 | clear(); 16 | } 17 | 18 | void set() 19 | { 20 | SDL_AtomicSet(&atom, 1); 21 | } 22 | 23 | void clear() 24 | { 25 | SDL_AtomicSet(&atom, 0); 26 | } 27 | 28 | operator bool() const 29 | { 30 | return SDL_AtomicGet(&atom); 31 | } 32 | 33 | private: 34 | mutable SDL_atomic_t atom; 35 | }; 36 | 37 | template 38 | int __sdlThreadFun(void *obj) 39 | { 40 | (static_cast(obj)->*func)(); 41 | return 0; 42 | } 43 | 44 | template 45 | SDL_Thread *createSDLThread(C *obj, const std::string &name = std::string()) 46 | { 47 | return SDL_CreateThread((__sdlThreadFun), name.c_str(), obj); 48 | } 49 | 50 | /* On Android, SDL_RWFromFile always opens files from inside 51 | * the apk asset folder even when a file with same name exists 52 | * on the physical filesystem. This wrapper attempts to open a 53 | * real file first before falling back to the assets folder */ 54 | static inline 55 | SDL_RWops *RWFromFile(const char *filename, 56 | const char *mode) 57 | { 58 | FILE *f = fopen(filename, mode); 59 | 60 | if (!f) 61 | return SDL_RWFromFile(filename, mode); 62 | 63 | return SDL_RWFromFP(f, SDL_TRUE); 64 | } 65 | 66 | inline bool readFileSDL(const char *path, 67 | std::string &out) 68 | { 69 | SDL_RWops *f = RWFromFile(path, "rb"); 70 | 71 | if (!f) 72 | return false; 73 | 74 | long size = SDL_RWsize(f); 75 | size_t back = out.size(); 76 | 77 | out.resize(back+size); 78 | size_t read = SDL_RWread(f, &out[back], 1, size); 79 | SDL_RWclose(f); 80 | 81 | if (read != (size_t) size) 82 | out.resize(back+read); 83 | 84 | return true; 85 | } 86 | 87 | template 88 | class SDLRWBuf : public std::streambuf 89 | { 90 | public: 91 | SDLRWBuf(SDL_RWops *ops) 92 | : ops(ops) 93 | { 94 | char *end = buf + bufSize + pbSize; 95 | setg(end, end, end); 96 | } 97 | 98 | private: 99 | int_type underflow() 100 | { 101 | if (!ops) 102 | return traits_type::eof(); 103 | 104 | if (gptr() < egptr()) 105 | return traits_type::to_int_type(*gptr()); 106 | 107 | char *base = buf; 108 | char *start = base; 109 | 110 | if (eback() == base) 111 | { 112 | memmove(base, egptr() - pbSize, pbSize); 113 | start += pbSize; 114 | } 115 | 116 | size_t n = SDL_RWread(ops, start, 1, bufSize - (start - base)); 117 | if (n == 0) 118 | return traits_type::eof(); 119 | 120 | setg(base, start, start + n); 121 | 122 | return underflow(); 123 | } 124 | 125 | SDL_RWops *ops; 126 | char buf[bufSize+pbSize]; 127 | }; 128 | 129 | class SDLRWStream 130 | { 131 | public: 132 | SDLRWStream(const char *filename, 133 | const char *mode) 134 | : ops(RWFromFile(filename, mode)), 135 | buf(ops), 136 | s(&buf) 137 | {} 138 | 139 | ~SDLRWStream() 140 | { 141 | if (ops) 142 | SDL_RWclose(ops); 143 | } 144 | 145 | operator bool() const 146 | { 147 | return ops != 0; 148 | } 149 | 150 | std::istream &stream() 151 | { 152 | return s; 153 | } 154 | 155 | private: 156 | SDL_RWops *ops; 157 | SDLRWBuf<> buf; 158 | std::istream s; 159 | }; 160 | 161 | #endif // SDLUTIL_H 162 | -------------------------------------------------------------------------------- /binding-mruby/window-binding.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** window-binding.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "window.h" 23 | #include "disposable-binding.h" 24 | #include "viewportelement-binding.h" 25 | #include "binding-util.h" 26 | 27 | DEF_TYPE(Window); 28 | 29 | MRB_METHOD(windowInitialize) 30 | { 31 | Window *w = viewportElementInitialize(mrb, self); 32 | 33 | setPrivateData(self, w, WindowType); 34 | 35 | w->initDynAttribs(); 36 | wrapProperty(mrb, self, &w->getCursorRect(), CScursor_rect, RectType); 37 | 38 | return self; 39 | } 40 | 41 | MRB_METHOD(windowUpdate) 42 | { 43 | Window *w = getPrivateData(mrb, self); 44 | 45 | w->update(); 46 | 47 | return mrb_nil_value(); 48 | } 49 | 50 | DEF_PROP_OBJ_REF(Window, Bitmap, Windowskin, CSwindowskin) 51 | DEF_PROP_OBJ_REF(Window, Bitmap, Contents, CScontents) 52 | DEF_PROP_OBJ_VAL(Window, Rect, CursorRect, CScursor_rect) 53 | 54 | DEF_PROP_B(Window, Stretch) 55 | DEF_PROP_B(Window, Active) 56 | DEF_PROP_B(Window, Pause) 57 | 58 | DEF_PROP_I(Window, X) 59 | DEF_PROP_I(Window, Y) 60 | DEF_PROP_I(Window, Width) 61 | DEF_PROP_I(Window, Height) 62 | DEF_PROP_I(Window, OX) 63 | DEF_PROP_I(Window, OY) 64 | DEF_PROP_I(Window, Opacity) 65 | DEF_PROP_I(Window, BackOpacity) 66 | DEF_PROP_I(Window, ContentsOpacity) 67 | 68 | 69 | void 70 | windowBindingInit(mrb_state *mrb) 71 | { 72 | RClass *klass = defineClass(mrb, "Window"); 73 | 74 | disposableBindingInit (mrb, klass); 75 | viewportElementBindingInit(mrb, klass); 76 | 77 | mrb_define_method(mrb, klass, "initialize", windowInitialize, MRB_ARGS_REQ(1)); 78 | mrb_define_method(mrb, klass, "update", windowUpdate, MRB_ARGS_NONE()); 79 | 80 | INIT_PROP_BIND( Window, Windowskin, "windowskin" ); 81 | INIT_PROP_BIND( Window, Contents, "contents" ); 82 | INIT_PROP_BIND( Window, Stretch, "stretch" ); 83 | INIT_PROP_BIND( Window, CursorRect, "cursor_rect" ); 84 | INIT_PROP_BIND( Window, Active, "active" ); 85 | INIT_PROP_BIND( Window, Pause, "pause" ); 86 | INIT_PROP_BIND( Window, X, "x" ); 87 | INIT_PROP_BIND( Window, Y, "y" ); 88 | INIT_PROP_BIND( Window, Width, "width" ); 89 | INIT_PROP_BIND( Window, Height, "height" ); 90 | INIT_PROP_BIND( Window, OX, "ox" ); 91 | INIT_PROP_BIND( Window, OY, "oy" ); 92 | INIT_PROP_BIND( Window, Opacity, "opacity" ); 93 | INIT_PROP_BIND( Window, BackOpacity, "back_opacity" ); 94 | INIT_PROP_BIND( Window, ContentsOpacity, "contents_opacity" ); 95 | 96 | mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE()); 97 | } 98 | -------------------------------------------------------------------------------- /binding-mri/window-binding.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** window-binding.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "window.h" 23 | #include "disposable-binding.h" 24 | #include "viewportelement-binding.h" 25 | #include "binding-util.h" 26 | 27 | DEF_TYPE(Window); 28 | 29 | RB_METHOD(windowInitialize) 30 | { 31 | Window *w = viewportElementInitialize(argc, argv, self); 32 | 33 | setPrivateData(self, w); 34 | 35 | w->initDynAttribs(); 36 | 37 | wrapProperty(self, &w->getCursorRect(), "cursor_rect", RectType); 38 | 39 | return self; 40 | } 41 | 42 | RB_METHOD(windowUpdate) 43 | { 44 | RB_UNUSED_PARAM; 45 | 46 | Window *w = getPrivateData(self); 47 | 48 | w->update(); 49 | 50 | return Qnil; 51 | } 52 | 53 | DEF_PROP_OBJ_REF(Window, Bitmap, Windowskin, "windowskin") 54 | DEF_PROP_OBJ_REF(Window, Bitmap, Contents, "contents") 55 | DEF_PROP_OBJ_VAL(Window, Rect, CursorRect, "cursor_rect") 56 | 57 | DEF_PROP_B(Window, Stretch) 58 | DEF_PROP_B(Window, Active) 59 | DEF_PROP_B(Window, Pause) 60 | 61 | DEF_PROP_I(Window, X) 62 | DEF_PROP_I(Window, Y) 63 | DEF_PROP_I(Window, Width) 64 | DEF_PROP_I(Window, Height) 65 | DEF_PROP_I(Window, OX) 66 | DEF_PROP_I(Window, OY) 67 | DEF_PROP_I(Window, Opacity) 68 | DEF_PROP_I(Window, BackOpacity) 69 | DEF_PROP_I(Window, ContentsOpacity) 70 | 71 | 72 | void 73 | windowBindingInit() 74 | { 75 | VALUE klass = rb_define_class("Window", rb_cObject); 76 | rb_define_alloc_func(klass, classAllocate<&WindowType>); 77 | 78 | disposableBindingInit (klass); 79 | viewportElementBindingInit(klass); 80 | 81 | _rb_define_method(klass, "initialize", windowInitialize); 82 | _rb_define_method(klass, "update", windowUpdate); 83 | 84 | INIT_PROP_BIND( Window, Windowskin, "windowskin" ); 85 | INIT_PROP_BIND( Window, Contents, "contents" ); 86 | INIT_PROP_BIND( Window, Stretch, "stretch" ); 87 | INIT_PROP_BIND( Window, CursorRect, "cursor_rect" ); 88 | INIT_PROP_BIND( Window, Active, "active" ); 89 | INIT_PROP_BIND( Window, Pause, "pause" ); 90 | INIT_PROP_BIND( Window, X, "x" ); 91 | INIT_PROP_BIND( Window, Y, "y" ); 92 | INIT_PROP_BIND( Window, Width, "width" ); 93 | INIT_PROP_BIND( Window, Height, "height" ); 94 | INIT_PROP_BIND( Window, OX, "ox" ); 95 | INIT_PROP_BIND( Window, OY, "oy" ); 96 | INIT_PROP_BIND( Window, Opacity, "opacity" ); 97 | INIT_PROP_BIND( Window, BackOpacity, "back_opacity" ); 98 | INIT_PROP_BIND( Window, ContentsOpacity, "contents_opacity" ); 99 | } 100 | -------------------------------------------------------------------------------- /binding-mruby/disposable-binding.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** disposable-binding.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef DISPOSABLEBINDING_H 23 | #define DISPOSABLEBINDING_H 24 | 25 | #include "disposable.h" 26 | #include "binding-util.h" 27 | 28 | #include "mruby/array.h" 29 | 30 | #include 31 | 32 | /* 'Children' are disposables that are disposed together 33 | * with their parent. Currently this is only used by Viewport 34 | * in RGSS1. 35 | * FIXME: Disable this behavior when RGSS2 or 3 */ 36 | inline void 37 | disposableAddChild(mrb_state *mrb, mrb_value disp, mrb_value child) 38 | { 39 | mrb_sym sym = getMrbData(mrb)->symbols[CSchildren]; 40 | mrb_value children = mrb_iv_get(mrb, disp, sym); 41 | 42 | if (mrb_nil_p(children)) 43 | { 44 | children = mrb_ary_new(mrb); 45 | mrb_iv_set(mrb, disp, sym, children); 46 | } 47 | 48 | /* Assumes children are never removed until destruction */ 49 | mrb_ary_push(mrb, children, child); 50 | } 51 | 52 | inline void 53 | disposableDisposeChildren(mrb_state *mrb, mrb_value disp) 54 | { 55 | MrbData *mrbData = getMrbData(mrb); 56 | mrb_value children = mrb_iv_get(mrb, disp, mrbData->symbols[CSchildren]); 57 | 58 | if (mrb_nil_p(children)) 59 | return; 60 | 61 | for (mrb_int i = 0; i < RARRAY_LEN(children); ++i) 62 | mrb_funcall_argv(mrb, mrb_ary_entry(children, i), 63 | mrbData->symbols[CS_mkxp_dispose_alias], 0, 0); 64 | } 65 | 66 | template 67 | MRB_METHOD(disposableDispose) 68 | { 69 | C *d = static_cast(DATA_PTR(self)); 70 | 71 | if (!d) 72 | return mrb_nil_value(); 73 | 74 | if (d->isDisposed()) 75 | return mrb_nil_value(); 76 | 77 | if (rgssVer == 1) 78 | disposableDisposeChildren(mrb, self); 79 | 80 | d->dispose(); 81 | 82 | return mrb_nil_value(); 83 | } 84 | 85 | template 86 | MRB_METHOD(disposableIsDisposed) 87 | { 88 | MRB_UNUSED_PARAM; 89 | 90 | C *d = static_cast(DATA_PTR(self)); 91 | 92 | if (!d) 93 | return mrb_true_value(); 94 | 95 | return mrb_bool_value(d->isDisposed()); 96 | } 97 | 98 | template 99 | static void disposableBindingInit(mrb_state *mrb, RClass *klass) 100 | { 101 | mrb_define_method(mrb, klass, "dispose", disposableDispose, MRB_ARGS_NONE()); 102 | mrb_define_method(mrb, klass, "disposed?", disposableIsDisposed, MRB_ARGS_NONE()); 103 | 104 | if (rgssVer == 1) 105 | mrb_alias_method(mrb, klass, getMrbData(mrb)->symbols[CS_mkxp_dispose_alias], 106 | mrb_intern_lit(mrb, "dispose")); 107 | } 108 | 109 | template 110 | inline void 111 | checkDisposed(mrb_state *mrb, mrb_value self) 112 | { 113 | if (mrb_test(disposableIsDisposed(0, self))) 114 | raiseDisposedAccess(mrb, self); 115 | } 116 | 117 | #endif // DISPOSABLEBINDING_H 118 | -------------------------------------------------------------------------------- /src/quad.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** quad.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef QUAD_H 23 | #define QUAD_H 24 | 25 | #include "vertex.h" 26 | #include "gl-util.h" 27 | #include "gl-meta.h" 28 | #include "sharedstate.h" 29 | #include "global-ibo.h" 30 | #include "shader.h" 31 | 32 | struct Quad 33 | { 34 | Vertex vert[4]; 35 | VBO::ID vbo; 36 | GLMeta::VAO vao; 37 | bool vboDirty; 38 | 39 | template 40 | static void setPosRect(V *vert, const FloatRect &r) 41 | { 42 | int i = 0; 43 | vert[i++].pos = r.topLeft(); 44 | vert[i++].pos = r.topRight(); 45 | vert[i++].pos = r.bottomRight(); 46 | vert[i++].pos = r.bottomLeft(); 47 | } 48 | 49 | template 50 | static void setTexRect(V *vert, const FloatRect &r) 51 | { 52 | int i = 0; 53 | vert[i++].texPos = r.topLeft(); 54 | vert[i++].texPos = r.topRight(); 55 | vert[i++].texPos = r.bottomRight(); 56 | vert[i++].texPos = r.bottomLeft(); 57 | } 58 | 59 | template 60 | static int setTexPosRect(V *vert, const FloatRect &tex, const FloatRect &pos) 61 | { 62 | setPosRect(vert, pos); 63 | setTexRect(vert, tex); 64 | 65 | return 1; 66 | } 67 | 68 | template 69 | static void setColor(V *vert, const Vec4 &c) 70 | { 71 | for (int i = 0; i < 4; ++i) 72 | vert[i].color = c; 73 | } 74 | 75 | Quad() 76 | : vbo(VBO::gen()), 77 | vboDirty(true) 78 | { 79 | GLMeta::vaoFillInVertexData(vao); 80 | vao.vbo = vbo; 81 | vao.ibo = shState->globalIBO().ibo; 82 | 83 | GLMeta::vaoInit(vao, true); 84 | VBO::allocEmpty(sizeof(Vertex[4]), GL_DYNAMIC_DRAW); 85 | GLMeta::vaoUnbind(vao); 86 | 87 | setColor(Vec4(1, 1, 1, 1)); 88 | } 89 | 90 | ~Quad() 91 | { 92 | GLMeta::vaoFini(vao); 93 | VBO::del(vbo); 94 | } 95 | 96 | void updateBuffer() 97 | { 98 | VBO::bind(vbo); 99 | VBO::uploadSubData(0, sizeof(Vertex[4]), vert); 100 | VBO::unbind(); 101 | } 102 | 103 | void setPosRect(const FloatRect &r) 104 | { 105 | setPosRect(vert, r); 106 | vboDirty = true; 107 | } 108 | 109 | void setTexRect(const FloatRect &r) 110 | { 111 | setTexRect(vert, r); 112 | vboDirty = true; 113 | } 114 | 115 | void setTexPosRect(const FloatRect &tex, const FloatRect &pos) 116 | { 117 | setTexPosRect(vert, tex, pos); 118 | vboDirty = true; 119 | } 120 | 121 | void setColor(const Vec4 &c) 122 | { 123 | for (int i = 0; i < 4; ++i) 124 | vert[i].color = c; 125 | 126 | vboDirty = true; 127 | } 128 | 129 | void draw() 130 | { 131 | if (vboDirty) 132 | { 133 | updateBuffer(); 134 | vboDirty = false; 135 | } 136 | 137 | GLMeta::vaoBind(vao); 138 | gl.DrawElements(GL_TRIANGLES, 6, _GL_INDEX_TYPE, 0); 139 | GLMeta::vaoUnbind(vao); 140 | } 141 | }; 142 | 143 | #endif // QUAD_H 144 | -------------------------------------------------------------------------------- /src/sdlsoundsource.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** sdlsoundsource.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2014 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "aldatasource.h" 23 | #include "exception.h" 24 | 25 | #include 26 | 27 | struct SDLSoundSource : ALDataSource 28 | { 29 | Sound_Sample *sample; 30 | SDL_RWops &srcOps; 31 | uint8_t sampleSize; 32 | bool looped; 33 | 34 | ALenum alFormat; 35 | ALsizei alFreq; 36 | 37 | SDLSoundSource(SDL_RWops &ops, 38 | const char *extension, 39 | uint32_t maxBufSize, 40 | bool looped) 41 | : srcOps(ops), 42 | looped(looped) 43 | { 44 | sample = Sound_NewSample(&srcOps, extension, 0, maxBufSize); 45 | 46 | if (!sample) 47 | { 48 | SDL_RWclose(&ops); 49 | throw Exception(Exception::SDLError, "SDL_sound: %s", Sound_GetError()); 50 | } 51 | 52 | sampleSize = formatSampleSize(sample->actual.format); 53 | 54 | alFormat = chooseALFormat(sampleSize, sample->actual.channels); 55 | alFreq = sample->actual.rate; 56 | } 57 | 58 | ~SDLSoundSource() 59 | { 60 | /* This also closes 'srcOps' */ 61 | Sound_FreeSample(sample); 62 | } 63 | 64 | Status fillBuffer(AL::Buffer::ID alBuffer) 65 | { 66 | uint32_t decoded = Sound_Decode(sample); 67 | 68 | if (sample->flags & SOUND_SAMPLEFLAG_EAGAIN) 69 | { 70 | /* Try to decode one more time on EAGAIN */ 71 | decoded = Sound_Decode(sample); 72 | 73 | /* Give up */ 74 | if (sample->flags & SOUND_SAMPLEFLAG_EAGAIN) 75 | return ALDataSource::Error; 76 | } 77 | 78 | if (sample->flags & SOUND_SAMPLEFLAG_ERROR) 79 | return ALDataSource::Error; 80 | 81 | AL::Buffer::uploadData(alBuffer, alFormat, sample->buffer, decoded, alFreq); 82 | 83 | if (sample->flags & SOUND_SAMPLEFLAG_EOF) 84 | { 85 | if (looped) 86 | { 87 | Sound_Rewind(sample); 88 | return ALDataSource::WrapAround; 89 | } 90 | else 91 | { 92 | return ALDataSource::EndOfStream; 93 | } 94 | } 95 | 96 | return ALDataSource::NoError; 97 | } 98 | 99 | int sampleRate() 100 | { 101 | return sample->actual.rate; 102 | } 103 | 104 | void seekToOffset(float seconds) 105 | { 106 | if (seconds <= 0) 107 | Sound_Rewind(sample); 108 | else 109 | Sound_Seek(sample, static_cast(seconds * 1000)); 110 | } 111 | 112 | uint32_t loopStartFrames() 113 | { 114 | /* Loops from the beginning of the file */ 115 | return 0; 116 | } 117 | 118 | bool setPitch(float) 119 | { 120 | return false; 121 | } 122 | }; 123 | 124 | ALDataSource *createSDLSource(SDL_RWops &ops, 125 | const char *extension, 126 | uint32_t maxBufSize, 127 | bool looped) 128 | { 129 | return new SDLSoundSource(ops, extension, maxBufSize, looped); 130 | } 131 | -------------------------------------------------------------------------------- /src/sharedstate.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** sharedstate.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef SHAREDSTATE_H 23 | #define SHAREDSTATE_H 24 | 25 | #include 26 | 27 | #define shState SharedState::instance 28 | #define glState shState->_glState() 29 | #define rgssVer SharedState::rgssVersion 30 | 31 | struct SharedStatePrivate; 32 | struct RGSSThreadData; 33 | struct GlobalIBO; 34 | struct SDL_Window; 35 | struct TEXFBO; 36 | struct Quad; 37 | struct ShaderSet; 38 | 39 | class Scene; 40 | class FileSystem; 41 | class EventThread; 42 | class Graphics; 43 | class Input; 44 | class Audio; 45 | class GLState; 46 | class TexPool; 47 | class Font; 48 | class SharedFontState; 49 | struct GlobalIBO; 50 | struct Config; 51 | struct Vec2i; 52 | struct SharedMidiState; 53 | 54 | struct SharedState 55 | { 56 | void *bindingData() const; 57 | void setBindingData(void *data); 58 | 59 | SDL_Window *sdlWindow() const; 60 | 61 | Scene *screen() const; 62 | void setScreen(Scene &screen); 63 | 64 | FileSystem &fileSystem() const; 65 | 66 | EventThread &eThread() const; 67 | RGSSThreadData &rtData() const; 68 | Config &config() const; 69 | 70 | Graphics &graphics() const; 71 | Input &input() const; 72 | Audio &audio() const; 73 | 74 | GLState &_glState() const; 75 | 76 | ShaderSet &shaders() const; 77 | 78 | TexPool &texPool() const; 79 | 80 | SharedFontState &fontState() const; 81 | Font &defaultFont() const; 82 | 83 | SharedMidiState &midiState() const; 84 | 85 | sigc::signal prepareDraw; 86 | 87 | unsigned int genTimeStamp(); 88 | 89 | /* Returns global quad IBO, and ensures it has indices 90 | * for at least minSize quads */ 91 | void ensureQuadIBO(size_t minSize); 92 | GlobalIBO &globalIBO(); 93 | 94 | /* Global general purpose texture */ 95 | void bindTex(); 96 | void ensureTexSize(int minW, int minH, Vec2i ¤tSizeOut); 97 | 98 | TEXFBO &gpTexFBO(int minW, int minH); 99 | 100 | Quad &gpQuad() const; 101 | 102 | /* Basically just a simple "TexPool" 103 | * replacement for Tilemap atlas use */ 104 | void requestAtlasTex(int w, int h, TEXFBO &out); 105 | void releaseAtlasTex(TEXFBO &tex); 106 | 107 | /* Checks EventThread's shutdown request flag and if set, 108 | * requests the binding to terminate. In this case, this 109 | * function will most likely not return */ 110 | void checkShutdown(); 111 | 112 | void checkReset(); 113 | 114 | static SharedState *instance; 115 | static int rgssVersion; 116 | 117 | /* This function will throw an Exception instance 118 | * on initialization error */ 119 | static void initInstance(RGSSThreadData *threadData); 120 | static void finiInstance(); 121 | 122 | private: 123 | SharedState(RGSSThreadData *threadData); 124 | ~SharedState(); 125 | 126 | SharedStatePrivate *p; 127 | }; 128 | 129 | #endif // SHAREDSTATE_H 130 | -------------------------------------------------------------------------------- /src/glstate.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** glstate.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "glstate.h" 23 | #include "shader.h" 24 | #include "etc.h" 25 | #include "gl-fun.h" 26 | #include "config.h" 27 | 28 | #include 29 | 30 | static void applyBool(GLenum state, bool mode) 31 | { 32 | mode ? gl.Enable(state) : gl.Disable(state); 33 | } 34 | 35 | void GLClearColor::apply(const Vec4 &value) 36 | { 37 | gl.ClearColor(value.x, value.y, value.z, value.w); 38 | } 39 | 40 | void GLScissorBox::apply(const IntRect &value) 41 | { 42 | gl.Scissor(value.x, value.y, value.w, value.h); 43 | } 44 | 45 | void GLScissorBox::setIntersect(const IntRect &value) 46 | { 47 | const IntRect ¤t = get(); 48 | 49 | SDL_Rect r1 = { current.x, current.y, current.w, current.h }; 50 | SDL_Rect r2 = { value.x, value.y, value.w, value.h }; 51 | 52 | SDL_Rect result; 53 | if (!SDL_IntersectRect(&r1, &r2, &result)) 54 | result.w = result.h = 0; 55 | 56 | set(IntRect(result.x, result.y, result.w, result.h)); 57 | } 58 | 59 | void GLScissorTest::apply(const bool &value) 60 | { 61 | applyBool(GL_SCISSOR_TEST, value); 62 | } 63 | 64 | void GLBlendMode::apply(const BlendType &value) 65 | { 66 | switch (value) 67 | { 68 | case BlendKeepDestAlpha : 69 | gl.BlendEquation(GL_FUNC_ADD); 70 | gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 71 | GL_ZERO, GL_ONE); 72 | break; 73 | 74 | case BlendNormal : 75 | gl.BlendEquation(GL_FUNC_ADD); 76 | gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 77 | GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 78 | break; 79 | 80 | case BlendAddition : 81 | gl.BlendEquation(GL_FUNC_ADD); 82 | gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, 83 | GL_ONE, GL_ONE); 84 | break; 85 | 86 | case BlendSubstraction : 87 | gl.BlendEquation(GL_FUNC_REVERSE_SUBTRACT); 88 | gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, 89 | GL_ZERO, GL_ONE); 90 | break; 91 | } 92 | } 93 | 94 | void GLBlend::apply(const bool &value) 95 | { 96 | applyBool(GL_BLEND, value); 97 | } 98 | 99 | void GLViewport::apply(const IntRect &value) 100 | { 101 | gl.Viewport(value.x, value.y, value.w, value.h); 102 | } 103 | 104 | void GLProgram::apply(const unsigned int &value) 105 | { 106 | gl.UseProgram(value); 107 | } 108 | 109 | GLState::Caps::Caps() 110 | { 111 | gl.GetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize); 112 | } 113 | 114 | GLState::GLState(const Config &conf) 115 | { 116 | gl.Disable(GL_DEPTH_TEST); 117 | 118 | clearColor.init(Vec4(0, 0, 0, 1)); 119 | blendMode.init(BlendNormal); 120 | blend.init(true); 121 | scissorTest.init(false); 122 | scissorBox.init(IntRect()); 123 | program.init(0); 124 | 125 | if (conf.maxTextureSize > 0) 126 | caps.maxTexSize = conf.maxTextureSize; 127 | } 128 | -------------------------------------------------------------------------------- /src/table.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** table.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "table.h" 23 | 24 | #include 25 | #include 26 | 27 | #include "serial-util.h" 28 | #include "exception.h" 29 | #include "util.h" 30 | 31 | /* Init normally */ 32 | Table::Table(int x, int y /*= 1*/, int z /*= 1*/) 33 | : xs(x), ys(y), zs(z), 34 | data(x*y*z) 35 | {} 36 | 37 | Table::Table(const Table &other) 38 | : xs(other.xs), ys(other.ys), zs(other.zs), 39 | data(other.data) 40 | {} 41 | 42 | int16_t Table::get(int x, int y, int z) const 43 | { 44 | return data[xs*ys*z + xs*y + x]; 45 | } 46 | 47 | void Table::set(int16_t value, int x, int y, int z) 48 | { 49 | if (x < 0 || x >= xs 50 | || y < 0 || y >= ys 51 | || z < 0 || z >= zs) 52 | { 53 | return; 54 | } 55 | 56 | data[xs*ys*z + xs*y + x] = value; 57 | 58 | modified(); 59 | } 60 | 61 | void Table::resize(int x, int y, int z) 62 | { 63 | if (x == xs && y == ys && z == zs) 64 | return; 65 | 66 | std::vector newData(x*y*z); 67 | 68 | for (int k = 0; k < std::min(z, zs); ++k) 69 | for (int j = 0; j < std::min(y, ys); ++j) 70 | for (int i = 0; i < std::min(x, xs); ++i) 71 | newData[x*y*k + x*j + i] = at(i, j, k); 72 | 73 | data.swap(newData); 74 | 75 | xs = x; 76 | ys = y; 77 | zs = z; 78 | 79 | return; 80 | } 81 | 82 | void Table::resize(int x, int y) 83 | { 84 | resize(x, y, zs); 85 | } 86 | 87 | void Table::resize(int x) 88 | { 89 | resize(x, ys, zs); 90 | } 91 | 92 | /* Serializable */ 93 | int Table::serialSize() const 94 | { 95 | /* header + data */ 96 | return 20 + (xs * ys * zs) * 2; 97 | } 98 | 99 | void Table::serialize(char *buffer) const 100 | { 101 | /* Table dimensions: we don't care 102 | * about them but RMXP needs them */ 103 | int dim = 1; 104 | int size = xs * ys * zs; 105 | 106 | if (ys > 1) 107 | dim = 2; 108 | 109 | if (zs > 1) 110 | dim = 3; 111 | 112 | writeInt32(&buffer, dim); 113 | writeInt32(&buffer, xs); 114 | writeInt32(&buffer, ys); 115 | writeInt32(&buffer, zs); 116 | writeInt32(&buffer, size); 117 | 118 | memcpy(buffer, dataPtr(data), sizeof(int16_t)*size); 119 | } 120 | 121 | 122 | Table *Table::deserialize(const char *data, int len) 123 | { 124 | if (len < 20) 125 | throw Exception(Exception::RGSSError, "Marshal: Table: bad file format"); 126 | 127 | readInt32(&data); 128 | int x = readInt32(&data); 129 | int y = readInt32(&data); 130 | int z = readInt32(&data); 131 | int size = readInt32(&data); 132 | 133 | if (size != x*y*z) 134 | throw Exception(Exception::RGSSError, "Marshal: Table: bad file format"); 135 | 136 | if (len != 20 + x*y*z*2) 137 | throw Exception(Exception::RGSSError, "Marshal: Table: bad file format"); 138 | 139 | Table *t = new Table(x, y, z); 140 | memcpy(dataPtr(t->data), data, sizeof(int16_t)*size); 141 | 142 | return t; 143 | } 144 | -------------------------------------------------------------------------------- /binding-mruby/graphics-binding.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** graphics-binding.cpp 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #include "graphics.h" 23 | #include "sharedstate.h" 24 | #include "binding-util.h" 25 | #include "exception.h" 26 | 27 | MRB_FUNCTION(graphicsUpdate) 28 | { 29 | MRB_FUN_UNUSED_PARAM; 30 | 31 | shState->graphics().update(); 32 | 33 | return mrb_nil_value(); 34 | } 35 | 36 | MRB_FUNCTION(graphicsFreeze) 37 | { 38 | MRB_FUN_UNUSED_PARAM; 39 | 40 | shState->graphics().freeze(); 41 | 42 | return mrb_nil_value(); 43 | } 44 | 45 | MRB_FUNCTION(graphicsTransition) 46 | { 47 | mrb_int duration = 8; 48 | const char *filename = ""; 49 | mrb_int vague = 40; 50 | 51 | mrb_get_args(mrb, "|izi", &duration, &filename, &vague); 52 | 53 | GUARD_EXC( shState->graphics().transition(duration, filename, vague); ) 54 | 55 | return mrb_nil_value(); 56 | } 57 | 58 | MRB_FUNCTION(graphicsFrameReset) 59 | { 60 | MRB_FUN_UNUSED_PARAM; 61 | 62 | shState->graphics().frameReset(); 63 | 64 | return mrb_nil_value(); 65 | } 66 | 67 | #define DEF_GRA_PROP_I(PropName) \ 68 | MRB_FUNCTION(graphics##Get##PropName) \ 69 | { \ 70 | MRB_FUN_UNUSED_PARAM; \ 71 | return mrb_fixnum_value(shState->graphics().get##PropName()); \ 72 | } \ 73 | MRB_FUNCTION(graphics##Set##PropName) \ 74 | { \ 75 | mrb_int value; \ 76 | mrb_get_args(mrb, "i", &value); \ 77 | shState->graphics().set##PropName(value); \ 78 | return mrb_fixnum_value(value); \ 79 | } 80 | 81 | #define DEF_GRA_PROP_B(PropName) \ 82 | MRB_FUNCTION(graphics##Get##PropName) \ 83 | { \ 84 | MRB_FUN_UNUSED_PARAM; \ 85 | return mrb_bool_value(shState->graphics().get##PropName()); \ 86 | } \ 87 | MRB_FUNCTION(graphics##Set##PropName) \ 88 | { \ 89 | mrb_bool value; \ 90 | mrb_get_args(mrb, "b", &value); \ 91 | shState->graphics().set##PropName(value); \ 92 | return mrb_bool_value(value); \ 93 | } 94 | 95 | DEF_GRA_PROP_I(FrameRate) 96 | DEF_GRA_PROP_I(FrameCount) 97 | 98 | DEF_GRA_PROP_B(Fullscreen) 99 | DEF_GRA_PROP_B(ShowCursor) 100 | 101 | #define INIT_GRA_PROP_BIND(PropName, prop_name_s) \ 102 | { \ 103 | mrb_define_module_function(mrb, module, prop_name_s, graphics##Get##PropName, MRB_ARGS_NONE()); \ 104 | mrb_define_module_function(mrb, module, prop_name_s "=", graphics##Set##PropName, MRB_ARGS_REQ(1)); \ 105 | } 106 | 107 | void graphicsBindingInit(mrb_state *mrb) 108 | { 109 | RClass *module = mrb_define_module(mrb, "Graphics"); 110 | 111 | mrb_define_module_function(mrb, module, "update", graphicsUpdate, MRB_ARGS_NONE()); 112 | mrb_define_module_function(mrb, module, "freeze", graphicsFreeze, MRB_ARGS_NONE()); 113 | mrb_define_module_function(mrb, module, "transition", graphicsTransition, MRB_ARGS_OPT(3)); 114 | mrb_define_module_function(mrb, module, "frame_reset", graphicsFrameReset, MRB_ARGS_NONE()); 115 | 116 | INIT_GRA_PROP_BIND( FrameRate, "frame_rate" ); 117 | INIT_GRA_PROP_BIND( FrameCount, "frame_count" ); 118 | 119 | INIT_GRA_PROP_BIND( Fullscreen, "fullscreen" ); 120 | INIT_GRA_PROP_BIND( ShowCursor, "show_cursor" ); 121 | } 122 | -------------------------------------------------------------------------------- /src/font.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** font.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef FONT_H 23 | #define FONT_H 24 | 25 | #include "etc.h" 26 | #include "util.h" 27 | 28 | #include 29 | #include 30 | 31 | struct SDL_RWops; 32 | struct _TTF_Font; 33 | struct Config; 34 | 35 | struct SharedFontStatePrivate; 36 | 37 | class SharedFontState 38 | { 39 | public: 40 | SharedFontState(const Config &conf); 41 | ~SharedFontState(); 42 | 43 | /* Called from FileSystem during font cache initialization 44 | * (when "Fonts/" is scanned for available assets). 45 | * 'ops' is an opened handle to a possible font file, 46 | * 'filename' is the corresponding path */ 47 | void initFontSetCB(SDL_RWops &ops, 48 | const std::string &filename); 49 | 50 | _TTF_Font *getFont(std::string family, 51 | int size); 52 | 53 | bool fontPresent(std::string family) const; 54 | 55 | static _TTF_Font *openBundled(int size); 56 | 57 | void setDefaultFontFamily(const std::string &family); 58 | 59 | private: 60 | SharedFontStatePrivate *p; 61 | }; 62 | 63 | struct FontPrivate; 64 | 65 | class Font 66 | { 67 | public: 68 | static bool doesExist(const char *name); 69 | 70 | Font(const std::vector *names = 0, 71 | int size = 0); 72 | 73 | /* Clone constructor */ 74 | Font(const Font &other); 75 | 76 | ~Font(); 77 | 78 | const Font &operator=(const Font &o); 79 | 80 | DECL_ATTR( Size, int ) 81 | DECL_ATTR( Bold, bool ) 82 | DECL_ATTR( Italic, bool ) 83 | DECL_ATTR( Color, Color& ) 84 | DECL_ATTR( Shadow, bool ) 85 | DECL_ATTR( Outline, bool ) 86 | DECL_ATTR( OutColor, Color& ) 87 | 88 | DECL_ATTR_STATIC( DefaultSize, int ) 89 | DECL_ATTR_STATIC( DefaultBold, bool ) 90 | DECL_ATTR_STATIC( DefaultItalic, bool ) 91 | DECL_ATTR_STATIC( DefaultColor, Color& ) 92 | DECL_ATTR_STATIC( DefaultShadow, bool ) 93 | DECL_ATTR_STATIC( DefaultOutline, bool ) 94 | DECL_ATTR_STATIC( DefaultOutColor, Color& ) 95 | 96 | /* There is no point in providing getters for these, 97 | * as the bindings will always return the stored native 98 | * string/array object anyway. It's impossible to mirror 99 | * in the C++ core. 100 | * The core object picks the first existing name from the 101 | * passed array and stores it internally (same for default). */ 102 | void setName(const std::vector &names); 103 | static void setDefaultName(const std::vector &names, 104 | const SharedFontState &sfs); 105 | 106 | static const std::vector &getInitialDefaultNames(); 107 | 108 | /* Assigns heap allocated objects to object properties; 109 | * using this in pure C++ will cause memory leaks 110 | * (ie. only to be used in GCed language bindings) */ 111 | void initDynAttribs(); 112 | static void initDefaultDynAttribs(); 113 | 114 | static void initDefaults(const SharedFontState &sfs); 115 | 116 | /* internal */ 117 | _TTF_Font *getSdlFont(); 118 | 119 | private: 120 | FontPrivate *p; 121 | }; 122 | 123 | #endif // FONT_H 124 | -------------------------------------------------------------------------------- /src/sharedmidistate.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** sharedmidistate.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2014 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef SHAREDMIDISTATE_H 23 | #define SHAREDMIDISTATE_H 24 | 25 | #include "config.h" 26 | #include "debugwriter.h" 27 | #include "fluid-fun.h" 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #define SYNTH_INIT_COUNT 2 34 | #define SYNTH_SAMPLERATE 44100 35 | 36 | struct Synth 37 | { 38 | fluid_synth_t *synth; 39 | bool inUse; 40 | }; 41 | 42 | struct SharedMidiState 43 | { 44 | bool inited; 45 | std::vector synths; 46 | const std::string &soundFont; 47 | fluid_settings_t *flSettings; 48 | 49 | SharedMidiState(const Config &conf) 50 | : inited(false), 51 | soundFont(conf.midi.soundFont) 52 | {} 53 | 54 | ~SharedMidiState() 55 | { 56 | /* We might have initialized, but if the consecutive libfluidsynth 57 | * load failed, no resources will have been allocated */ 58 | if (!inited || !HAVE_FLUID) 59 | return; 60 | 61 | fluid.delete_settings(flSettings); 62 | 63 | for (size_t i = 0; i < synths.size(); ++i) 64 | { 65 | assert(!synths[i].inUse); 66 | fluid.delete_synth(synths[i].synth); 67 | } 68 | } 69 | 70 | void initIfNeeded(const Config &conf) 71 | { 72 | if (inited) 73 | return; 74 | 75 | inited = true; 76 | 77 | initFluidFunctions(); 78 | 79 | if (!HAVE_FLUID) 80 | return; 81 | 82 | flSettings = fluid.new_settings(); 83 | fluid.settings_setnum(flSettings, "synth.gain", 1.0f); 84 | fluid.settings_setnum(flSettings, "synth.sample-rate", SYNTH_SAMPLERATE); 85 | fluid.settings_setstr(flSettings, "synth.chorus.active", conf.midi.chorus ? "yes" : "no"); 86 | fluid.settings_setstr(flSettings, "synth.reverb.active", conf.midi.reverb ? "yes" : "no"); 87 | 88 | for (size_t i = 0; i < SYNTH_INIT_COUNT; ++i) 89 | addSynth(false); 90 | } 91 | 92 | fluid_synth_t *allocateSynth() 93 | { 94 | assert(HAVE_FLUID); 95 | assert(inited); 96 | 97 | size_t i; 98 | 99 | for (i = 0; i < synths.size(); ++i) 100 | if (!synths[i].inUse) 101 | break; 102 | 103 | if (i < synths.size()) 104 | { 105 | fluid_synth_t *syn = synths[i].synth; 106 | fluid.synth_system_reset(syn); 107 | synths[i].inUse = true; 108 | 109 | return syn; 110 | } 111 | else 112 | { 113 | return addSynth(true); 114 | } 115 | } 116 | 117 | void releaseSynth(fluid_synth_t *synth) 118 | { 119 | size_t i; 120 | 121 | for (i = 0; i < synths.size(); ++i) 122 | if (synths[i].synth == synth) 123 | break; 124 | 125 | assert(i < synths.size()); 126 | 127 | synths[i].inUse = false; 128 | } 129 | 130 | private: 131 | fluid_synth_t *addSynth(bool usedNow) 132 | { 133 | fluid_synth_t *syn = fluid.new_synth(flSettings); 134 | 135 | if (!soundFont.empty()) 136 | fluid.synth_sfload(syn, soundFont.c_str(), 1); 137 | else 138 | Debug() << "Warning: No soundfont specified, sound might be mute"; 139 | 140 | Synth synth; 141 | synth.inUse = usedNow; 142 | synth.synth = syn; 143 | synths.push_back(synth); 144 | 145 | return syn; 146 | } 147 | }; 148 | 149 | #endif // SHAREDMIDISTATE_H 150 | -------------------------------------------------------------------------------- /src/bitmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** bitmap.h 3 | ** 4 | ** This file is part of mkxp. 5 | ** 6 | ** Copyright (C) 2013 - 2021 Amaryllis Kulla 7 | ** 8 | ** mkxp is free software: you can redistribute it and/or modify 9 | ** it under the terms of the GNU General Public License as published by 10 | ** the Free Software Foundation, either version 2 of the License, or 11 | ** (at your option) any later version. 12 | ** 13 | ** mkxp is distributed in the hope that it will be useful, 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ** GNU General Public License for more details. 17 | ** 18 | ** You should have received a copy of the GNU General Public License 19 | ** along with mkxp. If not, see . 20 | */ 21 | 22 | #ifndef BITMAP_H 23 | #define BITMAP_H 24 | 25 | #include "disposable.h" 26 | #include "etc-internal.h" 27 | #include "etc.h" 28 | 29 | #include 30 | 31 | class Font; 32 | class ShaderBase; 33 | struct TEXFBO; 34 | struct SDL_Surface; 35 | 36 | struct BitmapPrivate; 37 | // FIXME make this class use proper RGSS classes again 38 | class Bitmap : public Disposable 39 | { 40 | public: 41 | Bitmap(const char *filename); 42 | Bitmap(int width, int height); 43 | /* Clone constructor */ 44 | Bitmap(const Bitmap &other); 45 | ~Bitmap(); 46 | 47 | int width() const; 48 | int height() const; 49 | IntRect rect() const; 50 | 51 | void blt(int x, int y, 52 | const Bitmap &source, IntRect rect, 53 | int opacity = 255); 54 | 55 | void stretchBlt(const IntRect &destRect, 56 | const Bitmap &source, const IntRect &sourceRect, 57 | int opacity = 255); 58 | 59 | void fillRect(int x, int y, 60 | int width, int height, 61 | const Vec4 &color); 62 | void fillRect(const IntRect &rect, const Vec4 &color); 63 | 64 | void gradientFillRect(int x, int y, 65 | int width, int height, 66 | const Vec4 &color1, const Vec4 &color2, 67 | bool vertical = false); 68 | void gradientFillRect(const IntRect &rect, 69 | const Vec4 &color1, const Vec4 &color2, 70 | bool vertical = false); 71 | 72 | void clearRect(int x, int y, 73 | int width, int height); 74 | void clearRect(const IntRect &rect); 75 | 76 | void blur(); 77 | void radialBlur(int angle, int divisions); 78 | 79 | void clear(); 80 | 81 | Color getPixel(int x, int y) const; 82 | void setPixel(int x, int y, const Color &color); 83 | 84 | void hueChange(int hue); 85 | 86 | enum TextAlign 87 | { 88 | Left = 0, 89 | Center = 1, 90 | Right = 2 91 | }; 92 | 93 | void drawText(int x, int y, 94 | int width, int height, 95 | const char *str, int align = Left); 96 | 97 | void drawText(const IntRect &rect, 98 | const char *str, int align = Left); 99 | 100 | IntRect textSize(const char *str); 101 | 102 | DECL_ATTR(Font, Font&) 103 | 104 | /* Sets initial reference without copying by value, 105 | * use at construction */ 106 | void setInitFont(Font *value); 107 | 108 | /* extensions */ 109 | void writeToPng(const char *filename); 110 | 111 | void vFlip(); 112 | void hFlip(); 113 | 114 | /* */ 115 | TEXFBO &getGLTypes(); 116 | SDL_Surface *megaSurface() const; 117 | void ensureNonMega() const; 118 | 119 | /* Binds the backing texture and sets the correct 120 | * texture size uniform in shader */ 121 | void bindTex(ShaderBase &shader); 122 | 123 | /* Adds 'rect' to tainted area */ 124 | void taintArea(const IntRect &rect); 125 | 126 | sigc::signal modified; 127 | 128 | private: 129 | void releaseResources(); 130 | const char *klassName() const { return "bitmap"; } 131 | 132 | BitmapPrivate *p; 133 | }; 134 | 135 | #endif // BITMAP_H 136 | -------------------------------------------------------------------------------- /xxd+/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | static const char intro[] = 12 | "extern const %1 %2[] = {\n"; 13 | static const char outro[] = 14 | "\n};\nextern const %1 %2 = %3;"; 15 | 16 | int writeDump(const QString &srcFilename, 17 | const QString &dstFilename, 18 | const QString &dataType, 19 | const QString &lenType, 20 | const QString &dataSymbol, 21 | bool addNullTerm) 22 | { 23 | QFile srcFile(srcFilename); 24 | if (!srcFile.open(QFile::ReadOnly)) 25 | return 1; 26 | 27 | QFile dstFile(dstFilename); 28 | if (!dstFile.open(QFile::WriteOnly)) 29 | return 1; 30 | 31 | QByteArray srcData = srcFile.readAll(); 32 | if (addNullTerm) 33 | srcData.append('\0'); 34 | 35 | QBuffer srcBuffer(&srcData); 36 | srcBuffer.open(QBuffer::ReadOnly); 37 | 38 | QDataStream in(&srcBuffer); 39 | QTextStream out(&dstFile); 40 | 41 | QString introStr = QString(intro).arg(dataType, dataSymbol); 42 | out << introStr; 43 | 44 | const int byteColumns = 0x10; 45 | int columnInd = 0; 46 | int byteCount = 0; 47 | 48 | while (!in.atEnd()) 49 | { 50 | uchar byte; 51 | in >> byte; 52 | 53 | out << " "; 54 | if (columnInd == 0) 55 | out << " "; 56 | 57 | out << "0x"; 58 | if (byte < 0x10) 59 | out << "0"; 60 | out << QString::number(byte, 0x10); 61 | 62 | if (!in.atEnd()) 63 | out << ","; 64 | 65 | if (++columnInd == byteColumns) 66 | { 67 | out << "\n"; 68 | columnInd = 0; 69 | } 70 | 71 | ++byteCount; 72 | } 73 | 74 | if (addNullTerm) 75 | --byteCount; 76 | 77 | QString outroStr = QString(outro).arg(lenType, dataSymbol+"_len", QString::number(byteCount)); 78 | out << outroStr; 79 | 80 | return 0; 81 | } 82 | 83 | QString getNamedOption(const QStringList &args, 84 | const QString &optName, 85 | const QString &defValue) 86 | { 87 | QString value = defValue; 88 | 89 | if (args.contains(optName)) 90 | { 91 | int argInd = args.indexOf(optName); 92 | if (argInd < args.count()) 93 | value = args.at(argInd+1); 94 | } 95 | 96 | return value; 97 | } 98 | 99 | static const char usageStr[] = 100 | "Usage: %1 file [options]\n" 101 | "Options:\n" 102 | " -o [filename] Override default output filename.\n" 103 | " --symbol [sym] Override default data C symbol.\n" 104 | " --null-terminated Add null byte to data (not reflected in \"len\").\n" 105 | " --string Use char for data array. Implies \"--null-terminated\".\n" 106 | " --help Yo dawg.\n"; 107 | 108 | void usage(const QString &argv0) 109 | { 110 | QTextStream out(stdout); 111 | 112 | out << QString(usageStr).arg(argv0); 113 | } 114 | 115 | 116 | int main(int argc, char *argv[]) 117 | { 118 | (void) argc; (void) argv; 119 | 120 | if (argc < 2) 121 | { 122 | usage(*argv); 123 | return 0; 124 | } 125 | 126 | QString inFile(argv[1]); 127 | QFileInfo finfo(inFile); 128 | 129 | QStringList restArg; 130 | for (int i = 2; i < argc; ++i) 131 | restArg << argv[i]; 132 | 133 | if (restArg.contains("--help")) 134 | { 135 | usage(*argv); 136 | return 0; 137 | } 138 | 139 | bool nullTerm = false; 140 | bool stringData = false; 141 | 142 | if (restArg.contains("--null-terminated")) 143 | nullTerm = true; 144 | 145 | if (restArg.contains("--string")) 146 | { 147 | stringData = true; 148 | nullTerm = true; 149 | } 150 | 151 | QString outSymbol = finfo.baseName(); 152 | outSymbol.replace(".", "_"); 153 | 154 | QString outFile; 155 | 156 | outFile = getNamedOption(restArg, "-o", finfo.fileName() + ".xxd"); 157 | outSymbol = getNamedOption(restArg, "--symbol", outSymbol); 158 | 159 | QString dataType = stringData ? "char" : "unsigned char"; 160 | 161 | return writeDump(inFile, outFile, 162 | dataType, "unsigned int", 163 | outSymbol, nullTerm); 164 | } 165 | --------------------------------------------------------------------------------