Skip to content

Commit 65ba52d

Browse files
committed
Use float and double directly. Fixes 107
1 parent ecebe65 commit 65ba52d

10 files changed

Lines changed: 62 additions & 62 deletions

data_buffer.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ double DataBuffer::read_real(CompressionLevel p_compression_level) {
619619
return value;
620620
}
621621

622-
real_t DataBuffer::add_positive_unit_real(real_t p_input, CompressionLevel p_compression_level) {
622+
float DataBuffer::add_positive_unit_real(float p_input, CompressionLevel p_compression_level) {
623623
#ifdef DEBUG_ENABLED
624624
ERR_FAIL_COND_V_MSG(p_input < 0 || p_input > 1, p_input, "Value must be between zero and one.");
625625
#endif
@@ -642,12 +642,12 @@ real_t DataBuffer::add_positive_unit_real(real_t p_input, CompressionLevel p_com
642642
CRASH_COND((metadata_size + bit_size) > buffer.size_in_bits() && bit_offset > buffer.size_in_bits());
643643
#endif
644644

645-
const real_t value = decompress_unit_float(compressed_val, max_value);
645+
const float value = decompress_unit_float(compressed_val, max_value);
646646
DEB_WRITE(DATA_TYPE_POSITIVE_UNIT_REAL, p_compression_level, rtos(value).utf8());
647647
return value;
648648
}
649649

650-
real_t DataBuffer::read_positive_unit_real(CompressionLevel p_compression_level) {
650+
float DataBuffer::read_positive_unit_real(CompressionLevel p_compression_level) {
651651
ERR_FAIL_COND_V(is_reading == false, 0.0);
652652

653653
const int bits = get_bit_taken(DATA_TYPE_POSITIVE_UNIT_REAL, p_compression_level);
@@ -661,17 +661,17 @@ real_t DataBuffer::read_positive_unit_real(CompressionLevel p_compression_level)
661661
}
662662
bit_offset += bits;
663663

664-
const real_t value = decompress_unit_float(compressed_val, max_value);
664+
const float value = decompress_unit_float(compressed_val, max_value);
665665

666666
DEB_READ(DATA_TYPE_POSITIVE_UNIT_REAL, p_compression_level, rtos(value).utf8());
667667

668668
return value;
669669
}
670670

671-
real_t DataBuffer::add_unit_real(real_t p_input, CompressionLevel p_compression_level) {
671+
float DataBuffer::add_unit_real(float p_input, CompressionLevel p_compression_level) {
672672
ERR_FAIL_COND_V(is_reading == true, p_input);
673673

674-
const real_t added_real = add_positive_unit_real(ABS(p_input), p_compression_level);
674+
const float added_real = add_positive_unit_real(ABS(p_input), p_compression_level);
675675

676676
const int bits_for_sign = 1;
677677
const uint32_t is_negative = p_input < 0.0;
@@ -686,16 +686,16 @@ real_t DataBuffer::add_unit_real(real_t p_input, CompressionLevel p_compression_
686686
CRASH_COND((metadata_size + bit_size) > buffer.size_in_bits() && bit_offset > buffer.size_in_bits());
687687
#endif
688688

689-
const real_t value = is_negative ? -added_real : added_real;
689+
const float value = is_negative ? -added_real : added_real;
690690
DEB_WRITE(DATA_TYPE_UNIT_REAL, p_compression_level, rtos(value).utf8());
691691

692692
return value;
693693
}
694694

695-
real_t DataBuffer::read_unit_real(CompressionLevel p_compression_level) {
695+
float DataBuffer::read_unit_real(CompressionLevel p_compression_level) {
696696
ERR_FAIL_COND_V(is_reading == false, 0.0);
697697

698-
const real_t value = read_positive_unit_real(p_compression_level);
698+
const float value = read_positive_unit_real(p_compression_level);
699699

700700
const int bits_for_sign = 1;
701701
std::uint64_t is_negative;
@@ -705,7 +705,7 @@ real_t DataBuffer::read_unit_real(CompressionLevel p_compression_level) {
705705
}
706706
bit_offset += bits_for_sign;
707707

708-
const real_t ret = is_negative != 0 ? -value : value;
708+
const float ret = is_negative != 0 ? -value : value;
709709

710710
DEB_READ(DATA_TYPE_UNIT_REAL, p_compression_level, rtos(ret).utf8());
711711

@@ -772,9 +772,9 @@ Vector2 DataBuffer::add_normalized_vector2(Vector2 p_input, CompressionLevel p_c
772772
}
773773
bit_offset += bits;
774774

775-
const real_t decompressed_angle = (decompress_unit_float(compressed_angle, max_value) * Math_TAU) - Math_PI;
776-
const real_t x = Math::cos(decompressed_angle);
777-
const real_t y = Math::sin(decompressed_angle);
775+
const double decompressed_angle = (decompress_unit_float(compressed_angle, max_value) * Math_TAU) - Math_PI;
776+
const double x = Math::cos(decompressed_angle);
777+
const double y = Math::sin(decompressed_angle);
778778

779779
#ifdef DEBUG_ENABLED
780780
// Can't never happen because the buffer size is correctly handled.
@@ -807,9 +807,9 @@ Vector2 DataBuffer::read_normalized_vector2(CompressionLevel p_compression_level
807807
}
808808
bit_offset += bits;
809809

810-
const real_t decompressed_angle = (decompress_unit_float(compressed_angle, max_value) * Math_TAU) - Math_PI;
811-
const real_t x = Math::cos(decompressed_angle);
812-
const real_t y = Math::sin(decompressed_angle);
810+
const double decompressed_angle = (decompress_unit_float(compressed_angle, max_value) * Math_TAU) - Math_PI;
811+
const double x = Math::cos(decompressed_angle);
812+
const double y = Math::sin(decompressed_angle);
813813

814814
const Vector2 value = Vector2(x, y) * static_cast<float>(is_not_zero);
815815

@@ -859,9 +859,9 @@ Vector3 DataBuffer::add_normalized_vector3(Vector3 p_input, CompressionLevel p_c
859859

860860
DEB_DISABLE
861861

862-
const real_t x_axis = add_unit_real(p_input.x, p_compression_level);
863-
const real_t y_axis = add_unit_real(p_input.y, p_compression_level);
864-
const real_t z_axis = add_unit_real(p_input.z, p_compression_level);
862+
const float x_axis = add_unit_real(p_input.x, p_compression_level);
863+
const float y_axis = add_unit_real(p_input.y, p_compression_level);
864+
const float z_axis = add_unit_real(p_input.z, p_compression_level);
865865

866866
DEB_ENABLE
867867

@@ -875,9 +875,9 @@ Vector3 DataBuffer::read_normalized_vector3(CompressionLevel p_compression_level
875875

876876
DEB_DISABLE
877877

878-
const real_t x_axis = read_unit_real(p_compression_level);
879-
const real_t y_axis = read_unit_real(p_compression_level);
880-
const real_t z_axis = read_unit_real(p_compression_level);
878+
const float x_axis = read_unit_real(p_compression_level);
879+
const float y_axis = read_unit_real(p_compression_level);
880+
const float z_axis = read_unit_real(p_compression_level);
881881

882882
DEB_ENABLE
883883

data_buffer.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class DataBuffer : public Object {
7575
///
7676
///
7777
/// ## Vector2
78-
/// COMPRESSION_LEVEL_0: 2 * 64 bits are used - Double precision (will fallback to level 1 if REAL_T_IS_DOUBLE is not defined)
78+
/// COMPRESSION_LEVEL_0: 2 * 64 bits are used - Double precision
7979
/// COMPRESSION_LEVEL_1: 2 * 32 bits are used - Single precision
8080
/// COMPRESSION_LEVEL_2: 2 * 16 bits are used - Half precision
8181
/// COMPRESSION_LEVEL_3: 2 * 8 bits are used - Minifloat
@@ -91,7 +91,7 @@ class DataBuffer : public Object {
9191
///
9292
///
9393
/// ## Vector3
94-
/// COMPRESSION_LEVEL_0: 3 * 64 bits are used - Double precision (will fallback to level 1 if REAL_T_IS_DOUBLE is not defined)
94+
/// COMPRESSION_LEVEL_0: 3 * 64 bits are used - Double precision
9595
/// COMPRESSION_LEVEL_1: 3 * 32 bits are used - Single precision
9696
/// COMPRESSION_LEVEL_2: 3 * 16 bits are used - Half precision
9797
/// COMPRESSION_LEVEL_3: 3 * 8 bits are used - Minifloat
@@ -244,21 +244,21 @@ class DataBuffer : public Object {
244244
///
245245
/// Returns the compressed value so both the client and the peers can use
246246
/// the same data.
247-
real_t add_positive_unit_real(real_t p_input, CompressionLevel p_compression_level);
247+
float add_positive_unit_real(float p_input, CompressionLevel p_compression_level);
248248

249249
/// Parse the following data as a positive unit real.
250-
real_t read_positive_unit_real(CompressionLevel p_compression_level);
250+
float read_positive_unit_real(CompressionLevel p_compression_level);
251251

252252
/// Add a unit real into the buffer.
253253
///
254254
/// **Note:** Not unitary values lead to unexpected behaviour.
255255
///
256256
/// Returns the compressed value so both the client and the peers can use
257257
/// the same data.
258-
real_t add_unit_real(real_t p_input, CompressionLevel p_compression_level);
258+
float add_unit_real(float p_input, CompressionLevel p_compression_level);
259259

260260
/// Parse the following data as an unit real.
261-
real_t read_unit_real(CompressionLevel p_compression_level);
261+
float read_unit_real(CompressionLevel p_compression_level);
262262

263263
/// Add a vector2 into the buffer.
264264
/// Note: This kind of vector occupies more space than the normalized verison.

input_network_encoder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ uint32_t InputNetworkEncoder::register_input(
1919
const Variant &p_default_value,
2020
DataBuffer::DataType p_type,
2121
DataBuffer::CompressionLevel p_compression_level,
22-
real_t p_comparison_floating_point_precision) {
22+
float p_comparison_floating_point_precision) {
2323
switch (p_type) {
2424
case DataBuffer::DATA_TYPE_BOOL:
2525
ERR_FAIL_COND_V_MSG(p_default_value.get_type() != Variant::BOOL, UINT32_MAX, "The moveset initialization failed for" + p_name + " the specified data type is `BOOL` but the default parameter is " + itos(p_default_value.get_type()));
@@ -225,18 +225,18 @@ void InputNetworkEncoder::reset_inputs_to_defaults(LocalVector<Variant> &r_input
225225
}
226226
}
227227

228-
bool compare(const Vector2 &p_first, const Vector2 &p_second, real_t p_tolerance) {
228+
bool compare(const Vector2 &p_first, const Vector2 &p_second, float p_tolerance) {
229229
return Math::is_equal_approx(p_first.x, p_second.x, p_tolerance) &&
230230
Math::is_equal_approx(p_first.y, p_second.y, p_tolerance);
231231
}
232232

233-
bool compare(const Vector3 &p_first, const Vector3 &p_second, real_t p_tolerance) {
233+
bool compare(const Vector3 &p_first, const Vector3 &p_second, float p_tolerance) {
234234
return Math::is_equal_approx(p_first.x, p_second.x, p_tolerance) &&
235235
Math::is_equal_approx(p_first.y, p_second.y, p_tolerance) &&
236236
Math::is_equal_approx(p_first.z, p_second.z, p_tolerance);
237237
}
238238

239-
bool compare(const Variant &p_first, const Variant &p_second, real_t p_tolerance) {
239+
bool compare(const Variant &p_first, const Variant &p_second, float p_tolerance) {
240240
if (p_first.get_type() != p_second.get_type()) {
241241
return false;
242242
}

input_network_encoder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct NetworkedInputInfo {
1111
uint32_t index;
1212
DataBuffer::DataType data_type;
1313
DataBuffer::CompressionLevel compression_level;
14-
real_t comparison_floating_point_precision;
14+
float comparison_floating_point_precision;
1515
};
1616

1717
class InputNetworkEncoder : public Resource {
@@ -32,7 +32,7 @@ class InputNetworkEncoder : public Resource {
3232
const Variant &p_default_value,
3333
DataBuffer::DataType p_type,
3434
DataBuffer::CompressionLevel p_compression_level,
35-
real_t p_comparison_floating_point_precision = CMP_EPSILON);
35+
float p_comparison_floating_point_precision = CMP_EPSILON);
3636

3737
uint32_t find_input_id(const StringName &p_name) const;
3838
const LocalVector<NetworkedInputInfo> &get_input_info() const;

net_utilities.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,13 @@ void NS::SyncGroup::notify_variable_changed(ObjectData *p_object_data, const std
240240
}
241241
}
242242

243-
void NS::SyncGroup::set_trickled_update_rate(NS::ObjectData *p_object_data, real_t p_update_rate) {
243+
void NS::SyncGroup::set_trickled_update_rate(NS::ObjectData *p_object_data, float p_update_rate) {
244244
const int index = trickled_sync_objects.find(p_object_data);
245245
ERR_FAIL_COND(index < 0);
246246
trickled_sync_objects[index].update_rate = p_update_rate;
247247
}
248248

249-
real_t NS::SyncGroup::get_trickled_update_rate(const NS::ObjectData *p_object_data) const {
249+
float NS::SyncGroup::get_trickled_update_rate(const NS::ObjectData *p_object_data) const {
250250
for (int i = 0; i < int(trickled_sync_objects.size()); ++i) {
251251
if (trickled_sync_objects[i].od == p_object_data) {
252252
return trickled_sync_objects[i].update_rate;

net_utilities.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ struct SyncGroup {
533533
public:
534534
uint64_t user_data = 0;
535535

536-
real_t state_notifier_timer = 0.0;
536+
float state_notifier_timer = 0.0;
537537

538538
public:
539539
bool is_realtime_node_list_changed() const;
@@ -560,8 +560,8 @@ struct SyncGroup {
560560
void notify_new_variable(struct ObjectData *p_object_data, const std::string &p_var_name);
561561
void notify_variable_changed(struct ObjectData *p_object_data, const std::string &p_var_name);
562562

563-
void set_trickled_update_rate(struct ObjectData *p_object_data, real_t p_update_rate);
564-
real_t get_trickled_update_rate(const struct ObjectData *p_object_data) const;
563+
void set_trickled_update_rate(struct ObjectData *p_object_data, float p_update_rate);
564+
float get_trickled_update_rate(const struct ObjectData *p_object_data) const;
565565

566566
void sort_trickled_node_by_update_priority();
567567

networked_controller.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ FrameIndex RemotelyControlledController::last_known_frame_index() const {
510510
}
511511
}
512512

513-
bool RemotelyControlledController::fetch_next_input(real_t p_delta) {
513+
bool RemotelyControlledController::fetch_next_input(double p_delta) {
514514
bool is_new_input = true;
515515

516516
if (unlikely(current_input_buffer_id == FrameIndex::NONE)) {
@@ -962,7 +962,7 @@ int AutonomousServerController::get_inputs_count() const {
962962
return 0;
963963
}
964964

965-
bool AutonomousServerController::fetch_next_input(real_t p_delta) {
965+
bool AutonomousServerController::fetch_next_input(double p_delta) {
966966
SceneSynchronizerDebugger::singleton()->debug_print(&node->get_network_interface(), "Autonomous server fetch input.", true);
967967

968968
node->get_inputs_buffer_mut().begin_write(METADATA_SIZE);
@@ -1396,7 +1396,7 @@ void DollController::queue_instant_process(FrameIndex p_frame_index, int p_index
13961396
return;
13971397
}
13981398

1399-
bool DollController::fetch_next_input(real_t p_delta) {
1399+
bool DollController::fetch_next_input(double p_delta) {
14001400
if (queued_instant_to_process >= 0) {
14011401
if (queued_instant_to_process >= int(snapshots.size())) {
14021402
return false;

networked_controller.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ struct RemotelyControlledController : public Controller {
306306
FrameIndex last_known_frame_index() const;
307307

308308
/// Fetch the next inputs, returns true if the input is new.
309-
virtual bool fetch_next_input(real_t p_delta);
309+
virtual bool fetch_next_input(double p_delta);
310310

311311
virtual void set_frame_input(const FrameSnapshot &p_frame_snapshot, bool p_first_input);
312312

@@ -349,7 +349,7 @@ struct AutonomousServerController final : public ServerController {
349349

350350
virtual bool receive_inputs(const Vector<uint8_t> &p_data) override;
351351
virtual int get_inputs_count() const override;
352-
virtual bool fetch_next_input(real_t p_delta) override;
352+
virtual bool fetch_next_input(double p_delta) override;
353353
};
354354

355355
struct PlayerController final : public Controller {
@@ -399,7 +399,7 @@ struct DollController final : public RemotelyControlledController {
399399

400400
virtual bool receive_inputs(const Vector<uint8_t> &p_data) override;
401401
virtual void queue_instant_process(FrameIndex p_input_id, int p_index, int p_count) override;
402-
virtual bool fetch_next_input(real_t p_delta) override;
402+
virtual bool fetch_next_input(double p_delta) override;
403403
virtual void process(double p_delta) override;
404404
virtual void on_state_validated(FrameIndex p_frame_index) override;
405405
void notify_frame_checked(FrameIndex p_input_id);

scene_synchronizer.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ float SceneSynchronizerBase::get_max_trickled_interpolation_alpha() const {
253253
return max_trickled_interpolation_alpha;
254254
}
255255

256-
void SceneSynchronizerBase::set_frame_confirmation_timespan(real_t p_interval) {
256+
void SceneSynchronizerBase::set_frame_confirmation_timespan(float p_interval) {
257257
frame_confirmation_timespan = p_interval;
258258
}
259259

@@ -269,11 +269,11 @@ float SceneSynchronizerBase::get_max_predicted_intervals() const {
269269
return max_predicted_intervals;
270270
}
271271

272-
void SceneSynchronizerBase::set_objects_relevancy_update_time(real_t p_time) {
272+
void SceneSynchronizerBase::set_objects_relevancy_update_time(float p_time) {
273273
objects_relevancy_update_time = p_time;
274274
}
275275

276-
real_t SceneSynchronizerBase::get_objects_relevancy_update_time() const {
276+
float SceneSynchronizerBase::get_objects_relevancy_update_time() const {
277277
return objects_relevancy_update_time;
278278
}
279279

@@ -729,25 +729,25 @@ const std::vector<int> *SceneSynchronizerBase::sync_group_get_listening_peers(Sy
729729
return static_cast<ServerSynchronizer *>(synchronizer)->sync_group_get_listening_peers(p_group_id);
730730
}
731731

732-
void SceneSynchronizerBase::sync_group_set_trickled_update_rate(ObjectLocalId p_node_id, SyncGroupId p_group_id, real_t p_update_rate) {
732+
void SceneSynchronizerBase::sync_group_set_trickled_update_rate(ObjectLocalId p_node_id, SyncGroupId p_group_id, float p_update_rate) {
733733
NS::ObjectData *od = get_object_data(p_node_id);
734734
ENSURE_MSG(is_server(), "This function CAN be used only on the server.");
735735
static_cast<ServerSynchronizer *>(synchronizer)->sync_group_set_trickled_update_rate(od, p_group_id, p_update_rate);
736736
}
737737

738-
void SceneSynchronizerBase::sync_group_set_trickled_update_rate(ObjectNetId p_node_id, SyncGroupId p_group_id, real_t p_update_rate) {
738+
void SceneSynchronizerBase::sync_group_set_trickled_update_rate(ObjectNetId p_node_id, SyncGroupId p_group_id, float p_update_rate) {
739739
NS::ObjectData *od = get_object_data(p_node_id);
740740
ENSURE_MSG(is_server(), "This function CAN be used only on the server.");
741741
static_cast<ServerSynchronizer *>(synchronizer)->sync_group_set_trickled_update_rate(od, p_group_id, p_update_rate);
742742
}
743743

744-
real_t SceneSynchronizerBase::sync_group_get_trickled_update_rate(ObjectLocalId p_id, SyncGroupId p_group_id) const {
744+
float SceneSynchronizerBase::sync_group_get_trickled_update_rate(ObjectLocalId p_id, SyncGroupId p_group_id) const {
745745
const NS::ObjectData *od = get_object_data(p_id);
746746
ENSURE_V_MSG(is_server(), 0.0, "This function CAN be used only on the server.");
747747
return static_cast<ServerSynchronizer *>(synchronizer)->sync_group_get_trickled_update_rate(od, p_group_id);
748748
}
749749

750-
real_t SceneSynchronizerBase::sync_group_get_trickled_update_rate(ObjectNetId p_id, SyncGroupId p_group_id) const {
750+
float SceneSynchronizerBase::sync_group_get_trickled_update_rate(ObjectNetId p_id, SyncGroupId p_group_id) const {
751751
const NS::ObjectData *od = get_object_data(p_id);
752752
ENSURE_V_MSG(is_server(), 0.0, "This function CAN be used only on the server.");
753753
return static_cast<ServerSynchronizer *>(synchronizer)->sync_group_get_trickled_update_rate(od, p_group_id);
@@ -1861,14 +1861,14 @@ void ServerSynchronizer::set_peer_networking_enable(int p_peer, bool p_enable) {
18611861
sync_group_update(p_peer);
18621862
}
18631863

1864-
void ServerSynchronizer::sync_group_set_trickled_update_rate(NS::ObjectData *p_object_data, SyncGroupId p_group_id, real_t p_update_rate) {
1864+
void ServerSynchronizer::sync_group_set_trickled_update_rate(NS::ObjectData *p_object_data, SyncGroupId p_group_id, float p_update_rate) {
18651865
ERR_FAIL_COND(p_object_data == nullptr);
18661866
ERR_FAIL_COND_MSG(p_group_id.id >= sync_groups.size(), "The group id `" + itos(p_group_id.id) + "` doesn't exist.");
18671867
ERR_FAIL_COND_MSG(p_group_id == SyncGroupId::GLOBAL, "You can't change this SyncGroup in any way. Create a new one.");
18681868
sync_groups[p_group_id.id].set_trickled_update_rate(p_object_data, p_update_rate);
18691869
}
18701870

1871-
real_t ServerSynchronizer::sync_group_get_trickled_update_rate(const NS::ObjectData *p_object_data, SyncGroupId p_group_id) const {
1871+
float ServerSynchronizer::sync_group_get_trickled_update_rate(const NS::ObjectData *p_object_data, SyncGroupId p_group_id) const {
18721872
ERR_FAIL_COND_V(p_object_data == nullptr, 0.0);
18731873
ERR_FAIL_COND_V_MSG(p_group_id.id >= sync_groups.size(), 0.0, "The group id `" + itos(p_group_id.id) + "` doesn't exist.");
18741874
ERR_FAIL_COND_V_MSG(p_group_id == SyncGroupId::GLOBAL, 0.0, "You can't change this SyncGroup in any way. Create a new one.");

0 commit comments

Comments
 (0)