Split game code and tests into focused modules
This commit is contained in:
20 files changed
+2611
-2431
No files matched your search
@@ -0,0 +1,223 @@
|
||||
#include "test_support.h"
|
||||
|
||||
void check_following_and_battle(void)
|
||||
{
|
||||
static u16 expected[WIDTH * HEIGHT], visible[WIDTH * HEIGHT];
|
||||
static const unsigned directions[] = {RIGHT, DOWN, LEFT, UP};
|
||||
partner_owned = 1;
|
||||
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
|
||||
current_room = (enum Room)room;
|
||||
int x, y;
|
||||
reset_position(&x, &y);
|
||||
if (current_room == ROUTE) { y = 94; reset_follower(x, y); }
|
||||
assert(follower_x == x && follower_y == y);
|
||||
render_scene(x, y);
|
||||
copy_pending_rows(visible);
|
||||
for (int frame = 0; frame < 100; ++frame) {
|
||||
int old_x = x, old_y = y;
|
||||
int old_fx = follower_x, old_fy = follower_y;
|
||||
int old_head = trail_head;
|
||||
unsigned keys = directions[(frame / 10) % 4];
|
||||
player_facing = facing_for_keys(keys, player_facing);
|
||||
int nx = x + !!(keys & RIGHT) - !!(keys & LEFT);
|
||||
int ny = y + !!(keys & DOWN) - !!(keys & UP);
|
||||
if (can_walk(nx, y)) x = nx;
|
||||
if (can_walk(x, ny)) y = ny;
|
||||
move_follower(old_x, old_y, x, y);
|
||||
assert(can_walk(follower_x, follower_y));
|
||||
if (old_x == x && old_y == y) assert(trail_head == old_head);
|
||||
restore(old_x - 8, old_y - 20, 17, 24);
|
||||
restore(old_fx - 8, old_fy - 20, 17, 24);
|
||||
actors(x, y, 0);
|
||||
location_status(x, y);
|
||||
assert(pending_pixels() < 16500);
|
||||
copy_pending_rows(visible);
|
||||
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
||||
memcpy(expected, SCREEN, sizeof(expected));
|
||||
render_scene(x, y);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
copy_pending_rows(visible);
|
||||
}
|
||||
}
|
||||
current_room = OUTSIDE;
|
||||
reset_follower(108, 103);
|
||||
for (int step = 0; step < 20; ++step) move_follower(108 + step, 103, 109 + step, 103);
|
||||
assert(follower_x == 114 && follower_y == 103); /* Exactly 14 steps behind. */
|
||||
int head = trail_head;
|
||||
move_follower(128, 103, 128, 103);
|
||||
assert(trail_head == head);
|
||||
int x = 108, y = 131;
|
||||
assert(use_map_exit(&x, &y, DOWN));
|
||||
assert(follower_x == x && follower_y == y && current_room == ROUTE);
|
||||
current_room = OUTSIDE;
|
||||
reset_follower(108, 103);
|
||||
x = 108;
|
||||
y = 103;
|
||||
for (int step = 0; step < 20; ++step) {
|
||||
move_follower(x, y, x + 1, y);
|
||||
++x;
|
||||
}
|
||||
render_scene(x, y);
|
||||
write_preview("build/follower-preview.ppm");
|
||||
|
||||
partner_owned = 0;
|
||||
assert(!begin_battle(182, 113));
|
||||
partner_owned = 1;
|
||||
current_room = ROUTE;
|
||||
assert(!begin_battle(182, 113));
|
||||
current_room = OUTSIDE;
|
||||
assert(!begin_battle(108, 103));
|
||||
assert(!near_golden(162, 113));
|
||||
assert(begin_battle(182, 113));
|
||||
assert(!begin_battle(182, 113));
|
||||
assert(battle.phase == BATTLE_TURN && battle.sprout_hp == SPROUT_HP &&
|
||||
battle.enemy_hp == GOLDEN_HP);
|
||||
unsigned char saved[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
draw_battle();
|
||||
write_preview("build/battle-preview.ppm");
|
||||
copy_pending_rows(visible);
|
||||
assert(!battle_input(0));
|
||||
assert(!battle_input(SELECT));
|
||||
assert(battle.turns == 0);
|
||||
assert(battle_input(RIGHT));
|
||||
assert(battle.move == 1 && battle.enemy_hp == GOLDEN_HP);
|
||||
assert(battle_input(A));
|
||||
assert(battle.enemy_hp == 11 && battle.sprout_hp == 19 && battle.turns == 1);
|
||||
draw_battle_hud();
|
||||
assert(pending_pixels() < 16500);
|
||||
copy_pending_rows(visible);
|
||||
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
||||
memcpy(expected, SCREEN, sizeof(expected));
|
||||
draw_battle();
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
copy_pending_rows(visible);
|
||||
assert(!battle_input(0)); /* A held key without a new press adds no turn. */
|
||||
assert(battle.turns == 1);
|
||||
assert(battle_input(A));
|
||||
assert(battle.enemy_hp == 4 && battle.sprout_hp == 14);
|
||||
assert(battle_input(A));
|
||||
assert(battle.phase == BATTLE_WON && battle.enemy_hp == 0 && battle.sprout_hp == 14);
|
||||
draw_battle_hud();
|
||||
assert(pending_pixels() < 16500);
|
||||
write_preview("build/battle-win-preview.ppm");
|
||||
assert(!battle_input(RIGHT));
|
||||
assert(battle_input(A) && battle.phase == BATTLE_OFF);
|
||||
|
||||
assert(begin_battle(182, 113));
|
||||
assert(battle_input(B) && battle.phase == BATTLE_FLED);
|
||||
assert(battle.sprout_hp == SPROUT_HP && battle.enemy_hp == GOLDEN_HP);
|
||||
assert(battle_input(B) && battle.phase == BATTLE_OFF);
|
||||
assert(begin_battle(182, 113));
|
||||
battle.sprout_hp = 1;
|
||||
assert(battle_input(A) && battle.phase == BATTLE_LOST);
|
||||
assert(battle.sprout_hp == 0);
|
||||
assert(battle_input(A) && battle.phase == BATTLE_OFF);
|
||||
assert(begin_battle(182, 113));
|
||||
assert(battle.sprout_hp == SPROUT_HP); /* Free recovery after each battle. */
|
||||
for (int turn = 0; turn < 5; ++turn) assert(battle_input(A));
|
||||
assert(battle.phase == BATTLE_WON && battle.sprout_hp == 4 && battle.enemy_hp == 0);
|
||||
assert(battle_input(A) && battle.phase == BATTLE_OFF);
|
||||
assert(partner_owned && memcmp(saved, test_save, sizeof(saved)) == 0);
|
||||
partner_owned = 0;
|
||||
follower_ready = 0;
|
||||
player_facing = FACING_DOWN;
|
||||
}
|
||||
|
||||
void check_wild_encounters(void)
|
||||
{
|
||||
for (int kind = 0; kind < 3; ++kind) {
|
||||
int opaque = 0;
|
||||
for (int row = 0; row < 24; ++row) {
|
||||
assert(strlen(wild_art[kind].rows[row]) == 24);
|
||||
for (int col = 0; col < 24; ++col) {
|
||||
char pixel = wild_art[kind].rows[row][col];
|
||||
if (pixel == '.') continue;
|
||||
assert(pixel >= '1' && pixel <= '8');
|
||||
++opaque;
|
||||
}
|
||||
}
|
||||
assert(opaque > 180); /* Full original sprites, not palette swaps. */
|
||||
}
|
||||
partner_owned = 1;
|
||||
current_room = OUTSIDE;
|
||||
assert(!in_tall_grass(48, 70));
|
||||
assert(!check_grass_encounter(48, 70, 49, 70));
|
||||
current_room = ROUTE;
|
||||
assert(in_tall_grass(32, 53) && in_tall_grass(80, 86));
|
||||
assert(in_tall_grass(151, 112) && in_tall_grass(207, 132));
|
||||
assert(!in_tall_grass(31, 70) && !in_tall_grass(81, 70));
|
||||
assert(!in_tall_grass(48, 87) && !in_tall_grass(108, 94));
|
||||
partner_owned = 0;
|
||||
for (int i = 0; i < 100; ++i) assert(!check_grass_encounter(48, 70, 49, 70));
|
||||
assert(grass_steps == 0);
|
||||
partner_owned = 1;
|
||||
for (int i = 0; i < 100; ++i) assert(!check_grass_encounter(48, 70, 48, 70));
|
||||
assert(grass_steps == 0); /* Waiting in the grass never starts a battle. */
|
||||
for (int i = 0; i < 100; ++i) assert(!check_grass_encounter(108, 94, 109, 94));
|
||||
assert(grass_steps == 0);
|
||||
|
||||
unsigned seen = 0;
|
||||
for (unsigned trial = 1; trial <= 64; ++trial) {
|
||||
random_state = trial * 719u;
|
||||
grass_steps = 0;
|
||||
int steps;
|
||||
for (steps = 1; steps <= 64; ++steps) {
|
||||
int x = 48 + (steps & 1), old_x = 48 + ((steps + 1) & 1);
|
||||
if (check_grass_encounter(old_x, 70, x, 70)) break;
|
||||
assert(battle.phase == BATTLE_OFF);
|
||||
}
|
||||
assert(steps >= 24 && steps <= 64);
|
||||
assert(battle.enemy >= FERNFOX && battle.enemy <= PEBBLIT);
|
||||
assert(battle.phase == BATTLE_TURN && battle.enemy_hp == species[battle.enemy].hp);
|
||||
assert(grass_steps == 0);
|
||||
seen |= 1u << battle.enemy;
|
||||
assert(!check_grass_encounter(48, 70, 49, 70)); /* No nested battle. */
|
||||
assert(battle_input(B) && battle.phase == BATTLE_FLED);
|
||||
assert(battle_input(A) && battle.phase == BATTLE_OFF);
|
||||
for (int i = 0; i < 23; ++i) assert(!check_grass_encounter(48, 70, 49, 70));
|
||||
assert(!check_grass_encounter(80, 70, 81, 70));
|
||||
assert(grass_steps == 0); /* Leaving the grass resets the meter. */
|
||||
}
|
||||
assert(seen == ((1u << FERNFOX) | (1u << EMBERWING) | (1u << PEBBLIT)));
|
||||
int right_steps = 0;
|
||||
while (++right_steps <= 64)
|
||||
if (check_grass_encounter(180, 121, 181, 121)) break;
|
||||
assert(right_steps <= 64 && battle.phase == BATTLE_TURN);
|
||||
assert(battle_input(B) && battle_input(A));
|
||||
assert(battle.phase == BATTLE_OFF);
|
||||
unsigned char saved[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
static u16 visible[WIDTH * HEIGHT];
|
||||
const char *previews[] = {
|
||||
"build/wild-fernfox-preview.ppm", "build/wild-emberwing-preview.ppm", "build/wild-pebblit-preview.ppm"
|
||||
};
|
||||
for (int kind = FERNFOX; kind <= PEBBLIT; ++kind) {
|
||||
assert(start_battle((enum Species)kind));
|
||||
assert(battle.enemy == (enum Species)kind);
|
||||
draw_battle();
|
||||
write_preview(previews[kind - FERNFOX]);
|
||||
copy_pending_rows(visible);
|
||||
assert(battle_input(RIGHT));
|
||||
int turns = 0;
|
||||
while (battle.phase == BATTLE_TURN && turns < 10) {
|
||||
assert(battle_input(A));
|
||||
++turns;
|
||||
assert(battle.enemy_hp >= 0 && battle.enemy_hp <= species[kind].hp);
|
||||
assert(battle.sprout_hp >= 0 && battle.sprout_hp <= SPROUT_HP);
|
||||
draw_battle_hud();
|
||||
assert(pending_pixels() < 16500);
|
||||
copy_pending_rows(visible);
|
||||
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
||||
}
|
||||
assert(battle.phase == BATTLE_WON && battle.sprout_hp > 0);
|
||||
assert(battle_input(A) && battle.phase == BATTLE_OFF);
|
||||
}
|
||||
assert(!start_battle(SPECIES_COUNT));
|
||||
assert(memcmp(saved, test_save, sizeof(saved)) == 0);
|
||||
random_state = 0;
|
||||
assert(next_random() != 0);
|
||||
partner_owned = 0;
|
||||
grass_steps = 0;
|
||||
current_room = OUTSIDE;
|
||||
}
|
||||
+1
-1045
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,221 @@
|
||||
#include "test_support.h"
|
||||
|
||||
void check_buffered_walking(void)
|
||||
{
|
||||
static u16 visible[WIDTH * HEIGHT], before[WIDTH * HEIGHT];
|
||||
static const unsigned directions[] = {RIGHT, DOWN, LEFT, UP};
|
||||
reset_dirty_rows();
|
||||
mark_dirty(-2, -2, 4, 4);
|
||||
assert(pending_pixels() == 4);
|
||||
reset_dirty_rows();
|
||||
mark_dirty(239, 159, 4, 4);
|
||||
assert(pending_pixels() == 1);
|
||||
reset_dirty_rows();
|
||||
mark_dirty(-8, 0, 2, 2);
|
||||
mark_dirty(240, 160, 4, 4);
|
||||
assert(pending_pixels() == 0);
|
||||
|
||||
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
|
||||
current_room = (enum Room)room;
|
||||
player_facing = FACING_DOWN;
|
||||
int x, y;
|
||||
reset_position(&x, &y);
|
||||
if (current_room == ROUTE) y = 94;
|
||||
render_scene(x, y);
|
||||
assert(pending_pixels() == WIDTH * HEIGHT);
|
||||
copy_pending_rows(visible);
|
||||
for (int frame = 0; frame < 80; ++frame) {
|
||||
memcpy(before, visible, sizeof(before));
|
||||
unsigned keys = directions[(frame / 10) % 4];
|
||||
int old_x = x, old_y = y;
|
||||
player_facing = facing_for_keys(keys, player_facing);
|
||||
int nx = x + !!(keys & RIGHT) - !!(keys & LEFT);
|
||||
int ny = y + !!(keys & DOWN) - !!(keys & UP);
|
||||
if (can_walk(nx, y)) x = nx;
|
||||
if (can_walk(x, ny)) y = ny;
|
||||
restore(old_x - 8, old_y - 20, 17, 24);
|
||||
actors(x, y, (frame >> 3) & 1);
|
||||
if (near_door(old_x, old_y) != near_door(x, y) ||
|
||||
near_map_exit(old_x, old_y) != near_map_exit(x, y) ||
|
||||
near_route_sign(old_x, old_y) != near_route_sign(x, y)) location_status(x, y);
|
||||
assert(pending_pixels() < 16500);
|
||||
/* Neither erasing nor drawing the head may touch the display. */
|
||||
assert(memcmp(before, visible, sizeof(before)) == 0);
|
||||
copy_pending_rows(visible);
|
||||
assert(pending_pixels() == 0);
|
||||
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
||||
}
|
||||
status("TALKING TO MILA");
|
||||
dialogue_box(0);
|
||||
assert(pending_pixels() < 16500);
|
||||
copy_pending_rows(visible);
|
||||
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
||||
restore(DIALOGUE_X, DIALOGUE_Y, DIALOGUE_W, DIALOGUE_H);
|
||||
actors(x, y, 0);
|
||||
location_status(x, y);
|
||||
assert(pending_pixels() < 16500);
|
||||
copy_pending_rows(visible);
|
||||
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
||||
}
|
||||
current_room = OUTSIDE;
|
||||
player_facing = FACING_DOWN;
|
||||
}
|
||||
|
||||
void check_route_travel(void)
|
||||
{
|
||||
static u16 visible[WIDTH * HEIGHT];
|
||||
current_room = OUTSIDE;
|
||||
assert(reachable(108, 103, 108, 131));
|
||||
int x = 80, y = 131;
|
||||
assert(!use_map_exit(&x, &y, DOWN)); /* No exit through the fence. */
|
||||
x = 108;
|
||||
assert(!use_map_exit(&x, &y, UP)); /* Must walk out, not back in. */
|
||||
y = 130;
|
||||
assert(!use_map_exit(&x, &y, DOWN)); /* Not across the edge yet. */
|
||||
y = 131;
|
||||
assert(!use_map_exit(&x, &y, A)); /* No button press needed. */
|
||||
|
||||
for (int trip = 0; trip < 5; ++trip) {
|
||||
x = 108;
|
||||
y = 131;
|
||||
assert(use_map_exit(&x, &y, DOWN));
|
||||
assert(current_room == ROUTE && x == 108 && y == 60);
|
||||
assert(player_facing == FACING_DOWN && can_walk(x, y));
|
||||
assert(!use_map_exit(&x, &y, DOWN)); /* Held direction cannot bounce. */
|
||||
assert(!near_door(177, 83));
|
||||
assert(!near_npc(NPC_X, NPC_Y));
|
||||
assert(!use_door(&x, &y));
|
||||
assert(!can_walk(175, 60)); /* Pond. */
|
||||
assert(!can_walk(135, 65)); /* Sign. */
|
||||
assert(!can_walk(49, 114)); /* Boulder. */
|
||||
assert(!can_walk(20, 94)); /* Forest boundary. */
|
||||
assert(!can_walk(108, 132)); /* No unfinished south exit. */
|
||||
assert(can_walk(48, 70)); /* Grass patches are walkable. */
|
||||
assert(can_walk(183, 121));
|
||||
assert(near_route_sign(135, 80));
|
||||
assert(!near_route_sign(108, 54));
|
||||
assert(reachable(x, y, 135, 80));
|
||||
assert(reachable(x, y, 183, 121));
|
||||
assert(reachable(x, y, 108, 47));
|
||||
render_scene(x, y);
|
||||
assert(pending_pixels() == WIDTH * HEIGHT);
|
||||
copy_pending_rows(visible);
|
||||
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
||||
assert(SCREEN[NPC_Y * WIDTH + NPC_X] == route_scenery(NPC_X, NPC_Y));
|
||||
assert(SCREEN[95 * WIDTH + 181] == route_scenery(181, 95));
|
||||
write_preview("build/route-preview.ppm");
|
||||
|
||||
x = 180;
|
||||
y = 100;
|
||||
reset_position(&x, &y);
|
||||
assert(current_room == ROUTE && x == 108 && y == 60);
|
||||
assert(player_facing == FACING_DOWN);
|
||||
for (; y > 47; --y) assert(can_walk(x, y));
|
||||
assert(!use_map_exit(&x, &y, DOWN));
|
||||
assert(use_map_exit(&x, &y, UP));
|
||||
assert(current_room == OUTSIDE && x == 108 && y == 125);
|
||||
assert(player_facing == FACING_UP && can_walk(x, y));
|
||||
assert(!use_map_exit(&x, &y, UP));
|
||||
assert(reachable(x, y, 108, 103));
|
||||
assert(reachable(x, y, 177, 83)); /* House still reachable on return. */
|
||||
render_scene(x, y);
|
||||
copy_pending_rows(visible);
|
||||
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
||||
}
|
||||
current_room = COTTAGE;
|
||||
x = 108;
|
||||
y = 131;
|
||||
assert(!use_map_exit(&x, &y, DOWN)); /* Cottage keeps its own exit. */
|
||||
current_room = OUTSIDE;
|
||||
player_facing = FACING_DOWN;
|
||||
}
|
||||
|
||||
void check_mellon_visit(void)
|
||||
{
|
||||
static u16 expected[WIDTH * HEIGHT];
|
||||
current_room = OUTSIDE;
|
||||
assert(reachable(108, 103, 222, 113));
|
||||
int x = 222, y = 100;
|
||||
assert(!use_map_exit(&x, &y, RIGHT)); /* No passage through the fence. */
|
||||
y = 113;
|
||||
assert(!use_map_exit(&x, &y, LEFT));
|
||||
for (int visit = 0; visit < 5; ++visit) {
|
||||
x = 222;
|
||||
y = 113;
|
||||
assert(use_map_exit(&x, &y, RIGHT));
|
||||
assert(current_room == MELLON_GARDEN && x == 31 && y == 113);
|
||||
assert(player_facing == FACING_RIGHT && can_walk(x, y));
|
||||
assert(!use_map_exit(&x, &y, RIGHT));
|
||||
assert(!near_npc(NPC_X, NPC_Y));
|
||||
assert(reachable(x, y, 177, 83));
|
||||
assert(reachable(x, y, 17, 113));
|
||||
assert(!can_walk(40, 65)); /* Melon beds. */
|
||||
reset_position(&x, &y);
|
||||
assert(x == 31 && y == 113);
|
||||
render_scene(x, y);
|
||||
write_preview("build/mellon-garden-preview.ppm");
|
||||
assert(village_scenery(160, 41) != mellon_garden_scenery(160, 41));
|
||||
|
||||
x = 177;
|
||||
y = 83;
|
||||
assert(near_door(x, y));
|
||||
assert(use_door(&x, &y));
|
||||
assert(current_room == MELLON_HOUSE && x == 120 && y == 119);
|
||||
assert(can_walk(x, y) && !near_door(x, y));
|
||||
assert(!can_walk(PROF_X, PROF_Y));
|
||||
assert(near_npc(PROF_X, PROF_Y + 22));
|
||||
assert(!near_npc(PROF_X, PROF_Y + 23));
|
||||
assert(reachable(x, y, PROF_X, PROF_Y + 22));
|
||||
assert(reachable(x, y, 120, 125));
|
||||
assert(!near_map_exit(222, 113));
|
||||
reset_position(&x, &y);
|
||||
assert(x == 120 && y == 119 && current_room == MELLON_HOUSE);
|
||||
render_scene(x, y);
|
||||
write_preview("build/mellon-house-preview.ppm");
|
||||
|
||||
/* Repainting near either side of the professor must not leave trails. */
|
||||
const int positions[][2] = {{100, 92}, {126, 92}, {113, 101}, {113, 83}};
|
||||
for (unsigned i = 0; i < sizeof(positions) / sizeof(positions[0]); ++i) {
|
||||
int nx = positions[i][0], ny = positions[i][1];
|
||||
assert(can_walk(nx, ny));
|
||||
render_scene(nx, ny);
|
||||
memcpy(expected, SCREEN, sizeof(expected));
|
||||
render_scene(x, y);
|
||||
restore(x - 8, y - 20, 17, 24);
|
||||
actors(nx, ny, 0);
|
||||
location_status(nx, ny);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
dialogue_box(0);
|
||||
restore(DIALOGUE_X, DIALOGUE_Y, DIALOGUE_W, DIALOGUE_H);
|
||||
actors(nx, ny, 0);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
}
|
||||
render_scene(PROF_X, PROF_Y + 22);
|
||||
dialogue_box(0);
|
||||
write_preview("build/mellon-dialogue-preview.ppm");
|
||||
for (int page = 0; page < DIALOGUE_PAGES; ++page)
|
||||
for (int line = 0; line < 2; ++line) {
|
||||
const char *message = professor_dialogue[page][line];
|
||||
assert(strlen(message) <= 34);
|
||||
for (; *message; ++message)
|
||||
assert(*message == ' ' || (*message >= 'A' && *message <= 'Z'));
|
||||
}
|
||||
|
||||
x = 120;
|
||||
y = 125;
|
||||
assert(use_door(&x, &y));
|
||||
assert(current_room == MELLON_GARDEN && x == 177 && y == 83);
|
||||
assert(can_walk(x, y) && reachable(x, y, 17, 113));
|
||||
x = 17;
|
||||
y = 113;
|
||||
assert(!use_map_exit(&x, &y, RIGHT));
|
||||
assert(use_map_exit(&x, &y, LEFT));
|
||||
assert(current_room == OUTSIDE && x == 210 && y == 113);
|
||||
assert(player_facing == FACING_LEFT && can_walk(x, y));
|
||||
assert(!use_map_exit(&x, &y, LEFT));
|
||||
assert(reachable(x, y, 108, 131)); /* South route still accessible. */
|
||||
assert(reachable(x, y, 177, 83)); /* Original cottage still accessible. */
|
||||
}
|
||||
current_room = OUTSIDE;
|
||||
player_facing = FACING_DOWN;
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
#include "test_support.h"
|
||||
|
||||
void check_movement_clock_and_speed(void)
|
||||
{
|
||||
const int render_rates[] = {15, 20, 30, 60, 120};
|
||||
for (int following = 0; following < 2; ++following)
|
||||
for (unsigned rate = 0; rate < sizeof(render_rates) / sizeof(render_rates[0]); ++rate) {
|
||||
current_room = OUTSIDE;
|
||||
partner_owned = following;
|
||||
int x = 40, y = 125, total_ticks = 0;
|
||||
reset_follower(x, y);
|
||||
pause_movement_at(0);
|
||||
for (int frame = 1; frame <= render_rates[rate]; ++frame) {
|
||||
unsigned now = (unsigned)(frame * MOVEMENT_CLOCK_HZ / render_rates[rate]);
|
||||
int ticks = movement_ticks_at(now);
|
||||
total_ticks += ticks;
|
||||
assert(walk_movement(RIGHT, &x, &y, ticks) == WALK_NORMAL);
|
||||
}
|
||||
assert(total_ticks == MOVEMENT_HZ && x == 160 && y == 125);
|
||||
if (following) assert(follower_x == x - FOLLOW_STEPS && follower_y == y);
|
||||
}
|
||||
|
||||
/* Timer rollover, idle reads, bounded catch-up, and paused menus. */
|
||||
pause_movement_at(0xffffff00u);
|
||||
assert(movement_ticks_at(0x00000100u) == 1);
|
||||
assert(movement_ticks_at(0x00000100u) == 0);
|
||||
pause_movement_at(0);
|
||||
assert(movement_ticks_at(MOVEMENT_CLOCK_HZ) == MAX_MOVEMENT_TICKS);
|
||||
assert(movement_ticks_at(MOVEMENT_CLOCK_HZ) == 0); /* No hidden backlog. */
|
||||
pause_movement_at(123456u);
|
||||
assert(movement_ticks_at(123456u) == 0);
|
||||
pause_movement_at(999999u); /* Time spent in a menu is discarded. */
|
||||
assert(movement_ticks_at(999999u) == 0);
|
||||
assert(movement_ticks_at(999999u + MOVEMENT_CLOCK_HZ / 60 + 1) == 1);
|
||||
|
||||
partner_owned = 0;
|
||||
current_room = OUTSIDE;
|
||||
int x = 108, y = 103;
|
||||
assert(walk_movement(RIGHT, &x, &y, 1) == WALK_NORMAL);
|
||||
assert(x == 110 && y == 103 && player_facing == FACING_RIGHT);
|
||||
assert(walk_movement(UP, &x, &y, 0) == WALK_NORMAL);
|
||||
assert(x == 110 && y == 103 && player_facing == FACING_UP);
|
||||
x = 132; y = 106;
|
||||
assert(walk_movement(RIGHT, &x, &y, MAX_MOVEMENT_TICKS) == WALK_NORMAL);
|
||||
assert(x == 133 && can_walk(x, y)); /* Never tunnel through Mila. */
|
||||
x = 84; y = 70;
|
||||
assert(walk_movement(LEFT, &x, &y, 2) == WALK_NORMAL);
|
||||
assert(x == 82 && can_walk(x, y)); /* Stop at the pond, pixel by pixel. */
|
||||
x = 177; y = 80;
|
||||
assert(walk_movement(UP, &x, &y, 2) == WALK_NORMAL);
|
||||
assert(y == 78 && near_door(x, y)); /* Door remains usable. */
|
||||
|
||||
pause_movement_at(0);
|
||||
x = 160; y = 90;
|
||||
for (int tick = 0; tick < 20; ++tick)
|
||||
assert(walk_movement(RIGHT | DOWN, &x, &y, 1) == WALK_NORMAL);
|
||||
assert(x == 188 && y == 118); /* Approximately 40 pixels, not 56 diagonally. */
|
||||
assert(walk_movement(RIGHT, &x, &y, 1) == WALK_NORMAL);
|
||||
assert(x == 190 && diagonal_fraction == 0);
|
||||
assert(walk_movement(RIGHT | LEFT, &x, &y, 5) == WALK_NORMAL);
|
||||
assert(x == 190 && y == 118);
|
||||
|
||||
/* Crossing an exit stops remaining substeps instead of skipping its trigger. */
|
||||
partner_owned = 1;
|
||||
x = 108; y = 129;
|
||||
reset_follower(x, y);
|
||||
assert(walk_movement(DOWN, &x, &y, 1) == WALK_MAP_CHANGED);
|
||||
assert(current_room == ROUTE && x == 108 && y == 60);
|
||||
assert(follower_x == x && follower_y == y);
|
||||
y = 48;
|
||||
assert(walk_movement(UP, &x, &y, 1) == WALK_MAP_CHANGED);
|
||||
assert(current_room == OUTSIDE && x == 108 && y == 125);
|
||||
x = 221; y = 113;
|
||||
assert(walk_movement(RIGHT, &x, &y, 5) == WALK_MAP_CHANGED);
|
||||
assert(current_room == MELLON_GARDEN && x == 31 && y == 113);
|
||||
x = 18;
|
||||
assert(walk_movement(LEFT, &x, &y, 1) == WALK_MAP_CHANGED);
|
||||
assert(current_room == OUTSIDE && x == 210 && y == 113);
|
||||
current_room = COTTAGE;
|
||||
x = 120; y = 125;
|
||||
assert(walk_movement(DOWN, &x, &y, 5) == WALK_NORMAL);
|
||||
assert(current_room == COTTAGE && y == 131); /* Indoor exits still require A. */
|
||||
|
||||
/* Two-pixel ticks still count every traveled substep for grass and following. */
|
||||
current_room = ROUTE;
|
||||
x = 40; y = 70;
|
||||
reset_follower(x, y);
|
||||
grass_steps = 0;
|
||||
random_state = 1; /* First roll does not trigger an encounter. */
|
||||
for (int tick = 0; tick < 12; ++tick)
|
||||
assert(walk_movement(RIGHT, &x, &y, 1) == WALK_NORMAL);
|
||||
assert(x == 64 && grass_steps == 24 && follower_x == 50 && follower_y == 70);
|
||||
grass_steps = 63; /* Next traveled pixel guarantees an encounter. */
|
||||
assert(walk_movement(RIGHT, &x, &y, 5) == WALK_ENCOUNTER);
|
||||
assert(x == 65 && y == 70 && battle.phase == BATTLE_TURN);
|
||||
assert(battle_input(B) && battle_input(A) && battle.phase == BATTLE_OFF);
|
||||
/* Faster and catch-up frames must erase both old sprites completely. */
|
||||
static u16 snapshot[WIDTH * HEIGHT];
|
||||
const unsigned directions[] = {RIGHT, DOWN, LEFT, UP};
|
||||
const int tick_counts[] = {1, 2, 1, 3, 0};
|
||||
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
|
||||
current_room = (enum Room)room;
|
||||
reset_position(&x, &y);
|
||||
if (current_room == OUTSIDE) { x = 40; y = 125; }
|
||||
if (current_room == ROUTE) y = 94;
|
||||
reset_follower(x, y);
|
||||
render_scene(x, y);
|
||||
reset_dirty_rows();
|
||||
int phase = 0;
|
||||
for (int frame = 0; frame < 40; ++frame) {
|
||||
int old_x = x, old_y = y, old_fx = follower_x, old_fy = follower_y;
|
||||
int ticks = tick_counts[frame % 5];
|
||||
assert(walk_movement(directions[frame / 10], &x, &y, ticks) == WALK_NORMAL);
|
||||
restore(old_x - 8, old_y - 20, 17, 24);
|
||||
restore(old_fx - 8, old_fy - 20, 17, 24);
|
||||
actors(x, y, (phase >> 3) & 1);
|
||||
location_status(x, y);
|
||||
assert(pending_pixels() < 16500);
|
||||
memcpy(snapshot, SCREEN, sizeof(snapshot));
|
||||
render_scene(x, y);
|
||||
restore(x - 8, y - 20, 17, 24);
|
||||
actors(x, y, (phase >> 3) & 1);
|
||||
assert(memcmp(snapshot, SCREEN, sizeof(snapshot)) == 0);
|
||||
reset_dirty_rows();
|
||||
phase += ticks;
|
||||
}
|
||||
}
|
||||
current_room = OUTSIDE;
|
||||
partner_owned = follower_ready = 0;
|
||||
grass_steps = 0;
|
||||
player_facing = FACING_DOWN;
|
||||
pause_movement_at(0);
|
||||
puts("Movement: 120 pixels/second at 15/20/30/60/120 render updates, with or without Sprout");
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
#include "test_support.h"
|
||||
|
||||
void check_background_cache(void)
|
||||
{
|
||||
static u16 reference[WIDTH * HEIGHT];
|
||||
background_valid = 0;
|
||||
scenery_samples = 0;
|
||||
reset_dirty_rows();
|
||||
restore(-10, -10, 2, 2);
|
||||
restore(240, 160, 4, 4);
|
||||
assert(!background_valid && scenery_samples == 0 && pending_pixels() == 0);
|
||||
|
||||
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
|
||||
current_room = (enum Room)room;
|
||||
door_open = 0;
|
||||
unsigned before = scenery_samples;
|
||||
restore(0, 0, WIDTH, HEIGHT);
|
||||
assert(scenery_samples - before == WIDTH * HEIGHT);
|
||||
assert(background_valid && background_room == current_room);
|
||||
for (int y = 0; y < HEIGHT; ++y)
|
||||
for (int x = 0; x < WIDTH; ++x)
|
||||
reference[y * WIDTH + x] = scenery(x, y);
|
||||
assert(memcmp(SCREEN, reference, sizeof(reference)) == 0);
|
||||
assert(memcmp(background_cache, reference, sizeof(reference)) == 0);
|
||||
|
||||
/* Reference cost: every 17x24 restore previously evaluated 408 pixels. */
|
||||
before = scenery_samples;
|
||||
for (int y = 63; y < 87; ++y)
|
||||
for (int x = 100; x < 117; ++x) (void)scenery(x, y);
|
||||
assert(scenery_samples - before == 408);
|
||||
before = scenery_samples;
|
||||
for (int frame = 0; frame < 500; ++frame) {
|
||||
restore(100, 63, 17, 24);
|
||||
restore(120, 63, 17, 24); /* Same restoration work with Sprout. */
|
||||
}
|
||||
assert(scenery_samples == before); /* Zero procedural work while walking. */
|
||||
assert(memcmp(SCREEN, reference, sizeof(reference)) == 0);
|
||||
|
||||
/* Actors and menu graphics must never leak into the scenery cache. */
|
||||
int x, y;
|
||||
reset_position(&x, &y);
|
||||
actors(x, y, 0);
|
||||
draw_team();
|
||||
restore(0, 0, WIDTH, HEIGHT);
|
||||
assert(scenery_samples == before);
|
||||
assert(memcmp(SCREEN, reference, sizeof(reference)) == 0);
|
||||
assert(memcmp(background_cache, reference, sizeof(reference)) == 0);
|
||||
}
|
||||
|
||||
const enum Room houses[] = {OUTSIDE, MELLON_GARDEN};
|
||||
for (unsigned i = 0; i < sizeof(houses) / sizeof(houses[0]); ++i) {
|
||||
current_room = houses[i];
|
||||
door_open = 0;
|
||||
restore(0, 0, WIDTH, HEIGHT);
|
||||
for (int open = 1; open >= 0; --open) {
|
||||
door_open = open;
|
||||
unsigned before = scenery_samples;
|
||||
restore(170, 54, 15, 24);
|
||||
assert(scenery_samples - before == 13 * 18); /* Patch only the door. */
|
||||
for (int y = 0; y < HEIGHT; ++y)
|
||||
for (int x = 0; x < WIDTH; ++x)
|
||||
reference[y * WIDTH + x] = scenery(x, y);
|
||||
assert(memcmp(SCREEN, reference, sizeof(reference)) == 0);
|
||||
assert(memcmp(background_cache, reference, sizeof(reference)) == 0);
|
||||
before = scenery_samples;
|
||||
restore(170, 54, 15, 24);
|
||||
assert(scenery_samples == before);
|
||||
}
|
||||
}
|
||||
|
||||
/* Clip once before copying, without altering pixels outside the request. */
|
||||
current_room = OUTSIDE;
|
||||
restore(0, 0, WIDTH, HEIGHT);
|
||||
const u16 marker = RGB(1, 2, 3);
|
||||
rectangle(0, 0, WIDTH, HEIGHT, marker);
|
||||
reset_dirty_rows();
|
||||
unsigned before = scenery_samples;
|
||||
restore(-3, -2, 5, 4);
|
||||
restore(239, 159, 5, 4);
|
||||
restore(0, 0, 0, 10);
|
||||
restore(0, 0, 10, 0);
|
||||
assert(scenery_samples == before && pending_pixels() == 5);
|
||||
for (int y = 0; y < HEIGHT; ++y)
|
||||
for (int x = 0; x < WIDTH; ++x) {
|
||||
u16 expected = ((x < 2 && y < 2) || (x == 239 && y == 159)) ?
|
||||
background_cache[y * WIDTH + x] : marker;
|
||||
assert(SCREEN[y * WIDTH + x] == expected);
|
||||
}
|
||||
assert(test_pixels[0] == 0xbeef && test_pixels[WIDTH * HEIGHT + 1] == 0xbeef);
|
||||
puts("Background cache: 5 maps match reference; warm restores use 0 scenery evaluations (was 408 each)");
|
||||
}
|
||||
|
||||
/* Reference implementation of the previous per-pixel rectangle renderer. */
|
||||
static void reference_sprite(int x, int y, const char *const *art, int width, int rows,
|
||||
const u16 *palette, int scale, int mirrored)
|
||||
{
|
||||
for (int row = 0; row < rows; ++row)
|
||||
for (int col = 0; col < width; ++col) {
|
||||
char pixel = art[row][col];
|
||||
if (pixel == '.') continue;
|
||||
int index = pixel <= '9' ? pixel - '0' : pixel - 'A' + 10;
|
||||
rectangle(x + (mirrored ? width - 1 - col : col) * scale, y + row * scale,
|
||||
scale, scale, palette[index]);
|
||||
}
|
||||
}
|
||||
|
||||
static void sprite_test_canvas(void)
|
||||
{
|
||||
for (int i = 0; i < WIDTH * HEIGHT; ++i) SCREEN[i] = (u16)((i * 3 ^ 0x5a5a) & 0x7fff);
|
||||
reset_dirty_rows();
|
||||
}
|
||||
|
||||
void check_sprite_rows(void)
|
||||
{
|
||||
static u16 expected[WIDTH * HEIGHT], visible[WIDTH * HEIGHT];
|
||||
static const char *const zero_art[] = {"0A..B1..", "..1.....", "........"};
|
||||
const struct { const char *const *art; int width, rows; } images[] = {
|
||||
{person_art, 16, 20}, {person_back_art, 16, 20}, {person_side_art, 16, 20},
|
||||
{creature_art, 16, 16}, {fernfox_art, 24, 24}, {emberwing_art, 24, 24},
|
||||
{pebblit_art, 24, 24}, {zero_art, 8, 3}
|
||||
};
|
||||
const int positions[][2] = {
|
||||
{70, 60}, {-8, 40}, {232, 40}, {80, -12}, {80, 155},
|
||||
{-5, -7}, {236, 156}, {-100, -100}, {240, 30}, {50, 160}
|
||||
};
|
||||
u16 palette[13], alternate[13];
|
||||
for (int i = 0; i < 13; ++i) {
|
||||
palette[i] = RGB(i, i * 2, 31 - i);
|
||||
alternate[i] = RGB(31 - i, i, i * 2);
|
||||
}
|
||||
palette[0] = 0; /* Palette entry zero is opaque black, not transparency. */
|
||||
for (unsigned image = 0; image < sizeof(images) / sizeof(images[0]); ++image)
|
||||
for (int scale = 1; scale <= 3; ++scale)
|
||||
for (int mirror = 0; mirror < 2; ++mirror)
|
||||
for (unsigned p = 0; p < sizeof(positions) / sizeof(positions[0]); ++p) {
|
||||
int x = positions[p][0], y = positions[p][1];
|
||||
const u16 *colors = p & 1 ? alternate : palette;
|
||||
sprite_test_canvas();
|
||||
reference_sprite(x, y, images[image].art, images[image].width,
|
||||
images[image].rows, colors, scale, mirror);
|
||||
memcpy(expected, SCREEN, sizeof(expected));
|
||||
sprite_test_canvas();
|
||||
memcpy(visible, SCREEN, sizeof(visible));
|
||||
unsigned before_rectangles = rectangle_calls;
|
||||
unsigned before_rows = sprite_row_marks;
|
||||
blit_sprite(x, y, images[image].art, images[image].width,
|
||||
images[image].rows, colors, scale, mirror);
|
||||
assert(rectangle_calls == before_rectangles);
|
||||
assert(sprite_row_marks - before_rows <= (unsigned)images[image].rows);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
copy_pending_rows(visible);
|
||||
assert(memcmp(expected, visible, sizeof(expected)) == 0);
|
||||
}
|
||||
|
||||
/* Palette changes reuse decoded indices, rather than cached colors. */
|
||||
sprite_test_canvas();
|
||||
blit_sprite(20, 20, zero_art, 8, 3, palette, 1, 0);
|
||||
assert(SCREEN[20 * WIDTH + 20] == palette[0]);
|
||||
unsigned before_decodes = sprite_decodes;
|
||||
blit_sprite(20, 20, zero_art, 8, 3, alternate, 1, 0);
|
||||
assert(sprite_decodes == before_decodes);
|
||||
assert(SCREEN[20 * WIDTH + 20] == alternate[0]);
|
||||
|
||||
sprite_test_canvas();
|
||||
unsigned before_rectangles = rectangle_calls;
|
||||
reference_sprite(80, 60, person_art, 16, 20, palette, 1, 0);
|
||||
unsigned old_rectangles = rectangle_calls - before_rectangles;
|
||||
assert(old_rectangles > 100);
|
||||
sprite_test_canvas();
|
||||
before_rectangles = rectangle_calls;
|
||||
unsigned before_rows = sprite_row_marks;
|
||||
blit_sprite(80, 60, person_art, 16, 20, palette, 1, 0);
|
||||
assert(rectangle_calls == before_rectangles);
|
||||
assert(sprite_row_marks - before_rows == 20);
|
||||
before_decodes = sprite_decodes;
|
||||
for (int frame = 0; frame < 1000; ++frame)
|
||||
blit_sprite(80, 60, person_art, 16, 20, palette, 1, frame & 1);
|
||||
assert(sprite_decodes == before_decodes && rectangle_calls == before_rectangles);
|
||||
sprite_test_canvas();
|
||||
blit_sprite(0, 0, zero_art, 0, 3, palette, 1, 0);
|
||||
blit_sprite(0, 0, zero_art, 8, 25, palette, 1, 0);
|
||||
blit_sprite(0, 0, zero_art, 8, 3, palette, 0, 0);
|
||||
assert(pending_pixels() == 0);
|
||||
assert(test_pixels[0] == 0xbeef && test_pixels[WIDTH * HEIGHT + 1] == 0xbeef);
|
||||
printf("Sprite rows: character body uses 0 rectangle calls (was %u), 20 row marks, no repeat decoding\n",
|
||||
old_rectangles);
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
#include "test_support.h"
|
||||
|
||||
void check_starter_gift(void)
|
||||
{
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
load_progress();
|
||||
assert(!partner_owned);
|
||||
draw_team();
|
||||
assert(pending_pixels() == WIDTH * HEIGHT);
|
||||
write_preview("build/team-empty-preview.ppm");
|
||||
|
||||
current_room = OUTSIDE;
|
||||
assert(!begin_conversation(108, 103));
|
||||
assert(begin_conversation(NPC_X - 13, NPC_Y));
|
||||
assert(!gift_conversation);
|
||||
assert(advance_conversation(0) == 1);
|
||||
assert(!partner_owned && test_save[0] == 0xff);
|
||||
assert(advance_conversation(1) == -1);
|
||||
assert(!receive_partner());
|
||||
|
||||
current_room = MELLON_HOUSE;
|
||||
int x = PROF_X, y = PROF_Y + 22;
|
||||
assert(can_walk(x, y));
|
||||
assert(!begin_conversation(200, 120));
|
||||
assert(begin_conversation(x, y));
|
||||
assert(gift_conversation && !partner_owned);
|
||||
render_scene(x, y);
|
||||
dialogue_box(0);
|
||||
write_preview("build/starter-intro-preview.ppm");
|
||||
|
||||
assert(advance_conversation(0) == 1);
|
||||
assert(partner_owned && gift_conversation);
|
||||
dialogue_box(1);
|
||||
write_preview("build/starter-gift-preview.ppm");
|
||||
assert(!receive_partner()); /* The same gift cannot add a second partner. */
|
||||
unsigned char saved[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
assert(advance_conversation(1) == -1);
|
||||
assert(!gift_conversation);
|
||||
assert(begin_conversation(x, y));
|
||||
assert(!gift_conversation && partner_owned); /* Follow-up, not another gift. */
|
||||
assert(advance_conversation(0) == 1);
|
||||
assert(advance_conversation(1) == -1);
|
||||
assert(memcmp(saved, test_save, sizeof(saved)) == 0);
|
||||
for (int i = 9; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
|
||||
|
||||
/* Ownership survives map changes, position reset, and loading SRAM. */
|
||||
x = 120;
|
||||
y = 125;
|
||||
assert(use_door(&x, &y));
|
||||
assert(current_room == MELLON_GARDEN && partner_owned);
|
||||
x = 17;
|
||||
y = 113;
|
||||
assert(use_map_exit(&x, &y, LEFT));
|
||||
assert(current_room == OUTSIDE && partner_owned);
|
||||
reset_position(&x, &y);
|
||||
assert(partner_owned);
|
||||
partner_owned = 0;
|
||||
load_progress();
|
||||
assert(partner_owned);
|
||||
draw_team();
|
||||
write_preview("build/team-preview.ppm");
|
||||
static u16 expected[WIDTH * HEIGHT];
|
||||
render_scene(x, y);
|
||||
memcpy(expected, SCREEN, sizeof(expected));
|
||||
draw_team();
|
||||
render_scene(x, y);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
|
||||
/* Reject damaged, incomplete, or unknown-version save records. */
|
||||
for (int byte = 0; byte < 9; ++byte) {
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
test_save[byte] ^= 1;
|
||||
load_progress();
|
||||
assert(!partner_owned);
|
||||
}
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
test_save[0] = 0;
|
||||
load_progress();
|
||||
assert(!partner_owned);
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
load_progress();
|
||||
assert(partner_owned);
|
||||
|
||||
for (int page = 0; page < DIALOGUE_PAGES; ++page)
|
||||
for (int line = 0; line < 2; ++line) {
|
||||
const char *message = professor_followup[page][line];
|
||||
assert(strlen(message) <= 34);
|
||||
for (; *message; ++message)
|
||||
assert(*message == ' ' || (*message >= 'A' && *message <= 'Z'));
|
||||
}
|
||||
partner_owned = 0;
|
||||
gift_conversation = 0;
|
||||
current_room = OUTSIDE;
|
||||
player_facing = FACING_DOWN;
|
||||
}
|
||||
|
||||
void check_ball_gift(void)
|
||||
{
|
||||
static u16 expected[WIDTH * HEIGHT];
|
||||
/* The original Sprout-only save must survive the inventory upgrade. */
|
||||
const unsigned char legacy[] = {'F', 'Q', 'S', 'P', 1, 1, 0xa5, 0x5a};
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
memcpy(test_save, legacy, sizeof(legacy));
|
||||
load_progress();
|
||||
assert(partner_owned && !balls_given && ball_count == 0);
|
||||
assert(test_save[4] == 1); /* Loading alone does not rewrite the save. */
|
||||
|
||||
current_room = ROUTE;
|
||||
assert(!can_walk(RANGER_X, RANGER_Y));
|
||||
assert(can_walk(RANGER_X + 13, RANGER_Y));
|
||||
assert(near_npc(99, 97) && !near_npc(108, 60));
|
||||
assert(reachable(108, 60, 99, 97));
|
||||
assert(reachable(108, 60, 108, 47));
|
||||
assert(reachable(108, 60, 183, 121));
|
||||
assert(!begin_conversation(108, 60));
|
||||
assert(!receive_balls());
|
||||
reset_follower(108, 103);
|
||||
render_scene(99, 97);
|
||||
write_preview("build/ranger-preview.ppm");
|
||||
memcpy(expected, SCREEN, sizeof(expected));
|
||||
assert(begin_conversation(99, 97));
|
||||
assert(ball_gift_conversation && !gift_conversation);
|
||||
dialogue_box(0);
|
||||
assert(ball_count == 0); /* The gift arrives on its receipt page. */
|
||||
assert(advance_conversation(0) == 1);
|
||||
assert(ball_count == 5 && balls_given && partner_owned);
|
||||
dialogue_box(1);
|
||||
write_preview("build/ball-gift-preview.ppm");
|
||||
assert(!receive_balls());
|
||||
assert(advance_conversation(1) == -1);
|
||||
restore(DIALOGUE_X, DIALOGUE_Y, DIALOGUE_W, DIALOGUE_H);
|
||||
actors(99, 97, 0);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
assert(test_save[4] == 2);
|
||||
unsigned char saved[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
for (int visit = 0; visit < 10; ++visit) {
|
||||
assert(begin_conversation(99, 97) && !ball_gift_conversation);
|
||||
assert(advance_conversation(0) == 1);
|
||||
assert(advance_conversation(1) == -1);
|
||||
assert(ball_count == 5 && memcmp(saved, test_save, sizeof(saved)) == 0);
|
||||
}
|
||||
partner_owned = balls_given = ball_count = 0;
|
||||
load_progress();
|
||||
assert(partner_owned && balls_given && ball_count == 5);
|
||||
draw_team();
|
||||
write_preview("build/poke-balls-preview.ppm");
|
||||
for (int i = 9; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
|
||||
int x = 108, y = 47;
|
||||
assert(use_map_exit(&x, &y, UP));
|
||||
assert(ball_count == 5 && balls_given);
|
||||
|
||||
/* Getting the balls before Sprout is allowed and must also persist. */
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
load_progress();
|
||||
current_room = ROUTE;
|
||||
assert(begin_conversation(99, 97));
|
||||
assert(advance_conversation(0) == 1 && advance_conversation(1) == -1);
|
||||
load_progress();
|
||||
assert(!partner_owned && balls_given && ball_count == 5);
|
||||
current_room = MELLON_HOUSE;
|
||||
assert(begin_conversation(PROF_X, PROF_Y + 22));
|
||||
assert(advance_conversation(0) == 1 && advance_conversation(1) == -1);
|
||||
load_progress();
|
||||
assert(partner_owned && balls_given && ball_count == 5);
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
for (int byte = 0; byte < 9; ++byte) {
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
test_save[byte] ^= 1;
|
||||
load_progress();
|
||||
assert(!partner_owned && !balls_given && ball_count == 0);
|
||||
}
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
test_save[6] = 100;
|
||||
test_save[7] = (unsigned char)(0xa5 ^ 2 ^ test_save[5] ^ test_save[6]);
|
||||
load_progress();
|
||||
assert(!partner_owned && !balls_given && ball_count == 0);
|
||||
for (int page = 0; page < DIALOGUE_PAGES; ++page)
|
||||
for (int line = 0; line < 2; ++line) {
|
||||
const char *messages[] = {ranger_dialogue[page][line], ranger_followup[page][line]};
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
assert(strlen(messages[i]) <= 34);
|
||||
for (const char *p = messages[i]; *p; ++p)
|
||||
assert(*p == ' ' || (*p >= 'A' && *p <= 'Z'));
|
||||
}
|
||||
}
|
||||
current_room = OUTSIDE;
|
||||
gift_conversation = ball_gift_conversation = 0;
|
||||
partner_owned = balls_given = ball_count = follower_ready = 0;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "test_support.h"
|
||||
|
||||
u16 test_pixels[WIDTH * HEIGHT + 2];
|
||||
unsigned char test_save[32];
|
||||
|
||||
void render_scene(int x, int y)
|
||||
{
|
||||
draw_scene(x, y);
|
||||
}
|
||||
|
||||
int reachable(int start_x, int start_y, int end_x, int end_y)
|
||||
{
|
||||
static unsigned char visited[HEIGHT][WIDTH];
|
||||
static int queue[WIDTH * HEIGHT][2];
|
||||
static const int directions[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
|
||||
memset(visited, 0, sizeof(visited));
|
||||
int head = 0, tail = 1;
|
||||
queue[0][0] = start_x;
|
||||
queue[0][1] = start_y;
|
||||
visited[start_y][start_x] = 1;
|
||||
while (head < tail) {
|
||||
int x = queue[head][0], y = queue[head][1];
|
||||
++head;
|
||||
if (x == end_x && y == end_y) return 1;
|
||||
for (int direction = 0; direction < 4; ++direction) {
|
||||
int nx = x + directions[direction][0], ny = y + directions[direction][1];
|
||||
if (nx < 0 || nx >= WIDTH || ny < 0 || ny >= HEIGHT) continue;
|
||||
if (visited[ny][nx] || !can_walk(nx, ny)) continue;
|
||||
visited[ny][nx] = 1;
|
||||
queue[tail][0] = nx;
|
||||
queue[tail][1] = ny;
|
||||
++tail;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void check_art(const char *const *art, int rows, int colors)
|
||||
{
|
||||
for (int row = 0; row < rows; ++row) {
|
||||
assert(strlen(art[row]) == 16);
|
||||
for (const char *p = art[row]; *p; ++p) {
|
||||
if (*p == '.') continue;
|
||||
int index = *p <= '9' ? *p - '0' : *p - 'A' + 10;
|
||||
assert(index > 0 && index < colors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void write_preview(const char *path)
|
||||
{
|
||||
FILE *file = fopen(path, "wb");
|
||||
assert(file);
|
||||
fprintf(file, "P6\n%d %d\n255\n", WIDTH, HEIGHT);
|
||||
for (int i = 0; i < WIDTH * HEIGHT; ++i) {
|
||||
u16 color = SCREEN[i];
|
||||
fputc((color & 31) * 255 / 31, file);
|
||||
fputc(((color >> 5) & 31) * 255 / 31, file);
|
||||
fputc(((color >> 10) & 31) * 255 / 31, file);
|
||||
}
|
||||
assert(fclose(file) == 0);
|
||||
}
|
||||
|
||||
/* Simulate the same row copies as hardware DMA, into a separate display. */
|
||||
int pending_pixels(void)
|
||||
{
|
||||
int total = 0;
|
||||
for (int y = 0; y < HEIGHT; ++y) {
|
||||
assert(dirty_first[y] <= WIDTH && dirty_end[y] <= WIDTH);
|
||||
if (dirty_first[y] < dirty_end[y]) total += dirty_end[y] - dirty_first[y];
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
void copy_pending_rows(u16 *visible)
|
||||
{
|
||||
for (int y = 0; y < HEIGHT; ++y) {
|
||||
int first = dirty_first[y], end = dirty_end[y];
|
||||
if (first < end)
|
||||
memcpy(&visible[y * WIDTH + first], &SCREEN[y * WIDTH + first],
|
||||
(size_t)(end - first) * sizeof(u16));
|
||||
}
|
||||
reset_dirty_rows();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef TEST_SUPPORT_H
|
||||
#define TEST_SUPPORT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "../source/game.h"
|
||||
|
||||
void render_scene(int x, int y);
|
||||
int reachable(int start_x, int start_y, int end_x, int end_y);
|
||||
void check_art(const char *const *art, int rows, int colors);
|
||||
void write_preview(const char *path);
|
||||
int pending_pixels(void);
|
||||
void copy_pending_rows(u16 *visible);
|
||||
void check_buffered_walking(void);
|
||||
void check_route_travel(void);
|
||||
void check_mellon_visit(void);
|
||||
void check_starter_gift(void);
|
||||
void check_ball_gift(void);
|
||||
void check_following_and_battle(void);
|
||||
void check_wild_encounters(void);
|
||||
void check_background_cache(void);
|
||||
void check_sprite_rows(void);
|
||||
void check_movement_clock_and_speed(void);
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user