initial commit, 4.5 stable
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
This commit is contained in:
40
main/SCsub
Normal file
40
main/SCsub
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python
|
||||
from misc.utility.scons_hints import *
|
||||
|
||||
Import("env")
|
||||
|
||||
import main_builders
|
||||
|
||||
env.main_sources = []
|
||||
|
||||
env_main = env.Clone()
|
||||
|
||||
env_main.add_source_files(env.main_sources, "*.cpp")
|
||||
|
||||
if env["steamapi"] and env.editor_build:
|
||||
env_main.Append(CPPDEFINES=["STEAMAPI_ENABLED"])
|
||||
|
||||
if env["tests"]:
|
||||
env_main.Append(CPPDEFINES=["TESTS_ENABLED"])
|
||||
|
||||
env_main.CommandNoCache(
|
||||
"#main/splash.gen.h",
|
||||
"#main/splash.png",
|
||||
env.Run(main_builders.make_splash),
|
||||
)
|
||||
|
||||
if env_main.editor_build and not env_main["no_editor_splash"]:
|
||||
env_main.CommandNoCache(
|
||||
"#main/splash_editor.gen.h",
|
||||
"#main/splash_editor.png",
|
||||
env.Run(main_builders.make_splash_editor),
|
||||
)
|
||||
|
||||
env_main.CommandNoCache(
|
||||
"#main/app_icon.gen.h",
|
||||
"#main/app_icon.png",
|
||||
env.Run(main_builders.make_app_icon),
|
||||
)
|
||||
|
||||
lib = env_main.add_library("main", env.main_sources)
|
||||
env.Prepend(LIBS=[lib])
|
BIN
main/app_icon.png
Normal file
BIN
main/app_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
5127
main/main.cpp
Normal file
5127
main/main.cpp
Normal file
File diff suppressed because it is too large
Load Diff
102
main/main.h
Normal file
102
main/main.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/**************************************************************************/
|
||||
/* main.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/os/thread.h"
|
||||
#include "core/typedefs.h"
|
||||
|
||||
template <typename T>
|
||||
class Vector;
|
||||
|
||||
class Main {
|
||||
enum CLIOptionAvailability {
|
||||
CLI_OPTION_AVAILABILITY_EDITOR,
|
||||
CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG,
|
||||
CLI_OPTION_AVAILABILITY_TEMPLATE_RELEASE,
|
||||
CLI_OPTION_AVAILABILITY_HIDDEN,
|
||||
};
|
||||
|
||||
static void print_header(bool p_rich);
|
||||
static void print_help_copyright(const char *p_notice);
|
||||
static void print_help_title(const char *p_title);
|
||||
static void print_help_option(const char *p_option, const char *p_description, CLIOptionAvailability p_availability = CLI_OPTION_AVAILABILITY_TEMPLATE_RELEASE);
|
||||
static String format_help_option(const char *p_option);
|
||||
static void print_help(const char *p_binary);
|
||||
static uint64_t last_ticks;
|
||||
static uint32_t hide_print_fps_attempts;
|
||||
static uint32_t frames;
|
||||
static uint32_t frame;
|
||||
static bool force_redraw_requested;
|
||||
static int iterating;
|
||||
|
||||
public:
|
||||
static bool is_cmdline_tool();
|
||||
#ifdef TOOLS_ENABLED
|
||||
enum CLIScope {
|
||||
CLI_SCOPE_TOOL, // Editor and project manager.
|
||||
CLI_SCOPE_PROJECT,
|
||||
};
|
||||
static const Vector<String> &get_forwardable_cli_arguments(CLIScope p_scope);
|
||||
#endif
|
||||
|
||||
static int test_entrypoint(int argc, char *argv[], bool &tests_need_run);
|
||||
static Error setup(const char *execpath, int argc, char *argv[], bool p_second_phase = true);
|
||||
static Error setup2(bool p_show_boot_logo = true); // The thread calling setup2() will effectively become the main thread.
|
||||
static String get_rendering_driver_name();
|
||||
static void setup_boot_logo();
|
||||
#ifdef TESTS_ENABLED
|
||||
static Error test_setup();
|
||||
static void test_cleanup();
|
||||
#endif
|
||||
static int start();
|
||||
|
||||
static bool iteration();
|
||||
static void force_redraw();
|
||||
|
||||
static bool is_iterating();
|
||||
|
||||
static void cleanup(bool p_force = false);
|
||||
};
|
||||
|
||||
// Test main override is for the testing behavior.
|
||||
#define TEST_MAIN_OVERRIDE \
|
||||
bool run_test = false; \
|
||||
int return_code = Main::test_entrypoint(argc, argv, run_test); \
|
||||
if (run_test) { \
|
||||
return return_code; \
|
||||
}
|
||||
|
||||
#define TEST_MAIN_PARAM_OVERRIDE(argc, argv) \
|
||||
bool run_test = false; \
|
||||
int return_code = Main::test_entrypoint(argc, argv, run_test); \
|
||||
if (run_test) { \
|
||||
return return_code; \
|
||||
}
|
42
main/main_builders.py
Normal file
42
main/main_builders.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""Functions used to generate source files during build time"""
|
||||
|
||||
import methods
|
||||
|
||||
|
||||
def make_splash(target, source, env):
|
||||
buffer = methods.get_buffer(str(source[0]))
|
||||
|
||||
with methods.generated_wrapper(str(target[0])) as file:
|
||||
# Use a neutral gray color to better fit various kinds of projects.
|
||||
file.write(f"""\
|
||||
static const Color boot_splash_bg_color = Color(0.14, 0.14, 0.14);
|
||||
inline constexpr const unsigned char boot_splash_png[] = {{
|
||||
{methods.format_buffer(buffer, 1)}
|
||||
}};
|
||||
""")
|
||||
|
||||
|
||||
def make_splash_editor(target, source, env):
|
||||
buffer = methods.get_buffer(str(source[0]))
|
||||
|
||||
with methods.generated_wrapper(str(target[0])) as file:
|
||||
# The editor splash background color is taken from the default editor theme's background color.
|
||||
# This helps achieve a visually "smoother" transition between the splash screen and the editor.
|
||||
file.write(f"""\
|
||||
static const Color boot_splash_editor_bg_color = Color(0.125, 0.145, 0.192);
|
||||
inline constexpr const unsigned char boot_splash_editor_png[] = {{
|
||||
{methods.format_buffer(buffer, 1)}
|
||||
}};
|
||||
""")
|
||||
|
||||
|
||||
def make_app_icon(target, source, env):
|
||||
buffer = methods.get_buffer(str(source[0]))
|
||||
|
||||
with methods.generated_wrapper(str(target[0])) as file:
|
||||
# Use a neutral gray color to better fit various kinds of projects.
|
||||
file.write(f"""\
|
||||
inline constexpr const unsigned char app_icon_png[] = {{
|
||||
{methods.format_buffer(buffer, 1)}
|
||||
}};
|
||||
""")
|
525
main/main_timer_sync.cpp
Normal file
525
main/main_timer_sync.cpp
Normal file
@@ -0,0 +1,525 @@
|
||||
/**************************************************************************/
|
||||
/* main_timer_sync.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "main_timer_sync.h"
|
||||
|
||||
#include "core/os/os.h"
|
||||
#include "servers/display_server.h"
|
||||
|
||||
void MainFrameTime::clamp_process_step(double min_process_step, double max_process_step) {
|
||||
if (process_step < min_process_step) {
|
||||
process_step = min_process_step;
|
||||
} else if (process_step > max_process_step) {
|
||||
process_step = max_process_step;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////
|
||||
|
||||
void MainTimerSync::DeltaSmoother::update_refresh_rate_estimator(int64_t p_delta) {
|
||||
// the calling code should prevent 0 or negative values of delta
|
||||
// (preventing divide by zero)
|
||||
|
||||
// note that if the estimate gets locked, and something external changes this
|
||||
// (e.g. user changes to non-vsync in the OS), then the results may be less than ideal,
|
||||
// but usually it will detect this via the FPS measurement and not attempt smoothing.
|
||||
// This should be a rare occurrence anyway, and will be cured next time user restarts game.
|
||||
if (_estimate_locked) {
|
||||
return;
|
||||
}
|
||||
|
||||
// First average the delta over NUM_READINGS
|
||||
_estimator_total_delta += p_delta;
|
||||
_estimator_delta_readings++;
|
||||
|
||||
const int NUM_READINGS = 60;
|
||||
|
||||
if (_estimator_delta_readings < NUM_READINGS) {
|
||||
return;
|
||||
}
|
||||
|
||||
// use average
|
||||
p_delta = _estimator_total_delta / NUM_READINGS;
|
||||
|
||||
// reset the averager for next time
|
||||
_estimator_delta_readings = 0;
|
||||
_estimator_total_delta = 0;
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
int fps = Math::round(1000000.0 / p_delta);
|
||||
|
||||
// initial estimation, to speed up converging, special case we will estimate the refresh rate
|
||||
// from the first average FPS reading
|
||||
if (_estimated_fps == 0) {
|
||||
// below 50 might be chugging loading stuff, or else
|
||||
// dropping loads of frames, so the estimate will be inaccurate
|
||||
if (fps >= 50) {
|
||||
_estimated_fps = fps;
|
||||
#ifdef GODOT_DEBUG_DELTA_SMOOTHER
|
||||
print_line("initial guess (average measured) refresh rate: " + itos(fps));
|
||||
#endif
|
||||
} else {
|
||||
// can't get started until above 50
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// we hit our exact estimated refresh rate.
|
||||
// increase our confidence in the estimate.
|
||||
if (fps == _estimated_fps) {
|
||||
// note that each hit is an average of NUM_READINGS frames
|
||||
_hits_at_estimated++;
|
||||
|
||||
if (_estimate_complete && _hits_at_estimated == 20) {
|
||||
_estimate_locked = true;
|
||||
#ifdef GODOT_DEBUG_DELTA_SMOOTHER
|
||||
print_line("estimate LOCKED at " + itos(_estimated_fps) + " fps");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// if we are getting pretty confident in this estimate, decide it is complete
|
||||
// (it can still be increased later, and possibly lowered but only for a short time)
|
||||
if ((!_estimate_complete) && (_hits_at_estimated > 2)) {
|
||||
// when the estimate is complete we turn on smoothing
|
||||
if (_estimated_fps) {
|
||||
_estimate_complete = true;
|
||||
_vsync_delta = 1000000 / _estimated_fps;
|
||||
|
||||
#ifdef GODOT_DEBUG_DELTA_SMOOTHER
|
||||
print_line("estimate complete. vsync_delta " + itos(_vsync_delta) + ", fps " + itos(_estimated_fps));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef GODOT_DEBUG_DELTA_SMOOTHER
|
||||
if ((_hits_at_estimated % (400 / NUM_READINGS)) == 0) {
|
||||
String sz = "hits at estimated : " + itos(_hits_at_estimated) + ", above : " + itos(_hits_above_estimated) + "( " + itos(_hits_one_above_estimated) + " ), below : " + itos(_hits_below_estimated) + " (" + itos(_hits_one_below_estimated) + " )";
|
||||
|
||||
print_line(sz);
|
||||
}
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const int SIGNIFICANCE_UP = 1;
|
||||
const int SIGNIFICANCE_DOWN = 2;
|
||||
|
||||
// we are not usually interested in slowing the estimate
|
||||
// but we may have overshot, so make it possible to reduce
|
||||
if (fps < _estimated_fps) {
|
||||
// micro changes
|
||||
if (fps == (_estimated_fps - 1)) {
|
||||
_hits_one_below_estimated++;
|
||||
|
||||
if ((_hits_one_below_estimated > _hits_at_estimated) && (_hits_one_below_estimated > SIGNIFICANCE_DOWN)) {
|
||||
_estimated_fps--;
|
||||
made_new_estimate();
|
||||
}
|
||||
|
||||
return;
|
||||
} else {
|
||||
_hits_below_estimated++;
|
||||
|
||||
// don't allow large lowering if we are established at a refresh rate, as it will probably be dropped frames
|
||||
bool established = _estimate_complete && (_hits_at_estimated > 10);
|
||||
|
||||
// macro changes
|
||||
// note there is a large barrier to macro lowering. That is because it is more likely to be dropped frames
|
||||
// than mis-estimation of the refresh rate.
|
||||
if (!established) {
|
||||
if (((_hits_below_estimated / 8) > _hits_at_estimated) && (_hits_below_estimated > SIGNIFICANCE_DOWN)) {
|
||||
// decrease the estimate
|
||||
_estimated_fps--;
|
||||
made_new_estimate();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Changes increasing the estimate.
|
||||
// micro changes
|
||||
if (fps == (_estimated_fps + 1)) {
|
||||
_hits_one_above_estimated++;
|
||||
|
||||
if ((_hits_one_above_estimated > _hits_at_estimated) && (_hits_one_above_estimated > SIGNIFICANCE_UP)) {
|
||||
_estimated_fps++;
|
||||
made_new_estimate();
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
_hits_above_estimated++;
|
||||
|
||||
// macro changes
|
||||
if ((_hits_above_estimated > _hits_at_estimated) && (_hits_above_estimated > SIGNIFICANCE_UP)) {
|
||||
// increase the estimate
|
||||
int change = fps - _estimated_fps;
|
||||
change /= 2;
|
||||
change = MAX(1, change);
|
||||
|
||||
_estimated_fps += change;
|
||||
made_new_estimate();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool MainTimerSync::DeltaSmoother::fps_allows_smoothing(int64_t p_delta) {
|
||||
_measurement_time += p_delta;
|
||||
_measurement_frame_count++;
|
||||
|
||||
if (_measurement_frame_count == _measurement_end_frame) {
|
||||
// only switch on or off if the estimate is complete
|
||||
if (_estimate_complete) {
|
||||
int64_t time_passed = _measurement_time - _measurement_start_time;
|
||||
|
||||
// average delta
|
||||
time_passed /= MEASURE_FPS_OVER_NUM_FRAMES;
|
||||
|
||||
// estimate fps
|
||||
if (time_passed) {
|
||||
double fps = 1000000.0 / time_passed;
|
||||
double ratio = fps / (double)_estimated_fps;
|
||||
|
||||
//print_line("ratio : " + String(Variant(ratio)));
|
||||
|
||||
if ((ratio > 0.95) && (ratio < 1.05)) {
|
||||
_measurement_allows_smoothing = true;
|
||||
} else {
|
||||
_measurement_allows_smoothing = false;
|
||||
}
|
||||
}
|
||||
} // estimate complete
|
||||
|
||||
// new start time for next iteration
|
||||
_measurement_start_time = _measurement_time;
|
||||
_measurement_end_frame += MEASURE_FPS_OVER_NUM_FRAMES;
|
||||
}
|
||||
|
||||
return _measurement_allows_smoothing;
|
||||
}
|
||||
|
||||
int64_t MainTimerSync::DeltaSmoother::smooth_delta(int64_t p_delta) {
|
||||
// Conditions to disable smoothing.
|
||||
// Note that vsync is a request, it cannot be relied on, the OS may override this.
|
||||
// If the OS turns vsync on without vsync in the app, smoothing will not be enabled.
|
||||
// If the OS turns vsync off with sync enabled in the app, the smoothing must detect this
|
||||
// via the error metric and switch off.
|
||||
// Also only try smoothing if vsync is enabled (classical vsync, not new types) ..
|
||||
// This condition is currently checked before calling smooth_delta().
|
||||
if (!OS::get_singleton()->is_delta_smoothing_enabled() || Engine::get_singleton()->is_editor_hint()) {
|
||||
return p_delta;
|
||||
}
|
||||
|
||||
// only attempt smoothing if vsync is selected
|
||||
DisplayServer::VSyncMode vsync_mode = DisplayServer::get_singleton()->window_get_vsync_mode(DisplayServer::MAIN_WINDOW_ID);
|
||||
if (vsync_mode != DisplayServer::VSYNC_ENABLED) {
|
||||
return p_delta;
|
||||
}
|
||||
|
||||
// Very important, ignore long deltas and pass them back unmodified.
|
||||
// This is to deal with resuming after suspend for long periods.
|
||||
if (p_delta > 1000000) {
|
||||
return p_delta;
|
||||
}
|
||||
|
||||
// keep a running guesstimate of the FPS, and turn off smoothing if
|
||||
// conditions not close to the estimated FPS
|
||||
if (!fps_allows_smoothing(p_delta)) {
|
||||
return p_delta;
|
||||
}
|
||||
|
||||
// we can't cope with negative deltas .. OS bug on some hardware
|
||||
// and also very small deltas caused by vsync being off.
|
||||
// This could possibly be part of a hiccup, this value isn't fixed in stone...
|
||||
if (p_delta < 1000) {
|
||||
return p_delta;
|
||||
}
|
||||
|
||||
// note still some vsync off will still get through to this point...
|
||||
// and we need to cope with it by not converging the estimator / and / or not smoothing
|
||||
update_refresh_rate_estimator(p_delta);
|
||||
|
||||
// no smoothing until we know what the refresh rate is
|
||||
if (!_estimate_complete) {
|
||||
return p_delta;
|
||||
}
|
||||
|
||||
// accumulate the time we have available to use
|
||||
_leftover_time += p_delta;
|
||||
|
||||
// how many vsyncs units can we fit?
|
||||
int64_t units = _leftover_time / _vsync_delta;
|
||||
|
||||
// a delta must include minimum 1 vsync
|
||||
// (if it is less than that, it is either random error or we are no longer running at the vsync rate,
|
||||
// in which case we should switch off delta smoothing, or re-estimate the refresh rate)
|
||||
units = MAX(units, 1);
|
||||
|
||||
_leftover_time -= units * _vsync_delta;
|
||||
// print_line("units " + itos(units) + ", leftover " + itos(_leftover_time/1000) + " ms");
|
||||
|
||||
return units * _vsync_delta;
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
// returns the fraction of p_physics_step required for the timer to overshoot
|
||||
// before advance_core considers changing the physics_steps return from
|
||||
// the typical values as defined by typical_physics_steps
|
||||
double MainTimerSync::get_physics_jitter_fix() {
|
||||
return Engine::get_singleton()->get_physics_jitter_fix();
|
||||
}
|
||||
|
||||
// gets our best bet for the average number of physics steps per render frame
|
||||
// return value: number of frames back this data is consistent
|
||||
int MainTimerSync::get_average_physics_steps(double &p_min, double &p_max) {
|
||||
p_min = typical_physics_steps[0];
|
||||
p_max = p_min + 1;
|
||||
|
||||
for (int i = 1; i < CONTROL_STEPS; ++i) {
|
||||
const double typical_lower = typical_physics_steps[i];
|
||||
const double current_min = typical_lower / (i + 1);
|
||||
if (current_min > p_max) {
|
||||
return i; // bail out if further restrictions would void the interval
|
||||
} else if (current_min > p_min) {
|
||||
p_min = current_min;
|
||||
}
|
||||
const double current_max = (typical_lower + 1) / (i + 1);
|
||||
if (current_max < p_min) {
|
||||
return i;
|
||||
} else if (current_max < p_max) {
|
||||
p_max = current_max;
|
||||
}
|
||||
}
|
||||
|
||||
return CONTROL_STEPS;
|
||||
}
|
||||
|
||||
// advance physics clock by p_process_step, return appropriate number of steps to simulate
|
||||
MainFrameTime MainTimerSync::advance_core(double p_physics_step, int p_physics_ticks_per_second, double p_process_step) {
|
||||
MainFrameTime ret;
|
||||
|
||||
ret.process_step = p_process_step;
|
||||
|
||||
// simple determination of number of physics iteration
|
||||
time_accum += ret.process_step;
|
||||
ret.physics_steps = std::floor(time_accum * p_physics_ticks_per_second);
|
||||
|
||||
int min_typical_steps = typical_physics_steps[0];
|
||||
int max_typical_steps = min_typical_steps + 1;
|
||||
|
||||
// given the past recorded steps and typical steps to match, calculate bounds for this
|
||||
// step to be typical
|
||||
bool update_typical = false;
|
||||
|
||||
for (int i = 0; i < CONTROL_STEPS - 1; ++i) {
|
||||
int steps_left_to_match_typical = typical_physics_steps[i + 1] - accumulated_physics_steps[i];
|
||||
if (steps_left_to_match_typical > max_typical_steps ||
|
||||
steps_left_to_match_typical + 1 < min_typical_steps) {
|
||||
update_typical = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (steps_left_to_match_typical > min_typical_steps) {
|
||||
min_typical_steps = steps_left_to_match_typical;
|
||||
}
|
||||
if (steps_left_to_match_typical + 1 < max_typical_steps) {
|
||||
max_typical_steps = steps_left_to_match_typical + 1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (max_typical_steps < 0) {
|
||||
WARN_PRINT_ONCE("`max_typical_steps` is negative. This could hint at an engine bug or system timer misconfiguration.");
|
||||
}
|
||||
#endif
|
||||
|
||||
// try to keep it consistent with previous iterations
|
||||
if (ret.physics_steps < min_typical_steps) {
|
||||
const int max_possible_steps = std::floor((time_accum)*p_physics_ticks_per_second + get_physics_jitter_fix());
|
||||
if (max_possible_steps < min_typical_steps) {
|
||||
ret.physics_steps = max_possible_steps;
|
||||
update_typical = true;
|
||||
} else {
|
||||
ret.physics_steps = min_typical_steps;
|
||||
}
|
||||
} else if (ret.physics_steps > max_typical_steps) {
|
||||
const int min_possible_steps = std::floor((time_accum)*p_physics_ticks_per_second - get_physics_jitter_fix());
|
||||
if (min_possible_steps > max_typical_steps) {
|
||||
ret.physics_steps = min_possible_steps;
|
||||
update_typical = true;
|
||||
} else {
|
||||
ret.physics_steps = max_typical_steps;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret.physics_steps < 0) {
|
||||
ret.physics_steps = 0;
|
||||
}
|
||||
|
||||
time_accum -= ret.physics_steps * p_physics_step;
|
||||
|
||||
// keep track of accumulated step counts
|
||||
for (int i = CONTROL_STEPS - 2; i >= 0; --i) {
|
||||
accumulated_physics_steps[i + 1] = accumulated_physics_steps[i] + ret.physics_steps;
|
||||
}
|
||||
accumulated_physics_steps[0] = ret.physics_steps;
|
||||
|
||||
if (update_typical) {
|
||||
for (int i = CONTROL_STEPS - 1; i >= 0; --i) {
|
||||
if (typical_physics_steps[i] > accumulated_physics_steps[i]) {
|
||||
typical_physics_steps[i] = accumulated_physics_steps[i];
|
||||
} else if (typical_physics_steps[i] < accumulated_physics_steps[i] - 1) {
|
||||
typical_physics_steps[i] = accumulated_physics_steps[i] - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// calls advance_core, keeps track of deficit it adds to animaption_step, make sure the deficit sum stays close to zero
|
||||
MainFrameTime MainTimerSync::advance_checked(double p_physics_step, int p_physics_ticks_per_second, double p_process_step) {
|
||||
if (fixed_fps != -1) {
|
||||
p_process_step = 1.0 / fixed_fps;
|
||||
}
|
||||
|
||||
float min_output_step = p_process_step / 8;
|
||||
min_output_step = MAX(min_output_step, 1E-6);
|
||||
|
||||
// compensate for last deficit
|
||||
p_process_step += time_deficit;
|
||||
|
||||
MainFrameTime ret = advance_core(p_physics_step, p_physics_ticks_per_second, p_process_step);
|
||||
|
||||
// we will do some clamping on ret.process_step and need to sync those changes to time_accum,
|
||||
// that's easiest if we just remember their fixed difference now
|
||||
const double process_minus_accum = ret.process_step - time_accum;
|
||||
|
||||
// first, least important clamping: keep ret.process_step consistent with typical_physics_steps.
|
||||
// this smoothes out the process steps and culls small but quick variations.
|
||||
{
|
||||
double min_average_physics_steps, max_average_physics_steps;
|
||||
int consistent_steps = get_average_physics_steps(min_average_physics_steps, max_average_physics_steps);
|
||||
if (consistent_steps > 3) {
|
||||
ret.clamp_process_step(min_average_physics_steps * p_physics_step, max_average_physics_steps * p_physics_step);
|
||||
}
|
||||
}
|
||||
|
||||
// second clamping: keep abs(time_deficit) < jitter_fix * frame_slise
|
||||
double max_clock_deviation = get_physics_jitter_fix() * p_physics_step;
|
||||
ret.clamp_process_step(p_process_step - max_clock_deviation, p_process_step + max_clock_deviation);
|
||||
|
||||
// last clamping: make sure time_accum is between 0 and p_physics_step for consistency between physics and process
|
||||
ret.clamp_process_step(process_minus_accum, process_minus_accum + p_physics_step);
|
||||
|
||||
// all the operations above may have turned ret.p_process_step negative or zero, keep a minimal value
|
||||
if (ret.process_step < min_output_step) {
|
||||
ret.process_step = min_output_step;
|
||||
}
|
||||
|
||||
// restore time_accum
|
||||
time_accum = ret.process_step - process_minus_accum;
|
||||
|
||||
// forcing ret.process_step to be positive may trigger a violation of the
|
||||
// promise that time_accum is between 0 and p_physics_step
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (time_accum < -1E-7) {
|
||||
WARN_PRINT_ONCE("Intermediate value of `time_accum` is negative. This could hint at an engine bug or system timer misconfiguration.");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (time_accum > p_physics_step) {
|
||||
const int extra_physics_steps = std::floor(time_accum * p_physics_ticks_per_second);
|
||||
time_accum -= extra_physics_steps * p_physics_step;
|
||||
ret.physics_steps += extra_physics_steps;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (time_accum < -1E-7) {
|
||||
WARN_PRINT_ONCE("Final value of `time_accum` is negative. It should always be between 0 and `p_physics_step`. This hints at an engine bug.");
|
||||
}
|
||||
if (time_accum > p_physics_step + 1E-7) {
|
||||
WARN_PRINT_ONCE("Final value of `time_accum` is larger than `p_physics_step`. It should always be between 0 and `p_physics_step`. This hints at an engine bug.");
|
||||
}
|
||||
#endif
|
||||
|
||||
// track deficit
|
||||
time_deficit = p_process_step - ret.process_step;
|
||||
|
||||
// p_physics_step is 1.0 / iterations_per_sec
|
||||
// i.e. the time in seconds taken by a physics tick
|
||||
ret.interpolation_fraction = time_accum / p_physics_step;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// determine wall clock step since last iteration
|
||||
double MainTimerSync::get_cpu_process_step() {
|
||||
uint64_t cpu_ticks_elapsed = current_cpu_ticks_usec - last_cpu_ticks_usec;
|
||||
last_cpu_ticks_usec = current_cpu_ticks_usec;
|
||||
|
||||
cpu_ticks_elapsed = _delta_smoother.smooth_delta(cpu_ticks_elapsed);
|
||||
|
||||
return cpu_ticks_elapsed / 1000000.0;
|
||||
}
|
||||
|
||||
MainTimerSync::MainTimerSync() {
|
||||
for (int i = CONTROL_STEPS - 1; i >= 0; --i) {
|
||||
typical_physics_steps[i] = i;
|
||||
accumulated_physics_steps[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
// start the clock
|
||||
void MainTimerSync::init(uint64_t p_cpu_ticks_usec) {
|
||||
current_cpu_ticks_usec = last_cpu_ticks_usec = p_cpu_ticks_usec;
|
||||
}
|
||||
|
||||
// set measured wall clock time
|
||||
void MainTimerSync::set_cpu_ticks_usec(uint64_t p_cpu_ticks_usec) {
|
||||
current_cpu_ticks_usec = p_cpu_ticks_usec;
|
||||
}
|
||||
|
||||
void MainTimerSync::set_fixed_fps(int p_fixed_fps) {
|
||||
fixed_fps = p_fixed_fps;
|
||||
}
|
||||
|
||||
// advance one physics frame, return timesteps to take
|
||||
MainFrameTime MainTimerSync::advance(double p_physics_step, int p_physics_ticks_per_second) {
|
||||
double cpu_process_step = get_cpu_process_step();
|
||||
|
||||
return advance_checked(p_physics_step, p_physics_ticks_per_second, cpu_process_step);
|
||||
}
|
162
main/main_timer_sync.h
Normal file
162
main/main_timer_sync.h
Normal file
@@ -0,0 +1,162 @@
|
||||
/**************************************************************************/
|
||||
/* main_timer_sync.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/config/engine.h"
|
||||
|
||||
// Uncomment this define to get more debugging logs for the delta smoothing.
|
||||
// #define GODOT_DEBUG_DELTA_SMOOTHER
|
||||
|
||||
struct MainFrameTime {
|
||||
double process_step; // delta time to advance during process()
|
||||
int physics_steps; // number of times to iterate the physics engine
|
||||
double interpolation_fraction; // fraction through the current physics tick
|
||||
|
||||
void clamp_process_step(double min_process_step, double max_process_step);
|
||||
};
|
||||
|
||||
class MainTimerSync {
|
||||
class DeltaSmoother {
|
||||
public:
|
||||
// pass the recorded delta, returns a smoothed delta
|
||||
int64_t smooth_delta(int64_t p_delta);
|
||||
|
||||
private:
|
||||
void update_refresh_rate_estimator(int64_t p_delta);
|
||||
bool fps_allows_smoothing(int64_t p_delta);
|
||||
|
||||
// estimated vsync delta (monitor refresh rate)
|
||||
int64_t _vsync_delta = 16666;
|
||||
|
||||
// keep track of accumulated time so we know how many vsyncs to advance by
|
||||
int64_t _leftover_time = 0;
|
||||
|
||||
// keep a rough measurement of the FPS as we run.
|
||||
// If this drifts a long way below or above the refresh rate, the machine
|
||||
// is struggling to keep up, and we can switch off smoothing. This
|
||||
// also deals with the case that the user has overridden the vsync in the GPU settings,
|
||||
// in which case we don't want to try smoothing.
|
||||
static const int MEASURE_FPS_OVER_NUM_FRAMES = 64;
|
||||
|
||||
int64_t _measurement_time = 0;
|
||||
int64_t _measurement_frame_count = 0;
|
||||
int64_t _measurement_end_frame = MEASURE_FPS_OVER_NUM_FRAMES;
|
||||
int64_t _measurement_start_time = 0;
|
||||
bool _measurement_allows_smoothing = true;
|
||||
|
||||
// we can estimate the fps by growing it on condition
|
||||
// that a large proportion of frames are higher than the current estimate.
|
||||
int32_t _estimated_fps = 0;
|
||||
int32_t _hits_at_estimated = 0;
|
||||
int32_t _hits_above_estimated = 0;
|
||||
int32_t _hits_below_estimated = 0;
|
||||
int32_t _hits_one_above_estimated = 0;
|
||||
int32_t _hits_one_below_estimated = 0;
|
||||
bool _estimate_complete = false;
|
||||
bool _estimate_locked = false;
|
||||
|
||||
// data for averaging the delta over a second or so
|
||||
// to prevent spurious values
|
||||
int64_t _estimator_total_delta = 0;
|
||||
int32_t _estimator_delta_readings = 0;
|
||||
|
||||
void made_new_estimate() {
|
||||
_hits_above_estimated = 0;
|
||||
_hits_at_estimated = 0;
|
||||
_hits_below_estimated = 0;
|
||||
_hits_one_above_estimated = 0;
|
||||
_hits_one_below_estimated = 0;
|
||||
|
||||
_estimate_complete = false;
|
||||
|
||||
#ifdef GODOT_DEBUG_DELTA_SMOOTHER
|
||||
print_line("estimated fps " + itos(_estimated_fps));
|
||||
#endif
|
||||
}
|
||||
|
||||
} _delta_smoother;
|
||||
|
||||
// wall clock time measured on the main thread
|
||||
uint64_t last_cpu_ticks_usec = 0;
|
||||
uint64_t current_cpu_ticks_usec = 0;
|
||||
|
||||
// logical game time since last physics timestep
|
||||
double time_accum = 0;
|
||||
|
||||
// current difference between wall clock time and reported sum of process_steps
|
||||
double time_deficit = 0;
|
||||
|
||||
// number of frames back for keeping accumulated physics steps roughly constant.
|
||||
// value of 12 chosen because that is what is required to make 144 Hz monitors
|
||||
// behave well with 60 Hz physics updates. The only worse commonly available refresh
|
||||
// would be 85, requiring CONTROL_STEPS = 17.
|
||||
static const int CONTROL_STEPS = 12;
|
||||
|
||||
// sum of physics steps done over the last (i+1) frames
|
||||
int accumulated_physics_steps[CONTROL_STEPS];
|
||||
|
||||
// typical value for accumulated_physics_steps[i] is either this or this plus one
|
||||
int typical_physics_steps[CONTROL_STEPS];
|
||||
|
||||
int fixed_fps = 0;
|
||||
|
||||
protected:
|
||||
// returns the fraction of p_physics_step required for the timer to overshoot
|
||||
// before advance_core considers changing the physics_steps return from
|
||||
// the typical values as defined by typical_physics_steps
|
||||
double get_physics_jitter_fix();
|
||||
|
||||
// gets our best bet for the average number of physics steps per render frame
|
||||
// return value: number of frames back this data is consistent
|
||||
int get_average_physics_steps(double &p_min, double &p_max);
|
||||
|
||||
// advance physics clock by p_process_step, return appropriate number of steps to simulate
|
||||
MainFrameTime advance_core(double p_physics_step, int p_physics_ticks_per_second, double p_process_step);
|
||||
|
||||
// calls advance_core, keeps track of deficit it adds to animaption_step, make sure the deficit sum stays close to zero
|
||||
MainFrameTime advance_checked(double p_physics_step, int p_physics_ticks_per_second, double p_process_step);
|
||||
|
||||
// determine wall clock step since last iteration
|
||||
double get_cpu_process_step();
|
||||
|
||||
public:
|
||||
MainTimerSync();
|
||||
|
||||
// start the clock
|
||||
void init(uint64_t p_cpu_ticks_usec);
|
||||
// set measured wall clock time
|
||||
void set_cpu_ticks_usec(uint64_t p_cpu_ticks_usec);
|
||||
//set fixed fps
|
||||
void set_fixed_fps(int p_fixed_fps);
|
||||
|
||||
// advance one frame, return timesteps to take
|
||||
MainFrameTime advance(double p_physics_step, int p_physics_ticks_per_second);
|
||||
};
|
600
main/performance.cpp
Normal file
600
main/performance.cpp
Normal file
@@ -0,0 +1,600 @@
|
||||
/**************************************************************************/
|
||||
/* performance.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "performance.h"
|
||||
|
||||
#include "core/os/os.h"
|
||||
#include "core/variant/typed_array.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/main/scene_tree.h"
|
||||
#include "servers/audio_server.h"
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
#include "servers/navigation_server_2d.h"
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
#ifndef NAVIGATION_3D_DISABLED
|
||||
#include "servers/navigation_server_3d.h"
|
||||
#endif // NAVIGATION_3D_DISABLED
|
||||
#include "servers/rendering_server.h"
|
||||
|
||||
#ifndef PHYSICS_2D_DISABLED
|
||||
#include "servers/physics_server_2d.h"
|
||||
#endif // PHYSICS_2D_DISABLED
|
||||
|
||||
#ifndef PHYSICS_3D_DISABLED
|
||||
#include "servers/physics_server_3d.h"
|
||||
#endif // PHYSICS_3D_DISABLED
|
||||
|
||||
Performance *Performance::singleton = nullptr;
|
||||
|
||||
void Performance::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_monitor", "monitor"), &Performance::get_monitor);
|
||||
ClassDB::bind_method(D_METHOD("add_custom_monitor", "id", "callable", "arguments"), &Performance::add_custom_monitor, DEFVAL(Array()));
|
||||
ClassDB::bind_method(D_METHOD("remove_custom_monitor", "id"), &Performance::remove_custom_monitor);
|
||||
ClassDB::bind_method(D_METHOD("has_custom_monitor", "id"), &Performance::has_custom_monitor);
|
||||
ClassDB::bind_method(D_METHOD("get_custom_monitor", "id"), &Performance::get_custom_monitor);
|
||||
ClassDB::bind_method(D_METHOD("get_monitor_modification_time"), &Performance::get_monitor_modification_time);
|
||||
ClassDB::bind_method(D_METHOD("get_custom_monitor_names"), &Performance::get_custom_monitor_names);
|
||||
|
||||
BIND_ENUM_CONSTANT(TIME_FPS);
|
||||
BIND_ENUM_CONSTANT(TIME_PROCESS);
|
||||
BIND_ENUM_CONSTANT(TIME_PHYSICS_PROCESS);
|
||||
BIND_ENUM_CONSTANT(TIME_NAVIGATION_PROCESS);
|
||||
BIND_ENUM_CONSTANT(MEMORY_STATIC);
|
||||
BIND_ENUM_CONSTANT(MEMORY_STATIC_MAX);
|
||||
BIND_ENUM_CONSTANT(MEMORY_MESSAGE_BUFFER_MAX);
|
||||
BIND_ENUM_CONSTANT(OBJECT_COUNT);
|
||||
BIND_ENUM_CONSTANT(OBJECT_RESOURCE_COUNT);
|
||||
BIND_ENUM_CONSTANT(OBJECT_NODE_COUNT);
|
||||
BIND_ENUM_CONSTANT(OBJECT_ORPHAN_NODE_COUNT);
|
||||
BIND_ENUM_CONSTANT(RENDER_TOTAL_OBJECTS_IN_FRAME);
|
||||
BIND_ENUM_CONSTANT(RENDER_TOTAL_PRIMITIVES_IN_FRAME);
|
||||
BIND_ENUM_CONSTANT(RENDER_TOTAL_DRAW_CALLS_IN_FRAME);
|
||||
BIND_ENUM_CONSTANT(RENDER_VIDEO_MEM_USED);
|
||||
BIND_ENUM_CONSTANT(RENDER_TEXTURE_MEM_USED);
|
||||
BIND_ENUM_CONSTANT(RENDER_BUFFER_MEM_USED);
|
||||
BIND_ENUM_CONSTANT(PHYSICS_2D_ACTIVE_OBJECTS);
|
||||
BIND_ENUM_CONSTANT(PHYSICS_2D_COLLISION_PAIRS);
|
||||
BIND_ENUM_CONSTANT(PHYSICS_2D_ISLAND_COUNT);
|
||||
#ifndef _3D_DISABLED
|
||||
BIND_ENUM_CONSTANT(PHYSICS_3D_ACTIVE_OBJECTS);
|
||||
BIND_ENUM_CONSTANT(PHYSICS_3D_COLLISION_PAIRS);
|
||||
BIND_ENUM_CONSTANT(PHYSICS_3D_ISLAND_COUNT);
|
||||
#endif // _3D_DISABLED
|
||||
BIND_ENUM_CONSTANT(AUDIO_OUTPUT_LATENCY);
|
||||
#if !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED)
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_ACTIVE_MAPS);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_REGION_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_AGENT_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_LINK_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_POLYGON_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_EDGE_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_EDGE_MERGE_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_EDGE_CONNECTION_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_EDGE_FREE_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_OBSTACLE_COUNT);
|
||||
#endif // !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED)
|
||||
BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_CANVAS);
|
||||
BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_MESH);
|
||||
BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_SURFACE);
|
||||
BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_DRAW);
|
||||
BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_SPECIALIZATION);
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_2D_ACTIVE_MAPS);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_2D_REGION_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_2D_AGENT_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_2D_LINK_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_2D_POLYGON_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_MERGE_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_CONNECTION_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_FREE_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_2D_OBSTACLE_COUNT);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
#ifndef NAVIGATION_3D_DISABLED
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_3D_ACTIVE_MAPS);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_3D_REGION_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_3D_AGENT_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_3D_LINK_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_3D_POLYGON_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_MERGE_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_CONNECTION_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_FREE_COUNT);
|
||||
BIND_ENUM_CONSTANT(NAVIGATION_3D_OBSTACLE_COUNT);
|
||||
#endif // NAVIGATION_3D_DISABLED
|
||||
BIND_ENUM_CONSTANT(MONITOR_MAX);
|
||||
}
|
||||
|
||||
int Performance::_get_node_count() const {
|
||||
MainLoop *ml = OS::get_singleton()->get_main_loop();
|
||||
SceneTree *sml = Object::cast_to<SceneTree>(ml);
|
||||
if (!sml) {
|
||||
return 0;
|
||||
}
|
||||
return sml->get_node_count();
|
||||
}
|
||||
|
||||
String Performance::get_monitor_name(Monitor p_monitor) const {
|
||||
ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, String());
|
||||
static const char *names[MONITOR_MAX] = {
|
||||
PNAME("time/fps"),
|
||||
PNAME("time/process"),
|
||||
PNAME("time/physics_process"),
|
||||
PNAME("time/navigation_process"),
|
||||
PNAME("memory/static"),
|
||||
PNAME("memory/static_max"),
|
||||
PNAME("memory/msg_buf_max"),
|
||||
PNAME("object/objects"),
|
||||
PNAME("object/resources"),
|
||||
PNAME("object/nodes"),
|
||||
PNAME("object/orphan_nodes"),
|
||||
PNAME("raster/total_objects_drawn"),
|
||||
PNAME("raster/total_primitives_drawn"),
|
||||
PNAME("raster/total_draw_calls"),
|
||||
PNAME("video/video_mem"),
|
||||
PNAME("video/texture_mem"),
|
||||
PNAME("video/buffer_mem"),
|
||||
PNAME("physics_2d/active_objects"),
|
||||
PNAME("physics_2d/collision_pairs"),
|
||||
PNAME("physics_2d/islands"),
|
||||
PNAME("physics_3d/active_objects"),
|
||||
PNAME("physics_3d/collision_pairs"),
|
||||
PNAME("physics_3d/islands"),
|
||||
PNAME("audio/driver/output_latency"),
|
||||
#if !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED)
|
||||
PNAME("navigation/active_maps"),
|
||||
PNAME("navigation/regions"),
|
||||
PNAME("navigation/agents"),
|
||||
PNAME("navigation/links"),
|
||||
PNAME("navigation/polygons"),
|
||||
PNAME("navigation/edges"),
|
||||
PNAME("navigation/edges_merged"),
|
||||
PNAME("navigation/edges_connected"),
|
||||
PNAME("navigation/edges_free"),
|
||||
PNAME("navigation/obstacles"),
|
||||
#endif // !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED)
|
||||
PNAME("pipeline/compilations_canvas"),
|
||||
PNAME("pipeline/compilations_mesh"),
|
||||
PNAME("pipeline/compilations_surface"),
|
||||
PNAME("pipeline/compilations_draw"),
|
||||
PNAME("pipeline/compilations_specialization"),
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
PNAME("navigation_2d/active_maps"),
|
||||
PNAME("navigation_2d/regions"),
|
||||
PNAME("navigation_2d/agents"),
|
||||
PNAME("navigation_2d/links"),
|
||||
PNAME("navigation_2d/polygons"),
|
||||
PNAME("navigation_2d/edges"),
|
||||
PNAME("navigation_2d/edges_merged"),
|
||||
PNAME("navigation_2d/edges_connected"),
|
||||
PNAME("navigation_2d/edges_free"),
|
||||
PNAME("navigation_2d/obstacles"),
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
#ifndef NAVIGATION_3D_DISABLED
|
||||
PNAME("navigation_3d/active_maps"),
|
||||
PNAME("navigation_3d/regions"),
|
||||
PNAME("navigation_3d/agents"),
|
||||
PNAME("navigation_3d/links"),
|
||||
PNAME("navigation_3d/polygons"),
|
||||
PNAME("navigation_3d/edges"),
|
||||
PNAME("navigation_3d/edges_merged"),
|
||||
PNAME("navigation_3d/edges_connected"),
|
||||
PNAME("navigation_3d/edges_free"),
|
||||
PNAME("navigation_3d/obstacles"),
|
||||
#endif // NAVIGATION_3D_DISABLED
|
||||
};
|
||||
static_assert(std::size(names) == MONITOR_MAX);
|
||||
|
||||
return names[p_monitor];
|
||||
}
|
||||
|
||||
double Performance::get_monitor(Monitor p_monitor) const {
|
||||
int info = 0;
|
||||
|
||||
switch (p_monitor) {
|
||||
case TIME_FPS:
|
||||
return Engine::get_singleton()->get_frames_per_second();
|
||||
case TIME_PROCESS:
|
||||
return _process_time;
|
||||
case TIME_PHYSICS_PROCESS:
|
||||
return _physics_process_time;
|
||||
case TIME_NAVIGATION_PROCESS:
|
||||
return _navigation_process_time;
|
||||
case MEMORY_STATIC:
|
||||
return Memory::get_mem_usage();
|
||||
case MEMORY_STATIC_MAX:
|
||||
return Memory::get_mem_max_usage();
|
||||
case MEMORY_MESSAGE_BUFFER_MAX:
|
||||
return MessageQueue::get_singleton()->get_max_buffer_usage();
|
||||
case OBJECT_COUNT:
|
||||
return ObjectDB::get_object_count();
|
||||
case OBJECT_RESOURCE_COUNT:
|
||||
return ResourceCache::get_cached_resource_count();
|
||||
case OBJECT_NODE_COUNT:
|
||||
return _get_node_count();
|
||||
case OBJECT_ORPHAN_NODE_COUNT:
|
||||
return Node::orphan_node_count;
|
||||
case RENDER_TOTAL_OBJECTS_IN_FRAME:
|
||||
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TOTAL_OBJECTS_IN_FRAME);
|
||||
case RENDER_TOTAL_PRIMITIVES_IN_FRAME:
|
||||
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TOTAL_PRIMITIVES_IN_FRAME);
|
||||
case RENDER_TOTAL_DRAW_CALLS_IN_FRAME:
|
||||
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TOTAL_DRAW_CALLS_IN_FRAME);
|
||||
case RENDER_VIDEO_MEM_USED:
|
||||
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_VIDEO_MEM_USED);
|
||||
case RENDER_TEXTURE_MEM_USED:
|
||||
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TEXTURE_MEM_USED);
|
||||
case RENDER_BUFFER_MEM_USED:
|
||||
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_BUFFER_MEM_USED);
|
||||
case PIPELINE_COMPILATIONS_CANVAS:
|
||||
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_CANVAS);
|
||||
case PIPELINE_COMPILATIONS_MESH:
|
||||
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_MESH);
|
||||
case PIPELINE_COMPILATIONS_SURFACE:
|
||||
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_SURFACE);
|
||||
case PIPELINE_COMPILATIONS_DRAW:
|
||||
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_DRAW);
|
||||
case PIPELINE_COMPILATIONS_SPECIALIZATION:
|
||||
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_SPECIALIZATION);
|
||||
#ifndef PHYSICS_2D_DISABLED
|
||||
case PHYSICS_2D_ACTIVE_OBJECTS:
|
||||
return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ACTIVE_OBJECTS);
|
||||
case PHYSICS_2D_COLLISION_PAIRS:
|
||||
return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_COLLISION_PAIRS);
|
||||
case PHYSICS_2D_ISLAND_COUNT:
|
||||
return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ISLAND_COUNT);
|
||||
#else
|
||||
case PHYSICS_2D_ACTIVE_OBJECTS:
|
||||
return 0;
|
||||
case PHYSICS_2D_COLLISION_PAIRS:
|
||||
return 0;
|
||||
case PHYSICS_2D_ISLAND_COUNT:
|
||||
return 0;
|
||||
#endif // PHYSICS_2D_DISABLED
|
||||
#ifndef PHYSICS_3D_DISABLED
|
||||
case PHYSICS_3D_ACTIVE_OBJECTS:
|
||||
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ACTIVE_OBJECTS);
|
||||
case PHYSICS_3D_COLLISION_PAIRS:
|
||||
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_COLLISION_PAIRS);
|
||||
case PHYSICS_3D_ISLAND_COUNT:
|
||||
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ISLAND_COUNT);
|
||||
#else
|
||||
case PHYSICS_3D_ACTIVE_OBJECTS:
|
||||
return 0;
|
||||
case PHYSICS_3D_COLLISION_PAIRS:
|
||||
return 0;
|
||||
case PHYSICS_3D_ISLAND_COUNT:
|
||||
return 0;
|
||||
#endif // PHYSICS_3D_DISABLED
|
||||
|
||||
case AUDIO_OUTPUT_LATENCY:
|
||||
return AudioServer::get_singleton()->get_output_latency();
|
||||
|
||||
case NAVIGATION_ACTIVE_MAPS:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_ACTIVE_MAPS);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
#ifndef NAVIGATION_3D_DISABLED
|
||||
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_ACTIVE_MAPS);
|
||||
#endif // NAVIGATION_3D_DISABLED
|
||||
return info;
|
||||
|
||||
case NAVIGATION_REGION_COUNT:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_REGION_COUNT);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
#ifndef NAVIGATION_3D_DISABLED
|
||||
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_REGION_COUNT);
|
||||
#endif // NAVIGATION_3D_DISABLED
|
||||
return info;
|
||||
|
||||
case NAVIGATION_AGENT_COUNT:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_AGENT_COUNT);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
#ifndef NAVIGATION_3D_DISABLED
|
||||
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_AGENT_COUNT);
|
||||
#endif // NAVIGATION_3D_DISABLED
|
||||
return info;
|
||||
|
||||
case NAVIGATION_LINK_COUNT:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_LINK_COUNT);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
#ifndef NAVIGATION_3D_DISABLED
|
||||
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_LINK_COUNT);
|
||||
#endif // NAVIGATION_3D_DISABLED
|
||||
return info;
|
||||
|
||||
case NAVIGATION_POLYGON_COUNT:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_POLYGON_COUNT);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
#ifndef NAVIGATION_3D_DISABLED
|
||||
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_POLYGON_COUNT);
|
||||
#endif // NAVIGATION_3D_DISABLED
|
||||
return info;
|
||||
|
||||
case NAVIGATION_EDGE_COUNT:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_COUNT);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
#ifndef NAVIGATION_3D_DISABLED
|
||||
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_COUNT);
|
||||
#endif // NAVIGATION_3D_DISABLED
|
||||
return info;
|
||||
|
||||
case NAVIGATION_EDGE_MERGE_COUNT:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_MERGE_COUNT);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
#ifndef NAVIGATION_3D_DISABLED
|
||||
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_MERGE_COUNT);
|
||||
#endif // NAVIGATION_3D_DISABLED
|
||||
return info;
|
||||
|
||||
case NAVIGATION_EDGE_CONNECTION_COUNT:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_CONNECTION_COUNT);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
#ifndef NAVIGATION_3D_DISABLED
|
||||
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_CONNECTION_COUNT);
|
||||
#endif // NAVIGATION_3D_DISABLED
|
||||
return info;
|
||||
|
||||
case NAVIGATION_EDGE_FREE_COUNT:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_FREE_COUNT);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
#ifndef NAVIGATION_3D_DISABLED
|
||||
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_FREE_COUNT);
|
||||
#endif // NAVIGATION_3D_DISABLED
|
||||
return info;
|
||||
|
||||
case NAVIGATION_OBSTACLE_COUNT:
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_OBSTACLE_COUNT);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
#ifndef NAVIGATION_3D_DISABLED
|
||||
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_OBSTACLE_COUNT);
|
||||
#endif // NAVIGATION_3D_DISABLED
|
||||
return info;
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
case NAVIGATION_2D_ACTIVE_MAPS:
|
||||
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_ACTIVE_MAPS);
|
||||
case NAVIGATION_2D_REGION_COUNT:
|
||||
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_REGION_COUNT);
|
||||
case NAVIGATION_2D_AGENT_COUNT:
|
||||
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_AGENT_COUNT);
|
||||
case NAVIGATION_2D_LINK_COUNT:
|
||||
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_LINK_COUNT);
|
||||
case NAVIGATION_2D_POLYGON_COUNT:
|
||||
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_POLYGON_COUNT);
|
||||
case NAVIGATION_2D_EDGE_COUNT:
|
||||
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_COUNT);
|
||||
case NAVIGATION_2D_EDGE_MERGE_COUNT:
|
||||
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_MERGE_COUNT);
|
||||
case NAVIGATION_2D_EDGE_CONNECTION_COUNT:
|
||||
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_CONNECTION_COUNT);
|
||||
case NAVIGATION_2D_EDGE_FREE_COUNT:
|
||||
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_FREE_COUNT);
|
||||
case NAVIGATION_2D_OBSTACLE_COUNT:
|
||||
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_OBSTACLE_COUNT);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
#ifndef NAVIGATION_3D_DISABLED
|
||||
case NAVIGATION_3D_ACTIVE_MAPS:
|
||||
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_ACTIVE_MAPS);
|
||||
case NAVIGATION_3D_REGION_COUNT:
|
||||
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_REGION_COUNT);
|
||||
case NAVIGATION_3D_AGENT_COUNT:
|
||||
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_AGENT_COUNT);
|
||||
case NAVIGATION_3D_LINK_COUNT:
|
||||
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_LINK_COUNT);
|
||||
case NAVIGATION_3D_POLYGON_COUNT:
|
||||
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_POLYGON_COUNT);
|
||||
case NAVIGATION_3D_EDGE_COUNT:
|
||||
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_COUNT);
|
||||
case NAVIGATION_3D_EDGE_MERGE_COUNT:
|
||||
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_MERGE_COUNT);
|
||||
case NAVIGATION_3D_EDGE_CONNECTION_COUNT:
|
||||
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_CONNECTION_COUNT);
|
||||
case NAVIGATION_3D_EDGE_FREE_COUNT:
|
||||
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_FREE_COUNT);
|
||||
case NAVIGATION_3D_OBSTACLE_COUNT:
|
||||
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_OBSTACLE_COUNT);
|
||||
#endif // NAVIGATION_3D_DISABLED
|
||||
|
||||
default: {
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Performance::MonitorType Performance::get_monitor_type(Monitor p_monitor) const {
|
||||
ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, MONITOR_TYPE_QUANTITY);
|
||||
// ugly
|
||||
static const MonitorType types[MONITOR_MAX] = {
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_TIME,
|
||||
MONITOR_TYPE_TIME,
|
||||
MONITOR_TYPE_TIME,
|
||||
MONITOR_TYPE_MEMORY,
|
||||
MONITOR_TYPE_MEMORY,
|
||||
MONITOR_TYPE_MEMORY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_MEMORY,
|
||||
MONITOR_TYPE_MEMORY,
|
||||
MONITOR_TYPE_MEMORY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_TIME,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
|
||||
};
|
||||
static_assert((sizeof(types) / sizeof(MonitorType)) == MONITOR_MAX);
|
||||
|
||||
return types[p_monitor];
|
||||
}
|
||||
|
||||
void Performance::set_process_time(double p_pt) {
|
||||
_process_time = p_pt;
|
||||
}
|
||||
|
||||
void Performance::set_physics_process_time(double p_pt) {
|
||||
_physics_process_time = p_pt;
|
||||
}
|
||||
|
||||
void Performance::set_navigation_process_time(double p_pt) {
|
||||
_navigation_process_time = p_pt;
|
||||
}
|
||||
|
||||
void Performance::add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args) {
|
||||
ERR_FAIL_COND_MSG(has_custom_monitor(p_id), "Custom monitor with id '" + String(p_id) + "' already exists.");
|
||||
_monitor_map.insert(p_id, MonitorCall(p_callable, p_args));
|
||||
_monitor_modification_time = OS::get_singleton()->get_ticks_usec();
|
||||
}
|
||||
|
||||
void Performance::remove_custom_monitor(const StringName &p_id) {
|
||||
ERR_FAIL_COND_MSG(!has_custom_monitor(p_id), "Custom monitor with id '" + String(p_id) + "' doesn't exist.");
|
||||
_monitor_map.erase(p_id);
|
||||
_monitor_modification_time = OS::get_singleton()->get_ticks_usec();
|
||||
}
|
||||
|
||||
bool Performance::has_custom_monitor(const StringName &p_id) {
|
||||
return _monitor_map.has(p_id);
|
||||
}
|
||||
|
||||
Variant Performance::get_custom_monitor(const StringName &p_id) {
|
||||
ERR_FAIL_COND_V_MSG(!has_custom_monitor(p_id), Variant(), "Custom monitor with id '" + String(p_id) + "' doesn't exist.");
|
||||
bool error;
|
||||
String error_message;
|
||||
Variant return_value = _monitor_map[p_id].call(error, error_message);
|
||||
ERR_FAIL_COND_V_MSG(error, return_value, "Error calling from custom monitor '" + String(p_id) + "' to callable: " + error_message);
|
||||
return return_value;
|
||||
}
|
||||
|
||||
TypedArray<StringName> Performance::get_custom_monitor_names() {
|
||||
if (!_monitor_map.size()) {
|
||||
return TypedArray<StringName>();
|
||||
}
|
||||
TypedArray<StringName> return_array;
|
||||
return_array.resize(_monitor_map.size());
|
||||
int index = 0;
|
||||
for (KeyValue<StringName, MonitorCall> i : _monitor_map) {
|
||||
return_array.set(index, i.key);
|
||||
index++;
|
||||
}
|
||||
return return_array;
|
||||
}
|
||||
|
||||
uint64_t Performance::get_monitor_modification_time() {
|
||||
return _monitor_modification_time;
|
||||
}
|
||||
|
||||
Performance::Performance() {
|
||||
_process_time = 0;
|
||||
_physics_process_time = 0;
|
||||
_navigation_process_time = 0;
|
||||
_monitor_modification_time = 0;
|
||||
singleton = this;
|
||||
}
|
||||
|
||||
Performance::MonitorCall::MonitorCall(Callable p_callable, Vector<Variant> p_arguments) {
|
||||
_callable = p_callable;
|
||||
_arguments = p_arguments;
|
||||
}
|
||||
|
||||
Performance::MonitorCall::MonitorCall() {
|
||||
}
|
||||
|
||||
Variant Performance::MonitorCall::call(bool &r_error, String &r_error_message) {
|
||||
Vector<const Variant *> arguments_mem;
|
||||
arguments_mem.resize(_arguments.size());
|
||||
for (int i = 0; i < _arguments.size(); i++) {
|
||||
arguments_mem.write[i] = &_arguments[i];
|
||||
}
|
||||
const Variant **args = (const Variant **)arguments_mem.ptr();
|
||||
int argc = _arguments.size();
|
||||
Variant return_value;
|
||||
Callable::CallError error;
|
||||
_callable.callp(args, argc, return_value, error);
|
||||
r_error = (error.error != Callable::CallError::CALL_OK);
|
||||
if (r_error) {
|
||||
r_error_message = Variant::get_callable_error_text(_callable, args, argc, error);
|
||||
}
|
||||
return return_value;
|
||||
}
|
159
main/performance.h
Normal file
159
main/performance.h
Normal file
@@ -0,0 +1,159 @@
|
||||
/**************************************************************************/
|
||||
/* performance.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/object/class_db.h"
|
||||
#include "core/templates/hash_map.h"
|
||||
|
||||
#define PERF_WARN_OFFLINE_FUNCTION
|
||||
#define PERF_WARN_PROCESS_SYNC
|
||||
|
||||
template <typename T>
|
||||
class TypedArray;
|
||||
|
||||
class Performance : public Object {
|
||||
GDCLASS(Performance, Object);
|
||||
|
||||
static Performance *singleton;
|
||||
static void _bind_methods();
|
||||
|
||||
int _get_node_count() const;
|
||||
|
||||
double _process_time;
|
||||
double _physics_process_time;
|
||||
double _navigation_process_time;
|
||||
|
||||
class MonitorCall {
|
||||
Callable _callable;
|
||||
Vector<Variant> _arguments;
|
||||
|
||||
public:
|
||||
MonitorCall(Callable p_callable, Vector<Variant> p_arguments);
|
||||
MonitorCall();
|
||||
Variant call(bool &r_error, String &r_error_message);
|
||||
};
|
||||
|
||||
HashMap<StringName, MonitorCall> _monitor_map;
|
||||
uint64_t _monitor_modification_time;
|
||||
|
||||
public:
|
||||
enum Monitor {
|
||||
TIME_FPS,
|
||||
TIME_PROCESS,
|
||||
TIME_PHYSICS_PROCESS,
|
||||
TIME_NAVIGATION_PROCESS,
|
||||
MEMORY_STATIC,
|
||||
MEMORY_STATIC_MAX,
|
||||
MEMORY_MESSAGE_BUFFER_MAX,
|
||||
OBJECT_COUNT,
|
||||
OBJECT_RESOURCE_COUNT,
|
||||
OBJECT_NODE_COUNT,
|
||||
OBJECT_ORPHAN_NODE_COUNT,
|
||||
RENDER_TOTAL_OBJECTS_IN_FRAME,
|
||||
RENDER_TOTAL_PRIMITIVES_IN_FRAME,
|
||||
RENDER_TOTAL_DRAW_CALLS_IN_FRAME,
|
||||
RENDER_VIDEO_MEM_USED,
|
||||
RENDER_TEXTURE_MEM_USED,
|
||||
RENDER_BUFFER_MEM_USED,
|
||||
PHYSICS_2D_ACTIVE_OBJECTS,
|
||||
PHYSICS_2D_COLLISION_PAIRS,
|
||||
PHYSICS_2D_ISLAND_COUNT,
|
||||
PHYSICS_3D_ACTIVE_OBJECTS,
|
||||
PHYSICS_3D_COLLISION_PAIRS,
|
||||
PHYSICS_3D_ISLAND_COUNT,
|
||||
AUDIO_OUTPUT_LATENCY,
|
||||
NAVIGATION_ACTIVE_MAPS,
|
||||
NAVIGATION_REGION_COUNT,
|
||||
NAVIGATION_AGENT_COUNT,
|
||||
NAVIGATION_LINK_COUNT,
|
||||
NAVIGATION_POLYGON_COUNT,
|
||||
NAVIGATION_EDGE_COUNT,
|
||||
NAVIGATION_EDGE_MERGE_COUNT,
|
||||
NAVIGATION_EDGE_CONNECTION_COUNT,
|
||||
NAVIGATION_EDGE_FREE_COUNT,
|
||||
NAVIGATION_OBSTACLE_COUNT,
|
||||
PIPELINE_COMPILATIONS_CANVAS,
|
||||
PIPELINE_COMPILATIONS_MESH,
|
||||
PIPELINE_COMPILATIONS_SURFACE,
|
||||
PIPELINE_COMPILATIONS_DRAW,
|
||||
PIPELINE_COMPILATIONS_SPECIALIZATION,
|
||||
NAVIGATION_2D_ACTIVE_MAPS,
|
||||
NAVIGATION_2D_REGION_COUNT,
|
||||
NAVIGATION_2D_AGENT_COUNT,
|
||||
NAVIGATION_2D_LINK_COUNT,
|
||||
NAVIGATION_2D_POLYGON_COUNT,
|
||||
NAVIGATION_2D_EDGE_COUNT,
|
||||
NAVIGATION_2D_EDGE_MERGE_COUNT,
|
||||
NAVIGATION_2D_EDGE_CONNECTION_COUNT,
|
||||
NAVIGATION_2D_EDGE_FREE_COUNT,
|
||||
NAVIGATION_2D_OBSTACLE_COUNT,
|
||||
NAVIGATION_3D_ACTIVE_MAPS,
|
||||
NAVIGATION_3D_REGION_COUNT,
|
||||
NAVIGATION_3D_AGENT_COUNT,
|
||||
NAVIGATION_3D_LINK_COUNT,
|
||||
NAVIGATION_3D_POLYGON_COUNT,
|
||||
NAVIGATION_3D_EDGE_COUNT,
|
||||
NAVIGATION_3D_EDGE_MERGE_COUNT,
|
||||
NAVIGATION_3D_EDGE_CONNECTION_COUNT,
|
||||
NAVIGATION_3D_EDGE_FREE_COUNT,
|
||||
NAVIGATION_3D_OBSTACLE_COUNT,
|
||||
MONITOR_MAX
|
||||
};
|
||||
|
||||
enum MonitorType {
|
||||
MONITOR_TYPE_QUANTITY,
|
||||
MONITOR_TYPE_MEMORY,
|
||||
MONITOR_TYPE_TIME
|
||||
};
|
||||
|
||||
double get_monitor(Monitor p_monitor) const;
|
||||
String get_monitor_name(Monitor p_monitor) const;
|
||||
|
||||
MonitorType get_monitor_type(Monitor p_monitor) const;
|
||||
|
||||
void set_process_time(double p_pt);
|
||||
void set_physics_process_time(double p_pt);
|
||||
void set_navigation_process_time(double p_pt);
|
||||
|
||||
void add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args);
|
||||
void remove_custom_monitor(const StringName &p_id);
|
||||
bool has_custom_monitor(const StringName &p_id);
|
||||
Variant get_custom_monitor(const StringName &p_id);
|
||||
TypedArray<StringName> get_custom_monitor_names();
|
||||
|
||||
uint64_t get_monitor_modification_time();
|
||||
|
||||
static Performance *get_singleton() { return singleton; }
|
||||
|
||||
Performance();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(Performance::Monitor);
|
BIN
main/splash.png
Normal file
BIN
main/splash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
110
main/steam_tracker.cpp
Normal file
110
main/steam_tracker.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
/**************************************************************************/
|
||||
/* steam_tracker.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#if defined(STEAMAPI_ENABLED)
|
||||
|
||||
#include "steam_tracker.h"
|
||||
|
||||
// https://partner.steamgames.com/doc/sdk/api#initialization_and_shutdown
|
||||
|
||||
SteamTracker::SteamTracker() {
|
||||
String path;
|
||||
if (OS::get_singleton()->has_feature("linuxbsd")) {
|
||||
path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("libsteam_api.so");
|
||||
if (!FileAccess::exists(path)) {
|
||||
path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("../lib").path_join("libsteam_api.so");
|
||||
if (!FileAccess::exists(path)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (OS::get_singleton()->has_feature("windows")) {
|
||||
if (OS::get_singleton()->has_feature("64")) {
|
||||
path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("steam_api64.dll");
|
||||
} else {
|
||||
path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("steam_api.dll");
|
||||
}
|
||||
if (!FileAccess::exists(path)) {
|
||||
return;
|
||||
}
|
||||
} else if (OS::get_singleton()->has_feature("macos")) {
|
||||
path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("libsteam_api.dylib");
|
||||
if (!FileAccess::exists(path)) {
|
||||
path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("../Frameworks").path_join("libsteam_api.dylib");
|
||||
if (!FileAccess::exists(path)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
Error err = OS::get_singleton()->open_dynamic_library(path, steam_library_handle);
|
||||
if (err != OK) {
|
||||
steam_library_handle = nullptr;
|
||||
return;
|
||||
}
|
||||
print_verbose("Loaded SteamAPI library");
|
||||
|
||||
void *symbol_handle = nullptr;
|
||||
err = OS::get_singleton()->get_dynamic_library_symbol_handle(steam_library_handle, "SteamAPI_InitFlat", symbol_handle, true); // Try new API, 1.59+.
|
||||
if (err != OK) {
|
||||
err = OS::get_singleton()->get_dynamic_library_symbol_handle(steam_library_handle, "SteamAPI_Init", symbol_handle); // Try old API.
|
||||
if (err != OK) {
|
||||
return;
|
||||
}
|
||||
steam_init_function = (SteamAPI_InitFunction)symbol_handle;
|
||||
} else {
|
||||
steam_init_flat_function = (SteamAPI_InitFlatFunction)symbol_handle;
|
||||
}
|
||||
|
||||
err = OS::get_singleton()->get_dynamic_library_symbol_handle(steam_library_handle, "SteamAPI_Shutdown", symbol_handle);
|
||||
if (err != OK) {
|
||||
return;
|
||||
}
|
||||
steam_shutdown_function = (SteamAPI_ShutdownFunction)symbol_handle;
|
||||
|
||||
if (steam_init_flat_function) {
|
||||
char err_msg[1024] = {};
|
||||
steam_initialized = (steam_init_flat_function(&err_msg[0]) == SteamAPIInitResult_OK);
|
||||
} else if (steam_init_function) {
|
||||
steam_initialized = steam_init_function();
|
||||
}
|
||||
}
|
||||
|
||||
SteamTracker::~SteamTracker() {
|
||||
if (steam_shutdown_function && steam_initialized) {
|
||||
steam_shutdown_function();
|
||||
}
|
||||
if (steam_library_handle) {
|
||||
OS::get_singleton()->close_dynamic_library(steam_library_handle);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // STEAMAPI_ENABLED
|
71
main/steam_tracker.h
Normal file
71
main/steam_tracker.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/**************************************************************************/
|
||||
/* steam_tracker.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(STEAMAPI_ENABLED)
|
||||
|
||||
#include "core/os/os.h"
|
||||
|
||||
// SteamTracker is used to load SteamAPI dynamic library and initialize
|
||||
// the interface, this notifies Steam that Godot editor is running and
|
||||
// allow tracking of the usage time of child instances of the engine
|
||||
// (e.g., opened projects).
|
||||
//
|
||||
// Currently, SteamAPI is not used by the engine in any way, and is not
|
||||
// exposed to the scripting APIs.
|
||||
|
||||
enum SteamAPIInitResult {
|
||||
SteamAPIInitResult_OK = 0,
|
||||
SteamAPIInitResult_FailedGeneric = 1,
|
||||
SteamAPIInitResult_NoSteamClient = 2,
|
||||
SteamAPIInitResult_VersionMismatch = 3,
|
||||
};
|
||||
|
||||
// https://partner.steamgames.com/doc/api/steam_api#SteamAPI_Init
|
||||
typedef bool (*SteamAPI_InitFunction)();
|
||||
typedef SteamAPIInitResult (*SteamAPI_InitFlatFunction)(char *r_err_msg);
|
||||
|
||||
// https://partner.steamgames.com/doc/api/steam_api#SteamAPI_Shutdown
|
||||
typedef void (*SteamAPI_ShutdownFunction)();
|
||||
|
||||
class SteamTracker {
|
||||
void *steam_library_handle = nullptr;
|
||||
SteamAPI_InitFunction steam_init_function = nullptr;
|
||||
SteamAPI_InitFlatFunction steam_init_flat_function = nullptr;
|
||||
SteamAPI_ShutdownFunction steam_shutdown_function = nullptr;
|
||||
bool steam_initialized = false;
|
||||
|
||||
public:
|
||||
SteamTracker();
|
||||
~SteamTracker();
|
||||
};
|
||||
|
||||
#endif // STEAMAPI_ENABLED
|
Reference in New Issue
Block a user