Commit Graph
1040 Commits
Author SHA1 Message Date
kichikuou 04d5237020 Use glClear() to initialize texture in gfx_init_texture_rgba()
This is faster when initializing large textures.
2024-06-19 07:45:55 +09:00
kichikuou 6379dbad4b SengokuRanceFont: Draw text on sact_sprite.text.texture
To get consistent rendering results regardless of the background image
on the sprite.
2024-06-15 14:35:01 +09:00
kichikuou b155b4b79f Add a parameter to gfx_draw_glyph() for controlling blending behavior
This adds a new parameter `blend` to `gfx_draw_glyph()`. When `blend` is
true, the function performs normal alpha blending (same as
`gfx_draw_glyph_to_pmap()`).

If `blend` is false, the resulting pixel color will be the text color
and the alpha value will be copied from the glyph texture. However, if
the alpha value is less than 0.01, the pixel will not be written.

If you are drawing on a transparent texture (which will later be blended
into another texture), `blend` should be false. If you are drawing on top
of an image, `blend` should be true.

`gfx_draw_glyph()` used to fill transparent pixels with text color, but
this step is no longer needed and has been removed.
2024-06-15 14:34:58 +09:00
Nunuhara Cabbage d7fd6d4e1e Merge pull request #157 from kichikuou/mamanyonyo
Mamanyonyo support
2024-06-02 14:46:45 -07:00
kichikuou 64fd2a6858 Add HLL libraries for Mamanyonyo
== Handles

As a general pattern, these libraries have an interface based on integer
handles allocated by Open() and released by Close(); in the AliceSoft's
implementation, handles are pointers to internal objects. Note that:

* 0 is used to represent an invalid handle, and
* Small numbers cannot be handles. For example, Mamanyonyo has code that
  treats an integer as a CG number if it is less than 10000, and as a
  surface handle otherwise.

In this patch, handles are generated using id_pool.h functions. In order
to achieve the above, the interface is extended so that the minimum ID
value can be specified (the `base` parameter of id_pool_init()).

== Graphics System

Surface objects (implemented in vmSurface.[ch]) plays a central role in
Mamanyonyo's graphics system, and the sprite system (vmSprite.c) is
implemented on top of it. vmSprite.c uses scene.h functions.

== vmChrLoader and vmMapLoader

Since Mamanyonyo's character data format is the same as Widenyo's,
the ChrLoader code has been refactored and used from vmChrLoader.c.
On the other hand, MapLoader and vmMapLoader do not share code because
the map file format is different from Widenyo.
2024-05-31 13:36:29 +09:00
Nunuhara Cabbage 1ec06a4b80 Merge pull request #156 from kichikuou/sys41vm
VM changes for Mamanyonyo
2024-05-30 18:03:37 -07:00
kichikuou 2840b21946 Sys41VM: Do not unref arrays passed by value to HLL calls 2024-05-29 13:14:48 +09:00
kichikuou 69b1826d63 SR_ASSIGN does not take a struct type in ain v1 2024-05-29 13:14:48 +09:00
kichikuou 69cd1cb630 Add support for S_PLUSA instruction
I'm not sure how it is different from S_PLUSA2.
2024-05-29 13:14:48 +09:00
kichikuou 012f8f8af4 Implement scenario jump for ain v1
In ain v1, destination addresses of scenario jumps are stored in the
SLBL section of the ain.
2024-05-29 13:14:48 +09:00
kichikuou b85b426872 Local struct initialization in Sys41VM (ain v1)
Sys41VM doesn't have the SH_LOCALCREATE instruction, so struct pages
must be allocated when function_call() initializes local variables.
2024-05-29 13:14:48 +09:00
Nunuhara Cabbage 10169951c0 Merge pull request #155 from kichikuou/fix-incomplete-framebuffer
gfx: Clamp texture size larger than GL_MAX_TEXTURE_SIZE
2024-05-25 07:16:01 -07:00
kichikuou 8eefbcec95 gfx: Clamp texture size larger than GL_MAX_TEXTURE_SIZE
This prevents glTexImage2D() from failing and resulting in an invalid
texture if a width or height specified in sact2.SP_Create() is greater
than GL_MAX_TEXTURE_SIZE.

It is very rare and is probably a programming error in the game script.
If the resulting texture is used for rendering, it may mess up the
screen, but at least it won't crash.

