Skip to content

Commit bc2656e

Browse files
author
Trulio
committed
Merge branch 'master' of https://github.com/RednibCoding/OpenShadowFlare into feature/androidPort
2 parents 3e0a5ba + 155a0fe commit bc2656e

27 files changed

Lines changed: 832 additions & 47 deletions

‎roadmap.md‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,27 @@ draws the authored name and color over the proportional life fill, with the
162162
native-element marker from `StatusIcon.njp`. Enemy animation and movement now
163163
invalidate the world presentation even while the player stands still.
164164

165-
The immediate target is the rest of the first attack boundary: implement the
166-
ordinary action-two presentation through its CAF marker without inventing a
167-
second combat actor. The small enemy resource working set still needs a
168-
predictable reload boundary before later maps can move into resources outside
169-
their entry vicinity.
165+
The first ordinary enemy attack presentation is live as well. Action two asks
166+
for direct presentation one, faces the retained player or companion target,
167+
and advances the MCT-selected CAF with the retail ten-entry speed table using
168+
integer ratios. It scans every crossed frame for the three sound bits and the
169+
`0x40` impact marker, holds the final frame for one update, then publishes
170+
completion event two. The game still owns the one live enemy; there is no
171+
second presentation actor or renderer-side combat rule.
172+
173+
Attack art has a separate predictable lifetime. An action whose resource is
174+
not resident publishes a small request and waits. Between update and draw, the
175+
runtime may replace one inactive attack resource in the video-memory tail,
176+
then binds its immutable eight-direction CAF timeline back to every matching
177+
enemy. Near Remote Town's resource-one Goblin bank costs 842,596 bytes, leaves
178+
the main screen arena untouched, and can be rewound without touching the
179+
fixed framebuffer. This is a generic resource/chart boundary, not a list of
180+
special maps or Goblin IDs.
181+
182+
The immediate target is the direct impact receiver behind that marker:
183+
reconstruct the retail hit packet, defense and damage result, player or
184+
companion reaction, and presentation sounds. After that, the same working-set
185+
boundary can grow to direct variants two and three and the effect actions.
170186

171187
## Where we are now
172188

