[java] Java and performance

Started by
14 comments, last by Fovster 23 years, 5 months ago
Hola. I''ve been reading these forums for some time already and finally decided to participate. I have been planning out an isometric type of game in java, and have come up with some questions considering the fact that java as itself is a little slower than many alternatives. So, for not getting too excited and megalomaniac, I was wondering if it''s possible to code _large_ games in java, with _decent_ graphics and things like that? Or are there some straight restrictions that would make this impossible? I''ve seen many nice little java games, but no larger ones, that would have more to play than a few little levels like in pacman or some small car-racing game? Second, I was wondering (IF I can ever get to there, or if its not too much asked) about a situation, in which I have walls on my map, and a player moves behind them. I''d like the walls that the player is behind to become partially transparent. In this case I think I can''t avoid using PixelGrabber and MemoryImageSource to alter the alpha-values of the pixels? Same thing if I would like the tiles to have some dynamic lighting around the player; each time the player moves, I''d have to go through the tiles that would be affected by altering the color values of the pixels? Using PixelGrabber and MemoryImageSource in things like this would be very slow (?), and I couldn''t think of any faster alternatives, anyone have any? In the wall case, I could of course make transparent duplicates of the non-transparent ones, but i don''t think i could do it on each tile PS. Any tutorials or such would be very welcome, though i think i''ve gone through the most.. Thanks in advance. ''''2+2=5 for extremely large values of 2.''''
- Fovster
Advertisement
First, welcome Fovster.

It is possible to write large games in Java, but at the moment it is unrealistic to write them in 100% pure Java. 100% pure Java has a number of limitations that makes it unsuitable for commercial-class games. However, there are nothing preventing you from mixing Java with C++ and getting the best from both worlds.

The electronic arts game "Prax War" did this with success but was unfortunately cancelled before completion because it "slipped its technology window". This happens sometimes ad had nothing to do with using Java - in fact the developers was happy doing so.

Vampire - The Masquarade uses Java as its scripting engine, meaning that much control code is made in Java while the rest is in C++.

Also take a look at the forum FAQ. And read the article at www.gamasutra.com about Dirty Java. (you can find it under features)

I have written an article about these things here: (the server is down at the moment but I hope my ISP gets it up again shortly):
http://www.rolemaker.dk/articles/WhyJavaCanBeUsedForGames/index.htm

I am currently using this methodology to write a 3D CRPG authoring system (www.rolemaker.com) and are getting pretty good frame rates in 3D using a Quake II like engine.

And as for PixelGrabber and MemoryImageSource - those are good for applets or small games, but for large games; forget it. Use something more powerful that is available on your machine (directX or OpenGL or something like that).

I hope this has enlightened you.

Jacob Marner
Jacob Marner, M.Sc.Console Programmer, Deadline Games
Favster,

It all depends on how large a game you are talking about. I am working on a side scroller typ eof game and have been probing at the graphics performance thing. Here are some rough unauduted numbers from sun jdk 1.3..

640x480 drawing 2400 16x16 tiles randomly on the screen.

With a basic offscreen & tile w/alpha 10fps
With a basic offscreen & non transparent tiles 15fps
With an offscreen MemoryImageSource & copyarray to blit tiles 33fps

This is just testing and completly unoptimized. I believe I can even get much higher, it''s just a matter of getting more in tune with the actual display format.

So I would say that real game are not completly out of the question. You also have to remeber there are many advantages to a 100% or 99.995% ( jni not nessary, but optional ) programming. One thing would be the almost free porting to other platforms. Besides some testing and finding a good installed there is very little you will have to do for any system.

There are many drawbacks to straight java as well. You have to fight to get decent graphics speed, there are not many mature libraries to get you started, and the general stigma for the language.

And as for megalomaniac... we all have our days, but remeber that in many ways playability in a small game will beat a large game almost any day. When asking for transparency and such, remind yourself what you really need it for, and if there might be less costly possibilities insted. With your exmple you could rotate the view insted of trying to make things transparent. I have decided personally not to get into the 3d gaming because that would be way too much for a single part time programmer.

Some other things you can look into .... java & gl4java ( glOrtho mode ). With opengl you can get the transparency almost for free as well as many other neat tricks.

Good luck on your quest.
To felonius :

Your article was very interesting indeed, got me a little excited too!
I''ve been programming in java for ~2 years now, still i have many holes in my java knowledge. To confess, i''ve never had much to do with interfaces/abstract classes and such. Java was the first and only programming language i''ve had anything to do with, excluding a very basic course on C, and a very basic course on visual basic. The current game project is an applet, which made me wonder about how it would work. I had planned to run it in a 320x320 window, which is a little small.
I''ve been planning to get to know C, but have been too lazy (or afraid) to start with it. Maybe the largest reason has been that i haven''t been able to think about much use for it. Now i just might have.. In that case, though, i should probably dump the game project for some while to get to know the basics of JNI, C and DX first.

