14-01-2007, 06:04 AM
Why not just store the highest index of the array, and resize the array appropriately when needed? Every new character/npc/object/etc, you loop through the array checking for an unused slot, and if there is none, just redim preserve the array + 1 in size and update the last index value. Only time you'd ever loop through unused indexes is if entries not at the end of the array was removed, and nothing was added to fill in the gaps inside the array.
Shouldn't really even be too big of a problem, though, for the most part. Users you only have to update every X ticks to change their statuses (spells running out, hp/mp raising). The rest is event-based from the packets. For NPCs, you can loop through them, see if the map they are on has anyone on it first, then do the AI, which unless the AI is complex, should be quick and easy. For objects, you only have to update every minute or so to remove them if they have been on the ground too long and thats it - you don't even have to check that every loop.
Shouldn't really even be too big of a problem, though, for the most part. Users you only have to update every X ticks to change their statuses (spells running out, hp/mp raising). The rest is event-based from the packets. For NPCs, you can loop through them, see if the map they are on has anyone on it first, then do the AI, which unless the AI is complex, should be quick and easy. For objects, you only have to update every minute or so to remove them if they have been on the ground too long and thats it - you don't even have to check that every loop.