Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (499)
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  
  Input lost...  (Read 2691 times)
0 Members and 1 Guest are viewing this topic.
Offline zaphod

Senior Newbie




Java Developer by day, Java Developer by ... hey


« Posted 2003-07-06 07:09:50 »

I've got a very basic framework going for developing my first 2d game, but when I push the performance of it (which is badly in need of tuning, but never mind that at this point) I lose all input signals - keypresses, mouse clicks, etc.  I'm guessing it's burning through so much CPU that it's just locking out all input.  Is there a way to raise the priority of my events, or do I need to have my Thread yield or something?

I'm running on 98 right now and when this happens I can't even Alt-Tab / CTRL-ALT-DEL out of the app...  I am forced to shut it down the old way...

Thanks for any advice.
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2003-07-06 08:00:21 »

Normally you need a Thread.yield() in your main thread to allow the AWT thread to get a chance to pickup input events.

I always wonder if its safer to use a Thread.sleep(1) or something since Thread.yield() doesn't perform the same on all platforms.

Kev

Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #2 - Posted 2003-07-06 14:24:47 »

wow!

atlast some1 else has encountered this problem!!

I believe it is a problem with the way Java is using DirectDraw and is a problem specific to Win98.

It only occurs when in fullscreen and when using a Page Flipping BufferStrategy.

I've got a theory as to the cause,

when bufferStrategy.show() is called, Java waits for a vsync.
While it is waiting for the vsync it the event scheduling Thread is prevented from interrupting it. (this is only logical afterall, if the event thread could interrupt it you would miss the vsync often, which would result in massive loss of FPS)

Ofcourse, the Event Thread should interrupt your render loop while it is executing, so the events should still get serviced.

However, if your render loop executes very quickly, it is likely that the scheduler would never get a chance to interrupt. Hence the Event scheduler would end up never getting any processor time.

I don't know if this theory is correct; all i can say is that it fits the facts Shocked

If I am correct, then the following code on Win98 should result in the experienced behaviour.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
setFullscreenWindow(this);
createBufferStrategy(2);
BufferStrategy bs = getBufferStrategy();
while(true)
{
   //Graphics g = bs.getDrawGraphics();
  //g.dispose();
  //^^ these calls maybe needed for the problem to surface
  bs.show();
}

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zaphod

Senior Newbie




Java Developer by day, Java Developer by ... hey


« Reply #3 - Posted 2003-07-06 16:32:41 »

Thanks for the input folks!  I think I figured out what the problem was.  The Thread.yield() was not properly yielding to the AWT input.  By ensuring that there was at least 1ms sleep between each draw cycle I am getting my input again!

On a side note, I have determined that it is inherently unsafe to System.exit(-1) when in full screen mode, at least in 98.  While that may be obvious, it is definitely true.

Thanks again all.
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #4 - Posted 2003-07-06 16:44:01 »

Quote

On a side note, I have determined that it is inherently unsafe to System.exit(-1) when in full screen mode, at least in 98.  While that may be obvious, it is definitely true.

Thanks again all.


indeed,

always call dispose() on fullscreen frames.

The AWT Thread should always die naturally once you've disposed of all awt windows.

(there are however a few exceptions to that rule, if you ever create a Dialog/JDialog using the no parent constructor, it very kindly creates a hidden Frame which is impossible to dispose of <_<)

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2003-07-06 16:48:08 »

I think the Thread.yield() vs Thread.sleep(1) thing is to do with the two types of threading (can't remember the naming right now, is it pre-emptive and co-operative?).

One type supports yield(), it varies on different platforms (including evidently Win98 -> WinXP). Seems like the only safe way is to use Thread.sleep(1).

Kev

Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #6 - Posted 2003-07-06 18:52:46 »

If u use Thread.sleep(1) on win98,
your gonna be waiting for 55ms,
limiting your framerate to a pathetic 19fps  Roll Eyes

What we realy need is poll-able input so we can get rid of all the task switching.
(will JInput ever make its way into the core api?)

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline tortoise

Junior Member




<3 Shmups


« Reply #7 - Posted 2003-07-08 13:41:40 »

I thought the 55ms restriction didn't apply to Thread.sleep()?

One thing I did, slightly different, was change my main thread priorty to MAX_PRIORITY, and in all flavors of Windows it just completey shut out all other threads, denying any input (where as on Linux it game me a little 3-4fps boost with no adverse side effects). Once I turned that off my input thread under windows was just fine.
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #8 - Posted 2003-07-08 16:40:50 »

Quote
I thought the 55ms restriction didn't apply to Thread.sleep()?


oops, silly me.

w00t, my 300th post!

YAY, im a 'senior member'  Grin

Now wheres my pension Cool

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Jeff

JGO Coder




Got any cats?


« Reply #9 - Posted 2003-07-08 17:23:22 »

Ofcourse you can detour around the AWT input loop entirely by using JInput. Or LWJGL's input.

* This message brought to you by the project manager of the JInput project *


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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SpuTTer

Senior Member


Medals: 1


Lazy Middle Class Intellectual


« Reply #10 - Posted 2003-07-09 06:06:07 »

speaking of... is there any example source available for jinput? I found the compiled examples in the mind2machine build, but no source. Is that planned in the official build release?

Sorry if this might be construed as a tad off topic if the poster isnt considering jinput.

Sacramento Volleyball
"Whitty phrase goes here."
Archimedes
Guest
« Reply #11 - Posted 2003-07-09 12:27:29 »

Quote
Ofcourse you can detour around the AWT input loop entirely by using JInput. Or LWJGL's input.

* This message brought to you by the project manager of the JInput project *

Hello Jeff. That sounds good. Also it answers one half of my questions posted in thread "2SE input or jinput ?" ( http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=3D;action=display;num=1057740698 )
:-)

