{"id":30,"date":"2022-06-27T12:29:51","date_gmt":"2022-06-27T12:29:51","guid":{"rendered":"https:\/\/blogs.scummvm.org\/grisenti\/?p=30"},"modified":"2022-06-27T12:31:43","modified_gmt":"2022-06-27T12:31:43","slug":"compiling-the-game-and-completing-resource-loading","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/grisenti\/2022\/06\/27\/compiling-the-game-and-completing-resource-loading\/","title":{"rendered":"Compiling the game and completing resource loading"},"content":{"rendered":"<p>The first thing I worked on this week was finishing up the code that does resource loading which has now been moved to the <code>LowLevelResources<\/code> class inside of the resources folder. After doing that I worked on bringing in the game code. This was easier than expected with only a few problems with conversions from strings of <code>wchar_t<\/code>, used mainly for file code, to <code>char<\/code> strings. I then did some testing and got to load the <em>game.cfg<\/em> file, which is part of the game\u2019s assets. After that the code to instantiate the various systems gets executed and the program crashed by trying to dereference a null pointer.<\/p>\n<p>Next, I worked on replacing image loading. This was done by the <code>LowLevelResourcesSDL<\/code> class through the SDL image library. The data was then stored in the <code>SDLBitmap2D<\/code> class in the form of <code>SDL_surface<\/code>. Everything has now been moved to the <code>Bitmap2D<\/code> class in the graphics folder which also handles image loading through the <code>Image::*Decoder<\/code> family of classes. One problem I encountered was that after loading an image the relative <code>Graphics::Surface<\/code> cannot be modified, which is required by the <code>fillRect<\/code> and <code>drawToBitmap<\/code> methods. This led to the implementation of a copy-on-write mechanism.<\/p>\n<p>This week the codebase was also modified to reduce the number of warnings produced by gcc. After bringing in the engine code the total lines of warnings were about 24000. A lot of these where caused by missing virtual destructors in classes that had virtual methods. After adding these, the line count was reduced to 3000. With more changes, it\u2019s now at less than 2000, which is a huge improvement. The credit for this work goes to sev with me doing only very minor changes.<\/p>\n<p>The last thing I worked on this week was font loading. The game uses a format split into a .fnt xml file and some tga image files which contain a table of characters. This concludes resource loading for now, there\u2019s still the save system but this has been pushed to a later date since it\u2019s not necessary to get the game working.<\/p>\n<h4>Bonus problems<\/h4>\n<ul>\n<li>After including <em>pixelformat.h<\/em> in some files, the compiler started generating some weird errors which I couldn\u2019t figure out. Turn out the problem was that <em>hpl1\/engine\/graphics\/PixelFormat.h<\/em> and <em>graphics\/pixelformat.h<\/em> were considered the same file. I don\u2019t know what happened with the directories but for the files, this was caused by the windows file system being case insensitive.<\/li>\n<li>In the bitmap class I used <code>Common::ScopedPtr<\/code> for storing the image decoder. Trying to use the move assignment operator though generated compilation errors. The operation is implemented as:\n<pre style=\"color: #d1d1d1;background: #1E1E1E\"><span style=\"color: #e66170;font-weight: bold\">template<\/span><span style=\"color: #b060b0\">&lt;<\/span><span style=\"color: #e66170;font-weight: bold\">class<\/span> T2<span style=\"color: #b060b0\">&gt;<\/span>\r\nScopedPtr <span style=\"color: #d2cd86\">&amp;<\/span><span style=\"color: #e66170;font-weight: bold\">operator<\/span><span style=\"color: #d2cd86\">=<\/span><span style=\"color: #d2cd86\">(<\/span>ScopedPtr<span style=\"color: #b060b0\">&lt;<\/span>T2<span style=\"color: #b060b0\">&gt;<\/span> <span style=\"color: #d2cd86\">&amp;<\/span><span style=\"color: #d2cd86\">&amp;<\/span>other<span style=\"color: #d2cd86\">)<\/span> <span style=\"color: #b060b0\">{<\/span>\r\n\tPointerType oldPointer <span style=\"color: #d2cd86\">=<\/span> _pointer<span style=\"color: #b060b0\">;<\/span>\r\n\t_pointer <span style=\"color: #d2cd86\">=<\/span> other<span style=\"color: #d2cd86\">.<\/span>_pointer<span style=\"color: #b060b0\">;<\/span>\r\n\tother<span style=\"color: #d2cd86\">.<\/span>_pointer <span style=\"color: #d2cd86\">=<\/span> <span style=\"color: #e66170;font-weight: bold\">nullptr<\/span><span style=\"color: #b060b0\">;<\/span>\r\n\tDL<span style=\"color: #d2cd86\">(<\/span><span style=\"color: #d2cd86\">)<\/span><span style=\"color: #d2cd86\">(<\/span>oldPointer<span style=\"color: #d2cd86\">)<\/span><span style=\"color: #b060b0\">;<\/span>\r\n\t<span style=\"color: #e66170;font-weight: bold\">return<\/span> <span style=\"color: #d2cd86\">*<\/span><span style=\"color: #e66170;font-weight: bold\">this<\/span><span style=\"color: #b060b0\">;<\/span>\r\n<span style=\"color: #b060b0\">}<\/span>\r\n<\/pre>\n<p>The problem turned out to be that different istances of the same template class cannot access each other\u2019s private members. The fix was a friend declaration in <code>Common::ScopedPtr<\/code> to all the other instances of itself:<\/p>\n<pre style=\"color: #d1d1d1;background: #1E1E1E\"><span style=\"color: #e66170;font-weight: bold\">template<\/span><span style=\"color: #b060b0\">&lt;<\/span><span style=\"color: #e66170;font-weight: bold\">class<\/span> T2<span style=\"color: #d2cd86\">,<\/span> <span style=\"color: #e66170;font-weight: bold\">class<\/span> DL2<span style=\"color: #b060b0\">&gt;<\/span>\r\n<span style=\"color: #e66170;font-weight: bold\">friend<\/span> ScopedPtr<span style=\"color: #b060b0\">;<\/span> \r\n<\/pre>\n<\/li>\n<\/ul>\n<h4>Next week<\/h4>\n<p>Next week I\u2019ll start working the graphics system.<\/p>\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The first thing I worked on this week was finishing up the code that does resource loading which has now been moved to the LowLevelResources class inside of the resources folder. After doing that I worked on bringing in the game code. This was easier than expected with only a few problems with conversions from [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-30","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/posts\/30","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/comments?post=30"}],"version-history":[{"count":2,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/posts\/30\/revisions"}],"predecessor-version":[{"id":32,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/posts\/30\/revisions\/32"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/media?parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/categories?post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/tags?post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}