• Advertisement

Archived

This topic is now archived and is closed to further replies.

[java] Java 1.4 and games

This topic is 5752 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I'm about to begin making a small 2D game in Java using SDK 1.4. I've made a small game earlier (applet based), but using SDK 1.1. I was wondering if anyone could give some hints and tips about useful features of 1.3/1.4 that could be useful for games. I've noticed there are quite a few Image-like classes, though I don't know which ones to use. Also, is there a high-resolution timer in 1.4 or do I have to use the "timer thread" solution to get decent timer resolution in Win9x environments? Any suggestions are very welcome! [edited by - Kanzetsu on April 18, 2002 12:07:23 PM]

Share this post


Link to post
Share on other sites
Advertisement
Hi,

if you intend to do some precise synchronization, forget about M$ Windows 9x.

I found out myself that calling System.currentTimeMillis() on the Windows98SE platform yields numbers usually rounded to the nearest 10 ms! And that ruined my attempts to use a nice planning algorithm.

On the other hand Linux (RedHat 7.1, kernel 2.4.2-2) returns numbers in the scale of 1 ms.

So even if you would call for example Thread.sleep(1) (and run the program on Win9x) IMHO you can''t measure HOW MUCH TIME EXACTLY passed since (and correct the synchronization if needed).

hope it helped ...

P.S.: If you should find out something really important, be sure to post it here (or even e-mail me )

have a nice day

Share this post


Link to post
Share on other sites
The timer thread solution works quite well. I was one who wrote the code that was later incoperated into game frame 4 java. In 1.3 and 1.4 you have the option of using BufferedImages, part of the Java2d library. This get back the speed lost in 1.2 when MemoryImageSource was depreciated as the main way of doing custom images. BufferedImages picks up and add so much more in terms of flexability and access. Using display native BufferedImages ( created with createCompatibleImage ) are lightnig fast for blitting and you can access them by as arrays ( if you look into the API it''s there ).

1.4 adds fullscreen access and volitale images too, but the most important addition in 1.4 is buffer strategys for v-sync page flipping. Unfortunatly sun still did not see clear to put an accurate standard timing method into 1.4 ( for win9x ).

Share this post


Link to post
Share on other sites
If you for some reason are using Java3D, Java3D 1.3 contains a high resolution timer (> 1 ms on Win98).

Share this post


Link to post
Share on other sites
Thanks for all the info! I''m going to look into it.

Snowmoon, the timer thread code I''m using is actually based somewhat on yours, thanks for that one, works pretty well. Even under Win9x it is pretty accurate, the frame rate is only off by 1-2 FPS when locked at 40 FPS.

A question though: How does BufferedImage compare to VolatileImage?

// Kanzetsu

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
My Java teacher (supposedly he knows what he''s talking about) says a lot of the timer issues also reside in the way PCs use the System Timer. The system timer only updates every 20th of a second. Java on the other hand, works with milliseconds (1000th of a second). This could be incorrect, but it''s what I''ve been told/taught.

Share this post


Link to post
Share on other sites
The PC timer is very accurate and does not update every 20th of a second. It does by default but that can be set within the system. My question is this: Is there any way to change this in Java?

I''ve used C++ for years and I''m new to Java. I''d like to get into Java game programming but (although it''s a great language) I feel like there is 10 feet of cotton between me and the computer when I''m programming in it =(

- Jay

Get Tranced!

Share this post


Link to post
Share on other sites
Actually... Java under DOS aka Win9x reads the BIOS timer through the windows API. Unfortunatly sun chose consistancy over accuracy and hedaches I believe. Java can still run on win95 that had no great and universal way of getting a super hi-rez timer. 486''s and most non-intel chips did not contain performance counters at the time. Pentiums and win98 improved access to hi resolution timers through a more consistant multimedia API. The DOS timer runs at 18.5 ticks/second just as it has since the 8088, this unfortunatly leads to a granularity of ~54ms.

There are ways around this and there are hi-resolution timers on all platforms that Java works on. Sun should invest the time to correct this problem or they should have had a system property from the start that detailed the granualrity of the current timing system.

Share this post


Link to post
Share on other sites
Regarding hi resolution timers and 1.1.

The best thing to do is set up a low priority thread that sleeps the tick time you need and use that to increment a counter.

That way to can get past the 50ms Win barrier!

Hope that helps.... :-)

Share this post


Link to post
Share on other sites
if you are not concerned by using native code within your
java application, check
http://www.gaffer.org/ptc/distributions/Java/
using this in conjunction with "open PTC for windows" you will have access to the win32 high-precision timer with a resolution
of around 8*10^-3 ms.

when using pure java (1.3), what helps me was using a _high_-priority timer thread doing a sleep for 1ms. this always gave me a resolution of at least near 1ms, which is enough for most
issues.

Share this post


Link to post
Share on other sites

  • Advertisement