‎shadowflare/CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ add_library(
4646
assets/player_assets.c
4747
assets/retail_paths.c
4848
assets/scenario_actor_assets.c
49+
assets/scenario_enemy_attack_assets.c
4950
assets/scenario_enemy_assets.c
5051
assets/scenario_object_assets.c
5152
assets/title_assets.c
@@ -91,6 +92,7 @@ add_library(
9192
game/enemy_ai_selection.c
9293
game/enemy_action.c
9394
game/enemy_movement.c
95+
game/enemy_presentation.c
9496
game/game.c
9597
game/gameplay_service.c
9698
game/ground_item.c

‎shadowflare/README.md‎

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ it is invalid.
283283

284284
## Current screen budgets
285285

286-
The complete title currently uses 1,543,133 bytes of the 7 MiB main arena,
287-
leaving 5,796,899 bytes free. Its screen-scoped artwork accounts for 1,101,182
286+
The complete title currently uses 1,548,485 bytes of the 7 MiB main arena,
287+
leaving 5,791,547 bytes free. Its screen-scoped artwork accounts for 1,101,182
288288
bytes. The rest includes TWL/TAL state, game and screen metadata, persistent
289289
8-bit menu music and effects, and one reusable 60,000-byte decode buffer. The
290290
video pool contains only the 614,400-byte RGB555 framebuffer, leaving 3,579,904
@@ -297,29 +297,29 @@ nonblank case, all ten smoke streams together decode at most 57,864 bytes into
297297
the same reusable buffer during one rendered frame.
298298

299299
Character creation releases all title-only artwork before loading its own
300-
assets. It uses 856,056 bytes of the main arena, leaving 6,483,976 bytes free;
300+
assets. It uses 861,408 bytes of the main arena, leaving 6,478,624 bytes free;
301301
414,105 bytes of that total are character-screen artwork and font data. Shared
302302
NJP parts are decoded only once even when several patterns reference them, and
303303
a static character screen is not filled again until a visible state changes.
304304

305-
The load-game screen uses 816,272 bytes of the main arena, leaving 6,523,760
305+
The load-game screen uses 821,624 bytes of the main arena, leaving 6,518,408
306306
bytes free. Its screen-scoped artwork, font, and selected save preview account
307307
for 374,321 bytes. Save headers stay in a fixed six-entry catalog, while only
308308
the selected 391x114 thumbnail occupies memory. Changing selection decodes the
309309
new preview into the same 89,148-byte RGB555 buffer; idle frames perform no
310310
file access and do not refill the framebuffer.
311311

312-
The complete Remote Town gameplay screen uses 7,277,220 bytes of the main
313-
arena, leaving 62,812 bytes free. Its screen-owned scenario, script, map,
312+
The complete Remote Town gameplay screen uses 7,282,572 bytes of the main
313+
arena, leaving 57,460 bytes free. Its screen-owned scenario, script, map,
314314
player, owned companion, PEOPLE, type-zero objects, ground-item,
315315
inventory-panel, transport, equipment, and UI data and artwork account for
316316
6,835,269 bytes. GND rendering data is decoded directly from its compressed three-plane
317317
stream into two bytes
318318
per tile, so the 300x300 town grid occupies 180,000 bytes instead of retaining
319319
the 540,000-byte source layout.
320320

321-
The same runtime reload measured in Near Remote Town uses 7,241,992 bytes,
322-
leaving 98,040 bytes free; 6,800,041 bytes belong to that screen. The
321+
The same runtime reload measured in Near Remote Town uses 7,247,344 bytes,
322+
leaving 92,688 bytes free; 6,800,041 bytes belong to that screen. The
323323
transition never retains two maps at once. Its fixed request lives with the
324324
game owner, while the screen arena is rewound before the next scenario is
325325
decoded.
@@ -420,9 +420,22 @@ entry-vicinity resource, movement uses the shared route controller, and the
420420
enemy's dynamic blocker is updated in the same tick as its position. Attack
421421
selection and cadence, route movement, and the small per-enemy coordinator
422422
live in separate files so adding more actions does not grow one controller. The
423-
attack presentations are deliberately still dormant; the next slice will
424-
connect their CAF marker and damage boundary rather than applying damage from
425-
the movement controller.
423+
ordinary action-two presentation now lives in its own game file. It uses the
424+
MCT direct-attack chart, range, and speed index, faces the retained target,
425+
scans crossed CAF cells for the three audio bits and `0x40` impact bit, holds
426+
the final frame, and returns retail event two. Damage is deliberately not
427+
applied by the movement controller; the next slice will connect the marker to
428+
the direct-impact receiver.
429+
430+
Direct-attack artwork uses the previously empty video-memory tail instead of
431+
consuming the final main-RAM headroom. Only one inactive resource bank is
432+
replaceable at a time. The runtime rewinds that tail at a clear resource
433+
boundary, loads all eight directions for the requested chart, and binds the
434+
immutable cells to matching live enemies. The measured resource-one Goblin
435+
bank is 842,596 bytes. Together with the 614,400-byte RGB555 framebuffer it
436+
uses 1,456,996 bytes of the 4 MiB video pool, leaving 2,737,308 bytes. Ordinary
437+
updates and draws allocate nothing and perform no file access; only a missing
438+
attack bank enters this bounded prepare step.
426439

427440
The pointer side of that boundary is now live. Opaque pixels from the current
428441
enemy CAF frame participate in the normal click range with the enemy class's

‎shadowflare/RULES.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ headers, legacy libraries, and heap allocation.
106106
- A loading transition must fit its peak budget, not only its final state.
107107
- Assets are loaded for their current screen, map, or owner and released at a
108108
clear lifetime boundary.
109+
- Replaceable video artwork starts after the fixed framebuffer mark. A reload
110+
may rewind that tail only when no live presentation still references it;
111+
target backends do not own or reimplement this policy.
109112
- Main-RAM and video-RAM totals need tests whenever a new asset class lands.
110113
- Do not trade large lookup tables or caches for small CPU wins without
111114
measuring the memory cost.

‎shadowflare/assets/scenario_enemy_assets.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ static bool sf_scenario_enemy_visual_load(
200200
return true;
201201
}
202202

203+
203204
bool sf_scenario_enemy_assets_load(
204205
SfScenarioEnemyAssets *assets, const char *data_root,
205206
const SfMctScenario *scenario, SfWorldPoint focus, SfArena *arena) {
@@ -245,3 +246,26 @@ const SfScenarioEnemyVisual *sf_scenario_enemy_visual(
245246
}
246247
return NULL;
247248
}
249+
250+
bool sf_scenario_enemy_frame_assets(
251+
const SfScenarioEnemyAssets *assets, int32_t resource_id,
252+
uint16_t chart, uint8_t direction, SfScenarioEnemyFrameAssets *frame) {
253+
const SfScenarioEnemyVisual *visual;
254+
if (!assets || !frame || direction >= SF_SCENARIO_ENEMY_DIRECTION_COUNT)
255+
return false;
256+
memset(frame, 0, sizeof(*frame));
257+
if (assets->attack.loaded && assets->attack.resource_id == resource_id &&
258+
assets->attack.chart == chart) {
259+
frame->animation = &assets->attack.animations[direction];
260+
frame->artwork = &assets->attack.artwork;
261+
frame->shadows = &assets->attack.shadows;
262+
return frame->animation->frame_count > 0u;
263+
}
264+
if (chart >= SF_SCENARIO_ENEMY_ANIMATION_COUNT) return false;
265+
visual = sf_scenario_enemy_visual(assets, resource_id);
266+
if (!visual) return false;
267+
frame->animation = &visual->animations[chart][direction];
268+
frame->artwork = &visual->artwork;
269+
frame->shadows = &visual->shadows;
270+
return frame->animation->frame_count > 0u;
271+
}

‎shadowflare/assets/scenario_enemy_assets.h‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,24 @@ typedef struct SfScenarioEnemyVisual {
4242
uint8_t selected_parts;
4343
} SfScenarioEnemyVisual;
4444

45+
typedef struct SfScenarioEnemyAttackAssets {
46+
SfCafSelectedAnimation animations[SF_SCENARIO_ENEMY_DIRECTION_COUNT];
47+
SfNjpSparseResource artwork;
48+
SfNjpSparseResource shadows;
49+
size_t memory_bytes;
50+
int32_t resource_id;
51+
uint16_t chart;
52+
bool loaded;
53+
} SfScenarioEnemyAttackAssets;
54+
55+
typedef struct SfScenarioEnemyFrameAssets {
56+
const SfCafSelectedAnimation *animation;
57+
const SfNjpSparseResource *artwork;
58+
const SfNjpSparseResource *shadows;
59+
} SfScenarioEnemyFrameAssets;
60+
4561
typedef struct SfScenarioEnemyAssets {
62+
SfScenarioEnemyAttackAssets attack;
4663
SfScenarioEnemyVisual *visuals;
4764
size_t memory_bytes;
4865
uint16_t visual_count;
@@ -53,5 +70,12 @@ bool sf_scenario_enemy_assets_load(
5370
const SfMctScenario *scenario, SfWorldPoint focus, SfArena *arena);
5471
const SfScenarioEnemyVisual *sf_scenario_enemy_visual(
5572
const SfScenarioEnemyAssets *assets, int32_t resource_id);
73+
bool sf_scenario_enemy_attack_assets_load(
74+
SfScenarioEnemyAttackAssets *attack, const char *data_root,
75+
const SfMctScenario *scenario, int32_t resource_id, uint16_t chart,
76+
SfArena *arena);
77+
bool sf_scenario_enemy_frame_assets(
78+
const SfScenarioEnemyAssets *assets, int32_t resource_id,
79+
uint16_t chart, uint8_t direction, SfScenarioEnemyFrameAssets *frame);
5680

5781
#endif
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* Copyright (C) 2026 Michael Binder and contributors
3+
*
4+
* This file is part of OpenShadowFlare.
5+
*
6+
* OpenShadowFlare is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License as published by the Free
8+
* Software Foundation, either version 3 of the License, or (at your option)
9+
* any later version.
10+
*
11+
* OpenShadowFlare is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14+
* details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with OpenShadowFlare. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include "assets/scenario_enemy_assets.h"
21+
22+
#include "assets/retail_paths.h"
23+
24+
#include <stdio.h>
25+
#include <string.h>
26+
27+
static bool sf_enemy_attack_path(
28+
char *path, size_t capacity, const char *root,
29+
const char *format, int32_t resource_id) {
30+
char relative[SF_RETAIL_PATH_CAPACITY];
31+
const int length = snprintf(
32+
relative, sizeof(relative), format, resource_id);
33+
return length >= 0 && (size_t) length < sizeof(relative) &&
34+
sf_retail_path_join(path, capacity, root, relative);
35+
}
36+
37+
static bool sf_enemy_attack_add_pattern(
38+
int32_t *patterns, uint16_t *count, int32_t pattern) {
39+
uint16_t index;
40+
if (pattern < 0) return true;
41+
for (index = 0u; index < *count; ++index) {
42+
if (patterns[index] == pattern) return true;
43+
}
44+
if (*count >= SF_NJP_SPARSE_PATTERN_LIMIT) return false;
45+
patterns[(*count)++] = pattern;
46+
return true;
47+
}
48+
49+
static bool sf_enemy_attack_request(
50+
const SfMctScenario *scenario, int32_t resource_id, uint16_t chart,
51+
uint8_t *enabled_parts) {
52+
uint16_t enemy_index;
53+
bool found = false;
54+
for (enemy_index = 0u; enemy_index < scenario->enemy_count; ++enemy_index) {
55+
const SfMctEnemy *enemy = &scenario->enemies[enemy_index];
56+
const int32_t enemy_chart = enemy->post_ai_values[41] + 4;
57+
uint8_t part;
58+
if (enemy->resource_id != resource_id || enemy_chart != chart) continue;
59+
found = true;
60+
for (part = 0u; part < SF_MCT_PERSON_PART_LIMIT; ++part) {
61+
if (!enemy->custom_parts || enemy->part_visibility[part] != 0u)
62+
*enabled_parts = (uint8_t) (
63+
*enabled_parts | (uint8_t) (1u << part));
64+
}
65+
}
66+
return found;
67+
}
68+
69+
static bool sf_enemy_attack_collect_patterns(
70+
const SfCafSelectedAnimation *animations,
71+
int32_t *artwork_patterns, uint16_t *artwork_count,
72+
int32_t *shadow_patterns, uint16_t *shadow_count) {
73+
uint8_t direction;
74+
for (direction = 0u; direction < SF_SCENARIO_ENEMY_DIRECTION_COUNT;
75+
++direction) {
76+
const SfCafSelectedAnimation *animation = &animations[direction];
77+
uint8_t part;
78+
for (part = 0u; part < animation->part_count; ++part) {
79+
uint16_t frame;
80+
for (frame = 0u; frame < animation->frame_count; ++frame) {
81+
const SfCafCell *cell = &animation->parts[part].cells[frame];
82+
if (((cell->status & 8) == 0 && !sf_enemy_attack_add_pattern(
83+
artwork_patterns, artwork_count, cell->pattern)) ||
84+
((cell->status & 8) != 0 && !sf_enemy_attack_add_pattern(
85+
shadow_patterns, shadow_count, cell->pattern))) return false;
86+
}
87+
}
88+
}
89+
return *artwork_count > 0u && *shadow_count > 0u;
90+
}
91+
92+
bool sf_scenario_enemy_attack_assets_load(
93+
SfScenarioEnemyAttackAssets *attack, const char *data_root,
94+
const SfMctScenario *scenario, int32_t resource_id, uint16_t chart,
95+
SfArena *arena) {
96+
SfCafAnimationSelection selections[SF_SCENARIO_ENEMY_DIRECTION_COUNT];
97+
uint8_t selected_parts[SF_MCT_PERSON_PART_LIMIT];
98+
int32_t artwork_patterns[SF_NJP_SPARSE_PATTERN_LIMIT];
99+
int32_t shadow_patterns[SF_NJP_SPARSE_PATTERN_LIMIT];
100+
uint16_t artwork_count = 0u;
101+
uint16_t shadow_count = 0u;
102+
uint8_t selected_count = 0u;
103+
uint8_t enabled_parts = 0u;
104+
uint8_t available_parts = UINT8_MAX;
105+
uint8_t direction;
106+
uint8_t part;
107+
char path[SF_RETAIL_PATH_CAPACITY];
108+
size_t mark;
109+
bool success = false;
110+
if (!attack || !data_root || !scenario || resource_id < 0 || !arena)
111+
return false;
112+
mark = sf_arena_mark(arena);
113+
memset(attack, 0, sizeof(*attack));
114+
if (chart > UINT8_MAX || !sf_enemy_attack_request(
115+
scenario, resource_id, chart, &enabled_parts) ||
116+
!sf_enemy_attack_path(
117+
path, sizeof(path), data_root,
118+
sf_retail_enemy_paths.animation_format, resource_id)) goto done;
119+
for (direction = 0u; direction < SF_SCENARIO_ENEMY_DIRECTION_COUNT;
120+
++direction) {
121+
uint8_t count;
122+
if (!sf_caf_chart_direction_part_count(
123+
path, chart, direction, &count)) goto done;
124+
if (count < available_parts) available_parts = count;
125+
selections[direction].chart = chart;
126+
selections[direction].direction = direction;
127+
}
128+
if (available_parts > SF_MCT_PERSON_PART_LIMIT)
129+
available_parts = SF_MCT_PERSON_PART_LIMIT;
130+
for (part = 0u; part < available_parts; ++part) {
131+
if ((enabled_parts & (uint8_t) (1u << part)) != 0u)
132+
selected_parts[selected_count++] = part;
133+
}
134+
if (selected_count == 0u || !sf_caf_load_selected_animations(
135+
path, selections, SF_SCENARIO_ENEMY_DIRECTION_COUNT,
136+
selected_parts, selected_count, arena, attack->animations) ||
137+
!sf_enemy_attack_collect_patterns(
138+
attack->animations, artwork_patterns, &artwork_count,
139+
shadow_patterns, &shadow_count) ||
140+
!sf_enemy_attack_path(
141+
path, sizeof(path), data_root,
142+
sf_retail_enemy_paths.artwork_format, resource_id) ||
143+
!sf_njp_load_sparse_patterns(
144+
path, artwork_patterns, artwork_count, arena, &attack->artwork) ||
145+
!sf_enemy_attack_path(
146+
path, sizeof(path), data_root,
147+
sf_retail_enemy_paths.shadow_format, resource_id) ||
148+
!sf_njp_load_sparse_patterns(
149+
path, shadow_patterns, shadow_count, arena, &attack->shadows))
150+
goto done;
151+
attack->resource_id = resource_id;
152+
attack->chart = chart;
153+
attack->memory_bytes = sf_arena_mark(arena) - mark;
154+
attack->loaded = true;
155+
success = true;
156+
done:
157+
if (!success) {
158+
(void) sf_arena_rewind(arena, mark);
159+
memset(attack, 0, sizeof(*attack));
160+
}
161+
return success;
162+
}

0 commit comments

Comments
 (0)