Skip to content

Commit

Permalink
Merge pull request #955 from Spartan322/merge/0b6a717
Browse files Browse the repository at this point in the history
  • Loading branch information
Spartan322 authored Feb 4, 2025
2 parents dc9eade + 35e289f commit 0e13df4
Show file tree
Hide file tree
Showing 226 changed files with 4,887 additions and 1,892 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ repos:
stages: [manual] # Not automatically triggered, invoked via `pre-commit run --hook-stage manual clang-tidy`

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
rev: v0.9.4
hooks:
- id: ruff
args: [--fix]
Expand All @@ -48,7 +48,7 @@ repos:
types_or: [text]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
rev: v1.14.1
hooks:
- id: mypy
files: \.py$
Expand Down
60 changes: 27 additions & 33 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,11 @@ for x in sorted(glob.glob("platform/*")):
sys.path.remove(tmppath)
sys.modules.pop("detect")

custom_tools = ["default"]

platform_arg = ARGUMENTS.get("platform", ARGUMENTS.get("p", False))

if platform_arg == "android":
custom_tools = ["clang", "clang++", "as", "ar", "link"]
elif platform_arg == "web":
# Use generic POSIX build toolchain for Emscripten.
custom_tools = ["cc", "c++", "ar", "link", "textfile", "zip"]
elif os.name == "nt" and methods.get_cmdline_bool("use_mingw", False):
custom_tools = ["mingw"]

# We let SCons build its default ENV as it includes OS-specific things which we don't
# want to have to pull in manually.
# want to have to pull in manually. However we enforce no "tools", which we register
# further down after parsing our platform-specific configuration.
# Then we prepend PATH to make it take precedence, while preserving SCons' own entries.
env = Environment(tools=custom_tools)
env = Environment(tools=[])
env.PrependENVPath("PATH", os.getenv("PATH"))
env.PrependENVPath("PKG_CONFIG_PATH", os.getenv("PKG_CONFIG_PATH"))
if "TERM" in os.environ: # Used for colored output.
Expand Down Expand Up @@ -168,11 +157,7 @@ if profile:
opts = Variables(customs, ARGUMENTS)

# Target build options
if env.scons_version >= (4, 3):
opts.Add(["platform", "p"], "Target platform (%s)" % "|".join(platform_list), "")
else:
opts.Add("platform", "Target platform (%s)" % "|".join(platform_list), "")
opts.Add("p", "Alias for 'platform'", "")
opts.Add((["platform", "p"], "Target platform (%s)" % "|".join(platform_list), ""))
opts.Add(EnumVariable("target", "Compilation target", "editor", ("editor", "template_release", "template_debug")))
opts.Add(EnumVariable("arch", "CPU architecture", "auto", ["auto"] + architectures, architecture_aliases))
opts.Add(BoolVariable("dev_build", "Developer build with dev-only debugging code (DEV_ENABLED)", False))
Expand Down Expand Up @@ -312,10 +297,7 @@ if env["import_env_vars"]:

# Platform selection: validate input, and add options.

if env.scons_version < (4, 3) and not env["platform"]:
env["platform"] = env["p"]

if env["platform"] == "":
if not env["platform"]:
# Missing `platform` argument, try to detect platform automatically
if (
sys.platform.startswith("linux")
Expand All @@ -330,8 +312,8 @@ if env["platform"] == "":
elif sys.platform == "win32":
env["platform"] = "windows"

if env["platform"] != "":
print(f'Automatically detected platform: {env["platform"]}')
if env["platform"]:
print(f"Automatically detected platform: {env['platform']}")

# Deprecated aliases kept for compatibility.
if env["platform"] in compatibility_platform_aliases:
Expand All @@ -352,7 +334,7 @@ if env["platform"] not in platform_list:

if env["platform"] == "list":
print(text)
elif env["platform"] == "":
elif not env["platform"]:
print_error("Could not detect platform automatically.\n" + text)
else:
print_error(f'Invalid target platform "{env["platform"]}".\n' + text)
Expand Down Expand Up @@ -434,6 +416,23 @@ env.modules_detected = modules_detected
opts.Update(env, {**ARGUMENTS, **env.Dictionary()})
Help(opts.GenerateHelpText(env))


# FIXME: Tool assignment happening at this stage is a direct consequence of getting the platform logic AFTER the SCons
# environment was already been constructed. Fixing this would require a broader refactor where all options are setup
# ahead of time with native validator/converter functions.
tmppath = "./platform/" + env["platform"]
sys.path.insert(0, tmppath)
import detect

custom_tools = ["default"]
try: # Platform custom tools are optional
custom_tools = detect.get_tools(env)
except AttributeError:
pass
for tool in custom_tools:
env.Tool(tool)


# add default include paths

env.Prepend(CPPPATH=["#"])
Expand Down Expand Up @@ -515,10 +514,6 @@ if not env["deprecated"]:
if env["precision"] == "double":
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])

