Transport Tycoon goes Java

Hi,

I am trying to make a java version of the very cool and addictive game Transport Tycoon (Deluxe)
But I am having trouble with the graphics as i dont get a high fps
so I look for ppl who want to help with me with the graphics engine bcz mine isnt so performant

If you would like to help you can post it here or send me a private message

thx alot

PS: if u dont know transport tycoon go to http://openttd.org for some screens and more

Wow! I liked TT very much. I was addicted to it.
What are you comparing your code with when you say your graphics engine isn’t so performant?
Are you using Java2D, or some openGL bindings?
I have really little time nowdays, but maybe I could help with some issues.
cheers!

I am using full-screen exclusive awt mode at the moment but with that comes i have to redraw
my whole screen each frame. It can contain 1000 tiles ( at 1024*768) so this takes so much time
the game is beginning to run really slow and get only 30 fps orso.

30fps is playable but if u want it to get faster then try switching to opengl thru lwjgl. It will be much faster.

as i explained in another topic i tried using xith3d to opengl accelerate it but my images get screwed up
so my map looks so ugly. Java2d gives the best graphical result but it is very slow

Xith3D != LWJGL

it can use that renderer so in fact they use the same things. Same goes for jogl

if A uses B, then A is B? ::slight_smile:

And if your images get screwed up, that’s a bug in your code, that’s not due to hardware acceleration.

why would that be a bug in my code?

i just load the texture and display it not much more i can do with it

this is my java2D version http://users.skynet.be/fa006997/Test.jar
it render 250 frames and then gives you the fps

I didnt suggest that it was. but is Xith3D really suitable for what hes trying to do? just using ogl on its own would be simpler and probly faster i think.

Maybe you arent loading it right?

Yes, JOGL/LWJGL is what he needs, not a scene-graph like Xith3D, but he seems stuck in the idea it’s all the same.

I run the test.jar and I think Java2D is capable of rendering many more sprites per frame.
There are some important points to note however, so for example to make them hardware accelerated by Java.
Many of these notes have been discuessed in the forum’s 2D threads. I’m pretty sure some Java2D experts read so please: comment. :slight_smile: Thanks.
Kevin’s currently moving, so we’ll have to wait for his comments. Still his (?) FAQ is nice and helpful IMO: http://wiki.java.net/bin/view/Games/FAQ#2D_Rendering

Just in case the correct way to use Java2D doesn’t bring the performance you need then I’d go the OpenGL route. However, I can’t imagine you’d need the direct metal OpenGL way to do a isometric simulation.

P.S. Chris Sawyer rules. Together with D. Braben one of the - if not the - brightest minds in the entire video gaming industry. Man, he wrote the entire Rollercoaster Tycoon in Assembler. A real Scottish braveheart. :slight_smile:

I have made some small apps with jogl before so i should try and do that then?

For what is worth the following code is used to make a tile texture i did in xith3d (maybe then you why its complety different output):


	private Shape3D createTile (Point3f[] coords)
	{
	    return new Shape3D(getGeometry(coords), getAppearance());
	}
	
	private Geometry getGeometry(Point3f[] coords)
	{
        // Define Texture coords for a square shape
        TexCoord2f[] texCoords = new TexCoord2f[] {
             new TexCoord2f(0f, 0f),
             new TexCoord2f(1f, 0f),
             new TexCoord2f(1f, 1f),
             new TexCoord2f(0f, 1f) 
        };
        
        QuadArray g = new QuadArray(coords.length, GeometryArray.COORDINATES |
                                    			   GeometryArray.TEXTURE_COORDINATE_2);
        g.setCoordinates(0, coords);
        g.setTextureCoordinates(0, 0, texCoords);
          
        return g;
	}

	 private Appearance getAppearance()
	 {			   	
		BufferedImage bi = null;
	   	try {
			
			bi = ImageIO.read( new File( "./Images/tile3.png" ));
		}
		catch (java.io.IOException ioe) { ioe.printStackTrace(); }   	
		Texture2D texture = (Texture2D)TextureLoader.getInstance().createTexture(bi, false);
		
	   	TransparencyAttributes transparencyAttributes = new TransparencyAttributes();
	   	transparencyAttributes.setTransparencyMode(transparencyAttributes.BLENDED);
	   	transparencyAttributes.setDstBlendFunction(transparencyAttributes.BLEND_ONE);
	   	transparencyAttributes.setSrcBlendFunction(transparencyAttributes.BLEND_SRC_ALPHA);

	   	RenderingAttributes renderingAttributes = new RenderingAttributes();
	   	renderingAttributes.setDepthBufferEnable(false);
	   	
	   	TextureAttributes textureAttributes = new TextureAttributes();
	   	textureAttributes.setTextureMode(textureAttributes.MODULATE);
	   	textureAttributes.setPerspectiveCorrectionMode(textureAttributes.NICEST);

	   	Appearance    texturedAppearance = new Appearance();
	   	texturedAppearance.setTexture(texture);
	   	texturedAppearance.setTextureAttributes(textureAttributes);
	   	texturedAppearance.setRenderingAttributes(renderingAttributes);
	   	texturedAppearance.setTransparencyAttributes(transparencyAttributes);

	   	return texturedAppearance;
	 }

