Some thoughts on OpenTTD in Javascript

Got an idea for OpenTTD? Post it here!

Moderator: OpenTTD Developers

TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: Some thoughts on OpenTTD in Javascript

Post by TrueBrain »

Kogut wrote:(..)
Anyway - it is impossible and pointless to recreate OpenTTD in JavaScript(..)
Didn't read anything else in this thread, but I just wanted to jump on board of this one:

Let's start with a quote:

Code: Select all

“Never tell a young person that anything cannot be done. God may have been waiting centuries for someone ignorant enough of the impossible to do that very thing.” - G. M. Trevelyan
I think it is kinda hard to claim it is impossible, as for sure it is not. Pointless .. I don't understand why it would be? Was lemmings in DHTML pointless? Was Wolfenstein in Javascript pointless? I think not!

What is possible these days is incredible. I myself navigate often in this field, and I made some very kewl proof-of-concepts. For example, I made a full 3D landscape in WebGL. 2 years ago, every nay-sayer would have been the first to say: THAT WONT WORK! THAT WILL BE SLOW! And all the other default replies I am reading here. And yet here we are, able to fully render complete scenes in 3D, at 60+ FPS. So what is there to stop a game as complex as OpenTTD?

More to the point, it is a matter of progression. We now start to see more and more frameworks that allow easy creation of games in Javascript. We see Lemmings, Wolfestein, what is next? Of course there is a lot to do to make it quick and viable for a game like OpenTTD. It won't be a one-day-job, and it won't be easy. Modern browsers are doing a lot of testing with pre-compiled Javascript, even compiling it to byte-code and other tricks, to speed it up. My personal opinion? I would give it a year or 2 before a game like OpenTTD will run fine in Javascript.

Some other nice references to show how quick Javascript is going: Node.js is a pretty complex piece of software, purely written in Javascript, which runs like Python or any other modern scripting language. I am sure many people said it was impossible when they started .. yet they did it. I can keep going with countless examples of this :D


My point? Keep an open mind, and don't dismiss stuff with words like "impossible" and "pointless". You don't want to be that person that was too ignorant to see passed the present missing the future.


PS: 3 years ago I wrote a draft for OpenTTD in a browser. It was pretty kewl and in fact kinda worked .. but a big but: a client rendered PNGs which were streamed to the browser :D It's cheating, I know! But .. not the point ;)
PPS: of course it still requires progress and dedication for anything like this to work. I am purely making a remark on the strong terms used here which demotivate people, while it is unreasonable. As final example: I wrote a fully working 80386 DOS 16-bit decompiler, which outputs to fully compilable ANSI C. You have no clue how many people told me it was not possible, instead of answering the questions I was asking, or instead of just cheering me on for trying. 3 months later I released OpenDUNE, a result of this decompilation process. All I could say was: HA, to all those nay-sayers. I hope someone here will be able to say the same to you in 2 years or so, when he made OpenTTD in Javascript :P
PPPS: don't take it personal, I am just making a point here :)



@OP: your grf.js link doesn't work :'(
The only thing necessary for the triumph of evil is for good men to do nothing.
Reggino
Engineer
Engineer
Posts: 4
Joined: 10 Jun 2012 20:53

Re: Some thoughts on OpenTTD in Javascript

Post by Reggino »

Hmmm i managed to rewrite a part of openttd and get the isometric engine working, but while i was trying to set up some sort of demo page for you guys, i ran into this:

Http://www.play-ttd.com

Respect. I quit ;-)
Last edited by Reggino on 03 Jul 2012 20:17, edited 1 time in total.
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Some thoughts on OpenTTD in Javascript

Post by Terkhen »

Edit: I should read posts more carefully

Nice, it runs better than I would have expected :)

It fails to comply with many license requirements, though.
Last edited by Terkhen on 06 Jul 2012 16:23, edited 3 times in total.
oberhümer
Tycoon
Tycoon
Posts: 1283
Joined: 23 Oct 2009 19:35
Location: Here and there, sometime or another

Re: Some thoughts on OpenTTD in Javascript

Post by oberhümer »

It's not his/hers.

