{"id":20,"date":"2023-05-21T08:11:19","date_gmt":"2023-05-21T08:11:19","guid":{"rendered":"https:\/\/blogs.scummvm.org\/hax0kartik\/?p=20"},"modified":"2023-05-21T08:12:33","modified_gmt":"2023-05-21T08:12:33","slug":"preliminary-work","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/hax0kartik\/2023\/05\/21\/preliminary-work\/","title":{"rendered":"Preliminary Work"},"content":{"rendered":"<h4>Introduction<\/h4>\n<p>Sev <em>promoted<\/em> me to actually start the work on porting the CRAB engine after I had completed some tasks which he had assigned me.<\/p>\n<p>On this page, I hope to document to the<em> best of my efforts<\/em> what work I have already accomplished as of writing this page.<\/p>\n<h4>Importing the Engine Source code into ScummVM<\/h4>\n<p>The very first thing, <em>intuitively<\/em>, was to import the engine sources into ScummVM and get them to compile. To accomplish this, I first created a new skeleton engine and then imported all the files.<\/p>\n<p>Initially, I took the wrong approach, I focused on removing STL usage <em>before anything even compiled<\/em> and rewrote some functions.\u00a0Sev later made me realize that this was probably not the best approach and that I should first focus on getting all files to compile, and then remove STL usage.<\/p>\n<p>I got introduced to `FORBIDDEN_SYMBOL_ALLOW_ALL` which allowed linking with C++ STL(<em>future engine porters take note :p).\u00a0<\/em><\/p>\n<p>One thing that I took advantage of was that the src code of CRAB was well-separated into different components. So, instead of getting the whole codebase to compile at once, I instead made every component compilable one by one.<\/p>\n<p>With commit <a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/07a97c7f4d6c57837e766b60d256b2ec3d433389\">#07a97c7f<\/a> all files were compilable. It should be noted that I had to stub\/comment out some functions as they errored out.<\/p>\n<p>It is during this stage, that I also got the first visuals on screen by porting the Image class to use ScummVM&#8217;s equivalent of SDL drawing functions.<\/p>\n<figure id=\"attachment_21\" aria-describedby=\"caption-attachment-21\" style=\"width: 580px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-21\" src=\"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/first_visual-1024x474.png\" alt=\"\" width=\"580\" height=\"268\" srcset=\"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/first_visual-1024x474.png 1024w, https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/first_visual-300x139.png 300w, https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/first_visual-768x355.png 768w, https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/first_visual-1536x710.png 1536w, https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/first_visual-1200x555.png 1200w, https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/first_visual.png 1909w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><figcaption id=\"caption-attachment-21\" class=\"wp-caption-text\">This is the game loading screen just before the main menu.<\/figcaption><\/figure>\n<h4>Getting game to render and running into issues<\/h4>\n<p>Next, I ported the text drawing functions and soon I was able to go in-game. Yay!<\/p>\n<figure id=\"attachment_22\" aria-describedby=\"caption-attachment-22\" style=\"width: 580px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-22\" src=\"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/game_render-1024x576.png\" alt=\"\" width=\"580\" height=\"326\" srcset=\"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/game_render-1024x576.png 1024w, https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/game_render-300x169.png 300w, https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/game_render-768x432.png 768w, https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/game_render.png 1048w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><figcaption id=\"caption-attachment-22\" class=\"wp-caption-text\">The game renders correctly!<\/figcaption><\/figure>\n<p>However, if I pressed the left mouse button even once, the screen would simply scroll <em>way past<\/em> the point it was supposed to.<\/p>\n<p>I spent days debugging this, and ofcourse, the problem was the new rewritten functions I had created :). Reverting those, fixed the issue and now it worked as intended. (A more techincal description: A templated function did not take into account that floats\/doubles could be passed to it.)<\/p>\n<p>One important aspect that I haven&#8217;t talked about is &#8211; Performance. Originally the game is supposed to run at 60 fps, however I was only getting a glorious ~6 fps with ScummVM&#8217;s drawing functions.<\/p>\n<h4>Optimizing performance<\/h4>\n<p>The very first suggestion I got was to work with the minimal &#8211; resolution that the game supported, which in this case was 1280&#215;720.<\/p>\n<p>This boosted the fps to 10. It was definitely not a massive improvement, but a improvement, nonetheless.<\/p>\n<div style=\"width: 580px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-20-1\" width=\"580\" height=\"327\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/unrest.mp4?_=1\" \/><a href=\"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/unrest.mp4\">https:\/\/blogs.scummvm.org\/hax0kartik\/wp-content\/uploads\/sites\/68\/2023\/05\/unrest.mp4<\/a><\/video><\/div>\n<p>&nbsp;<\/p>\n<p>This is where the current progress stands. There are a few other optimizations which have definately helped but that is for a future blog post!<\/p>\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Sev promoted me to actually start the work on porting the CRAB engine after I had completed some tasks which he had assigned me. On this page, I hope to document to the best of my efforts what work I have already accomplished as of writing this page. Importing the Engine Source code into [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-json\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":3,"href":"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":26,"href":"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-json\/wp\/v2\/posts\/20\/revisions\/26"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/hax0kartik\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}