Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (541)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (604)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  threading troubles  (Read 872 times)
0 Members and 1 Guest are viewing this topic.
Offline bitshit

Junior Devvie




Java games rock!!


« Posted 2004-12-06 07:58:03 »

Hi all!

Im expiriencing some thread related problems with an applet game Im writing...

I have 3 threads running: the game thread itself, a keepalive thread that posts a message to the server each x seconds and an sound thread that pulls my musicplayer for sampledata frequently.

I found out that the applet's paint seems to get called by the browser, in certain situations the browser seems to call the applet's repaint in some sort of loop. This caused my sound thread to get too little priority which caused sound stutter. I was able do disable the browser repaints by setting: setIgnoreRepaint(true).

But I had to modify my run method too. Using the sleep() function halved my framerate, thread.yield() resulted in good fps but somehow i loose control after x secs and the whole applet goes beserk. When I call Thread.join(1) it seems to work ok, but I think thats not the proper way of doing this. I thought that join(1) waits 1 ms to kill the thread which doesn't seems to be what i want. Also on slower systems the game thread seems to pause very shortly when I play an audioclip.

How should I implement the thread.yield() properly? It somehow just looses control after a variable period of time...

Thanks!

Thijs
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2004-12-06 18:42:17 »

Can you describe what you mena by "loses control"?
Exaclty what happens?

Typically in any multi-threaded code, if a sleep 'fixes' your problem then it means you have a race condition somewhere...

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline bitshit

Junior Devvie




Java games rock!!


« Reply #2 - Posted 2004-12-07 17:54:52 »

I have one sound thread which constantly pulls my music player for sample data and feeds it to the javasound driver. The other thread is the game itself which basicly calls a repaint() followed by a thread.join(1) but which should be a thread.yield i think.

When using thread.yield() :
The game plays ok for about 30 seconds, after that just goes beserk; does not respond to input and it will stutter (sound & graphics). If i press fx the left key, it will respond with a lag of x seconds and seems to kep excecuting that...

When I use thread.join(1) it works ok, but im sure thats not the right way of doing what i want.

a sleep(>20) obviously halfs the framerate but works ok too...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Malohkan

Senior Devvie




while (true) System.out.println("WOO!!!!");


« Reply #3 - Posted 2004-12-08 14:31:32 »

I think we're gonna need to see some of your code to get an idea of why that's happening.  I personally can't think of a reason that your game should be blowing up on you like that.  Show some code and hopefully we can help you track down the problem.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (13 views)
2014-12-27 04:03:04

TheDudeFromCI (17 views)
2014-12-27 02:14:49

Mr.CodeIt (25 views)
2014-12-23 03:34:11

rwatson462 (56 views)
2014-12-15 09:26:44

Mr.CodeIt (46 views)
2014-12-14 19:50:38

BurntPizza (92 views)
2014-12-09 22:41:13

BurntPizza (113 views)
2014-12-08 04:46:31

JscottyBieshaar (86 views)
2014-12-05 12:39:02

SHC (96 views)
2014-12-03 16:27:13

CopyableCougar4 (102 views)
2014-11-29 21:32:03
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!