Comment On Sprite Threading

Sometime near the end of the previous millennium, Neinhalt Sieger accepted a programming at a small software company that built Java-based games. Although today we realize that Java wasn't quite the ideal platform for videogames, back in the 90's it was all the rage. If your game wasn't made in Java, it might as well have been with made out of wood and rolled with a stick. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Sprite Threading

2007-03-26 15:48 • by Jake Vinson
At the end of each level, in garbled speech: "I'M RAD!!"

Re: Sprite Threading

2007-03-26 15:53 • by scared to heck and back (unregistered)
MEDICAL EQUIPMENT?

AYIEEEEEE!!!

Re: Sprite Threading

2007-03-26 15:55 • by Erick
It's gonna take a LOT of threads to keep this patient alive!

Re: Sprite Threading

2007-03-26 16:05 • by Thuktun
For those who are not familiar with Java, the Sprite2D class was directly derived from the Runnable class. This means that it has the ability to create its own threads.
No, it implements the Runnable interface, which means it has a no-argument run() method that is easily plugged into a thread. The Runnable interface does not endow a class with the ability to create threads.

Re: Sprite Threading

2007-03-26 16:10 • by Tukaro
128600 in reply to 128597
Erick:
It's gonna take a LOT of threads to keep this patient alive!
I imagine that memory leaks in this case would be quite a bad thing...

Re: Sprite Threading

2007-03-26 16:12 • by PSWorx
Ewch... that's ugly...

While being on sprites though, does anyone know a decent, presumely non-WTF coded sprite library for java? (yes, there are still uses for java based games today...)

Also, while the threads thing is obvious, what exactly is wrong with using a delegation-based sprite manager?

Re: Sprite Threading

2007-03-26 16:13 • by Luke Dawson (unregistered)
128603 in reply to 128600
Tukaro:
Erick:
It's gonna take a LOT of threads to keep this patient alive!
I imagine that memory leaks in this case would be quite a bad thing...


And the term "blue screen of death" takes on a whole new meaning.

Re: Sprite Threading

2007-03-26 16:15 • by themagni
128604 in reply to 128597
Erick:
It's gonna take a LOT of threads to keep this patient alive!


Wouldn't those be "stitches"?

Re: Sprite Threading

2007-03-26 16:24 • by Lars (unregistered)
Alex Papadimoulis:
Although today we realize that Java wasn't quite the ideal platform for videogames, back in the 90's it was all the rage. If your game wasn't made in Java, it might as well have been with made out of wood and rolled with a stick.

So well spoken. I think the intense sarcasm of this paragraph pretty much sums up the reasons why I still keep checking his page. Keep it coming, Alex :D :D :D

Re: Sprite Threading

2007-03-26 16:33 • by Soro (unregistered)
For those who are not familiar with Java, the Sprite2D class was directly derived from the Runnable class. This means that it has the ability to create its own threads.


Bullshit. Those familiar with Java know that

(a) An interface implementation is not "deriving" a class. It is not inheritance.

(b) Implementing the
Runnable
interface (which is one single method called run()) does not give the Sprite2D class the ability to create its own threads.

(c) Implementing
Runnable
allows to execute (not create) instances of a class in a separate thread.

(d) To create a thread you need - surprise, surprise - the
Thread
class.

The fuck was apparently not the original author.

Re: Sprite Threading

2007-03-26 16:40 • by darin
128613 in reply to 128595
scared to heck and back:
MEDICAL EQUIPMENT?

AYIEEEEEE!!!

I'm writing software for medical equipment. I need to know what Bob's last name is so I can avoid him...

Re: Sprite Threading

2007-03-26 16:40 • by akatherder
Wait wait wait... this "Machine Man" game sounds suspiciously close to another popular game I used to play all the time. A game by the name of Q*Bert.

Re: Sprite Threading

2007-03-26 16:42 • by LKM (unregistered)
50 threads just for Pacman? I think that would be the perfect game engine for the PS3, then. Finally, a game that uses all cores!

