Tag: pulse

RPG Development Progress Pulse – Entry 2

Progress Pulse

Progress Pulse – Entry 2

Things have been pretty busy in real life the past couple of weeks, so I haven’t had too much time for working on this. However, for this entry in the progress pulse series I’ll talk about some of the challenges I had while looking at making a generic data (de)serialization API + implementation, and why I chose to make some of the decisions I did!

Which Tech To Pick?

I’ve felt burned in the past by trying to do data serialization for my game framework because it’s always created a barrier for refactoring once it’s in place (i.e. i change some data i need and now i have to re-make or migrate allllll my SQL data).

So I was thinking about how I plan to store game state, which I have written about, and then considered the implementations I had considered for persistent storage. One of them was a graph database called Neo4j, which has a JSON representation of all of its node data. Except… I’m not ready to commit to Neo4j just yet because I don’t want to feel tied down (like I used to tie myself down to SQLite). But my objects I’m creating *are* well suited to hierarchies of entities+components, so maybe JSON is a happy medium?

Here was my breakdown for starting with JSON:

Pros:

  • Very easy to get started with
  • (De)Serialization libraries available via nuget for free
  • Human readable which is great for creating, editing, and debugging
  • Hierarchical, which lends itself well to my data structures in memory
    • Should make refactoring easy (did a component change? only change that component’s data representation)
  • Could be a stepping stone for working with Neo4j in the future

Cons:

  • Writing is probably slow, especially if I want to just modify one chunk of JSON data
    • Likely will need to write whole JSON blobs out… But who knows if it’s slow, I need to benchmark it.
  • I suspect lookups would be slow
    • But… Maybe important data is cached in memory on startup? Maybe it’s not even an issue. Benchmark it.

Basically, I was left with a bunch of pros and a couple of cons that were really just speculation. Seemed like a great way to get started!

Lesson learned was to start with something that won’t keep you locked in, but is also just enough to get you going!

Start With Something Specific

I’m a sucker for trying to make really generic things in software. It’s an extreme I find myself taking because I want to make things as extensible and re-usable as possible. The side effect of it though is that sometimes I miss corner cases (and they end up being not corner cases in the general sense) or that I make APIs that suck to use because they’re so general and maybe they shouldn’t be.

I decided I was going to switch up my approach. I wanted to figure out how I could serialize and deserialize my item definition data. That probably warrants a brief explanation:

I want items (i.e. loot) in the game to be part of a system that can control generation of them based on game state, randomness, and pre-defined organization of loot. Some drops might be totally random common items. Others might be based on quest state and need to be very specific. Maybe there’s some that only drop at a specific time of day during specific whether after killing a certain enemy. This is what I’m shooting for. So the item definitions will contain information about how to generate a base item, and provide components that tell the game how to mutate that base item (i.e. set damage to a value between 5 and 10 and call it “Axe”). But there are drop tables that have weights associated with them that can link to specific items or other drop tables. This allows the game’s content creator to generate loot that’s like “When the player is in the swamp lands, common enemies drop between 1-3 items, with a 60% chance of those items being junk, 20% chance of those items being normal equipment, 15% chance of those items being magic equipment, and 5% chance of those items being powerful legendary equipment”. Drop tables are essentially nodes with weights on the vertices that point to other tables or specific item definitions. Simple 🙂

The reason I went with this approach is because I felt that even though some of the C# types I have might be specific to item definitions, the abstract structure of the types (i.e. entities with components on them) is shared across many different game systems. So if I can make it work for this one, it shouldn’t be too hard to do for the next.

Lesson learned was try not to repeat all of your history… Learn from it. Experiment with new approaches.

Hello Singletons, My Old Friend

My arch-nemesis Dr Singleton! Actually, way back I’ve written about singletons so I’m not TOTALLY against them, I just think that 99% of the time they aren’t actually what you need. Let’s talk about my little run in with them though.

I started custom writing some APIs for JSON serialization that would use Newtonsoft JSON behind the scenes. Based on the structure of my objects, I figured I was going to have some sort of recursive call system going on where children would have to tell their children to serialize, etc… Once I got this working for a simple case, I realized that Newtonsoft has custom converters you can set up. These use attributes to mark up interfaces/classes to tell the serialization engine to use particular converters when they encounter a type. (Edit: after writing this I realize that I don’t HAVE to use the attribute… which might make this whole point moot)

The problem with attributes is that I cannot control the instantiation of them. And because I can’t control the instantiation of them, I can’t control the parameters passed in via the constructor. In my particular case, I needed to create a singleton that this attribute class could access and use Autofac to configure the singleton instance. Essentially, I needed to register custom handlers into my singleton instance, and then the attribute class could pull the registrations from the singleton instance.

Ugly pattern? Yes. I’m not familiar with any other ways to pass information or access to objects when I can’t control the initialization of my object though. It’s buried deep down so it’s not like the API usage feels like garbage, but still wasn’t happy with it.

Lesson learned here was sometimes we end up using “bad patterns”, but if they’re limited in scope we can limit their “badness”.


RPG Development Progress Pulse – Entry 1

Progress Pulse

Progress Pulse – Entry 1

For the first entry in the progress pulse series I’ll touch on some things from the past week or so. There’s been a lot of smaller things being churned in the code base, some of them interesting, and others less interesting so I want to highlight a few. As a side note, it’s really cool to see that the layout and architecture is allowing for features to be added pretty easily, so I’ll dive a bit deeper on that. Overall, I’m pretty happy with how things are going.

Unity3D – Don’t Fight It!

I heard from a colleague before that Unity3D does some things you might not like, but don’t try to fight it, just go with it. To me, that’s a challenge. If I’m going to be spending time coding in something I want it to be with an API that I enjoy. I don’t want to spend time fighting it. An example of this is how I played with the stitching pattern to make my Autofac life easier with Unity3D behaviours.

