Skip to content

Commit 4593454

Browse files
committed
Fixed some other bugs and exposed the logger log_level.
1 parent cc87e5e commit 4593454

9 files changed

Lines changed: 43 additions & 101 deletions

core/core.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,14 @@ const char *get_process_phase_name(ProcessPhase pp) {
3131
}
3232

3333
std::string get_log_level_txt(NS::PrintMessageType p_level) {
34-
std::string log_level_str = "[INFO] ";
35-
if (NS::PrintMessageType::WARNING & p_level) {
34+
std::string log_level_str = "";
35+
if (NS::PrintMessageType::INFO == p_level) {
36+
log_level_str = "[INFO] ";
37+
} else if (NS::PrintMessageType::WARNING == p_level) {
3638
log_level_str = "[WARNING] ";
37-
}
38-
39-
if (NS::PrintMessageType::ERROR & p_level) {
39+
} else if (NS::PrintMessageType::ERROR == p_level) {
4040
log_level_str = "[ERROR] ";
41-
}
42-
43-
if (NS::PrintMessageType::__INTERNAL & p_level) {
41+
} else if (NS::PrintMessageType::__INTERNAL == p_level) {
4442
log_level_str = "";
4543
}
4644
return log_level_str;

core/core.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ const char *get_process_phase_name(ProcessPhase pp);
7171
NS_NAMESPACE_BEGIN
7272

7373
enum PrintMessageType : std::uint8_t {
74-
INFO = 0,
75-
WARNING = 1 << 0,
76-
ERROR = 1 << 1,
77-
__INTERNAL = 1 << 2,
74+
__INTERNAL = 0,
75+
INFO = 1,
76+
WARNING = 2,
77+
ERROR = 3,
7878
};
7979

8080
std::string get_log_level_txt(NS::PrintMessageType p_level);

godot4/gd_scene_synchronizer.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,16 @@ void GdSceneSynchronizer::on_init_synchronizer(bool p_was_generating_ids) {
276276
debugger_mode = "nonet";
277277
}
278278
SceneSynchronizerDebugger::singleton()->setup_debugger(debugger_mode, 0, get_tree());
279+
280+
// Setup the debugger log level.
281+
const int log_level = GLOBAL_GET("NetworkSynchronizer/log_level");
282+
if (log_level == 0) {
283+
SceneSynchronizerDebugger::singleton()->set_log_level(NS::INFO);
284+
} else if (log_level == 1) {
285+
SceneSynchronizerDebugger::singleton()->set_log_level(NS::WARNING);
286+
} else {
287+
SceneSynchronizerDebugger::singleton()->set_log_level(NS::ERROR);
288+
}
279289
}
280290

281291
void GdSceneSynchronizer::on_uninit_synchronizer() {
@@ -316,7 +326,7 @@ void GdSceneSynchronizer::update_objects_relevancy() {
316326
if (GDVIRTUAL_IS_OVERRIDDEN(_update_nodes_relevancy)) {
317327
const bool executed = GDVIRTUAL_CALL(_update_nodes_relevancy);
318328
if (executed == false) {
319-
NET_DEBUG_ERR("The function _update_nodes_relevancy failed!");
329+
SceneSynchronizerDebugger::singleton()->print(NS::ERROR, "The function _update_nodes_relevancy failed!");
320330
}
321331
}
322332
}
@@ -602,7 +612,7 @@ void GdSceneSynchronizer::setup_trickled_sync(Node *p_node, const Callable &p_co
602612
a.push_back(p_update_rate);
603613
p_collect_epoch_func.callv(a);
604614
},
605-
[p_apply_epoch_func](float delta, float alpha, DataBuffer &db_from, DataBuffer &db_to) -> void {
615+
[p_apply_epoch_func](double delta, float alpha, DataBuffer &db_from, DataBuffer &db_to) -> void {
606616
Array a;
607617
a.push_back(delta);
608618
a.push_back(alpha);

input_network_encoder.cpp

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

33
#include "modules/network_synchronizer/godot4/gd_network_interface.h"
44
#include "modules/network_synchronizer/godot4/gd_scene_synchronizer.h"
5+
#include "modules/network_synchronizer/scene_synchronizer_debugger.h"
56
#include "scene_synchronizer.h"
67

78
void InputNetworkEncoder::_bind_methods() {
@@ -90,7 +91,7 @@ void InputNetworkEncoder::encode(const LocalVector<Variant> &p_input, DataBuffer
9091

9192
#ifdef DEBUG_ENABLED
9293
if (i < p_input.size() && info.default_value.get_type() != p_input[i].get_type() && p_input[i].get_type() != Variant::NIL) {
93-
NET_DEBUG_ERR("During the input encoding the passed value `" + p_input[i].stringify() + "` has a different type to the expected one. Using the default value `" + info.default_value.stringify() + "`.");
94+
SceneSynchronizerDebugger::singleton()->print(NS::ERROR, "During the input encoding the passed value `" + std::string(p_input[i].stringify().utf8()) + "` has a different type to the expected one. Using the default value `" + std::string(info.default_value.stringify().utf8()) + "`.");
9495
}
9596
#endif
9697

net_utilities.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,6 @@
4545

4646
#endif
4747

48-
#ifdef DEBUG_ENABLED
49-
#define NET_DEBUG_PRINT(msg) \
50-
if (ProjectSettings::get_singleton()->get_setting("NetworkSynchronizer/log_debug_warnings_and_messages")) \
51-
print_line(String("[Net] ") + msg)
52-
#define NET_DEBUG_WARN(msg) \
53-
if (ProjectSettings::get_singleton()->get_setting("NetworkSynchronizer/log_debug_warnings_and_messages")) \
54-
WARN_PRINT(String("[Net] ") + msg)
55-
#define NET_DEBUG_ERR(msg) \
56-
ERR_PRINT(String("[Net] ") + msg)
57-
#else
58-
#define NET_DEBUG_PRINT(msg)
59-
#define NET_DEBUG_WARN(msg)
60-
#define NET_DEBUG_ERR(msg)
61-
#endif
62-
6348
NS_NAMESPACE_BEGIN
6449

6550
namespace MapFunc {

register_types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void initialize_network_synchronizer_module(ModuleInitializationLevel p_level) {
8080

8181
GLOBAL_DEF("NetworkSynchronizer/debug_server_speedup", false);
8282
GLOBAL_DEF("NetworkSynchronizer/log_debug_rewindings", false);
83-
GLOBAL_DEF("NetworkSynchronizer/log_debug_warnings_and_messages", true);
83+
GLOBAL_DEF("NetworkSynchronizer/log_level", 3);
8484
GLOBAL_DEF("NetworkSynchronizer/log_debug_nodes_relevancy_update", false);
8585
GLOBAL_DEF("NetworkSynchronizer/debugger/dump_enabled", false);
8686
GLOBAL_DEF("NetworkSynchronizer/debugger/dump_classes", Array());

scene_synchronizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,7 +2555,7 @@ void ClientSynchronizer::process_received_server_state() {
25552555
return;
25562556
}
25572557

2558-
ENSURE_MSG(player_controller, "There is no player controller and the only allowed snapshot are the one with `FrameIndex` set to NONE. The current one is set to " + last_received_server_snapshot->input_id + " so it's ignored.");
2558+
ENSURE_MSG(player_controller && player_controller->can_simulate(), "There is no player controller and the only allowed snapshot are the one with `FrameIndex` set to NONE. The current one is set to " + last_received_server_snapshot->input_id + " so it's ignored.");
25592559

25602560
PlayerController *inner_player_controller = player_controller->get_player_controller();
25612561

@@ -3423,7 +3423,7 @@ bool ClientSynchronizer::parse_snapshot(DataBuffer &p_snapshot) {
34233423
// Parse InputID:
34243424
[](void *p_user_pointer, FrameIndex p_input_id) {
34253425
ParseData *pd = static_cast<ParseData *>(p_user_pointer);
3426-
if (pd->player_controller != nullptr) {
3426+
if (pd->player_controller != nullptr && pd->player_controller->can_simulate()) {
34273427
// This is the main controller, store the `InputID`.
34283428
pd->snapshot.input_id = p_input_id;
34293429
}

scene_synchronizer_debugger.cpp

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,4 @@
1-
/*************************************************************************/
2-
/* scene_synchronizer_debugger.cpp */
3-
/*************************************************************************/
4-
/* This file is part of: */
5-
/* GODOT ENGINE */
6-
/* https://godotengine.org */
7-
/*************************************************************************/
8-
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
9-
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
10-
/* */
11-
/* Permission is hereby granted, free of charge, to any person obtaining */
12-
/* a copy of this software and associated documentation files (the */
13-
/* "Software"), to deal in the Software without restriction, including */
14-
/* without limitation the rights to use, copy, modify, merge, publish, */
15-
/* distribute, sublicense, and/or sell copies of the Software, and to */
16-
/* permit persons to whom the Software is furnished to do so, subject to */
17-
/* the following conditions: */
18-
/* */
19-
/* The above copyright notice and this permission notice shall be */
20-
/* included in all copies or substantial portions of the Software. */
21-
/* */
22-
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23-
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24-
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25-
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26-
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27-
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28-
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29-
/*************************************************************************/
30-
311
#include "scene_synchronizer_debugger.h"
32-
#include "modules/network_synchronizer/core/core.h"
33-
#include "modules/network_synchronizer/scene_synchronizer_debugger.h"
342

353
#ifdef DEBUG_ENABLED
364

@@ -86,6 +54,14 @@ SceneSynchronizerDebugger::~SceneSynchronizerDebugger() {
8654
#endif
8755
}
8856

57+
void SceneSynchronizerDebugger::set_log_level(NS::PrintMessageType p_log_level) {
58+
log_level = p_log_level;
59+
}
60+
61+
NS::PrintMessageType SceneSynchronizerDebugger::get_log_level() const {
62+
return log_level;
63+
}
64+
8965
void SceneSynchronizerDebugger::set_dump_enabled(bool p_dump_enabled) {
9066
#ifdef DEBUG_ENABLED
9167
dump_enabled = p_dump_enabled;
@@ -606,7 +582,7 @@ void SceneSynchronizerDebugger::debug_print(NS::NetworkInterface *p_network_inte
606582
#ifdef DEBUG_ENABLED
607583
print(
608584
NS::PrintMessageType::INFO,
609-
p_message.utf8().ptr(),
585+
std::string(p_message.utf8()),
610586
p_network_interface ? p_network_interface->get_owner_name() : "GLOBAL");
611587
#endif
612588
}
@@ -615,7 +591,7 @@ void SceneSynchronizerDebugger::debug_warning(NS::NetworkInterface *p_network_in
615591
#ifdef DEBUG_ENABLED
616592
print(
617593
NS::PrintMessageType::WARNING,
618-
p_message.utf8().ptr(),
594+
std::string(p_message.utf8()),
619595
p_network_interface ? p_network_interface->get_owner_name() : "GLOBAL");
620596
#endif
621597
}
@@ -633,13 +609,13 @@ void SceneSynchronizerDebugger::print(NS::PrintMessageType p_level, const std::s
633609

634610
const std::string log_level_str = NS::get_log_level_txt(p_level);
635611

636-
if ((log_level & p_level) || p_force_print_to_log) {
612+
if ((log_level <= p_level) || p_force_print_to_log) {
637613
NS::SceneSynchronizerBase::__print_line(log_level_str + "[" + p_object_name + "] " + p_message);
638614
}
639615

640616
__add_message(log_level_str + p_message, p_object_name);
641617
#else
642-
if ((log_level & p_level) || p_force_print_to_log) {
618+
if ((log_level <= p_level) || p_force_print_to_log) {
643619
const std::string log_level_str = NS::get_log_level_txt(p_level);
644620
NS::SceneSynchronizerBase::print_line(log_level_str + "[" + p_object_name + "] " + p_message);
645621
}

scene_synchronizer_debugger.h

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,5 @@
1-
/*************************************************************************/
2-
/* scene_synchronizer_debugger.h */
3-
/*************************************************************************/
4-
/* This file is part of: */
5-
/* GODOT ENGINE */
6-
/* https://godotengine.org */
7-
/*************************************************************************/
8-
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
9-
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
10-
/* */
11-
/* Permission is hereby granted, free of charge, to any person obtaining */
12-
/* a copy of this software and associated documentation files (the */
13-
/* "Software"), to deal in the Software without restriction, including */
14-
/* without limitation the rights to use, copy, modify, merge, publish, */
15-
/* distribute, sublicense, and/or sell copies of the Software, and to */
16-
/* permit persons to whom the Software is furnished to do so, subject to */
17-
/* the following conditions: */
18-
/* */
19-
/* The above copyright notice and this permission notice shall be */
20-
/* included in all copies or substantial portions of the Software. */
21-
/* */
22-
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23-
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24-
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25-
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26-
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27-
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28-
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29-
/*************************************************************************/
30-
311
#pragma once
322

33-
#include "modules/network_synchronizer/core/core.h"
343
#include "scene/main/node.h"
354

365
#ifdef DEBUG_ENABLED
@@ -85,9 +54,9 @@ class SceneSynchronizerDebugger : public Node {
8554
static void _bind_methods();
8655

8756
private:
88-
#ifdef DEBUG_ENABLED
8957
NS::PrintMessageType log_level = NS::PrintMessageType::ERROR;
9058

59+
#ifdef DEBUG_ENABLED
9160
bool dump_enabled = false;
9261
LocalVector<StringName> dump_classes;
9362
bool setup_done = false;
@@ -139,6 +108,9 @@ class SceneSynchronizerDebugger : public Node {
139108
SceneSynchronizerDebugger();
140109
~SceneSynchronizerDebugger();
141110

111+
void set_log_level(NS::PrintMessageType p_log_level);
112+
NS::PrintMessageType get_log_level() const;
113+
142114
void set_dump_enabled(bool p_dump_enabled);
143115
bool get_dump_enabled() const;
144116

0 commit comments

Comments
 (0)