{"id":28789,"date":"2015-09-29T12:15:58","date_gmt":"2015-09-29T17:15:58","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=28789"},"modified":"2015-09-29T12:15:58","modified_gmt":"2015-09-29T17:15:58","slug":"experienced-points-why-do-i-need-to-restart-the-game","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=28789","title":{"rendered":"Experienced Points: Why Do I Need to Restart the Game?"},"content":{"rendered":"<p><a href=\"http:\/\/www.escapistmagazine.com\/articles\/view\/video-games\/columns\/experienced-points\/14710-Why-You-Need-To-Restart-the-Game-When-You-Change-the-Graphics\">My column this week<\/a> answers the question posed by the title, which means the Title Police can piss off and can&#8217;t refer to it as &#8220;clickbait&#8221;. (Seriously, the Title Police have become almost as annoying as the clickbaiters by this point. But that&#8217;s a topic for another day.)<\/p>\n<p>This is yet another topic where you can go an inch deep or a mile deep, and you still won&#8217;t hit the bottom. It all depends on how much technical knowledge you demand of your audience. On the Escapist, I tried to keep things broad and accessible for general audiences. <\/p>\n<p>But let&#8217;s look a little deeper:<\/p>\n<p><!--more-->In C-flavored programming, we have pointers. You ask the operating system for a big ol&#8217; wad of memory, and you use that memory to store some crap. Maybe it&#8217;s the 3D model of the space marine. Maybe it&#8217;s the texture map of his face. Maybe it&#8217;s the animation that makes him look angry and constipated when you&#8217;re holding down the fire button. Maybe it&#8217;s the grunting sound he makes when the player jumps. Whatever. You get some memory and you put stuff in it.<\/p>\n<p>A pointer is just an address of memory: &#8220;The space marine face is stored at memory location #1,234,567.&#8221; The most expedient way to code is simply to create the object, and then let other systems grab that pointer whenever they need it. To save time, those other systems might save the pointer so they don&#8217;t have to keep looking it up.<\/p>\n<p>So far, so good.<\/p>\n<p>But then we change some graphics settings. Maybe the user bumps the texture resolution from &#8220;low&#8221; to &#8220;medium&#8221;. Now we need bigger textures. But all the textures we have in memory are for &#8220;low&#8221; texture mode. So we release the memory for the space marine texture at #1,234,567 and get a new block of memory to hold the bigger texture. This new texture will probably live at a new address. Say, #2,345,678.<\/p>\n<p>Now here is where our programmer starts to worry. How many other systems out there have the old address? What if one of them tries to use it? If they do, they will very likely crash the game. How can we keep this from happening? Various people will offer suggestions:<\/p>\n<p><strong>You can tell everything to always ask for the latest address of everything, always.<\/strong> But that creates a performance overhead. If this thing is something you use ten thousand times a frame, then any performance cost on that object will end up multiplied by ten thousand. This is really important these days when developers seem to be just barely able to maintain 60fps, and they need to save all the CPU cycles they can. <\/p>\n<p><strong>You can tell everything to update itself one a frame.<\/strong> Once at the start of a frame, everything can re-query all the addresses. But this creates a great deal of uncertainty, particularly when dealing with complex systems. Maybe when I&#8217;m updating a character, it has the check on the address of the model, and in the process of doing that, the model ends up (for some reason) trying to use (or even just examine) the texture. You end up with this chain of things that need to be checked in just the right order and the programmer has to understand how every single object interacts with every other object.<\/p>\n<p><strong>You can run around updating everything right at the moment it gets changed.<\/strong>  So the user changes the texture settings and the game immediately stops everything and forces every object to update just to make sure all the pointers are current. This pushes the problems into the future. Later on, a new programmer joins the team and nobody has explained to her that when you add a new thing, you also need to add that thing to this global refresh. She&#8217;ll run around adding all sorts of useful features to the code without noticing anything is wrong.  Then a playtester tries to change the graphics settings and the program dies a horrible death. Now we have to go back over the last few weeks of work and find all the things she added and &#8220;fix&#8221; them. It creates folk knowledge that you &#8220;just have to know&#8221; in order to work on this game. It doesn&#8217;t sound too bad in this example, but when you have thousands of systems that all have these little &#8220;by the way, make sure to always do X&#8221; things, it becomes dauntingly complex to keep track of them all. <\/p>\n<p>And none of these techniques will help if your game is multi-threaded. Let&#8217;s say you&#8217;ve got this bit of code:<\/p>\n<pre lang=\"c\" line=\"1\">\r\n\/\/Let's make sure the pointer is up-to-date!\r\npointer = GetNewPointerLocation ();\r\n\/\/Okay, that's safe now. We can proceed:\r\nDoSomethingUseful (pointer);\r\n<\/pre>\n<p>What if some background thread happens to change the location of that thing just after line #2 but before line #4? That&#8217;s a ticket to crash city.<\/p>\n<p>People usually try to fix this with programming orthodoxy: <em>Never use simple pointers! Always use classes with constructors \/ destructors! Comment your code! Use this strict programming paradigm!<\/em> Those solutions might help mitigate the problem that your code is now ten times as complex, but none of them as as easy, as safe, as clear, and as future-proof as simply wiping the slate clean with a restart.<\/p>\n<p>And that&#8217;s why game development sucks and only a fool would try to make a game in this day and age.<\/p>\n<p>Tomorrow! An update on the development of my indie game <a href=\"?cat=498\">Good Robot<\/a>!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My column this week answers the question posed by the title, which means the Title Police can piss off and can&#8217;t refer to it as &#8220;clickbait&#8221;. (Seriously, the Title Police have become almost as annoying as the clickbaiters by this point. But that&#8217;s a topic for another day.) This is yet another topic where you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[],"class_list":["post-28789","post","type-post","status-publish","format-standard","hentry","category-weekly-column"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/28789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=28789"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/28789\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=28789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=28789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=28789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}