{"id":15,"date":"2017-06-04T08:55:22","date_gmt":"2017-06-04T08:55:22","guid":{"rendered":"https:\/\/blogs.scummvm.org\/yinsimei\/?p=15"},"modified":"2022-05-24T09:00:13","modified_gmt":"2022-05-24T09:00:13","slug":"gsoc-week-2","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/yinsimei\/2017\/06\/04\/gsoc-week-2\/","title":{"rendered":"GSoC Week 2"},"content":{"rendered":"<h1>GSoC 2017: Sludge Engine Week 2<\/h1>\n<h2>Week task conclusion<\/h2>\n<p>In general, the second week of GSoC project was quite good: all goals achieved one day in advance, though the work was not as easy as the first week. Again, a huge thank you to my mentors _sev(Eugene Sandulenko), t0by(Tobia Tesan) and all scummvm team members that has helped me on graphics during this week.<\/p>\n<p>To make a brief conclusion about what we have and have not achieved for<b>\u00a0this week<\/b>\u00a0:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/blogs.scummvm.org\/yinsimei\/wp-content\/uploads\/sites\/61\/2022\/05\/pasted-image-1.png\" \/><\/p>\n<p><b>Tasks completed<\/b>:<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<ol>\n<li><a href=\"https:\/\/github.com\/yinsimei\/scummvm\/commit\/c1af97c988484443bcf6c4b719f08cab8551058f\">Get backdrop (background) reading and displaying work<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/yinsimei\/scummvm\/commit\/3ac43eed1ec1eea679208146e9abc47f057f2e16\">Get the sprite system up based on 1<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/yinsimei\/scummvm\/commit\/91424f9ff13f2ebdcb7e354f1e77ccdbabd49fd5\">Get spritebank up to have animations and display transparent sprites<\/a><\/li>\n<\/ol>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>And\u00a0<\/b>:<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<ol>\n<li>The segmentation fault caused by animation nullptr has been fixed<\/li>\n<li>scummvm can compile on windows<\/li>\n<\/ol>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>For later (They don\u2019t have much effects for now):<\/b><\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<ol>\n<li>There are shaders used in graphics in scummvm waiting to be rewritten (normally we rewrite it by figuring out what they do and reproducing the same effects by c++ code)<\/li>\n<li>OOPifying the code should be something coming quite soon, as we still work with global variables now and it begins getting complicated. Maybe for next week or the week after if time permits<\/li>\n<\/ol>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>Some problems left to be solved :<\/b><\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<ol>\n<li>The code don\u2019t compile for Mac yet<\/li>\n<\/ol>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>What\u2019s for next week: Text &amp; Sound<\/h2>\n<p>There is still some work before getting all sludge graphic features up, but I reckon that\u2019s enough for now and we will add them later when we need. What we will move on to next week are:<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<ol>\n<li>Get texts displayed (Graphics::FontManager and Font)<\/li>\n<li>Play sound (Audio classes)<\/li>\n<\/ol>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>And this makes the first game demo \u201cWelcome\u201d work completely. And we can see dialogues for \u201cVerb coin\u201d.<\/p>\n<h2>Problems encountered during week 2<\/h2>\n<p>As in this week, I was stuck several times with different problems (solved thanks to help from mentors and scummvm team members), I think it\u2019s good to talk about them.<\/p>\n<h3>1. Graphics format<\/h3>\n<p>First of all, we need to determine which graphic format is used in Sludge to initGraphics.<\/p>\n<p>As a result of lacking basic graphic knowledge, I was wrong about the graphic format because of the existence of palette structure in Sludge, which is actually used for transferring 256-color image (8-bit image) to 32-bit image.<\/p>\n<p>There is a number of way to see the graphic format, for example:<\/p>\n<p>In the graphic initialization code of the engine, there will be clues like :<\/p>\n<div>\n<div id=\"highlighter_498828\" class=\"syntaxhighlighter  cpp\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"cpp keyword bold\">if<\/code> <code class=\"cpp plain\">(SDL_SetVideoMode(realWinWidth, realWinHeight, 32, videoflags) == 0) {<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>The input parameter 32 shows that sludge is using 32 bit images.<\/p>\n<p>Besides, if we can have access to specific image byte loading code like:<\/p>\n<div>\n<div id=\"highlighter_549406\" class=\"syntaxhighlighter  cpp\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"cpp plain\">target = snapshotTexture + 4 * picWidth * y + x * 4;<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"cpp plain\">target[0] = (byte)redValue(c);<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"cpp plain\">target[1] = (byte)greenValue(c);<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"cpp plain\">target[2] = (byte)blueValue(c);<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"cpp plain\">target[3] = (byte)255;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>We can clearly see that they are reading at an offset of 4 bytes, which also means that sludge uses 32-bit images.<\/p>\n<p>Another funny mistake that I made during image loading is that I got wrong with PixelFormat and mixed up the channels, which gives an image like:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/blogs.scummvm.org\/yinsimei\/wp-content\/uploads\/sites\/61\/2022\/05\/welcome_wrong.png\" \/>which actually is<img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/blogs.scummvm.org\/yinsimei\/wp-content\/uploads\/sites\/61\/2022\/05\/welcome_right.png\" \/><\/p>\n<p>Just scrutinize the<a href=\"https:\/\/github.com\/scummvm\/scummvm\/blob\/master\/graphics\/pixelformat.h\">\u00a0bit shift code of PixelFormat<\/a>, there will be a clue.<\/p>\n<h3>2. Sprite loading error<\/h3>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/blogs.scummvm.org\/yinsimei\/wp-content\/uploads\/sites\/61\/2022\/05\/pasted-image-0.png\" \/><\/p>\n<p>Another interesting problem is that I got distorted sprites at first when I tried to load them. We can see that all bytes of the sprites have been correctly read but to the wrong place. Normally, there is a sprite dimension error for such problems. It\u2019s strongly suggested to log the sprite width and length of the image loading procedure to see if everything goes well.<\/p>\n<p>In my case, sprites\u2019 width and length were modified halfway by some improper manipulation.<\/p>\n<h3>3. Sprite flickering<\/h3>\n<p>I also met a sprite flickering problem due to multiple updateScreen() calls.<\/p>\n<p>The entire screen is in practice updated when updateScreen() is called, so if there is image flicker then you\u2019re presumably not producing the same frame consistently.<\/p>\n<p>For instance, multiple updateScreen() calls are made for an actual frame, and some of those overwrite something that\u2019s been previously rendered, then that could generate such errors, since you\u2019re effectively producing as many frames as you have calls to updateScreen().<\/p>\n<h2>Some findings about sludge<\/h2>\n<ol>\n<li>Graphics format used in Sludge is true color (32\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Color_depth\">bpp<\/a>)<\/li>\n<li>Character animation is saved as a series of sprites and a looping sound<\/li>\n<li>Sludge has 3 versions of sprite image (version 0, 1,2 saved as 8-bit image, version 3 as png)<\/li>\n<\/ol>\n<div id=\"atatags-370373-628c9d6caeed6\"><\/div>\n<div id=\"atatags-26942-628c9d6caef50\"><\/div>\n<div id=\"jp-post-flair\" class=\"sharedaddy sd-like-enabled sd-sharing-enabled\">\n<div class=\"sharedaddy sd-sharing-enabled\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>GSoC 2017: Sludge Engine Week 2 Week task conclusion In general, the second week of GSoC project was quite good: all goals achieved one day in advance, though the work was not as easy as the first week. Again, a huge thank you to my mentors _sev(Eugene Sandulenko), t0by(Tobia Tesan) and all scummvm team members [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/yinsimei\/wp-json\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/yinsimei\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/yinsimei\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/yinsimei\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/yinsimei\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":1,"href":"https:\/\/blogs.scummvm.org\/yinsimei\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"predecessor-version":[{"id":20,"href":"https:\/\/blogs.scummvm.org\/yinsimei\/wp-json\/wp\/v2\/posts\/15\/revisions\/20"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/yinsimei\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/yinsimei\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/yinsimei\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}