However, like Abuse put it: "(will JInput ever make its way into the core api?) "
Same applies to Jogl and Joal.

To deploy an Java application with Jogl you already need to provide Jogl-Jars and Jogl-Win-Dlls/Linux-Libs/Maclibs/Sparc-Libs/etc. (Javawebstart is not an option for so many projects.)

Now Jinput?
Next Joal?
What then...?
:-)

It's even hard to convince a team / producer of a game to go with Java, let alone when you've to tell them: oh well we need to ship a dozen DLLs more.

I see the inclusion of Jogl and other game-core extensions into the J2SE as an very important point.
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #12 - Posted 2003-07-09 16:50:23 »

Quote
will JInput ever make its way into the core api?


If it works, does it really matter?  The wrappers are going to be small anyway.  The only significant drawback is that to use the native code via webstart or an applet it must be signed.

I think these technologies should be optional packages that can be installed through WebStart's  extension installer mechanism... official builds could be signed by Sun.

Shipping DLLs & libraries in a game is normal with native code.. so why would it be a drawback for Java?????????

Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #13 - Posted 2003-07-09 17:33:28 »

Quote
Shipping DLLs & libraries in a game is normal with native code.. so why would it be a drawback for Java?????????


platform independence?

Having to ship a game with DLL's/libraries for each potencial platform would be pretty lame IMO.

I don't know how the input events are captured in AWT, but I would have thought JInput could be slotted neatly in there somewhere?

Infact JOGL, JOAL and JInput could all be slotted underneath the existing APIs. Couldn't they?

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #14 - Posted 2003-07-09 17:49:35 »

You don't have to ship DLLs that aren't for the specific platform the user is downloading for (you could build separate installs, or if possible use WebStart).

If distributing on CD these things are tiny and then at install time you still wouldn't copy them to the user's hard drive.

There is nothing in AWT to get events for game devices (steering wheels, flight yokes, joysticks, game pads, force feedback controllers, etc...).  JInput addresses this.  Also AWT is based on an event model, not polling.  Much of the events come from the Windows message loop and equivalents on other platforms.

I heard that OpenGL might be used to accelerate graphics on Linux, much like Direct X is used on Windows.  It would be cool if that effort ended up pulling JOGL into the core.

Archimedes
Guest
« Reply #15 - Posted 2003-07-09 17:58:32 »

Quote


platform independence?

Having to ship a game with DLL's/libraries for each potencial platform would be pretty lame IMO.

I don't know how the input events are captured in AWT, but I would have thought JInput could be slotted neatly in there somewhere?

Infact JOGL, JOAL and JInput could all be slotted underneath the existing APIs. Couldn't they?

Very good points; I 100% agree. :-)

The main point of Java is platform independency. You take your JAR and it runs on any machine where a Java VM is installed - without Internet.

Well, of course the installation of the JVM has to be as simple as possible for the end user - and also it shouldn't be my task as Java application deployer.
Needless to say that the need for further DLLs/LIBs/etc for Jogl/Joal/Jinput/etc does complicate the whole process of deployment. If it's going to be too much then it's easier to compile with C++ a Win32 only application and ship it. But not willing to do so is a main reason for many Java programmers, isn't it?
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #16 - Posted 2003-07-09 18:13:42 »

Quote
Of course the installation of the JVM has to be as simple as possible for the end user - and also it shouldn't be my task as Java application deployer.
Needless to say that the need for further DLLs/LIBs/etc for Jogl/Joal/Jinput/etc does complicate the whole process of deployment.


It actually isn't that complicated.. Install Anywhere would handle things easily.. but since I sort of agree with the idea :)...

I think something along the lines of the WebStart extension installation mechanism needs to be built in to the standard (and striped down) JRE.  Normal Java Applications would automatically install optional bits of the JRE on demand.  This could be triggered by the classloader which, when it doesn't find a class from the java.* or javax.* packages on the system would query java.sun.com and grab the needed package.  If no access to the internet is available it can bail out with a "You need package XYZ to run this program, it can be found at this URL and will be installed automatically if a net connection is available..."

The "Get Java" button is a good start at simplifying the basic JRE install for end users.  If you are making Java games and you don't host "the button" - shame on you ;).

Archimedes
Guest
« Reply #17 - Posted 2003-07-09 19:19:36 »

Quote
(..)
I heard that OpenGL might be used to accelerate graphics on Linux, much like Direct X is used on Windows.

Yes, this has been mentioned some time ago on Java-Developer (?) by somebody from the Java 1.4.x team (?). Basically they wanted to address the topic after Java 1.4.x - AFAIK.

Quote
 It would be cool if that effort ended up pulling JOGL into the core.

Yes, this would be really great.
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.

xsi3rr4x (44 views)
2014-04-15 18:08:23

BurntPizza (40 views)
2014-04-15 03:46:01

UprightPath (56 views)
2014-04-14 17:39:50

UprightPath (38 views)
2014-04-14 17:35:47

Porlus (54 views)
2014-04-14 15:48:38

tom_mai78101 (77 views)
2014-04-10 04:04:31

BurntPizza (136 views)
2014-04-08 23:06:04

tom_mai78101 (236 views)
2014-04-05 13:34:39

trollwarrior1 (197 views)
2014-04-04 12:06:45

CJLetsGame (205 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!