Here is a new version of the SDL2 port. I have tried to clean up some of the ugly workarounds I had initially added to get SDL2 to work. The game also runs more efficiently now.
My 'quick fix' to make blitting work was to convert all 8-bit images to 32-bit equivalents immediately before the program wanted to draw them. This of course created more problems than it solved (probably) and added cumbersome complexity. So, I have tried to revert this as much as possible to the way it worked with SDL1;
- I removed convert_surface_to_onscreen_format(); 8 bpp images are now properly blitted directly again
- The onscreen and offscreen surfaces are now 24 bpp again instead of 32. Unfortunately, I cannot get this surface to the screen correctly, so for now it is still converted to 32 bpp every time there is a screen update (which is at least less horrible than the way it used to be).
One strange side effect is that I had to change the argument order (b,g,r instead of r,g,b) in two calls to SDL_MapRGB(). Colors are normal using this hack but I don't understand why it became necessary:
Code: Select all
in method_5_rect() and set_bg_attr(): (seg009.c)
// @Hack: byte order (rgb) is reversed (otherwise the color is wrong) - why doesn't this work as expected?
uint32_t rgb_color = SDL_MapRGB(onscreen_surface_->format, palette_color.b<<2, palette_color.g<<2, palette_color.r<<2);
To improve the game's performance, I have reduced the number of times the screen is updated (it seems this was a bottleneck on my older laptop). Previously, the game would update the screen almost every time anything got drawn, unnecessarily. This is what I've changed:
- method_3_blit_mono() no longer requests screen updates; text should now display instantly instead of letter by letter. A screen update is now manually invoked in show_text() and in a few other places.
- I have added a global variable
screen_updates_suspended which is checked by request_screen_update() every time a screen update is requested (renamed from screen_update()). The heavy drawing routines such as draw_game_frame(), redraw_screen() etc now have the power to temporarily suspend screen updates so that they only need to request one update after they are done drawing everything.