Skip to main content
gamedev.net
🔒 Locked

[java] Why no multiplayer applets?

Started by fractoid Mar 12, 2004 at 8:32 AM 30 replies 8.7k views
Original Post
fractoid
fractoid
Title says it all, really. Applets can (or could, my java knowledge is well behind the times at the moment) open socket connections back to the server from which they were loaded, without any signing/whatnot that forces the user to click scary 'potentially let applet wipe my hard drive' dialogs. So why don't we see more (or any) action games that let the user just load up a web browser, type in a username, and have at it? In fact, I'm currently setting out to write such a game, so while I'm at it, those in the know feel free to espouse your views on the best current way to do things. Keep in mind that I'd like the game to be runnable on the majority of machines without downloading *another* JVM. (ie. don't tell me all about the cool stuff in Java 1.5 beta 2. ) Let's say I have an (as yet hypothetical) online game, FragLounge. Best way to imagine it is that FragLounge is to Mario as Subspace is to Asteroids. It's a 2D platformer, with maybe 20-30 people in a world (100 tops, if possible). The goal of the game is to click on a link, and immediately (after applet loading time, ofc) be in the game world ready to play. Graphically, I'm planning to have five logical image layers (parallax scrolling background, doodads such as trees and lamp-posts and such, player characters, platform world items like floors and walls, and projectiles and explosions). Most probably the layers will be drawn sequentially into a single back buffer, but if it's quicker to composit separately I'll do that. If there were some way to use available hardware acceleration for funky effects, that'd be cool, but not at the price of forcing the user to install an extra package (ie. java3D, gljava, javagl, ja-gl-va, or any such other JINI-based extraneous junk). Important question: Do java.awt.Image objects consume local OS resources? (ie. in Windows there's an unfairly small number of HBITMAPS that can be allocated at any one time. Does a similar limitation apply to Java?) In terms of sound, I'll keep things fairly basic. I'd like to be able to play 8kHz or 16kHz mono samples, possibly with stereo bias, and some midi music in the background. There used to be a choice between the java.applet.AudioClip that had a resource leak and rapidly crashed the system, and the undocumented sun.audio classes which worked goodly but weren't part of the spec and hence unportable, in theory if not in practice. What is there these days? Is AudioClip fixed? Is sun.audio documented? Networking-wise, I'm currently tossing up between using ObjectStreams wrapped around sockets (easy) or manually marshalling messages into UDP datagrams (probably faster). All damage distribution will be done on the server, and player motion will be client-side for responsiveness, with sanity checking on the server to prevent hacked clients from teleporting (much) or arbitrarily giving themselves weapons. For input, I figure the standard keyboard messages are more than enough - I used them often enough in my youth to know that they're plenty responsive enough for the sort of gameplay I picture, unless they've been drastically nobbled in recent times. So... comments, ladies and gentlemen? [edit: shortened title so as to be less annoying. C'mon, no-one's noticed this? Is Java inherently bad at this or something, for some reason I can't fathom?] [edited by - fractoid on March 12, 2004 10:01:06 AM]
princec
princec
Ask yourself first why you''ve hardly seen any decent games at *all* in Java, before wondering why no-one''s done a multiplayer applet yet.

If you sign the applet you should be able to include OpenGL accelerated libs with your applet. If you don''t use OpenGL libs then your performance will suffer somewhat if you do any fancy blending. If you''re just cookie cutting you should get excellent performance on 1.4 VMs on Windows. MacOS may not be so successful.

I advise using straight TCP for communications, and starting out with Serializable and then moving to Externalizable when you need to optimise the protocol. UDP will be much more trouble than it''s worth.

Cas
nonnus29
nonnus29
quote:
Original post by fractoid
In fact, I'm currently setting out to write such a game, so while I'm at it, those in the know feel free to espouse your views on the best current way to do things. Keep in mind that I'd like the game to be runnable on the majority of machines without downloading *another* JVM. (ie. don't tell me all about the cool stuff in Java 1.5 beta 2. )



You might as well stop before you even start; the majority of users have only the Microsoft java 1.1 compliant vm that comes with Internet Explorer. The aggresive 2d features your talking about will run like crap on that abomination.

