mas-bandwidth / netcode

Secure client/server connections over UDP
BSD 3-Clause "New" or "Revised" License
2.43k stars 191 forks source link

Add address map for better client index looking up #120

Closed kienhg96 closed 10 months ago

gafferongames commented 10 months ago

Some warnings need to be fixed, see above.

gafferongames commented 10 months ago

First issue. The map returns 0 if the client index isn't found, but client index of 0 is a valid index.

Please change that to return -1 if client index is found

gafferongames commented 10 months ago

Please change

define NETCODE_ADDRESS_MAP_BUCKETS 256

To be some function of the max clients, because as the max clients increases for the server, you will need more buckets.

(Maybe it should just be #define NETCODE_ADDRESS_MAP_BUCKETS NETCODE_MAX_CLIENTS? Then the size is n^2 on max clients... which is fine, and it handles worst case)

gafferongames commented 10 months ago

Please add a unit test for the map

kienhg96 commented 10 months ago

Ok, I'll check them

kienhg96 commented 10 months ago

I fixed the issues above, please have a check

kienhg96 commented 10 months ago

I have added the create and destroy functions using allocator. I think you should wrap the allocator_context, allocate_function and free_function to a new struct called allocator. It could be much more convenient.

gafferongames commented 10 months ago

Merged. Thanks!