<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bartosz &#8211; Games Architecture</title>
	<atom:link href="http://gamesarchitecture.com/author/admin1589/feed/" rel="self" type="application/rss+xml" />
	<link>http://gamesarchitecture.com</link>
	<description>For indie developers who already know that making games is not easy</description>
	<lastBuildDate>Sat, 30 Dec 2017 20:29:19 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.4</generator>
	<item>
		<title>Short #2 Leave these parameters alone</title>
		<link>http://gamesarchitecture.com/short-2-leave-parameters-alone/</link>
		<comments>http://gamesarchitecture.com/short-2-leave-parameters-alone/#respond</comments>
		<pubDate>Sat, 30 Dec 2017 20:29:19 +0000</pubDate>
		<dc:creator><![CDATA[Bartosz]]></dc:creator>
				<category><![CDATA[Good Practices]]></category>
		<category><![CDATA[Shorts]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[parameters]]></category>
		<category><![CDATA[short]]></category>

		<guid isPermaLink="false">http://gamesarchitecture.com/?p=505</guid>
		<description><![CDATA[<p>You&#8217;re updating an old method by adding only two simple lines of code at the end, but something is really wrong here. You checked all the method calls and parameters that you&#8217;re passing, but they are correct. So maybe their values are incorrect? You run a debugger and check. Nope, they are perfectly fine. The &#8230; </p>
<p class="link-more"><a href="http://gamesarchitecture.com/short-2-leave-parameters-alone/" class="more-link">Continue reading<span class="screen-reader-text"> "Short #2 Leave these parameters alone"</span></a></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/short-2-leave-parameters-alone/">Short #2 Leave these parameters alone</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;"><img class="aligncenter wp-image-508 size-full" src="http://gamesarchitecture.com/wp-content/uploads/2017/12/1514665184729.png" alt="lemmings_portal_method_parameters" width="1534" height="510" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/12/1514665184729.png 1534w, http://gamesarchitecture.com/wp-content/uploads/2017/12/1514665184729-300x100.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/12/1514665184729-768x255.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/12/1514665184729-1024x340.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><br />
You&#8217;re updating an old method by adding only two simple lines of code at the end, but something is really wrong here. You checked all the method calls and parameters that you&#8217;re passing, but they are correct. So maybe their values are incorrect? You run a debugger and check. Nope, they are perfectly fine. The problem might be in the function itself, but it worked like a charm until now, so you&#8217;re rechecking your two lines and you still cannot see any issues.<span id="more-505"></span></p>
<p style="text-align: justify;">The problem might be the old code in the method. Maybe it doesn&#8217;t introduce any bugs by itself, but if it modifies procedure&#8217;s parameters at some place, it can cause annoying issues later.</p>
<p style="text-align: justify;">It is like basing the decision about renting an apartment on internet advertisement. The description seems great, the photos are splendid, and the price is low. But when you come to see the flat, it&#8217;s dirty, smells bad, and it lacks a fridge. The ad didn&#8217;t mention that previous residents damaged it and left it like that. You feel cheated. It would be great if you could just trust an ad, right?</p>
<p style="text-align: justify;">It seems impossible for an advertisement to be honest, but it is doable for the method code. Don&#8217;t change the function&#8217;s parameters in the body so that you can trust its signature. Of course, if the method is meant to modify its parameters, its name should denote it, or you should use the right keyword (i.e. out in C#) so that the user can be aware of it.</p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/short-2-leave-parameters-alone/">Short #2 Leave these parameters alone</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamesarchitecture.com/short-2-leave-parameters-alone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;Is it too late for me to start learning programming?&#8221;</title>
		<link>http://gamesarchitecture.com/is-it-too-late-to-start-learning-programming/</link>
		<comments>http://gamesarchitecture.com/is-it-too-late-to-start-learning-programming/#respond</comments>
		<pubDate>Sat, 09 Dec 2017 15:58:26 +0000</pubDate>
		<dc:creator><![CDATA[Bartosz]]></dc:creator>
				<category><![CDATA[Generic]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://gamesarchitecture.com/?p=493</guid>
		<description><![CDATA[<p>I see a plenty of questions on Quora like &#8220;I am X years old, is it too late to start learning programming?&#8221; Many of these questions are asked by people around their 20s. Well, I believe I might know the answer, and it is not a cliche &#8216;It is never too late mate!&#8217; I would &#8230; </p>
<p class="link-more"><a href="http://gamesarchitecture.com/is-it-too-late-to-start-learning-programming/" class="more-link">Continue reading<span class="screen-reader-text"> "&#8220;Is it too late for me to start learning programming?&#8221;"</span></a></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/is-it-too-late-to-start-learning-programming/">&#8220;Is it too late for me to start learning programming?&#8221;</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;"><img class="aligncenter wp-image-494 size-full" src="http://gamesarchitecture.com/wp-content/uploads/2017/12/Is-it-too-late-to-start-learning-programming.png" alt="Banner - &quot;Is it too late for me to start learning programming?&quot; Well..." width="1534" height="850" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/12/Is-it-too-late-to-start-learning-programming.png 1534w, http://gamesarchitecture.com/wp-content/uploads/2017/12/Is-it-too-late-to-start-learning-programming-300x166.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/12/Is-it-too-late-to-start-learning-programming-768x426.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/12/Is-it-too-late-to-start-learning-programming-1024x567.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><br />
I see a plenty of questions on <a href="https://www.quora.com" target="_blank" rel="noopener">Quora</a> like &#8220;I am X years old, is it too late to start learning programming?&#8221; Many of these questions are asked by people around their 20s. Well, I believe I might know the answer, and it is not a cliche &#8216;It is never too late mate!&#8217; I would say &#8216;It depends on how much you have left.&#8217; Yes, I mean until you die. I assumed that the reason WHY you want to learn to program is to make your app or a game. I&#8217;ll try to estimate the time you will need, taking games into account because I kinda know the subject. I won&#8217;t even try to estimate apps or web services, as they aren&#8217;t areas of my expertise. However, if you want to try to do that for these fields, you&#8217;re more than welcome. In the article, I&#8217;ve prepared a table that estimates how much time do you need from total zero programming knowledge to finishing your game. I&#8217;ve included different kinds of games so that you can have a better picture of that. You may have a small &#8220;haha, right&#8230;&#8221; on your face right now, that&#8217;s okay because I&#8217;m basing on my experience and convictions. If you think numbers can be more accurate, feel free to add your two cents in the comments, and we&#8217;ll make it better. Now click &#8216;read more…&#8217; and check out the numbers.<span id="more-493"></span></p>
<h1>First, let&#8217;s make some assumptions</h1>
<ul>
<li style="text-align: justify;">You&#8217;ve got a daily job, ~40 hours per week,</li>
<li style="text-align: justify;">You&#8217;re pretty motivated. It means that if you can go out with friends, to the cinema or play a game a whole evening twice a week, now you can do this twice per month because you rather be programming.</li>
<li style="text-align: justify;">I&#8217;m NOT estimating the time needed for graphics/sounds creation.</li>
<li style="text-align: justify;">Some of the games (marked as &#8216;Solo&#8217;) you can make all by yourself, some of them require a team (&#8216;Team&#8217;). While estimating the second ones, I assumed that you need to learn by doing some smaller projects first, then you need to be hired by a company.</li>
<li style="text-align: justify;">In &#8216;Solo&#8217; projects by &#8216;learn&#8217; I mean that you understand what you&#8217;re doing and what people in tutorials say. The code you&#8217;ll write won&#8217;t be the most robust (well-planned and fast) code ever written, though. Companies usually (especially these bigger ones) are more demanding than that, so the learning time is longer in that case.</li>
<li style="text-align: justify;">You use existing engine (Unity, Unreal Engine, Game Maker, the one that a company uses, etc.)</li>
<li style="text-align: justify;">You&#8217;re learning by reading AND practice (article lecture -&gt; coding attempt -&gt; tutorial -&gt; next coding attempt).</li>
<li style="text-align: justify;">More advanced games require (a bit) more advanced math from you that you need to learn as well.</li>
</ul>
<p style="text-align: justify;"><strong>So as you may see, if you&#8217;ve got plenty of free time and you&#8217;re HIGHLY motivated, time probably will be significantly shorter.</strong></p>
<p style="text-align: justify;">If you just want to make a game, with only a little understanding of what&#8217;s going on, time probably will be significantly shorter as well. But I don&#8217;t think that&#8217;s the case if you particularly asked about &#8216;learning.&#8217;</p>
<h1>OK, enough talk, here&#8217;s a table</h1>
<p><img class="aligncenter wp-image-495 size-full" src="http://gamesarchitecture.com/wp-content/uploads/2017/12/EXCEL_2017-12-04_21-53-48.jpg" alt="Table with learning times for different games" width="535" height="379" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/12/EXCEL_2017-12-04_21-53-48.jpg 535w, http://gamesarchitecture.com/wp-content/uploads/2017/12/EXCEL_2017-12-04_21-53-48-300x213.jpg 300w" sizes="(max-width: 535px) 100vw, 535px" /></p>
<p style="text-align: justify;">*The time is not the time that particular game was made in, it is just my estimation (running away with me)</p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/is-it-too-late-to-start-learning-programming/">&#8220;Is it too late for me to start learning programming?&#8221;</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamesarchitecture.com/is-it-too-late-to-start-learning-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t bring web development toys to Unity&#8217;s kindergarten</title>
		<link>http://gamesarchitecture.com/dont-bring-web-development-toys-to-unitys-kindergarten/</link>
		<comments>http://gamesarchitecture.com/dont-bring-web-development-toys-to-unitys-kindergarten/#comments</comments>
		<pubDate>Fri, 17 Nov 2017 22:18:51 +0000</pubDate>
		<dc:creator><![CDATA[Bartosz]]></dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://gamesarchitecture.com/?p=466</guid>
		<description><![CDATA[<p>That&#8217;s right, I said it. It looks like some web developers want to bring their habits to Unity with them. I understand that you expect it will be easier this way. But I think it may be easier for you (at the beginning), but not for other game developers. Especially not for Unity developers. I &#8230; </p>
<p class="link-more"><a href="http://gamesarchitecture.com/dont-bring-web-development-toys-to-unitys-kindergarten/" class="more-link">Continue reading<span class="screen-reader-text"> "Don&#8217;t bring web development toys to Unity&#8217;s kindergarten"</span></a></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/dont-bring-web-development-toys-to-unitys-kindergarten/">Don&#8217;t bring web development toys to Unity&#8217;s kindergarten</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-467" src="http://gamesarchitecture.com/wp-content/uploads/2017/11/1325383397346.png" alt="" width="1534" height="630" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/11/1325383397346.png 1534w, http://gamesarchitecture.com/wp-content/uploads/2017/11/1325383397346-300x123.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/11/1325383397346-768x315.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/11/1325383397346-1024x421.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">That&#8217;s right, I said it. It looks like some web developers want to bring their habits to Unity with them. I understand that you expect it will be easier this way. But I think it may be easier for you (at the beginning), but not for other game developers. Especially not for Unity developers. I came across a couple blog posts, and I saw in the comments that people that thank for the &#8220;MVC for Unity tutorial&#8221; are the ones that are already familiar with MVC and want to do something in Unity. I find it a quite dangerous approach. It looks like they don&#8217;t know what MVC is for, WHY do we even use it. Main benefits of using it shatter in Unity when understood wrong. When I want to learn Unity, I should look for &#8220;Unity tutorial&#8221; in Google. Or &#8220;Xamarin tutorial,&#8221; or &#8220;Ruby on Rails tutorial.&#8221; Looking for something like &#8220;How to make a web page in Unity&#8221; doesn&#8217;t seem the most effective path, though it may be an interesting adventure. It’s a good idea to explain some new concepts basing on the ones you are already familiar with (i.e. <a href="https://docs.unrealengine.com/latest/INT/GettingStarted/FromUnity/" target="_blank" rel="noopener">Unreal Engine for Unity developers</a>). But then you should familiarize with the new framework and its &#8220;culture.&#8221; And don&#8217;t get me wrong, it&#8217;s totally okay to try new, even weird, things. It may only develop you as a programmer. Go, have fun, make a game in assembly or banking app in Unity. But if you really want to learn something new, then learn something new. Don&#8217;t stick to your habits just because you feel safe. Let&#8217;s get to some technical details.<span id="more-466"></span></p>
<h1>Content</h1>
<p>What is MVC and what it gives us<br />
How we work in Unity<br />
Where is the MVC?<br />
My problems with that understanding of MVC<br />
Summary<br />
Some links</p>
<h1 style="text-align: justify;">What is MVC and what it gives us</h1>
<p>MVC is an architectural concept that separates application to three domains.</p>
<ul>
<li>Model &#8211; Data and data access. It does nothing except containing data and (eventually) providing API for data management.</li>
<li>View &#8211; The visual presentation that is responsible for displaying Model in some way (tables, scroll views, etc.) The View never changes the Model directly.</li>
<li>Controller – A bunch of scripts that interpret user input, change Model according to it and deciding which View to display next.</li>
</ul>
<p style="text-align: justify;">Through all these years (<a href="http://heim.ifi.uio.no/~trygver/1979/mvc-2/1979-12-MVC.pdf" target="_blank" rel="noopener">the oldest paper I found is from 1979</a>), MVC got many varieties. You can approach different definitions of MVC if you ask different people with different development backgrounds. I’ll provide you with sources I based on. Anyway, MVC has been adapted to many platforms, and Unity is one of them.</p>
<p>Alright, that&#8217;s the basic idea, but what are the benefits of using MVC?</p>
<ol>
<li>Separation of a back-end (often &#8211; a model and a controller) from the front-end (a view), so web designers can focus on a page look and developers on managing data, connections with databases, etc.</li>
<li>Controller separation, so if we want to add or change the way data is processed (application behavior), view and model don&#8217;t care,</li>
<li>View separation so that we can have multiple views (i.e. for different platform/browser) or we&#8217;re able to reskin web page easily, without bothering developers.</li>
<li>Probably more. Can you add something?</li>
</ol>
<h1>How we work in Unity</h1>
<p>I&#8217;m assuming you know Unity, or at least its architecture based on components and how to combine them to make something work. We&#8217;ll need an understanding of &#8220;<a href="http://gamesarchitecture.com/cohesive-abstraction-solving-most-of-your-dilemmas-in-an-easy-way/" target="_blank" rel="noopener">class cohesion</a>&#8221; as well.</p>
<p style="text-align: justify;">When we (me and my teammates, whatever a team was) made a game, everyone who worked in Unity was a Unity developer. Unity was a front-end. A separate server (i.e. GameSparks, something on Azure) and a database were a back-end. Unity talked with the server via a REST API (Get, Post, etc.) if a game needed it. The server was responsible for communication with the database. Artists worked on graphics and sound assets, and very often they didn&#8217;t have Unity installed at all. Designers worked on scenes (level design, aligning UI) and tweaked values in the Inspector.</p>
<h1>Where is the MVC?</h1>
<p>We can look for MVC architecture in the project in a couple of ways. Everything depends on how far we zoomed out our perspective.</p>
<ul>
<li style="text-align: justify;">F2P or multiplayer games usually need a server and a database (back-end). Users data and values for level definitions/difficulty are kept in the database. Game logic (the rules; how you play the game) are scripted in Unity. But some of the things, like if a player should win a reward, should be implemented on the server to prevent cheating. Okay, so what in that case is M, V, and C in our MVC concept? For me, it looks like the database is a Model (data part), the server (with a bunch of scripts) is a Model (data access part) and Controller (method for random reward winning), and Unity is a Controller (game logic) and a View. If you&#8217;ve got a different perspective of that, remember to share it with us in comments.</li>
<li style="text-align: justify;">Singleplayer games usually don&#8217;t need a server or database (maybe for analytics). In this case, Unity is responsible for all the letters in &#8220;MVC,&#8221; and forcing MVC concepts here is risky. In <a href="https://www.toptal.com/unity-unity3d/unity-with-mvc-how-to-level-up-your-game-development" target="_blank" rel="noopener">this very popular blog post</a> about it, the author cuts a Player to three different scripts (one per M, V, and C). I don&#8217;t agree with that concept, and here&#8217;s why.</li>
</ul>
<h1>My problems with that understanding of MVC</h1>
<ul>
<li style="text-align: justify;">MVC adds another level of complexity you have to manage and maintain. It&#8217;s not natural for Unity projects, so it is harder to get used to for Unity developers.</li>
<li style="text-align: justify;">Unity supports building for different platforms and does the hardest part for you. Is it Android or iPhone UI? For Unity, in most cases, it doesn&#8217;t matter. You can do a reskin in the editor. It doesn&#8217;t matter if a reskinned object has some behavior on it or not. Designer updates only one of its component anyway.</li>
<li style="text-align: justify;">It kills and pees the <a href="https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)" target="_blank" rel="noopener">encapsulation</a>. A Player object that has some scripts on it, another PlayerView object with a Renderer and yet another one with Health field? It&#8217;s not like object-oriented programming works. Classes are collections of data and behavior. MVC (in above understanding) separates these two things from each other.</li>
<li style="text-align: justify;">It does the same to hermetization (hiding) and makes reasoning about a code much harder. &#8220;This access will allow every MVC class to reach every other.&#8221; Without any constraints, the code flow may (and will) complicate very quickly. Hermetization is one of the most important (if not the most) OOP paradigm (though it is often described as a part of the encapsulation).</li>
<li style="text-align: justify;">The sentence <em>&#8220;By splitting the thinking process into data, interface, and decisions, developers can reduce the number of source files that must be searched in order to add or fix functionality.&#8221;</em> is just not true. It&#8217;s exactly the opposite. Instead of one Player script, now we have three of them. To handle a new parameter you&#8217;d have to update THREE files and the code communication between them. Every change is much harder to manage.</li>
<li style="text-align: justify;">It’s slower. Instead of managing the Player in a Player script (it sounds obvious, right?), you&#8217;re wasting resources on sending messages.</li>
</ul>
<h1>Summary</h1>
<p style="text-align: justify;">As you probably noticed, it seems like successfully applying MVC architecture strongly depends on what you consider being M, V, and C. Don&#8217;t adapt known concepts to new environments just because it seems possible. First, you should probably try to learn the new environment to some extent, how it works and what practices are the most broadly used before you consider changing it. Probably. The decision about that shouldn&#8217;t be based only on the convenience or discomfort you feel while thinking about The Great New. Work with others, ask more experienced developers what they think about your idea. MVC is a great architectural concept, but like every other pattern, it shouldn&#8217;t be adapted to new situation carelessly, just because it worked perfectly somewhere else. Maybe someday someone will show great examples of &#8220;MVC for Unity.&#8221; Don&#8217;t stop looking for better workflows and don&#8217;t forget to inform me if you find something interesting.</p>
<h1>Some links</h1>
<ul>
<li><a href="http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html" target="_blank" rel="noopener">Sources about MVC (dated to 1979)</a></li>
<li><a href="http://heim.ifi.uio.no/~trygver/1979/mvc-2/1979-12-MVC.pdf" target="_blank" rel="noopener">Trygve Reenskaug &#8211; MODELS &#8211; VIEWS &#8211; CONTROLLERS (1979)</a></li>
<li><a href="https://www.toptal.com/unity-unity3d/unity-with-mvc-how-to-level-up-your-game-development" target="_blank" rel="noopener">Unity with MVC: How to Level Up Your Game Development</a></li>
<li><a href="https://blog.codinghorror.com/understanding-model-view-controller/" target="_blank" rel="noopener">Understanding Model-View-Controller (Coding Horror)</a></li>
<li><a href="http://blog.iandavis.com/2008/12/what-are-the-benefits-of-mvc/" target="_blank" rel="noopener">What Are The Benefits of MVC?</a></li>
</ul>
<div class="grammarly-disable-indicator"></div>
<div class="grammarly-disable-indicator"></div>
<div class="grammarly-disable-indicator"></div>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/dont-bring-web-development-toys-to-unitys-kindergarten/">Don&#8217;t bring web development toys to Unity&#8217;s kindergarten</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamesarchitecture.com/dont-bring-web-development-toys-to-unitys-kindergarten/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Read it like a book &#8211; Painless way of programming Game Modes and Skills (Part III)</title>
		<link>http://gamesarchitecture.com/painless-way-of-programming-game-modes-and-skills-strategy-pattern/</link>
		<comments>http://gamesarchitecture.com/painless-way-of-programming-game-modes-and-skills-strategy-pattern/#comments</comments>
		<pubDate>Fri, 29 Sep 2017 20:01:08 +0000</pubDate>
		<dc:creator><![CDATA[Bartosz]]></dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://gamesarchitecture.com/?p=431</guid>
		<description><![CDATA[<p>Strategy is a meritorious pattern, and I think it may interest you. Why? Because you want your code to be flexible. That flexibility allows you, for example, to switch behavior with ease, whenever you like. You don’t want to replace half of the classes when the rules of your game change. Or maybe you want &#8230; </p>
<p class="link-more"><a href="http://gamesarchitecture.com/painless-way-of-programming-game-modes-and-skills-strategy-pattern/" class="more-link">Continue reading<span class="screen-reader-text"> "Read it like a book &#8211; Painless way of programming Game Modes and Skills (Part III)"</span></a></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/painless-way-of-programming-game-modes-and-skills-strategy-pattern/">Read it like a book &#8211; Painless way of programming Game Modes and Skills (Part III)</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-440" src="http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_skills_tapir.png" alt="" width="1176" height="546" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_skills_tapir.png 1176w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_skills_tapir-300x139.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_skills_tapir-768x357.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_skills_tapir-1024x475.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;"><em>Strategy</em> is a meritorious pattern, and I think it may interest you. Why? Because you want your code to be flexible. That flexibility allows you, for example, to switch behavior with ease, whenever you like. You don’t want to replace half of the classes when the rules of your game change. Or maybe you want to have different game modes, and you’re struggling with <code>switch</code> statements all around the place? <em>Strategy</em> pattern allows you to code another game mode without the fear of breaking the rest of the game.</p>
<p><span id="more-431"></span></p>
<h1>&#8216;Read it like a book&#8217; series</h1>
<p><a href="http://gamesarchitecture.com/read-it-like-a-book-centralized-control-part-i" target="_blank" rel="noopener">Part I &#8211; Centralized Control</a><br />
<a href="http://gamesarchitecture.com/read-it-like-a-book-what-to-do-when-centralized-control-does-not-work-part-ii/" target="_blank" rel="noopener">Part II &#8211; What to do when Centralized Control does not work?</a><br />
Part III &#8211; Painless way of programming Game Modes and Skills (this)<br />
Part IV &#8211; Soon</p>
<h1>Content</h1>
<p>When you might need a Strategy?<br />
Strategy Example &#8211; Player Skills<br />
Strategy Example &#8211; Game Modes<br />
One more thing<br />
Summary</p>
<h1>When you might need a Strategy?</h1>
<p style="text-align: justify;">Even if you&#8217;ve got only two game modes you&#8217;ll make use of the <em>Strategy</em>, because of the effortless switching between them in runtime. Cases where you&#8217;ll take advantage of the pattern, don&#8217;t have to be such big things like whole game modes, though. Maybe you&#8217;ve got a bunch of skills (mapped from 1 to 9 on the keyboard) that are used by pressing a key, but their behavior differs from each other fundamentally. One skill will increase the player&#8217;s HP; another one will change him into a super-fast blue tapir. All the skills have few things in common:</p>
<ul>
<li style="text-align: justify;">They all are used by the player the same way &#8211; press a key, and wait for an animation to end.</li>
<li style="text-align: justify;">The class that uses them shouldn&#8217;t know the difference between one and another, so it won’t be dependent on their implementation &#8211; the skills are interchangeable.</li>
<li>They can be switched between the keys on the fly.</li>
<li style="text-align: justify;">They change the player somehow, so they need a reference to him or a proper player’s interface. We assume that skills are very different, so we cannot extract common parameters for them. In that case, the best solution is to pass the player’s object to them (if a &#8216;Dependency Injection&#8217; term came up to your mind, you’re damn right).</li>
<li style="text-align: justify;">You want to add/remove/update skills independently from the rest of the codebase, and you probably wish to have a painless way of doing that.</li>
</ul>
<p>Let&#8217;s see how the <em>Strategy</em> pattern looks like in general:<br />
<img class="aligncenter size-full wp-image-441" src="http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_pattern.png" alt="" width="1660" height="880" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_pattern.png 1660w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_pattern-300x159.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_pattern-768x407.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_pattern-1024x543.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">You&#8217;ve got a <em>Strategy</em> abstract class that the <code>Context</code> uses. Concrete strategies derive from a <em>Strategy</em> to define a particular behavior. Each of them has its class so that they can be defined independently.<br />
<code>Context</code> is configured with a concrete strategy by another class or by itself. It delegates the operation to its current strategy class to avoid <code>switch</code> statements here and there.</p>
<h1>Strategy Example &#8211; Player Skills</h1>
<p>Below you can see how the <em>Strategy</em> may look like when put into the player’s skills scenario:<br />
<img class="aligncenter size-full wp-image-442" src="http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_player_skills.png" alt="" width="1690" height="878" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_player_skills.png 1690w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_player_skills-300x156.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_player_skills-768x399.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_player_skills-1024x532.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">The most important question now is probably &#8216;How to configure the <code>Player</code> with a concrete <code>PlayerSkill</code> class?&#8217;</p>
<p style="text-align: justify;">The simplest solution is probably to call an event in <code>SkillBar</code> script every time the player had pressed a proper key. Catch that event in the <code>UIController</code>, which has a reference to the player, and cast a chosen skill from there.</p>
<p><img class="aligncenter size-full wp-image-443" src="http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_player_skills_initializing.png" alt="" width="1250" height="656" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_player_skills_initializing.png 1250w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_player_skills_initializing-300x157.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_player_skills_initializing-768x403.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_player_skills_initializing-1024x537.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">The above solution lets you add many skills without worrying that it&#8217;ll affect the rest of the game. You don&#8217;t have to have <code>switch</code> statements with a <code>case</code> for every skill. You don&#8217;t need an additional <code>enum</code> field in skills or dynamic casting to know which skill is it. You may have a few other programmers working on their skills implementation without interfering with each other. How does it sound?</p>
<h1>Strategy Example &#8211; Game Modes</h1>
<p>While <code>Player</code>&#8211;<code>Skill</code> relation is quite ephemeral (we&#8217;re using a skill and moving on), <code>Gameboard</code> will definitely keep a reference to the <code>GameMode</code> through the whole play:<br />
<img class="aligncenter size-full wp-image-444" src="http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_game_modes.png" alt="" width="1464" height="950" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_game_modes.png 1464w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_game_modes-300x195.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_game_modes-768x498.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/09/strategy_game_modes-1024x664.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;"><code>Gameboard</code> delegates a few different operations to the <code>GameMode</code> <em>Strategy</em>. We’ve got a Chess game and two modes: Classic and Battle.<br />
<code>Classic</code>:<br />
<code>StartGame()</code>: Set up chess normally.<br />
<code>EndGame()</code>: Clear out the board and show statistics.<br />
<code>OnPlayerMoved()</code>: Switch active player</p>
<p><code>Battle</code>:<br />
<code>StartGame()</code>: Set up chess and randomize positions of a few pawns for both players.<br />
<code>EndGame()</code>: Clear out the board and show statistics (same behavior as <code>Classic</code>).<br />
<code>OnPlayerMoved()</code>: Disable random empty field, so the chess cannot be moved there.</p>
<p style="text-align: justify;">And <code>Gameboard</code> doesn’t know about any of that. It is initialized with a particular <code>GameMode</code> depending on a button the player clicks. All its operations which behavior depends on a game mode are delegated to the <em>Strategy</em> pattern. Do you need a new game mode? Create a new class that derives from a <code>GameMode</code>, implement its abstract interface and place a new game mode button in the menu. Simple as that.</p>
<h1>One more thing</h1>
<p style="text-align: justify;">It is worth to mention one more variation of the pattern. If you’ve got many operations in the <em>Strategy</em> and a bunch of game modes that differ only in one or two of them, you can have a default game mode with virtual methods. It would be placed between the abstract class (<code>GameMode</code>) and concrete strategies (<code>Classic</code> and <code>Battle</code>). If your game mode doesn’t change default behavior it doesn’t override its method.</p>
<h1>Summary</h1>
<p style="text-align: justify;">Today, we haven’t mentioned the <em>Singleton</em>. The <em>Strategy</em> MIGHT help you avoid using <em>Singleton</em>, but it isn&#8217;t its primary purpose and the biggest advantage. However, it is a very precious tool in your arsenal as many games would make a very good use of it. In the next post, you&#8217;ll see a design pattern that is very similar to the <em>Singleton</em> but somehow better. It should fill all the gaps that we haven&#8217;t filled yet.</p>
<p style="text-align: justify;"><em>And now I wish to ask you for advice. Tell me how do you feel about the Games Architecture. Do you think that I should change something, or everything is perfect for you? Maybe you&#8217;ve got a particular problem and want to share it with us so we can think how to solve it together? I&#8217;m here, and I can hear you.</em></p>
<div class="grammarly-disable-indicator"></div>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/painless-way-of-programming-game-modes-and-skills-strategy-pattern/">Read it like a book &#8211; Painless way of programming Game Modes and Skills (Part III)</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamesarchitecture.com/painless-way-of-programming-game-modes-and-skills-strategy-pattern/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Short #1 Don&#8217;t stick to &#8216;no negations in conditions&#8217; rule</title>
		<link>http://gamesarchitecture.com/short-1-dont-stick-to-no-negations-in-conditions-rule/</link>
		<comments>http://gamesarchitecture.com/short-1-dont-stick-to-no-negations-in-conditions-rule/#comments</comments>
		<pubDate>Tue, 12 Sep 2017 14:49:14 +0000</pubDate>
		<dc:creator><![CDATA[Bartosz]]></dc:creator>
				<category><![CDATA[Good Practices]]></category>
		<category><![CDATA[Shorts]]></category>

		<guid isPermaLink="false">http://gamesarchitecture.com/?p=422</guid>
		<description><![CDATA[<p>I mean, what&#8217;s the point? Let the code flow naturally after the &#8216;if&#8217; and leave more unlikely situations for &#8216;else&#8217; (displaying error for instance). In the &#8216;if&#8217; block, you can put cases that are more natural for your game. A player wants to deal damage to living enemies. It is more common, as dead bodies &#8230; </p>
<p class="link-more"><a href="http://gamesarchitecture.com/short-1-dont-stick-to-no-negations-in-conditions-rule/" class="more-link">Continue reading<span class="screen-reader-text"> "Short #1 Don&#8217;t stick to &#8216;no negations in conditions&#8217; rule"</span></a></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/short-1-dont-stick-to-no-negations-in-conditions-rule/">Short #1 Don&#8217;t stick to &#8216;no negations in conditions&#8217; rule</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;"><img class="aligncenter size-full wp-image-426" src="http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-11-o-19.46.55.png" alt="" width="1400" height="398" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-11-o-19.46.55.png 1400w, http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-11-o-19.46.55-300x85.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-11-o-19.46.55-768x218.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-11-o-19.46.55-1024x291.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" />I mean, what&#8217;s the point? Let the code flow naturally after the &#8216;if&#8217; and leave more unlikely situations for &#8216;else&#8217; (displaying error for instance). In the &#8216;if&#8217; block, you can put cases that are more natural for your game. A player wants to deal damage to living enemies. It is more common, as dead bodies are usually waiting for being cleaned up and are less attractive for the player. So:<span id="more-422"></span></p>
<pre class="brush: csharp; collapse: false; title: ; notranslate">If (!enemy.IsDead())
{
    enemy.TakeDamage();
}
else
{
    enemy.AddForce(FORWARD); // Profane the corpse
}</pre>
<p style="text-align: justify;">It increases readability and stresses the expected game flow. If an attacker tells Mr. Wayne &#8220;Give me that wallet, or else…,&#8221; Mr. Wayne should give the wallet back, move on and doesn&#8217;t care about &#8220;else.&#8221; It&#8217;s the standard course of the situation and that solution should be considered first.</p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/short-1-dont-stick-to-no-negations-in-conditions-rule/">Short #1 Don&#8217;t stick to &#8216;no negations in conditions&#8217; rule</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamesarchitecture.com/short-1-dont-stick-to-no-negations-in-conditions-rule/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Read it like a book &#8211; What to do when Centralized Control does not work? (Part II)</title>
		<link>http://gamesarchitecture.com/read-it-like-a-book-what-to-do-when-centralized-control-does-not-work-part-ii/</link>
		<comments>http://gamesarchitecture.com/read-it-like-a-book-what-to-do-when-centralized-control-does-not-work-part-ii/#respond</comments>
		<pubDate>Fri, 01 Sep 2017 19:48:49 +0000</pubDate>
		<dc:creator><![CDATA[Bartosz]]></dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://gamesarchitecture.com/?p=412</guid>
		<description><![CDATA[<p>In the previous post of &#8216;Read it like a book&#8217; series we talked about Centralized Control. In this basic object-oriented concept, high-level classes call methods on lower-level ones. Lower-level classes call events that the high-level classes listened and reacted to. But it is not always the best or even a possible solution. Observers are great, &#8230; </p>
<p class="link-more"><a href="http://gamesarchitecture.com/read-it-like-a-book-what-to-do-when-centralized-control-does-not-work-part-ii/" class="more-link">Continue reading<span class="screen-reader-text"> "Read it like a book &#8211; What to do when Centralized Control does not work? (Part II)"</span></a></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/read-it-like-a-book-what-to-do-when-centralized-control-does-not-work-part-ii/">Read it like a book &#8211; What to do when Centralized Control does not work? (Part II)</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;"><img class="aligncenter size-full wp-image-417" src="http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-01-o-21.38.16.png" alt="" width="1608" height="600" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-01-o-21.38.16.png 1608w, http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-01-o-21.38.16-300x112.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-01-o-21.38.16-768x287.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-01-o-21.38.16-1024x382.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" />In the previous post of &#8216;Read it like a book&#8217; series we talked about Centralized Control. In this basic object-oriented concept, high-level classes call methods on lower-level ones. Lower-level classes call events that the high-level classes listened and reacted to. But it is not always the best or even a possible solution. Observers are great, but there are cases where using them leads to classes that cause some nasty problems. In the next two posts of the series we&#8217;ll introduce design patterns that&#8217;ll help you to handle foreign services (databases, analytics), multi-platform development (analogical, but separate services for Android and iOS, like In-App Purchases or Leaderboards) and such everyday things like Audio or Input Managers.<br />
<span id="more-412"></span></p>
<h1>&#8216;Read it like a book&#8217; series</h1>
<p><a href="http://gamesarchitecture.com/read-it-like-a-book-centralized-control-part-i" target="_blank" rel="noopener">Part I &#8211; Centralized Control</a><br />
Part II &#8211; What to do when Centralized Control does not work? (this)<br />
<a href="http://gamesarchitecture.com/painless-way-of-programming-game-modes-and-skills-strategy-pattern/" target="_blank" rel="noopener">Part III &#8211; Painless way of programming Game Modes and Skills</a><br />
Part IV &#8211; Soon</p>
<h1>Content:</h1>
<p>A few more information about Centralized Control<br />
Devil&#8217;s favor of the Singleton<br />
What did they tell you about Inversion of Control?<br />
Just pass it</p>
<h1>A few more information about Centralized Control</h1>
<p style="text-align: justify;">1. Remember about the cohesive abstraction. If your <em>UIController</em> operates on too low-level objects, consider creating a class in the middle. If, for example, the <em>UIController</em> turns on and off whole game screens and, on the other hand, keeps track of player&#8217;s score value and <em>Text</em> component that displays that value, something smells bad. You can create <em>ScoreUI</em> class with <code>AddPoints(int)</code> interface method, which will do the same, but it will hide it behind a single method call. If you add animation after the score updates, you have to update only that method. Having abstraction in mind somehow forces you to write more methods, and the more named pieces of code, the better. You get greater flexibility and easier codebase maintenance.</p>
<p style="text-align: justify;">2. Cohesive abstraction helps to maintain a beautiful tree of a class hierarchy, but it is quite difficult to keep that abstraction tight. Mainly because in game development we often want to program smaller features fast. This is where the little bugs come from. Sometimes it is tempting to add the score handling to the <em>UIController</em> because it is faster than creating a new class for it. Especially if you just want to add points. If you create a <em>ScoreUI</em> class with only <code>AddPoints()</code> procedure, you may &#8220;feel&#8221; like you HAVE TO add the whole interface right away. <code>Reset()</code>, <code>GetScore()</code>, <code>Save()</code>, <code>Subtract()</code> and maybe a few more. You know what? You don&#8217;t have to. Add the <em>ScoreUI</em> class with the interface you need RIGHT NOW. If you or someone else will need new API later, the right script is already there.</p>
<h1>Devil&#8217;s favor of the Singleton</h1>
<p style="text-align: justify;">Singleton pattern arouses many emotions. It is a class that can only has one instance, and it can be used from every corner of the codebase &#8211; it is globally available. In game development it’s so popular, that we can see it almost everywhere. <em>Audio Manager</em>? Singleton. <em>Input Manager</em>? Singleton. <em>Analytics Controller</em>? Singleton. It is not bad on its own, but it is often used very dangerously. Robert Nystrom has already written an <a href="http://gameprogrammingpatterns.com/singleton.html" target="_blank" rel="noopener">excellent piece</a> about it, and I strongly advise you to read it.</p>
<p>You can use it just like that:<br />
<code>AchievementsController.Instance().UnlockAchievement(Achievements.SINGLETON_ARTICLE_READ);</code></p>
<p style="text-align: justify;">If you do not see why this is bad, read the above article first with a strong emphasis on <a href="http://gameprogrammingpatterns.com/singleton.html#why-we-regret-using-it" target="_blank" rel="noopener">Why We Regret Using It</a> section. I wish to add one more thing to the What We Can Do Instead part.</p>
<p style="text-align: justify;">Let&#8217;s take an <em>Achievement Controller</em> as an example. To avoid coupling everything that unlocks an achievement to a singleton class you can consider events. Did a player jump off from a gigantic cliff? Send <code>PlayerFeltFromHeight(float)</code> event and allow <em>Achievement Controller</em> to decide if the achievement should be unlocked or not. Some of the events may seem like they exist for only that particular reason, so what? You lose nothing and gain decoupled classes. You may consider this solution whenever you need to call something, and a return value is not expected (send analytics data, post leaderboards score, update database and so on.). Of course, it&#8217;s not always possible, but we&#8217;ll get to it.</p>
<p style="text-align: justify;">A more tricky situation is when you need something FROM the Singleton class.<br />
<code>IAPController.Instance().GetPrice(Items.BAZOOKA);</code><br />
or<br />
<code>InputController.GetActionDown(Actions.JUMP);</code><br />
I intentionally left off the &#8216;<code>Instance()</code>&#8216; in the second example. Here, the <em>Input Controller</em> does not have an instance; it is a simple static class. It is often a better choice because you do not always need an object at all. In the above cases, we&#8217;ve got a few options. But first, let me ask you a question.</p>
<h1>What did they tell you about Inversion of Control?</h1>
<p style="text-align: justify;">You may have heard of it as a term interchangeable to Dependency Injection, but it is not accurate. Dependency Injection is a one way to achieve Inversion of Control (IoC). Do you remember the scheme from the previous post with a class tree? IoC is when the arrow goes up, instead of going down (still, only one arrow connects these two classes). Instead of letting the high-level class to decide where to call low-level methods, we allow low-level classes to do the opposite. The control is inverted.</p>
<p style="text-align: justify;">I often struggled with an <em>Audio Controller</em> on multi-scene games (so most of them). I usually had only one <em>Audio Controller</em> with ALL the references from the WHOLE game to listen to events and play sounds according to what happened, but it has a few drawbacks. On a scene change, I had to find the proper references, start to listen to them and stop when the scene changed. When I added (or remove) something &#8220;vocal&#8221; to the scene, I had to update the <em>Audio Controller</em> script to listen and react to that new thing. The class contained mostly one-line methods that only play a sound when something happens. Reading such a class to see what clips play when is a real pain. The standard solution to that is to have <em>Audio Controller</em> as a singleton and call its methods from the classes that need a sound. To be honest, this is a by far more convenient way to solve this. But not every class needs that possibility, so let&#8217;s do something else, what will give us an extra feature and keep the architecture neat.</p>
<p style="text-align: justify;">Let&#8217;s assume we&#8217;ve got an RPG game, where the player can pick a male or female character. With a standard audio singleton, we would need to put some &#8216;ifs&#8217; here and there to play a sound depending on a character&#8217;s sex. Or we could have two derived classes for male and female that differ only with playing sounds. Or we can use Dependency Injection.</p>
<h1>Just pass it</h1>
<p style="text-align: justify;">Dependency Injection is a pattern when you pass the necessary reference through the constructor or some kind of setter method (<code>Initialize()</code> for instance) to the class that needs it. In the above example, the <em>Player</em> class could have an <code>Initialize(..., AudioController, ...)</code> method. Then, whenever it needs to shout, it calls an <em>Audio Controller</em>&#8216;s method. The huge advantage of that solution is that we don&#8217;t have to expect a concrete class. The method used for injecting audio controller can expect an interface. Like this <code>Initialize(..., ICharacterAudio, ...)</code>. Here we did two things. We allowed any class that implements this interface to pass, and we limited the audio only to character&#8217;s realm (i.e., screams, groans or steps). Now we are allowed to write something like this:</p>
<pre class="brush: csharp; collapse: true; light: false; title: ICharacterAudio (click to unfold); toolbar: true; notranslate">
public interface ICharacterAudio
{
    void Scream();
    void Groan();
    void Step();
}</pre>
<pre class="brush: csharp; collapse: true; light: false; title: PlayerMaleAudio (click to unfold); toolbar: true; notranslate">
public class PlayerMaleAudio : ICharacterAudio
{
    void Scream() { AudioController.Instance.PlaySound(PLAYER_MALE_SCREAM); }
    void Groan() { AudioController.Instance.PlaySound(PLAYER_MALE_GROAN); }
    void Step() { AudioController.Instance.PlaySound(PLAYER_STEP); } // The same sound for both sexes.
}</pre>
<pre class="brush: csharp; collapse: true; light: false; title: PlayerFemaleAudio (click to unfold); toolbar: true; notranslate">
public class PlayerFemaleAudio : ICharacterAudio
{
    // Replace all 'MALE' with 'FEMALE'
}</pre>
<p style="text-align: justify;">Now, allow to <em>Gameplay Controller</em>/<em>Character Creator Controller</em> to do this:</p>
<pre class="brush: csharp; collapse: true; light: false; title: GameplayController/CharacterCreatorController (click to unfold); toolbar: true; notranslate">
ICharacterAudio playerAudio;
if (playerSex == Sex.MALE) // playerSex can be taken for example from the CharacteCreator class or game's save file.
{
    playerAudio = new PlayerMaleAudio();
}
else if (playerSex == Sex.FEMALE)
{
    playerAudio = new PlayerFemaleAudio();
}
[...]

playerCharacter.Initialize(..., playerAudio, ...);</pre>
<p>Scheme for this architecture:<img class="aligncenter size-full wp-image-416" src="http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-01-o-21.37.20.png" alt="" width="2042" height="1238" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-01-o-21.37.20.png 2042w, http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-01-o-21.37.20-300x182.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-01-o-21.37.20-768x466.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/09/Zrzut-ekranu-2017-09-01-o-21.37.20-1024x621.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">By doing it that way, we can have a whole bunch of controllers for every sex, race (it doesn&#8217;t have to be a human after all) and age. Each one of them is small and very readable. Even more important, we have only one, very liberal, <em>Player</em> class that doesn&#8217;t care about the sex or race.</p>
<p style="text-align: justify;">To achieve even greater flexibility, we can add a setter to the <em>ICharacterAudio</em> to the <em>Player</em> so we can change it at runtime (in the Fable game, our character got older and older, and the voice changed).</p>
<p style="text-align: justify;">Now, we have <em>Audio Controller</em> linked only to the classes strictly responsible for audio. <em>Player</em> uses part of the sounds it needs, and we can add new character&#8217;s types very quickly.</p>
<p style="text-align: justify;">There is yet another way to deal with it. Perhaps more straightforward and popular. We don&#8217;t have to limit the access to sounds only to the classes that definitely need to play audio. We can just assume that every game object should have that possibility. In this case, we can put the reference to the <em>Audio Controller</em> in the base class of every game object (<em>Actor</em>, <em>GameObject</em> or something similar). Every object that is meant to be put on the scene can play a sound through inheritance. We can even go one step further and make <em>Audio Controller</em> a regular class, create an instance of it in some kind of <em>Game Controller</em> and initialize every <em>Game Object</em> with it through dependency injection. But the utility of that last step somehow depends on the engine you&#8217;re using. Remember, the goal is to minimize the number of singletons in your code or get rid of them entirely if possible, but don&#8217;t be so rigorous. If removing the singleton will cause more problems than profits, just drop that idea and maybe try to limit access to it to as few classes as possible.</p>
<p style="text-align: justify;">Sometimes passing that dependency may be a problem. In bigger codebases, it may be required to pass the injected object through a bunch of classes just to lead it to the class that really needs it. In the next part, we&#8217;ll talk about that and about dealing with multi-platform services (Facebook, analytics) and how to decouple the game code from them.</p>
<div class="grammarly-disable-indicator"></div>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/read-it-like-a-book-what-to-do-when-centralized-control-does-not-work-part-ii/">Read it like a book &#8211; What to do when Centralized Control does not work? (Part II)</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamesarchitecture.com/read-it-like-a-book-what-to-do-when-centralized-control-does-not-work-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easy method to fix bugs in your game &#8211; Debugging (Part II)</title>
		<link>http://gamesarchitecture.com/easy-method-to-fix-bugs-in-your-game/</link>
		<comments>http://gamesarchitecture.com/easy-method-to-fix-bugs-in-your-game/#respond</comments>
		<pubDate>Wed, 09 Aug 2017 19:23:49 +0000</pubDate>
		<dc:creator><![CDATA[Bartosz]]></dc:creator>
				<category><![CDATA[Generic]]></category>
		<category><![CDATA[Good Practices]]></category>

		<guid isPermaLink="false">http://gamesarchitecture.com/?p=357</guid>
		<description><![CDATA[<p>In an ideal world, we write bug-free code. In the same universe, we don&#8217;t have to struggle with marketing our indie games, and we are skilled in design, programming, graphics and audio. Today I&#8217;ll try to make fixing bugs easier and faster for you, so you&#8217;ll have more time for more enjoyable tasks. Welcome to &#8230; </p>
<p class="link-more"><a href="http://gamesarchitecture.com/easy-method-to-fix-bugs-in-your-game/" class="more-link">Continue reading<span class="screen-reader-text"> "Easy method to fix bugs in your game &#8211; Debugging (Part II)"</span></a></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/easy-method-to-fix-bugs-in-your-game/">Easy method to fix bugs in your game &#8211; Debugging (Part II)</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-380" src="http://gamesarchitecture.com/wp-content/uploads/2017/08/Zrzut-ekranu-2017-08-09-o-20.48.33.png" alt="" width="1380" height="424" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/08/Zrzut-ekranu-2017-08-09-o-20.48.33.png 1380w, http://gamesarchitecture.com/wp-content/uploads/2017/08/Zrzut-ekranu-2017-08-09-o-20.48.33-300x92.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/08/Zrzut-ekranu-2017-08-09-o-20.48.33-768x236.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/08/Zrzut-ekranu-2017-08-09-o-20.48.33-1024x315.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">In an ideal world, we write bug-free code. In the same universe, we don&#8217;t have to struggle with marketing our indie games, and we are skilled in design, programming, graphics and audio. Today I&#8217;ll try to make fixing bugs easier and faster for you, so you&#8217;ll have more time for more enjoyable tasks. Welcome to the second part of the series about making debugging an (almost) pleasant experience for you.</p>
<p style="text-align: justify;">Fixing bugs is difficult enough. You don&#8217;t want to add &#8216;What the fuck is this shit&#8217; on top of that. In the previous post &#8211; <a href="http://gamesarchitecture.com/debugging-part-i-7-good-code-practices-that-will-help-you-in-debugging/" target="_blank" rel="noopener">7 good code practices that will help you in debugging</a> &#8211; we tried to get rid of those unpleasant thoughts, so in this one, we&#8217;ll be dealing with a pure puzzle solving. That is because bug happens. So let&#8217;s get into it.</p>
<p><span id="more-357"></span></p>
<h1>&#8216;Debugging&#8217; series</h1>
<p><a href="http://gamesarchitecture.com/debugging-part-i-7-good-code-practices-that-will-help-you-in-debugging/" target="_blank" rel="noopener">Part I &#8211; 7 good code practices that will help you in debugging</a><br />
Part II &#8211; Easy method to fix bugs in your game (this)</p>
<h1>Content</h1>
<p>6 steps of debugging<br />
Easy to use tools and real-life example</p>
<h1>6 steps of debugging</h1>
<p style="text-align: justify;">Every issue is different, so it is not possible to write exact workflow for every one of them, so we&#8217;ll generalize it a bit. One more thing. I use this workflow. It worked for me when I had to fix bugs in my code, as well as bugs in huge codebases that I didn&#8217;t contribute in writing at all. I worked it out, and I want to share it with you. It doesn&#8217;t have to be as fabulous for you as it is for me, but if you don&#8217;t have your workflow, I believe this one is a great start. And after that, I&#8217;ll show you a real-life example.</p>
<h3>A. Find a scenario that in 100% of cases triggers the bug</h3>
<p style="text-align: justify;">Play a game until you know exactly how to bring out the issue. It is even more important in foreign code or game part you don&#8217;t remember very well. It helps you understand the code better if you already know its in-game behavior and all circumstances for the bug.</p>
<h3>B. Use tools to find a place in the code that is responsible for it</h3>
<p style="text-align: justify;">By tools I mean the IDE features you can use to see what the code does and what are the values of variables. We&#8217;ll talk about them later. I assure you that if you find a region where the bug is located, you have more than a half of the work behind you. By region, I mean a method or methods, class or a module. All the code that is involved in the examined feature. That&#8217;s where an advice from the <a href="http://gamesarchitecture.com/debugging-part-i-7-good-code-practices-that-will-help-you-in-debugging/" target="_blank" rel="noopener">first part of the series</a>, as well as the ones from the &#8220;<a href="http://gamesarchitecture.com/read-it-like-a-book-centralized-control-part-i/" target="_blank" rel="noopener">Read it like a book &#8211; Centralized Control</a>&#8221; article make a difference.</p>
<h3>C. Use tools to find out what is going on there</h3>
<p style="text-align: justify;">After this one you&#8217;ll know if the place you have found in &#8216;B&#8217; is the one that causes the bug. If not, repeat &#8216;B&#8217; and &#8216;C&#8217; until you find the bug. I&#8217;ll show you the example of &#8216;C&#8217; in a moment.</p>
<h3>D. Fix it</h3>
<p style="text-align: justify;">After a couple (of dozens) of &#8216;B&#8217;-&#8216;C&#8217; iterations, you&#8217;ll know your enemy. Fix it. It may be a simple change from &#8216;&lt;&#8216; to &#8216;&lt;=&#8217; or it may require some refactoring. You&#8217;ll probably know.</p>
<h3>E. Use tools to find out if it looks okay now</h3>
<p style="text-align: justify;">Basically, you have to repeat the &#8216;C&#8217; to see if the code looks correct now. A pretty common mistake is avoiding this point and going straight to the &#8216;F.&#8217; However, missing the &#8216;E&#8217; leads to the trial and error loop that may last as well five minutes as five hours or even days. If you already made the &#8216;C,&#8217; &#8216;E&#8217; will be easy peasy. I&#8217;m guilty of that mistake sometimes, but until now I&#8217;ve worked out a Samuel L. Jackson-like signal in my head that says &#8220;Stop. Right. There, you <a href="https://youtu.be/c0LBi1MHoaU?t=27" target="_blank" rel="noopener">motherfucka&#8217; motherfucka&#8217;</a>&#8221; Yeah, I&#8217;ve got that alarm, I&#8217;m not joking. It backs me on the right path.</p>
<h3>F. Test it in the game</h3>
<p style="text-align: justify;">Play the scenario from the &#8216;A&#8217; couple of times, and check if related features didn&#8217;t break. If the codebase is large, even if it is wonderfully written, the change can entail some unwanted flaws. It is worth to check it now when you&#8217;re &#8220;in the code.&#8221; It will be cheaper to fix it now than later.</p>
<h1>Easy to use tools and real-life example</h1>
<p style="text-align: justify;">I&#8217;m using Visual Studio 2017 Community here. The functions I&#8217;ll show below look much the same in previous versions, and they are present in most (if not all) nowadays&#8217; IDEs.</p>
<p style="text-align: justify;">I&#8217;ll show you a real bug from my project and the workflow of fixing it.</p>
<p style="text-align: justify;">First, I&#8217;ve observed such a behavior of an enemy.</p>
<p><img class="aligncenter size-full wp-image-358" src="http://gamesarchitecture.com/wp-content/uploads/2017/08/1.gif" alt="" width="896" height="520" /></p>
<p style="text-align: justify;">I&#8217;ve found that this &#8220;dancing&#8221; happens when the enemy sees the player and then the player runs away (step &#8216;A&#8217;). Since the enemy behavior utilizes <a href="http://gameprogrammingpatterns.com/state.html" target="_blank" rel="noopener">Finite-State Machine</a> pattern, the issue may be related to the one of its states &#8211; <code>ChasingState</code>. I put some breakpoints here and there (step &#8216;B&#8217;).</p>
<p><img class="aligncenter size-full wp-image-360" src="http://gamesarchitecture.com/wp-content/uploads/2017/08/2.gif" alt="" width="960" height="444" /></p>
<p style="text-align: justify;">Breakpoints mark the lines of code where the game should pause, so we will be able to check what are the variables&#8217; values at that point. From these breakpoints we can start going through the code step by step, and see the flow of the application. When we marked the suspicious places already, let&#8217;s launch a debugger.</p>
<p><img class="aligncenter size-full wp-image-361" src="http://gamesarchitecture.com/wp-content/uploads/2017/08/3.png" alt="" width="622" height="125" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/08/3.png 622w, http://gamesarchitecture.com/wp-content/uploads/2017/08/3-300x60.png 300w" sizes="(max-width: 622px) 100vw, 622px" /></p>
<p style="text-align: justify;">Yes, it&#8217;s as simple as that. In other IDE&#8217;s it may look a bit different, and maybe it is called &#8220;Start Debugging&#8221; or so, but you&#8217;ve got the idea.</p>
<p style="text-align: justify;">With a debugger running, we can start our game in the editor, and we repeat the scenario we found during step &#8216;A.&#8217; Then, the game pauses and Visual Studio shows up.</p>
<p><img class="aligncenter size-full wp-image-362" src="http://gamesarchitecture.com/wp-content/uploads/2017/08/4.gif" alt="" width="960" height="444" /></p>
<p style="text-align: justify;">Yellow background highlights the line that will execute. after we move to the very next line. It means that the highlighted one is waiting for execution, yet. In the meantime we can check, what the variables look like.</p>
<p style="text-align: justify;">Using the navigation buttons (or shortcuts) we can move as the code execution moves.</p>
<p><img class="aligncenter size-full wp-image-363" src="http://gamesarchitecture.com/wp-content/uploads/2017/08/5.gif" alt="" width="1026" height="200" /><br />
These buttons are:<br />
<em>Continue (F5)</em> &#8211; resumes the game and stops it on the next breakpoint.<br />
<em>Step Over (F10)</em> &#8211; Executes highlighted line and goes to the next one.<br />
<em>Step Into (F11)</em> &#8211; Same as F10, but when the highlighted line is a method call, it moves onto it.</p>
<p style="text-align: justify;">The next highlighted line will be the first line of this method. I&#8217;ve used these navigation shortcuts to check, what is going on there (step C).</p>
<p style="text-align: justify;"><em>There are two iterations &#8211; during one GIF play, we&#8217;re going into <code>IsCheckpointReached()</code> twice.</em></p>
<p><img class="aligncenter size-full wp-image-364" src="http://gamesarchitecture.com/wp-content/uploads/2017/08/6.gif" alt="" width="960" height="444" /></p>
<p style="text-align: justify;">I stepped into <code>IsCheckpointReached()</code> method by pushing F11 (using F10 would move me to line 119 or 121 depending on if statement&#8217;s result). During the first pass, the first &#8216;if&#8217; statement in <code>IsCheckpointReached()</code> was false. The execution moved to the line 122. I pushed F5 (Continue). After this, the next highlighted line was 117. It was the <code>IsCheckpointReached()</code> again (as in that time I had only one breakpoint set), but this time during the next frame. During the second pass, I&#8217;ve noticed that enemy reached X and Z coordinates (taking the error into account), but not Y. Since this enemy cannot jump or climb, checking Y is just wrong. Knowing that I could move to the step &#8216;D&#8217; &#8211; fixing. I&#8217;ve introduced a new <code>IsCheckpointReached()</code> method (with suffix &#8216;2D&#8217;), for the enemies that cannot jump and I&#8217;ve replaced the current function occurrences (found by clicking on the method and pushing Shift+F12 &#8211; Find All References) with this new version.</p>
<pre class="brush: csharp; collapse: true; light: false; title: IsCheckpointReached2D (click to unfold); toolbar: true; notranslate">    /// 
&amp;lt;summary&amp;gt;
    /// Indicates if the checkpoint has been reached or not. Takes distance error into account.
    /// 2D version of the method. Y axis is not checked.
    /// &amp;lt;/summary&amp;gt;

    /// &amp;lt;param name=&quot;enemy&quot;&amp;gt; Enemy that is checked. &amp;lt;/param&amp;gt;
    /// &amp;lt;param name=&quot;position&quot;&amp;gt; Position of the checkpoint. &amp;lt;/param&amp;gt;
    /// &amp;lt;param name=&quot;errorDistance&quot;&amp;gt; Error distance that can be made for X and Z axis. &amp;lt;/param&amp;gt;
    /// &amp;lt;returns&amp;gt;True - checkpoint reached, false - otherwise. &amp;lt;/returns&amp;gt;
    protected bool IsCheckpointReached2D(TEnemy enemy, Vector3 position, float errorDistance = 0.0f)
    {
        if (Math.Abs(position.x - enemy.transform.position.x) &amp;gt; errorDistance) return false;
        if (Math.Abs(position.z - enemy.transform.position.z) &amp;gt; errorDistance) return false;

        return true;
    }</pre>
<p style="text-align: justify;">I&#8217;ve checked the code (&#8216;E&#8217;), as I could forget about something (&#8216;something&#8217; is a good word here &#8211; you usually cannot name things you forgot about) and then I&#8217;ve checked the enemies behavior in the game. It worked, character stood still after losing the player out of his sight. Maybe it is not the smartest AI behavior, but now it needs improvements, not fixes.</p>
<p style="text-align: justify;">There is one more tool I wanted to show you. A wonderful one. It&#8217;s called Call Stack and thanks to it, you can see how the game flow looked like until currently highlighted line. It will show you the list of method calls that led to this point.</p>
<p><img class="aligncenter size-full wp-image-366" src="http://gamesarchitecture.com/wp-content/uploads/2017/08/9.gif" alt="" width="946" height="676" /></p>
<p style="text-align: justify;">It is especially useful when you need to know WHY something happened. Why is this method being called?</p>
<p style="text-align: justify;">I&#8217;ve used different code because the above one only had two positions on the list. Also, the new Visual Studio seems to have an issue, so it shows Call Stack twice. Maybe someone should debug it?</p>
<p style="text-align: justify;"><em>There you have it! I hope you like it. I got a lot of amazing feedback recently. I wrote it down as bullet point list, and I read it during writing to improve the text. I appreciate it. Thanks to your suggestions I can do better and better. Join our community, that believes or feels that better coding is crucial for making great games. It is easier this way, once you prove it to yourself. So prove it. I&#8217;ll do my best to help you with that, but I need your voice. Follow Games Architecture however you like and let’s make some great games together.</em></p>
<h1>If you want more:</h1>
<ul>
<li style="text-align: justify;"><a href="https://www.codeproject.com/Articles/359801/plus-powerful-debugging-tricks-with-Visual-Studi" target="_blank" rel="noopener">10+ powerful debugging tricks with Visual Studio</a></li>
<li style="text-align: justify;"><a href="http://gameprogrammingpatterns.com/state.html" target="_blank" rel="noopener">Finite-State Machine</a></li>
</ul>
<div class="grammarly-disable-indicator"></div>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/easy-method-to-fix-bugs-in-your-game/">Easy method to fix bugs in your game &#8211; Debugging (Part II)</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamesarchitecture.com/easy-method-to-fix-bugs-in-your-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When to stop preparing design and get to work?</title>
		<link>http://gamesarchitecture.com/when-to-stop-preparing-design-and-get-to-work/</link>
		<comments>http://gamesarchitecture.com/when-to-stop-preparing-design-and-get-to-work/#comments</comments>
		<pubDate>Mon, 24 Jul 2017 19:07:50 +0000</pubDate>
		<dc:creator><![CDATA[Bartosz]]></dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Philosophy]]></category>

		<guid isPermaLink="false">http://gamesarchitecture.com/?p=337</guid>
		<description><![CDATA[<p>In indie game development, roles in a team aren&#8217;t as purely diverse as they are in bigger studios. In a crew composed of several people most of them are probably doing more than one thing. When you&#8217;re working alone, this is unavoidable. I noticed that the role that is the most often distributed over the &#8230; </p>
<p class="link-more"><a href="http://gamesarchitecture.com/when-to-stop-preparing-design-and-get-to-work/" class="more-link">Continue reading<span class="screen-reader-text"> "When to stop preparing design and get to work?"</span></a></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/when-to-stop-preparing-design-and-get-to-work/">When to stop preparing design and get to work?</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p><img src="http://gamesarchitecture.com/wp-content/uploads/2017/07/design_onion.png" alt="" width="924" height="520" class="aligncenter size-full wp-image-338" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/07/design_onion.png 924w, http://gamesarchitecture.com/wp-content/uploads/2017/07/design_onion-300x169.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/07/design_onion-768x432.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">In indie game development, roles in a team aren&#8217;t as purely diverse as they are in bigger studios. In a crew composed of several people most of them are probably doing more than one thing. When you&#8217;re working alone, this is unavoidable. I noticed that the role that is the most often distributed over the team members is designer. The general underestimation of that function may be the reason. The designer&#8217;s profile is often reduced to the &#8216;idea-guy.&#8217; Most of us have many excellent ideas, so what&#8217;s the point in having a designer, right? Whether your crew has a designer or not, you probably have some kind of design document or game vision that you and your partners share. Or you may think that everyone has the same image of the project, while the truth may be quite different. On the second hand, you all may be very insightful designers, that have an accurate design document, but it may be just a waste of your time and effort. The 90% of it may be just rubbish. Yes, that&#8217;s a bit harsh, but I&#8217;m not telling you that IT SURELY IS trash. I&#8217;ll just try to explain how can you find out without so much work being wasted.</p>
<p><span id="more-337"></span></p>
<p><strong>1. How can a lack of a design document be dangerous?</strong></p>
<p style="text-align: justify;">Let&#8217;s start with a more typical case. If you don&#8217;t have ANY design document and a whole vision is in your head, you can&#8217;t share it with the other people in a &#8216;healthy&#8217; way. You can try, but it seems almost impossible to remember all the details and keep track of them while you&#8217;re working on the game. Too many ideas pop out and mix during the development time. Your and your peer&#8217;s visions will go different ways at one point. It may cause wasting time when you need to explain it to them over and over. It may also lead to conflicts, as your team pursued different game than you did.</p>
<p style="text-align: justify;">In my opinion, having the document is important even if you&#8217;re a lone wolf. First, because if you make a change in the document, you can immediately read through the other dependent sections and think if the change makes sense for the other aspects of the game. The second reason is that it is much easier to write down tasks on Trello or Jira and prioritize them if you&#8217;ve got a well-constructed document. I&#8217;ll explain what I mean by &#8216;well-constructed document&#8217; in a moment.</p>
<p><strong>2. How can too much of a design be harmful?</strong></p>
<p style="text-align: justify;">Here I&#8217;m assuming that you&#8217;re NOT working on 1 to 1 clone of some other game because in this case all their mechanics are defined, and a symbiosis between them is already tested. When you&#8217;re working on a new (at least not-a-clone) idea, you can rarely be sure that all aspects of it fit each other before you actually play it. We&#8217;re living in an era of <a href="http://www.gamasutra.com/blogs/KatharineNeil/20161214/287515/How_we_design_games_now_and_why.php" target="_blank">unselfconscious design</a>, which means that we lack the tools that will allow us to prepare a whole design before development. For now, design and development go together till the end (well, to be accurate, the design usually starts a bit sooner). You probably already feel why too much design can harm you, but let’s say it out loud. Too much design is likely to be a waste of time and effort because non-fundamental decisions are based on a core that hasn&#8217;t been examined yet. If you&#8217;ll make a playable demo at some point and you see that your main mechanics are just not fun, you don&#8217;t want to have many hours spent on designing behind you.</p>
<p><img src="http://gamesarchitecture.com/wp-content/uploads/2017/07/design_comic.png" alt="" width="1418" height="731" class="aligncenter size-full wp-image-339" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/07/design_comic.png 1418w, http://gamesarchitecture.com/wp-content/uploads/2017/07/design_comic-300x155.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/07/design_comic-768x396.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/07/design_comic-1024x528.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">For every game concept the margin of &#8216;too much design&#8217; may be placed somewhere else. For example, if you&#8217;re making an &#8216;FPS with a jetpack&#8217; you can probably start to implement FPS mechanics right now as they are pretty the same for the whole genre and have been tested many times. In the meantime, you can prepare a design for the jetpack. How high it should fly (to the sky, buh-bye), what its velocity should be, and how strong inertia it should have? Does it need a fuel? You&#8217;ve got the point. And then you can think of a level design already because it strongly depends on the jetpack&#8217;s capabilities. After that, you can go to the enemies&#8217; project, because their behavior depends on the jetpack and level design. Go to the next layer of design, if the underlying one has been well thought out.</p>
<p><strong>3. Time for the answers!</strong></p>
<p style="text-align: justify;">I mentioned a well-constructed design document and layers of design. Let&#8217;s start with the second one. I believe that the design has layers, just like an onion. The most crucial and fundamental mechanics are placed in its center. The ideas that are directly based on them surround the onion&#8217;s core. The further we go, the less significant design decisions we make. The main menu layout or the font family cannot be totally dumped of course, but they are by far less important than your core mechanics. Maybe they&#8217;re the least important in the whole project? In that case, those are the onion&#8217;s shell.</p>
<p><img src="http://gamesarchitecture.com/wp-content/uploads/2017/07/design_onion.png" alt="" width="924" height="520" class="aligncenter size-full wp-image-338" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/07/design_onion.png 924w, http://gamesarchitecture.com/wp-content/uploads/2017/07/design_onion-300x169.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/07/design_onion-768x432.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;"><em>Note, that design layers depend entirely on a particular game. Sometimes even the Audio may be the core.</em></p>
<p style="text-align: justify;">And now, knowing that, let&#8217;s answer the question &#8216;What a well-constructed design document means?&#8217; For me, it means that the beginning of the paper is the onion&#8217;s center. It explains fundamentals of your game. Further, you can read about these fundamentals&#8217; details and later about mechanics that are based on these pillars. What do you get by constructing the document this way?</p>
<p style="text-align: justify;">First, the reader (teammate, publisher, future-you) has a much easier time trying to understand the vision because it goes from fundamentals to less relevant details that only support primary mechanics. The next thing (but not less important) is when you&#8217;re changing something on the very top of the design, you must go through all of the following sections and rethink them. You have just shaken the pillars, so you should check if the rest of the vision didn&#8217;t fall down. The further part of the design you&#8217;re tweaking the potentially less you have to check because the fewer decisions are based on that changed detail.</p>
<p style="text-align: justify;">And you&#8217;ll make changes to make your game entertaining. Even if you&#8217;ve got the most beautiful art style, if the whole game is just not fun, &#8220;the loser is you.&#8221;</p>
<p style="text-align: justify;">Knowing all of this, let&#8217;s answer the question in the title.</p>
<p style="text-align: justify;">&#8216;When to stop preparing design and get to work?&#8217; or on the other hand, &#8216;How much design do you need, before you can start?&#8217; If your core mechanics are based on a universal concept (input and movement in FPS, point &#8216;n&#8217; click, real-time strategy, etc.), preparing a design document is not necessary before starting implementation. Instead, you can do them in parallel. The first most important mechanics, that is not that common, require design. You can go layer by layer in design-develop-test iterations. And you can do as many iterations within one layer as you need, to make sure that the current layer is solid and fun. With each iteration, you can do more and more design before starting to implement (but you don&#8217;t have to, though, as coding is fun after all). Why? Because the closer to the outer shell of our onion-game you are, the weaker dependencies between mechanics become. The main menu and font are less dependant on each other than player&#8217;s movement and level&#8217;s structure. Plan and design every non-obvious idea before implementing and don&#8217;t go through design layers in one iteration.</p>
<p><strong>4. [DLC] 2 more tips to the design document</strong></p>
<p style="text-align: justify;">As an introduction sections to the paper you may consider two things:</p>
<ul>
<li style="text-align: justify;">First page(s) may be filled with your game&#8217;s inspirations. Try to explain how your game&#8217;s mechanics are similar to the existing and well-known titles. Try to put screenshots that show the similarities.
<p style="text-align: justify;"><strong>Example:</strong><br />
&#8216;I took a camera perspective from the Mass Effect: Andromeda [screenshot] (it&#8217;s a good game!) Instead of traditional weapons, there will be weapons like in the Worms series [screenshot]. Players will have to cooperate in fighting AI enemies and building fortifications, like in the Call of Duty: Zombies [screenshot]. The building aspect will be taken from the Minecraft [screenshot].&#8217; It&#8217;s just a few sentences, but you can immediately imagine a final and non-trivial product. Sure you can put more examples of a game to one mechanics there!</p>
</li>
<li style="text-align: justify;">After that you can prepare FAKE player&#8217;s and magazine&#8217;s reviews you wish to read and hear about your game. It will tell the reader what the essence of your game is, and what the design document should pursue.<br />
<strong>Examples:</strong><br />
&#8220;The story is incredible! Deep, real and heart-warming.&#8221;<br />
&#8220;This is the fastest racing game I ever played. Online matches are intense and spectacular!&#8221;<br />
&#8220;It&#8217;s like playing a mix of Assassin&#8217;s Creed and Thief. The freedom of the AC, sneaking&#8217;s tension of the Thief.”</li>
</ul>
<p style="text-align: justify;">That&#8217;s it. The article is based on nowadays&#8217; uncertainty of design, personal experiences and lessons learned from them. What do you think about it? Do you have your own workflow or pieces of advice you want to share? Write a comment!</p>
<p><strong>It may interest you as well:</strong></p>
<ul>
<li style="text-align: justify;"><a href="http://www.gamasutra.com/blogs/PhilippZupke/20170509/297644/The_Uncertainty_of_Design.php" target="_blank">The Uncertainty of Design</a></li>
<li style="text-align: justify;"><a href="http://www.gamasutra.com/blogs/KatharineNeil/20161214/287515/How_we_design_games_now_and_why.php" target="_blank">How we design games now and why</a></li>
<li style="text-align: justify;">As an example of the resistance movement against unselfconscious design: <a href="http://slides.com/piotrsobolewski85/what-happens-in-our-brains-when-we-play-games#" target="_blank">What happens in our brains when we play games?</a></li>
</ul>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/when-to-stop-preparing-design-and-get-to-work/">When to stop preparing design and get to work?</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamesarchitecture.com/when-to-stop-preparing-design-and-get-to-work/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Read it like a book &#8211; Centralized Control (Part I)</title>
		<link>http://gamesarchitecture.com/read-it-like-a-book-centralized-control-part-i/</link>
		<comments>http://gamesarchitecture.com/read-it-like-a-book-centralized-control-part-i/#comments</comments>
		<pubDate>Mon, 17 Jul 2017 17:37:32 +0000</pubDate>
		<dc:creator><![CDATA[Bartosz]]></dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://gamesarchitecture.com/?p=303</guid>
		<description><![CDATA[<p>Oh, it&#8217;s you, hi! I want to invite you to read the first post in a new series about Centralized Control. This one is an overview of the subject. You&#8217;ll get familiar with the centralized architecture, how it looks like, and what are the biggest benefits of sticking to it. You&#8217;re probably using it already, &#8230; </p>
<p class="link-more"><a href="http://gamesarchitecture.com/read-it-like-a-book-centralized-control-part-i/" class="more-link">Continue reading<span class="screen-reader-text"> "Read it like a book &#8211; Centralized Control (Part I)"</span></a></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/read-it-like-a-book-centralized-control-part-i/">Read it like a book &#8211; Centralized Control (Part I)</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-317" src="http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_cancer-1.png" alt="" width="691" height="335" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_cancer-1.png 691w, http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_cancer-1-300x145.png 300w" sizes="(max-width: 691px) 100vw, 691px" /></p>
<p style="text-align: justify;">Oh, it&#8217;s you, hi! I want to invite you to read the first post in a new series about Centralized Control. This one is an overview of the subject. You&#8217;ll get familiar with the centralized architecture, how it looks like, and what are the biggest benefits of sticking to it. You&#8217;re probably using it already, but the chances are it has got a few holes. When it has the holes, the benefits leak through them like a blood. Are you sure that you&#8217;re okay with that?</p>
<p><span id="more-303"></span></p>
<h1>&#8216;Read it like a book&#8217; series</h1>
<p>Part I &#8211; Centralized Control (this)<br />
<a href="http://gamesarchitecture.com/read-it-like-a-book-what-to-do-when-centralized-control-does-not-work-part-ii/" target="_blank" rel="noopener">Part II &#8211; What to do when Centralized Control does not work?</a><br />
<a href="http://gamesarchitecture.com/painless-way-of-programming-game-modes-and-skills-strategy-pattern/" target="_blank" rel="noopener">Part III &#8211; Painless way of programming Game Modes and Skills</a><br />
Part IV &#8211; Soon</p>
<h1>Content</h1>
<p>What is the Centralized Control?<br />
Project structure and communication between scripts<br />
Some benefits of the Centralized Control</p>
<h1>What is the Centralized Control?</h1>
<p style="text-align: justify;">Centralized control is a relation between classes, where one of them uses the others, the others use yet other ones, and that structure is never inverted. Centralized control doesn&#8217;t have to apply to the whole project, but it can be implemented only in a few modules. These particular modules&#8217; architecture is centralized then. This code structurization is so natural for an object-oriented programming that almost everyone, even unconsciously, tends toward it. But somewhere on the programming trip that centralization starts to shatter. We give the very specialized classes like Fireball a surprising amount of information. The Fireball starts to demand a data about the world from the higher-level classes. It can even force these classes to do things by calling methods on them. Directly! Ugh. The flow of the game code breaks. You start to walk a dark path deeper and deeper into the underworld inhabited by miserably deformed and unfinished games.</p>
<p><img class="aligncenter size-full wp-image-328" src="http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_unfinished_games2.png" alt="" width="1114" height="631" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_unfinished_games2.png 1114w, http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_unfinished_games2-300x170.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_unfinished_games2-768x435.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_unfinished_games2-1024x580.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">Do you really want that for your little baby you sick bastard? No, of course you don&#8217;t want that, my friend. Let&#8217;s see how the structure of the centralized control looks like.</p>
<h1>Project structure and communication between scripts</h1>
<p><img class="aligncenter size-full wp-image-323" src="http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_centralized_scheme.png" alt="" width="1191" height="544" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_centralized_scheme.png 1191w, http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_centralized_scheme-300x137.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_centralized_scheme-768x351.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_centralized_scheme-1024x468.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">Pretty straightforward, right? Now look at the part of your game&#8217;s codebase and try to draw its scheme. If none of the arrows go back to the upper class, you&#8217;re cool. If there are some places when it happens, watch out. These are the places you should rethink as they might be a source of a major problem in the future. Huge cancer can grow on these arrows.</p>
<p style="text-align: justify;">Broken centralized architecture can be compared to dealing with an official matter in the <em>Department of Spaghetti</em>. You start on the first floor, and you want to submit an application at the window 101. There you&#8217;re being informed that you need a certificate from the window 821 on the third floor to proceed. On the third floor, you hear that you need to go to the second one. On the second floor you are being directed to the fifth floor, then to the first one and suddenly you don&#8217;t know why are you here anymore and where it all ends. Guys from the <em>Department of Centralization</em> organized their work different way. You start on the floor one at window 101 (&#8220;Oh, that is scary&#8221;, you think). Then you&#8217;re being directed to the floor two, three, four, and five. When you&#8217;re on the fourth floor, you know you&#8217;re getting close to the end. When your case is finalized on the fifth floor, you notice an elevator with Ed Sheeran inside it. While you&#8217;re riding down, he plays his guitar and sings gently. An elevator is a place where you can take a deep breath and rethink a whole logical journey.</p>
<p><img class="aligncenter size-full wp-image-319" src="http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_ed_sheeran-1.png" alt="" width="695" height="294" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_ed_sheeran-1.png 695w, http://gamesarchitecture.com/wp-content/uploads/2017/07/centralized_control_ed_sheeran-1-300x127.png 300w" sizes="(max-width: 695px) 100vw, 695px" /></p>
<p style="text-align: justify;">Communication between scripts in the centralized architecture is as simple as its structure. High-level classes call methods on the low-level classes and might expect a return value. The low-level classes do their work, and when something interesting happens, they call an event (You remember events, right? <a href="http://gamesarchitecture.com/watch-out-youre-being-observed/" target="_blank" rel="noopener">The Observer pattern?</a>) High-level classes catch these events, and do the same things as they would do in regular methods. Coupling is one-sided.</p>
<h1>Some benefits of the Centralized Control</h1>
<ul>
<li style="text-align: justify;">The flow of the code is easier to understand.</li>
<li style="text-align: justify;">P. J. Plauger says about The Principle of One Right Place, that &#8220;There should be one right place to look for any non-trivial piece of code, and One Right Place to make a likely maintenance change.&#8221; It means that you&#8217;ll find the code you&#8217;re looking for faster, and you&#8217;ll make a change easier.</li>
<li style="text-align: justify;">Controllers’ and Managers’ classes have greater control over subordinate classes. This bullet is somehow related to the previous one. The fewer places where the low-level class is used, the less risk is taken by a high-level class that manages it.</li>
<li style="text-align: justify;">Believe me or not, but the classes&#8217; interfaces become simpler and clearer. That makes writing a code easier, not only reading it! Relax, I&#8217;ll explain it in the next post.</li>
</ul>
<p style="text-align: justify;">Speaking of the next post&#8230; In the next part of the series, we&#8217;ll look at a very different approach and how it may be useful. We&#8217;ll talk a bit about one of the most overused programming patterns in relation to the Centralized Control and code maintenance. You&#8217;ll get some tips about this architecture, its dangers and the solutions. Interested? And you&#8217;re aware, that you can subscribe &amp;&amp;/|| like a <a href="https://www.facebook.com/gamesarchitecture/" target="_blank" rel="noopener">Facebook page</a>, right? Great. So see you there!</p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/read-it-like-a-book-centralized-control-part-i/">Read it like a book &#8211; Centralized Control (Part I)</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamesarchitecture.com/read-it-like-a-book-centralized-control-part-i/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Debugging (Part I) &#8211; 7 good code practices that will help you in debugging</title>
		<link>http://gamesarchitecture.com/debugging-part-i-7-good-code-practices-that-will-help-you-in-debugging/</link>
		<comments>http://gamesarchitecture.com/debugging-part-i-7-good-code-practices-that-will-help-you-in-debugging/#respond</comments>
		<pubDate>Sun, 02 Jul 2017 14:35:37 +0000</pubDate>
		<dc:creator><![CDATA[Bartosz]]></dc:creator>
				<category><![CDATA[Generic]]></category>
		<category><![CDATA[Good Practices]]></category>

		<guid isPermaLink="false">http://gamesarchitecture.com/?p=249</guid>
		<description><![CDATA[<p>Hey guys! Welcome in the first post in a series about debugging process. This post will be treating about good practices which will help you in the debugging (and/or decrease amount of situations where you&#8217;ll need to do that). The second one will be about debugging process workflow, tools and how to use them in &#8230; </p>
<p class="link-more"><a href="http://gamesarchitecture.com/debugging-part-i-7-good-code-practices-that-will-help-you-in-debugging/" class="more-link">Continue reading<span class="screen-reader-text"> "Debugging (Part I) &#8211; 7 good code practices that will help you in debugging"</span></a></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/debugging-part-i-7-good-code-practices-that-will-help-you-in-debugging/">Debugging (Part I) &#8211; 7 good code practices that will help you in debugging</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-294" src="http://gamesarchitecture.com/wp-content/uploads/2017/07/2.png" alt="" width="1876" height="440" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/07/2.png 1876w, http://gamesarchitecture.com/wp-content/uploads/2017/07/2-300x70.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/07/2-768x180.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/07/2-1024x240.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">Hey guys! Welcome in the first post in a series about debugging process. This post will be treating about good practices which will help you in the debugging (and/or decrease amount of situations where you&#8217;ll need to do that). The second one will be about debugging process workflow, tools and how to use them in Visual Studio. I will focus on the most useful ones in my opinion. After these two posts, you should be equipped with a set of tools that, I think, are enough in most cases. This article collects code practices that are good in general, so even if you think you don&#8217;t need debugging (yet), you will make use of them. I decided to write this short series for two reasons. The good practices are good not because the big individuals said so. They are good for a reason. They make our development lives easier. I want to show you their usefulness during the debugging process because debugging is a reasoning about the code. It requires a lot of focus from us. This is a situation where code quality makes a huge difference. These practices make that reasoning easier. The second reason is that I see too many &#8216;easy&#8217; questions on the Stack Overflow, Quora, and Facebook groups. By &#8216;easy&#8217; I mean the problems that are fairly simple to solve during the debugging process. It seems like many of us just don&#8217;t debug at all. Maybe because they just don&#8217;t know how or it seems too hard or time-consuming. They prefer to delegate the problem to the Internet, what is usually more time consuming than debugging it by themselves. And the truth is, after fair amount of practice, you can find it <em>almost</em> easy and <em>almost</em> mechanical. No matter how good your code is, the bugs will happen sooner or later. You will have to get to the source of the problem. This is where the debugging begins and you better be prepared for that. Let&#8217;s get into it!</p>
<p><span id="more-249"></span></p>
<h1>&#8216;Debugging&#8217; series</h1>
<p>Part I &#8211; 7 good code practices that will help you in debugging (this)<br />
<a href="http://gamesarchitecture.com/easy-method-to-fix-bugs-in-your-game/" target="_blank" rel="noopener">Part II &#8211; What to do when Centralized Control does not work?</a></p>
<h1>Content</h1>
<p>1. One instruction per line<br />
2. Keep variables&#8217; span and live time the lowest possible<br />
3. Move complex logical operations to a separate variables/methods<br />
4. If you have getters/setters, don&#8217;t use variables directly<br />
5. Program offensively/defensively<br />
6. Keep nesting as shallow as possible<br />
7. Write comments</p>
<p>Let me start with the quite &#8216;obvious&#8217; advice, but a crucial one.</p>
<h1>1. One instruction per line</h1>
<p style="text-align: justify;">It may sound almost like a cliché, but let&#8217;s compare it to reading a recipe. Below you have two instruction sets.</p>
<ol>
<li>Boil at least 250ml of water, take a cup to which you&#8217;ll need to put a tea bag and when the water boils, pour it into the cup until it&#8217;s full.</li>
</ol>
<p>And&#8230;</p>
<ol>
<li>Boil at least 250ml of water,</li>
<li>Take a cup,</li>
<li>Put the tea bag inside the cup,</li>
<li>Wait for the water to boil,</li>
<li>Pour boiled water to the cup until it&#8217;s full.</li>
</ol>
<p style="text-align: justify;">While making a tea is fairly simple, imagine thai soup recipe (no cheating, you&#8217;re doing a curry paste!) written in one, enormous sentence. Besides easier reading, one instruction per line rule does one more thing. Assume that something went wrong and you can see line number of the error displayed in the console. You immediately know which instruction or method call is guilty before even launching a debugger. Write something like</p>
<pre class="brush: csharp; collapse: false; title: ; notranslate">
{
    // ...
    return ShowMatchSummaryWindow(GetWinner().Name, GetLoser().Name, Time.ToSeconds(GetMatchTime())).Owner == GetHost();
}
</pre>
<p style="text-align: justify;">and you are screwed. You have to launch the debugger first and go through every method call to see where the game blew up exactly. It wastes your time.<br />
Instead, you can write this:</p>
<pre class="brush: csharp; collapse: false; title: ; notranslate">
string winnerName = GetWinner().Name;
string loserName = GetLoser().Name;
int matchTimeInMilliseconds = GetMatchTime();
float matchTimeInSeconds = Time.ToSeconds(matchTimeInMilliseconds);
Player windowOwner = ShowMatchSummaryWindow(winnerName, loserName, matchTimeInSeconds);

bool windowOwnerIsHost = windowOwner == GetHost();
return windowOwnerIsHost;
</pre>
<p style="text-align: justify;">Yes, you can split it to even more lines, that&#8217;s okay. Do it until you know that there is only one thing that can go wrong on every line. Caching the value before returning it may be a good idea as well. Try to avoid things like <code>return MethodCall();</code></p>
<h1>2. Keep variables&#8217; span and live time the lowest possible</h1>
<p style="text-align: justify;">Steve McConnel describes two metrics about variables that you should be aware of in his book, <em>Code Complete</em>. The first one is a <em>live time</em> which says for how many code lines the variable exists. If it has been declared in line 100 and its last use is in line 150, the variable&#8217;s live time equals 51. The second metric is a <em>span</em>. It references to a number of lines between next usages of the variable. Declare a variable in line 10, use it in line 12 and the span will be 1. Then use it again in line 20 and an AVERAGE span will be equal to 4. Minimizing variable&#8217;s live time and average span reduces a chance that somewhere in between the variable will be changed incorrectly. Keeping in mind what the variable is and how it is changed for tens of lines of code is difficult. A couple of such variables and you no longer know what you are reading. Maintaining these metrics low allows you to focus on little pieces of the code and keeping all the variable usages on one screen (in case of local/auto variables).</p>
<p style="text-align: justify;">Here&#8217;s a quote about scope minimizing from the mentioned book:</p>
<blockquote><p>The difference between the &#8220;convenience&#8221; philosophy and the &#8220;intellectual manageability&#8221; philosophy boils down to a difference in emphasis between writing programs and reading them. The maximizing scope might indeed make programs easy to write, but a program in which any routine can use any variable at any time is harder to understand than a program that uses well-factored routines. In such a program, you can&#8217;t understand only one routine; you have to understand all the other routines with which that routine shares global data. Such programs are hard to read, hard to debug, and hard to modify.<br />
&#8211; Steve McConnel, Code Complete 2nd</p></blockquote>
<h1>3. Move complex logical operations to a separate variables/methods</h1>
<p style="text-align: justify;">Look at this:</p>
<pre class="brush: csharp; collapse: false; title: AttackPlayer() method:; notranslate">
public void AttackPlayer(Player player)
{
    if (GetDistanceTo(player) &lt;= rangeOfView &amp;&amp; player.HasCamouflageActive() &amp;&amp; !Physics.Raycast(this, player, rangeOfView))
    {
        // attack the player
    }
}</pre>
<p style="text-align: justify;">In a code like the above one, you have to read through the condition to see what is being checked. If you split it into separate variables and method, the code will look as follows:</p>
<pre class="brush: csharp; collapse: false; title: AttackPlayer() method (improved):; notranslate">
public void AttackPlayer(Player player)
{
    if (IsPlayerVisible(player))
    {
        // attack the player
    }
}

private bool IsPlayerVisible(Player player)
{
    bool isInRangeOfView = GetDistanceTo(player) &lt;= rangeOfView;
    bool hasCamouflageActive = player.HasCamouflageActive();
    bool isCoveredByObstacle = Physics.Raycast(this, player, rangeOfView);

    return isInRangeOfView &amp;&amp; !hasCamouflageActive &amp;&amp; !isCoveredByObstacle;
}</pre>
<p style="text-align: justify;">And we both know that the conditions can become way more complicated than this. By moving them to separate methods and/or naming each condition, you have a code that is easier to understand and fix.</p>
<h1>4. If you have getters/setters, don&#8217;t use variables directly</h1>
<p style="text-align: justify;">In C# they are called Properties, in C++ or any other language they might be just <code>GetVariable()</code> and <code>SetVariable()</code> methods. They are used to access the variable in a proper, cohesive way. Set it or get it and do something else in the middle. This &#8216;something else&#8217; part might be serializing the variable to string format in getter or calling the <code>StrengthChanged()</code> event in <code>SetStrength()</code> so the other parts of the game can react to that change.</p>
<p style="text-align: justify;">If the getters and setters are methods that do only getting and setting and nothing else, it may seem like in the class&#8217; body it doesn&#8217;t matter which one you use. But that is not true. If you need to add &#8216;something&#8217; to the accessors, your job should be done there. When you are using the variable directly, you have to take that change into account in every direct usage of the variable. And you can simply forget to do that.</p>
<p style="text-align: justify;">Secondly, if you&#8217;re looking for all references to the variable (Shift + F12 in VS), you can do this for accessor method only, not for accessor AND for the variable. You&#8217;ve got full list of usages, instead of two scraps of it.</p>
<p style="text-align: justify;">Sometimes you might think that it is better (or even that it is the only way) to use the variable directly, but stop yourself there and take a moment to rethink it. <strong>Very often it is a signal that the accessor method does too much.</strong> Every operation in the getter/setter should be an operation that can be called no matter how the world outside the class looks like or what is the current state of the class. It is a bit of generalization, but just consider it when you feel tempted to use a variable directly while having an accessor for it already. Try to move some of the operations that &#8216;shouldn&#8217;t be there&#8217; out of the accessor and to a separate method. Then, after every accessor usage, you can call this new method if you need it.</p>
<h1>5. Program offensively/defensively</h1>
<p>Your game will be evolving very often during the design&#8217;n&#8217;development process. That&#8217;s the good thing. Preconditions for methods will stop to be fulfilled, you&#8217;ll have null pointer references, types of the variables will change and mismatches will appear. And that&#8217;s a natural order of things. Don&#8217;t be afraid of bugs during the development time. They are very valuable pieces of information about what went wrong. The worst thing you can do is to hide them or try to secure every possible case by writing a lot of additional code. This is a very important subject and I am gonna write a whole post about it, but for now, take this with you</p>
<pre class="brush: csharp; collapse: false; title: Don&#039;t:; notranslate">
    public void RemoveCondition(ConditionType conditionType)
    {
        if (!_initialized) Initialize();

        _conditionsManager.RemoveCondition(conditionType);
    }
</pre>
<p style="text-align: justify;">You&#8217;re admitting here that you didn&#8217;t consider very well when the class can be used and when it shouldn&#8217;t be. When it is not initialized, you made a mistake in the code. Don&#8217;t try to &#8216;patch&#8217; it here and there. Maybe you forgot about the class that initializes this one? The object that initializes it hasn&#8217;t been loaded during the level load? Fix it, don&#8217;t patch or mask it.</p>
<pre class="brush: csharp; collapse: false; title: OMG, OMG, please DON&#039;T:; notranslate">
    public void RemoveCondition(ConditionType conditionType)
    {
        if (!_initialized) return;

        _conditionsManager.RemoveCondition(conditionType);
    }
</pre>
<p style="text-align: justify;">This is so bad and so frequent. Man, you&#8217;ve just called the method and you think that the condition has been removed. Your game is running. And weird things happen. Something went wrong. You don&#8217;t know what. You don&#8217;t know where or when you&#8217;ll see the results. You cannot even be sure that the results on the screen will be related to the original issue at first glance.</p>
<p><img class="aligncenter size-full wp-image-299" src="http://gamesarchitecture.com/wp-content/uploads/2017/07/Zrzut-ekranu-2017-07-02-o-16.25.06.png" alt="" width="1924" height="390" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/07/Zrzut-ekranu-2017-07-02-o-16.25.06.png 1924w, http://gamesarchitecture.com/wp-content/uploads/2017/07/Zrzut-ekranu-2017-07-02-o-16.25.06-300x61.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/07/Zrzut-ekranu-2017-07-02-o-16.25.06-768x156.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/07/Zrzut-ekranu-2017-07-02-o-16.25.06-1024x208.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<pre class="brush: csharp; collapse: false; title: Do:; notranslate">
    public void RemoveCondition(ConditionType conditionType)
    {
        if (!_initialized) Debug.LogError(&quot;Conditions Behaviour is not initialized, so the conditions won't be applied. Initialize it first.&quot;);

        _conditionsManager.RemoveCondition(conditionType);
    }
</pre>
<p style="text-align: justify;">Boom! &#8216;Boy, you cannot use me, you forgot about the initialization!&#8217;. Your game is your spaceship. If something is wrong with it, you want to know what it is, so it can be fixed before the launch. You can ignore any checking and let things to be handled by the compiler, but I think it is not quite a good idea either. First, you cannot be sure if the compiler&#8217;s error will be displayed immediately or if the issue will be propagated for a few more methods before doing that. Secondly, you give up on your own, human, messages, written to your future self.</p>
<p style="text-align: justify;">Don&#8217;t secure your game against every possible issue. That&#8217;s a lot of code that is just rubbish. Inform that there is an issue and expect that this particular case will be fixed. You don&#8217;t have to check if an index is within a range right before accessing an array. The compiler will do this for you. But on the other hand, if your compiler&#8217;s message, in this case, is a mess or you want to add additional information to the message &#8211; feel free to do that. Cooperate with the complier. As I said, I will talk about it later.</p>
<p style="text-align: justify;">You can read more about defensive programming <a href="https://en.wikipedia.org/wiki/Defensive_programming" target="_blank" rel="noopener">here</a> and offensive one <a href="https://en.wikipedia.org/wiki/Offensive_programming" target="_blank" rel="noopener">here</a>.<br />
If you found some great articles on these topics, feel free to share them with us in the comments.</p>
<h1>6. Keep nesting as shallow as possible</h1>
<p style="text-align: justify;">There&#8217;s an if in another if, in a for loop in one of the switch cases&#8230; No. Try to keep number of nests below 4.</p>
<p><img class="aligncenter size-full wp-image-293" src="http://gamesarchitecture.com/wp-content/uploads/2017/07/1.png" alt="" width="1984" height="864" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/07/1.png 1984w, http://gamesarchitecture.com/wp-content/uploads/2017/07/1-300x131.png 300w, http://gamesarchitecture.com/wp-content/uploads/2017/07/1-768x334.png 768w, http://gamesarchitecture.com/wp-content/uploads/2017/07/1-1024x446.png 1024w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<h1>7. Write comments</h1>
<p style="text-align: justify;">Yeah, some people say &#8216;Don&#8217;t write comments, write a code that comments itself&#8217;. Other ones say &#8216;Write a lot of comments&#8217;. Or something like that. But you can be a more balanced. Write comments if you decided to write something &#8216;this way&#8217;, even if it may not be the most obvious way of all. Explain in the comment WHY you&#8217;ve written it like that. &#8216;Because here I don&#8217;t have a reference to that and this method is called before that one, and I didn&#8217;t want to&#8230;&#8217;. Yes, you&#8217;re describing &#8216;why&#8217; you did it, not &#8216;what&#8217; it does. Maybe consider writing comments for more complicated blocks of code. Even if your code is really good, treat it as a possibility to check yourself after reading. Low-level code usually requires more comments than the high-level one.</p>
<p style="text-align: justify;">I think this is a good place to say it loud and clear. It is impossible to write and describe every case where the rule is applicable. To point out every &#8216;unless&#8217; with an exception. It often HAS TO be a little simplified to make the text done and readable by a human being with a job and/or life. But that&#8217;s a good thing. The major goal of mine is to help you to be aware of the rules, good practices and what they are for. The main advice is to THINK what are the solutions for the problem, which one seems the best (and the simplest) NOW (for the current problem). Be AWARE of the good practices and rules, so you can write the code consciously. But the good part of it is, that very often you don&#8217;t have to find the perfect solution. Usually, your decisions are trade-offs anyway. But make them consciously and it will be okay. Calm down. Think. Go for it. And see you soon.</p>
<div class="grammarly-disable-indicator"></div>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/debugging-part-i-7-good-code-practices-that-will-help-you-in-debugging/">Debugging (Part I) &#8211; 7 good code practices that will help you in debugging</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamesarchitecture.com/debugging-part-i-7-good-code-practices-that-will-help-you-in-debugging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cohesive abstraction &#8211; solving most of your dilemmas in an easy way</title>
		<link>http://gamesarchitecture.com/cohesive-abstraction-solving-most-of-your-dilemmas-in-an-easy-way/</link>
		<comments>http://gamesarchitecture.com/cohesive-abstraction-solving-most-of-your-dilemmas-in-an-easy-way/#comments</comments>
		<pubDate>Tue, 13 Jun 2017 16:57:34 +0000</pubDate>
		<dc:creator><![CDATA[Bartosz]]></dc:creator>
				<category><![CDATA[Philosophy]]></category>

		<guid isPermaLink="false">http://gamesarchitecture.com/?p=229</guid>
		<description><![CDATA[<p>Many of the code problems come from airiness during writing. We add features to the game not exactly in the best place with the thought that we&#8217;ll improve it later (yeah, sure&#8230;). And after a while, we don&#8217;t know which class does what. Maybe some classes do a bit of everything. We don&#8217;t know where &#8230; </p>
<p class="link-more"><a href="http://gamesarchitecture.com/cohesive-abstraction-solving-most-of-your-dilemmas-in-an-easy-way/" class="more-link">Continue reading<span class="screen-reader-text"> "Cohesive abstraction &#8211; solving most of your dilemmas in an easy way"</span></a></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/cohesive-abstraction-solving-most-of-your-dilemmas-in-an-easy-way/">Cohesive abstraction &#8211; solving most of your dilemmas in an easy way</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-242" src="http://gamesarchitecture.com/wp-content/uploads/2017/06/003_cohesive_abstraction_unicorn.jpg" alt="" width="779" height="186" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/06/003_cohesive_abstraction_unicorn.jpg 779w, http://gamesarchitecture.com/wp-content/uploads/2017/06/003_cohesive_abstraction_unicorn-300x72.jpg 300w, http://gamesarchitecture.com/wp-content/uploads/2017/06/003_cohesive_abstraction_unicorn-768x183.jpg 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">Many of the code problems come from airiness during writing. We add features to the game not exactly in the best place with the thought that we&#8217;ll improve it later (yeah, sure&#8230;). And after a while, we don&#8217;t know which class does what. Maybe some classes do a bit of everything. We don&#8217;t know where to add another feature, so we pick a random class that already has the most of the needed references. Classes become just files with loosely connected methods and fields. Soon enough you&#8217;ll find yourself in a place, where you&#8217;ll have to change the current functionality. And that&#8217;s when everything fucks up. If this scenario sounds somehow familiar, read on.<span id="more-229"></span></p>
<p style="text-align: justify;"><strong>Abstraction and the unicorn</strong><br />
ADT (abstract data type) is a set of data and methods that operate on it and that represents a single entity. Nowadays, in object oriented programming, an ADT and a class may be considered equivalent concepts. More or less. An ADT is something that you can find a &#8216;real&#8217; object. A player, an enemy soldier, a unicorn mount &#8211; these are ADTs. However, sometimes you can see a class that is called a <code>Unicorn</code>, but it also has got public methods like <code>ReadUnicornPositionFromServer()</code> or public fields like <code>Color[] unicornColors</code>. How often do you see a unicorn that connects to the server or manages arrays? Exactly. That is, because the unicorn simply doesn&#8217;t do that, or it is very efficient in hiding its secrets. You should get rid of these unicorn inadequate behaviors or change the class&#8217; name to <code>ServerUnicornArrayManager</code>. Despite the ugliness of that name, it also implies that the class may be doing too much.</p>
<p><img class="aligncenter size-full wp-image-240" src="http://gamesarchitecture.com/wp-content/uploads/2017/06/003_cohesive_abstraction_merged.jpg" alt="" width="790" height="189" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/06/003_cohesive_abstraction_merged.jpg 790w, http://gamesarchitecture.com/wp-content/uploads/2017/06/003_cohesive_abstraction_merged-300x72.jpg 300w, http://gamesarchitecture.com/wp-content/uploads/2017/06/003_cohesive_abstraction_merged-768x184.jpg 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">Okay, but why should you bother about this that much? Writing classes is simple, right? Right. But writing coherent classes, that are ADTs and that help you solving dilemmas mentioned in the title is not given for every class once and for eternity. It requires discipline and attention during implementation and making changes. Why do you write classes? The main reason is to use a class in other parts of the game without thinking what happens inside. You implement ADT using classes to operate on a higher level. To use a unicorn as a unicorn, not pile of bones, skin, horn etc. But on long terms, it works that way only if the class is coherent and hides its implementation details.</p>
<p style="text-align: justify;"><strong>Cohesion</strong><br />
The class is coherent if its data (fields) describes one and only one real entity, its procedures (methods) manage this data and the interface (public methods and data) allows you to do everything that you should be able to do and nothing more. Like the mentioned unicorn. It may be able to connect to the server, but when you&#8217;re flying on it (or using interface of the Unicorn class), you cannot see that. You can feed the unicorn, but you cannot see its digestive processes because it doesn&#8217;t help you play with it and it&#8217;s probably disgusting or hard to understand. And that is exactly like a good class should look like. It should allow you to do every freaking cool stuff it is designed to do, but protect you from the stuff you don&#8217;t want to know and you definitely shouldn&#8217;t interfere with. So…</p>
<p><em>ADT is a single entity presented as data and methods that operate on it.</em></p>
<p style="text-align: justify;"><em>Class is an ADT when it is coherent and hides everything that should be hidden.</em></p>
<p style="text-align: justify;"><em>Hiding (behind the private element and an abstraction) is called hermetization. It protects the class from incorrect use and the class&#8217; user from details a headache.</em></p>
<p style="text-align: justify;"><em>Abstraction and hermetization are really good friends. It is impossible to have good abstraction when all the implementation details are known outside the class.</em></p>
<p style="text-align: justify;"><strong>Be a hamster &#8211; hide everything you can</strong><br />
You don&#8217;t use <code>player.health</code> directly to heal or hurt the player. If something will change in the future, for example, you&#8217;ll add a temporary immortality, you&#8217;ll have to find and change all of the field&#8217;s uses to take that into account. You provide an interface to manage the player&#8217;s health. If you add the immortality, you&#8217;ll have to consider it only in the player&#8217;s class, not in the entire game. Changes are less invasive. And when you&#8217;re using the class, you don&#8217;t have to think about details, you operate on a higher level.</p>
<p style="text-align: justify;"><strong>Keep an abstraction consistent</strong><br />
Good interface should also be restricted to only one level of abstraction. That means when you&#8217;re using <code>cat.TakeDamage()</code>, you shouldn&#8217;t be able to use <code>cat.livesNumber -= 1</code>. It is just a ticking bomb and makes the reasoning about the class a lot harder.</p>
<p style="text-align: justify;"><strong>Difficult problem, simple solution</strong><br />
When you already know all of this, let&#8217;s present that easy solution. It is just a simple question that should be asked before making EVERY change to the class. <em>&#8216;SHOULD it be here?&#8217;</em> Yeah, that&#8217;s it. Don&#8217;t tell me you feel disappointed! This question triggers special mechanism in your brain, that is being forced to figure out if the new change will keep abstraction coherent and the hermetization on the proper level.</p>
<ul>
<li style="text-align: justify;">Should the <code>health</code> be a public field? Am I sure that class&#8217; users (clients) can ensure that the <code>health</code>, at any point, is over 0 and below or equal to its maximum level? What will I have to do if I change the <code>health</code> from being a float to being an integer?</li>
<li style="text-align: justify;">Should a <code>GetPlayerID()</code> method be in a tank&#8217;s interface? Should the tank know about the player? Is the tank the one that uses a player, or is the player the one that uses the tank?</li>
<li style="text-align: justify;">Should a <code>GunsMenu</code> have a <code>DeleteKey()</code> public method? Will the clients know for sure what the key is? Is the key on a proper abstraction level? Maybe the <code>GunsMenu</code> should operate on a <code>GunEntry</code> instead of the mysterious key? Maybe the <code>GunEntries</code> collection should be private for the <code>GunsMenu</code>?</li>
</ul>
<p style="text-align: justify;"><strong>HanSoloChewbacca.cpp</strong><br />
If you are not able to say what abstraction the class represents, or having its name you can see methods and data that &#8216;shouldn&#8217;t be there&#8217;, it is probably a good idea to split that class into two or more separate abstractions.</p>
<p><img class="aligncenter size-full wp-image-241" src="http://gamesarchitecture.com/wp-content/uploads/2017/06/003_cohesive_abstraction_sliced.jpg" alt="" width="776" height="170" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/06/003_cohesive_abstraction_sliced.jpg 776w, http://gamesarchitecture.com/wp-content/uploads/2017/06/003_cohesive_abstraction_sliced-300x66.jpg 300w, http://gamesarchitecture.com/wp-content/uploads/2017/06/003_cohesive_abstraction_sliced-768x168.jpg 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">On the other hand, sometimes you&#8217;ll find two classes that very often send the data between each other. Maybe both of them have a reference to each other. Or when you need to add another functionality and you are not sure to which class of these two you should add it, because it seems to fit them both. These may be good premises to combine those classes into one, as they may be two halves of the same apple.</p>
<p style="text-align: justify;"><strong>Speaking of objects…</strong><br />
Object-oriented programming is wonderful paradigm with many rules and guidelines. It already has proven its value for the game programming. But by creating objects that are weird inconsistent masses instead of real coherent objects we reject all of these rules. The class is one of the most basic units we use. If you undermine this foundation it will be impossible to construct something magnificent or even stable. Ignore the problem of incoherent abstraction and keep building on that and at one floor the building will fall. Or it will stay under construction forever.</p>
<p><strong>More information on the topic:</strong><br />
<em>Code Complete 2nd</em> by Steve McConnell, Chapter 6 “Working Classes”.<br />
I strongly recommend the whole book (not only me, look on the Internet). It was a big revelation for me.</p>
<p style="text-align: justify;"><em>There you go! At the beginning, I&#8217;m trying to create &#8216;vertical slice&#8217; of the blog. That is, I want to show you the real samples instead of only promises of the content. Thank you for coming by, I hope you found this article valuable. Tell me what you think, I need your feedback. It will also give me the motivation to keep going. I&#8217;m looking forward to hearing from you in the comments. And see you in the next post!</em></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/cohesive-abstraction-solving-most-of-your-dilemmas-in-an-easy-way/">Cohesive abstraction &#8211; solving most of your dilemmas in an easy way</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamesarchitecture.com/cohesive-abstraction-solving-most-of-your-dilemmas-in-an-easy-way/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Watch out, you&#8217;re being observed!</title>
		<link>http://gamesarchitecture.com/watch-out-youre-being-observed/</link>
		<comments>http://gamesarchitecture.com/watch-out-youre-being-observed/#comments</comments>
		<pubDate>Mon, 29 May 2017 17:44:30 +0000</pubDate>
		<dc:creator><![CDATA[Bartosz]]></dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://gamesarchitecture.com/?p=172</guid>
		<description><![CDATA[<p>Hi! Welcome in the essentially first post on Games Architecture. I’m really glad you’re here and just in a minute I’ll let you dive into the substance, but first you need to know something about me. I’ve mentioned it in the very first post, but I think it is quite important to point it out &#8230; </p>
<p class="link-more"><a href="http://gamesarchitecture.com/watch-out-youre-being-observed/" class="more-link">Continue reading<span class="screen-reader-text"> "Watch out, you&#8217;re being observed!"</span></a></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/watch-out-youre-being-observed/">Watch out, you&#8217;re being observed!</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p><img src="http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_tatarataaa.jpg" alt="" width="948" height="327" class="aligncenter size-full wp-image-183" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_tatarataaa.jpg 948w, http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_tatarataaa-300x103.jpg 300w, http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_tatarataaa-768x265.jpg 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">Hi! Welcome in the essentially first post on Games Architecture. I’m really glad you’re here and just in a minute I’ll let you dive into the substance, but first you need to know something about me. I’ve mentioned it in the very first post, but I think it is quite important to point it out once again. I try to simplify things wherever I can and the code is first-class example. Programming is more about reading the code than writing it. You really want to make the first one as easy as you can, for future-you and the fellas that will be helping you.</p>
<p style="text-align: justify;">There are a couple of places where you can find some information about this design pattern (and I’ll point you there at the right time) but we will focus on examples and some tangible aspects of it. Ok, so here’s the problem:</p>
<p style="text-align: justify;">Let’s assume we have a monster and a player. Pretty common setting in games, isn’t it? The monster attacks the player, so programming it can be as simple as calling <code>player.TakeDamage()</code>. But (you expected the &#8216;but&#8217; didn&#8217;t you?) the games are rather multimedia experiences, so you’ll probably want to have some audio (<em>ouch!</em>) and maybe a screen effect, on instance red <em>Call of Duty</em> style indicator. Oh, oh, and somewhere on the screen the HP bar is placed. Let&#8217;s write this:</p>
<p><span id="more-172"></span></p>
<pre class="brush: csharp; collapse: true; light: false; title: Enemy (click to unfold); toolbar: true; notranslate">public class Enemy : Actor
{
    private Player _player;

    private int _attackDamage = 10;

    private void Update()
    {
        _player.TakeDamage(_attackDamage);
    }
}</pre>
<pre class="brush: csharp; collapse: true; light: false; title: Player (click to unfold); toolbar: true; notranslate">public class Player : Actor
{
    private AudioController _audioController;
    private Camera _effectsCamera;
    private UIController _uiController;

    private int _healthPoints = 100;

    public void TakeDamage(int damageValue)
    {
        _healthPoints -= damageValue;

        _audioController.PlayHitSound();
        _effectsCamera.ShowHitIndicator(seconds: 1);
        _uiController.UpdateHealthBar(newValue: _healthPoints);

        // Deal with players death...
    }
}</pre>
<p>So the diagram looks like this:<br />
<img class="aligncenter size-full wp-image-180" src="http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_before.jpg" alt="" width="954" height="266" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_before.jpg 954w, http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_before-300x84.jpg 300w, http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_before-768x214.jpg 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">It’s quite possible that you feel that this is somehow wrong. Besides fighting with monsters and caring about our input, the hero has to manage all of the things he shouldn’t know about. To keep abstraction cohesive, player should care about input and his behavior, monster about attacking, audio about playing… you get the idea. But how to call all of these methods without actually calling them from player class? The answer is – don’t call them. Just let the player shout about the fact that it hurts so badly and hope for the best. Or you can make sure that someone is hearing by programming it. The one who hears the player&#8217;s pain is our today&#8217;s star – The Observer:</p>
<p><img class="aligncenter size-full wp-image-183" src="http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_tatarataaa.jpg" alt="" width="948" height="327" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_tatarataaa.jpg 948w, http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_tatarataaa-300x103.jpg 300w, http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_tatarataaa-768x265.jpg 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">But the Observer is not a separate class, it&#8217;s more like an additional ability or a role of the existing class. He (the Observer) can listen to the others (classes of interest – subjects) and based on that, rule his realm (call appropriate methods). Instead of the above scenario, when subjects come to the Observer and make him do things (<em>&#8220;Hey ruler, play that track for me, mkay?&#8221;</em>), they just do their job and when something interesting happens, like they get hit by an arrow in the knee, they just shout about it. And they don’t know who and how many of them are listening in the moment. It can be a Bard (Audio) Observer that plays a sad song about the fallen hero, or it can be a Painter (UI) Observer, that updates his paintings that portray hero&#8217;s condition. Or it can be both of them. Or none. Nothing changes for the hero. Snap back to the reality (Oh, there goes gravity) and write some code.</p>
<pre class="brush: csharp; collapse: true; light: false; title: Player (click to unfold); toolbar: true; notranslate">public class Player : Actor
{
    /// &lt;summary&gt;
    /// Sends players object that just have died.
    /// &lt;/summary&gt;
    public Action&lt;Player&gt; Dead = delegate { }; // Don't be afraid of that syntax, its use is pretty simple.

    /// &lt;summary&gt;
    /// Sends players object that has been hit and new health value.
    /// &lt;/summary&gt;
    public Action&lt;Player, int&gt; Hit = delegate { };

    private int _healthPoints = 100;
    
    public void TakeDamage(int damageValue)
    {
        _healthPoints -= damageValue;

        Hit(this, _healthPoints); // Shout about being hit.

        if (_healthPoints &lt;= 0)
        {
            //Send another event, about players death and let the Gameplay Controller decide what to do with the body.
            Dead(this);
        }
    }
}</pre>
<pre class="brush: csharp; collapse: true; light: false; title: AudioController (click to unfold); toolbar: true; notranslate">public class AudioController
{
    private Player _player;

    private void Start()
    {
        // Start listening.
        _player.Dead += OnPlayerDead;
        _player.Hit += OnPlayerHit;
    }

    private void OnPlayerDead(Player player)
    {
        // Stop listening.
        _player.Dead -= OnPlayerDead;
        _player.Hit -= OnPlayerHit;
    }

    private void OnPlayerHit(Player player, int newHealthValue)
    {
        PlayHitSound();
    }

    private void PlayHitSound()
    {
        // Ouch!
    }
}</pre>
<p>We&#8217;ll skip the <code>Camera</code> and <code>UIController</code> scripts, they are analogous to the above.</p>
<p style="text-align: justify;"><strong>NOTE I:</strong> I&#8217;ve introduced one more event, <code>Dead</code>, to show unsubscribing and some danger related to using events. I&#8217;ll make use of it later.</p>
<p style="text-align: justify;"><strong>NOTE II:</strong> In the above example I’m sending player&#8217;s object. I didn’t have to do that, as every controller knows the player, but if we had a multiplayer game, we would want to know which player has been hit.</p>
<p>So now the diagram looks like that:<br />
<img class="aligncenter size-full wp-image-184" src="http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_after_a.jpg" alt="" width="950" height="266" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_after_a.jpg 950w, http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_after_a-300x84.jpg 300w, http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_after_a-768x215.jpg 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;"><strong>NOTE III:</strong> I dropped drawing arrows from the controllers to the player and replaced them with little antennas to keep diagrams more readable, but remember that now they are linked to the player.</p>
<p>Or, we can go for more centralized control:</p>
<pre class="brush: csharp; collapse: true; light: false; title: GameplayController (click to unfold); toolbar: true; notranslate">public class GameplayController
{
    private AudioController _audioController;
    private Camera _effectsCamera;
    private Player _player;
    private UIController _uiController;
    
    private void Start()
    {
        // Start listening.
        _player.Dead += OnPlayerDead;
        _player.Hit += OnPlayerHit;
    }

    private void OnPlayerDead(Player player)
    {
        // Stop listening.
        _player.Dead -= OnPlayerDead;
        _player.Hit -= OnPlayerHit;

        // Restart level.
    }

    private void OnPlayerHit(Player player, int newHealthValue)
    {
        _audioController.PlayHitSound();
        _effectsCamera.ShowHitIndicator(seconds: 1);
        _uiController.UpdateHealthBar(newHealthValue);
    }
}</pre>
<p>And the diagram:<br />
<img class="aligncenter size-full wp-image-187" src="http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_after_b.jpg" alt="" width="954" height="297" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_after_b.jpg 954w, http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_after_b-300x93.jpg 300w, http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_after_b-768x239.jpg 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;">The first one is simpler but less reusable as the controllers are more rigidly connected to player&#8217;s events. The second one allows for controllers reuse, as the Gameplay Controllers uses their API. Gameplay Controller in that case will be linked to everything, which is a bit harder to manage, but has an advantage in some cases. For example, if your game has a few game modes, changing game behavior is as simple as writing a new Gameplay Controller and switching between them accordingly. In that case making them derive from a common class will possibly be a good idea.</p>
<p style="text-align: justify;">Okay, let’s point out the biggest advantages of using this pattern and then we will move to the another example. Events (this is what the Observer listens) wonderfully decouple classes, so one of them doesn’t have to be aware of the second&#8217;s existence. And what do we get thanks to that?</p>
<ul>
<li>Adding another behaviors or changing existing ones doesn’t entail a change of all the other classes that are involved. Less opportunities to make a mistake.</li>
</ul>
<ul>
<li>It is easier to wrap your mind around programmed features, because you have to focus only on one class at the time. UI, Audio and Image effects can wait until you&#8217;re done with the most important code &#8211; players behavior.</li>
</ul>
<ul>
<li>Changing the Audio System completely, its API, adding and removing image effects (so classes <em>from above</em>*) doesn’t force you to change the player (class <em>from below</em>*). The new Audio System just listens to an appropriate event (but it doesn’t have to, if we don’t want to play that sound anymore) and does whatever it does. Player doesn’t know about it and doesn’t even care. The only thing that can change is adding a new event. And it can be used by every other class, without linking the player to anything.</li>
</ul>
<p style="text-align: justify;">* Not-so-formal definition of what I mean by classes <em>from above</em> and <em>from below</em> sounds as follow: Class <em>from above</em> knows more about game&#8217;s realm <strong>comparing to</strong> class <em>from below</em>. For example, player is class from above for projectile class. The second one may know about itself and about physics engine, while the first one knows about itself and that projectile. It doesn&#8217;t mean that class <em>from above</em> has to have reference to the class <em>from below</em>. It is just an <em>ability to know</em>.</p>
<p>Let&#8217;s jump to the another example.</p>
<p style="text-align: justify;">Imagine a level divided into a hex fields and two armies confronting each other on it. There are a couple of obstacles on some fields. Some of the hexes are placed on the hill, what gives the accuracy boost to the unit that stands there. When the soldier misses his shot, the opposite one has a chance to lead a counterattack. OK, let’s stop here. If you played something like <em>Heroes</em> or <em>Neuroshima Hex</em>, you are probably aware, how complex these systems can be. You can exercise a little and before you start looking closer on the code and the diagram below, you can try to solve this on your own. Oh, hey, you can even share it with me in the comments if you like! When you are ready, there is one of the solutions**:</p>
<p><img class="aligncenter size-full wp-image-196" src="http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_example-1.jpg" alt="" width="950" height="300" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_example-1.jpg 950w, http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_example-1-300x95.jpg 300w, http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_diagram_example-1-768x243.jpg 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><br />
The diagram is quite simple, right? I think that we need some code snippets:</p>
<pre class="brush: csharp; collapse: true; light: false; title: Unit (click to unfold); toolbar: true; notranslate">public class Unit
{
    public Action&lt;Unit&gt; AnimationDodgeEnd = delegate { };
    public Action&lt;Unit&gt; Dead = delegate { };
    public Action&lt;Unit, int&gt; Hit = delegate { };

    private int _accuracy = 50;
    private int _damage = 50;
    private int _range = 3;
    private Player _owner;
    private Vector2 _currentPosition;

    public Unit(Player owner, int accuracy, int damage, int range) { /* Initialize private fields. */ }

    // Getters for private fields.

    public void Move(Vector2 newPosition) { /* Move the unit to the new position. */ }

    public void TakeDamage(int damageValue) { /* Pretty same as in player class. */ }

    public void PlayAnimationAttack() { /* ... */ }

    public void PlayAnimationDodge() { /* ... */ }

    public void PlayAnimationHit() { /* ... */ }
}</pre>
<pre class="brush: csharp; collapse: true; light: false; title: EnvironmentController (click to unfold); toolbar: true; notranslate">public class EnvironmentController
{
    public int GetFieldAccuracyBonus(Vector2 fieldPosition) { /* Check field bonus and return it. */ }
    
    public bool IsFieldAvailable(Vector2 fieldPosition) { /* Check field availability and return it. */ }

    public bool IsFieldInRange(Vector2 centerField, int range) { /* ... */ }
    
    public void HighlightFieldsAround(Vector2 centerField, int range) { /* Highlight available fields on green and unavailable on red. */ }
}</pre>
<pre class="brush: csharp; collapse: true; light: false; title: FieldInputController (click to unfold); toolbar: true; notranslate">public class FieldInputController
{
    public Action&lt;Vector2&gt; FieldClicked = delegate { };
    public Action&lt;Unit&gt; UnitClicked = delegate { };
}</pre>
<pre class="brush: csharp; collapse: true; light: false; title: BattleController (click to unfold); toolbar: true; notranslate">public class BattleController
{
    private EnvironmentController _environmentController;
    private FieldInputController _fieldInputController;
    private Player _currentPlayer;
    private Unit _activeUnit;

    private void StartBattle()
    {
        _fieldInputController.FieldClicked += OnFieldClicked;
        _fieldInputController.UnitClicked += OnUnitClicked;
    }

    private bool IsAttackHit(Unit attackerUnit, int additionalAccuracy) { /* ... */ }

    private void OnFieldClicked(Vector2 fieldPosition)
    {
        // If player clicked on field, move the player there if it is available for him.
    }

    private void OnUnitClicked(Unit clickedUnit)
    {
        // If player clicked on his unit, make it active and highlight available fields around it.
        Player unitOwner = clickedUnit.GetOwner();
        if (unitOwner == _currentPlayer)
        {
            /* ... */
        }
        else // If player clicked on the enemy, attack that enemy unit if it's in range.
        {
            bool playerHit = TryAttackUnitInRange(_activeUnit, clickedUnit); // Plays the attackers attack animation.
            if (playerHit)
            {
                clickedUnit.PlayAnimationHit();
            }
            else
            {
                clickedUnit.PlayAnimationDodge();
                clickedUnit.AnimationDodgeEnd += OnUnitDodgeEnd;

                // Stop listening to input, until the turn ends.
                _fieldInputController.FieldClicked -= OnFieldClicked;
                _fieldInputController.UnitClicked -= OnUnitClicked;
            }
        }
    }

    private void OnUnitDodgeEnd(Unit victimUnit)
    {
        // Oh, yeah, we don't need to listen this anymore.
        victimUnit.AnimationDodgeEnd -= OnUnitDodgeEnd;

        // Give it back!
        bool unitHit = TryAttackUnitInRange(victimUnit, _activeUnit);
        if (unitHit)
        {
            _activeUnit.PlayAnimationHit();
        }
        else
        {
            _activeUnit.PlayAnimationDodge();
        }

        // Switch the current player, end the turn and listen to the input again.
        // We don't need to hear to attackers dodge animation end,
        // because we're assuming here, that end turn animation will last longer.
        // In the actual game you shouldn't rely on animations duration and another event subscription would be needed.

        _fieldInputController.FieldClicked += OnFieldClicked;
        _fieldInputController.UnitClicked += OnUnitClicked;
    }

    private bool TryAttackUnitInRange(Unit attackerUnit, Unit victimUnit) { /* Returns true, if attacker unit hit the victim unit. */ }
}</pre>
<p style="text-align: justify;">** I said &#8216;one of the solutions&#8217;, so can there be more than one? Is that at least the best one? Answer for the first question is <em>yes</em> and for the second one is <em>probably no</em>. It is really good though and easy to understand as this pattern is well known by the programming world. You should always look for the better solution, when you can see flaws in the current one that cannot be accepted. Don’t look for the perfect architecture, because there rarely is one. You should choose a solution that is good enough, be aware of its advantages and disadvantages and be confident that despite the fact that the cons exist, this is the right, conscious choice. And just for the record, we can talk about conscious choice only when you considered more than one solution.</p>
<p style="text-align: justify;">There you go. Use cases for Observer pattern are countless, but don’t get too excited. There are some flaws. You can find more technical one (memory and performance) <a href="http://gameprogrammingpatterns.com/observer.html" target="_blank" rel="noopener noreferrer">here</a> and I&#8217;ll add one more, from the programmer point of view. There are difficulties related to where to start subscribing and where to stop it. In the ideal world, we could hook up to the events on the application start and don’t bother unsubscribing. Or we could do it on level start and level end. But we live in a more challenging world, so for example we’re spawning (or enabling in case of object pooling) objects – monsters, projectiles, map chunks, menu entries and we’re destroying (disabling) them eventually. That’s why we have to spend additional time to check if we have subscribed as many times as we have unsubscribed. And it’s not always that obvious because of the complexity of the code. Consequences of this are very different, they are often hard to find and usually barely visible. The easiest case is when you can see that for one tango down you gain points two times. But it is rarely that easy. That’s why you should take a breath, take some distance (both literally and metaphorically) and double check if everything is fine.</p>
<p style="text-align: justify;">In first example we began listening in Start method and stopped when the player was dead. To make it work, after player&#8217;s death we should restart whole level, so the Start method will be called. When we are just spawning the player (with blinking and immortality?) short after his death, we won’t subscribe to his events.</p>
<p style="text-align: justify;">This inconvenience shouldn’t stop you from using the events, because at the end of the day they are crucial in game development. You’ll make mistakes, everyone does &#8211; especially if this is new to you. But the fear of unknown shouldn’t be the deciding factor in not using them. Go for it!</p>
<p style="text-align: justify;"><em>Okay, we made it. Despite the topic isn’t new, there is still so much codebases that don’t utilize the Observer pattern. That’s why I decided to start with it, even if it might be not the strongest card I could draw in the beginning. As you can see, the blog is new, so every feedback will be very appreciated. Tell me what you think, what are your experiences with the topic, who you are. If we’re sharing the same passion, I want to know.</em></p>
<p><img class="aligncenter size-full wp-image-188" src="http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_feedback.jpg" alt="" width="950" height="105" srcset="http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_feedback.jpg 950w, http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_feedback-300x33.jpg 300w, http://gamesarchitecture.com/wp-content/uploads/2017/05/002_observer_feedback-768x85.jpg 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p style="text-align: justify;"><em>I’ve got a bunch of notes and drafts for the next posts and I’m excited about sharing them with you. If you think that it might be somehow interesting, stay in touch with me.</em></p>
<p style="text-align: justify;"><em>Oh, oh! I hope you&#8217;ve seen the <a href="http://gamesarchitecture.com/hello-world-of-gamedev/" target="_blank">first &#8220;hello world&#8221; post</a> about the blog and its future content. It will give you a better insight in what will be happening here. See you soon!</em></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/watch-out-youre-being-observed/">Watch out, you&#8217;re being observed!</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamesarchitecture.com/watch-out-youre-being-observed/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hello world of gamedev!</title>
		<link>http://gamesarchitecture.com/hello-world-of-gamedev/</link>
		<comments>http://gamesarchitecture.com/hello-world-of-gamedev/#comments</comments>
		<pubDate>Sun, 21 May 2017 09:12:11 +0000</pubDate>
		<dc:creator><![CDATA[Bartosz]]></dc:creator>
				<category><![CDATA[Generic]]></category>

		<guid isPermaLink="false">http://gamesarchitecture.com/?p=62</guid>
		<description><![CDATA[<p>Hey mate! First of all, I want to thank you for coming by. I hope you&#8217;ll find next few minutes worthwhile and you&#8217;ll stay with me forever for a while to see what I&#8217;ve got. Don&#8217;t forget to look at the second post! I&#8217;m starting this blog for two reasons, but before I tell you about them I&#8217;ll give &#8230; </p>
<p class="link-more"><a href="http://gamesarchitecture.com/hello-world-of-gamedev/" class="more-link">Continue reading<span class="screen-reader-text"> "Hello world of gamedev!"</span></a></p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/hello-world-of-gamedev/">Hello world of gamedev!</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;"><span lang="en-US">Hey mate! First of all, I want to thank you for coming by. I hope you&#8217;ll find next</span><span lang="pl"> </span><span lang="en-US">few minutes worthwhile</span><span lang="pl"> </span><span lang="en-US">and you&#8217;ll stay with me</span><span lang="pl"> forever </span><span lang="en-US">for a while to see what I&#8217;ve got. Don&#8217;t forget to </span><span lang="pl">look at </span><span lang="en-US">the <a href="http://gamesarchitecture.com/watch-out-youre-observed/" target="_blank" rel="noopener noreferrer">second post</a>!</span><span lang="en-US"> I&#8217;m starting this blog for two reasons, but </span><span lang="pl">before I tell you about them </span><span lang="en-US">I&#8217;ll give you some motivation background.</span></p>
<p style="text-align: justify;">’ve worked on sooo many projects that had a codebase that literally sucked. Where any, even small change, took forever and that time felt so wasted. I’ve also heard some shit from many devs and read it on a bunch of blogs about dreaming big but starting small. This is like mantra for our beloved industry. If you’re indie game developer I’m more than sure, that you’ve read something like this as well. If not, well, you’ve just lost your gamedev virginity with me. High five! And yeah, that is a really good advice and I mean it. But the thing is, that you have to like mobile/very simple games or you must be able to force yourself to make them anyway. I have to convince myself to even play something on mobile to be up to date with the industry, but I don’t find it pleasant in most cases. How long can I possibly “do small”, if I DON’T like that small game I’m working on? How to find motivation to keep going? At some point, you’ll probably find yourself in a place where you just won’t be able to go for another small project. Or maybe you’re just there right now?</p>
<p style="text-align: justify;"><img src="http://gamesarchitecture.com/wp-content/uploads/2017/05/gamesarchitectore_com_spaghetti.jpg" alt="" width="749" height="235" /></p>
<p style="text-align: justify;"><strong><span lang="en-US">I want to share my knowledge with you that will hopefully help you make your game come true</span></strong><span lang="en-US"><strong>.</strong> I&#8217;ll tell you what I know about </span><span lang="pl">writing</span><span lang="en-US"> a code that will stand a test of time better and won&#8217;t make it harder for you than it already is. </span><strong><span lang="pl">Bigger projects take much more that one-two months and working with crappy code becomes a nightmare very quickly and stops you from adding another feature</span></strong><span lang="en-US"><strong>.</strong> You’re starting to think &#8216;Oh, if I had started this once again, I would write it a lot better. Sigh.&#8217; I’ll try to help you to avoid that in the future. Too much work is wasted because of that. Making games is a really difficult thing. Making these big ones is a hard-as-fuck thing and to make it real, one needs calmness, perseverance and humility. And of course &#8216;a bit&#8217; of know-how. By &#8216;bigger games&#8217; I mean bigger than you made before, so this is purely subjective.</span></p>
<p style="text-align: justify;"><strong>If you dream about your Game and I mean The Game, I am writing for you.</strong></p>
<p style="text-align: justify;"><strong>If you want to be better as a programmer, I&#8217;m writing for you as well.</strong></p>
<p style="text-align: justify;">I’m also writing for myself, because I want to meet people that share the same dream. I wish to become a better game developer as I’m writing this blog and I just want to see more games out there that I actually want to play.</p>
<p style="text-align: justify;">So the first reason is You, second is Me, as simple as that.</p>
<p style="text-align: justify;"><img src="http://gamesarchitecture.com/wp-content/uploads/2017/05/gamesarchitectore_com_hi_there_scheme-1.jpg" alt="" width="798" height="348" /></p>
<p style="text-align: justify;">Below I’ll list the most important information about this blog. They will give you some perspective on the content, before I write more.</p>
<ul style="text-align: justify;">
<li>Most of the posts will focus on programming stuff and code architecture. Basically they will try to explain how to write certain things in the way that will help you add more things in the future with pleasure. How to avoid spaghetti and write more lasagna style, if you know what I mean.</li>
<li>Most of the code examples will be prepared in Unity. Does it mean that if you don’t use Unity this blog isn’t for you? Well, no. I think you’ll get the idea anyway. It will be like reading C# code, while already knowing C++ or any other object oriented language. And in many cases you won’t even notice Unity here, so give it a try. However…</li>
<li>From time to time I’ll write something Unity-specific or at least somehow related to the engine. But still it will be more about code/work organization than actual tips and tricks or Unity tutorials.</li>
<li>More personal aspects of the game development will also be discussed here. These topics, as I strongly believe, will help you become more approachable person and will be helpful in your work. Example? Humility and calmness will help you in interpersonal contacts as well as learning faster and debugging (to be continued…)</li>
<li>I will write about design as well. This is far more difficult craft than it looks like, but liberating and satisfying as fuck. These will be in minority, but I want you to be prepared.</li>
<li><span lang="en-US">Oh yea, and in case you didn</span><span lang="pl">’</span><span lang="en-US">t notice yet, I’ll try to keep things simple, because I’m not a native English speaker and I really like the</span><span lang="en-US"> </span><a href="https://en.wikipedia.org/wiki/KISS_principle"><span lang="pl">KISS</span></a><span lang="pl"> &#8216;way of life&#8217;. I cannot afford fancy style, but I can afford being honest with you. Deal?</span></li>
<li>I’m NOT finding myself as &#8216;knows it all&#8217; expert, I’m just a guy who loves games, is kinda’ geeky about code quality and believes. And I want you to believe too. Take it slowly, we’ll make it. More about me in… <a href="http://gamesarchitecture.com/about-me/" target="_blank" rel="noopener">About me</a>.</li>
</ul>
<p style="text-align: justify;">And I think that’s all for now. We’ll be tweaking things later on. See you!</p>
<p>The post <a rel="nofollow" href="http://gamesarchitecture.com/hello-world-of-gamedev/">Hello world of gamedev!</a> appeared first on <a rel="nofollow" href="http://gamesarchitecture.com">Games Architecture</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamesarchitecture.com/hello-world-of-gamedev/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
