Sunday, May 11, 2008

De-PImpl'ed and Unicode'ized

This is what I was(and am) working on last 3 days.

The PImpl - Private Implementation

When I just started DGE I knew I must find a way to separate the interface from implementation. And since I did not use boost's smart pointers back then, I tried to avoid every 'new' call in DGE itself and in its design as well, so there wont be something like DGE *engine = new DGE(); Thats why private section of DGE class definition looked like this: DGE_Data *m_data; and all calls to private members were like this: m_data->some_memeber.SomeFunction(); which is very ugly IMO.
Now Im using boost's libraries pretty much everywhere, as well as the smart_pointers, and since I dont have to avoid 'new' calls now, I decided to make some changes. I created a DGE_Implementation class which derives from DGE which was turned into abstract interface with all pure virtual methods and with no members. I added a new global function, DGE_Create() which returns a pointer to DGE interface, pretty standard technique 8) DGE_Data was finally eliminated, as well as those ugly m_data->some_member.SomeFunction(); and it feels much better now. Im sure I will not regret I did this 8)

Unicode

Boy, multilingual support was the last thing I was thinking about when the core of DGE was written 8) All I ever needed was good ol' std::string. But then I accidentally found this article: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
It reminded me of very much really nasty problems with encoding, like the website or mail encoding guessed wrong by app, or like youre working with some really cool library and that damn piece of software understands only ASCII >_<
So I decided to Unicode'ize DGE. All std::strings were replaced with std::wstrings, and I thought thats it, end of story :D Actually there are more to it than it seems. All I did by replacing std::strings with std::wstrings is changed the way the text data was handled inside the application, when whats really important its the application's interaction with the user - i/o. So I had to hack into font loading and displaying code as well to make it understand unicode fonts and display them correctly. Also, after deciding thatI should save DGE's log in UTF-8 format I spent much time just surfing the web for info about Unicode, its encodings and its use in C++. Unfortunately actual Unicode support is still in C++0x, so I ended up using this neato library for UTF-8 logging (btw, I made reverting back to ANSI logging really easy, just in case).
Now Im considering making changes to *.das file format (Da Game Engine Sprite) to make it UTF-8 as well, but this is not the top priority right now.

Next, Im planning to extend text rendering features, like newline support, wrapping text inside specified box, and more GUI controls.

Oh yes, I will release the Unicode'ized version after I finish the testing of every feature that has any relation to text.