<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by David J Torrey on Medium]]></title>
        <description><![CDATA[Stories by David J Torrey on Medium]]></description>
        <link>https://medium.com/@davidjamestorreysr?source=rss-5d97ad5d6f97------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_5yFNkuewZv9d--VK_cVwg.jpeg</url>
            <title>Stories by David J Torrey on Medium</title>
            <link>https://medium.com/@davidjamestorreysr?source=rss-5d97ad5d6f97------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 13:49:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@davidjamestorreysr/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a mod system for a game]]></title>
            <link>https://medium.com/@davidjamestorreysr/building-a-mod-system-for-a-game-fd566b00759b?source=rss-5d97ad5d6f97------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd566b00759b</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[David J Torrey]]></dc:creator>
            <pubDate>Tue, 18 Jul 2017 23:39:13 GMT</pubDate>
            <atom:updated>2017-07-18T23:39:13.942Z</atom:updated>
            <content:encoded><![CDATA[<h4>Item/Property System</h4><p>I decided I wanted to build a game with an inventory system and items to populate the inventory. This isn’t a unique feature, so I decided to do some research to see how others do it. There are a couple of ways I saw item systems get implemented, but most usually deal with an item data structure referencing a series of systems, components, or properties which are executed when the item is used. This allows the developer to quickly extend capabilities and reduce code duplication while allowing the game designer to quickly create items since the item itself does not implement any functional code, it just describes the item’s values and which systems/components to run.</p><p>I want my game to be modded, though. Ideally I need to open the system up a little more in order to allow others to write the features that the item describes and add them to my game.</p><p>I began to think about a moddable item/property system. The idea isn’t too far different from the original underlying method. Conceptually, you have an item that acts as a pure data structure and properties which implement the features described in the item.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*OTUcMkFI3g-T5aqyUUjWwA.png" /><figcaption>Item/Property Concept</figcaption></figure><p>The item data structure has an id, name, description, perhaps the name or location of textures and icons, and then it has a list of property id’s that are referenced. When the item is “used” it runs each attached property and loops through their execution in the update loop.</p><p>The trick here to make it moddable is to get properties that others have developed into the game for the items to reference.</p><h4>Exposing the Property Interface</h4><p>Games that can be modded have feature rich API’s for other developers to work from. It provides the context and structure for the mod code to interact with the game’s baseline code. For others to effectively write code, the game developer would provide the API to the community which they, in turn, would use to encapsulate the new features. The code is ingested by the game and stored in a way that can easily be called during runtime. Here is a quick diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*GoeB1-sHHBVPBxRRgxz-iw.png" /><figcaption>Moddable property system</figcaption></figure><p>The developer creates the new ideas, the API provides the interfaces which results in new mod code. The user converts it into a .dll which is imported at load into a database using a unique id and the Property class type. At runtime, an instance of the type is created by referencing the unique id.</p><p>To expose the Property interface, your best bet is to create an external library that you allow developers to download. They would simply need to create a new project and add your library as a reference before they can create classes that extend your interface or abstract classes.</p><p><strong>Importing Assemblies</strong></p><p>This is the real tricky part. Allowing a user to reference your libraries does nothing if your code has no way to then accept the external .dll that’s created. Your game needs a way to dynamically find .dll’s and load them at runtime.</p><p>Personally, I really like the way Kerbal Space Program’s folder structure looks. It has a GameData folder which then stores discrete directories for each mod. The developer simply needs to compress their compiled code and support content into a .zip file, and all the game user needs to do is unpack and drop the zip file into the GameData folder. Kerbal Space Program is then able to locate the .dll’s and load them into the game.</p><p>The first step, to importing new content is to narrow down where to look. We tell the system which folder to look at and it will search in all sub-directories for content. You need to go one step further, though, to make sure you are not accidentally importing .dll’s which are not relevant. In theory I don’t think it would matter because we will do checks to make sure we are importing the right classes (and in some cases, depending on how you want to set yours up, you might want to allow developers to make a single assembly for everything instead of breaking them into different parts). Regardless, from the base directory I check to find any folder labeled “gameProperties”. If a developer wants to make new properties, under their mod folder they will need to make a new one labeled “gameProperties” and place the code and support files in there. Inside of that, I do a search for all .dll files:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*sn4KHomz8J5k-0sQ7RX9gQ.png" /></figure><p>The first string array stores all of the directories which contain gameProperties folders. The next string array holds the list of found .dll files. Once the libraries are found, they are loaded using Assembly.loadFile found in System.Reflection. This step is actually important because I want to <em>load</em> all of the assemblies before I actually try to use them, or there’s potential for errors to crop up due to failed dependencies.</p><h4>Checking for Property Types</h4><p>Now that the assemblies have been loaded and stored, it’s time to find any classes which inherit from my Property interface. I only want these class types to be saved so that I can instantiate them later with a keyword. We loop through each assembly which was loaded and get the assembly types:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*4vC-XcZp0L_30DutykyHAQ.png" /></figure><p>The first thing you’ll notice is a utility class that I created called AssemblyUtils. There is an interesting quirk with getting all of the class types from an assembly which is actually pretty difficult to avoid in many cases. If there is an issue whatsoever with finding a class type, it throws an error. A common solution that I found was to use a try-catch which attempts to get all types. If it fails, it takes all of the types which <em>were</em> successfully loaded and returns them in a type array:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*vc2qxQ6Pj_NZqrX7uFYWGQ.png" /></figure><p>The method accepts the assembly to check and the type to check against. You’ll see that I check to make sure the interface exists through GetInterfaces(). I use GetExportedTypes() because I want to make sure the classes I’m checking are intended to be public. If there is an error, all of the non-null types are returned.</p><p>Back to getting the types stored:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*4vC-XcZp0L_30DutykyHAQ.png" /></figure><p>In this case, my property interface requires any implementing classes to have a UID getter. In order to actually get that UID, I create an instance of it through Activator.CreateInstance and cast it into a Property type. Finally, provided the object is not null, I simply add to my database, in this case a simple &lt;string,Type&gt; dictionary, the UID string for the key and the actual class type as the value.</p><h4>Instantiating at Runtime:</h4><p>Finally we come to how you can instantiate an imported type during runtime. If you look at the above code, we actually already did it once. We use the Activator.CreateInstance to make a new object which is then returned:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*h14DRZnfi2ZmzNw2zPlcTg.png" /></figure><p>In this case, I require the UID since that is how I will find the type to instantiate, but I also allow the for the change of value, name, and description of the new object, in case there are unique items to be used. Finally, I simply return the object to the calling code.</p><h4>Conclusion</h4><p>This is, all in all, a pretty basic setup that should be pretty easy to implement. I’m sure there are easily better ways to improve upon this and add more functionality, but this should be a good head start in thinking about how you can build moddable games using C#.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd566b00759b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The workbench]]></title>
            <link>https://medium.com/@davidjamestorreysr/the-workbench-5cbc72a59f43?source=rss-5d97ad5d6f97------2</link>
            <guid isPermaLink="false">https://medium.com/p/5cbc72a59f43</guid>
            <category><![CDATA[craft]]></category>
            <category><![CDATA[storytelling]]></category>
            <category><![CDATA[woodworking]]></category>
            <category><![CDATA[diy]]></category>
            <category><![CDATA[woodwork]]></category>
            <dc:creator><![CDATA[David J Torrey]]></dc:creator>
            <pubDate>Fri, 12 May 2017 14:36:21 GMT</pubDate>
            <atom:updated>2017-05-12T14:36:21.648Z</atom:updated>
            <content:encoded><![CDATA[<p>When I began to build a simple workbench for my garage, I had no idea that it would take me down the path of wood working the way it has. Initially, I just wanted some extra storage to put all of my tools away — most of them firmly planted in computer and electronic tools. The task seemed pretty straight forward; build 4 legs, attach them together, screw down a sheet of plywood for a table top and voila, my table would be finished.</p><p>Well, four legs and a plywood table surface later, I had quite frankly what can only be described as, if I’m being honest with myself, a wobbly pile of crap. “<em>What the hell?</em> I thought. <em>This thing has legs, it should be more sturdy than this.” </em>I grew frustrated out of just how poor the design was. I even tried to add braces in every which direction to try to make it a bit more sturdy, to no avail.</p><p>This vexing problem nagged at me. Some days I’d be at work and my mind would momentarily drift back to that wobbled design. “<em>I need to make it better. What do I need to do to make it more sturdy? This is going to require a bit of research.”</em></p><p>Let me start off my saying that prior to this I had absolutely zero experience in wood crafting. Yes, I went through a wood shop course in high school where we drilled holes in wood, tried to make a bridge to see how much weight it could hold out of sticks (I was terrible at it), and sanded down a block of wood into a derby car propelled by co2 cartridges. I sucked at it all. I always thought it was interesting, but I simply sucked at it.</p><p>Now here I was trying to build furniture; rudimentary and unpolished, but furniture nonetheless. I thought back to the design my father had built for his workbench so many years ago; the very same one he uses today. “<em>That thing has lasted over 30 years, there’s got to be some wisdom in that design.”</em> So I went to visit my dad and scoped out what he had built. I went onto Youtube, the new-age DIY spot for just about anything you could possibly <em>want</em> to do. I began to learn a few things.</p><p>After looking at the several designs, I began to notice the way the table was braced. First, the skirt of the table (the part just below the surface which runs the perimeter of the table) is not just for looks, it acts as a solid frame which allows you to screw, glue, joint, or otherwise attach the base, in this case the legs, of the table.</p><p>The next thing I noticed was that the legs, at the base, were joined together in a similar fashion as the skirt along the top. This, I came to surmise, was probably particularly important for a workbench, where the table would need to be quite sturdy to withstand heavy weight and weather the storm of other forces wrought on it in a shop-like environment. Particularly if I wished to store my extra wood or other heavy equipment I began to accumulate, like a chop saw, I’d need something that didn’t threaten to collapse each time I added or removed something.</p><p>I felt this was sufficient knowledge and began on a new workbench right away. I was quite satisfied as I began my first cuts of board to length. “<em>This one will be different.</em> <em>I’ve put in much more forethought than the last time.”</em> I cut my boards to length, finding a sort of simplistic pleasure in working with my hands for a change. There is something quite gratifying in working with something tangible toward an end goal; the satisfaction of realizing an image from your brain has been translated to a real and physical object.</p><p>I started on the legs, attached the skirt, and began to proceed on the bottom framing. “<em>I thought I cut these all to proper length, why am I having to put so much pressure on these boards to properly align them?” </em>I thought. After heavily yanking on the boards to screw them in place, I finished by placing a quarter inch thick plywood board at the base for some rudimentary shelving to place my wood on, and a full inch thick plywood board on top as a surface. <em>“There,” </em>I thought, <em>“Finally, a work bench that’s solid.”</em> I wiggled it in all directions to validate my statement, even jumped up and down on top of it once or twice for good measure.</p><p>I then went to place a few screwdrivers and remaining nails on top of it to clean up the area I had just been working in.</p><p><strong><em>*CLUNK*</em></strong></p><p>I paused for a moment. I looked over to see my screwdriver had fallen. I slowly reached out for it and cautiously placed it back on top of the table. I must have been clumsy and not placed it fully on the table.</p><p><strong><em>*CLUNK*</em></strong></p><p>The screwdriver rolled off the top and back down onto the ground. I stood for quite a long while looking at that workbench. There was a moment where I considered trying to lift it just to heave it across my garage. <em>“How could I not have considered this? The top isn’t even close to flat.”</em> I went back to home depot for some more equipment. Using a level and a ruler, I found that one side was almost a full inch lower than the other.</p><p>My first thought was that I had simply not made the workbench on a flat surface. If I was attempting to level on a graded surface, such as my driveway, then it would make sense that one side was a bit lower than the other. <em>“I’ll need to actually build this </em><strong><em>in</em></strong><em> my garage,”</em> I surmised, <em>“the driveway is not flat enough.”</em></p><p>My solution for the workbench at hand was to place “sugar packets” underneath the once side to lift it up and make the table completely flat on top. I put a lot of effort in that workbench, I would not waste it like the last one simply because it wasn’t level. Still, I wanted another workbench anyway. After making several trips to the store, I was beginning to collect a large number of power tools, and all of these tools needed a home to store and a surface to work upon.</p><p>This time I built a longer workbench in the garage where, according to my level, it was flat. I had cut everything to length, as I had done similar before, and noted somewhere in the middle of construction that I was still having issues with requiring an extraordinary amount of force to join the boards together and screw them in place. This one, however, would be perfect. Nice and flat, or so I thought.</p><p>Once again, I placed a level on top and noticed that one side was considerably lower than the other. <em>“I did everything right, this time!”</em> I couldn’t comprehend what was happening to make my tables so off. Perhaps I wasn’t cut out for woodworking, after all (I still think this, from time to time). Back to the drawing board, I went to the blueprints to make sure I was building it right, looked up other sites, and came to a conclusion: I was not accounting for warped and twisted boards.</p><p>Dumbfounded. That probably best describes my thoughts and feelings at that point in time. I was completely dumbfounded. <em>“How did I not consider this?”</em> It seemed so obvious. Board twisting and warping would perfectly explain all of that “inexplicable” force I had to exert while building these blasted things. <em>“How in the hell do I solve </em><strong><em>this </em></strong><em>problem?” </em>I jumped in deeper after some additional research and bought a planer and jointer.</p><p>“<em>Well, now I’m really in it,”</em> I decided, <em>“I’ve got just about every tool I’d need to build anything.</em>” I went about milling the boards prior to cutting them and placing them together. My unskilled hands still created discrepancies. There were still gaps I needed to putty over, mistakes with glue, slight — smaller than previously but still existent — grades in the surface, and many, many boards thrown in the scrap pile after a large mar, crack, or splinter would form while attempting to work.</p><p>Still, despite those issues, I finally built a workbench, and this one was built to last. It was — mostly — flat on the surface, held sturdy storage underneath, and seemed viable for working on. <em>“Finally, I built it.”</em> I stood proudly over my creation. In that moment, all the splendors of life filled me to the brim, and I was ecstatic that these unskilled hands had finally built something. Sure, there were blemishes, but this was an achievement. As it turned out, a workbench was far more than four legs and a surface top.</p><p>Now I started to get cocky. “<em>What else can I build?” </em>I wondered. Maybe now I’d try my hands at building real furniture. In fact, I recalled, I really needed a nightstand for the bedroom in the basement. Why buy one when I can build it? Not much time passed after I began the planning and construction that I heard those familiar words, “oops.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5cbc72a59f43" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>