i don't know anything about sounds so how would i go about to stream a wav-file since apparently AudioClip.loop() loads the whole wav-file into memory. i use mp3s at the moment and convert them into wav-files at startup and they tend to get very big, say 40 mbs, and that's too much to keep in memory.

AudioClip is an old API and really shouldn't be used anymore. Look up the javax.sound API form info on streaming sound data. You can also take a look at the GAGESound source for an example of how to stream manually. GAGESound does stream from memory, but the basic concept is the same.

yeah i had a look at javax.sound.sampled but i didn't understand much of it. i kept looking for something like play() but found nothing. i haven't experimented though so it might be simpler than i think

the second was atleast about javax.sound.sampled but unfortunately "The next step is to read the entire file into memory". that's what i want to avoid.. i'll check out the GAGE-thing.. the gage-timer didn't work (or i did something wrong since the timer slowed down when in fullscreen -- odd behaviour)

The way I do it in GAGESound should be no different than how you'd do it to stream from disk. The only difference is that you'd read directly from the AudioInputStream and write it out to the SourceDataLine. Both of these are obtained via the AudioSystem object. Here's some psuedo-code for you. It won't compile (since this is a rough estimate pulled from memory), but it should give you an idea:

about the timer.. nevermind what i said. i figured out what was wrong!

i used to store the dt in a float and since the main loop was so fast the dt was set to 0 and not to 0.00000000000000000000000000000001 or whatever. since the dt was 0 most of the time, everything moved slowly! solution? use a double instead or multiply the dt with some constant. i'll give it a go right away!

btw, does the timer only work on win32? (i tried like ten timers that day so i didn't exercise it thoroughly)

It's hard to come up with a good buffer size. What I do with GAGESound is I keep filling the buffer with enough to play the length of the last rendering loop. This way, my sound lags about 1 or 2 frames behind.

The GAGETimer works on all OSes with a 1/1000 sec resolution. Windows is special because it has a resolution of either 10ms or 50ms without the DLL or better than 1/1000 sec with the DLL. If you're not sure if the DLL is getting loaded, check the console. It should throw a stack trace if it doesn't load.

I don't use any threads and only use the timer and use that to time motions. this results in 100% cpu usage and it seems like events like KeyPressed lags behind.

i looked at your example and you don't sleep at all. no AdvancedTimer.sleep(...) or Thread.sleep(...) at all.

If i use AdvancedTimer.sleep(...) i don't see any difference. If I use Thread.sleep(...) cpu usage goes down to like 1% and the fps goes down to around 50 from 450 which i had when i didn't use Thread.sleep(...). It doesn't matter if I sleep 1 ms or 10 ms, I always get 50 fps or below. I have no clue why your game runs just fine and mine lags behind. Loading images are also slowed down by two or three times.

Are you using Java2D? You shouldn't be able to get 450 fps using a bufferstrategy. The reason why my code doesn't need sleeps is that the strategy.show() line allows other threads to get some work done. If you're running flat out at 450 fps, other threads aren't getting any time. You should be able to fix this by using the AdvancedTimer sleep methods or a Thread.sleep() method. Can you tell me how you were using AdvancedTimer.sleep(...)? Usually, it's better to use AdvancedTimer.sleepUntil(...) like this:

The beautiful part about this algo is that it automatically catches up if the game falls behind.

Gergis, erikd had the right answer for you. Keep the DLL within the same directory you launch from and you should be fine. And his webstart example is correct as well. You can find more info on this in the Webstart developer docs.

Glad you've got it figured out mill. BTW, the AdvancedTimer code never actually sleeps. It just uses Thread.yield() to give up some time to other threads. This way, your rendering thread gets returned to quickly without bogging down other threads.

You said you had used AdvancedTimer.sleep() before and that it didn't help. Why I asked how you were using it was I figured you were probably doing something along the lines of:

timer.sleep(1);

This *won't work*. The timer runs so fast that the time will probably already have expired before the code even checks what time it is.

It's *supposed* to be impossible. That doesn't mean it is. :-) There have been bugs in the past where the VSync wouldn't happen and the game would run amok. My first revision of Duke Nukes Stuff had this problem. Apparently when I slept for a second or two while switching to full screen mode, the JDK would fail to acquire a VSync lock. Got 500 fps with good keyboard response. Pretty proud of myself, i was.

I think they've fixed that particular problem since then. Jeff? Do you know if that one was fixed?

*chuckle* I'm sorry. DNS was something I discussed on the old boards. Duke Nukes Stuff was a simple game I made out of everyone's favorite Java mascot, Duke! It was really just a technology test for the (then new) 1.4 gaming APIs.

*chuckle* I'm sorry. DNS was something I discussed on the old boards. Duke Nukes Stuff was a simple game I made out of everyone's favorite Java mascot, Duke! It was really just a technology test for the (then new) 1.4 gaming APIs.

The AdvancedTimer class isn't available in standard java library right? If I wanted my game to work at school (which has a typical installation of Java) I couldn't use it right? Is there any alternatives?

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org