@ Chris Sawyer rules. Together with D. Braben one of the - if not the - brightest minds in the entire video gaming industry. Man, he wrote the entire Rollercoaster Tycoon in Assembler. A real Scottish braveheart. :slight_smile:

TT was completely written in assembler, dont know about rt but it is true he roels :slight_smile:

I have uploaded a new java2d version which gives me a good 75 fps

1280 * 1024:http://users.skynet.be/fa006997/Test_1280.jar
1024 * 768: http://users.skynet.be/fa006997/Test_1024.jar

Let me know what ya think

also i am looking for ppl to help with the multiplayer part because i cant run any of those
netwerk appz :s

For any one who is interested I will upload a newer version regullary on this site:

studweb.hogent.be/~032660sl/TTGJ/

I’ve tested the newer benchmarks and still think it’s somewhat slow, but well, I’m no Java2D expert.
From what I’ve seen from Kevin’s and other’s Java2D examplesI think it should go much faster. Could any Java2D expert please comment?

My own hobby 2d project (a parallax side scroller) is being done in OpenGL (JOGL) with an 1:1 orthogonal view (so no scaling of the bitmap textures) but just because the game’s main task (> 75%) is to move textures around on the screen and the whole point is smoothly moving tons of large sprites. :slight_smile:

This won’t be the case for your Tycoon game, where just a small amount of the game’s performance goes into drawing the graphics (25% maybe?).
So I wouldn’t worry too much about graphics speed. Because by the time you finish the other parts of your game in Java you’ll have evaluated a fast and neat way to plot them in Java2D.
And… of course it’s a good idea to encapsulate your internal graphics system so that you can always decide to change the final plotting class(es) of the sprites.

Good luck with your project! There are many Tycoon fans out there.

Btw, I suggest to open another thread on the Java2D sub-forum here: http://www.java-gaming.org/forums/index.php?board=15.0
Not linked to the exact type of the game, but “just” something like: how to do fast isometric plotting with Java2D or such…

well it allways needs optimization but some ppl are against threading and other for but i dont know
how much they slow down the system

I will also uplad containing the source code as the current version

Had a look at the source to the first example, and have to say you are doing some things in very peculiar ways.

Your fps counting for starters is totally crazy, and inaccurate.

Creation of your images is odd too (Transparency class)
why not just load the images with ImageIO, and copy them to a BufferedImage [managed] returned from GraphicsConfiguration.createCompatibleImage.
You shouldn’t need to use Toolkit.createImage(ImageProducer) ever.

your VolatileImages class is also fundamentally flawed, and quite useless.

now for something different…
TTD is indeed awesome! My friends and me play OpenTTD almost every evening on the Internet. So I find the idea to port it Java pretty cool and I would be happy to help you concerning the GUI, which makes a pretty big part of TTD. I could provide the in-game window frames, Widgets like tables, text fields, buttons etc.

However, OpenTTD is constantly enhanced and the OpenTTD-Guys drop builds like I change my shorts. Which is why I would like to ask on which version of OpenTTD you rely. And how do you intend to keep up with the enhancements? Or do you just fork from an old version?

Johannes