Compare commits

..

82 Commits

Author SHA1 Message Date
Amaryllis Kulla 6a875b30d2 README: Update matrix space link 2023-10-12 20:53:19 +02:00
Amaryllis Kulla 998aa9f846 README: Update soundfont link 2023-10-05 21:18:55 +02:00
Amaryllis Kulla b4c439c6eb README: Update links 2023-09-08 20:54:46 +02:00
Amaryllis Kulla 380b676777
README: Point binary links at mapleshrine.eu 2021-11-06 00:04:25 +01:00
Amaryllis Kulla a962c158db Update copyright notice again
Keep information on first file creation year,
and update my email address yet again.
2021-10-16 22:57:08 +02:00
Jaiden cf6403ae65 Update glstate.cpp
Fixes the GL blend formula for Subtractive blending
2021-09-19 15:24:12 +02:00
Ancurio f138731f7c Update copyright notice 2021-09-06 20:50:44 +02:00
mara ac8f4b1594 build: Support SDL_sound in different prefix as SDL2
As the required SDL_sound is a custom fork which is not packaged as
system package, it could plausibly be installed in a different path.
2021-09-03 07:43:11 +02:00
Jari Vetoniemi 990843a50b Compile with newer openal-soft 2021-08-28 07:40:15 +02:00
Jari Vetoniemi 66dc9309db Add .editorconfig to the project
Saves time and hassle
2020-08-12 22:17:37 +02:00
Jonas Kulla 5c117a55bf
README: Remember that markdown is a thing 2020-08-10 09:42:00 +02:00
Jonas Kulla cb09036c55
README: Add project discord link 2020-08-10 09:41:19 +02:00
Jonas Kulla 6903f2ab43 README: Add link to gist document 2020-05-06 07:38:25 +02:00
Jonas Kulla 9dc42914de README: Clarify target group of project 2019-06-20 06:01:20 +02:00
Jonas Kulla 86194118a3 FileSystem: Check PHYSFS_registerArchiver() for success 2019-05-18 16:48:17 +02:00
Jonas Kulla 98bdfcf758 FileSystem: Check PHYSFS_init() for success
Move it above the allocations so exceptions don't leak memory.
2019-05-18 16:42:56 +02:00
Jonas Kulla 6fa5b8c856 Sprite: Define M_PI manually
Apparently (older?) mingw-w64 with C++11 enabled doesn't have it.
2019-05-18 16:21:21 +02:00
Jonas Kulla d6b477b887 qmake.pro: Add explicit C++11 flags 2019-05-18 16:17:09 +02:00
Jonas Kulla 9dcfb66e86 fluid-fun: Define destructor signature based on fluidsynth version
As per @carstene1ns 's suggestion.
2019-03-22 21:16:57 +01:00
Jonas Kulla d4b9adc1d1 fluid-fun: Adjust function signature to fluidsynth 2.0
This breaks compilation with FLUID_SHARED against <2.0 versions,
which should be reasonable given that the default mode can still
dynamically load both variants.

Fixes #219.
2019-03-21 08:07:02 +01:00
Luis Caceres 43cb318862 Config: Add case-insensitive ini file parser 2019-03-19 19:26:50 +01:00
Eliza Velasquez bab22d87be Fix font enumeration
Currently, the font enumeration callback erroneously stops searching if
it finds any files that aren't fonts. In the case that you have, say, a
desktop.ini or a .DS_Store or a license file, it may prevent all of the
fonts from being loaded. This commit resolves this.
2018-10-13 20:28:36 +02:00
Jonas Kulla ae59fcd112 Graphics: Fix transition when new scene has gray tone effect
Rendering the scene may cause PingPong swaps of front / backbuffer,
so don't take references to those buffers until after rendering.

Fixes #199
2018-05-21 12:22:23 +02:00
ReinUsesLisp b5e5a26d8b Config: Set debug editor's debug variables into ruby 2018-02-22 09:08:45 +01:00
Jonas Kulla 9f44ee5068 FileSystem: Fix while termination condition 2018-01-22 10:54:21 +01:00
Jonas Kulla 183ebbed65 RGSSAD: Fix parsing of top level directory entries
We were spamming every path into the hash (including the top
level ones) without noticing... oh well.
2017-12-12 22:46:25 +01:00
Jonas Kulla 7902d0942d Filesystem: Properly iterate top level dir entries
"." seemed to have worked in earlier PhysFS versions,
but it was never the correct way.
2017-12-12 22:45:01 +01:00
Jonas Kulla 947974cac6 Config: Properly use windowTitle everywhere instead of game.title 2017-12-12 17:57:02 +01:00
Jonas Kulla 2f81fbbf4b Fix ordering 2017-12-11 00:51:21 +01:00
Jonas Kulla 7d9a85dbbd Config: Add entry to override the game window title 2017-12-11 00:48:35 +01:00
Carsten Teibes d427df0c2b Adapt RGSS archivers and filesystem to physfs 3.0 API 2017-10-12 14:27:19 +02:00
Carsten Teibes b1bdf1e445 Fix CMake build, only use `resource.h` on Windows
This was broken in commit 01e17ed5c6 (move windows specific files).
2017-08-18 22:42:27 +02:00
Carsten Teibes fde6a92197 Fix deprecation warning on build with MRI>2.3
Fixes #158.

The old alias is deprecated since: ruby/ruby@fdb957925f.
2017-08-18 22:41:16 +02:00
Marty Plummer 01e17ed5c6 windows: move windows specific files
Moved the windows-specific files into their own subdir for
cleanliness's sake and mesonbuild organization.

Signed-off-by: Marty Plummer <ntzrmtthihu777@gmail.com>
2017-08-10 21:58:31 +02:00
Jonas Kulla f172f58c74 Sprite: Fix regression with "mirror" attribute
FloatRect::hFlipped() returns a rectangle with negative width,
which was clobbered by the clamping further down.

Regression introduced in 55cec53911.
2017-08-10 21:39:17 +02:00
Jonas Kulla fba20e6294 Sprite: Check for disposed state before accessing bitmap 2017-07-30 23:00:18 +02:00
Marty Plummer f5c30affaa mingw-w64: allow cmake cross-compile
Tested on gentoo with x86_64-w64-mingw32 toolchain and libraries.

Signed-off-by: Marty Plummer <ntzrmtthihu777@gmail.com>
2017-05-25 13:01:11 +02:00
Jonas Kulla bd694f9f99 Graphics: Remove superfluous TEXFBOs while reusing existing ones
While the PingPong buffers were always texture-backed, currentScene
and transBuffer used to be backed by renderbuffers, which might have
been more optimized as render targets on older hardware; but since
all buffers in Graphics got switched to being texture backed to allow
blitting via rendering (when hardware blitting isn't available or broken,
eg. on mobile platforms), their reason to exist vanished.

For transBuffer, we can reuse the backbuffer of the PingPong structure,
while currentScene might have been useless from the start.
2017-05-11 12:37:15 +02:00
Jonas Kulla cab453ac3a Graphics: Use proper resizing function for TEXFBOs
Manually resizing the contained TEX objects skips updating the
width/height TEXFBO properties, which GLMeta::blit relies on.
2017-05-11 12:32:56 +02:00
Jonas Kulla 006f701fec Config: Add "enableBlitting" entry to toggle GL_EXT_framebuffer_blit 2017-04-23 14:32:11 +02:00
Jonas Kulla 1478e1e0f9 Config: Add "maxTextureSize" entry to artificially limit texture sizes 2017-04-23 14:10:54 +02:00
Jonas Kulla 06feafe9ef Add missing include 2017-04-08 20:06:12 +02:00
Jonas Kulla e4079d5738 Fix build on OSX after 60e967e3b7 2017-04-08 19:13:31 +02:00
Jonas Kulla 0481f920b0 Input: Remove ugly [-20,-20] mouse position hack
This was supposed to disappear shortly after To the Moon's release,
but it unfortunately survived a bit longer :)

The status of the mouse cursor being inside / outside the game window
is now properly exposed (in MRI) via MKXP.mouse_in_window.
2017-04-08 18:45:24 +02:00
Jonas Kulla 3ea24bd757 EventThread: Make system cursor visible over black aspect ratio bars
Should be less confusing for the player.
2017-04-08 18:45:24 +02:00
Marty Plummer 60e967e3b7 Add icon and resource files for windows
Signed-off-by: Marty Plummer <ntzrmtthihu777@gmail.com>
2017-03-09 08:24:13 +01:00
Jonas Kulla 0f9b5f274a Filesystem: Search for "Fonts/" with case-insensitivity 2017-03-08 16:30:07 +01:00
Jonas Kulla 6349146e01 main: Only set window icon on Linux
OSX carries high-resolution icons in its bundles, and windows uses
windres to embed .ico files, so don't interfere with those.
2017-03-04 11:04:02 +01:00
Jonas Kulla c4dd3ffaf6 Config: Use set for preloadScripts
Would probably make sense for all other string vectors too.
2017-03-03 19:37:19 +01:00
Jonas Kulla 55cec53911 Sprite: Clamp src_rect to bitmap bounds 2017-02-17 19:29:38 +01:00
Jonas Kulla 541e24f678 Bitmap: Use more accurate HSV-based hue shift algorithm
The previously YIQ-based algorithm turned out to be both slow,
and horribly inaccurate.

Another algorithm based on rotating the color value in the
RGB cube along the diagonal axis was also considered, which was
acceptable in terms of accuracy, and very fast.

In the end, I decided on a HSV-based one, because it is by far
the most accurate one, while still being a tad faster than the
YIQ solution.
Algorithm source: gamedev.stackexchange.com/a/59808/24839

A very simple GPU time benchmark when shifting a 2048^2 bitmap:

         YIQ rot   RGB rot   HSV shift
radeon   13.4 ms   2.8 ms    11.4 ms
intel    13.0 ms   6.0 ms    10.5 ms

radeon: HD 3650 mobility
intel:  N3540 integrated (Baytrail)

However hue shifting has never shown up as a bottleneck before,
so these are more academic.
2016-10-30 08:50:45 +01:00
Jonas Kulla 0ec1fce4ac MRI: Bind Audio.setup_midi 2016-09-12 20:20:56 +02:00
Jonas Kulla d4e09f55bd WindowVX: Fix move() not setting the correct dirty flags 2016-07-27 12:03:45 +02:00
Jonas Kulla e98c2e0535 Bitmap: Don't throw away cached surface in setPixel()
Instead, update the surface with the same change. For many
consecutive getPixel() -> setPixel() calls on the same bitmap,
this avoids calling glReadPixels at every iteration.
2016-07-27 11:59:08 +02:00
Jonas Kulla fdaf6c3611 Bitmap: Split surface pixel address calculation into helper 2016-07-27 11:56:43 +02:00
Jonas Kulla 47ef36ca19 EventThread: ifdef out broken SDL function on OSX 2016-02-24 17:55:28 +01:00
Jonas Kulla de74fc1bc3 EventThread: Fix mouse cursor not being hidden 2016-02-24 17:45:55 +01:00
Jonas Kulla 5d776319b5 Font/MRI: Improve handling of (default_)name attributes
More accurate behavior, such as Font objects properly inheriting
their name attributes, and centralization of code for picking
the first existing name from a passed string array.

Also centralizes initial default_name population in core.

Note: This currently breaks the mruby binding build.
2016-01-05 08:47:52 +01:00
Jonas Kulla 53b5b923d4 Merge pull request #138 from mook/graphics-playmovie-stub
MRI: Stub out Graphics.play_movie
2015-10-30 16:20:47 +01:00
Mook 8e411cbcfe Graphics: Stub out play_movie
Some people are using it to detect the RGSS version.
2015-10-30 08:01:36 -07:00
Jonas Kulla 7bf6eca362 EventThread: Comment out unneeded SDL2 constants 2015-07-26 23:56:50 +02:00
Jonas Kulla 4d97a17c44 TilemapVX: Ensure legs of out-of-view table tiles are drawn 2015-07-21 12:13:25 +02:00
Jonas Kulla 7017ca1c53 Use static lifetime for constant array 2015-07-21 12:13:25 +02:00
Jonas Kulla 30465691ae Tilemap: Fix map viewport calculation
Calculation was completely off as it didn't take into
account the imposed viewport origin.

