Ferrari3D - simple racing game

About two years ago I made a simple racing game in Java 3D for a school course called Advanced 3D. Although the result looked reasonable, especially as I had only six weeks to make it, it suffered from always consuming 200+ mb of memory and having framerates of 15-20. A few months ago I discovered jMonkeyEngine, and quickly became impressed with its set of features. As I no longer have the time to create an entirely new game I decided to port Ferrari3D to JME. The result is quite impressive, it looks and plays MUCH better and smoother than the original.



The game itself is rather basic though, although all the standard stuff (multiple cameras, AI, track records) is there. Multiplayer is only via LAN through standard sockets, I haven

I can't keep on the track in curves because the car does not steer enough,

It seem not even the AI manages to keep on the Track :wink:

And when i crash into a wall, i am Stuck. Somehow i can't drive backwards.



Otherwise it looks nice, keep working on it, i am sure it will be fun to play after a few things have been fixed.

Well, you could always brake before a corner. This isn't Mario Kart :wink: I agree with you that the AI is poor, I

but but but, i do brake before the the curve :slight_smile:

But even when i drive 10 km/h i can't keep on the track in the first S-Curve.

Another thing is that when you break, you can't steer at the same time.

Thanks for sharing your experiences in porting a game across to jME. :)  It looks nice.  If you can grab some video footage, post it on youtube so I can add it to the jME play list :slight_smile:

I

mpeg4 and avi both work ok… (for best results use 640x480)

Again a poor performance game under Mac OS X (7 FPS, track disapears frequently, probably because of the poor framerate). I guess you use swingui.

Ender said:

Again a poor performance game under Mac OS X (7 FPS, track disapears frequently, probably because of the poor framerate). I guess you use swingui.


That surprised me a bit. I have a Mac Mini myself and I get framerates between 25 and 30. Which kind of Mac do you have, and are you using Tiger or Leopard? It's bizarre how low your framerates are, I tested on a 4-year old laptop and the framerate was almost never below 20.

Edit: What could happen is that your resolution is so high that the painting of the HUD takes up an unreasonable amount of time. Could you try running in non-fullscreen mode, so that the HUD is 800x128?

I use a quad in ortho mode to paint the GUI, as described in the tutorial "HUDs for the total n00b", although I do use Java 2D to paint the actual image on the HUD. The menus are in Swing, but they are in a separate window that is destroyed when the game is started.

Also, videos are now at http://www.youtube.com/watch?v=o4_ILn5SjXM and http://www.youtube.com/watch?v=08Eagw5WcoE . Thank MEncoder for the blurryness.

Unbelievable!!! I have a Mac Pro 2 * Quad Core 3 GHz, 4 GB RAM, a ATI Radeon X1900 XT with 512 MB of VRAM, and Tiger 10.4.11.

Java version is:

$ java -version
java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05-241)
Java HotSpot(TM) Client VM (build 1.5.0_13-121, mixed mode, sharing)



Is your Mac Mini a Intel Mac Mini or a PPC Mac Mini?

Every other 3D applications run really smooth. I reached 127 FPS with World of Warcraft full screen and all the graphics and audio settings at the max.

EDIT: I explored the libraries folder and I discovered that openal.dylib is not Universal, it is a PowerPC binary. Do you think that it could be the cause?

Ok. I tested the openal.dylib sobstituting it with a Universal version taken by MacPorts but this not resolved the problem.



Anyway after playing a little more with it I can make this considerations.


  1. At the start the track is always invisible and I have poor framerate.
  2. When framerate is poor (about 5-7 FPS), the track is allways invisible and I only see other cars, other objects in the scene and a light-gray background color. I guess the two things are related.
  3. Framerate is not allways 5-7 FPS, there are areas of the track where I see the track and I also have about 60-87 FPS.



    I guess 2 possible reasons.


  4. It could be something that is related to acceleration of the car. Even if it is strange that at the beginning the problem appears even if my car is almost 0 velocity.
  5. Or it could be something related to some lighting effect. I notice that there is a Sun flare…



    … any other ideas?

First of all, thank you for your incredibly detailed post(s)!



My Mac Mini has a 1.66ghz Core Duo, so Intel, and 1 gb of memory. To be honest I only know one other person with a Mac, and he has good framerates as well on his MBP with a Core 2 Duo. The first question I would like to ask is how you actually run the game, as I didn't make an application bundle before. You can get that at http://www.dennisbijlsma.com/data/ferrari3d/ferrari3d_macosx.zip.



The first thing that I would guess from the combination of poor framerates and graphical problems, is that some operation is not supported by your graphics card. If you look at the two screenshots on the right, where everything appears to be normal, the framerate is 70 - 90, which seems reasonable for your uber-computer. It could be something with the bumpmap that the track uses, although it does seem to look OK in the last screenshot. Another possibility is that sorting Zs is really slow for some reason.



As for loading, it's much faster when you're using Java 6, which is only available as a beta for Mac unfortunately. From the profiler shot I see that loading the circuit takes up 11 seconds. Even though that's by far the largest piece of geometry I'll check if something is taking up an unreasonable amount of time there.

