java?

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Vano2000
Engineer
Engineer
Posts: 20
Joined: 14 Jul 2006 19:20
Location: SITE UofO

java?

Post by Vano2000 »

i was wondering if it would be possible to translate the current code into java.
I know it would be a lot of work so it's not a request, just a question.
how different is the current syntax from java syntax and is it possible at all to translate it to java.
i'm currently studying java, getting my degree, so i will soo start looking for ways to translate this code into java. but before i even start thinking about it i just want to know if it's possible?
Image
Click Here And Kill Some One
<- this is a link to an online browser-type game, feel free to click
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post by DaleStan »

Possible? Of course. Everything's possible.

The real question is whether or not it would run with anything vaguely resembling a framerate.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
Vano2000
Engineer
Engineer
Posts: 20
Joined: 14 Jul 2006 19:20
Location: SITE UofO

Post by Vano2000 »

yeah i have heard that java is somewhat slower, but will it really have a huge impact on the speed and performance
Image
Click Here And Kill Some One
<- this is a link to an online browser-type game, feel free to click
Sleepie
Director
Director
Posts: 534
Joined: 03 Jan 2007 08:46
Location: Germany

Post by Sleepie »

I think the real question is Why you would do it? As Dalestan said, everything is possible, but what would be the benefit of doing it?
Denke nie gedacht zu haben, denn das Denken der Gedanken ist gedankenloses Denken.
Wiki Page/Talk, Member of the OpenTTD Scenarios Team
Looking for OpenTTD scenarios? - Here's a List of player-made scenarios. Please help us grow the database with your contributions.
User avatar
Born Acorn
Tycoon
Tycoon
Posts: 7596
Joined: 10 Dec 2002 20:36
Skype: bornacorn
Location: Wrexham, Wales
Contact:

Post by Born Acorn »

The only reason I can think of is that a lot of people learn java in schools and colleges, so a lot more people know it.
Image
Vloris
Engineer
Engineer
Posts: 108
Joined: 13 Jan 2007 22:39
Location: Enschede, The Netherlands
Contact:

Post by Vloris »

That sounds to me more like another reason not to convert it to java: with that many people understanding (or at least thinking they do understand) java it's much harder to guide the development in a controlled way :)
User avatar
charlieg
Transport Coordinator
Transport Coordinator
Posts: 323
Joined: 08 Oct 2003 14:07
Contact:

Post by charlieg »

Development is controlled by the project leaders through savvy SVN commit priveleges, so that's a complete misdirection to suggest more potential contributors is a bad thing.

Also Java GFX performance these days is pretty good; it's a bit of a myth that it's so bad, a myth perpetuated by people who don't know how to do GFX programming in Java properly.

Still, the notion of moving to Java for OTTD is fantasy at best. The work involved is astronomical; you are talking basically a ground up redesign and rewrite of the code because the current OTTD codebase does not lend itself at all to the programming concepts fundamental to Java.

The only [barely] realistic path would be for a move to C++ but even then I don't know if that would bring any tangible benefits.

I would give up on this. You are better off starting your own version / own game if you want to use Java.
Open source tycoon games
--
Free Gamer - open source and Free Software games
FreeGameDev forums - open source game development community
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Post by richk67 »

... would be a move to C++ ...

I thought we already were ;)

OK, not everything is in classes and objects etc yet, but the code is now .cpp and .hpp, and some parts (YAPF) are already C++ anyway.
OTTD NewGRF_ports. Add an airport design via newgrf.Superceded by Yexo's NewGrf Airports 2
Want to organise your trains? Try Routemarkers.
--- ==== --- === --- === ---
Firework Photography
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

Java is not happening. The only real benefit would be to be able to use it on several platforms where C(++) code needs porting. Since we already did the porting part, we will not benefit from Java at all. It's slower to use the byte code than the CPU specific code nomatter how well you optimise it, so it will always have a speed impact to use Java instead.

A lot of people want to use Java because they think it's easier, but I'm not so sure. If the time spend on learning Java were spent on C instead, that person would become a C coder and will be able to do a lot of nice C code. If not, then that person spent too little time with Java to make nice Java code.
User avatar
Ailure
Route Supervisor
Route Supervisor
Posts: 435
Joined: 26 Apr 2005 19:06
Location: Sweden

Post by Ailure »

While Java is good, have a future it's... well. Java have A LOT of flaws that would make a game originally programmed in assembly a bit slower. ;) There's no good generics, things like enums is ugh. Simple Enums as they work in C++ is non-existant.

Performance isn't as bad as people want to make it though, as while Java is slower than C++, it's just is slightly slower than C++ in certain cases. Java tends to have extra overhead, and it's VM likes to take reserve a quite bit memory. Besides I suspect openTTD is programmed in a such way that wouldn't work well with Java. :P

Besides C++ is flexible enough, while I like Java for it's flaws I tend to prefer C++ for stuff such as openTTD.

