1: Alpha-blending now works properly
As you might remember from my last post, alpha blending was sort of non-existent in the code at that point. I did do specific skipping of completely transparent pixels, but that didn't prove to pretty:
|Previous version, without alpha-blending for anything but full transparency|
"I recommend to take a look at the code of RenderedImage::blit() in engines/sword25/gfx/image/renderedimage.cpp"Which I did, and although I haven't completed the refactoring into common-code that he asked for yet, I did add the code to my own branch, which gives the following result:
|New version, with alpha transparency|
2: Bitmap-fonts are drawn correctly nowPreviously, the bitmap-fonts were drawn with some rather weird offsets, making the characters have odd spacing. The transparency in those images were also quite off:
|Previous version, with broken bitmap-fonts|
Which explained that part of the problem, I clearly had to replace the existing alpha-channel with the colour key specified by the game.// convert 32-bit BMPs to 24-bit or they appear totally transparent (does any app actually write alpha in BMP properly?)
As for the weird spacing, the engine uses BSurface::IsTransparentAtLite to detect the width of the characters. This is also the reason why the engine explicitly requires the characters to be left-aligned.
Now IsTransparentAtLite was one of the functions that were stubbed when I removed the SDL2-requirement, so adding in new code to check for transparency solved that problem:
|New version, with working bitmap-fonts.|
3: Sprite scaling works
If you look at that last picture, do you notice anything else that's different from the previous ones? Yeah, Baxter is a bit smaller, and for a good reason, the code I borrowed from the Sword 2.5-engine included scaling before drawing, which solves quite a few issues. Previously if you tried to walk up to the door, Baxter would walk in-place, and not seem to go anywhere, simply because he couldn't "walk into the screen" in any visible fashion (he would have had to get smaller to show it). But now, he's scaled accordingly. That screenshot is actually quite close to this screenshot from the original WME Lite-engine, that you might remember from my last post:
|The original WME Lite-engine|
Yes, there are a few minor differencies, for one, there's some definite breakage in the gradient that makes up the road he's standing on, but the important bit here is, that this is the very first scene in the game, without any movement done, if you compare this to the first two images in this post, notice how he was way to big to begin with? Well, that's solved now.
4: Sprite mirroring works
One of the features that were missing from WME Lite, when compared to the full Wintermute-engine, was sprite mirroring/rotation, since the Sword 2.5 code I borrowed also contained support for vertical/horizontal flips, it was rather straight-forward to add that little feature back in. Now for testing this, I had to find a game that used it, which in this case was the game Rosemary. Walking left in this game was done by simply mirroring the walk-right sprites, which made it look rather odd without sprite mirroring enabled:
|Walking left in Rosemary, without sprite-mirroring|
|Walking left in Rosemary, WITH sprite-mirroring|
5: Fixed some bugs that crept in while refactoring code
Yes, bad things might happen when handling large code-bases, back before the last blog post, I changed a lot of char* into const char* to silence some warnings, and ease the hunting of a few segfaults, this had the interesting side effect of breaking a few virtual-functions, making inheriting classes no longer override the proper functions (C++ can be tricky there, as const char* and char* are quite different types that can be cast only one way). This led to scripts like playRandomMouseOver in Rosemary not running, as the super-class version got run instead of the correct one (the reasoning behind the bug was simple; the function-name was stored in a char* and the super class declared a function that accepted char* as parameter, while the subclasses accepted const char*, thus the wrong one was chosen).
6: Fixed speaking to characters (and in doing so, most of the sound)
Previously, if you tried to talk to any character in Dirty Split, the conversation would be cut short, this was because the engine needs to know the length of the text, to know how long it should wait before issuing new lines of text, and unlocking the objects that are speaking. When I did the sound-system before the last blog-post, I only added in the necessary bits for getting something to play, but I didn't bother doing all the various other functions. Specifically GetLength() proved to be quite important for this little tidbit, as it was previously just stubbed to 0. Explaining the rather short conversations.
What remains to be done in the sound-system, is (among other smaller things) supporting loops and seeking in the audio.
7: Added detection for a few more games
I changed the detection-scheme to use the Advanced Detector so that I could easily flag the various games for how compatible they were, as well as detect them based on more detail than the original detection solution. Now, adding every single game to this list will be a never-ending job, as new games are made all the time, but at least the known good and known bad games should be added over time. Particularly the known bad ones should be important to add here (such as all the 3D-games), so that the users will know why their particular game won't work. Another thing planned for this solution, is to have a simple fallback that registers unknown games by simply finding a data.dcp file that doesn't match any known ones. This should allow playing any new or in-development titles without having to first put the hashes into ScummVM.
The currently added games are:
I'll happily add more, if anyone has any good suggestions, but these at least let me test a few of the functions in the engines rather thorougly.
8: TrueType-font support
I have started working on allowing the games to load the TTF-fonts they ask for, which is rather necessary to for instance get subtitles in the conversations in Dirty Split. WME does support TTF-fonts, and defaults to using Arial, this does pose a problem for a ScummVM-port though, as while Arial can be loaded easily on Mac OS X or Windows, from the system-font-directories, various other platforms either lack Arial, or even a system font-concept at all. I'm looking at finding a way to use GNU FreeFont as a fallback alternative for these platforms.
There is also the ever-existing question of what do to if FreeType2 isn't available when building, I guess there will have to be some sort of fallback to one of the GUI-fonts in ScummVM, as a fallback in that case.
Anyhow, TTF-support is still a bit lacking in the WME-port at the moment, as I haven't entirely worked out the details for getting the proper sizes for the fonts, but that's work that will be solved in the coming weeks.
For the curious, this is how TTF-font-rendering looks in WME Lite:
|TTF-font in WME Lite|
And this is how it currently looks in ScummVM:
|TTF-font in ScummVM|
For comparison's sake, both of these use Arial at the moment, but long term, if users want to have Arial or something similar used with their games, they'll have to put a copy of the font file in their game folder.
One of the things that are handled fine at this point though, is text-wrapping:
|Text-wrapping in J.U.L.I.A.|
Yes, it's ugly at the moment, and the picture above even uses a few cheats to get the lower parts of the characters to get drawn (think the "cellar-part" of a g for instance), but it is what it is, a work in progress.
9: Screen refreshing now works
The original engine cleared the screen to black before every frame, that was another part of the SDL-code that I removed while getting it compiling in ScummVM. At certain points this would mean that parts of the screen that were supposed to be black, just kept what was there in the last frame that updated it. Which isn't really pretty:
|J.U.L.I.A.-demo without clearing|
Especially the particle engine in the above shot gives use problems. Anyway, making the entire screen draw a color between frames made things quite a lot prettier:
|J.U.L.I.A.-demo with clearing|
The downside of this though, is that the blitting functions used here aren't exactly free CPU-wise, so having to redraw everything every frame doesn't exactly reduce the CPU-usage. But atleast J.U.L.I.A. looks right now.
Now here comes the reason why I was talking about images in the opening of this post, because, if one image is worth a thousand words, then full motion video must be worth rather vastly larger sums than that again.
I mentioned J.U.L.I.A. in #9, and that's a game that really needs video support to shine. I got bored of hunting a bug at some point during the past few days, and decided to do something else for a while, which meant adding back Theora-video-support to the engine.
This was yet another field where the Sword 2.5-engine came to the rescue, as it already had a ScummVM-friendly implementation of libtheora, ready for use as a VideoDecoder, which meant that all I had to do was download the original WME sources (after contacting Mnemonic to make sure I could use them under GPLv2, instead of GPLv3), and dig out the removed pieces of code from there. In this case, that meant the code for functions like PlayTheora in AdEntity/AdGame, as well as the Vid-files from Base/ to see what the interface had been originally.
Connecting up the Sword 2.5 wrapper for libtheora to the WME-theora handler wasn't much work, and soon I had video's playing in all my games. A current limitation though, is that seeking is not yet implemented for Theora.
I'll close of this rather lengthy blogpost, with an image of a video playing in J.U.L.I.A.:
|The intro video from the J.U.L.I.A.-demo |
(note that this image was taken before fixing the screen-clearing issue)