I'm not too impressed anyway, just generating a 2048-square map with a lot of mountains has made it hang showing the world generation screen for 20 minutes now. Trying something smaller.

ed: Now it's just hanging, period. Too much load on the server?
--- Licenses: GNU LGPL, version 2 or newer, code and graphics. CC-By-SA, graphics, alternatively. If you're using any, I'd like to hear about it --- Call them "track types" ---
--- Mostly inactive developer for: NuTracks - Central European Train Set --- Running/compiling for: Linux (x86) - Android - Windows (32/64 bit) ---

--- Need a file packer? 7-Zip --- BOINC - use your computing power to benefit science --- Block trackers, not ads --- Unix in dispersible pellets, the formula for the future. ---
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Some thoughts on OpenTTD in Javascript

Post by FooBar »

oberhümer wrote:I'm not too impressed anyway, just generating a 2048-square map with a lot of mountains has made it hang showing the world generation screen for 20 minutes now.
I tried a 1024x512 and got five subsequent timeout messages from my browser during the process. With 256x512 (my favourite map size) there was only one such message, but even then after map generation I had 90% CPU consumption with just a map and no vehicles. Adding one train and you could already see that it couldn't keep up with regular gamespeed.

So I'm not too impressed either, as you may have guessed :) It also doesn't surprise me that this doesn't work properly, but as a proof-of-concept I can applaud the effort. I'm not even going to try to run this on my phone :D

Either way, if it's really javascript, everything should run locally, so server load shouldn't be an issue then. At this time map generation times here are the same as before, just so you know.
User avatar
NekoMaster
Tycoon
Tycoon
Posts: 4001
Joined: 16 Aug 2008 22:26
Skype: neko-master
Location: Oshawa, Ontario, CANADA

Re: Some thoughts on OpenTTD in Javascript

Post by NekoMaster »

I think this is a step forward in proving OpenTTD can run in your browser. Its still new so I hope that more work will be done to stream line the code and fix errors. One thing i'd like to know is if it keeps a config file somewhere? I looked in my documents and appdata but nothings there
Image Proud Canadian Image
Nekomasters Projects! (Downloads available on BaNaNaS!) \(>^w^<)/
# NARS ADD-ON SET 2CC | 2cc Rapid Transit For Me! (2ccRTFM) | 2cc Wagons In NML (2ccWIN)
# NML Category System (Organize your GRFS!) <- TT-Forums Exclusive Download!
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: Some thoughts on OpenTTD in Javascript

Post by TrueBrain »

You guys are weird. Complaining it runs poorly while you put unrealistic expectations against it. I suggest trying a 128x128 map or something. On a decent computer (read: mine) it runs smooth. In fact, it runs so smooth, it shocked me; never expected this to happen already .. was more guessing it would happen in 2013 or 2014 or something. I really don't understand how people can reply with: I am not impressed. You really should be. Or at least try to be a bit more optimistic. It is always so easy to burn stuff down .. *sigh*.

The mechanics leading up to this type of website is impressive. There are complete tools that compile LLVM-bytecode to Javascript (so: any C/C++ application can be compiled to Javascript, kinda anyway). They even 'ported' libSDL. Very very impressive. The author of that site even made MIDI work. A rather nice touch. Now let's just hope he shares his patches etc.


@Neko: from what I can tell, files are stored in your local storage of your browser. I am unsure if you can concult it manually, but it is this new HTML5 thing, where Javascript can store files on the clientside. It appears that is also where savegames and configuration ends up. I might be wrong of course, as the code is rather unreadable (no s*** :P).
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Some thoughts on OpenTTD in Javascript

Post by FooBar »

TrueBrain wrote:I really don't understand how people can reply with: I am not impressed. You really should be.
Maybe I'm simply not easily impressed, but in this case I'm really not sure why I would be.

Remember that I'm looking at this from a player perspective, not a technological perspective. I'm comparing it with TTD in 1995, which could run 256x256 maps just fine on a computer with 32 MB ram, 2 MB video memory and a processor that you can keep up with walking. Now I see this javascript port that can't run a map only twice as big on a computer at least a 100 times faster. Why should I be impressed about that?
Starting from TTD and making it into what OpenTTD is now, now that's impressive. Taking OpenTTD and making it worse is not.

