SengokuRanceFont.DLL falls back to MS Gothic for characters whose glyphs
are absent from the FNL font. Reproduce this behavior to enable Japanese
translations of mods based on the MangaGamer release of Sengoku Rance.
Add an HLL-local composite font that wraps each selected FNL font_size
together with a FreeType Gothic font_size. The composite font checks for
each glyph in the FNL font and delegates rendering and size to Gothic
when the glyph is missing.
Scale fallback glyphs down and adjust their vertical position so that
they align with the FNL text line.
Move alpha_clipper_parts_no into inherited part parameters so child
parts use their parent's clipper unless they explicitly override it.
Bump the save version to 7.
parts_release detached children without marking them dirty, leaving
them with global parameters inherited from the released parent.
Furthermore, parts_update_component skipped global parameter updates
for parentless parts.
Mark orphaned children dirty and combine parentless parts against the
root parameters.
Offset the sprite so that the origin matches the anchor selected by the
graphic key's align field. Use the source rectangle dimensions when an
area is specified, and the full texture dimensions otherwise.
Serialize the SealEngine plugin bound to the component. Instances now
remember the name so referenced assets can be reloaded.
Bump the parts save format version to 6.
Blade Briders inserts three layer functions at func_id 3-5 into the
assignment used by Rance9, shifting all subsequent func_ids up by three.
Evenicle uses the same assignment as Blade Briders.
Use this assignment internally and add three to Rance9 func_ids before
dispatch. Also implement the functions 3-5.
In SealEngine, the frame images of a billboard instance are PNG files in
the archive, named "<name>\<basename>.png", "<name>\<basename>[1].png"
and so on, and the motion frame number is the index into them.
This also changes the lifetime management for billboard motions. A
billboard's motion holds the frame animation state of the instance,
which the game sets up before calling Load, so keep it across loads
and free it in free_instance.
Store the four billboard vertex positions and UVs in each RE_instance
and use them for regular billboard rendering. The static billboard mesh
is kept for billboard particles.
On Windows RAND_MAX is 0x7fff, which makes Rand() and RandF() far too
coarse. Use mt19937 instead so that seeded sequences reproduce the
original engine's behavior.
Text lines are saved individually without newlines. Insert an explicit
newline between lines on load so the original line structure is
restored. Also free the strings read from the save data.
Rance 9's AFA archives have no ID field, so asset IDs are sequential
indices local to each archive. When the game loads an additional CG
archive, the ID spaces overlap: a name resolved to an ID against the
base archive later fetches a different CG from the additional archive.
Keep the CG name instead.
Bumps the save version to 5; version 4 and earlier saves still store IDs
and are converted on load.
AFAFactory.LoadArchive passed the SJIS archive name straight through, so
the extra assets loaded by the Rance 9 v2.00 patch were never found.
Move the path resolution out of CGManager.LoadArchive so that both
callers share it.
Bump the save version and always serialize controller state and the
Rance 9 parts fields. Load these fields based on the save version while
retaining compatibility with existing multi-controller saves.
Commit 03062d5 fixed audio lookup for Rance 9, but the new archive-data
preparation path bypassed BGI and WAI metadata. Pass the asset number
through that path so loop points are applied correctly.
Audio linesize may include unused buffer space. Using it as the sample
count caused short Vorbis frames to replay stale samples and slowed down
audio playback.
Fortress.alm from Rance IX uses an MPEG-2 Program Stream containing
MPEG-1 video and MPEG-1 Layer II audio. As far as I checked, it is the
only .alm movie released in Japan that does not use an MPEG-1 Program
Stream.
The existing pl_mpeg decoders support its elementary streams, but the
demuxer rejects its MPEG-2 pack and PES headers. Extend the demuxer to
parse those headers and the PTS/DTS combinations used by Fortress.alm.
Replace direct one-shot zlib compression and decompression calls with
the libsys4 wrappers. Use exact-size decompression where file formats
provide the uncompressed size.
File2.c continues to depend directly on zlib because it uses streaming
inflate.
When NumLock is disabled, Windows reports numpad keys as navigation
virtual-key codes in the WM_KEYDOWN message. SACT2 games rely on this
behavior.
Translate SDL keypad scancodes to the corresponding SACT key codes in
that state, and map keypad Enter to VK_RETURN.
Fixes#359.
Add the following commands to the debugger:
3d list [all] List plugins and instances
3d plugin [<plugin>] Show or select the current plugin
3d show [<instance>] Dump plugin or instance state
3d set <instance> draw <0|1> Enable or disable drawing
3d set <instance> pos <x> <y> <z> Set the instance position
3d help Show command help
The show and set commands operate on the current plugin. If only one
plugin exists, it is selected automatically. Changes made with set are
rendered immediately.
If AddCreateCGToProcess fails for a missing CG, no create op is added to
the construction process. Game scripts still add drawing operations and
then build the process, leaving those operations with no destination
texture and causing an incomplete framebuffer error.
This makes construction build operations return false as soon as an
operation cannot be executed.
Fixes#356.
Game-specific .xsys4rc files are loaded from the game directory, so
relative paths in that file are most useful when interpreted from the
same directory. This allows patches that ship external fonts to
reference them with relative paths.
In both TapirEngine and SealEngine an instance is outlined only when the
global edge draw option and its per-instance edge flag are both on. The
per-instance flag is exposed via Set/GetInstanceDrawParam, whose edge
index differs by engine (Tapir 0, Seal 2).
For the global option the engine only distinguishes on/off, so drop the
RE_draw_edge_mode enum.
In SealEngine the outline length and color are plugin-wide values set
via SetEdgeLength/SetEdgeColor, not the per-mesh .opr parameters used by
TapirEngine.
Only resolve the method when the function's signature matches the
delegate type, returning 0 otherwise.
Also, DG_SET / DG_NEW_FROM_METHOD / DG_ADD should not add function 0.
This implements the sky/middle/ground hemisphere ambient driven by
light_params[8..19].
SealEngine has no separate specular-light instance; its specular instead
shares the hemisphere light vector.
SealEngine manages a 41-float light parameter set (serialized as .lit
file) for tone mapping, hemisphere lighting, and light scattering. This
adds the storage and HLL plumbing, without wiring values into shaders.
- A DIRECTIONAL_LIGHT instance owns a parameter set, filled by loading a
.lit file (RE_instance_load).
- SealEngine.StoreInstanceLightParam() reflects that presets into the
plugin's master buffer, which is used by the renderer.
- SealEngine.LoadInstanceLightParam() copies the master back into an
instance, and Reset()/Set()/Get() operate directly on the master.
Some games (e.g. Rance 01, Rance 9) only export GetFlag and SetFlag, so
Init() is never called. Initialize from _PreLink with a default save
file name in that case.
In TapirEngine, CalcIntersectEyeVec() only worked on models with a
"collision" mesh. In SealEngine, a raycast collider is built from the
union of meshes flagged HeightDetection=true in .opr.
Also return the nearest intersection instead of the first.
The EMISSIVE and ENV_MAP diffuse modes did not apply the ambient term or
vertex color (color_mod) to the fragment. In the original TapirEngine /
SealEngine, all diffuse modes contribute ambient and vertex color.
This fixes a bug where the movement/attack range indicator color did
not change in battle scenes.
SetInstanceDiffuse has two roles depending on the instance type: for
directional lights it is the light color, and for meshes it is a
multiplier on the mesh color. xsystem4 honored only the former.
Treat inst->diffuse as color multiplier, via the diffuse_mod uniform.
This adds a helper that resets every per-draw uniform to a neutral
default and call it at the start of the billboard, .pae and .3de paths.
This fixes uv_scroll and use_blend_texture leaks from a previously
rendered model.
KeepPreviousView and its mode are purely a rendering performance knob
(incremental rendering optimization). Toggling the mode never affects
rendering correctness, so leaving these unimplemented is harmless and
warning about them is just noise.
PE_Reset() zeroed the controller stack, leaving it with no default
controller. Since PE_Reset() does not clear parts_engine_initialized,
the subsequent PE_Init() returns early so the stack stays empty.
Reset the stack with ctrl_stack_init() instead, which re-creates the
default controller. ctrl_stack_fini() is now unused and removed.
Save a reduced copy of the main surface to a file. The image is written
as QNT under the save directory.
To avoid aliasing at large reductions, the surface is downscaled by
repeatedly halving before the final stretch.
At spawn, init_particle() samples its fixed properties from a
deterministic PRNG into s3de_particle, so playback is reproducible.
Each frame, update_object_states() interpolates the emitter's animated
properties into s3de_object_state.
To draw, render_s3de_effect() combines the two: for each live particle
s3de_billboard_world_transform() or s3de_mesh_world_transform() derives
a world matrix from the lifetime state computed by eval_particle(),
together with a posture basis that orients the quad or mesh. Objects are
drawn sorted by distance from the camera.
.3de is the particle/effect format used by SealEngine. Like the
ReignEngine's .pae, it is a text format describing an effect as a set of
emitters, but the two differ enough in design that .3de lives in its own
file (s3de.c) rather than being folded into particle.c.
This commit lays the groundwork:
- Parse .3de text.
- Integrate effect loading, playback, and caching into the existing
infrastructure.
- Apply the camera object's per-frame override to RE_camera.
- Play the companion sound asset.
Billboard and polygon-object rendering will be added separately.
The original {Reign,Tapir,Seal}Engine apply motion bones to model bones
purely by array position, never consulting bone name or bone_id.
This fixes bone animation of "Shizuka & Nagi" model in Rance 9.
After loading a save, the game script may give a negative passed_time
because it computes the delta time using an absolute system.GetTime()
value stored in the save data.
This fixes hang on load in Rance 9.
This also removes the equivalent workaround in parts_render_update for
Rance 01, since the new clamp covers that case as well.
.mpr is an optional sidecar to .mot used by SealEngine, replacing .txa
used in ReignEngine / TapirEngine. While .mot drives bone poses, .mpr
drives material properties on a per-frame timeline.
Supported keys, all keyed by frame number:
Object{MulAlpha,MulDiffuse,AddAmbient} : applied to the whole model
Mesh{MulAlpha,MulDiffuse,AddAmbient} : applied per named mesh
MeshTextureAnime : swap diffuse texture index
Colors and alpha use linear interpolation between keys. Out-of-range
frames hold the nearest endpoint.
Mesh* tracks act as per-mesh tints and do not leak to other meshes
that happen to share a material. MeshTextureAnime is the exception:
it rewrites the shared material's diffuse slot, so all meshes using
that material animate in sync (e.g. in Rance 9, hanny_black_move.mpr
lists only hibana_R but hibana_L animates together).
The camera view direction was computed incorrectly in two ways:
1. glm_euler (XYZ order) applies pitch around world X. The original
engine uses YXZ where pitch is around the camera's local X after yaw.
2. SetCameraAngle negated the input yaw.
This implements rendering of FLAT_LIB_EMITTER libraries: timed spawning,
per-particle motion, fade, and 3-axis rotation.
For each visible emitter, render_flat_emitter() builds an emitter base
matrix from the ancestor key stack so particles follow their parent
timelines. parent_key_mode chooses between filtering ancestor properties
via the emitter's inherit_* flags (SELECTIVE) and using ancestor poses
wholesale (ANCESTOR_CURRENT / ANCESTOR_AT_BIRTH). For each birth frame
in the lifetime window, parts_flat_foreach_emitter_particle() reseeds
the RNG from (rand_seed, birth_frame), making particles deterministic
across re-renders, and yields each particle's pose, which is composed
with the emitter transform and submitted as a quad through the standard
parts texture pipeline.
3DLayer and Movie parts use a SACT sprite as their render target (for
SealEngine output or movie frames). That sprite was registered into
the scene at z=0, so the content was drawn at z=0 instead of (or in
addition to) the parts engine's render path at the parts' configured Z.
Hide the bound SACT sprite from the scene so the parts engine is the
sole renderer of its texture, and add a parts_render case for 3DLayer
that composites the bound sprite's texture through parts_render_cg.
The original engine implements proper perspective projection, but we
use simpler orthographic foreshortening. In Rance 9, the visual
difference is barely noticeable.
area_x/area_y select a sub-rectangle of the texture, but should not
shift the on-screen position. Translate the quad by (-area_x, -area_y)
to cancel the offset the sub-rect's top-left would otherwise introduce.
A parent key's draw_filter had no effect on CG/STOP_MOTION leaves
inside descendant TIMELINE libraries. Resolve the effective filter
at each key (own if non-NORMAL, otherwise inherited) and thread it
through the render chain.
FLAT_LIB_STOP_MOTION represents a sprite animation as a sequence of CG
frames. A stop_motion library specifies a base CG file (e.g. "foo.png");
at load time, parts_flat_load() discovers numbered frame variants
("foo_01.png", "foo_02.png", ...) and builds a frame list.
At render time, the active frame is resolved from the local timeline
clock using three parameters:
- span: number of timeline ticks each frame is displayed
- loop_type: 0 = play once and stop at last frame,
1 = loop forward,
2 = ping-pong (forward then backward)
- local: the timeline's current local time
The multiply and screen blend functions used in render_flat_item
ignored the source alpha, so transparent pixels still modulated the
destination color instead of leaving it untouched.
Add a draw_filter uniform to the parts fragment shader and have it
output an alpha-baked source color, so that the framebuffer result
after the GL blend equation interpolates correctly in alpha:
- multiply: shader outputs src = mix(vec3(1.0), mod_color, alpha)
blend (GL_DST_COLOR, GL_ZERO) gives src*dst,
i.e. mix(dst, mod_color*dst, alpha)
- screen: shader outputs src = mod_color * alpha
blend (GL_ONE, GL_ONE_MINUS_SRC_COLOR) gives src + (1-src)*dst,
i.e. mod_color*alpha + (1 - mod_color*alpha)*dst
In both cases alpha=0 leaves the destination untouched, alpha=1
gives the full multiply/screen result.
Also switch the surface-area mask from multiplication to discard,
so pixels outside the rect leave the destination intact under
multiply blending (where multiplying src by 0 would otherwise
zero out dst).
This adds a key handler facility to input.c so that the InputString
can intercept the Backspace key while the IME is open, and remove the
last character from the result string. Backspace is ignored while the
IME has composing text, so it does not interfere with IME editing.
The newer version (from Boku Dake no Hokenshitsu onwards) of
InputString.GetResultString() does not clear its internal string.
This fixes the issue in Rance 02 where the text always remained empty
when editing save comments.
This fixes heap use-after-free in the music mode in Rance 9.
Hold a reference to the struct page (`this` pointer) for the duration
of a method call. Without this, if the sole external reference to an
object is dropped during one of its method calls (e.g. an event handler
that destroys its own parent), the object and its members are freed
immediately, causing use-after-free when the VM tries to access them
afterward.
This matches the behavior of the original VM, which was introduced in
Rance9.exe and later titles.
The fix is gated on AIN v6.1+ (AIN v6 with a MSG1 section) to match
the original. Applying it unconditionally would change the heap refcount
state visible to resume saves, potentially breaking existing saves for
older games.
line_space was stored but never used during rendering or size
calculation. Apply it as inter-line spacing in both the size calculation
and the render path. Also initialize empty lines with the current text
style height so that newline-only lines occupy the correct space.
Change line_space from unsigned to int because negative values can be
set.
This fixes the rendering of the sample message in the "Message Color"
configuration of Rance 9.
PE_SetPartsFont* and PE_SetText*Space functions only modified the text
style struct without re-rendering existing character textures. Since
character glyphs are baked into textures at append time, subsequent
style changes had no visible effect.
mag_speed is a per-plugin integer (default 1) set by SetMagSpeed on
all existing plugins. use_mag_speed is a per-instance flag (default
true) set by SetInstanceUseMagSpeed. When use_mag_speed is true,
motion delta_frame is multiplied by mag_speed.
POL v4 introduces material groups with texture blending. A material's
sub-material can be a "blend group" containing exactly two leaf
materials, whose textures are blended using per-vertex weights for
smooth terrain transitions.
This implements Parts_SetDrag and drag/drop event handling. When a part
has drag enabled, clicking and moving the mouse will move the part and
emit DRAG_BEGIN/DRAGGING/DRAG_END messages. Drop target detection emits
DROP_ENTER/DROP_ON/DROPPED/DROP_LEAVE messages on parts under the cursor
during drag.
This adds PARTS_LAYOUT_BOX parts type with support for automatic
horizontal/vertical child positioning. Layout calculation runs during
the component update cycle, repositioning children before their global
parameters are combined.
This function has a large number of parameters, which are serialized
fields from CASConstructionProcess. Dispatch on the command number to
the appropriate PE_Add*ToPartsConstructionProcess function.
MOUSE_ON is sent every frame while hovering, with cursor position and
accumulated hover time. MOUSE_MOVE is sent when the cursor position
changes during hover.
This implements SetPassCursor/GetPartsPassCursor HLL functions. The
pass_cursor flag controls whether the cursor "passes through" a
component to reach parts behind it.
Key changes to input processing:
- Iteration order changed from back-to-front to front-to-back for proper
cursor consumption
- MOUSE_ENTER / MOUSE_LEAVE now fire for all parts regardless of
clickable
- Click hit test uses clickable || !pass_cursor pre-filter
- pass_cursor=false parts consume the cursor, preventing hover and
click events from reaching parts behind them
parts_set_state silently ignored transitions to uninitialized states,
causing parts without a HOVERED state to remain in CLICKED after mouse
release. Fall back through CLICKED -> HOVERED -> DEFAULT so the first
initialized state is always selected. DEFAULT is accepted unconditionally
as the terminal fallback, matching the original engine's behavior.
This introduces a per-parts is_hovered flag (replacing the global
parts_prev_pos) and fire MOUSE_ENTER, MOUSE_LEAVE, KEY_TRIGGER,
KEY_DOWN, MOUSE_CLICK, and KEY_UP events on the corresponding mouse
state transitions.
This also fixes the hittest in parts_update_mouse() to account for the
parent's global position, and to use the DEFAULT state hitbox (matching
the original engine's behavior).
PartsEngine in Rance 9 manages multiple "controllers" (called "layers"
in game scripts) that provide part grouping, draw-order control, and
bulk release. This implements the core controller API:
- AddController / RemoveController: push/pop a controller on the
stack. RemoveController releases all parts belonging to the removed
controller and returns their IDs in erase_number_list.
- SetActiveLayer / GetActiveLayer / GetSystemOverlayLayer: control
which controller newly created parts are assigned to. The system
overlay controller is a special controller that always renders on
top and survives ReleaseAllWithoutSystem.
- ReleaseAllWithoutSystem: releases all parts except those in the
system overlay controller and re-initializes the controller stack.
Controllers are identified by their position in the stack (0 = bottom).
Draw ordering uses the scene's two-level sprite sorting: sp.z is set to
the controller's stack index and sp.z2 to the part's Z value, so parts
in higher controllers always render above lower ones regardless of
individual Z values. When the parts_multi_controller flag (see below) is
false, the original Z ordering is preserved (allowing Z-interleaving
with non-parts scene sprites -- see #180) for compatibility with games
that do not use controllers.
Save/load of the controller stack and per-part controller_no is gated on
a parts_multi_controller flag (set at PreLink time when the game's HLL
exports AddController) rather than a save version bump. This keeps the
save format stable for games that do not use controllers, while allowing
the save format to evolve freely during development.