tmppath = "./platform/" + env["platform"]
sys.path.insert(0, tmppath)
import detect

# Default num_jobs to local cpu count if not user specified.
# SCons has a peculiarity where user-specified options won't be overridden
# by SetOption, so we can rely on this to know if we should use our default.
Expand Down Expand Up @@ -587,7 +582,7 @@ if env["dev_mode"]:
if env["production"]:
env["use_static_cpp"] = methods.get_cmdline_bool("use_static_cpp", True)
env["debug_symbols"] = methods.get_cmdline_bool("debug_symbols", False)
if platform_arg == "android":
if env["platform"] == "android":
env["swappy"] = methods.get_cmdline_bool("swappy", True)
# LTO "auto" means we handle the preferred option in each platform detect.py.
env["lto"] = ARGUMENTS.get("lto", "auto")
Expand Down Expand Up @@ -1003,8 +998,7 @@ if env["disable_3d"]:
if env["disable_advanced_gui"]:
if env.editor_build:
print_error(
"Build option `disable_advanced_gui=yes` cannot be used for editor builds, "
"only for export template builds."
"Build option `disable_advanced_gui=yes` cannot be used for editor builds, only for export template builds."
)
Exit(255)
else:
Expand Down
4 changes: 2 additions & 2 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1265,10 +1265,10 @@ void ProjectSettings::refresh_global_class_list() {
Array script_classes = get_global_class_list();
for (int i = 0; i < script_classes.size(); i++) {
Dictionary c = script_classes[i];
if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) {
if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base") || !c.has("is_abstract") || !c.has("is_tool")) {
continue;
}
ScriptServer::add_global_class(c["class"], c["base"], c["language"], c["path"]);
ScriptServer::add_global_class(c["class"], c["base"], c["language"], c["path"], c["is_abstract"], c["is_tool"]);
}
}

Expand Down
53 changes: 18 additions & 35 deletions core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ Input *Input::singleton = nullptr;

void (*Input::set_mouse_mode_func)(Input::MouseMode) = nullptr;
Input::MouseMode (*Input::get_mouse_mode_func)() = nullptr;
void (*Input::set_mouse_mode_override_func)(Input::MouseMode) = nullptr;
Input::MouseMode (*Input::get_mouse_mode_override_func)() = nullptr;
void (*Input::set_mouse_mode_override_enabled_func)(bool) = nullptr;
bool (*Input::is_mouse_mode_override_enabled_func)() = nullptr;
void (*Input::warp_mouse_func)(const Vector2 &p_position) = nullptr;
Input::CursorShape (*Input::get_current_cursor_shape_func)() = nullptr;
void (*Input::set_custom_mouse_cursor_func)(const Ref<Resource> &, Input::CursorShape, const Vector2 &) = nullptr;
Expand All @@ -88,51 +92,29 @@ Input *Input::get_singleton() {
}

void Input::set_mouse_mode(MouseMode p_mode) {
ERR_FAIL_INDEX((int)p_mode, 5);

if (p_mode == mouse_mode) {
return;
}

// Allow to be set even if overridden, to see if the platform allows the mode.
ERR_FAIL_INDEX(p_mode, MouseMode::MOUSE_MODE_MAX);
set_mouse_mode_func(p_mode);
mouse_mode = get_mouse_mode_func();

if (mouse_mode_override_enabled) {
set_mouse_mode_func(mouse_mode_override);
}
}

Input::MouseMode Input::get_mouse_mode() const {
return mouse_mode;
return get_mouse_mode_func();
}