Fixes https://github.com/kichikuou/xsystem4-android/issues/4.
2024-05-25 08:11:15 +09:00
Nunuhara Cabbage f73dd38dab Merge pull request #153 from kichikuou/remove_utf8
Fix system.DeleteSaveFile and vmFile.Delete on Windows
2024-05-19 06:46:43 -07:00
kichikuou 9e821a754c Fix system.DeleteSaveFile and vmFile.Delete on Windows 2024-05-19 16:03:48 +09:00
Nunuhara Cabbage f2caed46a8 Merge pull request #152 from kichikuou/little_endian
Use little_endian.h in libsys4
2024-05-18 22:08:14 -07:00
kichikuou 7ef9719cc7 Use little_endian.h in libsys4 2024-05-19 10:59:50 +09:00
Nunuhara Cabbage f47e5e5a82 Merge pull request #151 from kichikuou/PixelRestore
Add stubs for PixelRestore hll
2024-05-03 20:37:55 -07:00
kichikuou f0fc0b6699 Add stubs for PixelRestore hll
It is used (only?) in Beat Blades Haruka, when two enemies are found by
enemy seek.

This is just a screen effect and can be ignored without affecting
gameplay.
2024-05-04 07:31:35 +09:00
Nunuhara Cabbage 8cfc20999f Merge pull request #150 from kichikuou/PassRegister
PassRegister: Use the same format as AliceSoft's implementation
2024-04-26 21:12:47 -07:00
kichikuou bb72ad60b2 PassRegister: Improve query performance
Keep the arrays sorted and use binary search.
2024-04-27 11:45:35 +09:00
kichikuou 2b3e100cba PassRegister: Use the same format as AliceSoft's implementation
The old JSON format can still be loaded for backwards compatibility.
2024-04-27 11:45:29 +09:00
Nunuhara Cabbage 5f432ce672 Merge pull request #149 from kichikuou/file
Fix compilation error with clang
2024-04-15 06:09:24 -07:00
kichikuou c3e4cd5e9f Fix compilation error with clang 2024-04-15 15:27:29 +09:00
Nunuhara Cabbage 0f4529e1a6 Merge pull request #148 from kichikuou/file
File.Read/Write: Use the same format as AliceSoft's implementation
2024-04-14 15:46:57 -07:00
kichikuou 58366e199e File.Read/Write: Use the same format as AliceSoft's implementation
This improves interoperability of save files in Rance6, GALZOO, etc.
The old JSON format can still be loaded for backwards compatibility.
2024-04-14 09:23:23 +09:00
Nunuhara Cabbage d512275f99 Merge pull request #147 from kichikuou/system-gettime
system.GetTime(): Use SDL_GetTicks() instead of clock_gettime()
2024-04-02 17:30:09 -07:00
kichikuou 7e54e159df system.GetTime(): Use SDL_GetTicks() instead of clock_gettime()
Some games (e.g. Toushin Toshi 3) malfunction when system.GetTime()
returns a negative number.

On many systems clock_gettime(CLOCK_MONOTONIC) returns the time since
OS startup, but this wraps to a negative number after about 24.8 days.

As a mitigation, use SDL_GetTicks() instead, which returns the elapsed
time since game startup.
2024-04-02 13:26:53 +09:00
Nunuhara Cabbage a92e26c49c Merge pull request #146 from kichikuou/fix-feedback-loop
SACT2: Do not put sprite -1 (main surface) in the scene list
2024-03-30 07:37:18 -07:00
kichikuou e65a506dac SACT2: Do not put sprite -1 (main surface) in the scene list
Since this is the surface to render to, it should not be added to the
list of surfaces to draw from.

This is done by marking sprite -1 as hidden. Now SACT2.SP_GetShow(-1)
returns 0 and SACT2.SP_SetShow(-1, true) raises a runtime error. This is
consistent with the AliceSoft's implementation.
2024-03-28 09:38:50 +09:00
Nunuhara Cabbage 6e78f05d75 Merge pull request #145 from kichikuou/android-upstream
Android support
2024-03-16 09:10:40 -07:00
kichikuou f0f84a05ce Android: Fix text input issue
On Android, when the user enters "ら", "ん", "す" with the virtual
keyboard and converts it to "ランス", xsystem4 receives the following
events:

    SDL_TEXTINPUT("ら")
    SDL_TEXTINPUT("ん")
    SDL_TEXTINPUT("す")
    SDL_KEYDOWN(backspace)
    SDL_KEYUP(backspace)
    SDL_KEYDOWN(backspace)
    SDL_KEYUP(backspace)
    SDL_KEYDOWN(backspace)
    SDL_KEYUP(backspace)
    SDL_TEXTINPUT("ランス")

The backspace key events are generated by SDL to delete the unconverted
text. However, System4 games process the backspace key by polling, so
if the SDL_KEYDOWN and SDL_KEYUP events occur in close succession, the
game cannot detect that the backspace key has been pressed.