I'm sure you're "impression" comes from the technological side of all. Yes, of course it's a great feat that OpenTTD, of in fact any C/C++ code and compile it to javascript. It's a great proof-of-concept, but I'll be impressed when it's actually playable. For now I appreciate the effort that went into this.
User avatar
Lukenwolf
Engineer
Engineer
Posts: 81
Joined: 14 Jun 2012 12:09
Location: Nordschleifistan, Germanyland

Re: Some thoughts on OpenTTD in Javascript

Post by Lukenwolf »

TrueBrain wrote:You guys are weird. Complaining it runs poorly while you put unrealistic expectations against it. I suggest trying a 128x128 map or something. On a decent computer (read: mine) it runs smooth. In fact, it runs so smooth, it shocked me; never expected this to happen already .. was more guessing it would happen in 2013 or 2014 or something. I really don't understand how people can reply with: I am not impressed. You really should be. Or at least try to be a bit more optimistic. It is always so easy to burn stuff down .. *sigh*.
Sorry, mate, you may demand that I be impressed, but I'm not. First of all, porting OpenTTD to JavaScript as an idea doesn't impress me the least bit, because it is a rubbish idea to begin with. OpenTTD runs natively on most systems anyways, so why is there a need to port it to a language that is not well suited to achieve the goal.

Why doesn't any Formula One team bin the idea of making most of the car's component of carbon fibre and goes for steel instead? Simple - carbon fibre is better suited to do the job. I see no real gain in porting OpenTTD to a slow platform. As FooBar has already said. The original TTD ran well on computers that were beaten in the speed department by geology. OpenTTD runs decently on my laptop even with huge maps and 1000 trains. Why should I be impressed by a port that makes it run slower on the very same system?
Beer is not the answer. It's the question, and the answer is YES.
User avatar
kamnet
Moderator
Moderator
Posts: 8705
Joined: 28 Sep 2009 17:15
Location: Eastern KY
Contact:

Re: Some thoughts on OpenTTD in Javascript

Post by kamnet »

I'm impressed as well. From a end user standpoint, this is nice because I don't have to download or install anything, which is good if I'm using a computer where I don't have permission to install software, or I'm using a device which doesn't have a supported and compiled version (say, oh, your iPad?).

Yep, it's a sluggish beast right now, but it isn't unplayable. It can only get faster from here.
User avatar
Lukenwolf
Engineer
Engineer
Posts: 81
Joined: 14 Jun 2012 12:09
Location: Nordschleifistan, Germanyland

Re: Some thoughts on OpenTTD in Javascript

Post by Lukenwolf »

kamnet wrote: Yep, it's a sluggish beast right now, but it isn't unplayable. It can only get faster from here.
The problem is, that it WILL stay sluggish. JavaScript is an interpreted language, which can NEVER even remotely come close to the speed of a natively compiled binary and OpenTTD is simply too complex to run smoothly in an interpreted environment. And what the whole thing doesn't even yet touch is - how are you going to deal with 3rd party content, like AI's, NewGRF's and the like?
Everyone with enough experience in programming - especially if he or she learned it the proper way (Assembler, C, C++) instead of crutches like Java or .NET - will tell you that a real 100% port to JavaScript just isn't possible. You'll have trade-offs and things that are just not possible. Why do you think there are applications that are still written in C or C++, even though you could code them in C# in half the time? Simple - it's a question of speed and efficiency. C# generated applications are slower than C++ compiled applications, but in contrast to JavaScript, C# is still a BAE Concorde.
Beer is not the answer. It's the question, and the answer is YES.
User avatar
kamnet
Moderator
Moderator
Posts: 8705
Joined: 28 Sep 2009 17:15
Location: Eastern KY
Contact:

Re: Some thoughts on OpenTTD in Javascript

Post by kamnet »

Why does it need to come remotely close to the speed of a natively-compiled client? I don't play OpenTTD because it is fast, I play it because it is fun.
User avatar
Lukenwolf
Engineer
Engineer
Posts: 81
Joined: 14 Jun 2012 12:09
Location: Nordschleifistan, Germanyland

