Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Killer Game Programming's Animation Framework Being Wrong on: 2013-03-14 19:35:26
awt is thread-safe

Huh?  You do know that Swing uses the AWT event dispatch thread (EDT), right?  Wink

AWT is equally single-threaded and not thread-safe - http://en.wikipedia.org/wiki/Event_dispatching_thread

Seems like this book had already been outdated when it was printed. Because as far as I know the change in Swing rule was made in 2004.

No, Swing has always been single threaded.  The "rule" that changed was around creating components off the EDT before they were realised (ie. before making them visible).  It's now recommended to always create components in the EDT.

However, active rendering to an AWT or Swing component is OK.  I'd recommend a Canvas, and searching for information on using BufferStrategy.

While painting to the component is OK, I'd recommend building and displaying the window and canvas on the EDT first.  You also should probably use setIgnoreRepaint(true) to stop the component trying to respond to paint requests from the EDT.



Hello. Thanks for the reply.

Can you give more specific information on why it's OK to paint ? Doesn't painting mean modifying? Is every painting function thread-safe or what?

I use this method to create the Frame and the JPanel. GameMain contains the code to instantiate and show JFrame.

 public static void main(String[] args) {
      // Use the event dispatch thread to build the UI for thread-safety.
      SwingUtilities.invokeLater(new Runnable() {
         @Override
         public void run() {
            new GameMain();
         }
      });
   }
2  Game Development / Newbie & Debugging Questions / Killer Game Programming's Animation Framework Being Wrong on: 2013-03-14 18:10:12
Hello. I'm a new member here.
While I'm not a newbie in Java, I've just started to game programming. And I need your advices on this.

In the resources page of the site (http://www.java-gaming.org/index.php?action=resources), I've seen that "Killer Game Programming in Java - Andrew Davison" is one of the recommended books.

I have been trying to read this book for a while but I have discovered that the animation framework presented in the second chapter of this book is wrong. Because in Java tutorial it's said that GUI components should be accessed (created, modified, queried, etc.) only in EDT (Event Dispatch Thread). But in Killer Game Programming, animation is controlled by another thread. And it uses a technique named 'Active Rendering' which doesn't event use method repaint. Instead, it tries to get graphics context of JFrame in order to render everything by itself. It uses JPanel from another thread therefore violates Swing's single thread rule.


Seems like this book had already been outdated when it was printed. Because as far as I know the change in Swing rule was made in 2004.

Since you recommend this book to newbies, can you enlighten me? What should I do? Should I continue reading a wrong book? Am I the wrong one?
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

Dwinin (23 views)
2014-09-12 09:08:26

Norakomi (56 views)
2014-09-10 13:57:51

TehJavaDev (69 views)
2014-09-10 06:39:09

Tekkerue (34 views)
2014-09-09 02:24:56

mitcheeb (56 views)
2014-09-08 06:06:29

BurntPizza (40 views)
2014-09-07 01:13:42

Longarmx (25 views)
2014-09-07 01:12:14

Longarmx (32 views)
2014-09-07 01:11:22

Longarmx (31 views)
2014-09-07 01:10:19

mitcheeb (39 views)
2014-09-04 23:08:59
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!