[CF-Devel] traps stacking order
crossfire-devel at archives.real-time.com
crossfire-devel at archives.real-time.com
Sun May 16 00:02:42 CDT 2004
Preston Crow wrote:
>
I just noticed that if there's a chest with a bunch of traps in a random
>
map and you leave the map and come back, the order of the traps is
>
reversed.
>
>
It probably doesn't matter, but it's possible that it's a symptom of a
>
bug with more serious consequences that haven't been noticed yet.
>
This is a long standing 'feature'. You'd actually notice it with your
inventory, except that the client sorts the inventory.
This could actually be fixed pretty easily, but at some performance loss.
Basically, when the game saves a map/player/whatever, it saves the objects in
order, eg, first object in inventory is saved, then the next one, then the next
one, etc.
However, when it comes to loading them back in, instead of processing the list
of objects and adding it to the end, it adds it to the head of the list. This
is much more simple, as it is just a simple tmp->next = op->inv; op->inv=tmp
(there is a bit more to it, but basically that is it). To add to the tail end,
it would have to find the last object in the op->inv, and then put it in.
This gets quite costly if there are lots of objects in the inventory (it's an
O(n^2) operation vs O(1)).
The more efficient way to do it would actually be to load them as above, and
then reverse them after they are all loaded, as that would only be an O(n)
operation.
You'd actually see the same thing with objects stored in a container on the
ground. Eg, if you have a chest in your apartment, you may notice the order
changes each time the map goes through a load/save operation.
_______________________________________________
crossfire-devel mailing list
crossfire-devel at lists.real-time.com
https://mailman.real-time.com/mailman/listinfo/crossfire-devel
More information about the crossfire
mailing list