Re: Sprite Threading

2007-03-26 16:42 • by htg (unregistered)
I wrote Tetris in Java back in 1998 during a summer internship during university - it took a couple of days, and ran on a 40MHz ARM7 based set top box from Acorn with a JVM that was as optimised as a Fiat Pinto in a Formula 1 race, and it was smooth and worked. I'd only done a few dozen hours of Java programming beforehand (although I was a Blitz Basic 2 whizz, lol). The code was probably quite shite to be honest, but must have looked like gleaming gold in comparison to multithreaded pacman.

I suspect that many developers enter the complexity-zone between the time they're inexperienced newbies and reasonably good programmers. It seems that many don't escape but some of them somehow get enough money to have their own game company. I can just imagine the thought processes however, vaguely.

Re: Sprite Threading

2007-03-26 16:54 • by MikeCD (unregistered)
the usual horrors of no documentation, a wide variety of magic numbers, and plenty of code duplication

From what I understand, this is the accepted norm in game programming.

Re: Sprite Threading

2007-03-26 16:54 • by RobIII
As for Bob, the original architect and designer of Machine Man and the game library, he left the games industry a while back and is now writing software for medical equipment.

...munching away pills...

Re: Sprite Threading

2007-03-26 16:56 • by namezero (unregistered)
The real WTF here is unfortunately what happens very often in the software industry - using completely inappropriate tools for the job.

Java is just not the language for an application that is supposed to run at real speed, including games.


CAPTCHA: smile :)

Re: Sprite Threading

2007-03-26 17:00 • by nobody (unregistered)
I wrote a Pac-Man clone (sort of) on an Apple ][ in FORTH.
It ran too fast; I had to slow it down or all the "ghosts" would get you before you could hit a button.

Re: Sprite Threading

2007-03-26 17:00 • by Rootbeer
I hate to be That "The Real WTF is..." Guy, but TRWTF is using a sprite object to represent each of the pellets in the maze. Assuming that Machine Man was supposed to play similarly to the popular arcade game, the pellets never change position in relation to each other or to the playfield.

Re: Sprite Threading

2007-03-26 17:02 • by OSE (unregistered)
128627 in reply to 128621
You're not wrong. Let's just say that the guys who develop the interfaces to graphics and sound technology aren't noted for their communication skills, the ability to speak English, or their familiarity with accepted standards of documentation.

I don't miss writing J2ME.

Re: Sprite Threading

2007-03-26 17:04 • by jkohen
128628 in reply to 128623
namezero:
The real WTF here is unfortunately what happens very often in the software industry - using completely inappropriate tools for the job.

Java is just not the language for an application that is supposed to run at real speed, including games.


Troll. I have a server application written in Java (almost entirely by myself) tending to over a thousand socket connections at all times, most of which are active to some degree, and it consumes *at most* 1% CPU in a single-core single-CPU i386 computer. Even under higher, artificial loads, the VM behaves very well.

You can code with the VM or against the VM. The original developer was obviously coding against it, whereas the day's savior knew better.

Re: Sprite Threading

2007-03-26 17:05 • by dolo54 (unregistered)
This is what happens when theory takes a priority over reality. Aka... "I want it to follow strict OOP architecture." as opposed to "I want it to work."

Re: Sprite Threading

2007-03-26 17:11 • by SuperousOxide
128635 in reply to 128623
namezero:
The real WTF here is unfortunately what happens very often in the software industry - using completely inappropriate tools for the job.

Java is just not the language for an application that is supposed to run at real speed, including games.


CAPTCHA: smile :)


If you want an easily deployable and simple game, java is a reasonable tool for this job. Pac Man does not require hardcore graphics-card crunching to implement, and a modern PC should be
able to handle it easily.

You probably don't want to be writing Doom in it, though.

Re: Sprite Threading

