Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework floating point compression #23

Merged
merged 0 commits into from
May 20, 2021
Merged

Rework floating point compression #23

merged 0 commits into from
May 20, 2021

Conversation

Shatur
Copy link

@Shatur Shatur commented May 17, 2021

This PR implements real numbers compression according to IEEE 754 floating point representation. Some corner cases not covered here (like INF, NAN) and will be added soon.

Note: I changed the type from real_t to double, because the code will not work correctly with the REAL_T_IS_DOUBLE define.

Copy link
Owner

@AndreaCatania AndreaCatania left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing job, really, this is just the correct way of doing it! Thanks!

modules/network_synchronizer/data_buffer.cpp Outdated Show resolved Hide resolved
Copy link
Owner

@AndreaCatania AndreaCatania left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! It's looking really great, just some minor things to address.

@@ -90,8 +90,6 @@ void BitArray::store_bits(int p_bit_offset, uint64_t p_value, int p_bits) {

val >>= bits_to_write;
}

CRASH_COND_MSG(val != 0, "This is a bug, please open an issue");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this been removed for mistake?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry :)

Copy link
Author

@Shatur Shatur May 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, no, I forgot that this causes issues when I sending signed values. I would have to manually zero out the unnecessary bits. I thought that the check could be removed, since we have already covered everything with tests. Let me know If I should put it back.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's fine, you right. The test are much better than this check.

if (p_compression_level == DataBuffer::COMPRESSION_LEVEL_0) {
p_compression_level = DataBuffer::COMPRESSION_LEVEL_1;
}
#endif
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't put this fallback directly inside the float compressor function? I think it would make more sense anyway.

Also, I think we need to add a warning here, so the user knows that doesn't make sense use compression 0 when it's using a single precision binary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because add_real does not depend on this definition. It accepts doubles. But Vector2 and Vector3 use real_t as underlying type.

You will have an incredible amount of warnings because this function gets called very often.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but it doesn't make senses anyway compress a single precision to double to convert it back to single precision.

The warning would tell the user how to properly use the api, and it would spam only when the api is not properly used. Which make sense. What do you think?

Copy link
Author

@Shatur Shatur May 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but it doesn't make senses anyway compress a single precision to double to convert it back to single precision.

It depends on what type is used. If double is used, and not real_t, then there will be no narrowing conversion.
GDScript documentation says that 64-bit floats are used and only some types have (such as Vector2) uses real_t.

The warning would tell the user how to properly use the api, and it would spam only when the api is not properly used. Which make sense. What do you think?

Hm... Okay, I will add a warning!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here too.

Copy link
Owner

@AndreaCatania AndreaCatania left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just few typos

@@ -90,8 +90,6 @@ void BitArray::store_bits(int p_bit_offset, uint64_t p_value, int p_bits) {

val >>= bits_to_write;
}

CRASH_COND_MSG(val != 0, "This is a bug, please open an issue");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's fine, you right. The test are much better than this check.

modules/network_synchronizer/data_buffer.cpp Outdated Show resolved Hide resolved
modules/network_synchronizer/data_buffer.cpp Outdated Show resolved Hide resolved
if (p_compression_level == DataBuffer::COMPRESSION_LEVEL_0) {
p_compression_level = DataBuffer::COMPRESSION_LEVEL_1;
}
#endif
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here too.

modules/network_synchronizer/data_buffer.cpp Outdated Show resolved Hide resolved
Copy link
Owner

@AndreaCatania AndreaCatania left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thanks a lot!!

@AndreaCatania AndreaCatania merged this pull request into AndreaCatania:player_proto May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants