• ### Announcements

#### Archived

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

# [java] i don't understand java

## Recommended Posts

yo. my game is shitty and i don''t know why. the thing is that i don''t get how java works. it runs good on some systems, and terrible on some systems. sometimes it''s jerky as hell, sometimes not. on some computers there is a giant lag sometimes (gc perhaps?). obviously i''m doing something wrong (threads, graphics, everything?) if someone has a few mins over and will have a look at my code, i''d appreciate it. since it''s too much to post here, download the source at http://mill.3dfxsweden.net/temp/src.rar for a playable version, http://mill.3dfxsweden.net/games/race

##### Share on other sites
Worked pretty well for me. I averaged around 50fps on a dual p2 333 gf2mx. A couple times, I don''t know if it is gc or something else, I got a second or so long pause and everything went to hell the second time it happened and the applet froze.

The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran

Opere Citato

##### Share on other sites
Seems to run perfectly on the PC i''m at. PII-400 with 256 MB ram, and a crappy ATI graphics card(rage 64).

##### Share on other sites
thanks for trying it out. i''ve had a fair amount of testers, just nobody seems to be unemployed (read gots lots of free time to review the code) :/

i''m glad it went smoothly on yer systems. i got a tip about the gc at javagaming.org. they said i didn''t give the gc enough time to run, so instead it runs less frequently but to compensate it runs longer. i need to make it run more frequently by limiting the fps and by letting the threads sleep.

for the lazy ones, most of you that is, i''ll post pseudo code or atleast just post the most crucial code, how''s that? i''ll do that tomoz (or later tonight if i can''t sleep).

##### Share on other sites
thanks for trying it out. i''ve had a fair amount of testers, just nobody seems to be unemployed (read gots lots of free time to review the code) :/

i''m glad it went smoothly on yer systems. i got a tip about the gc at javagaming.org. they said i didn''t give the gc enough time to run, so instead it runs less frequently but to compensate it runs longer. i need to make it run more frequently by limiting the fps and by letting the threads sleep.

for the lazy ones, most of you that is, i''ll post pseudo code or atleast just post the most crucial code, how''s that? i''ll do that tomoz (or later tonight if i can''t sleep).

##### Share on other sites
It runs _mainly_ ok on my computer.
Time to time there comes a "lag" bursts, when car(s) jump to another position.

I have had very similar problems in my own (Threaded)applets, which have been done exactly right, so it''s not bad coding necessary.

btw. my computer: AMD 1200@1350, Voodoo3, 256mb.

##### Share on other sites
I think it might be less jerky if you increase the sleepTime to 50. Don''t quote me on that, though.

##### Share on other sites
i've been fiddling a little with high-res timers and some other stuff and here it works a little better now.

http://mill.3dfxsweden.net/games/race/index.html

note that it's a bit slow right now, just need to increase a few parameters. that's not important right now. i'd like to know if those who thought it performed badly think it's better know.

got lots to improve though. thank's in advance.

Edited by - mill-o on February 20, 2002 4:48:54 PM

Edited by - mill-o on February 20, 2002 4:50:06 PM

##### Share on other sites
I don''t know what you did but it wasn''t good. I got 0.6fps before IE6 crashed. It was going nuts on my harddrive. I don''t know how you managed that since I had 80megs of physical left.

The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran

Opere Citato

##### Share on other sites
basically all i''ve done is to use a high res timer and a little less temp variables and stuff like that.

it''s disturbing that it''s WORSE than before. those who had a louse 15 fps on a cel600 now get 35 fps (i''ve limited the fps to 35 and sleep more so that the gc gets happy).

i even tried it on an old sun ultra sparc 1 (167 Mhz, 128 Mb ram, creator gfx card) and i got ~18 fps.

about 300 people have tested it and only a few say something. thought i''d get a little more feedback :/

GKW: what OS and what vm are you using? 0,6 fps is really shitty so i must be doing something wrong

(yah i know, people keep telling me to NOT rotate sprites in real-time, but disabling that on my system have NO effect at all. i''ll change that when i get time)

##### Share on other sites
I am running w2ksp2 with 1.4.0. I tried it again this morning and it basically ran for a second and then totally stopped and crashed IE6 when I tried to close the window. I had a 140 megs of free physical memory this morn prior to starting hte applet, I am curious why it messes with the harddrive so much.

The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran

Opere Citato

##### Share on other sites
It seems to work a lot better for me, actually. It sticks around 35 FPS, which seems a bit slow considering my system, but it certainly doesn''t snap as much as it used to. And about the number of people testing vs. the number that have given ya feedback, that''s probably a pretty standard thing (to have lots of people look, but only a few spend the time to tell you what they thought).

Ya know, garbage collection is simultaneously the best and worst feature in Java. I''ve written applets before that work perfectly with the Microsoft VM, but for some reason leak memory like a mofo with any other VM (I never could even find the reason... it was a very small applet -- like 4 files, and yet it hemmoraged). It''s just one of those things that makes Java fun (ha).

-pirate_dau

##### Share on other sites
yay! replies! not lots, but two are far better than none.

GKW: hmm that''s odd. i have no clue why it''s acting the way it is. i''m working slowly towards converting my applet to 1.1 which is kinda hard. hmm i wonder if i can just copy the classes that are missing in 1.1 and include those in the same folder as the applet? hmm could be a copyright issue. better look it up.

pirate_dau: yah, it''s limited to 35 fps, otherwise the gc won''t have time to collect garbage.

##### Share on other sites
quote:
hmm i wonder if i can just copy the classes that are missing in 1.1 and include those in the same folder as the applet? hmm could be a copyright issue. better look it up.

Yes, I'm pretty sure the Sun license forbids messing with the jars.

Edited by - HenryApe on February 21, 2002 2:43:24 PM

##### Share on other sites
ack, froze up in both the browser (netscape with 1.4 plugin) and appletviewer

just noticed the error messages. there's about a billion RasterFormatExceptions from Track.update line 54. also a NullPointer in Race.run line 81 and Interrupted at SleepTimer.run line 53. might help a bit.

oh wait, those last 2 are probably from when i killed the applet...

Edited by - buh on February 21, 2002 3:47:53 PM

Edited by - buh on February 21, 2002 3:48:55 PM

##### Share on other sites
buh: the update in Track looks like this:

  protected void update(Graphics g) { for (int i = 0; i < cars.length; i++) { int x = (int) cars[i].getPrevX(); int y = (int) cars[i].getPrevY(); g.drawImage(buffImage.getSubimage(x-2, y-2, 34, 34), x-2, y-2, applet); } for (int i = 0; i < skidMarks.size(); i++) ((SkidMark) skidMarks.get(i)).draw(g);}

i use BufferedImage and getSubimage to get the parts of the background that needs to be redrawn since they are "dirty". dunno why, but they are probably responsible for all the RasterFormat-thingies. this is perhaps a bad approach. i have another idea which is basically like this:
1. divide the background into several tiles.
2. when a car is moving, mark the covered tiles to be dirty. (1-4 tiles at the most per car).
3. redraw the dirty tiles.

should work better and faster in general, i think.

about the nullpointer. yah, i''m aware of that. forgot to fix that. thanks for pointing it out.

##### Share on other sites
Have you tried using volatile image for the background and using the GraphicsConfiguration image creation facilities? In a 800 by 450 screen with a couple moving 128^2 blended sprites I get almost 300fps at full bore. I can even fit in incremental garbage collection entirely in between frames if I drop the rate to 70fps or so. That is almost 10 times better than anything I ever did with just images or buffered images. Literally I am getting almost 10 times the framerate.

The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran

Opere Citato

##### Share on other sites
nope. this is an applet and i intend on dowgrading to 1.1.

would love to see those features in an applet though

##### Share on other sites
hey mill-o,

I haven''t looked at your code, but i can guess that it is the same problem that I had while making an applet game: telling the threads to sleep might not work, and you might have to enforce stricter timing.

My game run''s fine on my computer, but on others, especially laptops, is reeeeally jerky. I realized that threads in java dont'' always run in equal times, so this is what you might need to do:

It''s an article from the Hands-On Interactive Game Tutorial on this very forum, and I found it to fix my problems.

http://www.gamedev.net/community/forums/topic.asp?topic_id=49739

note that instead of getTime() or getTickCount(), it''s System.getCurrentTimeMillis() (if i remember)

And if this is not something that is causing your game to lock up... sorry! don''t know what it could be... i''ll download your code though to check it out

riz

##### Share on other sites
Ya, tiling the track should give it a boost.

Just a thought: maybe if you just drew the grey part of the track instead of the whole image it might be fast enough so you don''t have to bother with dirty rectangles. I don''t know,though.

btw, did you draw the rtack yourself? It''s pretty cool

##### Share on other sites
hey, thanks for the replies. actually i''ve done tons of changes (got lots of help on "another" forum).

like motion blur, locked fps, using setClip instead, no object creation in game loop, uses look-up tables everywhere, pre-rotated the images, upgraded to 1.4 instead of downgrading to 1.1 (1.1 is really old and who use, lets say, dx3 nowadays?? i made my point) and lots of other minor changes.

i''ll check out that link right away

i''ll keep you updated.

##### Share on other sites
haven''t tried it yet because it uses Java 1.4 and I only have 1.3 runtime so i have to download jdk or jre 1.4

No, HTML is not an OO language.

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627665
• Total Posts
2978523

• 10
• 10
• 12
• 22
• 13