Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Tue Mar 19, 2019 5:05 am

All times are UTC

Post new topic  Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Sun Mar 23, 2014 8:50 pm 

Joined: Sun Mar 23, 2014 7:07 pm
Posts: 2
Skype: Same as nick
Location: St. Petersburg, Russia
Hello, OpenTTD developers and others!
I am currently working on OpenTTD port to flash. Flash has a poorly supported project called "Crossbridge" that provides a toolchain for compiling c/c++ code into llvm, which allows you to execute it in flash player.
However, flash is VERY different in comparison to OS so basically everything should be simulated: Filesystem, video system, sound, input, etc.
Also, crossbridge is buggy and i'm not the c/c++ developer (i'm ActionScript developer).
Also, the linker... It is sooo sloooow. Something changed? Wait 10 minutes pls...
And also, the lack of debugging capabilities

I want to give you a quick pick on what is going on :)
>>> You may check my current progress HERE <<<
You need to allow Flash to store data on your PC (small window opens at first start). This storage is used to keep your saves, config, and resources (like grf) in future.
I've packaged OpenGFX and a bunch of AIs
I recommend you to change interface-interaction-"Reverse scroll direction" option as the game loads.

Okay, now more details:
Current condition
Working alpha. Some hard things are done, a lot more to do.
The game is laggy at the beginning. Flash has some dynamic bytecode process - maybe JIT, baybe some security check. So, first execution of every piece of code is slow. You can see this behavior when you are dragging map - it lags but only at start.

I've used SDL that comes with crossbridge. It works, but it is suboptimal (very). It simulates VGL VESA display, and forms image in memory (not even in actual memory but in a virtual machine memory).
The other possibility is to implement custom SDL backend (is hard because SDL is not as simple as it called)
Or to implement custom video driver inside OpenTTD, which seems easier, if only someone explains me how openttd blitter works

Input is done also through VGL
Mouse is working, but it delays a bit
Keyboard is partially working. Command keys are working (arrows for example) while letters don't. Console could be opened by pressing 1.

Virtual file system
Is done. Any changed files stored in flash cache (LocalStorage) on your PC.

Not done at all. Is possible but I currently have no idea.

Not done at all. Also possible (flash has support of TCP) but also flash has a very annoying security system - Before establishing a connection flash sends a security request and server must respond and allow access. So:
- To connect to openttd servers, openttd server musl listen another port and respond to flash security requests
- Same with online content distribution system
- It is possible to implement content loading with browser and transferring it to flash using ExternalInterface. But only http direct links and no tcp sockets. However, in this case, it may be required to modify openttd online content loader significantly.

Game sometimes freezes competely. Most likely when doing some long and heavy operation but it can freeze at any time.
Also game used to crash 100% reproducible when displaying news in function news_gui.cpp - NewsTypeData::GetDisplay. When i've added logs to this function to determine crash source, crashes disappears. I've removed logs - crashes appears again. So i kept logs for now.

Flash philosophy is very different in comparison to C++. While in c++ all code executes inside main() function, flash uses asynchronousity, events and frames (you execute code only within a frame).
There are two ways to run c++ application. The most simple one is to run it in separate thread (this does not require any modification to c++ code). But flash is single-threaded, so "another thread" is basically another copy of flash runtime that does not share memory and interacts with main "thread" via messages and some other stuff. This way it is very memory-inefficient (every "thread" uses about 100 mb of ram) and it starts slowly. That's why i compiled openttd without threads, but i need to use one to run c++ code.
Another way is to initialize everything in main() and call ActionScript code (as last main() command) which never returns. Flash will continue work as normal and it is possible to call another function every once in a while, which will be a single pass of main game loop. This would be much more reliable but it requires mass changes to main(). main() should be VERY simple, just basic initialization. Any other initialization should be split in parts so code can interrupt between parts.

I will add sources to GitHub, maybe tomorrow.
To save your settings you must exit game, even if it does no sense in browser :D

Last edited by ShadowTheAge on Sun Mar 23, 2014 11:20 pm, edited 2 times in total.

PostPosted: Sun Mar 23, 2014 9:03 pm 
Transport Coordinator
Transport Coordinator

Joined: Mon Jul 23, 2007 3:13 pm
Posts: 294
Location: Somewhere in this page

That's going to make ICT lessons a little more bearable...

It's not exactly butter-smooth, but it is certainly playable.


Yay! I'm back! Did you miss me?


I thought not.

PostPosted: Sun Mar 23, 2014 10:31 pm 
Transport Coordinator
Transport Coordinator

Joined: Wed Jul 16, 2003 6:33 pm
Posts: 285
Nice :)
To bad it says no network. But it runs okay in my chromium browser (iron).
Maybe it would be best to pinpoint some setting like size of map etc.
So you can play with it nicely.
If the network code works someday it could be some nice mmo browser game :)
first time i would consider to play online *lol*

Hope to see more. Good job so far. :bow:

PostPosted: Sun Mar 23, 2014 11:08 pm 

Joined: Sun Mar 23, 2014 7:07 pm
Posts: 2
Skype: Same as nick
Location: St. Petersburg, Russia
Glad you like it!

As I said, map-drag lag disappears in a few minutes. It is possible to speed up video with a custom driver, but because it works now it is a low-priority task

Unfortunately, network is the most trickiest part here. It is not enough to pass network through flash, content and game servers should also handle connection from flash as necessary

PostPosted: Sun Mar 23, 2014 11:38 pm 
User avatar

Joined: Tue Jul 12, 2011 12:09 pm
Posts: 1534
Location: St Ives, Cambs, UK
A similar thing has already been done (with dubious trademark/copyright infringement :? ) using Emscripten to cross-compile to Javascript.

That also suffers from being ludicrously slow, and I can't remember what features were broken.

Temporary Permanent signature filling text. Content coming soon delayed indefinitely! Oh, and I have a screenshot thread now...
Linux user (XMonad DWM/KDE, Arch), IRC obsessive and rail enthusiast. No longer buiding robots.
Author of an incredibly boring stickied post about NewGRFs.

PostPosted: Sun Mar 30, 2014 10:25 am 
User avatar

Joined: Sat Mar 06, 2004 11:51 pm
Posts: 1499
Location: The sunny side of Alps
Very nice effort!
And it isn't slow at all. Quite playable. Well - anyone here tried playing even TTOriginal on a 386 25MHz? Now that is slow and barely bearable. :]

NewGRF: Oil Wells in Temperate terrain now can Increase production, Better vehicle names, Use-able default aircraft, Oil Rig for Snowland and Desert, Speed for Suspension bridges.
Patches (OpenTTD): Improved smooth_economy [in trunk], More (diesel) smoke [in trunk], Realistic_acceleration finetune.

Keep 'em rollin'!

PostPosted: Tue Apr 01, 2014 12:12 am 

Joined: Wed Jan 17, 2007 12:14 am
Posts: 7299
SirkoZ wrote:
anyone here tried playing even TTOriginal on a 386 25MHz?
oooh yes :p

i think i never got much beyond 1940. (starting 1930)

You might not exactly be interested in Ferion, but if you are, have fun :)

PostPosted: Sun Oct 19, 2014 8:24 pm 
User avatar

Joined: Sat Sep 15, 2007 12:51 am
Posts: 85
Location: Slovenia
Did you make any more progress? Is it still in development or is this it?

Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 8 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 3 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2019 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2019.
Hosted by Zernebok Hosting.