2007-03-26 17:12 • by my name is missing (unregistered)
I hate to spoil your parade, but Java IS fast enough to write games with today, assuming you have a clue and use an opengl framework like jogl. After all much of the work is done in opengl which is native code. I had friends who wrote an F22 simulator for Lockheed in java based on the real plane systems and it ran with high FPS on cheap linux hardware.

Of course in 1997 this wasn't possible at all.

In any case using 50 threads in any language for Pacman is a wtf in any case.

Re: Sprite Threading

2007-03-26 17:13 • by my name is missing (unregistered)
Gag, in any case I needed to edit my comment in any case.

Re: Sprite Threading

2007-03-26 17:15 • by Leonel (unregistered)
The senior development team decided to build themselves their own set of cutting-edge libraries and a framework that would ...


Now, this is why I love this site. That is just the kind of sentence that makes me shiver and gets my spine cold.

This is not very different from watching scary movies, after all.

Re: Sprite Threading

2007-03-26 17:16 • by Ian Tester (unregistered)
128639 in reply to 128615
LKM:
50 threads just for Pacman? I think that would be the perfect game engine for the PS3, then. Finally, a game that uses all cores!

The Cell in the PS3 only has one core. Do not mistake the SPE's for "cores". They're basically just vector co-processors. While they are quite flexible, the SPE's are really only good for processing chunks of data. Think of them being similar to shading units in modern GPU's.

Re: Sprite Threading

2007-03-26 17:18 • by Shinobu (unregistered)
Java wasn't quite the ideal platform for videogames
And then the article shows that actually the game was just programmed horribly.
For the record, I've played a game full of Java code, and even some Python code, a 3D-game no less, that actually runs better and looks better than the usual Quake-derivatives. No gratuitous language bashing please, people might get the impression you're immature.

Re: Sprite Threading

2007-03-26 17:18 • by tieTYT (unregistered)
that was a great article. Thanks

Re: Sprite Threading

2007-03-26 17:25 • by Stephen (unregistered)
The multiple threads idea is very nice in theory, the limitation here is a matter of implementation. I bet that what the hero did was to copy-and-paste code from every thread into the main loop(or methods called from it), then removing the threads. After all, the game logic is designed in such a way as to provide the illusion that everything is happening at the same time, when in fact we know it is not.

That too is the purpose of threads. With the added benefit that they can scale to multiple cores and the scheduler is (usually) already written. Wouldn't it be nice if we could use threads for every sprite, as the WTF guys did, but with much less overhead?

Assuming you don't really care about multiprocessors and just want to have a better abstraction, there's the concept of "microthreads". While not "real" threads, they are very convenient :)

For examples, see Stackless Python, and one major commercial game implemented with it, EVE Online. Every entity(players included) is a thread and they can even be serialized and relocated to other physical servers. Probably hundreds of thousands of "threads", with little overhead.

So, in my opinion the pacman guys had a nice idea, but a poor implementation. A classic example of using the wrong tool for the job :)

Re: Sprite Threading

2007-03-26 17:35 • by Digitalbath
128645 in reply to 128644
Stephen:
The multiple threads idea is very nice in theory, the limitation here is a matter of implementation. I bet that what the hero did was to copy-and-paste code from every thread into the main loop(or methods called from it), then removing the threads. After all, the game logic is designed in such a way as to provide the illusion that everything is happening at the same time, when in fact we know it is not.

That too is the purpose of threads. With the added benefit that they can scale to multiple cores and the scheduler is (usually) already written. Wouldn't it be nice if we could use threads for every sprite, as the WTF guys did, but with much less overhead?

Assuming you don't really care about multiprocessors and just want to have a better abstraction, there's the concept of "microthreads". While not "real" threads, they are very convenient :)

For examples, see Stackless Python, and one major commercial game implemented with it, EVE Online. Every entity(players included) is a thread and they can even be serialized and relocated to other physical servers. Probably hundreds of thousands of "threads", with little overhead.

So, in my opinion the pacman guys had a nice idea, but a poor implementation. A classic example of using the wrong tool for the job :)


I tried to paint my house this weekend with a shovel. It did not go so well.

