Skip to content

Commit dca7a2e

Browse files
author
GsLogiMaker
committed
Refactor error macros
1 parent c7473ab commit dca7a2e

File tree

2 files changed

+23
-28
lines changed

2 files changed

+23
-28
lines changed

cpp/src/utils.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
#include "utils.h"
33
#include "godot_cpp/core/defs.hpp"
4-
#include "godot_cpp/variant/utility_functions.hpp"
54
#include "godot_cpp/variant/variant.hpp"
65
#include "world.h"
76

cpp/src/utils.h

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,35 @@
88
#include <flecs.h>
99
#include <godot_cpp/variant/utility_functions.hpp>
1010

11-
#define ERR(return_value, ...) \
12-
UtilityFunctions::printerr(__VA_ARGS__); \
13-
UtilityFunctions::push_error(__VA_ARGS__); \
11+
#define WARN(...) \
12+
UtilityFunctions::print_rich("[color='INDIAN_RED']GLECS: ", __VA_ARGS__); \
13+
UtilityFunctions::push_error(__VA_ARGS__);
14+
#define ERR(return_value, ...) \
15+
WARN(__VA_ARGS__); \
1416
return return_value;
1517

16-
#define CHECK_ENTITY_ALIVE(entity, gf_world, return_value, ...) \
17-
if (!gf_world->is_id_alive(entity)) { \
18-
ERR(return_value, \
19-
__VA_ARGS__, \
20-
" ID ", entity, " is not alive" \
21-
); \
18+
#define CHECK_ENTITY_ALIVE(entity, gf_world, return_value, ...) \
19+
if (!gf_world->is_id_alive(entity)) { \
20+
ERR(return_value, \
21+
__VA_ARGS__, \
22+
" ID ", entity, " is not alive" \
23+
); \
2224
}
2325

24-
#define CHECK_NOT_HAS_CHILD(entity, child_name, gf_world, return_value, err) \
25-
if (gf_world->id_has_child(entity, child_name)) { \
26-
ERR(return_value, \
27-
err, \
28-
" ", gf_world->id_to_text(entity) ," already has a child named \"", child_name, "\"" \
29-
); \
26+
#define CHECK_NOT_HAS_CHILD(entity, child_name, gf_world, return_value, err) \
27+
if (gf_world->id_has_child(entity, child_name)) { \
28+
ERR(return_value, \
29+
err, \
30+
" ", gf_world->id_to_text(entity) ," already has a child named \"", child_name, "\"" \
31+
); \
3032
}
3133

32-
#define CHECK_NOT_PAIR(entity, gf_world, return_value, ...) \
33-
if (!gf_world->is_id_alive(entity)) { \
34-
ERR(return_value, \
35-
__VA_ARGS__, \
36-
" Entity ", gf_world->id_to_text(entity), " is a pair" \
37-
); \
34+
#define CHECK_NOT_PAIR(entity, gf_world, return_value, ...) \
35+
if (!gf_world->is_id_alive(entity)) { \
36+
ERR(return_value, \
37+
__VA_ARGS__, \
38+
" Entity ", gf_world->id_to_text(entity), " is a pair" \
39+
); \
3840
}
3941

4042
template <typename T, typename E>
@@ -86,12 +88,6 @@ class Result {
8688
};
8789
};
8890

89-
#define CHECK_VARIANT(VALUE, VARIANT_TYPE) \
90-
if (value.get_type() != VARIANT_TYPE) { ERR(/**/, \
91-
"Expected variant value, ", VALUE, ", to be of type ", \
92-
Variant::get_type_name(VARIANT_TYPE), \
93-
", but is of type ", Variant::get_type_name(VALUE.get_type()) \
94-
); } \
9591

9692
namespace godot {
9793
typedef Result<ecs_entity_t, String> EntityResult;

0 commit comments

Comments
 (0)