Snowmoon:

What kind of computer are you developing your game on? The FPS seem very nice to me, considering the size of your screen!

About the transparency thing.. The walls arent the only place i''d need to adjust the tile bitmaps on. I mean, of course nice gfx definately don''t make your game good, but if you''re trying to create something realistic and would like to use line of sight algorithm and stuff like that, it quickly becomes a must.
This project of mine isn''t 3D either. Just 2D tiles drawn from an isometric view. This makes rotating the view kind hard.. I decided not to go for 3D yet either, got to learn a little more maths first. I made a rotating wireframe sphere though

Considering all the things i had orignally planned for my game (LOS stuff, GFX effects etc.), the applet idea would probably not have worked on the first place.



Thanks for suggestions.
- Fovster
well for one thing you shouldn''t use an applet if you plan on doing a big project. Applications give you more freedom. Are you even allowed to use Java2D in applets?
I''m developing on a PIII 700. I do believe that I can get much more performace out of java too, it''s just a matter of knowing how to stroke the jvm into doing what you want it to do. Applets are not a bad start too, as they tend to keep you honest about portability and size. Bloated java apps are a killer. Java is a good language to work with as it is very unforgiving with errors, I find it''s much easier to track down a bug in java than it ever was in c or c++. You can do isometric 2d with the opengl or direct 3d libraries, but you would have to know the math first.

Yes you can do Java2d in a browser, but only with the java plug-in.

Good luck
>>There are many drawbacks to straight java as well. You have to fight to get decent graphics speed, there are not many mature libraries to get you started, and the general stigma for the language.

I would like to note a thing about mature libraries. Using an high performance library for Java (such as Magician) removes the code from being 100% pure Java, as such libraries themselves use native code.

However, if you can get your hands on a library written by someelse then the clear benefit is that you don''t have to waste your time in C/C++, but can stay in Java. You should just be aware that the code being run was actual written in C.

In fact, large parts of the implementations of the Java standard library is also written in C or some other system level language (such as Pascal, Cobol or Fortran). This way such things as AWT routines are allowed to write to the graphics display.

All Java programmers should be very aware of the fact that Java is an "application level language" while C, Pascal, Fortran, and Cobol are "system level languages". For instance, you cannot write a OS kernal in Java, but you can in any of the others. This is not to say that Java is bad, just that there is somethings that it cannot do - there is however many advantages of Java, as programmer you must always use the right tool for the right job.
If I needed to write a printer driver, Java would be a bad choice.

Jacob Marner
Jacob Marner, M.Sc.Console Programmer, Deadline Games
VB must be at least twice as fast as Java. And it''s way simpler! I started writing a Tetris game in VB, as one of my first games, and I got the majority of it done in one night. It took 2 nights to do that in Java, and I''m coming from a C++ background. Java is a nice tool, but it''s not the easiest thing to use, and it poses a ton of limitations, for all that it offers.
quote:Original post by qurob

VB must be at least twice as fast as Java. And it''s way simpler! I started writing a Tetris game in VB, as one of my first games, and I got the majority of it done in one night. It took 2 nights to do that in Java, and I''m coming from a C++ background. Java is a nice tool, but it''s not the easiest thing to use, and it poses a ton of limitations, for all that it offers.


A ton of limitations?!? I think you don''t know your languages. VB is a primitive piece of crap - and yes I know it and have written lots of programs in it at work - because I had to and I hated it.

First, VB doesn''t have proper classes. It doesn''t support inheritance. It doesn''t support polymophy in general (UDT are not objects) and the ways you can organize large projects are a hell.

As as for speed. I think you should read the article I gave to Fovster. Without native code compilers you might be right about speed, but with them it is the same speed.

VB is good for baby programs - but for serious projects forget it. It sucks. And trust me. I really know my languages.

Ok, I will quit flaming, but I really hate when people come and say something they don''t know sh*t about.

Jacob Marner

There was this editor...for this game, they wrote it in Visual Basic....what game was it....oh yeah....Unreal!

VB can''t be THAT bad if they used it to make UnrealEd. Granted, it might not be the best it could be, but when''s the last time you seen a level editor for a highly rated 3D fps written in Java?

Enough about that. In my original post I was talking more about VB''s blazing compiled speed compared to Java''s speed. (oxymoron?)

This topic is closed to new replies.

Advertisement