Re: Some thoughts on OpenTTD in Javascript

Post by Lukenwolf »

Because you need some speed to play OpenTTD at all? If you want to be restricted to 128x128 maps with maximum of 80 default vehicle trains on it, maybe that'll work one day, but it somehow doesn't quite relate to my idea of fun :roll:

There's more to OpenTTD than just displaying some map. You have to make the signalling work, trains have to move and the pathfinder has to do its job. The graphical aspect of OTTD is minor in contrast to the amount of CPU time that is used up by numerical and logical calculations. Trying to do that in Javascript is like trying to manhandle a cow up the fire stairs. You might get the job done, but the result won't be particularly pretty.

And as far as I could see, it isn't even a proper port yet. First of all, it won't work on Internet Exploder behind a proxy and that doesn't even come to the technical aspects. As far as I could see, it is C++ code compiled to LLVM code, which means that's the first time you'll trade-off some efficiency (read: it becomes slower) and then it is converted to JavaScript code, which makes it massively slower. Have you seen the generated Javascript code? It makes stenographed modem noise look readable - you wouldn't even be able to modify anything.

I'm still convinced that a really working variant of OpenTTD in Javascript is not possible.
Beer is not the answer. It's the question, and the answer is YES.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Some thoughts on OpenTTD in Javascript

Post by Kogut »

Kogut wrote:Anyway - it is impossible and pointless to recreate OpenTTD in JavaScript
Thanks for proving me wrong!
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4766
Joined: 09 Sep 2007 05:03
Location: home

Re: Some thoughts on OpenTTD in Javascript

Post by Alberth »

Lukenwolf wrote:I'm still convinced that a really working variant of OpenTTD in Javascript is not possible.
So what?
Not everything has to be immediately useful (nobody is getting paid for results). We are all here to have fun in one way or the other. Whether the result is usable in the end, is not really relevant some times.

Besides, the only way to make progress in areas like this is to push against the boundaries and see how flexible they are (or not).


As another example: http://dmitry.co/index.php?p=./04.Thoug ... 0on%208bit
This guy is running Linux on a 8 bit micro controller without MMU. Current state: starting /bin/bash from init takes 2 hours.

Is it useful? No chance whatsoever.

Is weird, wonderful, and fun? I betch ya!

My guess is that he is having loads of wonderful new ideas to try out, and having lots of fun while doing this project.
I also shows that the impossible is much less impossible than we all think.
User avatar
CMircea
Chairman
Chairman
Posts: 887
Joined: 29 Dec 2006 14:05

Re: Some thoughts on OpenTTD in Javascript

Post by CMircea »

Don't forget Atwood's law!
Any application that can be written in JavaScript, will eventually be written in JavaScript.
caiiiycuk
Engineer
Engineer
Posts: 3
Joined: 08 Jul 2012 03:44

Re: Some thoughts on OpenTTD in Javascript

Post by caiiiycuk »

Hi all. I am ported open ttd in javascript with emscripten (http://play-ttd.com). I am glad that my work is interesting for the community.
In future i planned, to do much work on project.

I planned:
* Performance improvements
* Fixing bugs
* Add sound effects (only music now works)
* Open*FX
* Add social element

Also i have some little patches to OpenTTD and i should contribute it.

Who knows russian language may read article about porting job: http://caiiiycuk.info/ttd-online/

OpenTTD ported in configuration:
* Single-thread mode
* little-endian
* no network features
* video: patched SDL
* new music driver
* new mechanism for saving games
* new resource locator
User avatar
kamnet
Moderator
Moderator
Posts: 8705
Joined: 28 Sep 2009 17:15
Location: Eastern KY
Contact:

Re: Some thoughts on OpenTTD in Javascript

Post by kamnet »

Welcome to the OpenTTD community, and thank you for your contributions!
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Some thoughts on OpenTTD in Javascript

Post by Kogut »

Terkhen wrote:It fails to comply with many license requirements, though.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Post Reply

Return to “OpenTTD Suggestions”

Who is online

Users browsing this forum: No registered users and 3 guests