42core-team / connection

GNU Affero General Public License v3.0
0 stars 0 forks source link

Persistent obj memory locations #67

Open FreddyMSchubert opened 1 week ago

FreddyMSchubert commented 1 week ago

Would make working with objects a lot easier. Theoretically, we should be able to just not free the objects each loop iteration & update them with the data from the server. Just gotta be careful to free the objects that didn't receive any updates (e.g. dead units)

FreddyMSchubert commented 6 days ago

If this works we can also do this: https://github.com/42core-team/connection/issues/62

PaulicStudios commented 5 days ago

A possible solution could be to add a boolean isalive to the objs and when the server does not return an id anymore it is set to death. Otherwise it just updates the values in the objs. For that we also have to change the getter functions to make it clear if they return dead units or not

FreddyMSchubert commented 5 days ago

That would be cool, we just have to keep track of all the dead objects seperately somewhere so we don't leak them.

We could even combine it with making the create unit function return an object immediately - it's just uninitialized. So, an isValid bool or hasData or isInGame or smth that is false and the right type & an id of 0.

So when we receive unit data, we first match based on id, and then try to find an element with a 0 id of the same type, which will be the one we previously returned. Since we'll need to have all the obj arrays be t_obj ** anyways as the t_objs will be all over memory and not all in sequence, we don't need to terminate them with a 0 id anymore and can just use NULL, so we can use the 0 id as an indicator here.

I believe that should work I'll try both of those things tomorrow.

Question is, would it be useful for users to differentiate between the uninitalized invalid state and the dead invalid state, in that case maybe we could use a UNINITIALIZED - ALIVE - DEAD enum or something.

If we pull this off these would be amazing improvements. Please tell me if I missed something.

FreddyMSchubert commented 5 days ago

I implemented all of the above. Ignoring the aggressive segfaulting before computing a single thing, it works in spirit.