Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Collision map

Thread view: 
Francois Lionet - 07 Apr 2007 11:06 GMT
Hello,

For the game I am writing, I need to handle a collision map. This collision
map is a simple array of bits representing an image, a bit set indicating
that there is a collision for this pixel. I am wondering on how to implement
this... I need to be able to scroll this array to follow the scrolling of
the game, to poke a shape into it, and retreive every pixel individually.
The size of this array can be quite big, bigger than the screen.
Should I do it by hand : reserve an array of bytes, and poke the shapes
myself, and do the collision detection. I fear that the scrolling would be
very slow, and that the overall performance would be bad. Is there a utility
class to shift the data in an array by an offset?
Should I use a BufferedImage of BINARY type? This would be really easy for
poking the shapes into it, and scrolling would be fast. But to get the data,
I would have to use the raster class, and the only way of getting the data
is to copy them into an array of Int (or float/double even worse), with one
int per pixel! Imagine the size of the array, and the time needed to copy
the data. Do you know if there is a way of getting the data in the raster
without copying them in an array?

What do you think? Do you think that the by hand method would be fast
enough? Do you know any method of getting access to the raster data without
copy?

Thanks, Francois
Robert Klemme - 07 Apr 2007 13:31 GMT
> For the game I am writing, I need to handle a collision map. This collision
> map is a simple array of bits representing an image, a bit set indicating
[quoted text clipped - 17 lines]
> enough? Do you know any method of getting access to the raster data without
> copy?

Did you look at BitSet?  I am not sure how that does for all the
operations you want, peeking and manipulating bits is certainly pretty
fast.  And maybe you can do the scrolling by calculating offsets to indexes.

Kind regards

    robert
Patricia Shanahan - 07 Apr 2007 13:42 GMT
> Hello,
>
[quoted text clipped - 8 lines]
> very slow, and that the overall performance would be bad. Is there a utility
> class to shift the data in an array by an offset?

Is there any way you can use a base index, so that instead of shifting
data in the array you shift where you are looking? Can you pick a
maximum size during initialization?

If so, you could use an array as a circular buffer, and just adjust the
current base. You could wrap it in a class of your own that automates
mapping from the logical index to the actual index.

Consider using a java.util.BitSet as a circular buffer. It is very space
efficient, packing bits into a long[], 64 bits per element. The size in
bytes would be one eighth of the number of pixels. It already has
methods for setting and clearing blocks of consecutive bits that might
be useful when adding a shape.

If you do end up having to shift the data, rather than adjust the index,
look at System.arraycopy.

Patricia


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.