void Input::set_mouse_mode_override_enabled(bool p_enabled) {
if (p_enabled == mouse_mode_override_enabled) {
return;
}

mouse_mode_override_enabled = p_enabled;

if (p_enabled) {
set_mouse_mode_func(mouse_mode_override);
mouse_mode_override = get_mouse_mode_func();
} else {
set_mouse_mode_func(mouse_mode);
}
void Input::set_mouse_mode_override(MouseMode p_mode) {
ERR_FAIL_INDEX(p_mode, MouseMode::MOUSE_MODE_MAX);
set_mouse_mode_override_func(p_mode);
}

void Input::set_mouse_mode_override(MouseMode p_mode) {
ERR_FAIL_INDEX((int)p_mode, 5);
Input::MouseMode Input::get_mouse_mode_override() const {
return get_mouse_mode_override_func();
}

if (p_mode == mouse_mode_override) {
return;
}
void Input::set_mouse_mode_override_enabled(bool p_override_enabled) {
set_mouse_mode_override_enabled_func(p_override_enabled);
}

if (mouse_mode_override_enabled) {
set_mouse_mode_func(p_mode);
mouse_mode_override = get_mouse_mode_func();
}
bool Input::is_mouse_mode_override_enabled() {
return is_mouse_mode_override_enabled_func();
}

void Input::_bind_methods() {
Expand Down Expand Up @@ -201,6 +183,7 @@ void Input::_bind_methods() {
BIND_ENUM_CONSTANT(MOUSE_MODE_CAPTURED);
BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED);
BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED_HIDDEN);
BIND_ENUM_CONSTANT(MOUSE_MODE_MAX);

BIND_ENUM_CONSTANT(CURSOR_ARROW);
BIND_ENUM_CONSTANT(CURSOR_IBEAM);
Expand Down
14 changes: 9 additions & 5 deletions core/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ class Input : public Object {
static constexpr uint64_t MAX_EVENT = 32;

public:
// Keep synced with "DisplayServer::MouseMode" enum.
enum MouseMode {
MOUSE_MODE_VISIBLE,
MOUSE_MODE_HIDDEN,
MOUSE_MODE_CAPTURED,
MOUSE_MODE_CONFINED,
MOUSE_MODE_CONFINED_HIDDEN,
MOUSE_MODE_MAX,
};

#undef CursorShape
Expand Down Expand Up @@ -107,10 +109,6 @@ class Input : public Object {
bool legacy_just_pressed_behavior = false;
bool disable_input = false;

MouseMode mouse_mode = MOUSE_MODE_VISIBLE;
bool mouse_mode_override_enabled = false;
MouseMode mouse_mode_override = MOUSE_MODE_VISIBLE;

struct ActionState {
uint64_t pressed_physics_frame = UINT64_MAX;
uint64_t pressed_process_frame = UINT64_MAX;
Expand Down Expand Up @@ -270,6 +268,10 @@ class Input : public Object {

static void (*set_mouse_mode_func)(MouseMode);
static MouseMode (*get_mouse_mode_func)();
static void (*set_mouse_mode_override_func)(MouseMode);
static MouseMode (*get_mouse_mode_override_func)();
static void (*set_mouse_mode_override_enabled_func)(bool);
static bool (*is_mouse_mode_override_enabled_func)();
static void (*warp_mouse_func)(const Vector2 &p_position);

static CursorShape (*get_current_cursor_shape_func)();
Expand All @@ -288,8 +290,10 @@ class Input : public Object {
public:
void set_mouse_mode(MouseMode p_mode);
MouseMode get_mouse_mode() const;
void set_mouse_mode_override_enabled(bool p_enabled);
void set_mouse_mode_override(MouseMode p_mode);
MouseMode get_mouse_mode_override() const;
void set_mouse_mode_override_enabled(bool p_override_enabled);
bool is_mouse_mode_override_enabled();

#ifdef TOOLS_ENABLED
void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ String FileAccess::get_line() const {
uint8_t c = get_8();

while (!eof_reached()) {
if (c == '\n' || c == '\0') {
if (c == '\n' || c == '\0' || get_error() != OK) {
line.push_back(0);
return String::utf8(line.get_data());
} else if (c != '\r') {
Expand Down
29 changes: 17 additions & 12 deletions core/math/basis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,11 @@ void Basis::get_rotation_axis_angle_local(Vector3 &p_axis, real_t &p_angle) cons
}

Vector3 Basis::get_euler(EulerOrder p_order) const {
// This epsilon value results in angles within a +/- 0.04 degree range being simplified/truncated.
// Based on testing, this is the largest the epsilon can be without the angle truncation becoming
// visually noticeable.
const real_t epsilon = 0.00000025;

switch (p_order) {
case EulerOrder::XYZ: {
// Euler angles in XYZ convention.
Expand All @@ -468,8 +473,8 @@ Vector3 Basis::get_euler(EulerOrder p_order) const {

Vector3 euler;
real_t sy = rows[0][2];
if (sy < (1.0f - (real_t)CMP_EPSILON)) {
if (sy > -(1.0f - (real_t)CMP_EPSILON)) {
if (sy < (1.0f - epsilon)) {
if (sy > -(1.0f - epsilon)) {
// is this a pure Y rotation?
if (rows[1][0] == 0 && rows[0][1] == 0 && rows[1][2] == 0 && rows[2][1] == 0 && rows[1][1] == 1) {
// return the simplest form (human friendlier in editor and scripts)
Expand Down Expand Up @@ -503,8 +508,8 @@ Vector3 Basis::get_euler(EulerOrder p_order) const {

Vector3 euler;
real_t sz = rows[0][1];
if (sz < (1.0f - (real_t)CMP_EPSILON)) {
if (sz > -(1.0f - (real_t)CMP_EPSILON)) {
if (sz < (1.0f - epsilon)) {
if (sz > -(1.0f - epsilon)) {
euler.x = Math::atan2(rows[2][1], rows[1][1]);
euler.y = Math::atan2(rows[0][2], rows[0][0]);
euler.z = Math::asin(-sz);
Expand Down Expand Up @@ -534,8 +539,8 @@ Vector3 Basis::get_euler(EulerOrder p_order) const {

real_t m12 = rows[1][2];

if (m12 < (1 - (real_t)CMP_EPSILON)) {
if (m12 > -(1 - (real_t)CMP_EPSILON)) {
if (m12 < (1 - epsilon)) {
if (m12 > -(1 - epsilon)) {
// is this a pure X rotation?
if (rows[1][0] == 0 && rows[0][1] == 0 && rows[0][2] == 0 && rows[2][0] == 0 && rows[0][0] == 1) {
// return the simplest form (human friendlier in editor and scripts)
Expand Down Expand Up @@ -570,8 +575,8 @@ Vector3 Basis::get_euler(EulerOrder p_order) const {

Vector3 euler;
real_t sz = rows[1][0];
if (sz < (1.0f - (real_t)CMP_EPSILON)) {
if (sz > -(1.0f - (real_t)CMP_EPSILON)) {
if (sz < (1.0f - epsilon)) {
if (sz > -(1.0f - epsilon)) {
euler.x = Math::atan2(-rows[1][2], rows[1][1]);
euler.y = Math::atan2(-rows[2][0], rows[0][0]);
euler.z = Math::asin(sz);
Expand All @@ -598,8 +603,8 @@ Vector3 Basis::get_euler(EulerOrder p_order) const {
// -cx*sy sx cx*cy
Vector3 euler;
real_t sx = rows[2][1];
if (sx < (1.0f - (real_t)CMP_EPSILON)) {
if (sx > -(1.0f - (real_t)CMP_EPSILON)) {
if (sx < (1.0f - epsilon)) {
if (sx > -(1.0f - epsilon)) {
euler.x = Math::asin(sx);
euler.y = Math::atan2(-rows[2][0], rows[2][2]);
euler.z = Math::atan2(-rows[0][1], rows[1][1]);
Expand All @@ -626,8 +631,8 @@ Vector3 Basis::get_euler(EulerOrder p_order) const {
// -sy cy*sx cy*cx
Vector3 euler;
real_t sy = rows[2][0];
if (sy < (1.0f - (real_t)CMP_EPSILON)) {
if (sy > -(1.0f - (real_t)CMP_EPSILON)) {
if (sy < (1.0f - epsilon)) {
if (sy > -(1.0f - epsilon)) {
euler.x = Math::atan2(rows[2][1], rows[2][2]);
euler.y = Math::asin(-sy);
euler.z = Math::atan2(rows[1][0], rows[0][0]);
Expand Down
Loading

0 comments on commit 0e13df4

Please sign in to comment.