SummerOfCode/2012/PortSupertux

From MozillaWiki
Jump to: navigation, search

This project is going to port Supertux to web by using Emscripten, a C/C++-to-Javascript compiler.

Status Report

Aug 6 - Aug 12

The overall status of the project is that the game can play and menus works, with some remaining work to do. 80% of the project is done.

For the latest game, see the page: http://forandom.github.com/WebSupertux.

Works done in this week:

(1) Fix the page stuck when loading worldmap.

(2) Fix the page stuck when return from game loop to main menu.

(3) Add bonus Games support.

(4) Add Credit menu support.

(5) Compile the game using -O2.

Remaining work:

(1) Commit any modifications to Emscripten.

(2) Show the frame rate correctly on the screen.

(3) Fix the nosing music problem.

(4) Add level editor support.


Jul 30 - Aug 5

(1) After using set_emscirpten_main_loop and -O1/-O2 option, the game can run, but has two little problems: a. Some bad guys don't move. b. When tux dies and another round begins, the game will hang up.

Finally, I found the reason is that the frame rate is no set properly. The argument passed to emscripten_set_main_loop should be the frame rate instead of the time for each frame.

(2) Change the structure of the code so that when the game session loop ends, the control flow goes into worldmap loop.

Jul 23 - Jul 29

I'm leaving school and going back home. No work was done this week.

Jul 16 - Jul 22

(1) Fix Issue #504, and send pull request.

(2) Change loops in the game by using set_emscripten_main_loop. Now it can run a single session.


Jul 9 - Jul 15

(1)Last week I thought the page stuck when showing the worldmap was caused by stack growing rapidly. But finally I found that was because I forgeted to comment stack recover statement and calling destructor of worldmap in the display_loop. Now the game can run from the main menu to worldmap, then gamesession.

(2)Learn the usage of set_emscripten_main_loop.

Jul 2 - Jul 8

(1)Try to port a complete Supertux.

From the begining of the game to the real playing stage, there are three loops.

a)title_loop, the demo session in the background when the game begins.

b)display_loop, shows the worldmap and allow the player to select levels.

c)main_loop, the game loop.

Each loop will kill the previous loop. When in main_loop, the backtrace result looks like as follows:

->main_loop(called by setInterval)

->gamesession

->display_loop(called by setInterval)

->display

->title_loop(called by setInterval)

->title

->main

Because setInterval is non-blocking, each previous function will return immediately. For main_loop to work well, the stack recover statement before return in previous functions should be commented. But this will cause the stack growing rapidly because of setInterval.


Jun 25th - Jul 1st

(1)Find out why Fire/Run key not work.

SDLK_LCTRL has different value in SDL headers and library_sdl.js. See https://github.com/kripken/emscripten/issues/504.

(2)Try to use emcc -O1 and -O2 option.

-O2 is too aggressive that many source information is removed. For example, it's hard to find the game loop in the generated html page.


Jun 18th - Jun 24th

The game can play now. This week I did the followings:

(1)Find out why no input is processed.

Last week I commented the statements that change the stack base when function returns. But two kind of things are missed:

a) Call to destructors at the end of main().

b) Call to exitRuntime after main() returns.

After commented these statements in the generated html, the game can play on nightly build Firefox 16.

(2) Try to port the worldmap.

When showing the worldmap, the game will load all the levels in the map and construct Level object for each level. This process is very slow. The page wil get stuck. Need to modify the level loading process.

(3) Create repo on GitHub.

lnk: https://github.com/forandom/WebSupertux


Jun 11th - Jun 17th

This week I spent most time to figure out why the animation failed after changed the game loop to setInterval form. Finally I figured it out.

Here's the call chain from main to the game loop:

main->GameSession::run()->setInterval->main_loop

After setInterval is executed, the program will return from run() and finally exit from main. This return process will modify the global stack base which is also used by other threads. I just comment any code after setInterval. The following animation works:

(1) The tux can drop from the sky onto the land. (2) The elapse time showing works. (3) The question mark on brisk shines.

But the tux cannot move now. It seems that the game can not receive event. Supertux uses SDL_PollEvent which is in a while loop. I add printf into the loop and recompiled the code, and it's weird that there's no drawing anymore. I'll keep looking.


Jun 4th - Jun 10th

Sorry, this week has no update. This is my final week in graduate school, I spent all the time preparing for theise oral defense. I'll compensate by pay more efforts in following weeks.


May 28th - Jun 3rd

Continue to fix problems when run the compiled page in broswer.

(1)Implement the missing SDL function SDL_GetKeyName in Emscripten.

SDL_GetKeyName is used in drawing text when user setting new control key bindings.

(2)Fix the no drawing problem.

I found that when linking llvm found the definition of SDL_Rect from the system header, which include uint16 element. But when running, the code to read SDL_Rect treated element in SDL_Rect as uint32, which was defined in Emscripten's SDL header files.

LLVM should use the Emscripten's header files instead of the system's. This is caused by the configure script of Supertux, which use /usr/bin/sdl-config to find the header files, while the emconfigure right now cannot affect the behavior of sdl-config.

I removed the sdl-config part in configure, but there was several compiling errors. This is because Supertux use SDL 1.2, while Emscripten use SDL 2.0. After a little modification to the supertux source, the compiling errors gone. The modification include:

a. remove alpah element from struct PixelFormat

b. change SDL_GetKeyState to SDL_GetKeyboardState

(3) Change the game main loop to ansychronized form in javascript.

After doing this, the picture still dosen't move. I'll figure it out.


May 21st - May 27th

I'v compiled the supertux to a html. And I'm going to run it in broswer and fix any problems met during this process.

(1)Fix page stuck caused by audio format.

Supertux contains MOD format audios which are not supported by the current HTML5 audio. This problem is solved by converting the audios to ogg format.

(2)Fix page stuck caused by IMG_Load.

Emscripten's IMG_Load implementation seems buggy, as it will trim the leading "/' of an absolute path of the image. I just commented the code, and this stuck disappeared. I'll talk to Alon about this problem.

(3)Fix page stuck caused by missing SDL functions in Emscripten.

a. Mix_ReserveChannels: I just commented the code in Supertux.

b. SDL_WM_SetIcon: commented.

c. SDL_Joystick*: commented.

d. SDL_GetKeyState: similar to SDL_GetKeyboardState, implemented.

e. SDL_GetVideoSurface: just return the SDL.screen, implemented.

After doing this, the html page now can run into the game main loop, and background music plays well. But still has no pictures, as there's still some SDL functions not implemented, and the main loop is not yet changed to javascript setTimeInterval form.




Status report before May 21st will be added as soon as possible.