The two main cool features for games in jdk 1.5 beta is 1) a highresolution timer and 2) opengl 2d rendering on linux (edit imo). But jdk 1.4 is outstanding on its own; it will use hardware accelerated 2d rendering in windows; you can get very respectable frames rates for free on windows and the win xp timer isn't too bad.

I'd force users to install at least 1.4.2; if your games good enough, they won't mind.

Sounds like you've got a 'neat' origional concept, good luck.

[edited by - nonnus29 on March 12, 2004 8:48:45 PM]
pinacolada
pinacolada
When Java applet technology was new, a lot of great games came out. Now you hardly see any, everybody just uses flash now.

Did anyone play the games on Centerfleet? (also called Centerscore). Those games were multiplayer and they were freaking awesome. There was a tetris-style game called Avalanche, that you would play against 3 other people at a time, and when you did a combo, you got powerups that you could use to make extra blocks fall on an enemy player. Man I got really good at that game.

There was another popular game that I didn't play as much, an Asteroids-style game called Wormhole, where bad guys would appear through a wormhole, and when you killed them you could get powerups, and some of the powerups buffed up your ship, and some powerups were used to send enemy ships at the other players.

But at some point, Centerscore took down all those games, and it looks from their new site that they are doing cell-phone games now. Those bastards.

Edit, also I agree that there should be more applets out there. I'm writing a personal webpage right now that's just going to be nothing but one big applet. I'm not sure yet if I'm going to force my average user to upgrade from 1.1, or if I'm just going to make it 1.1 compatible.


[edited by - pinacolada on March 12, 2004 9:20:03 PM]
fractoid
fractoid
@princec: I''m not talking about, or planning on making, the next cutting-edge FPS or RTS, let alone a freakin'' MMORPG. (Why is EVERYONE making one of those? They''re not even fun!) I''m talking about a small, lightweight, fun game that you can load up, play for fifteen minutes at lunchtime against the marketting guys down the hall, and then quit. As for ''cookie cutting'' - if you mean making a clone of another game for learning purposes, then no. I''ve already gone through that phase. Besides - name one online multiplayer platform game (apart from Stick Soldiers, which might qualify, but I''ve never played). Give up?

<bitch>Everyone seems to have become dependant these days on near-infinite fill rate and kickass hardware to take all the effort out of making games. Remember games like Earthworm Jim? They had good graphics (roughly on par with my targets for this game) and they did it on a freakin'' 486. If yer vanilla 1GHz machine can''t keep up with that in Java, it''s a disgrace. </bitch>

As for the networking - I think I''ll use an ObjectStream socket for authoratitive stuff (kills, weapon pickups, etc) and a UDP packet stream for updating enemy players'' positions etc.

@nonnus29: The 1.1 JVM had enough guts to run fairly advanced software 3D engines (remember anfy3d?) so it should handle this. I think it''s not so much generic performance as specific bottlenecks, such as writing an image to the screen which seems to take around 20-50ms regardless of anything else. I''ll give it a go, anyway.

@pinacolada: I never managed to find any realtime multiplayer applets... it was always Hearts or Reversi or whatnot. The closest was some kind of online version of pictionary. I don''t get why companies take games down after putting all that work into them - seems silly. Maybe the bandwidth was costing too much?
nonnus29
nonnus29
So what will be the dimensions of the applet? What will the tile size be? Sprites? Do you have an artist? Will you use scripting for the levels if so what scripting language? Jumping on your friends head like mario might be fun but street fighting or blasting each other would be more fun or joining together to beat a boss would rule.

Heres a link with alot of good discussion about tcp/real time game networking:

http://www.javagaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=Networking;action=display;num=1078270630

The below has community alot more activety; however the participants are a bit more ''leet'' (ie focused on triple A commercial level games and 1.1 dev is frowned upon).

http://community.java.net/games/
fractoid
fractoid
The applet will be somewhere between 230x240 and 400x300 depending on how fast I can get it. My original plan was to have an applet embedded in a web page, but Java Web Start seems to have become useful since I last looked at it, so I''m considering switching to that for the funky loading screen and version checking etc.

