Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bflib_datetm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int get_trigger_time_measurement_fps(struct TriggerTimeMeasurement *trigger)
float get_delta_time()
{
// Allow frame skip to work correctly when delta time is enabled
if ( (game.frame_skip != 0) && ((game.play_gameturn % game.frame_skip) != 0)) {
if ( (game.fastforward_speed != 0) && ((game.play_gameturn % game.fastforward_speed) != 0)) {
return 1.0;
}
long double frame_time_in_nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(TimeNow - delta_time_previous_timepoint).count();
Expand Down
2 changes: 1 addition & 1 deletion src/bflib_sndlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ extern "C" SoundMilesID play_sample(
return source.mss_id;
}
}
if (game.frame_skip < 2)
if (game.fastforward_speed < 2)
{
ERRORLOG("Can't play sample %d from bank %u, too many samples playing at once", smptbl_id, bank_id);
}
Expand Down
4 changes: 2 additions & 2 deletions src/engine_camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ void set_previous_camera_values(struct PlayerInfo* player) {
previous_cam_rotation_angle_y = cam->rotation_angle_y;
previous_cam_rotation_angle_z = cam->rotation_angle_z;
previous_camera_zoom = scale_camera_zoom_to_screen(cam->zoom);
if (game.frame_skip > 0)
if (game.fastforward_speed > 0)
{
reset_interpolation_of_camera(player); // Stop camera from being laggy while frameskipping
reset_interpolation_of_camera(player); // Stop camera from being laggy while fast forwarding
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/engine_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ static void calculate_hud_scale(struct Camera *cam) {

long interpolate(long variable_to_interpolate, long previous, long current)
{
if (is_feature_on(Ft_DeltaTime) == false || game.frame_skip > 0) {
if (is_feature_on(Ft_DeltaTime) == false || game.fastforward_speed > 0) {
return current;
}
// future: by using the predicted future position in the interpolation calculation, we can remove input lag (or visual lag).
Expand Down Expand Up @@ -4966,7 +4966,7 @@ static void draw_fastview_mapwho(struct Camera *cam, struct BucketKindJontySprit
lbDisplay.DrawFlags |= Lb_TEXT_UNDERLNSHADOW;
lbSpriteReMapPtr = red_pal;
thing->time_spent_displaying_hurt_colour += game.delta_time;
if (thing->time_spent_displaying_hurt_colour >= 1.0 || game.frame_skip > 0)
if (thing->time_spent_displaying_hurt_colour >= 1.0 || game.fastforward_speed > 0)
{
thing->time_spent_displaying_hurt_colour = 0;
thing->rendering_flags &= ~TRF_BeingHit; // Turns off red damage colour tint
Expand Down Expand Up @@ -7997,7 +7997,7 @@ static void draw_jonty_mapwho(struct BucketKindJontySprite *jspr)
lbDisplay.DrawFlags |= Lb_TEXT_UNDERLNSHADOW;
lbSpriteReMapPtr = red_pal;
thing->time_spent_displaying_hurt_colour += game.delta_time;
if (thing->time_spent_displaying_hurt_colour >= 1.0 || game.frame_skip > 0)
if (thing->time_spent_displaying_hurt_colour >= 1.0 || game.fastforward_speed > 0)
{
thing->time_spent_displaying_hurt_colour = 0;
thing->rendering_flags &= ~TRF_BeingHit; // Turns off red damage colour tint
Expand Down
2 changes: 1 addition & 1 deletion src/front_fmvids.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void demo(void)
{
strcpy(game.packet_fname, fname);
game.packet_load_enable = 1;
game.turns_fastforward = 0;
game.turns_to_skip = 0;
frontend_set_state(FeSt_PACKET_DEMO);
}
break;
Expand Down
81 changes: 42 additions & 39 deletions src/front_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,48 +330,48 @@ TbBool check_if_mouse_is_over_button(const struct GuiButton *gbtn)
return check_if_pos_is_over_button(gbtn, GetMouseX(), GetMouseY());
}

void clip_frame_skip(void)
void clip_fastforward_speed(void)
{
if (game.frame_skip > 512)
game.frame_skip = 512;
if (game.frame_skip < 0)
game.frame_skip = 0;
if (game.fastforward_speed > 512)
game.fastforward_speed = 512;
if (game.fastforward_speed < 0)
game.fastforward_speed = 0;
}

void increaseFrameskip(void)
{
// Default no longer using frame_skip=1, which will not change the logic frame rate but the makes the game will less smooth. But it can still be passed in through parameters
// Default no longer using fastforward_speed=1, which will not change the logic frame rate but the makes the game will less smooth. But it can still be passed in through parameters
int level = 16;
for (int i=0; i<10; i++) {
if (game.frame_skip < level)
if (game.fastforward_speed < level)
break;
level <<= 1;
}
int adj = level/8;
game.frame_skip += adj;
clip_frame_skip();
game.fastforward_speed += adj;
clip_fastforward_speed();
char speed_txt[256] = "normal";
if (game.frame_skip > 0)
sprintf(speed_txt, "x%ld", game.frame_skip);
show_onscreen_msg(game_num_fps*(game.frame_skip+1), "Fast Forward %s", speed_txt);
if (game.fastforward_speed > 0)
sprintf(speed_txt, "x%ld", game.fastforward_speed);
show_onscreen_msg(game_num_fps*(game.fastforward_speed+1), "Fast Forward %s", speed_txt);
}

void decreaseFrameskip(void)
{
// Defaul no longer using frame_skip=1, which will not change the logic frame rate but the makes the game will less smooth. But it can still be passed in through parameters
// Defaul no longer using fastforward_speed=1, which will not change the logic frame rate but the makes the game will less smooth. But it can still be passed in through parameters
int level = 16;
for (int i=0; i<10; i++) {
if (game.frame_skip <= level)
if (game.fastforward_speed <= level)
break;
level <<= 1;
}
int adj = level/8;
game.frame_skip -= adj;
clip_frame_skip();
game.fastforward_speed -= adj;
clip_fastforward_speed();
char speed_txt[256] = "normal";
if (game.frame_skip > 0)
sprintf(speed_txt, "x%ld", game.frame_skip);
show_onscreen_msg(game_num_fps*(game.frame_skip+1), "Fast Forward %s", speed_txt);
if (game.fastforward_speed > 0)
sprintf(speed_txt, "x%ld", game.fastforward_speed);
show_onscreen_msg(game_num_fps*(game.fastforward_speed+1), "Fast Forward %s", speed_txt);
}

/**
Expand Down Expand Up @@ -1973,14 +1973,14 @@ short get_map_action_inputs(void)

// TODO: Might want to initiate this in main() and pass a reference to it
// rather than using this global variable. But this works.
int global_frameskipTurn = 0;
int global_fastforward_turn = 0;

void get_isometric_or_front_view_mouse_inputs(struct Packet *pckt,int rotate_pressed,TbBool mods_used)
{
// Reserve the scroll wheel for the resurrect and transfer creature specials
if ((menu_is_active(GMnu_RESURRECT_CREATURE) || menu_is_active(GMnu_TRANSFER_CREATURE) || rotate_pressed || mods_used) == 0)
{
// mouse scroll zoom unaffected by frameskip
// mouse scroll zoom unaffected by fast forward
if ((pckt->control_flags & PCtr_MapCoordsValid) != 0)
{
if (wheel_scrolled_up)
Expand All @@ -2004,39 +2004,39 @@ void get_isometric_or_front_view_mouse_inputs(struct Packet *pckt,int rotate_pre
gui_next_battle(0);
}
}
// Only pan the camera as often as normal despite frameskip
if (game.frame_skip > 0)
// Only pan the camera as often as normal despite fast forward
if (game.fastforward_speed > 0)
{
int frameskipMax = 1;
if (game.frame_skip < 4)
int fastforward_max = 1;
if (game.fastforward_speed < 4)
{
frameskipMax = game.frame_skip;
fastforward_max = game.fastforward_speed;
}
else if (game.frame_skip == 4)
else if (game.fastforward_speed == 4)
{
frameskipMax = 3;
fastforward_max = 3;
}
else if (game.frame_skip > 20 && game.frame_skip < 50)
else if (game.fastforward_speed > 20 && game.fastforward_speed < 50)
{
frameskipMax = (game.frame_skip) / ( log(game.frame_skip) / log(17) );
fastforward_max = (game.fastforward_speed) / ( log(game.fastforward_speed) / log(17) );
}
else if (game.frame_skip < 200)
else if (game.fastforward_speed < 200)
{
frameskipMax = game.frame_skip / ( log(game.frame_skip) / log(10) );
fastforward_max = game.fastforward_speed / ( log(game.fastforward_speed) / log(10) );
}
else if (game.frame_skip == 512) // max frameskip
else if (game.fastforward_speed == 512) // max fast forward
{
frameskipMax = 60;
fastforward_max = 60;
}
else // more than 200 but less than 512
{
frameskipMax = game.frame_skip / ( log(game.frame_skip) / log(4) );
fastforward_max = game.fastforward_speed / ( log(game.fastforward_speed) / log(4) );
}
TbBool moveTheCamera = (global_frameskipTurn == 0);
//Checking for evenly distributed camera movement for the various frameskip amounts
TbBool moveTheCamera = (global_fastforward_turn == 0);
//Checking for evenly distributed camera movement for the various fast forward amounts
//JUSTMSG("moveTheCamera: %d", moveTheCamera);
global_frameskipTurn++;
if (global_frameskipTurn > frameskipMax) global_frameskipTurn = 0;
global_fastforward_turn++;
if (global_fastforward_turn > fastforward_max) global_fastforward_turn = 0;
if (!moveTheCamera) return;
}
// Camera Panning : mouse at window edge scrolling feature
Expand Down Expand Up @@ -2655,6 +2655,9 @@ TbBool active_menu_functions_while_paused()
*/
short get_inputs(void)
{
if (game.turns_to_skip > 0) {
game.turns_to_skip--;
}
if ((game.mode_flags & MFlg_IsDemoMode) != 0)
{
SYNCDBG(5,"Starting for demo mode");
Expand Down
4 changes: 2 additions & 2 deletions src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3176,7 +3176,7 @@ char update_menu_fade_level(struct GuiMenu *gmnu)
gmnu->visual_state = 2;
return 0;
}
if (game.frame_skip == 0)
if (game.fastforward_speed == 0)
{
gmnu->fade_time -= game.delta_time;
} else {
Expand All @@ -3189,7 +3189,7 @@ char update_menu_fade_level(struct GuiMenu *gmnu)
gmnu->fade_time = 0.0;
return -1; // Kill menu
}
if (game.frame_skip == 0)
if (game.fastforward_speed == 0)
{
gmnu->fade_time -= game.delta_time;
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/ftests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is proof of concept; the goal is primarily for setting up scenarios to repl

Added benefit is that if tests are setup in a continuous integration environment we can automatically know when we break behaviours when adding new features.

The functional tests should run fast, hence you will see `frame_skip = 8` is used by default for some tests. It can be specified per-test.
The functional tests should run fast, hence you will see `fastforward_speed = 8` is used by default for some tests. It can be specified per-test.
They also skip the trademark/cutscene by default for super fast launch.

# Quickstart
Expand Down Expand Up @@ -74,8 +74,8 @@ They also skip the trademark/cutscene by default for super fast launch.
- add the include for your tests header file
- example: `#include "tests/ftest_bug_warlock_cooks_chicken.h"`
- update [tests_list](./ftest_list.c#L30)
- add the `test_name` of your test, your tests `init_func`, the `level_file` and specify the `frame_skip` *(there are other advanced optional values not listed here)*
- example: `{ .test_name="bug_warlock_cooks_chicken", .init_func=ftest_bug_warlock_cooks_chicken_init, .level_file="keeporig", .level=1, .frame_skip=0 },`
- add the `test_name` of your test, your tests `init_func`, the `level_file` and specify the `fastforward_speed` *(there are other advanced optional values not listed here)*
- example: `{ .test_name="bug_warlock_cooks_chicken", .init_func=ftest_bug_warlock_cooks_chicken_init, .level_file="keeporig", .level=1, .fastforward_speed=0 },`
- this `test_name` is what you pass to the `ftests` arg in [launch.json](../../.vscode/launch.json) if you only want to run that test
6. [Run Your Test](#run-existing-test)

Expand Down
2 changes: 1 addition & 1 deletion src/ftests/ftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ TbBool ftest_setup_test(struct FTestConfig* const test_config)
}

// set frame skip
game.frame_skip = test_config->frame_skip;
game.fastforward_speed = test_config->fastforward_speed;

// set seed
start_params.functest_seed = test_config->seed;
Expand Down
6 changes: 3 additions & 3 deletions src/ftests/ftest.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ struct FTestConfig {
LevelNumber level;

/**
* @brief Override frameskip for your test (optional)
*
* @brief Override fast forward speed for your test (optional)
*
*/
int frame_skip;
int fastforward_speed;

/**
* @brief Override seed for your test (optional)
Expand Down
22 changes: 11 additions & 11 deletions src/ftests/ftest_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ struct ftest_onlyappendtests__config ftest_onlyappendtests__conf = {

// place regular tests in this list
.tests_list = {
{ .test_name="example_template_test", .init_func=ftest_template_init, .level_file="keeporig", .level=8, .frame_skip=8 },
{ .test_name="bug_imp_tp_attack_door__claim", .init_func=ftest_bug_imp_tp_attack_door__claim_init, .level_file="deepdngn", .level=80, .frame_skip=8 },
{ .test_name="bug_imp_tp_attack_door__prisoner", .init_func=ftest_bug_imp_tp_attack_door__prisoner_init, .level_file="deepdngn", .level=80, .frame_skip=8 },
{ .test_name="bug_imp_tp_attack_door__deadbody", .init_func=ftest_bug_imp_tp_attack_door__deadbody_init, .level_file="deepdngn", .level=80, .frame_skip=8 },
{ .test_name="bug_imp_goldseam_dig", .init_func=ftest_bug_imp_goldseam_dig_init, .level_file="keeporig", .level=1, .frame_skip=8 },
{ .test_name="bug_pathing_stair_treasury", .init_func=ftest_bug_pathing_stair_treasury_init, .level_file="keeporig", .level=1, .frame_skip=8 },
{ .test_name="bug_invisible_units_cant_select", .init_func=ftest_bug_invisible_units_cant_select_init, .level_file="keeporig", .level=1, .frame_skip=0 },

// WIP TEST { .test_name="bug_pathing_pillar_circling", .init_func=ftest_bug_pathing_pillar_circling_init, .level_file="keeporig", .level=1, .frame_skip=0 },
// WIP TEST { .test_name="bug_invisible_units_cant_select", .init_func=ftest_bug_invisible_units_cant_select_init, .level_file="lostlvls", .level=103, .frame_skip=0 },
{ .test_name="example_template_test", .init_func=ftest_template_init, .level_file="keeporig", .level=8, .fastforward_speed=8 },
{ .test_name="bug_imp_tp_attack_door__claim", .init_func=ftest_bug_imp_tp_attack_door__claim_init, .level_file="deepdngn", .level=80, .fastforward_speed=8 },
{ .test_name="bug_imp_tp_attack_door__prisoner", .init_func=ftest_bug_imp_tp_attack_door__prisoner_init, .level_file="deepdngn", .level=80, .fastforward_speed=8 },
{ .test_name="bug_imp_tp_attack_door__deadbody", .init_func=ftest_bug_imp_tp_attack_door__deadbody_init, .level_file="deepdngn", .level=80, .fastforward_speed=8 },
{ .test_name="bug_imp_goldseam_dig", .init_func=ftest_bug_imp_goldseam_dig_init, .level_file="keeporig", .level=1, .fastforward_speed=8 },
{ .test_name="bug_pathing_stair_treasury", .init_func=ftest_bug_pathing_stair_treasury_init, .level_file="keeporig", .level=1, .fastforward_speed=8 },
{ .test_name="bug_invisible_units_cant_select", .init_func=ftest_bug_invisible_units_cant_select_init, .level_file="keeporig", .level=1, .fastforward_speed=0 },

// WIP TEST { .test_name="bug_pathing_pillar_circling", .init_func=ftest_bug_pathing_pillar_circling_init, .level_file="keeporig", .level=1, .fastforward_speed=0 },
// WIP TEST { .test_name="bug_invisible_units_cant_select", .init_func=ftest_bug_invisible_units_cant_select_init, .level_file="lostlvls", .level=103, .fastforward_speed=0 },
// append your test to tests_list here, eg: { .test_name="your_test_name", .init_func=ftest_your_test_name_init, .level_file="lostlvls", .level=103 },
},

// place long-running tests in this list, to include them use the -includelongtests flag
.long_running_tests_list = {
{ .test_name="bug_ai_bridge", .init_func=ftest_bug_ai_bridge_init, .level_file="keeporig", .level=15, .frame_skip=128, .seed=1, .repeat_n_times=100 },
{ .test_name="bug_ai_bridge", .init_func=ftest_bug_ai_bridge_init, .level_file="keeporig", .level=15, .fastforward_speed=128, .seed=1, .repeat_n_times=100 },
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/ftests/tests/ftest_bug_ai_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ FTestActionResult ftest_bug_ai_bridge_action002__end_test(struct FTestActionArgs
++vars->test_runs_with_bridges;
FTESTLOG("Bridges were found at GameTurn %d, reporting and exiting test", game.play_gameturn);
vars->take_screenshot = true;
game.frame_skip = 0;
game.fastforward_speed = 0;
ftest_bug_ai_bridge__report_stats_and_increment_seed();
return FTRs_Go_To_Next_Action; // exit test
}
Expand Down
4 changes: 2 additions & 2 deletions src/game_legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ struct Game {
unsigned int packet_file_pos;
struct PacketSaveHead packet_save_head;
unsigned long turns_stored;
unsigned long turns_fastforward;
unsigned long turns_to_skip;
unsigned char packet_loading_in_progress;
unsigned char packet_checksum_verify;
unsigned long log_things_start_turn;
Expand Down Expand Up @@ -262,7 +262,7 @@ struct Game {
struct PerExpLevelValues creature_scores[CREATURE_TYPES_MAX];
struct Bookmark bookmark[BOOKMARKS_COUNT];
struct CreaturePool pool;
long frame_skip;
long fastforward_speed;
TbBool frame_step;
TbBool paused_at_gameturn;
GameTurnDelta pay_day_progress;
Expand Down
6 changes: 5 additions & 1 deletion src/keeperfx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,16 @@ struct StartupParameters {
TbBool packet_load_enable;
char packet_fname[150];
unsigned char packet_checksum_verify;
int frame_skip;
int fastforward_speed;
char selected_campaign[CMDLN_MAXLEN+1];
TbBool overrides[CMDLINE_OVERRIDES];
char config_file[CMDLN_MAXLEN+1];
GameTurn pause_at_gameturn;
unsigned char startup_flags;
GameTurn skip_to_turn;
unsigned long override_seed;
TbBool log_seed;
TbBool use_override_seed;
#ifdef FUNCTESTING
unsigned char functest_flags;
char functest_name[FTEST_MAX_NAME_LENGTH];
Expand Down
Loading
Loading