{"id":186,"date":"2009-09-24T07:38:47","date_gmt":"2009-09-23T21:38:47","guid":{"rendered":"http:\/\/www.doolwind.com\/blog\/?p=186"},"modified":"2009-09-24T07:38:47","modified_gmt":"2009-09-23T21:38:47","slug":"model-view-controller-mvc-game-engine","status":"publish","type":"post","link":"https:\/\/www.doolwind.com\/blog\/model-view-controller-mvc-game-engine\/","title":{"rendered":"Model View Controller (MVC) Game Engine"},"content":{"rendered":"<p><a href=\"http:\/\/www.doolwind.com\/images\/blog\/MVC.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright\" title=\"MVC\" src=\"http:\/\/www.doolwind.com\/images\/blog\/MVC.png\" alt=\"\" width=\"130\" height=\"133\" \/><\/a>The Model View Controller (MVC) pattern has been used with great success in business software development for years.\u00a0 Despite this, it has never fully been picked up by the games industry.\u00a0 Today I&#8217;m going to discuss why the MVC pattern is perfect for game development.<\/p>\n<h2><strong>Introduction<\/strong><\/h2>\n<p>The Model View Controller pattern isolates gameplay logic from input and rendering.\u00a0 This &#8220;Separation of Concerns&#8221; allows each layer to be developed, tested and maintained independently.\u00a0 Graphics programmers work solely on rendering, gameplay programmers or designers work on gameplay and whoever&#8217;s left can work on input.<\/p>\n<p>Model &#8211; Gameplay (game entities, eg. Player, Sword)<br \/>\nView &#8211; Rendering<br \/>\nController &#8211; Input and non-gameplay flow (menu&#8217;s etc)<\/p>\n<p>The controller takes input from the player and changes the model.\u00a0 The controller then passes the model (and any other relevant information) to the view to be rendered.<\/p>\n<h2><strong>Advantages<\/strong><\/h2>\n<p><strong>Cleaner Code<\/strong>. \u00a0Large teams can work independently on each layer of the application without conflict.\u00a0 Clear interfaces are used to define communication across layer boundaries.\u00a0 As the engine grows, this separation of concerns helps to minimize complexity.<\/p>\n<p><strong>Better Cross Platform Support<\/strong>.\u00a0 Gameplay is separate and not reliant on platform specific technology.\u00a0 Rendering and input (both heavily platform specific) are separate and can easily be changed.<\/p>\n<p><strong>Decoupled Rendering.<\/strong>\u00a0 In most engines the game world and renderer are tightly coupled.\u00a0 MVC decouples the game world (and input) from the rendering.\u00a0 Rather than calling &#8220;Render&#8221; of each game entity the rendering system uses the model when rendering.\u00a0 This also simplifies the process of adding multi-threaded support to the game or renderer.<\/p>\n<p>I&#8217;ve used this technique in my latest engine and it feels so much more natural.\u00a0 Rather than blurring the line between gameplay and rendering they are distinct and the renderer is responsible for bringing them together.<\/p>\n<p><strong>Scripting\/Designers<\/strong>.\u00a0 All changes made to the model by the controller are through a known interface.\u00a0 This interface can be exposed to designers\/modders through a scripting language giving them greater flexibility and control.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>I won&#8217;t go into implementation details right now.\u00a0 If anyone is interested, I&#8217;ll put together a blog on implementation and look at releasing the MVC framework I created in XNA.\u00a0 Let me know your thoughts, where you see there might be problems and if you&#8217;re interested in me discussing this further.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Model View Controller (MVC) pattern has been used with great success in business software development for years.\u00a0 Despite this, it has never fully been picked up by the games industry.\u00a0 Today I&#8217;m going to discuss why the MVC pattern is perfect for game development. Introduction The Model View Controller pattern isolates gameplay logic from <a class=\"more-link\" href=\"https:\/\/www.doolwind.com\/blog\/model-view-controller-mvc-game-engine\/\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[33],"tags":[35,51,63],"class_list":["post-186","post","type-post","status-publish","format-standard","hentry","category-game-development","tag-game-engine","tag-mvc","tag-scripting"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pgEc5-30","_links":{"self":[{"href":"https:\/\/www.doolwind.com\/blog\/wp-json\/wp\/v2\/posts\/186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.doolwind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.doolwind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.doolwind.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.doolwind.com\/blog\/wp-json\/wp\/v2\/comments?post=186"}],"version-history":[{"count":0,"href":"https:\/\/www.doolwind.com\/blog\/wp-json\/wp\/v2\/posts\/186\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.doolwind.com\/blog\/wp-json\/wp\/v2\/media?parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.doolwind.com\/blog\/wp-json\/wp\/v2\/categories?post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.doolwind.com\/blog\/wp-json\/wp\/v2\/tags?post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}