Re: Sprite Threading

2007-03-26 17:39 • by dolo54 (unregistered)
128646 in reply to 128644
I think one thread is plenty to handle 1 pacman and 3 scary ghosts. <quote>Assuming you don't really care about multiprocessors and just want to have a better abstraction...</quote> ummm when and why would you not care about performance and just want better abstraction??? That's the exact type of thinking that leads to http://worsethanfailure.com/Articles/The_Complicator's_Gloves.aspx

Re: Sprite Threading

2007-03-26 17:42 • by bstorer
128648 in reply to 128635
SuperousOxide:
If you want an easily deployable and simple game, java is a reasonable tool for this job. Pac Man does not require hardcore graphics-card crunching to implement, and a modern PC should be
able to handle it easily.

You probably don't want to be writing Doom in it, though.

Oh really?

Re: Sprite Threading

2007-03-26 17:42 • by Reed (unregistered)
Typical DBT pattern: Design before Thought.

Next time, engage your brain before your typing fingers :)

Re: Sprite Threading

2007-03-26 17:46 • by bstorer
128650 in reply to 128613
darin:
scared to heck and back:
MEDICAL EQUIPMENT?

AYIEEEEEE!!!

I'm writing software for medical equipment. I need to know what Bob's last name is so I can avoid him...

Actually, these entries are anonymized, so Bob was actually you all along. Now put down the thread and step away from the x-ray machine...

Re: Sprite Threading

2007-03-26 17:47 • by kibagami genjuro (unregistered)
BAH!

Re: Sprite Threading

2007-03-26 17:49 • by Reed (unregistered)
Anyway, it's not the threads that kill you (a thread is really a rather lightweight object in general), it's the interdependencies and locks.

Re: Sprite Threading

2007-03-26 17:49 • by Andrew (unregistered)
128653 in reply to 128599
Thuktun:
For those who are not familiar with Java, the Sprite2D class was directly derived from the Runnable class. This means that it has the ability to create its own threads.
No, it implements the Runnable interface, which means it has a no-argument run() method that is easily plugged into a thread. The Runnable interface does not endow a class with the ability to create threads.


Yes, the original article explained the Runnable interface wrong. However, a class that implements Runnable can create its own threads using the java.lang.Thread class.

Sometimes, a class already extends another class, other than java.lang.Thread. In this case, it implements Runnable, and has a method to create a Thread object from itself.

class MyClass extends MySuperClass implements Runnable {
void run() {} // Have a thread do something...
void start() {
Thread myThread = new Thread(this);
myThread.run();
}
}

Re: Sprite Threading

2007-03-26 18:05 • by emurphy
128658 in reply to 128646
dolo54:
I think one thread is plenty to handle 1 pacman and 3 scary ghosts. <quote>Assuming you don't really care about multiprocessors and just want to have a better abstraction...</quote> ummm when and why would you not care about performance and just want better abstraction??? That's the exact type of thinking that leads to http://worsethanfailure.com/Articles/The_Complicator's_Gloves.aspx


Oh, he cares, he just doesn't really care.

More seriously, in most situations, a certain level of performance is good enough - that's the whole point of high-level languages. But you probably knew that, and no one is seriously arguing that Machine Man v1 qualified.

Re: Sprite Threading

2007-03-26 18:14 • by someoneorother (unregistered)
Not, of course, that I'm a great Java fan - but to give credit where credit is due these guys are doing quite impressively to be emulating a whole PC:

JPC

OTOH you wouldn't really want to use Java for high performance & low memory embeded system ... even C can't manage it all the time (ie spend 80% of time writing asm code)

Re: Sprite Threading

2007-03-26 18:14 • by Sven (unregistered)
At least this game is ready for when Intel puts that 80-core CPU into production.

And consider this: this game is probably better at using multi-core machines than Flight Simulator X. :P

(Yeah, yeah, it probably won't actually work that well because of all the synchronization going on... sheesh, spoil my fun, why don't you)