However, I met my match recently. At work, we were doing an internal hackathon where we could work on projects of our choosing over a 24 hour period, and they didn’t have to be related to work at all. It’s a great way to collaborate with your peers and learn new things. I worked on Macerus and ProjectXyz. I was reaching a point where I had enough small seemingly corner-case bugs switching scenes and resetting things that I decided it was dragging my productivity down. It wasn’t exciting work, but I had to do something about it.

After debugging some console logs (I still have to figure out how to get visual studio properly attached for debugging… Maybe I’ll write an article on that when I figure it out?) I noticed I had a scenario that could only happen if one of my objects was running some work at the same time… as itself? Which shouldn’t happen. Basically, I had caught a scenario where my asynchronous code was running two instances of worker threads and it was a scenario in my game that should never occur.

I tried putting in task cancellation and waiting into my unity game. I managed to hang the main thread on scene switching and application close. No dice. I spent a few hours trying to play around with a paradigm here where I could make my ProjectXyz game engine object run asynchronously within Unity and not be a huge headache.

I needed to stop fighting it though. There was an easier solution.

I could make a synchronous and asynchronous API to my game engine. If you have a game where you want the engine on a thread, call it Async(). Unity3D already has its own game engine loop. Why re-invent it? So in Unity3D, I can simply just call the synchronous version of the game engine’s API. With this little switch, suddenly I fixed about 3 or 4 bugs. I had to stop fighting the synchronous pattern with my asynchronous code.

The lesson? Sometimes you can just come up with a simple solution that’s an alternative instead of hammering away trying to fix a problem you created yourself.

DevOps – Build & Copy Dependencies

This one for me has been one of my biggest nightmares so far.

The structure of my current game setup is as follows:

  • ProjectXyz.sln: The solution that contains all of my back-end shared game framework code. This is the really generic stuff I’m trying to build up so that I can build other games with generic pieces if I wanted to.
  • Macerus.sln: The game-specific business logic for my RPG built using ProjectXyz as a dependency. Strictly business logic though.
  • Macerus Unity: The project that Unity3D creates. This contains presentation layer code built on Macerus.sln outputs and ProjectXyz.sln outputs.

I currently don’t have my builds set up to create nuget packages. This would probably be an awesome route to go, but I also think it might result in a ton of churn right now too as the different pieces are constantly seeing churn. It’s probably something I’ll revisit as things harden, but for now it seems like too much effort given the trade off.

So what have I been doing?

  • I build ProjectXyz.sln.
    • The outputs go into this solution’s bin folder
  • I build Macerus.sln
    • There’s a prebuild step that copies ProjectXyz dependencies over
    • The outputs go into this solutions bin folder
  • I use a custom in-editor menu to copy dependencies into my Unity project
    • This resets my current “dependencies” asset folder
    • The build outputs form the other solutions are copied over
  • I can run the project with new code!

This is a little tedious, sure. But it hasn’t been awful. The problem? Visual studio can only seem to clean what it has knowledge about.

I’ve been refactoring and renaming assemblies to better fit the structure I want. A side note worth mentioning is that MUCH of my code is pluggable… The framework is very light and most things are injected via Autofac from enumerating plugin modules. One of the side effects is that downstream dependencies of ProjectXyz.sln (i.e. Macerus.sln) have build outputs that include some of the old DLLs prior to the rename. And now… Visual Studio doesn’t seem to want to clean then up on build. So what happens?

Unity3D starts automatically referencing these orphaned dlls and the auto-plugin loading is having some crazy behaviour. I’ve been seeing APIs show up that haven’t existed for weeks because some stale DLL is now showing up after an update to the dependencies. This kind of thing was chewing up HOURS of my debugging time. Not going to fly.

I decided to expand my menu a bit more. I now call MSBuild.exe on my dependency solutions prior to copying over dependencies. This removes two completely manual steps from the process I also purged my local bin directories. Now when I encounter this problem of orphaned DLLs, my single click to update all my content can let me churn iterations faster, and shorten my debugging time. Unfortunately still not an ultimate solution to the orphaned dependencies lingering around, but it’s better.

The lesson learned here was that sometimes you don’t need THE solution to your problem, but if you can make temporarily fixing it or troubleshooting it easier then it might be good enough to move forward for now.


RPG Development Progress Pulse

Progress Pulse Series

I figured this would be a fun thing to start to do just to get small updates out and talk about what I’ve been working on for ProjectXyz and my RPG I’m building in Unity3D. This will hopefully be some small updates on the order of semi to bi-weekly about what kinds of things are going on when I’m programming for these projects. This could include:

  • How and why I decided to refactor something
  • A new design practice I’m trying
  • Reflecting on why a design decision has(n’t) been working out
  • A new feature that’s interesting
  • etc…

Some of these will be technical and others much less. A bit of progress pulse allows me an outlet to talk about interesting things I’m doing and maybe sheds some light on some areas (game development or just general programming) that you might be interested.

Where Can I Find Entries In This Series?

I’ll try to organize these Progress Pulse entries into a specific category on my blog. Ideally that way you can navigate them pretty easily. You can click the link below and you should get all the entries in this series!

Click Here For Entire Progress Pulse Series


  • Subscribe to Blog via Email

    Enter your email address to subscribe to this blog and receive notifications of new posts by email.

  • Nick Cosentino

    Nick Cosentino

    I work as a team lead of software engineering at Magnet Forensics (http://www.magnetforensics.com). I'm into powerlifting, bodybuilding, and blogging about leadership/development topics over at http://www.devleader.ca.

    Verified Services

    View Full Profile →

  • Copyright © 1996-2010 Dev Leader. All rights reserved.
    Jarrah theme by Templates Next | Powered by WordPress