mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Add game speed controls to the embedded game window
This commit is contained in:
parent
abbe792575
commit
7ddce8ab26
10 changed files with 173 additions and 11 deletions
|
|
@ -38,24 +38,40 @@
|
|||
#include "core/version.h"
|
||||
#include "servers/rendering/rendering_device.h"
|
||||
|
||||
void Engine::_update_time_scale() {
|
||||
_time_scale = _user_time_scale * _game_time_scale;
|
||||
user_ips = MAX(1, ips * _user_time_scale);
|
||||
max_user_physics_steps_per_frame = MAX(max_physics_steps_per_frame, max_physics_steps_per_frame * _user_time_scale);
|
||||
}
|
||||
|
||||
void Engine::set_physics_ticks_per_second(int p_ips) {
|
||||
ERR_FAIL_COND_MSG(p_ips <= 0, "Engine iterations per second must be greater than 0.");
|
||||
ips = p_ips;
|
||||
_update_time_scale();
|
||||
}
|
||||
|
||||
int Engine::get_physics_ticks_per_second() const {
|
||||
return ips;
|
||||
}
|
||||
|
||||
int Engine::get_user_physics_ticks_per_second() const {
|
||||
return user_ips;
|
||||
}
|
||||
|
||||
void Engine::set_max_physics_steps_per_frame(int p_max_physics_steps) {
|
||||
ERR_FAIL_COND_MSG(p_max_physics_steps <= 0, "Maximum number of physics steps per frame must be greater than 0.");
|
||||
max_physics_steps_per_frame = p_max_physics_steps;
|
||||
_update_time_scale();
|
||||
}
|
||||
|
||||
int Engine::get_max_physics_steps_per_frame() const {
|
||||
return max_physics_steps_per_frame;
|
||||
}
|
||||
|
||||
int Engine::get_user_max_physics_steps_per_frame() const {
|
||||
return max_user_physics_steps_per_frame;
|
||||
}
|
||||
|
||||
void Engine::set_physics_jitter_fix(double p_threshold) {
|
||||
if (p_threshold < 0) {
|
||||
p_threshold = 0;
|
||||
|
|
@ -112,11 +128,21 @@ uint32_t Engine::get_frame_delay() const {
|
|||
}
|
||||
|
||||
void Engine::set_time_scale(double p_scale) {
|
||||
_time_scale = p_scale;
|
||||
_game_time_scale = p_scale;
|
||||
_update_time_scale();
|
||||
}
|
||||
|
||||
double Engine::get_time_scale() const {
|
||||
return freeze_time_scale ? 0 : _time_scale;
|
||||
return freeze_time_scale ? 0.0 : _game_time_scale;
|
||||
}
|
||||
|
||||
void Engine::set_user_time_scale(double p_scale) {
|
||||
_user_time_scale = p_scale;
|
||||
_update_time_scale();
|
||||
}
|
||||
|
||||
double Engine::get_effective_time_scale() const {
|
||||
return freeze_time_scale ? 0.0 : _time_scale;
|
||||
}
|
||||
|
||||
double Engine::get_unfrozen_time_scale() const {
|
||||
|
|
|
|||
|
|
@ -59,13 +59,17 @@ private:
|
|||
double _process_step = 0;
|
||||
|
||||
int ips = 60;
|
||||
int user_ips = 60;
|
||||
double physics_jitter_fix = 0.5;
|
||||
double _fps = 1;
|
||||
int _max_fps = 0;
|
||||
int _audio_output_latency = 0;
|
||||
double _time_scale = 1.0;
|
||||
double _game_time_scale = 1.0;
|
||||
double _user_time_scale = 1.0;
|
||||
uint64_t _physics_frames = 0;
|
||||
int max_physics_steps_per_frame = 8;
|
||||
int max_user_physics_steps_per_frame = 8;
|
||||
double _physics_interpolation_fraction = 0.0f;
|
||||
bool abort_on_gpu_errors = false;
|
||||
bool use_validation_layers = false;
|
||||
|
|
@ -101,14 +105,19 @@ private:
|
|||
|
||||
bool freeze_time_scale = false;
|
||||
|
||||
protected:
|
||||
void _update_time_scale();
|
||||
|
||||
public:
|
||||
static Engine *get_singleton();
|
||||
|
||||
virtual void set_physics_ticks_per_second(int p_ips);
|
||||
virtual int get_physics_ticks_per_second() const;
|
||||
virtual int get_user_physics_ticks_per_second() const;
|
||||
|
||||
virtual void set_max_physics_steps_per_frame(int p_max_physics_steps);
|
||||
virtual int get_max_physics_steps_per_frame() const;
|
||||
virtual int get_user_max_physics_steps_per_frame() const;
|
||||
|
||||
void set_physics_jitter_fix(double p_threshold);
|
||||
double get_physics_jitter_fix() const;
|
||||
|
|
@ -132,6 +141,8 @@ public:
|
|||
|
||||
void set_time_scale(double p_scale);
|
||||
double get_time_scale() const;
|
||||
void set_user_time_scale(double p_scale);
|
||||
double get_effective_time_scale() const;
|
||||
double get_unfrozen_time_scale() const;
|
||||
|
||||
void set_print_to_stdout(bool p_enabled);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue