Skip to content

Commit

Permalink
Core: Integrate C++20 using enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Repiteo committed Jan 24, 2025
1 parent 894c2dc commit 0dfea2c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 90 deletions.
23 changes: 11 additions & 12 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace core_bind {
ResourceLoader *ResourceLoader::singleton = nullptr;

Error ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads, CacheMode p_cache_mode) {
return ::ResourceLoader::load_threaded_request(p_path, p_type_hint, p_use_sub_threads, ResourceFormatLoader::CacheMode(p_cache_mode));
return ::ResourceLoader::load_threaded_request(p_path, p_type_hint, p_use_sub_threads, p_cache_mode);
}

ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const String &p_path, Array r_progress) {
Expand All @@ -60,7 +60,7 @@ ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const
r_progress.resize(1);
r_progress[0] = progress;
}
return (ThreadLoadStatus)tls;
return tls;
}

Ref<Resource> ResourceLoader::load_threaded_get(const String &p_path) {
Expand All @@ -71,7 +71,7 @@ Ref<Resource> ResourceLoader::load_threaded_get(const String &p_path) {

Ref<Resource> ResourceLoader::load(const String &p_path, const String &p_type_hint, CacheMode p_cache_mode) {
Error err = OK;
Ref<Resource> ret = ::ResourceLoader::load(p_path, p_type_hint, ResourceFormatLoader::CacheMode(p_cache_mode), &err);
Ref<Resource> ret = ::ResourceLoader::load(p_path, p_type_hint, p_cache_mode, &err);

ERR_FAIL_COND_V_MSG(err != OK, ret, vformat("Error loading resource: '%s'.", p_path));
return ret;
Expand Down Expand Up @@ -315,15 +315,15 @@ PackedByteArray OS::read_buffer_from_stdin(int64_t p_buffer_size) {
}

OS::StdHandleType OS::get_stdin_type() const {
return (OS::StdHandleType)::OS::get_singleton()->get_stdin_type();
return ::OS::get_singleton()->get_stdin_type();
}

OS::StdHandleType OS::get_stdout_type() const {
return (OS::StdHandleType)::OS::get_singleton()->get_stdout_type();
return ::OS::get_singleton()->get_stdout_type();
}

OS::StdHandleType OS::get_stderr_type() const {
return (OS::StdHandleType)::OS::get_singleton()->get_stderr_type();
return ::OS::get_singleton()->get_stderr_type();
}

int OS::execute(const String &p_path, const Vector<String> &p_arguments, Array r_output, bool p_read_stderr, bool p_open_console) {
Expand Down Expand Up @@ -593,7 +593,7 @@ bool OS::is_debug_build() const {
}

String OS::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
return ::OS::get_singleton()->get_system_dir(::OS::SystemDir(p_dir), p_shared_storage);
return ::OS::get_singleton()->get_system_dir(p_dir, p_shared_storage);
}

String OS::get_keycode_string(Key p_code) const {
Expand Down Expand Up @@ -917,7 +917,7 @@ TypedArray<PackedVector2Array> Geometry2D::intersect_polyline_with_polygon(const
}

TypedArray<PackedVector2Array> Geometry2D::offset_polygon(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) {
Vector<Vector<Point2>> polys = ::Geometry2D::offset_polygon(p_polygon, p_delta, ::Geometry2D::PolyJoinType(p_join_type));
Vector<Vector<Point2>> polys = ::Geometry2D::offset_polygon(p_polygon, p_delta, p_join_type);

TypedArray<PackedVector2Array> ret;

Expand All @@ -928,7 +928,7 @@ TypedArray<PackedVector2Array> Geometry2D::offset_polygon(const Vector<Vector2>
}

TypedArray<PackedVector2Array> Geometry2D::offset_polyline(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
Vector<Vector<Point2>> polys = ::Geometry2D::offset_polyline(p_polygon, p_delta, ::Geometry2D::PolyJoinType(p_join_type), ::Geometry2D::PolyEndType(p_end_type));
Vector<Vector<Point2>> polys = ::Geometry2D::offset_polyline(p_polygon, p_delta, p_join_type, p_end_type);

TypedArray<PackedVector2Array> ret;

Expand Down Expand Up @@ -1373,7 +1373,7 @@ Error Thread::start(const Callable &p_callable, Priority p_priority) {
Ref<Thread> *ud = memnew(Ref<Thread>(this));

::Thread::Settings s;
s.priority = (::Thread::Priority)p_priority;
s.priority = p_priority;
thread.start(_start_func, ud, s);

return OK;
Expand Down Expand Up @@ -1482,8 +1482,7 @@ Variant ClassDB::instantiate(const StringName &p_class) const {
}

ClassDB::APIType ClassDB::class_get_api_type(const StringName &p_class) const {
::ClassDB::APIType api_type = ::ClassDB::get_api_type(p_class);
return (APIType)api_type;
return ::ClassDB::get_api_type(p_class);
}

bool ClassDB::class_has_signal(const StringName &p_class, const StringName &p_signal) const {
Expand Down
97 changes: 23 additions & 74 deletions core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "core/debugger/engine_profiler.h"
#include "core/io/resource_loader.h"
#include "core/io/resource_saver.h"
#include "core/math/geometry_2d.h"
#include "core/os/semaphore.h"
#include "core/os/thread.h"
#include "core/templates/safe_refcount.h"
Expand All @@ -52,20 +53,10 @@ class ResourceLoader : public Object {
static ResourceLoader *singleton;

public:
enum ThreadLoadStatus {
THREAD_LOAD_INVALID_RESOURCE,
THREAD_LOAD_IN_PROGRESS,
THREAD_LOAD_FAILED,
THREAD_LOAD_LOADED
};

enum CacheMode {
CACHE_MODE_IGNORE,
CACHE_MODE_REUSE,
CACHE_MODE_REPLACE,
CACHE_MODE_IGNORE_DEEP,
CACHE_MODE_REPLACE_DEEP,
};
using enum ::ResourceLoader::ThreadLoadStatus;
using ThreadLoadStatus = ::ResourceLoader::ThreadLoadStatus;
using enum ResourceFormatLoader::CacheMode;
using CacheMode = ResourceFormatLoader::CacheMode;

static ResourceLoader *get_singleton() { return singleton; }

Expand Down Expand Up @@ -97,16 +88,8 @@ class ResourceSaver : public Object {
static ResourceSaver *singleton;

public:
enum SaverFlags {
FLAG_NONE = 0,
FLAG_RELATIVE_PATHS = 1,
FLAG_BUNDLE_RESOURCES = 2,
FLAG_CHANGE_PATH = 4,
FLAG_OMIT_EDITOR_PROPERTIES = 8,
FLAG_SAVE_BIG_ENDIAN = 16,
FLAG_COMPRESS = 32,
FLAG_REPLACE_SUBRESOURCE_PATHS = 64,
};
using enum ::ResourceSaver::SaverFlags;
using SaverFlags = ::ResourceSaver::SaverFlags;

static ResourceSaver *get_singleton() { return singleton; }

Expand Down Expand Up @@ -144,17 +127,14 @@ class OS : public Object {
RENDERING_DRIVER_METAL,
};

using enum ::OS::SystemDir;
using SystemDir = ::OS::SystemDir;
using enum ::OS::StdHandleType;
using StdHandleType = ::OS::StdHandleType;

PackedByteArray get_entropy(int p_bytes);
String get_system_ca_certificates();

enum StdHandleType {
STD_HANDLE_INVALID,
STD_HANDLE_CONSOLE,
STD_HANDLE_FILE,
STD_HANDLE_PIPE,
STD_HANDLE_UNKNOWN,
};

virtual PackedStringArray get_connected_midi_inputs();
virtual void open_midi_inputs();
virtual void close_midi_inputs();
Expand Down Expand Up @@ -243,17 +223,6 @@ class OS : public Object {
int get_processor_count() const;
String get_processor_name() const;

enum SystemDir {
SYSTEM_DIR_DESKTOP,
SYSTEM_DIR_DCIM,
SYSTEM_DIR_DOCUMENTS,
SYSTEM_DIR_DOWNLOADS,
SYSTEM_DIR_MOVIES,
SYSTEM_DIR_MUSIC,
SYSTEM_DIR_PICTURES,
SYSTEM_DIR_RINGTONES,
};

String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const;

Error move_to_trash(const String &p_path) const;
Expand Down Expand Up @@ -289,6 +258,13 @@ class Geometry2D : public Object {
static void _bind_methods();

public:
using enum ::Geometry2D::PolyBooleanOperation;
using PolyBooleanOperation = ::Geometry2D::PolyBooleanOperation;
using enum ::Geometry2D::PolyJoinType;
using PolyJoinType = ::Geometry2D::PolyJoinType;
using enum ::Geometry2D::PolyEndType;
using PolyEndType = ::Geometry2D::PolyEndType;

static Geometry2D *get_singleton();
Variant segment_intersects_segment(const Vector2 &p_from_a, const Vector2 &p_to_a, const Vector2 &p_from_b, const Vector2 &p_to_b);
Variant line_intersects_line(const Vector2 &p_from_a, const Vector2 &p_dir_a, const Vector2 &p_from_b, const Vector2 &p_dir_b);
Expand All @@ -307,12 +283,6 @@ class Geometry2D : public Object {
Vector<Point2> convex_hull(const Vector<Point2> &p_points);
TypedArray<PackedVector2Array> decompose_polygon_in_convex(const Vector<Vector2> &p_polygon);

enum PolyBooleanOperation {
OPERATION_UNION,
OPERATION_DIFFERENCE,
OPERATION_INTERSECTION,
OPERATION_XOR
};
// 2D polygon boolean operations.
TypedArray<PackedVector2Array> merge_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // Union (add).
TypedArray<PackedVector2Array> clip_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // Difference (subtract).
Expand All @@ -324,18 +294,6 @@ class Geometry2D : public Object {
TypedArray<PackedVector2Array> intersect_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon); // Chop.

// 2D offset polygons/polylines.
enum PolyJoinType {
JOIN_SQUARE,
JOIN_ROUND,
JOIN_MITER
};
enum PolyEndType {
END_POLYGON,
END_JOINED,
END_BUTT,
END_SQUARE,
END_ROUND
};
TypedArray<PackedVector2Array> offset_polygon(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type = JOIN_SQUARE);
TypedArray<PackedVector2Array> offset_polyline(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type = JOIN_SQUARE, PolyEndType p_end_type = END_SQUARE);

Expand Down Expand Up @@ -442,12 +400,8 @@ class Thread : public RefCounted {
static void _start_func(void *ud);

public:
enum Priority {
PRIORITY_LOW,
PRIORITY_NORMAL,
PRIORITY_HIGH,
PRIORITY_MAX
};
using enum ::Thread::Priority;
using Priority = ::Thread::Priority;

Error start(const Callable &p_callable, Priority p_priority = PRIORITY_NORMAL);
String get_id() const;
Expand All @@ -467,13 +421,8 @@ class ClassDB : public Object {
static void _bind_methods();

public:
enum APIType {
API_CORE,
API_EDITOR,
API_EXTENSION,
API_EDITOR_EXTENSION,
API_NONE,
};
using enum ::ClassDB::APIType;
using APIType = ::ClassDB::APIType;

PackedStringArray get_class_list() const;
PackedStringArray get_inheriters_from_class(const StringName &p_class) const;
Expand Down
2 changes: 0 additions & 2 deletions core/io/resource_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ class ResourceFormatLoader : public RefCounted {
virtual ~ResourceFormatLoader() {}
};

VARIANT_ENUM_CAST(ResourceFormatLoader::CacheMode)

typedef void (*ResourceLoadErrorNotify)(const String &p_text);
typedef void (*DependencyErrorNotify)(const String &p_loading, const String &p_which, const String &p_type);

Expand Down
6 changes: 4 additions & 2 deletions core/os/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class Thread {
enum Priority {
PRIORITY_LOW,
PRIORITY_NORMAL,
PRIORITY_HIGH
PRIORITY_HIGH,
PRIORITY_MAX,
};

struct Settings {
Expand Down Expand Up @@ -166,7 +167,8 @@ class Thread {
enum Priority {
PRIORITY_LOW,
PRIORITY_NORMAL,
PRIORITY_HIGH
PRIORITY_HIGH,
PRIORITY_MAX,
};

struct Settings {
Expand Down

0 comments on commit 0dfea2c

Please sign in to comment.