All in all, similar fixes as the previous ones to TilemapVX.
2015-07-21 12:13:25 +02:00
Jonas Kulla dd7545fcf2 TilemapVX: Clean up the horrible map viewport calculation code
Also rename "offset" to "origin" which makes a lot more sense
for ox/oy attributes.
2015-07-21 12:13:24 +02:00
Jonas Kulla 5aaeb0206c Remove some stuff that was accidentally committed 2015-07-21 12:13:24 +02:00
Jonas Kulla 9a3dd2d554 Config: Enable smoothScaling by default
There's really no reason not to.
2015-07-21 12:13:24 +02:00
Jonas Kulla 384249c31a Unify float literals to use f suffix and avoid double promotions
I might have missed some.
2015-07-21 12:13:24 +02:00
Jonas Kulla d1ee507ec4 Vec2i, IntRect: Add unequal operator 2015-07-21 12:13:24 +02:00
Jonas Kulla 21247b18b5 Merge pull request #127 from cremno/add-sprite-bush_opacity
MRI: add Sprite#{bush_opacity,bush_opacity=} bindings
2015-07-21 12:12:24 +02:00
cremno 861d261af2 add Sprite#{bush_opacity,bush_opacity=} 2015-07-21 07:27:53 +02:00
Jonas Kulla fe6799d00b TilemapVX: Fix map viewport calculation 2015-07-10 04:58:28 +02:00
Jonas Kulla fe709b6010 Use vector math 2015-07-10 04:51:29 +02:00
Jonas Kulla 54c1107f19 FileSystem: Fix file lookup if unrelated files with same name exist
Before, even though we did match all possible extensions,
we only took the first match and tried opening it.
If we were looking for a .png image, but there was an unrelated
.txt file with the same name (as it actually happens in RTPs),
we would potentially see the .txt first, try opening it,
and fail alltogether, even though the image file existed.

Now we try opening all matching files until we find one that
we can parse.

This fixes #101.
2015-07-09 15:38:50 +02:00
Jonas Kulla 533e69275a Constify 2015-07-09 14:53:59 +02:00
Jonas Kulla e4558c9dfb Use FS::openReadRaw() where ext supplementing makes no sense
Specifically, in places where the full filename is always supplied,
eg. when reading .rxdata type files.
2015-07-09 12:58:01 +02:00
Jonas Kulla 5382cc11a3 MidiSource: Close source SDL_RWops before throwing error 2015-07-09 12:38:04 +02:00
Jonas Kulla 1e9e24e45c README: Add note about RGSS version support 2015-07-09 12:33:55 +02:00
Jonas Kulla 9acdd206f6 Vec4: Rename 'xyzHasEffect()' to something that makes sense 2015-07-07 16:07:04 +02:00
Jonas Kulla 6e176a454c Constify 2015-07-07 16:06:45 +02:00
Jonas Kulla afab51279e Graphics: Fix viewport color/flash effectiveness calculation
Fixes #121.
2015-07-07 16:06:11 +02:00
Jonas Kulla 61849a9158 GLMeta: Eliminate redundant parameter 2015-07-07 15:25:48 +02:00
162 changed files with 1560 additions and 1084 deletions

5
.editorconfig Normal file
View File

@ -0,0 +1,5 @@
root=true
[*]
end_of_line = lf
indent_style = tab
indent_size = 4

View File