To solve this problem, this patch queues these consecutive input events
and processes them with an interval of at least 10ms.

Fixes https://github.com/kichikuou/xsystem4-android/issues/2.
2024-03-16 13:36:57 +09:00
kichikuou 18a71960e8 Add touch gestures
This adds gestures that allow touch device users to emulate the
following mouse/keyboard actions:

- Right-click: touch outside the game's viewport
- Ctrl key: one-finger touch and hold (for one second)
- Mouse wheel: Swipe up / down with two fingers
2024-03-16 13:35:12 +09:00
kichikuou 5e80c96587 Defer mouse button events synthesized from touch events
A typical event loop in System4 game looks like this:

    while (true) {
        SACT2.Mouse_GetPos(x, y);

        // Update the screen according to the mouse position (x, y)
        ...
        SACT2.Update();

        if (SACT2.Key_IsDown(VK_LBUTTON)) {
            // A button was pressed at (x, y)
            ...
        }
    }

This works poorly with touch devices. Assume that a touch event occured
during SACT2.Update(). It updates internal mouse position and button
status. After SACT2.Update(), the game calls SACT2.Key_IsDown(VK_LBUTTON).
It returns true, but the game has not yet called SACT2.Mouse_GetPos()
after the touch event, so it assumes that the button was pressed where
the mouse pointer was before the touch.

In order to avoid this situation, this defers mouse button events
synthesized (by SDL) from touch. Such deferred events are processed when
SACT2.Mouse_GetPos() is called or after 50ms.
2024-03-16 13:26:29 +09:00
kichikuou 9ec354c198 Android: Add CMakeLists.txt 2024-03-16 12:54:54 +09:00
kichikuou b7304f747b Android: Load fonts and shaders from apk assets 2024-03-16 12:53:56 +09:00
kichikuou b7ab1ed476 Android: Enforce landscape fullscreen mode 2024-03-16 12:49:52 +09:00
kichikuou bc522b27e0 Android: Report ERROR() with a message box 2024-03-16 12:45:07 +09:00
kichikuou 3e9f975213 Update libsys4 2024-03-16 12:43:55 +09:00
Nunuhara Cabbage ba9e42fad6 Merge pull request #144 from kichikuou/resume-save
Add support for reading / writing System4 resume save files
2024-02-15 20:34:45 -08:00
kichikuou 05226453d9 Add support for reading / writing System4 resume save files
Writing save files in RSM format is only enabled if `--save-format=rsm`
command line flag is specified, because this implementation does not
create save files that are fully compatible with the AliceSoft's
implementation:

* There is no simple way to determine the RSM format version used by the
  game.
* There are several unknown fields in the RSM format.
* Empty arrays are represented as NULL pages in xsystem4, so type
  information of such objects cannot be saved.

These limitations are not a problem for the following use cases:

* Use the created save files only in xsystem4
* Load save files created by System40.exe

Also, RSM save files are much smaller and faster to read and write than
JSON.
2024-02-14 12:45:37 +09:00
Nunuhara Cabbage 4e2c050ffc Merge pull request #143 from kichikuou/savedir
Create savedir just before running VM
2024-02-09 06:52:02 -08:00
kichikuou 39701c7657 Create savedir just before running VM
Before this change, directory described in System40.ini was created even
if --save-folder was specified.
2024-02-07 16:36:57 +09:00
Nunuhara Cabbage 6bdd22f875 Merge pull request #142 from kichikuou/game_compatibility
Update game_compatibility.md
2024-01-31 06:12:09 -08:00
kichikuou 20411f3518 Update game_compatibility.md 2024-01-31 18:09:28 +09:00
Nunuhara Cabbage 27e733758d Merge pull request #141 from kichikuou/banmisc
BanMisc: Use the same save format as AliceSoft's implementation
2023-12-16 17:01:35 -08:00
kichikuou 288381d8f6 BanMisc: Use the same save format as AliceSoft's implementation
BanMisc.{Save,Load}Struct now serializes structs in the same format as
AliceSoft's implementation, rather than in JSON format. The old JSON
format can also be loaded for backwards compatibility.
2023-12-17 09:01:36 +09:00
kichikuou c3f39aeb96 Use mt19937_xorcode helper function 2023-12-17 09:01:28 +09:00
Nunuhara Cabbage 05d2ad8600 Merge pull request #139 from kichikuou/shimaima
Update libsys4
2023-11-17 23:41:48 -08:00
kichikuou 0911103949 Update libsys4
And add tests for https://github.com/nunuhara/libsys4/pull/26.
2023-11-18 16:35:58 +09:00