{"id":10,"date":"2012-03-23T03:33:52","date_gmt":"2012-03-23T01:33:52","guid":{"rendered":"https:\/\/blogs.scummvm.org\/jakimushka\/?p=10"},"modified":"2022-04-18T06:42:23","modified_gmt":"2022-04-18T04:42:23","slug":"at-the-beginning-of-a-long-journey","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/jakimushka\/2012\/03\/23\/at-the-beginning-of-a-long-journey\/","title":{"rendered":"At the beginning of a long journey"},"content":{"rendered":"<p><span lang=\"EN-US\">I want to take part in summvm development as a part of the Google Summer of Code Event. Here I\u2019ll tell about work done, about my impressions from this project and about other things related to this.<\/span><\/p>\n<p><span lang=\"EN-US\"> It was highly recommended to make bugfix or path of existing code for participation \u00a0in the project. But I have some problems with them. After trying about ten bugs from bugtracker, I can\u2019t reproduce any of them. That\u2019s why, I\u2019m going to start working on the idea I want to implement during this project. <\/span><\/p>\n<p><!--more--><\/p>\n<p><span lang=\"EN-US\"> So, my aim is to write testing framework, which can record or reproduce user\u2019s actions. There is already implemented module in the project, but it has some problems with synchronization with states of engine. After analyzing the existing sources, I\u2019ve found that previous version of the recorder was based on the idea that input events are in the form of interrupts and they linked to the time. In fact, events are state of input controls during the current iteration of engine. So for the recorders correct work, it\u2019s necessary to store\/restore the state of input controls in each iteration.<\/span><\/p>\n<p><span lang=\"EN-US\"> It looks much easier than previous version cause there is no necessity to make any time calculations. But difficulty lay in the fact that calling of recorder must be implemented in every supported engine and different implementation of main loop in engines also can be a problem. So calls recorder\u2019s interface must be as easy and compact as possible. Ideally, recorder must be encapsulated into Event Manger. <\/span><\/p>\n<p><span lang=\"EN-US\">My first step is implementation of Event Recorder class and integration into one of the existing engines (I think it going to be Sky engine, cause it is very easy to find game for testing) and testing until it will work perfectly.<br \/>\nThen I\u2019ll try to integrate it into another engine and analyze what difference it has and what should I change in engines to make integration easy.<\/span><br \/>\nNext I\u2019ll integrate it into all engines and will write guidelines for using it in new engines.<\/p>\n<p>The main loop of engine was easily found in\u00a0<a href=\"http:\/\/doxygen.scummvm.org\/d2\/d94\/sky_8cpp-source.html#l00170\">g<\/a><a href=\"http:\/\/doxygen.scummvm.org\/d2\/d94\/sky_8cpp-source.html#l00170\">o()<\/a> method of SkyEngine class. This method implements all game logic and it calls\u00a0<a href=\"http:\/\/doxygen.scummvm.org\/d2\/d94\/sky_8cpp-source.html#l00390\">delay()<\/a>\u00a0function which sync engine with FPS and also processes events.<\/p>\n<p><i>Actually, I do not really like main loop implementation, and if it would be permitted, I refactor it.<br \/>\nFirstly, I think that methods\u00a0<\/i> <a href=\"http:\/\/doxygen.scummvm.org\/d2\/d94\/sky_8cpp-source.html#l00390\">delay()<\/a> and <a href=\"http:\/\/doxygen.scummvm.org\/d2\/d43\/sky_2intro_8cpp-source.html#l00652\">doIntro <\/a>\u00a0<i>isn\u2019t routines. They are states of engine! And engine is a classic state machine, which can be in following states:<br \/>\nSTATE_INTRO &#8211; playing of intro, which can be interrupted by escape key pressing and going into action state<br \/>\nSTATE_ACTION &#8211; working iteration of engine. Makes updates in logic graphicks, analyze input<br \/>\nSTATE_IDLE &#8211; state for syncing with FPS<br \/>\nSTATE_PAUSE &#8211; ingame pause<br \/>\nNow it works how statemachine but logic \u201csmoothed\u201c with the code. Function delay() , following its name must pause application work. But it also makes an events processing (btw, events processing loop wants to be extracted from delay method).\u00a0<\/i><\/p>\n<p>To test my idea, I\u2019m adding public methods saveEngineInputState and restoreEngineInputState into EventRecorder class. They are only writing given state of keyboard and mouse to file depends from recorder state. (if recorder in writing state &#8211; restoreEngineInputState doesn\u2019t work. if recorder in playback state, saveEngineInputState doesnt work) . I\u2019m going to store input state after processMessages routine and push stored messages into EventManager before processMessages routine (faking real events).<\/p>\n<p>Pseudocode:<\/p>\n<pre>g_eventRec.restoreEngineInputState();\u00a0\r\nprocessMessages();\u00a0\r\ng_eventRec.saveEngineInputState(_keyBoardState, mouseState, mouseClicked);<\/pre>\n<p>After testing, I\u2019ve noticed that this principle works really great in things related to synchronization. But it also has some problems, which must be solved:<br \/>\nonly mouse and keyboard events are processing now. And only aim engine routine. For instance, EVENT_QUIT willn\u2019t handle. Keys pressing will not handling properly too. (but that moment I thought it was due to weak engine architecture)<\/p>\n<ul>\n<li>aren\u2019t processing mouse movement events<\/li>\n<li>there may be some problems with using it in different engines<\/li>\n<li>aren\u2019t processing random (easy to fix)<\/li>\n<\/ul>\n<p>In general, I think, I get awesome progress for few hours of work. I\u2019m looking forward for any suggestions and criticism\u00a0comments.<b><br \/>\n<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I want to take part in summvm development as a part of the Google Summer of Code Event. Here I\u2019ll tell about work done, about my impressions from this project and about other things related to this. It was highly recommended to make bugfix or path of existing code for participation \u00a0in the project. But [&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-10","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/jakimushka\/wp-json\/wp\/v2\/posts\/10","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/jakimushka\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/jakimushka\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/jakimushka\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/jakimushka\/wp-json\/wp\/v2\/comments?post=10"}],"version-history":[{"count":3,"href":"https:\/\/blogs.scummvm.org\/jakimushka\/wp-json\/wp\/v2\/posts\/10\/revisions"}],"predecessor-version":[{"id":23,"href":"https:\/\/blogs.scummvm.org\/jakimushka\/wp-json\/wp\/v2\/posts\/10\/revisions\/23"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/jakimushka\/wp-json\/wp\/v2\/media?parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/jakimushka\/wp-json\/wp\/v2\/categories?post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/jakimushka\/wp-json\/wp\/v2\/tags?post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}