Tile size will be 32x32, with animations generally in the 2-5 frame range. I don''t have an artist yet, and it''d be premature to call out for one until I have enough of an implementation to be sure it''ll work, but the game design is aimed towards community interaction (ie. each registered player can supply their own avatar to use, and players can submit levels/tilesets).

In terms of gameplay, maybe Mario wasn''t the best example. The picture in my mind is actually more like Zeb (the example platformer bundled with The Games Factory, which I bought back before I realized it was more work making a game in a game authoring package than just writing it myself). Little commando guys, aliens, micro-mecha etc. battling it out with a variety of guns, grenades and so on, in the obligatory jungle/snow/desert/city tilesets plus whatever people can think up. I hadn''t planned cooperative mode for starters, but I''m considering putting in ''creeps'' (neutral hostile NPCs) that one can kill for weapons, so it''s not a big step from there to multiplayer co-op missions.

Thanks for the links - they look useful. The community.java.net site seems more geared to mobile and high profile commercial PC games, as you say, but I''m sure a lot of it is relevant.
fractoid
fractoid
Untrue. Signed JWS apps have to be authorized, but get the run of the system. Unsigned JWS apps don''t have the security dialog, but are still sandboxed (although they can read from, and write to, the hard disk, under uesr control). I don''t know whether or how much the network access restrictions differ between applets and JWS.

It''s true that Java Web Start Applications and Applets are different beasts, definitely.
fractoid
fractoid
Aaaaah, I see. I thought it was a ''yet another platformer'' comment... sorry.

I was planning to have transparency support, but possibly rig it so that only a small number of pixels actually needed blending around the outside. I want to save as many CPU cycles as possible for the explosions...

Hey, I saw Alien Flux for sale on some website just now... where was that again? Ah, addictive247. Coolies... I wonder how much money it''s making?
Arild Fines
Arild Fines
Huh? Yahoo Games has had multiplayer applets for years.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
fractoid
fractoid
@AP: Did you have a point? And were you talking to anyone in particular? It''s a mistery to me too.

@Arild: Yes, I know it''s possible , otherwise I wouldn''t attempt to do it. However, if Yahoo! Reversi is your idea of a fun action/arcade game, I pity you deeply.
uncutno
uncutno
Some freands of mine did this 4 years ago!

http://www.brutalhomicide.com/

the site is beeing recreated just now, but the game rocks, and is multiplayer and java!

-Anders-Oredsson-Norway-
RPGeezus
RPGeezus
There still are some pretty decent multiplayer applets. Sure, they''re not as complex as say GTA3, but they''re still pretty good.

www.minatrix.com has a few games, specifically Castrol Racing 2. It''s 3D, runs reasonably fast, and is two player. It could be better IMHO if they added guns and rockets, but this is a game design issue, not a Java issue.

I think the biggest reason we''re not seeing more multiplayer Java applets is because of bandwitdh. It costs money to host these things, and I doubt many people would be willing to play Castrol Racing 2 if they had to pay for it.

I run XP and home and work. At home I have Sun''s JVM, and at work MS''s. They both seem to work pretty well.

Will
boutell
boutell
I found this thread via Google, and I''m impressed with the level of the discussion -- and the fact that there *is* a live discussion of Java game applet programming going on here in 2004. Very cool.

I have a hot tip for those who are struggling to get good frame rates from a Java applet: if you can live with 256 colors, of your own choice, you can get very high frame rates even in an applet window, on typical PCs, at applet sizes as large as 400x400 (the largest I''ve played with today, anyway).

My applets typically ran at 15-20FPS, or worse, until I discovered the following absolutely essential tricks. My new applet is redrawing the entire pixel array for every frame, with no dirty rectangles or other optimizations to minimize redraws, and yet it is running at easily 50FPS:

1. You need to use the IndexColorModel (palette color rather than truecolor). Even though the user''s display is almost certainly NOT running in 256 colors, the Java VM implementations are enormously faster at handling MemoryImageSource stuff when the pixel array consists of bytes, not 32-bit ints. This is as much as a 4x speedup, or more. Don''t ignore it. I did, for a long while, and now I see the error of my ways.

