English 中文(简体)
how to efficiently track the use of space on a map, both objects and free areas
原标题:

OK I start with a blank map, which is 512x512 = 262144 pixels/locations.

I need a way to efficiently draw some objects on it, and then be able to find the areas of free space, so that later more different objects can be added to these free areas. I cant figure out the best way to store this data, or algorithms to find the free areas.

I had a working solution, but it took forever to compute. I m working with AS3, in case that impacts what would be the best solution.

Any Advice? thanks.

最佳回答

There is plenty of methods to work with bitmaps at Bitmap and BitmapData classes.

I ve never done anything like that, but you could try. I believe the best approach is to draw the objects at the map. Then, use the method bitmapData.getColorBoundsRect() to get the areas that are not free. These AS3 native methods are very, very fast!

Here is the documentation: http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/BitmapData.html

Cheers, CaioToOn!

问题回答

Your problem is almost identical to the issue of memory allocation in operating systems - issues of fragmentation, cleanup, appropriate contiguous space usage all appear there as well. I d read on up how this problem is solved in OS s: start on Wikipedia.

The first thing that comes to mind is to use polygon-filling techniques. Consider your space as a set of scan lines, one scan line per Y coordinate. On each scan line, store a list of X coordinates representing transitions between free and occupied space.





相关问题
What to look for in performance analyzer in VS 2008

What to look for in performance analyzer in VS 2008 I am using VS Team system and got the performance wizard and reports going. What benchmarks/process do I use? There is a lot of stuff in the ...

SQL Table Size And Query Performance

We have a number of items coming in from a web service; each item containing an unknown number of properties. We are storing them in a database with the following Schema. Items - ItemID - ...

How to speed up Visual Studio 2008? Add more resources?

I m using Visual Studio 2008 (with the latest service pack) I also have ReSharper 4.5 installed. ReSharper Code analysis/ scan is turned off. OS: Windows 7 Enterprise Edition It takes me a long time ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

热门标签