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.Video
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 worksInput
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.Audio
Not done at all. Is possible but I currently have no idea.Network
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.Bugs
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.Misc
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.PS
I will add sources to GitHub, maybe tomorrow.
To save your settings you must exit game, even if it does no sense in browser