Java and C++ is very similar code-wise anyway. I don't really see a reason porting over. If you feel comfortable, you should be able to handle c++ after a few hours, biggest difference is mostly stuff like pointers, memory managment and some generic programming.
Last edited by Ailure on 10 Feb 2007 00:44, edited 1 time in total.
Vano2000
Engineer
Engineer
Posts: 20
Joined: 14 Jul 2006 19:20
Location: SITE UofO

Post by Vano2000 »

so what is the code used now in ottd? C, C++ ???
Image
Click Here And Kill Some One
<- this is a link to an online browser-type game, feel free to click
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post by DaleStan »

Mostly, it's C compiled with a C++ compiler.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
Sacro
Tycoon
Tycoon
Posts: 1145
Joined: 18 Jun 2005 21:08
Location: Here
Contact:

Post by Sacro »

Ailure wrote:as while Java is slower than Java
Please don't make my brain hurt...
We Am De Best

Host of ThroughTheTube site
Mchl
Director
Director
Posts: 611
Joined: 05 Jan 2007 15:50
Location: Poland
Contact:

Post by Mchl »

The main benefit I see in such enterprise, is that the fully object oriented Java code could be then converted back to C++.
But would it do any good?

As one of my colleagues put it:' Java. Yeah. User friendly etc. Everything's an object. Even things that shouldn't be or by definition cannot be objects.' :wink:

Vano2000: You'd probably spend your time better by writing JavaTTD from scratch... Or by learning these few (ok, I know there are many, but most common syntax is almost the same) differences between C, C++ and Java and start contributing here :)
KeeperOfTheSoul
Engineer
Engineer
Posts: 1
Joined: 10 Feb 2007 00:08

Post by KeeperOfTheSoul »

You really should be studying how do program as opposed to a specific language. A language can only really be considered useful as a working example. A language really is the easy bit, the difficult bit is understanding how the application works and fits together. By the time you've read through enough of the code to work that out you'd have most likly picked up C by then from just reading through enough code.

I myself havn't done much with C/C++ and currently wouldn't be able to write an app from scratch in this language. This doesn't really hinder me too much though, I just take slightly longer to work things out as I learn new things about the language. As I've said, the hard bit is working out how things fit together.

So really if your interested in the project your time would probaly best be spent getting a broader range of languages so you can understand some of the basic differences between them.

It isn't too difficult to create some of the simpler patches to fix small anoyances (such as I didn't like the way changing the window size would affect the fullscreen size). So I'd advise you just jump right in and learn something new, you'll get enough time with Java on the course.
User avatar
Ailure
Route Supervisor
Route Supervisor
Posts: 435
Joined: 26 Apr 2005 19:06
Location: Sweden

Post by Ailure »

Sacro wrote:
Ailure wrote:as while Java is slower than Java
Please don't make my brain hurt...
Grr, I wish I stop making those stupid typos.

Fixed for clarity.
KUDr
OpenTTD Developer
OpenTTD Developer
Posts: 219
Joined: 11 Jan 2006 21:36
Location: Czech Republic

Post by KUDr »

In C++ you can make the same constructs like in Java plus much more (low level things). What would be different when doing such game in Java?

● You can still do dirty hacks in Java that will break original design, you can still use hard-to-read constructs in Java, etc..
● What you can't do in Java are low level optimizations to minimize memory and CPU load.
● Object arrays are arrays of managed pointers, local variables of type class are managed pointers as well and objects are always allocated from gc managed heap. They are destroyed later (in unpredicable way). Such non-deterministic core behavior would not help us to make the code better or faster.
● Most powerfull features of Java (synchronization, dynamic bindings, reflection package, etc.) would not help us a lot as they are slow. Maybe for the future processors (8 and more cores) it would make sense (if we find a way how to use more threads in this game).
Vano2000
Engineer
Engineer
Posts: 20
Joined: 14 Jul 2006 19:20
Location: SITE UofO

Post by Vano2000 »

so what you guys are saying is
Java = bad,
C++ = good.
Got it. I was learning C++ before i started java so i gues i'll just continue C++
thx
Image
Click Here And Kill Some One
<- this is a link to an online browser-type game, feel free to click
KUDr
OpenTTD Developer
OpenTTD Developer
Posts: 219
Joined: 11 Jan 2006 21:36
Location: Czech Republic

Post by KUDr »

No, Java is not bad (i like Java). Just not the best one for such game working with tons of low level data in real time with limited CPU/memory (in order to run on old HW).
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

Actually I would say that the most important reason not to change the programming language is that it would take ages to do so. Even changing to C++ took a while and those two are so similar that C++ can compile most C code.
Now that we have C++ (with the option of adding C code if we like as long as we link it in C++ mode), we should do rather nicely. No need to change anything.

Note: even though the game is now written in C++, it's still the same code (more or less) as when it was written in C, so it's basically C with a few C++ additions. It's not really an objective design as we don't use classes and inheritage (yet?). Any C coder without knowing C++ can still work on it.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Amazon [Bot] and 12 guests