keeskist said:
The first question I would like to ask is how you actually run the game, as I didn't make an application bundle before. You can get that at http://www.dennisbijlsma.com/data/ferrari3d/ferrari3d_macosx.zip.


I used a command line instruction (now converted to a bash script).

if [ "$1" = "noprof" ] ; then
  echo "Run ferrari3d alone."
  java -jar -Xmx256m -classpath ./libraries/jme.jar:./libraries/lwjgl.jar:./libraries/platinumlaf2.jar:./libraries/quaqua.jar:./libraries/utilities.jar -Djava.library.path=./libraries ferrari3d.jar
elif [ "$1" != "noprof" ] ; then
  echo "Run ferrari3d with profiler."
  java -jar -Xmx256m -classpath ./libraries/jme.jar:./libraries/lwjgl.jar:./libraries/platinumlaf2.jar:./libraries/quaqua.jar:./libraries/utilities.jar -Djava.library.path=./libraries -javaagent:/Applications/profiler4j-1.0-beta2/agent.jar ferrari3d.jar
fi



keeskist said:
The first thing that I would guess from the combination of poor framerates and graphical problems, is that some operation is not supported by your graphics card.


It is exactly the same idea I have. But I don't know how to isolate the problem. Generally JMEDesktop is a jME feature that gives a lot of problems with Mac. So, at the beginning I guessed that it could be the reason. But, after those experiments I changed my idea and I think that is something related to 3D GL, as to say LWGJL or jME.

keeskist said:
It could be something with the bumpmap that the track uses, although it does seem to look OK in the last screenshot. Another possibility is that sorting Zs is really slow for some reason.


The important thing is the strange behaviour. There is something that triggers only if I turn right relative to the track direction. Anyway I will test it more to see what exactly happens there.
If we discover any bug related to some Mac OS configuration in LWJGL and/or jME I will try to understand if I can fix it. Or if the authors can fix it for me.

keeskist said:
From the profiler shot I see that loading the circuit takes up 11 seconds. Even though that's by far the largest piece of geometry I'll check if something is taking up an unreasonable amount of time there.


Thanks.

I tested the Mac Bundle. And I got the same problems.



I made just one more test. I tried to invert the direction I run through the track. This confirmed that there is some computation triggered only if I point the car towards inner side of the track "ring".







The 1st and 2nd images shows again the limit-orientation (this time I tried remain in the track lane, to see if the bump map could cause the problem, but it do not). Beyond the limit-orientation something is triggered. The 3rd image shows as the same situation is reproduced if I reverse direction. Outer side of the track ring is safe, while inner side triggers the problem.

There is an exception to this. In the 4th image you can see a circle I drew (green angles are safe, orange are buggy) just before the 3rd curve, where "trees wall" is closer to the inner side of the track. There there is a little "umbrella" zone if I stay close to the "trees wall".

I was thinking of something related to the Sun flare or some other lights issue.

I will investigate also in the jME and LWJGL code...

I would say that this is either some fault by me, or an incorrect OBJ or JME file with one of the models.



Perhaps you could just remove some objects to see what the problem is. The model is stored in <installDir>/circuits/monza/monza.f3d, which is just an XML file with a weird name. You can just delete one of the <node> tags and the game will still run. The most likely candidates to be causing problems are "monza", which is the grass/dirt/etc, "tarmac", and the trees node who's name I have forgotten.

Thanks for the tips. I will try to remove them. Soon I will feedback…

I think I've found the problem - tarmac.obj. This file takes up more loading time than all other files combined. It seems that 3ds max produces a problematic OBJ file. Could you try removing this file from the circuit (as described in my previous post) and see if all problems go away?

No. It is not Tarmac. I commented it out in the XML code but I still have problems.


<!--<node id="tarmac" type="model">
   <position>0.0,0.0,0.0</position>
   <rotation>0.0,0.0,0.0</rotation>
   <scale>1.0</scale>
   <url>tarmac.obj</url>
   <material>#FFFFFF,100,tarmac_texture.jpg,false,tarmac_texture.jpg,none</material>
   <shader>none</shader>
</node>-->



Edit: I just tried to comment out everything except the monza node. And now it works great! Smooth as like as silk! The only thing I do not understand is the track asphalt texture disappeared. ??? There is another node that is responsible for track asphalt bump map?

It could be some texture/shader/material/lightting problem instead of a geometry problem.



I will try to re-enable one by one and see if I can isolate the model responsible of that problem.

I improved the graphics somewhat and the AI also behaves much better now. Something was definately wrong with the tarmac texture coordinates, it seems that 3ds max produces an incorrect OBJ file for this model. Removing the texture (hopefully temporarily) slashed my loading time to about 5 seconds. Also, the framerate is now around 40-50 on my Mac Mini, which is reasonable.



The download URLs remain unchanged:



Windows: Windows: http://www.dennisbijlsma.com/data/ferrari3d/ferrari3d_windows.zip

Mac OS X: Windows: http://www.dennisbijlsma.com/data/ferrari3d/ferrari3d_macosx.zip