On 9 mayo, 21:58,
numeronreac...@gmail.com wrote:
> Since Im using java, my threads synchronize by locking objects, so considering Im no longer using Tile objects, this makes things a bit challenging. In particular, java doesnt seem to provide any way to create an array of volatile bytes (note the SharedByteArray object is based on AtomicIntegerArray which uses an array of ints). I could synchronize the entire arrays as I use them, but I fear that would remove much of the benefit of using threads in the first place.
>
> Is there a good way to accomplish a tile lock in my new system or should I switch back to tile object per tile system? Due to some of the improvements not needing to be reverted, a quick calculation puts my new projected Tile object at 24 or 32 bytes (depending whether 32 or 64 bit system). Using SharedByteArrays takes up 24 bytes per tile anyway.
How about splitting the big map arrays into small zones? For example,
if your map size is 80x20, you could implement each map as an array of
16x4 zones, each zone holding 5x5 tiles. That way you don't have to
lock/sync the entire map, just the individual zones that changed. The
memory overhead would be one pointer per zone, most likely less than
if you used Tile objects.