Re: Sprite Threading

2007-03-26 18:23 • by iToad (unregistered)
This reminds me of Mickey Mouse as The Sorcerer's Apprentice in the old Disney classic Fantasia.

(The one with the spawning broomsticks with buckets of water).


Re: Sprite Threading

2007-03-26 18:24 • by someoneorother (unregistered)
128664 in reply to 128660
I should have pointed out that one of the games they're demoing on JPC is pacmania ... surely that qualifies as a WTF - running Pacman on an PC emulated in Java (and I bet they got the threading right).

BTW can anyone control the damned lemmings in lemmings 1 ?

Re: Sprite Threading

2007-03-26 18:27 • by mathew (unregistered)
Ignoring the out-of-date crap about Java being too slow for games (maybe it was in 1997, but it isn't now, see Jake2, Puzzle Pirates etc)...

If the sprite framework expected the sprite objects to draw themselves and handle their collision detection, then the real WTF is "WTF is this sprite framework *for*? What does it get me?"

Re: Sprite Threading

2007-03-26 18:27 • by Andrew (unregistered)
128667 in reply to 128611
Soro:
For those who are not familiar with Java, the Sprite2D class was directly derived from the Runnable class. This means that it has the ability to create its own threads.


Bullshit. Those familiar with Java know that

(a) An interface implementation is not "deriving" a class. It is not inheritance.

(b) Implementing the
Runnable
interface (which is one single method called run()) does not give the Sprite2D class the ability to create its own threads.

(c) Implementing
Runnable
allows to execute (not create) instances of a class in a separate thread.

(d) To create a thread you need - surprise, surprise - the
Thread
class.

The fuck was apparently not the original author.


Not understanding a concept is a bigger WTF than confusing the terminology. Read this.

Java Interfaces replace "Multiple Inheritance" in other languages. The most well known is C++; see its I/O Streams library. Two parent classes shouldn't each give the same method to the child, a IS-A relationship for both parents. This is a great C++ compile-time error.

Runnable and every other Java Interface changes Multiple Inheritance to a HAS-A for the second class. It (java.lang.Thread) is stored a as member field, and its Interface (java.lang.Runnable) is implemented. The other class is extended by the child class.

Often, a class that implements java.lang.Runnable has a java.lang.Thread inside to actually run the thread.

Re: Sprite Threading

2007-03-26 18:28 • by ahnfelt
128668 in reply to 128593
...:
public class Sprite2D implements Runnable, Cloneable

For those who are not familiar with Java, the Sprite2D class was directly derived from the Runnable class.


Does those include the author? Because Runnable is not a class and you can only implement an interface.

Nice WTF though!

Re: Sprite Threading

2007-03-26 18:38 • by infidel (unregistered)
Wonder who else caught the Samurai Showdown II reference...

Re: Sprite Threading

2007-03-26 18:57 • by Jim (unregistered)

Often, ppl try to make a better engine while they dont achieve to make a descent engine

I would say first make a descent engine, then make a better engine

Re: Sprite Threading

2007-03-26 19:24 • by VGR
There are certain antipatterns which are universal, committed by nearly every new Java programmer.

One of them is trying to do everything with threads.

I did it when I was first learning Java. Almost everyone does it.

Re: Sprite Threading

2007-03-26 19:39 • by Phalphalak
128681 in reply to 128636
my name is missing:
I hate to spoil your parade, but Java IS fast enough to write games with today, assuming you have a clue and use an opengl framework like jogl. After all much of the work is done in opengl which is native code. I had friends who wrote an F22 simulator for Lockheed in java based on the real plane systems and it ran with high FPS on cheap linux hardware.

Of course in 1997 this wasn't possible at all.

In any case using 50 threads in any language for Pacman is a wtf in any case.


Bump that!
I admit, I too write my games in Java and it does not perform slow at all (sophisticated and fast 3D Graphics, fast AI processing in the background etc. is all possible). Of course, back then that was an entirely different topic. :)
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment