edbeeching / godot_rl_agents

An Open Source package that allows video game creators, AI researchers and hobbyists the opportunity to learn complex behaviors for their Non Player Characters or agents
MIT License
942 stars 69 forks source link

Refactor godot_env.py #129

Closed Ivan-267 closed 10 months ago

Ivan-267 commented 1 year ago

As I'm not familiar with low level protocols, Python's handling of them, or the entire gdrl network code, please review this possible solution before potential merging for any issues or errors in understanding.

Here are some assumptions made based on looking at docs and the code: 1) Godot first sends the size of the string in 4 bytes 2) After we receive the size, we try to receive the entire data / string from Godot. 3) In case of recv taking too long or the entire string never being received, timeout will occur after specified interval.

Other changes: I've replaced the recursion with a while loop, in case the size also doesn't get received completely within the first recv, and the string concatenation with a bytearray, although there may be more optimal solutions for performance. The small time delay is also removed, but please let me know if should be returned.

Performance: After a short test (not a proper benchmark so it's not conclusive data), this did not improve a single string receive operation's time delay to some noticeable threshold with a single observation with a relatively large array and when setting the recv size to a small value so that it has to repeat multiple times.

Another change to consider is perhaps renaming the method to _get_string if the only purpose is to receive a string from Godot.