@ -110,6 +110,7 @@ set(MAIN_HEADERS
src/flashable.h
src/font.h
src/input.h
src/iniconfig.h
src/plane.h
src/scene.h
src/sprite.h
@ -167,6 +168,7 @@ set(MAIN_SOURCE
src/filesystem.cpp
src/font.cpp
src/input.cpp
src/iniconfig.cpp
src/plane.cpp
src/scene.cpp
src/sprite.cpp
@ -205,6 +207,11 @@ set(MAIN_SOURCE
src/fluid-fun.cpp
)
if(WIN32)
list(APPEND MAIN_HEADERS windows/resource.h)
list(APPEND MAIN_SOURCE windows/resource.rc)
endif()
source_group("MKXP Source" FILES ${MAIN_SOURCE} ${MAIN_HEADERS})
## Setup embedded source ##
@ -405,10 +412,12 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
)
target_include_directories(${PROJECT_NAME} PRIVATE
src
windows
${SIGCXX_INCLUDE_DIRS}
${PIXMAN_INCLUDE_DIRS}
${PHYSFS_INCLUDE_DIRS}
${SDL2_INCLUDE_DIRS} # Blindly assume other SDL bits are in same directory
${SDL_SOUND_INCLUDE_DIRS}
${Boost_INCLUDE_DIR}
${MRI_INCLUDE_DIRS}
${VORBISFILE_INCLUDE_DIRS}

View File

@ -1,13 +1,19 @@
# mkxp
Discord community: https://discord.gg/A8xHE8P
Matrix space: https://matrix.to/#/#rpgmaker:mapleshrine.eu
Further links: https://mapleshrine.eu
mkxp is a project that seeks to provide a fully open source implementation of the Ruby Game Scripting System (RGSS) interface used in the popular game creation software "RPG Maker XP", "RPG Maker VX" and "RPG Maker VX Ace" (trademark by Enterbrain, Inc.), with focus on Linux. The goal is to be able to run games created with the above software natively without changing a single file.
It is licensed under the GNU General Public License v2+.
## Prebuilt binaries
[**Linux (32bit/64bit)**](http://ancurio.bplaced.net/mkxp/generic/)
[**Linux / Windows**](https://www.mapleshrine.eu/releases/)
[**OSX**](https://app.box.com/mkxpmacbuilds) by Ali
[**Windows (mingw-w64 32bit)**](http://ancurio.bplaced.net/mkxp/mingw32/)
## Should I use mkxp
mkxp primarily targets technically versed users that are comfortable with Ruby / RGSS, and ideally know how to compile the project themselves. The reason for this is that for most games, due to Win32-API usage, mkxp is simply not a plug-and-play solution, but a building block with which a fully cross-platform version can be created in time.
## Bindings
Bindings provide the glue code for an interpreted language environment to run game scripts in. Currently there are three bindings:
@ -20,6 +26,8 @@ Matz's Ruby Interpreter, also called CRuby, is the most widely deployed version
For a list of differences, see:
http://stackoverflow.com/questions/21574/what-is-the-difference-between-ruby-1-8-and-ruby-1-9
This binding supports RGSS1, RGSS2 and RGSS3.
### mruby (Lightweight Ruby)
Website: https://github.com/mruby/mruby
@ -29,6 +37,8 @@ Due to heavy differences between mruby and MRI as well as lacking modules, runni
Some extensions to the standard classes/modules are provided, taking the RPG Maker XP helpfile as a quasi "reference". These include Marshal, File, FileTest and Time.
This binding only supports RGSS1.
**Important:** If you decide to use [mattn's oniguruma regexp gem](https://github.com/mattn/mruby-onig-regexp), don't forget to add `-lonig` to the linker flags to avoid ugly symbol overlaps with libc.
### null
@ -79,7 +89,7 @@ To run mkxp, you should have a graphics card capable of at least **OpenGL (ES) 2
## Dependency kit
To facilitate hacking, I have assembled a package containing all dependencies to compile mkxp on a bare-bones Ubuntu 12.04 64bit installation. Compatibility with other distributions has not been tested. You can download it [here](https://www.dropbox.com/s/mtp44ur367m2zts/mkxp-depkit.tar.xz). Read the "README" for instructions.
To facilitate hacking, I have assembled a package containing all dependencies to compile mkxp on a bare-bones Ubuntu 12.04 64bit installation. Compatibility with other distributions has not been tested. You can download it [here](https://mapleshrine.eu/depkits/linux64.tar.xz). Read the "README" for instructions.
## Configuration
@ -95,7 +105,7 @@ Example: `./mkxp --gameFolder="my game" --vsync=true --fixedFramerate=60`
mkxp doesn't come with a soundfont by default, so you will have to supply it yourself (set its path in the config). Playback has been tested and should work reasonably well with all RTP assets.
You can use this public domain soundfont: [GMGSx.sf2](https://www.dropbox.com/s/qxdvoxxcexsvn43/GMGSx.sf2?dl=0)
You can use this public domain soundfont: [GMGSx.sf2](https://mapleshrine.eu/unsorted/GMGSx.sf2)
## Fonts

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -97,6 +97,15 @@ DEF_FADE( me )
DEF_PLAY_STOP( se )
RB_METHOD(audioSetupMidi)
{
RB_UNUSED_PARAM;
shState->audio().setupMidi();
return Qnil;
}
RB_METHOD(audioReset)
{
RB_UNUSED_PARAM;
@ -135,6 +144,8 @@ audioBindingInit()
{
BIND_POS( bgm );
BIND_POS( bgs );
_rb_define_module_function(module, "setup_midi", audioSetupMidi);
}
BIND_PLAY_STOP( se )

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -80,6 +80,7 @@ RB_METHOD(mriP);
RB_METHOD(mkxpDataDirectory);
RB_METHOD(mkxpPuts);
RB_METHOD(mkxpRawKeyStates);
RB_METHOD(mkxpMouseInWindow);
RB_METHOD(mriRgssMain);
RB_METHOD(mriRgssStop);
@ -144,8 +145,18 @@ static void mriBindingInit()
_rb_define_module_function(mod, "data_directory", mkxpDataDirectory);
_rb_define_module_function(mod, "puts", mkxpPuts);
_rb_define_module_function(mod, "raw_key_states", mkxpRawKeyStates);
_rb_define_module_function(mod, "mouse_in_window", mkxpMouseInWindow);
/* Load global constants */
rb_gv_set("MKXP", Qtrue);
VALUE debug = rb_bool_new(shState->config().editor.debug);
if (rgssVer == 1)
rb_gv_set("DEBUG", debug);
else if (rgssVer >= 2)
rb_gv_set("TEST", debug);
rb_gv_set("BTEST", rb_bool_new(shState->config().editor.battleTest));
}
static void
@ -222,6 +233,13 @@ RB_METHOD(mkxpRawKeyStates)
return str;
}
RB_METHOD(mkxpMouseInWindow)
{
RB_UNUSED_PARAM;
return rb_bool_new(EventThread::mouseState.inWindow);
}
static VALUE rgssMainCb(VALUE block)
{
rb_funcall2(block, rb_intern("call"), 0, 0);
@ -452,8 +470,9 @@ static void runRMXPScripts(BacktraceData &btData)
}
/* Execute preloaded scripts */
for (size_t i = 0; i < conf.preloadScripts.size(); ++i)
runCustomScript(conf.preloadScripts[i]);
for (std::set<std::string>::iterator i = conf.preloadScripts.begin();
i != conf.preloadScripts.end(); ++i)
runCustomScript(*i);
VALUE exc = rb_gv_get("$!");
if (exc != Qnil)

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -23,7 +23,6 @@
#define BINDING_UTIL_H
#include <ruby.h>
#undef inline //ruby's config.h has #define inline __inline, which cause error in xkeycheck.h
#include "exception.h"
@ -68,7 +67,7 @@ raiseRbExc(const Exception &exc);
/* 2.1 has added a new field (flags) to rb_data_type_t */
#include <ruby/version.h>
#if RUBY_API_VERSION_MINOR > 0
#if RUBY_API_VERSION_MAJOR >= 2 && RUBY_API_VERSION_MINOR >= 1
/* TODO: can mkxp use RUBY_TYPED_FREE_IMMEDIATELY here? */
#define DEF_TYPE_FLAGS 0
#else
@ -91,7 +90,12 @@ raiseRbExc(const Exception &exc);
template<rb_data_type_t *rbType>
static VALUE classAllocate(VALUE klass)
{
/* 2.3 has changed the name of this function */
#if RUBY_API_VERSION_MAJOR >= 2 && RUBY_API_VERSION_MINOR >= 3
return rb_data_typed_object_wrap(klass, 0, rbType);
#else
return rb_data_typed_object_alloc(klass, 0, rbType);
#endif
}
template<class C>

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -46,7 +46,7 @@ fileIntForPath(const char *path, bool rubyExc)
try
{
shState->fileSystem().openRead(*ops, path);
shState->fileSystem().openReadRaw(*ops, path);
}
catch (const Exception &e)
{

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -27,6 +27,29 @@
#include <string.h>
static void
collectStrings(VALUE obj, std::vector<std::string> &out)
{
if (RB_TYPE_P(obj, RUBY_T_STRING))
{
out.push_back(RSTRING_PTR(obj));
}
else if (RB_TYPE_P(obj, RUBY_T_ARRAY))
{
for (long i = 0; i < RARRAY_LEN(obj); ++i)
{
VALUE str = rb_ary_entry(obj, i);
/* Non-string objects are tolerated (ignored) */
if (!RB_TYPE_P(str, RUBY_T_STRING))
continue;
out.push_back(RSTRING_PTR(str));
}
}
}
DEF_TYPE(Font);
RB_METHOD(fontDoesExist)
@ -48,12 +71,30 @@ RB_METHOD(FontSetName);
RB_METHOD(fontInitialize)
{
VALUE name = Qnil;
VALUE namesObj = Qnil;
int size = 0;
rb_get_args(argc, argv, "|oi", &name, &size RB_ARG_END);
rb_get_args(argc, argv, "|oi", &namesObj, &size RB_ARG_END);
Font *f = new Font(0, size);
Font *f;
if (NIL_P(namesObj))
{
namesObj = rb_iv_get(rb_obj_class(self), "default_name");
f = new Font(0, size);
}
else
{
std::vector<std::string> names;
collectStrings(namesObj, names);
f = new Font(&names, size);
}
/* This is semantically wrong; the new Font object should take
* a dup'ed object here in case of an array. Ditto for the setters.
* However the same bug/behavior exists in all RM versions. */
rb_iv_set(self, "name", namesObj);
setPrivateData(self, f);
@ -65,13 +106,6 @@ RB_METHOD(fontInitialize)
if (rgssVer >= 3)
wrapProperty(self, &f->getOutColor(), "out_color", ColorType);
if (NIL_P(name))
name = rb_iv_get(rb_obj_class(self), "default_name");
/* Going over the 'name=' function automatically causes
* a possbile name array to be re-verified for existing fonts */
FontSetName(1, &name, self);
return self;
}
@ -105,57 +139,17 @@ RB_METHOD(FontGetName)
return rb_iv_get(self, "name");
}
static void
fontSetNameHelper(VALUE self, int argc, VALUE *argv,
const char *nameIv, char *outBuf, size_t outLen)
{
rb_check_argc(argc, 1);
VALUE arg = argv[0];
// Fixme: in RGSS3, specifying "" (and only that) as font name results in
// no text being drawn (everything else is substituted with Arial I think)
strncpy(outBuf, "", outLen);
if (RB_TYPE_P(arg, RUBY_T_STRING))
{
strncpy(outBuf, RSTRING_PTR(arg), outLen);
}
else if (RB_TYPE_P(arg, RUBY_T_ARRAY))
{
for (long i = 0; i < RARRAY_LEN(arg); ++i)
{
VALUE str = rb_ary_entry(arg, i);
/* Non-string objects are tolerated (ignored) */
if (!RB_TYPE_P(str, RUBY_T_STRING))
continue;
const char *family = RSTRING_PTR(str);
/* We only set the core Font object's name attribute
* to the actually existing font name */
if (!shState->fontState().fontPresent(family))
continue;
strncpy(outBuf, family, outLen);
}
}
/* RMXP doesn't even care if the argument type is
* something other than string/array. Whatever... */
rb_iv_set(self, nameIv, arg);
}
RB_METHOD(FontSetName)
{
Font *f = getPrivateData<Font>(self);
char result[256];
fontSetNameHelper(self, argc, argv, "name",
result, sizeof(result));
rb_check_argc(argc, 1);
f->setName(result);
std::vector<std::string> namesObj;
collectStrings(argv[0], namesObj);
f->setName(namesObj);
rb_iv_set(self, "name", argv[0]);
return argv[0];
}
@ -223,11 +217,15 @@ RB_METHOD(FontGetDefaultName)
RB_METHOD(FontSetDefaultName)
{
char result[256];
fontSetNameHelper(self, argc, argv, "default_name",
result, sizeof(result));
RB_UNUSED_PARAM;
Font::setDefaultName(result);
rb_check_argc(argc, 1);
std::vector<std::string> namesObj;
collectStrings(argv[0], namesObj);
Font::setDefaultName(namesObj, shState->fontState());
rb_iv_set(self, "default_name", argv[0]);
return argv[0];
}
@ -267,7 +265,24 @@ fontBindingInit()
Font::initDefaultDynAttribs();
wrapProperty(klass, &Font::getDefaultColor(), "default_color", ColorType);
rb_iv_set(klass, "default_name", rb_str_new_cstr(Font::getDefaultName()));
/* Initialize default names */
const std::vector<std::string> &defNames = Font::getInitialDefaultNames();
VALUE defNamesObj;
if (defNames.size() == 1)
{
defNamesObj = rb_str_new_cstr(defNames[0].c_str());
}
else
{
defNamesObj = rb_ary_new2(defNames.size());
for (size_t i = 0; i < defNames.size(); ++i)
rb_ary_push(defNamesObj, rb_str_new_cstr(defNames[i].c_str()));
}
rb_iv_set(klass, "default_name", defNamesObj);
if (rgssVer >= 3)
wrapProperty(klass, &Font::getDefaultOutColor(), "default_out_color", ColorType);
@ -310,14 +325,4 @@ fontBindingInit()
INIT_PROP_BIND(Font, Outline, "outline");
INIT_PROP_BIND(Font, OutColor, "out_color");
}
if (rgssVer >= 2)
{
VALUE defNames = rb_ary_new2(3);
rb_ary_push(defNames, rb_str_new2("Verdana"));
rb_ary_push(defNames, rb_str_new2("Arial"));
rb_ary_push(defNames, rb_str_new2("Courier New"));
FontSetDefaultName(1, &defNames, klass);
}
}

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -183,6 +183,18 @@ RB_METHOD(graphicsReset)
return Qnil;
}
RB_METHOD(graphicsPlayMovie)
{
RB_UNUSED_PARAM;
const char *filename;
rb_get_args(argc, argv, "z", &filename RB_ARG_END);
shState->graphics().playMovie(filename);
return Qnil;
}
DEF_GRA_PROP_I(FrameRate)
DEF_GRA_PROP_I(FrameCount)
DEF_GRA_PROP_I(Brightness)
@ -223,6 +235,11 @@ void graphicsBindingInit()
INIT_GRA_PROP_BIND( Brightness, "brightness" );
}
if (rgssVer >= 3)
{
_rb_define_module_function(module, "play_movie", graphicsPlayMovie);
}
INIT_GRA_PROP_BIND( Fullscreen, "fullscreen" );
INIT_GRA_PROP_BIND( ShowCursor, "show_cursor" );
}

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -56,6 +56,7 @@ DEF_PROP_I(Sprite, Y)
DEF_PROP_I(Sprite, OX)
DEF_PROP_I(Sprite, OY)
DEF_PROP_I(Sprite, BushDepth)
DEF_PROP_I(Sprite, BushOpacity)
DEF_PROP_I(Sprite, Opacity)
DEF_PROP_I(Sprite, BlendType)
DEF_PROP_I(Sprite, WaveAmp)
@ -126,6 +127,8 @@ spriteBindingInit()
_rb_define_method(klass, "width", spriteWidth);
_rb_define_method(klass, "height", spriteHeight);
INIT_PROP_BIND( Sprite, BushOpacity, "bush_opacity" );
INIT_PROP_BIND( Sprite, WaveAmp, "wave_amp" );
INIT_PROP_BIND( Sprite, WaveLength, "wave_length" );
INIT_PROP_BIND( Sprite, WaveSpeed, "wave_speed" );

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -19,10 +19,6 @@
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef _MSC_VER
#define NOMINMAX
#endif
#include <algorithm>
#include "table.h"
#include "binding-util.h"

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2014 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2014 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -114,8 +114,17 @@ static void mrbBindingInit(mrb_state *mrb)
/* Load RPG module */
mrb_load_irep(mrb, mrbModuleRPG);
/* Load global constants */
mrb_define_global_const(mrb, "MKXP", mrb_true_value());
mrb_value debug = rb_bool_new(shState->config().editor.debug);
if (rgssVer == 1)
mrb_define_global_const(mrb, "DEBUG", debug);
else if (rgssVer >= 2)
mrb_define_global_const(mrb, "TEST", debug);
mrb_define_global_const(mrb, "BTEST", mrb_bool_value(shState->config().editor.battleTest));
mrb_gc_arena_restore(mrb, arena);
}
@ -266,7 +275,7 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
mrb_state *scriptMrb = mrb_open();
SDL_RWops ops;
shState->fileSystem().openRead(ops, scriptPack.c_str());
shState->fileSystem().openReadRaw(ops, scriptPack.c_str());
mrb_value scriptArray = mrb_nil_value();
std::string readError;

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -57,9 +57,9 @@
# Apply linear interpolation when game screen
# is upscaled
# (default: disabled)
# (default: enabled)
#
# smoothScaling=false
# smoothScaling=true
# Sync screen redraws to the monitor refresh rate
@ -86,6 +86,12 @@
# defScreenH=480
# Override the game window title
# (default: none)
#
# windowTitle=Custom Title
# Enforce a static frame rate
# (0 = disabled)
#
@ -124,6 +130,26 @@
# subImageFix=false
# Enable framebuffer blitting if the driver is
# capable of it. Some drivers carry buggy
# implementations of this functionality, so
# disabling it can be used as a workaround
# (default: enabled)
#
# enableBlitting=true
# Limit the maximum size (width, height) of
# most textures mkxp will create (exceptions are
# rendering backbuffers and similar).
# If set to 0, the hardware maximum is used.
# This is useful for recording traces that can
# be played back on machines with lower specs.
# (default: 0)
#
# maxTextureSize=0
# Set the base path of the game to '/path/to/game'
# (default: executable directory)
#

View File

@ -8,6 +8,10 @@ INCLUDEPATH += . src
CONFIG(release, debug|release): DEFINES += NDEBUG
CONFIG += c++11
# And for older qmake versions..
QMAKE_CXXFLAGS += -std=c++11
isEmpty(BINDING) {
BINDING = MRI
}
@ -89,6 +93,7 @@ HEADERS += \
src/flashable.h \
src/font.h \
src/input.h \
src/iniconfig.h \
src/plane.h \
src/scene.h \
src/sprite.h \
@ -145,6 +150,7 @@ SOURCES += \
src/filesystem.cpp \
src/font.cpp \
src/input.cpp \
src/iniconfig.cpp \
src/plane.cpp \
src/scene.cpp \
src/sprite.cpp \

View File

@ -1,48 +1,40 @@
uniform sampler2D inputTexture;
uniform float hueAdjust;
uniform sampler2D texture;
uniform mediump float hueAdjust;
varying vec2 v_texCoord;
/* Source: gamedev.stackexchange.com/a/59808/24839 */
vec3 rgb2hsv(vec3 c)
{
const vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
/* Avoid divide-by-zero situations by adding a very tiny delta.
* Since we always deal with underlying 8-Bit color values, this
* should never mask a real value */
const float eps = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + eps)), d / (q.x + eps), q.x);
}
vec3 hsv2rgb(vec3 c)
{
const vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main ()
{
const vec4 kRGBToYPrime = vec4 (0.299, 0.587, 0.114, 0.0);
const vec4 kRGBToI = vec4 (0.596, -0.275, -0.321, 0.0);
const vec4 kRGBToQ = vec4 (0.212, -0.523, 0.311, 0.0);
vec4 color = texture2D (texture, v_texCoord.xy);
vec3 hsv = rgb2hsv(color.rgb);
const vec4 kYIQToR = vec4 (1.0, 0.956, 0.621, 0.0);
const vec4 kYIQToG = vec4 (1.0, -0.272, -0.647, 0.0);
const vec4 kYIQToB = vec4 (1.0, -1.107, 1.704, 0.0);
hsv.x += hueAdjust;
color.rgb = hsv2rgb(hsv);
/* Sample the input pixel */
vec4 color = texture2D (inputTexture, v_texCoord.xy);
/* Convert to YIQ */
float YPrime = dot (color, kRGBToYPrime);
float I = dot (color, kRGBToI);
float Q = dot (color, kRGBToQ);
/* Calculate the hue and chroma */
float hue = atan (Q, I);
float chroma = sqrt (I * I + Q * Q);
/* Make the user's adjustments */
hue += hueAdjust;
/* Remember old I and color */
float IOriginal = I;
vec4 coOriginal = color;
/* Convert back to YIQ */
Q = chroma * sin (hue);
I = chroma * cos (hue);
/* Convert back to RGB */
vec4 yIQ = vec4 (YPrime, I, Q, 0.0);
color.r = dot (yIQ, kYIQToR);
color.g = dot (yIQ, kYIQToG);
color.b = dot (yIQ, kYIQToB);
/* Save the result */
gl_FragColor = (IOriginal == 0.0) ? coOriginal : color;
gl_FragColor = color;
}

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -238,6 +238,6 @@ inline ALenum chooseALFormat(int sampleSize, int channelCount)
#define AUDIO_SLEEP 10
#define STREAM_BUF_SIZE 32768
#define GLOBAL_VOLUME 0.8
#define GLOBAL_VOLUME 0.8f
#endif // ALUTIL_H

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2014 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2014 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2014 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2014 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -19,7 +19,6 @@
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
*/
#include "crossplatform.h"
#include "alstream.h"
#include "sharedstate.h"
@ -43,12 +42,12 @@ ALStream::ALStream(LoopMode loopMode,
source(0),
thread(0),
preemptPause(false),
pitch(1.0)
pitch(1.0f)
{
alSrc = AL::Source::gen();
AL::Source::setVolume(alSrc, 1.0);
AL::Source::setPitch(alSrc, 1.0);
AL::Source::setVolume(alSrc, 1.0f);
AL::Source::setPitch(alSrc, 1.0f);
AL::Source::detachBuffer(alSrc);
for (int i = 0; i < STREAM_BUFS; ++i)
@ -173,7 +172,7 @@ void ALStream::setPitch(float value)
/* If the source supports setting pitch natively,
* we don't have to do it via OpenAL */
if (source && source->setPitch(value))
AL::Source::setPitch(alSrc, 1.0);
AL::Source::setPitch(alSrc, 1.0f);
else
AL::Source::setPitch(alSrc, value);
}
@ -200,43 +199,73 @@ void ALStream::closeSource()
delete source;
}
struct ALStreamOpenHandler : FileSystem::OpenHandler
{
SDL_RWops *srcOps;
bool looped;
ALDataSource *source;
std::string errorMsg;
ALStreamOpenHandler(SDL_RWops &srcOps, bool looped)
: srcOps(&srcOps), looped(looped), source(0)
{}
bool tryRead(SDL_RWops &ops, const char *ext)
{
/* Copy this because we need to keep it around,
* as we will continue reading data from it later */
*srcOps = ops;
/* Try to read ogg file signature */
char sig[5] = { 0 };
SDL_RWread(srcOps, sig, 1, 4);
SDL_RWseek(srcOps, 0, RW_SEEK_SET);
try
{
if (!strcmp(sig, "OggS"))
{
source = createVorbisSource(*srcOps, looped);
return true;
}
if (!strcmp(sig, "MThd"))
{
shState->midiState().initIfNeeded(shState->config());
if (HAVE_FLUID)
{
source = createMidiSource(*srcOps, looped);
return true;
}
}
source = createSDLSource(*srcOps, ext, STREAM_BUF_SIZE, looped);
}
catch (const Exception &e)
{
/* All source constructors will close the passed ops
* before throwing errors */
errorMsg = e.msg;
return false;
}
return true;
}
};
void ALStream::openSource(const std::string &filename)
{
char ext[8];
shState->fileSystem().openRead(srcOps, filename.c_str(), false, ext, sizeof(ext));
ALStreamOpenHandler handler(srcOps, looped);
shState->fileSystem().openRead(handler, filename.c_str());
source = handler.source;
needsRewind.clear();
/* Try to read ogg file signature */
char sig[5] = { 0 };
SDL_RWread(&srcOps, sig, 1, 4);
SDL_RWseek(&srcOps, 0, RW_SEEK_SET);
try
{
if (!strcmp(sig, "OggS"))
{
source = createVorbisSource(srcOps, looped);
return;
}
if (!strcmp(sig, "MThd"))
{
shState->midiState().initIfNeeded(shState->config());
if (HAVE_FLUID)
{
source = createMidiSource(srcOps, looped);
return;
}
}
source = createSDLSource(srcOps, ext, STREAM_BUF_SIZE, looped);
}
catch (const Exception &e)
if (!source)
{
char buf[512];
snprintf(buf, sizeof(buf), "Unable to decode audio stream: %s.%s: %s",
filename.c_str(), ext, e.msg.c_str());
snprintf(buf, sizeof(buf), "Unable to decode audio stream: %s: %s",
filename.c_str(), handler.errorMsg.c_str());
Debug() << buf;
}

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2014 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2014 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -170,7 +170,7 @@ struct AudioPrivate
else
{
/* BGM is stopped. -> MeNotPlaying */
bgm.setVolume(AudioStream::External, 1.0);
bgm.setVolume(AudioStream::External, 1.0f);
if (!bgm.noResumeStop)
bgm.stream.play();
@ -193,7 +193,7 @@ struct AudioPrivate
if (bgm.stream.queryState() == ALStream::Stopped)
{
/* BGM stopped midway fade in. -> MeNotPlaying */
bgm.setVolume(AudioStream::External, 1.0);
bgm.setVolume(AudioStream::External, 1.0f);
meWatch.state = MeNotPlaying;
bgm.unlockStream();
@ -219,7 +219,7 @@ struct AudioPrivate
if (vol >= 1)
{
/* BGM fully faded in. -> MeNotPlaying */
vol = 1.0;
vol = 1.0f;
meWatch.state = MeNotPlaying;
}

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2014 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2014 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -34,11 +34,11 @@ AudioStream::AudioStream(ALStream::LoopMode loopMode,
noResumeStop(false),
stream(loopMode, threadId)
{
current.volume = 1.0;
current.pitch = 1.0;
current.volume = 1.0f;
current.pitch = 1.0f;
for (size_t i = 0; i < VolumeTypeCount; ++i)
volumes[i] = 1.0;
volumes[i] = 1.0f;
fade.thread = 0;
fade.threadName = std::string("audio_fadeout (") + threadId + ")";
@ -82,8 +82,8 @@ void AudioStream::play(const std::string &filename,
lockStream();
float _volume = clamp<int>(volume, 0, 100) / 100.f;
float _pitch = clamp<int>(pitch, 50, 150) / 100.f;
float _volume = clamp<int>(volume, 0, 100) / 100.0f;
float _pitch = clamp<int>(pitch, 50, 150) / 100.0f;
ALStream::State sState = stream.queryState();
@ -211,7 +211,7 @@ void AudioStream::fadeOut(int duration)
}
fade.active.set();
fade.msStep = (1.0) / duration;
fade.msStep = 1.0f / duration;
fade.reqFini.clear();
fade.reqTerm.clear();
fade.startTicks = SDL_GetTicks();
@ -302,7 +302,7 @@ void AudioStream::fadeOutThread()
lockStream();
uint32_t curDur = SDL_GetTicks() - fade.startTicks;
float resVol = 1.0 - (curDur*fade.msStep);
float resVol = 1.0f - (curDur*fade.msStep);
ALStream::State state = stream.queryState();
@ -313,7 +313,7 @@ void AudioStream::fadeOutThread()
if (state != ALStream::Paused)
stream.stop();
setVolume(FadeOut, 1.0);
setVolume(FadeOut, 1.0f);
unlockStream();
break;
@ -340,15 +340,15 @@ void AudioStream::fadeInThread()
/* Fade in duration is always 1 second */
uint32_t cur = SDL_GetTicks() - fadeIn.startTicks;
float prog = cur / 1000.0;
float prog = cur / 1000.0f;
ALStream::State state = stream.queryState();
if (state != ALStream::Playing
|| prog >= 1.0
|| prog >= 1.0f
|| fadeIn.rqFini)
{
setVolume(FadeIn, 1.0);
setVolume(FadeIn, 1.0f);
unlockStream();
break;

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2014 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2014 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -221,9 +221,9 @@ struct BitmapPrivate
surf = surfConv;
}
void onModified()
void onModified(bool freeSurface = true)
{
if (surface)
if (surface && freeSurface)
{
SDL_FreeSurface(surface);
surface = 0;
@ -233,13 +233,26 @@ struct BitmapPrivate
}
};
struct BitmapOpenHandler : FileSystem::OpenHandler
{
SDL_Surface *surf;
BitmapOpenHandler()
: surf(0)
{}
bool tryRead(SDL_RWops &ops, const char *ext)
{
surf = IMG_LoadTyped_RW(&ops, 1, ext);
return surf != 0;
}
};
Bitmap::Bitmap(const char *filename)
{
SDL_RWops ops;
char ext[8];
shState->fileSystem().openRead(ops, filename, false, ext, sizeof(ext));
SDL_Surface *imgSurf = IMG_LoadTyped_RW(&ops, 1, ext);
BitmapOpenHandler handler;
shState->fileSystem().openRead(handler, filename);
SDL_Surface *imgSurf = handler.surf;
if (!imgSurf)
throw Exception(Exception::SDLError, "Error loading image '%s': %s",
@ -755,6 +768,14 @@ void Bitmap::clear()
p->onModified();
}
static uint32_t &getPixelAt(SDL_Surface *surf, SDL_PixelFormat *form, int x, int y)
{
size_t offset = x*form->BytesPerPixel + y*surf->pitch;
uint8_t *bytes = (uint8_t*) surf->pixels + offset;
return *((uint32_t*) bytes);
}
Color Bitmap::getPixel(int x, int y) const
{
guardDisposed();
@ -777,9 +798,7 @@ Color Bitmap::getPixel(int x, int y) const
glState.viewport.pop();
}
size_t offset = x*p->format->BytesPerPixel + y*p->surface->pitch;
uint8_t *bytes = (uint8_t*) p->surface->pixels + offset;
uint32_t pixel = *((uint32_t*) bytes);
uint32_t pixel = getPixelAt(p->surface, p->format, x, y);
return Color((pixel >> p->format->Rshift) & 0xFF,
(pixel >> p->format->Gshift) & 0xFF,
@ -806,7 +825,16 @@ void Bitmap::setPixel(int x, int y, const Color &color)
p->addTaintedArea(IntRect(x, y, 1, 1));
p->onModified();
/* Setting just a single pixel is no reason to throw away the
* whole cached surface; we can just apply the same change */
if (p->surface)
{
uint32_t &surfPixel = getPixelAt(p->surface, p->format, x, y);
surfPixel = SDL_MapRGBA(p->format, pixel[0], pixel[1], pixel[2], pixel[3]);
}
p->onModified(false);
}
void Bitmap::hueChange(int hue)
@ -826,13 +854,10 @@ void Bitmap::hueChange(int hue)
quad.setTexPosRect(texRect, texRect);
quad.setColor(Vec4(1, 1, 1, 1));
/* Calculate hue parameter */
hue = wrapRange(hue, 0, 359);
float hueAdj = -((M_PI * 2) / 360) * hue;
HueShader &shader = shState->shaders().hue;
shader.bind();
shader.setHueAdjust(hueAdj);
/* Shader expects normalized value */
shader.setHueAdjust(wrapRange(hue, 0, 359) / 360.0f);
FBO::bind(newTex.fbo);
p->pushSetViewport(shader);
@ -877,9 +902,9 @@ static void applyShadow(SDL_Surface *&in, const SDL_PixelFormat &fm, const SDL_C
SDL_Surface *out = SDL_CreateRGBSurface
(0, in->w+1, in->h+1, fm.BitsPerPixel, fm.Rmask, fm.Gmask, fm.Bmask, fm.Amask);
float fr = c.r / 255.0;
float fg = c.g / 255.0;
float fb = c.b / 255.0;
float fr = c.r / 255.0f;
float fg = c.g / 255.0f;
float fb = c.b / 255.0f;
/* We allocate an output surface one pixel wider and higher than the input,
* (implicitly) blit a copy of the input with RGB values set to black into
@ -933,11 +958,11 @@ static void applyShadow(SDL_Surface *&in, const SDL_PixelFormat &fm, const SDL_C
continue;
}
float fSrcA = srcA / 255.0;
float fShdA = shdA / 255.0;
float fSrcA = srcA / 255.0f;
float fShdA = shdA / 255.0f;
/* Because opacity == 1, co1 == fSrcA */
float co2 = fShdA * (1.0 - fSrcA);
float co2 = fShdA * (1.0f - fSrcA);
/* Result alpha */
float fa = fSrcA + co2;
/* Temp value to simplify arithmetic below */
@ -946,10 +971,10 @@ static void applyShadow(SDL_Surface *&in, const SDL_PixelFormat &fm, const SDL_C
/* Result colors */
uint8_t r, g, b, a;
r = clamp<float>(fr * co3, 0, 1) * 255;
g = clamp<float>(fg * co3, 0, 1) * 255;
b = clamp<float>(fb * co3, 0, 1) * 255;
a = clamp<float>(fa, 0, 1) * 255;
r = clamp<float>(fr * co3, 0, 1) * 255.0f;
g = clamp<float>(fg * co3, 0, 1) * 255.0f;
b = clamp<float>(fb * co3, 0, 1) * 255.0f;
a = clamp<float>(fa, 0, 1) * 255.0f;
*outP = SDL_MapRGBA(&fm, r, g, b, a);
}
@ -1054,11 +1079,11 @@ void Bitmap::drawText(const IntRect &rect, const char *str, int align)
Vec2i gpTexSize;
shState->ensureTexSize(txtSurf->w, txtSurf->h, gpTexSize);
bool fastBlit = !p->touchesTaintedArea(posRect) && txtAlpha == 1.0;
bool fastBlit = !p->touchesTaintedArea(posRect) && txtAlpha == 1.0f;
if (fastBlit)
{
if (squeeze == 1.0 && !shState->config().subImageFix)
if (squeeze == 1.0f && !shState->config().subImageFix)
{
/* Even faster: upload directly to bitmap texture.
* We have to make sure the posRect lies within the texture

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -33,6 +33,7 @@
#include "debugwriter.h"
#include "util.h"
#include "sdl-util.h"
#include "iniconfig.h"
#ifdef INI_ENCODING
extern "C" {
@ -134,6 +135,12 @@ static std::string prefPath(const char *org, const char *app)
return str;
}
template<typename T>
std::set<T> setFromVec(const std::vector<T> &vec)
{
return std::set<T>(vec.begin(), vec.end());
}
typedef std::vector<std::string> StringVec;
namespace po = boost::program_options;
@ -151,15 +158,18 @@ void Config::read(int argc, char *argv[])
PO_DESC(winResizable, bool, false) \
PO_DESC(fullscreen, bool, false) \
PO_DESC(fixedAspectRatio, bool, true) \
PO_DESC(smoothScaling, bool, false) \
PO_DESC(smoothScaling, bool, true) \
PO_DESC(vsync, bool, false) \
PO_DESC(defScreenW, int, 0) \
PO_DESC(defScreenH, int, 0) \
PO_DESC(windowTitle, std::string, "") \
PO_DESC(fixedFramerate, int, 0) \
PO_DESC(frameSkip, bool, true) \
PO_DESC(syncToRefreshrate, bool, false) \
PO_DESC(solidFonts, bool, false) \
PO_DESC(subImageFix, bool, false) \
PO_DESC(enableBlitting, bool, true) \
PO_DESC(maxTextureSize, int, 0) \
PO_DESC(gameFolder, std::string, ".") \
PO_DESC(anyAltToggleFS, bool, false) \
PO_DESC(enableReset, bool, true) \
@ -180,6 +190,27 @@ void Config::read(int argc, char *argv[])
// Not gonna take your shit boost
#define GUARD_ALL( exp ) try { exp } catch(...) {}
editor.debug = false;
editor.battleTest = false;
/* Read arguments sent from the editor */
if (argc > 1)
{
std::string argv1 = argv[1];
/* RGSS1 uses "debug", 2 and 3 use "test" */
if (argv1 == "debug" || argv1 == "test")
editor.debug = true;
else if (argv1 == "btest")
editor.battleTest = true;
/* Fix offset */
if (editor.debug || editor.battleTest)
{
argc--;
argv++;
}
}
#define PO_DESC(key, type, def) (#key, po::value< type >()->default_value(def))
po::options_description podesc;
@ -226,7 +257,7 @@ void Config::read(int argc, char *argv[])
PO_DESC_ALL;
GUARD_ALL( preloadScripts = vm["preloadScript"].as<StringVec>(); );
GUARD_ALL( preloadScripts = setFromVec(vm["preloadScript"].as<StringVec>()); );
GUARD_ALL( rtps = vm["RTP"].as<StringVec>(); );
@ -280,26 +311,32 @@ void Config::readGameINI()
return;
}
po::options_description podesc;
podesc.add_options()
("Game.Title", po::value<std::string>())
("Game.Scripts", po::value<std::string>())
;
po::variables_map vm;
std::string iniFilename = execName + ".ini";
SDLRWStream iniFile(iniFilename.c_str(), "r");
if (iniFile)
{
try
INIConfiguration ic;
if(ic.load(iniFile.stream()))
{
po::store(po::parse_config_file(iniFile.stream(), podesc, true), vm);
po::notify(vm);
GUARD_ALL( game.title = ic.getStringProperty("Game", "Title"); );
GUARD_ALL( game.scripts = ic.getStringProperty("Game", "Scripts"); );
strReplace(game.scripts, '\\', '/');
if (game.title.empty())
{
Debug() << iniFilename + ": Could not find Game.Title property";
}
if (game.scripts.empty())
{
Debug() << iniFilename + ": Could not find Game.Scripts property";
}
}
catch (po::error &error)
else
{
Debug() << iniFilename + ":" << error.what();
Debug() << iniFilename + ": Failed to parse ini file";
}
}
else
@ -307,11 +344,6 @@ void Config::readGameINI()
Debug() << "FAILED to open" << iniFilename;
}
GUARD_ALL( game.title = vm["Game.Title"].as<std::string>(); );
GUARD_ALL( game.scripts = vm["Game.Scripts"].as<std::string>(); );
strReplace(game.scripts, '\\', '/');
#ifdef INI_ENCODING
/* Can add more later */
const char *languages[] =
@ -348,11 +380,7 @@ void Config::readGameINI()
size_t inLen = game.title.size();
size_t outLen = inLen * 4;
std::string buf(outLen, '\0');
#ifdef _MSC_VER
const char *inPtr = game.title.c_str();
#else
char *inPtr = const_cast<char*>(game.title.c_str());
#endif
char *outPtr = const_cast<char*>(buf.c_str());
errno = 0;

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -24,49 +24,7 @@
#include <string>
#include <vector>
struct TouchOverlay
{
std::string image;
struct Button
{
enum Shape
{
Rectangle,
Circle,
Triangle
};
std::string id;
std::string target;
Shape shape;
int x;
int y;
union
{
struct
{
int width;
int height;
} r;
struct
{
int radius;
} c;
struct
{
int x1, y1;
int x2, y2;
} t;
} u;
};
std::vector<Button> buttons;
};
#include <set>
struct Config
{
@ -83,6 +41,7 @@ struct Config
int defScreenW;
int defScreenH;
std::string windowTitle;
int fixedFramerate;
bool frameSkip;
@ -91,6 +50,8 @@ struct Config
bool solidFonts;
bool subImageFix;
bool enableBlitting;
int maxTextureSize;
std::string gameFolder;
bool anyAltToggleFS;
@ -120,13 +81,19 @@ struct Config
bool useScriptNames;
std::string customScript;
std::vector<std::string> preloadScripts;
std::set<std::string> preloadScripts;
std::vector<std::string> rtps;
std::vector<std::string> fontSubs;
std::vector<std::string> rubyLoadpaths;
/* Editor flags */
struct {
bool debug;
bool battleTest;
} editor;
/* Game INI contents */
struct {
std::string scripts;

View File

@ -1,17 +0,0 @@
#ifndef MKXP_CROSSPLATFORM_H
#define MKXP_CROSSPLATFORM_H
#ifdef _MSC_VER
//#define _CRT_SECURE_NO_DEPRECATE //should be defined in binding-mri's preprocessor for vsnprintf, fopen
#include <direct.h>
#ifndef snprintf
#define snprintf _snprintf
#endif
#ifndef chdir
#define chdir _chdir
#endif
#endif
#endif //MKXP_CROSSPLATFORM_H

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -61,9 +61,9 @@ struct Vec4
return (x == other.x && y == other.y && z == other.z && w == other.w);
}
bool xyzHasEffect() const
bool xyzNotNull() const
{
return (x != 0.0 || y != 0.0 || z != 0.0);
return (x != 0.0f || y != 0.0f || z != 0.0f);
}
};
@ -88,6 +88,11 @@ struct Vec2i
return x == other.x && y == other.y;
}
bool operator!=(const Vec2i &other) const
{
return !(*this == other);
}
Vec2i &operator+=(const Vec2i &value)
{
x += value.x;
@ -131,6 +136,11 @@ struct Vec2i
return Vec2i(x % value, y % value);
}
Vec2i operator&(unsigned value) const
{
return Vec2i(x & value, y & value);
}
Vec2i operator-() const
{
return Vec2i(-x, -y);
@ -176,6 +186,11 @@ struct IntRect : SDL_Rect
w == other.w && h == other.h);
}
bool operator!=(const IntRect &other) const
{
return !(*this == other);
}
Vec2i pos() const
{
return Vec2i(x, y);
@ -259,13 +274,13 @@ struct NormValue
NormValue(int unNorm)
: unNorm(unNorm),
norm(unNorm / 255.0)
norm(unNorm / 255.0f)
{}
void operator =(int value)
{
unNorm = clamp(value, 0, 255);
norm = unNorm / 255.0;
norm = unNorm / 255.0f;
}
bool operator ==(int value) const

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -19,7 +19,6 @@
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
*/
#include "crossplatform.h"
#include "eventthread.h"
#include <SDL_events.h>
@ -28,9 +27,9 @@
#include <SDL_timer.h>
#include <SDL_thread.h>
#include <SDL_touch.h>
#include <SDL_rect.h>
#include <al.h>
#include <alc.h>
#include <alext.h>
#include "sharedstate.h"
@ -84,6 +83,7 @@ enum
REQUEST_SETCURSORVISIBLE,
UPDATE_FPS,
UPDATE_SCREEN_RECT,
EVENT_COUNT
};
@ -112,7 +112,11 @@ void EventThread::process(RGSSThreadData &rtData)
UnidirMessage<Vec2i> &windowSizeMsg = rtData.windowSizeMsg;
initALCFunctions(rtData.alcDev);
// XXX this function breaks input focus on OSX
#ifndef __MACOSX__
SDL_SetEventFilter(eventFilter, &rtData);
#endif
fullscreen = rtData.config.fullscreen;
int toggleFSMod = rtData.config.anyAltToggleFS ? KMOD_ALT : KMOD_LALT;
@ -128,7 +132,11 @@ void EventThread::process(RGSSThreadData &rtData)
bool displayingFPS = false;
bool cursorInWindow = false;
bool windowFocused = false;
/* Will be updated eventually */
SDL_Rect gameScreen = { 0, 0, 0, 0 };
/* SDL doesn't send an initial FOCUS_GAINED event */
bool windowFocused = true;
bool terminate = false;
@ -165,7 +173,7 @@ void EventThread::process(RGSSThreadData &rtData)
delete sMenu;
sMenu = 0;
updateCursorState(cursorInWindow && windowFocused);
updateCursorState(cursorInWindow && windowFocused, gameScreen);
}
continue;
@ -206,14 +214,14 @@ void EventThread::process(RGSSThreadData &rtData)
case SDL_WINDOWEVENT_ENTER :
cursorInWindow = true;
mouseState.inWindow = true;
updateCursorState(cursorInWindow && windowFocused && !sMenu);
updateCursorState(cursorInWindow && windowFocused && !sMenu, gameScreen);
break;
case SDL_WINDOWEVENT_LEAVE :
cursorInWindow = false;
mouseState.inWindow = false;
updateCursorState(cursorInWindow && windowFocused && !sMenu);
updateCursorState(cursorInWindow && windowFocused && !sMenu, gameScreen);
break;
@ -224,13 +232,13 @@ void EventThread::process(RGSSThreadData &rtData)
case SDL_WINDOWEVENT_FOCUS_GAINED :
windowFocused = true;
updateCursorState(cursorInWindow && windowFocused && !sMenu);
updateCursorState(cursorInWindow && windowFocused && !sMenu, gameScreen);
break;
case SDL_WINDOWEVENT_FOCUS_LOST :
windowFocused = false;
updateCursorState(cursorInWindow && windowFocused && !sMenu);
updateCursorState(cursorInWindow && windowFocused && !sMenu, gameScreen);
resetInputStates();
break;
@ -263,7 +271,7 @@ void EventThread::process(RGSSThreadData &rtData)
if (!sMenu)
{
sMenu = new SettingsMenu(rtData);
updateCursorState(false);
updateCursorState(false, gameScreen);
}
sMenu->raise();
@ -287,14 +295,14 @@ void EventThread::process(RGSSThreadData &rtData)
if (fullscreen)
{
/* Prevent fullscreen flicker */
strncpy(pendingTitle, rtData.config.game.title.c_str(),
strncpy(pendingTitle, rtData.config.windowTitle.c_str(),
sizeof(pendingTitle));
havePendingTitle = true;
break;
}
SDL_SetWindowTitle(win, rtData.config.game.title.c_str());
SDL_SetWindowTitle(win, rtData.config.windowTitle.c_str());
}
break;
@ -369,6 +377,7 @@ void EventThread::process(RGSSThreadData &rtData)
case SDL_MOUSEMOTION :
mouseState.x = event.motion.x;
mouseState.y = event.motion.y;
updateCursorState(cursorInWindow, gameScreen);
break;
case SDL_FINGERDOWN :
@ -400,7 +409,7 @@ void EventThread::process(RGSSThreadData &rtData)
case REQUEST_MESSAGEBOX :
SDL_ShowSimpleMessageBox(event.user.code,
rtData.config.game.title.c_str(),
rtData.config.windowTitle.c_str(),
(const char*) event.user.data1, win);
free(event.user.data1);
msgBoxDone.set();
@ -408,7 +417,7 @@ void EventThread::process(RGSSThreadData &rtData)
case REQUEST_SETCURSORVISIBLE :
showCursor = event.user.code;
updateCursorState(cursorInWindow);
updateCursorState(cursorInWindow, gameScreen);
break;
case UPDATE_FPS :
@ -419,7 +428,7 @@ void EventThread::process(RGSSThreadData &rtData)
break;
snprintf(buffer, sizeof(buffer), "%s - %d FPS",
rtData.config.game.title.c_str(), event.user.code);
rtData.config.windowTitle.c_str(), event.user.code);
/* Updating the window title in fullscreen
* mode seems to cause flickering */
@ -433,6 +442,15 @@ void EventThread::process(RGSSThreadData &rtData)
SDL_SetWindowTitle(win, buffer);
break;
case UPDATE_SCREEN_RECT :
gameScreen.x = event.user.windowID;
gameScreen.y = event.user.code;
gameScreen.w = reinterpret_cast<intptr_t>(event.user.data1);
gameScreen.h = reinterpret_cast<intptr_t>(event.user.data2);
updateCursorState(cursorInWindow, gameScreen);
break;
}
}
@ -491,13 +509,13 @@ int EventThread::eventFilter(void *data, SDL_Event *event)
Debug() << "SDL_APP_LOWMEMORY";
return 0;
case SDL_RENDER_TARGETS_RESET :
Debug() << "****** SDL_RENDER_TARGETS_RESET";
return 0;
// case SDL_RENDER_TARGETS_RESET :
// Debug() << "****** SDL_RENDER_TARGETS_RESET";
// return 0;
case SDL_RENDER_DEVICE_RESET :
Debug() << "****** SDL_RENDER_DEVICE_RESET";
return 0;
// case SDL_RENDER_DEVICE_RESET :
// Debug() << "****** SDL_RENDER_DEVICE_RESET";
// return 0;
}
return 1;
@ -527,9 +545,13 @@ void EventThread::setFullscreen(SDL_Window *win, bool mode)
fullscreen = mode;
}
void EventThread::updateCursorState(bool inWindow)
void EventThread::updateCursorState(bool inWindow,
const SDL_Rect &screen)
{
if (inWindow)
SDL_Point pos = { mouseState.x, mouseState.y };
bool inScreen = inWindow && SDL_PointInRect(&pos, &screen);
if (inScreen)
SDL_ShowCursor(showCursor ? SDL_TRUE : SDL_FALSE);
else
SDL_ShowCursor(SDL_TRUE);
@ -635,6 +657,19 @@ void EventThread::notifyFrame()
SDL_PushEvent(&event);
}
void EventThread::notifyGameScreenChange(const SDL_Rect &screen)
{
/* We have to get a bit hacky here to fit the rectangle
* data into the user event struct */
SDL_Event event;
event.type = usrIdStart + UPDATE_SCREEN_RECT;
event.user.windowID = screen.x;
event.user.code = screen.y;
event.user.data1 = reinterpret_cast<void*>(screen.w);
event.user.data2 = reinterpret_cast<void*>(screen.h);
SDL_PushEvent(&event);
}
void SyncPoint::haltThreads()
{
if (mainSync.locked)

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -36,8 +36,9 @@
#include <stdint.h>
#include <alc.h>
struct RGSSThreadData;
typedef struct ALCdevice_struct ALCdevice;
struct SDL_Window;
union SDL_Event;
@ -98,12 +99,16 @@ public:
/* RGSS thread calls this once per frame */
void notifyFrame();
/* Called on game screen (size / offset) changes */
void notifyGameScreenChange(const SDL_Rect &screen);
private:
static int eventFilter(void *, SDL_Event*);
void resetInputStates();
void setFullscreen(SDL_Window *, bool mode);
void updateCursorState(bool inWindow);
void updateCursorState(bool inWindow,
const SDL_Rect &screen);
bool fullscreen;
bool showCursor;

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -22,8 +22,6 @@
#ifndef EXCEPTION_H
#define EXCEPTION_H
#include "crossplatform.h"
#include <string>
#include <stdio.h>
#include <stdarg.h>

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -19,7 +19,6 @@
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
*/
#include "crossplatform.h"
#include "filesystem.h"
#include "rgssad.h"
@ -38,6 +37,7 @@
#include <string.h>
#include <algorithm>
#include <vector>
#include <stack>
#ifdef __APPLE__
#include <iconv.h>
@ -250,215 +250,93 @@ strcpySafe(char *dst, const char *src,
return cpyMax;
}
/* Attempt to locate an extension string in a filename.
* Either a pointer into the input string pointing at the
* extension, or null is returned */
static const char *
findExt(const char *filename)
{
size_t len;
for (len = strlen(filename); len > 0; --len)
{
if (filename[len] == '/')
return 0;
if (filename[len] == '.')
return &filename[len+1];
}
return 0;
}
static void
initReadOps(PHYSFS_File *handle,
SDL_RWops &ops,
bool freeOnClose)
{
ops.size = SDL_RWopsSize;
ops.seek = SDL_RWopsSeek;
ops.read = SDL_RWopsRead;
ops.write = SDL_RWopsWrite;
if (freeOnClose)
ops.close = SDL_RWopsCloseFree;
else
ops.close = SDL_RWopsClose;
ops.type = SDL_RWOPS_PHYSFS;
ops.hidden.unknown.data1 = handle;
}
static void strTolower(std::string &str)
{
for (size_t i = 0; i < str.size(); ++i)
str[i] = tolower(str[i]);
}
const Uint32 SDL_RWOPS_PHYSFS = SDL_RWOPS_UNKNOWN+10;
struct FileSystemPrivate
{
/* Maps: lower case filepath without extension,
* To: mixed case full filepath
* This is for compatibility with games that take Windows'
* case insensitivity for granted */
/* Maps: lower case full filepath,
* To: mixed case full filepath */
BoostHash<std::string, std::string> pathCache;
/* Maps: lower case directory path,
* To: list of lower case filenames */
BoostHash<std::string, std::vector<std::string> > fileLists;
/* This is for compatibility with games that take Windows'
* case insensitivity for granted */
bool havePathCache;
/* Attempt to locate an extension string in a filename.
* Either a pointer into the input string pointing at the
* extension, or null is returned */
const char *findExt(const char *filename)
{
size_t len;
for (len = strlen(filename); len > 0; --len)
{
if (filename[len] == '/')
return 0;
if (filename[len] == '.')
return &filename[len+1];
}
return 0;
}
struct CompleteFilenameData
{
bool found;
/* Contains the incomplete filename we're looking for;
* when found, we write the complete filename into this
* same buffer */
char *outBuf;
/* Length of incomplete file name */
size_t filenameLen;
/* Maximum we can write into outBuf */
size_t outBufN;
};
static void completeFilenameRegCB(void *data, const char *,
const char *fname)
{
CompleteFilenameData &d = *static_cast<CompleteFilenameData*>(data);
if (d.found)
return;
if (strncmp(d.outBuf, fname, d.filenameLen) != 0)
return;
/* If fname matches up to a following '.' (meaning the rest is part
* of the extension), or up to a following '\0' (full match), we've
* found our file */
switch (fname[d.filenameLen])
{
case '.' :
/* Overwrite the incomplete file name we looked for with
* the full version containing any extensions */
strcpySafe(d.outBuf, fname, d.outBufN, -1);
case '\0' :
d.found = true;
}
}
bool completeFilenameReg(const char *filepath,
char *outBuffer,
size_t outN)
{
strcpySafe(outBuffer, filepath, outN, -1);
size_t len = strlen(outBuffer);
char *delim;
/* Find the deliminator separating directory and file name */
for (delim = outBuffer + len; delim > outBuffer; --delim)
if (*delim == '/')
break;
bool root = (delim == outBuffer);
CompleteFilenameData d;
if (!root)
{
/* If we have such a deliminator, we set it to '\0' so we
* can pass the first half to PhysFS as the directory name,
* and compare all filenames against the second half */
d.outBuf = delim+1;
d.filenameLen = len - (delim - outBuffer + 1);
*delim = '\0';
}
else
{
/* Otherwise the file is in the root directory */
d.outBuf = outBuffer;
d.filenameLen = len - (delim - outBuffer);
}
d.found = false;
d.outBufN = outN - (d.outBuf - outBuffer);
PHYSFS_enumerateFilesCallback(root ? "" : outBuffer, completeFilenameRegCB, &d);
if (!d.found)
return false;
/* Now we put the deliminator back in to form the completed
* file path (if required) */
if (delim != outBuffer)
*delim = '/';
return true;
}
bool completeFilenamePC(const char *filepath,
char *outBuffer,
size_t outN)
{
std::string lowCase(filepath);
for (size_t i = 0; i < lowCase.size(); ++i)
lowCase[i] = tolower(lowCase[i]);
if (!pathCache.contains(lowCase))
return false;
const std::string &fullPath = pathCache[lowCase];
strcpySafe(outBuffer, fullPath.c_str(), outN, fullPath.size());
return true;
}
bool completeFilename(const char *filepath,
char *outBuffer,
size_t outN)
{
if (havePathCache)
return completeFilenamePC(filepath, outBuffer, outN);
else
return completeFilenameReg(filepath, outBuffer, outN);
}
PHYSFS_File *openReadHandle(const char *filename,
char *extBuf,
size_t extBufN)
{
char found[512];
if (!completeFilename(filename, found, sizeof(found)))
throw Exception(Exception::NoFileError, "%s", filename);
PHYSFS_File *handle = PHYSFS_openRead(found);
if (!handle)
throw Exception(Exception::PHYSFSError, "PhysFS: %s", PHYSFS_getLastError());
if (!extBuf)
return handle;
for (char *q = found+strlen(found); q > found; --q)
{
if (*q == '/')
break;
if (*q != '.')
continue;
strcpySafe(extBuf, q+1, extBufN, -1);
break;
}
return handle;
}
void initReadOps(PHYSFS_File *handle,
SDL_RWops &ops,
bool freeOnClose)
{
ops.size = SDL_RWopsSize;
ops.seek = SDL_RWopsSeek;
ops.read = SDL_RWopsRead;
ops.write = SDL_RWopsWrite;
if (freeOnClose)
ops.close = SDL_RWopsCloseFree;
else
ops.close = SDL_RWopsClose;
ops.type = SDL_RWOPS_PHYSFS;
ops.hidden.unknown.data1 = handle;
}
};
static void throwPhysfsError(const char *desc)
{
PHYSFS_ErrorCode ec = PHYSFS_getLastErrorCode();
const char *englishStr = PHYSFS_getErrorByCode(ec);
throw Exception(Exception::PHYSFSError, "%s: %s", desc, englishStr);
}
FileSystem::FileSystem(const char *argv0,
bool allowSymlinks)
{
if (PHYSFS_init(argv0) == 0)
throwPhysfsError("Error initializing PhysFS");
/* One error (=return 0) turns the whole product to 0 */
int er = 1;
er *= PHYSFS_registerArchiver(&RGSS1_Archiver);
er *= PHYSFS_registerArchiver(&RGSS2_Archiver);
er *= PHYSFS_registerArchiver(&RGSS3_Archiver);
if (er == 0)
throwPhysfsError("Error registering PhysFS RGSS archiver");
p = new FileSystemPrivate;
p->havePathCache = false;
PHYSFS_init(argv0);
PHYSFS_registerArchiver(&RGSS1_Archiver);
PHYSFS_registerArchiver(&RGSS2_Archiver);
PHYSFS_registerArchiver(&RGSS3_Archiver);
if (allowSymlinks)
PHYSFS_permitSymbolicLinks(1);
}
@ -485,99 +363,107 @@ void FileSystem::addPath(const char *path)
}
}
#ifdef __APPLE__
struct CacheEnumCBData
struct CacheEnumData
{
FileSystemPrivate *p;
std::stack<std::vector<std::string>*> fileLists;
#ifdef __APPLE__
iconv_t nfd2nfc;
char buf[512];
#endif
CacheEnumCBData(FileSystemPrivate *fsp)
CacheEnumData(FileSystemPrivate *p)
: p(p)
{
p = fsp;
#ifdef __APPLE__
nfd2nfc = iconv_open("utf-8", "utf-8-mac");
#endif
}
~CacheEnumCBData()
~CacheEnumData()
{
#ifdef __APPLE__
iconv_close(nfd2nfc);
#endif
}
void nfcFromNfd(char *dst, const char *src, size_t dstSize)
/* Converts in-place */
void toNFC(char *inout)
{
size_t srcSize = strlen(src);
#ifdef __APPLE__
size_t srcSize = strlen(inout);
size_t bufSize = sizeof(buf);
char *bufPtr = buf;
char *inoutPtr = inout;
/* Reserve room for null terminator */
--dstSize;
/* iconv takes a char** instead of a const char**, even though
* the string data isn't written to. */
--bufSize;
iconv(nfd2nfc,
const_cast<char**>(&src), &srcSize,
&dst, &dstSize);
&inoutPtr, &srcSize,
&bufPtr, &bufSize);
/* Null-terminate */
*dst = 0;
*bufPtr = 0;
strcpy(inout, buf);
#else
(void) inout;
#endif
}
};
#endif
static void cacheEnumCB(void *d, const char *origdir,
const char *fname)
static PHYSFS_EnumerateCallbackResult
cacheEnumCB(void *d, const char *origdir, const char *fname)
{
#ifdef __APPLE__
CacheEnumCBData *data = static_cast<CacheEnumCBData*>(d);
FileSystemPrivate *p = data->p;
#else
FileSystemPrivate *p = static_cast<FileSystemPrivate*>(d);
#endif
CacheEnumData &data = *static_cast<CacheEnumData*>(d);
char fullPath[512];
char buf[512];
if (*origdir == '\0')
strncpy(buf, fname, sizeof(buf));
if (!*origdir)
snprintf(fullPath, sizeof(fullPath), "%s", fname);
else
snprintf(buf, sizeof(buf), "%s/%s", origdir, fname);
snprintf(fullPath, sizeof(fullPath), "%s/%s", origdir, fname);
#ifdef __APPLE__
char bufNfc[sizeof(buf)];
data->nfcFromNfd(bufNfc, buf, sizeof(bufNfc));
#else
char *const bufNfc = buf;
#endif
/* Deal with OSX' weird UTF-8 standards */
data.toNFC(fullPath);
char *ptr = bufNfc;
std::string mixedCase(fullPath);
std::string lowerCase = mixedCase;
strTolower(lowerCase);
/* Trim leading slash */
if (*ptr == '/')
++ptr;
PHYSFS_Stat stat;
PHYSFS_stat(fullPath, &stat);
std::string mixedCase(ptr);
for (char *q = bufNfc; *q; ++q)
*q = tolower(*q);
p->pathCache.insert(std::string(ptr), mixedCase);
for (char *q = ptr+strlen(ptr); q > ptr; --q)
if (stat.filetype == PHYSFS_FILETYPE_DIRECTORY)
{
if (*q == '/')
break;
/* Create a new list for this directory */
std::vector<std::string> &list = data.p->fileLists[lowerCase];
if (*q != '.')
continue;
/* Iterate over its contents */
data.fileLists.push(&list);
PHYSFS_enumerate(fullPath, cacheEnumCB, d);
data.fileLists.pop();
}
else
{
/* Get the file list for the directory we're currently
* traversing and append this filename to it */
std::vector<std::string> &list = *data.fileLists.top();
std::string lowerFilename(fname);
strTolower(lowerFilename);
list.push_back(lowerFilename);
*q = '\0';
p->pathCache.insert(std::string(ptr), mixedCase);
/* Add the lower -> mixed mapping of the file's full path */
data.p->pathCache.insert(lowerCase, mixedCase);
}
PHYSFS_enumerateFilesCallback(mixedCase.c_str(), cacheEnumCB, d);
return PHYSFS_ENUM_OK;
}
void FileSystem::createPathCache()
{
#ifdef __APPLE__
CacheEnumCBData data(p);
PHYSFS_enumerateFilesCallback("", cacheEnumCB, &data);
#else
PHYSFS_enumerateFilesCallback("", cacheEnumCB, p);
#endif
CacheEnumData data(p);
data.fileLists.push(&p->fileLists[""]);
PHYSFS_enumerate("", cacheEnumCB, &data);
p->havePathCache = true;
}
@ -588,17 +474,16 @@ struct FontSetsCBData
SharedFontState *sfs;
};
static void fontSetEnumCB(void *data, const char *,
const char *fname)
static PHYSFS_EnumerateCallbackResult
fontSetEnumCB (void *data, const char *dir, const char *fname)
{
FontSetsCBData *d = static_cast<FontSetsCBData*>(data);
FileSystemPrivate *p = d->p;
/* Only consider filenames with font extensions */
const char *ext = p->findExt(fname);
const char *ext = findExt(fname);
if (!ext)
return;
return PHYSFS_ENUM_OK;
char lowExt[8];
size_t i;
@ -608,40 +493,195 @@ static void fontSetEnumCB(void *data, const char *,
lowExt[i] = '\0';
if (strcmp(lowExt, "ttf") && strcmp(lowExt, "otf"))
return;
return PHYSFS_ENUM_OK;
char filename[512];
snprintf(filename, sizeof(filename), "Fonts/%s", fname);
snprintf(filename, sizeof(filename), "%s/%s", dir, fname);
PHYSFS_File *handle = PHYSFS_openRead(filename);
if (!handle)
return;
return PHYSFS_ENUM_ERROR;
SDL_RWops ops;
p->initReadOps(handle, ops, false);
initReadOps(handle, ops, false);
d->sfs->initFontSetCB(ops, filename);
SDL_RWclose(&ops);
return PHYSFS_ENUM_OK;
}
/* Basically just a case-insensitive search
* for the folder "Fonts"... */
static PHYSFS_EnumerateCallbackResult
findFontsFolderCB(void *data, const char *, const char *fname)
{
size_t i = 0;
char buffer[512];
const char *s = fname;
while (*s && i < sizeof(buffer))
buffer[i++] = tolower(*s++);
buffer[i] = '\0';
if (strcmp(buffer, "fonts") == 0)
PHYSFS_enumerate(fname, fontSetEnumCB, data);
return PHYSFS_ENUM_OK;
}
void FileSystem::initFontSets(SharedFontState &sfs)
{
FontSetsCBData d = { p, &sfs };
PHYSFS_enumerateFilesCallback("Fonts", fontSetEnumCB, &d);
PHYSFS_enumerate("", findFontsFolderCB, &d);
}
void FileSystem::openRead(SDL_RWops &ops,
const char *filename,
bool freeOnClose,
char *extBuf,
size_t extBufN)
struct OpenReadEnumData
{
PHYSFS_File *handle = p->openReadHandle(filename, extBuf, extBufN);
FileSystem::OpenHandler &handler;
SDL_RWops ops;
p->initReadOps(handle, ops, freeOnClose);
/* The filename (without directory) we're looking for */
const char *filename;
size_t filenameN;
/* Optional hash to translate full filepaths
* (used with path cache) */
BoostHash<std::string, std::string> *pathTrans;
/* Number of files we've attempted to read and parse */
size_t matchCount;
bool stopSearching;
/* In case of a PhysFS error, save it here so it
* doesn't get changed before we get back into our code */
const char *physfsError;
OpenReadEnumData(FileSystem::OpenHandler &handler,
const char *filename, size_t filenameN,
BoostHash<std::string, std::string> *pathTrans)
: handler(handler), filename(filename), filenameN(filenameN),
pathTrans(pathTrans), matchCount(0), stopSearching(false),
physfsError(0)
{}
};
static PHYSFS_EnumerateCallbackResult
openReadEnumCB(void *d, const char *dirpath, const char *filename)
{
OpenReadEnumData &data = *static_cast<OpenReadEnumData*>(d);
char buffer[512];
const char *fullPath;
if (data.stopSearching)
return PHYSFS_ENUM_STOP;
/* If there's not even a partial match, continue searching */
if (strncmp(filename, data.filename, data.filenameN) != 0)
return PHYSFS_ENUM_OK;
if (!*dirpath)
{
fullPath = filename;
}
else
{
snprintf(buffer, sizeof(buffer), "%s/%s", dirpath, filename);
fullPath = buffer;
}
char last = filename[data.filenameN];
/* If fname matches up to a following '.' (meaning the rest is part
* of the extension), or up to a following '\0' (full match), we've
* found our file */
if (last != '.' && last != '\0')
return PHYSFS_ENUM_STOP;
/* If the path cache is active, translate from lower case
* to mixed case path */
if (data.pathTrans)
fullPath = (*data.pathTrans)[fullPath].c_str();
PHYSFS_File *phys = PHYSFS_openRead(fullPath);
if (!phys)
{
/* Failing to open this file here means there must
* be a deeper rooted problem somewhere within PhysFS.
* Just abort alltogether. */
data.stopSearching = true;
data.physfsError = PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode());
return PHYSFS_ENUM_ERROR;
}
initReadOps(phys, data.ops, false);
const char *ext = findExt(filename);
if (data.handler.tryRead(data.ops, ext))
data.stopSearching = true;
++data.matchCount;
return PHYSFS_ENUM_OK;
}
void FileSystem::openRead(OpenHandler &handler, const char *filename)
{
char buffer[512];
size_t len = strcpySafe(buffer, filename, sizeof(buffer), -1);
char *delim;
if (p->havePathCache)
for (size_t i = 0; i < len; ++i)
buffer[i] = tolower(buffer[i]);
/* Find the deliminator separating directory and file name */
for (delim = buffer + len; delim > buffer; --delim)
if (*delim == '/')
break;
const bool root = (delim == buffer);
const char *file = buffer;
const char *dir = "";
if (!root)
{
/* Cut the buffer in half so we can use it
* for both filename and directory path */
*delim = '\0';
file = delim+1;
dir = buffer;
}
OpenReadEnumData data(handler, file, len + buffer - delim - !root,
p->havePathCache ? &p->pathCache : 0);
if (p->havePathCache)
{
/* Get the list of files contained in this directory
* and manually iterate over them */
const std::vector<std::string> &fileList = p->fileLists[dir];
for (size_t i = 0; i < fileList.size(); ++i)
openReadEnumCB(&data, dir, fileList[i].c_str());
}
else
{
PHYSFS_enumerate(dir, openReadEnumCB, &data);
}
if (data.physfsError)
throw Exception(Exception::PHYSFSError, "PhysFS: %s", data.physfsError);
if (data.matchCount == 0)
throw Exception(Exception::NoFileError, "%s", filename);
}
void FileSystem::openReadRaw(SDL_RWops &ops,
@ -651,12 +691,10 @@ void FileSystem::openReadRaw(SDL_RWops &ops,
PHYSFS_File *handle = PHYSFS_openRead(filename);
assert(handle);
p->initReadOps(handle, ops, freeOnClose);
initReadOps(handle, ops, freeOnClose);
}
bool FileSystem::exists(const char *filename)
{
char found[512];
return p->completeFilename(filename, found, sizeof(found));
return PHYSFS_exists(filename);
}

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -43,17 +43,28 @@ public:
* available font assets */
void initFontSets(SharedFontState &sfs);
void openRead(SDL_RWops &ops,
const char *filename,
bool freeOnClose = false,
char *extBuf = 0,
size_t extBufN = 0);
struct OpenHandler
{
/* Try to read and interpret data provided from ops.
* If data cannot be parsed, return false, otherwise true.
* Can be called multiple times until a parseable file is found.
* It's the handler's responsibility to close every passed
* ops structure, even when data could not be parsed.
* After this function returns, ops becomes invalid, so don't take
* references to it. Instead, copy the structure without closing
* if you need to further read from it later. */
virtual bool tryRead(SDL_RWops &ops, const char *ext) = 0;
};
void openRead(OpenHandler &handler,
const char *filename);
/* Circumvents extension supplementing */
void openReadRaw(SDL_RWops &ops,
const char *filename,
bool freeOnClose = false);
/* Does not perform extension supplementing */
bool exists(const char *filename);
private:

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -6,10 +6,6 @@
#include "debugwriter.h"
#ifdef SHARED_FLUID
#include <fluidsynth.h>
#endif
#if __LINUX__ || __ANDROID__
#define FLUID_LIB "libfluidsynth.so.1"
#elif __MACOSX__

View File

@ -1,6 +1,12 @@
#ifndef FLUIDFUN_H
#define FLUIDFUN_H
#ifdef SHARED_FLUID
# include <fluidsynth.h>
#else
# define FLUIDSYNTH_VERSION_MAJOR 2
#endif
typedef struct _fluid_hashtable_t fluid_settings_t;
typedef struct _fluid_synth_t fluid_synth_t;
@ -19,7 +25,12 @@ typedef int (*FLUIDSYNTHPROGRAMCHANGEPROC)(fluid_synth_t* synth, int chan, int p
typedef fluid_settings_t* (*NEWFLUIDSETTINGSPROC)(void);
typedef fluid_synth_t* (*NEWFLUIDSYNTHPROC)(fluid_settings_t* settings);
typedef void (*DELETEFLUIDSETTINGSPROC)(fluid_settings_t* settings);
#if FLUIDSYNTH_VERSION_MAJOR == 1
typedef int (*DELETEFLUIDSYNTHPROC)(fluid_synth_t* synth);
#else
typedef void (*DELETEFLUIDSYNTHPROC)(fluid_synth_t* synth);
#endif
#define FLUID_FUNCS \
FLUID_FUN(settings_setnum, FLUIDSETTINGSSETNUMPROC) \

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -174,7 +174,7 @@ _TTF_Font *SharedFontState::getFont(std::string family,
// FIXME 0.9 is guesswork at this point
// float gamma = (96.0/45.0)*(5.0/14.0)*(size-5);
// font = TTF_OpenFontRW(ops, 1, gamma /** .90*/);
font = TTF_OpenFontRW(ops, 1, size* .90);
font = TTF_OpenFontRW(ops, 1, size* 0.90f);
if (!font)
throw Exception(Exception::SDLError, "%s", SDL_GetError());
@ -184,7 +184,7 @@ _TTF_Font *SharedFontState::getFont(std::string family,
return font;
}
bool SharedFontState::fontPresent(std::string family)
bool SharedFontState::fontPresent(std::string family) const
{
/* Check for substitutions */
if (p->subs.contains(family))
@ -202,6 +202,26 @@ _TTF_Font *SharedFontState::openBundled(int size)
return TTF_OpenFontRW(ops, 1, size);
}
void pickExistingFontName(const std::vector<std::string> &names,
std::string &out,
const SharedFontState &sfs)
{
/* Note: In RMXP, a names array with no existing entry
* results in no text being drawn at all (same for "" and []);
* we can't replicate this in mkxp due to the default substitute. */
for (size_t i = 0; i < names.size(); ++i)
{
if (sfs.fontPresent(names[i]))
{
out = names[i];
return;
}
}
out = "";
}
struct FontPrivate
{
@ -229,15 +249,15 @@ struct FontPrivate
static Color defaultColorTmp;
static Color defaultOutColorTmp;
static std::vector<std::string> initialDefaultNames;
/* The actual font is opened as late as possible
* (when it is queried by a Bitmap), prior it is
* set to null */
TTF_Font *sdlFont;
FontPrivate(const char *name = 0,
int size = 0)
: name(name ? std::string(name) : defaultName),
size(size ? size : defaultSize),
FontPrivate(int size)
: size(size),
bold(defaultBold),
italic(defaultItalic),
outline(defaultOutline),
@ -290,6 +310,8 @@ Color *FontPrivate::defaultOutColor = &FontPrivate::defaultOutColorTmp;
Color FontPrivate::defaultColorTmp(255, 255, 255, 255);
Color FontPrivate::defaultOutColorTmp(0, 0, 0, 128);
std::vector<std::string> FontPrivate::initialDefaultNames;
bool Font::doesExist(const char *name)
{
if (!name)
@ -298,10 +320,15 @@ bool Font::doesExist(const char *name)
return shState->fontState().fontPresent(name);
}
Font::Font(const char *name,
Font::Font(const std::vector<std::string> *names,
int size)
{
p = new FontPrivate(name, size);
p = new FontPrivate(size ? size : FontPrivate::defaultSize);
if (names)
setName(*names);
else
p->name = FontPrivate::defaultName;
}
Font::Font(const Font &other)
@ -321,17 +348,9 @@ const Font &Font::operator=(const Font &o)
return o;
}
const char *Font::getName() const
void Font::setName(const std::vector<std::string> &names)
{
return p->name.c_str();
}
void Font::setName(const char *value)
{
if (p->name == value)
return;
p->name = value;
pickExistingFontName(names, p->name, shState->fontState());
p->sdlFont = 0;
}
@ -367,14 +386,15 @@ DEF_ATTR_SIMPLE_STATIC(Font, DefaultOutline, bool, FontPrivate::defaultOutli
DEF_ATTR_SIMPLE_STATIC(Font, DefaultColor, Color&, *FontPrivate::defaultColor)
DEF_ATTR_SIMPLE_STATIC(Font, DefaultOutColor, Color&, *FontPrivate::defaultOutColor)
const char *Font::getDefaultName()
void Font::setDefaultName(const std::vector<std::string> &names,
const SharedFontState &sfs)
{
return FontPrivate::defaultName.c_str();
pickExistingFontName(names, FontPrivate::defaultName, sfs);
}
void Font::setDefaultName(const char *value)
const std::vector<std::string> &Font::getInitialDefaultNames()
{
FontPrivate::defaultName = value;
return FontPrivate::initialDefaultNames;
}
void Font::initDynAttribs()
@ -393,8 +413,30 @@ void Font::initDefaultDynAttribs()
FontPrivate::defaultOutColor = new Color(FontPrivate::defaultOutColorTmp);
}
void Font::initDefaults()
void Font::initDefaults(const SharedFontState &sfs)
{
std::vector<std::string> &names = FontPrivate::initialDefaultNames;
switch (rgssVer)
{
case 1 :
// FIXME: Japanese version has "MS PGothic" instead
names.push_back("Arial");
break;
case 2 :
names.push_back("UmePlus Gothic");
names.push_back("MS Gothic");
names.push_back("Courier New");
break;
default:
case 3 :
names.push_back("VL Gothic");
}
setDefaultName(names, sfs);
FontPrivate::defaultOutline = (rgssVer >= 3 ? true : false);
FontPrivate::defaultShadow = (rgssVer == 2 ? true : false);
}

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -25,6 +25,9 @@
#include "etc.h"
#include "util.h"
#include <vector>
#include <string>
struct SDL_RWops;
struct _TTF_Font;
struct Config;
@ -47,7 +50,7 @@ public:
_TTF_Font *getFont(std::string family,
int size);
bool fontPresent(std::string family);
bool fontPresent(std::string family) const;
static _TTF_Font *openBundled(int size);
@ -55,22 +58,6 @@ private:
SharedFontStatePrivate *p;
};
/* Concerning Font::name/defaultName :
* In RGSS, this is not actually a string; any type of
* object is accepted, however anything but strings and
* arrays is ignored (and text drawing turns blank).
* Single strings are interpreted as font family names,
* and directly passed to the underlying C++ object;
* arrays however are searched for the first string
* object corresponding to a valid font family name,
* and rendering is done with that. In mkxp, we pass
* this first valid font family as the 'name' attribute
* back to the C++ object on assignment and object
* creation (in case Font.default_name is also an array).
* Invalid parameters (things other than strings or
* arrays not containing any valid family name) are
* passed back as "". */
struct FontPrivate;
class Font
@ -78,31 +65,43 @@ class Font
public:
static bool doesExist(const char *name);
Font(const char *name = 0,
Font(const std::vector<std::string> *names = 0,
int size = 0);
/* Clone constructor */
Font(const Font &other);
~Font();
const Font &operator=(const Font &o);
DECL_ATTR( Name, const char * )
DECL_ATTR( Size, int )
DECL_ATTR( Bold, bool )
DECL_ATTR( Italic, bool )
DECL_ATTR( Color, Color& )
DECL_ATTR( Shadow, bool )
DECL_ATTR( Outline, bool )
DECL_ATTR( OutColor, Color& )
DECL_ATTR( Size, int )
DECL_ATTR( Bold, bool )
DECL_ATTR( Italic, bool )
DECL_ATTR( Color, Color& )
DECL_ATTR( Shadow, bool )
DECL_ATTR( Outline, bool )
DECL_ATTR( OutColor, Color& )
DECL_ATTR_STATIC( DefaultName, const char* )
DECL_ATTR_STATIC( DefaultSize, int )
DECL_ATTR_STATIC( DefaultBold, bool )
DECL_ATTR_STATIC( DefaultItalic, bool )
DECL_ATTR_STATIC( DefaultColor, Color& )
DECL_ATTR_STATIC( DefaultShadow, bool )
DECL_ATTR_STATIC( DefaultOutline, bool )
DECL_ATTR_STATIC( DefaultOutColor, Color& )
DECL_ATTR_STATIC( DefaultSize, int )
DECL_ATTR_STATIC( DefaultBold, bool )
DECL_ATTR_STATIC( DefaultItalic, bool )
DECL_ATTR_STATIC( DefaultColor, Color& )
DECL_ATTR_STATIC( DefaultShadow, bool )
DECL_ATTR_STATIC( DefaultOutline, bool )
DECL_ATTR_STATIC( DefaultOutColor, Color& )
/* There is no point in providing getters for these,
* as the bindings will always return the stored native
* string/array object anyway. It's impossible to mirror
* in the C++ core.
* The core object picks the first existing name from the
* passed array and stores it internally (same for default). */
void setName(const std::vector<std::string> &names);
static void setDefaultName(const std::vector<std::string> &names,
const SharedFontState &sfs);
static const std::vector<std::string> &getInitialDefaultNames();
/* Assigns heap allocated objects to object properties;
* using this in pure C++ will cause memory leaks
@ -110,7 +109,7 @@ public:
void initDynAttribs();
static void initDefaultDynAttribs();
static void initDefaults();
static void initDefaults(const SharedFontState &sfs);
/* internal */
_TTF_Font *getSdlFont();

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2014 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2014 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2014 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2014 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2014 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2014 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -175,9 +175,9 @@ void blitSource(TEXFBO &source)
}
}
void blitRectangle(const IntRect &src, const Vec2i &dstPos, bool smooth)
void blitRectangle(const IntRect &src, const Vec2i &dstPos)
{
blitRectangle(src, IntRect(dstPos.x, dstPos.y, src.w, src.h), smooth);
blitRectangle(src, IntRect(dstPos.x, dstPos.y, src.w, src.h), false);
}
void blitRectangle(const IntRect &src, const IntRect &dst, bool smooth)

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2014 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2014 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -68,8 +68,7 @@ void vaoUnbind(VAO &vao);
void blitBegin(TEXFBO &target);
void blitBeginScreen(const Vec2i &size);
void blitSource(TEXFBO &source);
void blitRectangle(const IntRect &src, const Vec2i &dstPos,
bool smooth = false);
void blitRectangle(const IntRect &src, const Vec2i &dstPos);
void blitRectangle(const IntRect &src, const IntRect &dst,
bool smooth = false);
void blitEnd();

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -23,6 +23,7 @@
#include "shader.h"
#include "etc.h"
#include "gl-fun.h"
#include "config.h"
#include <SDL_rect.h>
@ -83,10 +84,9 @@ void GLBlendMode::apply(const BlendType &value)
break;
case BlendSubstraction :
// FIXME Alpha calculation is untested
gl.BlendEquation(GL_FUNC_REVERSE_SUBTRACT);
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE,
GL_ONE, GL_ONE);
GL_ZERO, GL_ONE);
break;
}
}
@ -111,7 +111,7 @@ GLState::Caps::Caps()
gl.GetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
}
GLState::GLState()
GLState::GLState(const Config &conf)
{
gl.Disable(GL_DEPTH_TEST);
@ -121,4 +121,7 @@ GLState::GLState()
scissorTest.init(false);
scissorBox.init(IntRect(0, 0, 640, 480));
program.init(0);
if (conf.maxTextureSize > 0)
caps.maxTexSize = conf.maxTextureSize;
}

View File

@ -3,7 +3,7 @@
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** Copyright (C) 2013 - 2021 Amaryllis Kulla <ancurio@mapleshrine.eu>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -27,6 +27,8 @@
#include <stack>
#include <assert.h>
struct Config;
template<typename T>
struct GLProperty
{
@ -130,7 +132,7 @@ public:
} caps;
GLState();
GLState(const Config &conf);
};
#endif // GLSTATE_H

Some files were not shown because too many files have changed in this diff Show More