2. Don''t create new MemoryImageSource and Image objects over and over! Call setAnimated on your MemoryImageSource. Also call setFullBufferUpdates. You can then call createImage(source), and magically update that image with the new contents of your byte array of pixels by calling source.newPixels().

3. Don''t call repaint(); just call paint(getGraphics()). Your paint() method should call source.newPixels(), then gd.drawImage to copy your image to the display.

You can find full source code for an applet that does all of these things correctly here:

http://rsb.info.nih.gov/plasma2/

There is also a smaller version with a table of FPS rates submitted by users of many different browsers and CPUs; note that acceptable performance is easily achieved with the faster Pentium IIs and up, which are now quite old and mostly retired (my how time flies):

http://rsb.info.nih.gov/plasma/

As for the UDP situation, I did the deed once long, long ago -- a quick and dirty spacewar applet -- but haven''t tried it yet with modern machines.

Reasons why nobody used UDP in applets:

1. The biggest reason: MacOS Java never supported it. With anybody''s virtual machine. This has *probably* finally changed with MacOS X, but I haven''t tried that out yet. If you can''t be portable, you might as well write a win32 application that runs fast and isn''t restricted, et cetera, et cetera. So people did.

2. The sandbox restriction to contacting the server only. At the time, win32 applications could communicate peer-to-peer quite freely. That has changed now; cable routers, and certainly firewalls, won''t allow peer-to-peer UDP connections to be established by default -- you can only talk to servers anyway without annoying router configuration changes most people don''t understand how to make. That''s part of why major multiplayer games use battle.net or another centralized server rather than peer-to-peer for Internet-wide play. So the playing field has actually been leveled a bit! If you could design your protocol to use bandwidth very, very sparingly, or somehow convince people to pay something for your game, you might be able to justify it.

I do plan to write a new Java UDP game soon, and hopefully I''ll at least get as far as doing some testing with different browsers and OSes. If I do, I''ll share some results here.

Cheers.


Thomas Boutell
Boutell.Com, Inc.
Purveyors of quality web resources since 1993.

Thomas BoutellBoutell.Com, Inc.Purveyors of quality web resources since 1993.
boutell
boutell
P.S. In response to your question about java.awt.Image objects and AudioClip resource leaks, I recommend that you composite things yourself using a byte array of pixels and MemoryImageSource as I described, because it runs a great deal faster. As for the sun audio classes, I don''t think those have been available in the average browser java environment for quite a while now. AudioClip is used in my applets and doesn''t destroy the world, although I fetch a modest number of short clips initially and use them throughout as needed.

(My current applets aren''t yet taking advantage of much of this cool speed-enhancing advice -- they get adequate speed the old-fashioned way by just not drawing a whole heck of a lot!)


Thomas Boutell
Boutell.Com, Inc.
Purveyors of quality web resources since 1993.

Thomas BoutellBoutell.Com, Inc.Purveyors of quality web resources since 1993.
fractoid
fractoid
Oooh, this thread isn''t dead after all!

Thomas: Yep, I''ve used MemoryImageSource before, but wasn''t sure if it was quicker to let (hopefully faster) native code handle blitting or to do it myself. I''ll probably stick with handling my own framebuffer anyway, just because that way it''s easier to do special effects such as explosions, alpha blending etc.

As for networking, I''m currently nervous about UDP on the basis that it''ll probably need friggin'' around with firewalls to get the datagrams from the server to the client. This is expressly the sort of thing I want to avoid in a low-effort web game... the generic web audience can''t, or won''t bother, handling that sort of thing. However, I can''t see a good way to do games with inherently poor prediction (ie platformers, FPS games) without the UDP send-and-forget system. What about the sendUrgentData() or whatever it''s called, in java.net.Socket? I know it sends out-of-band data, but does that then remove the order-dependance and waiting-for-acks problems that TCP faces? I''m guessing not, or I would have heard about it, but hey, it''s a straw, watch me clutch it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.