Category: coding jabber

  • code distractions

    Pleck’s Mart is still in development.

    Oh, I know, I’ve been remiss in posting updates or, to be blunt, in actually writing code for the game, but that doesn’t mean I’ve completely shelved it.

    First, it was summer, and the project was always a kind of too-cold-to-be-outside winter project for me to poke away at.

    Second, I’ve had some contract work that involves a lot of development work so my coding brain has been fatigued in a way that is hard to articulate.

    Third, when I’ve been coding for fun I’ve been working on another little non-game project: a custom CMS.

    Oh, I can hear you groaning. Just what the internet needs—another custom CMS system.

    But the truth is that coding practice is coding practice, and writing a CMS is a great little intermediary coding project to practice all sorts of hard coding skills: database design, interface design, security, and conditional logic for a start. But it also is a way to curate some softer skills around code management, feature creep, usability, and quality assurance.

    I mean, it’s unlikely I’ll ever do much to release this besides perhaps making the repo public at some point, but this little CMS I built started out life as a tool for myself to post social media-like content on a self-hosted website without the pressures of “engagement” getting in the way. I started using the very early version as a kind of mobile-focused travel blog back in 2022 on a trip to New York, the posts resembling nothing more than an old school Instagram: a photo and some text and some metadata.

    In the intervening years I’ve added more features, but mostly as a way to enhance the original vision of the tool: incorporating code to detect and better display panoramic photos, the ability to attach an audio clip to a post (think photo of Disneyland with a minute of ambient sound recorded while walking through the Small World queue) or a robust hashtagging system that allows me to essentially categorize and create photo collections on the fly.

    I’ve learned a ton building it and maintaining it, even just for my own personal use.

    And having spent a dozen free hours this past week adding some geo-linked features to the administration panel, fine tuning my security, tweaking some display quirks, and generally doing some code maintenance, it continues to teach me new lessons about developing software and writing code that I am 100% certain will translate back into writing better game code when I finally settle into my winter game design routines.

    Hobby projects can be a route towards experience that many professionals overlook. Sure, you went to school to learn something or you got on the job training at something else, but until you do it for yourself and become the primary problem solver for a project—be that coding, woodworking, cooking, or any other profession-meets-hobby—you are always just part of the job, and are missing out on build some skill that you might not even realize was there waiting to be learned.

    It doesn’t need to be a CMS, obviously. Just what the internet needs, after all, another CMS. But making something for yourself is a great skill-building distraction for anyone.

  • mountain views

    Almost always when you’re up in the wilderness climbing a mountain the terrain changes with each passing trail marker, sometimes step by step, definitely hour by hour. You may start off on a wide trail with a gentle grade surrounded by rich forest, and that may break out into a rocky traverse along the dog legged trail through a centuries old rockslide, which around the next bend becomes a narrow clamber up and down through some root-laden single track all of it leading to a steep cliff where you need all four limbs coordinated and strong to reach the top.

    If I ever needed an analogy to write about indie game design and development, I think one of  the obvious options would be to compare it to climbing a mountain. It changes with every step, and you need to be prepared for what’s around the next corner—and that could be anything.

    My life has been cluttered up with non-game work these past couple weeks so progress on development has been a bit of picnic stop at a scenic viewpoint.  I’ve been swatting bugs, changing my socks, and enjoying the view from my efforts so far, but I’m not getting much closer to the top. Yet, this moment of pause and assessment is, as any seasoned mountain hiker would tell you, might be as important as any forward step up the trail.

    All that said, as I write this I’m getting fueled up for the next few days of knuckling in and pushing on.

    Sadly (for my forward effort in my education) my weekend round of lectures was postponed and rescheduled. This sets me back by about a month in my professional training, but—lemons made lemonade—frees up three solid days for some game coding.

    What have I done since last checking in?

    A lot, actually, but only a lot if—again to the mountain climbing analogy—if you consider squashing bugs, play-testing, cleaning up code, and poking around in my supplies an important part of the journey.

    It had been over three weeks since I loaded a snapshot on my SteamDeck, and doing so with my bug-tracker sitting open next to me gave me a full day of work tuning controls, stabilizing code, and catching other little UI quality of life  fixes.

    I also dug into the back end of how I’d built things at the beginning and did some refinement. My understanding of Rust and Bevy both have grown exponentially since December and I look at the ways I built some of those original functions and see significant improvements to be made. And maybe this is a little disheartening to rewrite stuff that was already working, but then at the same time I’m tweaking stuff so that it can be expanded to to ten more things in addition to the thing it was originally written to do.

    I’ve also made a lot of art. 

    Art is time consuming. Heck. I figure I need somewhere in the neighbourhood of 300-500 more art assets. I’m able to make about four or five an hour. So, mathy time, that is something like a hundred plus hours of work drawing little pixel sprite carrots and tomatoes and blue cheese. Fortunately I can multitask my art (unlike my code) by which I mean I can draw with the “distraction” of the TV on, so I’m simultaneously getting my fill of classic Simpsons episodes while I draw.

    After I write this I’m going to do a couple things.

    I’m going to record a video of the game-play and grab some more screenshots. If that goes well it should get dropped about here…

    And I’m going to go into GitHub and reassess my issues. I’ve pushed and nudged and swept all the fiddly jobs into a pile and that pile is sitting in the middle of me finishing this latest milestone. So I need to reassess some of the things I said I was going to do and either say frak it and just do them today, or figure out where to shuttle them off to a future state again.

    Either way, I’m closing out 0.4.8 today and moving onto 0.4.9–and bound and determined to move into 0.5 by the end of the weekend.

    Stay tuned.

  • connective tissues of code

    I like to write about the interstitial tissues of this coding effort because I assume that you assume in turn that much of the guts of this thing is me sitting at a desk writing code into a collection of text files.   The interstitial connective tissue between that coding is what is often more interesting.

    Yet, sometimes, I make those layered efforts and the stringy bit in between writing that actual code feels like a lack of progress, when in fact I need to remind myself that is often some of the more important work.

    This weekend I went down a rabbit hole of interstitial work that felt a bit like progress when it worked and like so much more wasted time when I was struggling.

    Last week, after I wrote my last post about the milestone of achieving the foundational bare minimum of a game I got an idea into my head. See, to remind you, after nearly two months of writing code that amounted to a kind of half-baked collection of systems that did stuff, I wrote the last of the systems that led me to a point in the writing of this game wherein I could actually start calling it a “game” — as in, or that is to say, the systems reacted and progressed in a way that it was more than a cute demo of code and sprites and time clocks and other loops, but rather there was suddenly therein a point. It became a game, if a utterly simple and mostly pointless cozy toy of doing stuff with no broader implications. It kept a score, it had conditions to progress, it played. It was a bare minimum game by my own biased approximation. 

    I got it into my head to do a thing with it. I got it into my head to put this game on my Steamdeck.

    For those reading this who may be less techie than I, a Steamdeck is a portable gaming computer very much resembling a Nintendo Switch but whose guts are more much more powerful than that and encompassing a gaming ecosystem designed, built and sold by a company called Valve who owns the Steam game store which in 2025 is The Foremost Place to buy and sell PC games. A couple years back they released this portable gaming system that was built on the ideologies of open design, right to repair, and extensibility. Simply, it’s a computer that is packed into a little portable form factor, running an open source operating system and linked to a downloadable ecosystem of countless games, from triple-A titles to little indie games like mine.

    Mine. But not yet, mine. 

    See the end goal of an indie game guy like me is to get their game into the hands of gamers and the aforementioned Steam game store is the modern go to for gaming self-publishing.  For a small fee I can put my game on there and anyone (and there are literally hundreds of millions) of their customers can buy and download it. 

    A lot of those people would, of course, want to play it on their very popular  Steamdeck. 

    I have a Steamdeck. And so logically, developing this I should figure out how to at the very least test it on there.

    This was where my brain was last week as I was playing around with the code and the compiled version of my game there on my Windows PC where I write my code each day.

    So. Off I set, down into the rabbit hole. 

    Down, down, down I went. Down deep into learning about the Steam developer tools, about cross-compilation, and about the lack of important code libraries that would make all that seamless and easy.

    A few hours into my efforts I realized that I would not be able to just press a button on my Windows PC and have a working copy of my game that would run on the Steamdeck. The Steamdeck, see, runs on an operating system called Linux. You may know enough about computers (not mobile devices, that’s a whole other ballgame) to know that there is Windows and there is MacOS, but then also that there is a third equivalent called Linux. Linux is technically free in as much as there is no Licence to buy to use it. There is a steep learning curve to making it work well, a curve that has smoothed considerably since I started playing around with Linux in the 90s but a curve none-the-less. Likely you interact with Linux on a daily basis and don’t even realize it. It lives on a huge percentage of the worlds web servers, for example, or on many little gadgets and toys (the Steamdeck for one) that haven’t switched over to something like Android. I have a few little Raspberry Pi computers in my house, the famous little fifty-dollar computer which runs a flavour of Linux called Raspberry Pi OS which is, again, just Linux. 

    I haven’t been writing my code in Linux. I’ve been writing it in Windows. And while normally in 2025 that isn’t the main problem because things like cross-compiling exist, I ran into one of those cases where I was making something complex enough that it didn’t “just work” like I had been expecting. 

    So there I was, a few hours in of mucking around in Windows trying to make a game that would run in Linux, and it wasn’t working. 

    Side note: Steamdeck does have a little emulator called Proton that lets you run Windows games, but that wasn’t working either. 

    So, deeper into the rabbit hole I went.

    First, I thought to myself that it since my Steamdeck is technically just a Linux computer in a pretty box I could just move the code over there and compile it there. I spent a good two hours installing software and building drivers and connecting all the dots and—well, I’ll be honest. I seemed to be running into roadblocks that seemed like they were inherent to the Steamdeck itself and as thing were grinding away I was already looking to other machines in my house for help. 

    At some point I moved onto one of those aforementioned Raspberry Pi machines. They are slow but persistent. They are meant to do simple word processing or manage file systems. I put all the pieces on a little Raspberry Pi 400 I have set up as a mini desktop computer in our bedroom and started compiling— and quickly ran into the same problems I had encountered on the Steamdeck. 

    Ok. So it wasn’t a Steamdeck issue. But I pushed on and solved those issues, dug deep and found the right commands to download the right libraries and then—slowly, like eighty minutes slowly—it churned through the code and finally spit out a working game. 

    The Raspberry Pi doesn’t have a graphics card, mind you, so when I booted Pleck’s Mart to life it chugged away at about 2 FPS struggling to keep up.  I had a game running on Linux.

    I copied all the files over and, though it was approaching midnight and I had a wife giving me dirty looks from where she was planning on going to sleep fifteen feet from where I was compiling code late into the night, I ported it all over and loaded it into the Steamdeck. 

    Memory stick transfer. Upload to deck. Press play. Bonk!

    Again. It did not work.

    I went to bed, having failed to complete my goal.

    I was up around 5am with a new idea. 

    A couple years ago I had loaded a copy of Ubuntu, a popular version of Linux, onto a twenty-year-old laptop computer.  It had few advantages over the  Raspberry Pi in speed but it did have the bonus that it was not in the bedroom where my wife was sleeping at 5am on a Saturday morning. 

    I dug it out, booted it up, went through all the same steps to get that compiler up and running as I’d done on my Pi the night before and—wham, by 7am I had yet another compiled copy of my game. 

    Memory stick transfer. Upload to deck. Press play. Crash.

    That didn’t work either. 

    After breakfast I spent another couple hours doing online resesarch and, sparing you the thought processes and digging through the cryptic Steamdeck logs, I will tell you that I learned that by default my game engine of choice, Bevy, uses something called Dynamic Linking. That is to say, when I put the game on my Steamdeck it was looking for files that were linked (to save space, or something I assume) to the the computer where I compiled it.  Turns out, if you want to “ship” your game, you need to use Static Linking and bundle all those important things up with the code.

    Another couple hours and adding even more plugins to my laptop I tried one more time to compile the whole damn thing. 

    Memory stick transfter. Upload to deck. Press play. Game!

    Almost twenty-four hours of frustrated tweaking and nudging and the game actually booted on my Steamdeck. Success, rigt?

    Yeah. And I could have ended the story there. 

    But by mid-afternoon on Saturday, after enjoying an hour of gleeful playing around with my new portable game on the couch, I had come to the conclusion that my biggest mistake was that I was using the wrong operating system at the foundations of this effort: that is to say, I should be using Linux as my development computer, not Windows. 

    Either work. There are arguements in favour of either. But Linux has advantages that were weighing in its favour for my work going forward.

    So. No time like the present to make the switch, huh?

    Here I endured another twenty-four hours of sporadic effort of trying to build my computer into a dual-boot system split between Windows and Ubuntu Linux, first by trying to run it (very unsuccessfully) off a USB memory stick (toooooooo slow) and then off a hard drive partition. By late Sunday night I had duplicated all the functions of my slow twenty-year-old laptop into a fresh development environment on a cleaved off chunk of hard drive on my newer, faster desktop PC—and had not only managed to compile the code, but to do a couple of code commits to my git repository. 

    And now, as of writing this, I have been happily writing and digging back into the day-to-day coding and working on “tickets” fully in Linux, having added little more than a couple behind the scenes tweaks and enhancements to the game. But coding. 

    Having changed nothing, but simultaneously almost everything.

    This is all interstitial stuff. Connective tissue of the actual code writing work that is so much more satisfying.

    I had spent nearly forty-eight hours of effort and frustrations doing little more than nudging my code into a different part of the hard drive on my computer.  

    Yet, confirming that I could do exactly that. 

    When my wife was more awake I noted to her that if I could not have made the game run on the Steamdeck there was a notion in my head that my whole plan might need adjustment. What would have been the point? You know? 

    And as I wrote above, it feels like simultaneously so much progress and virtually none at all. Very important yet invisibly trivial. Everything and nothing.

    Connective tissues. 

  • them carrots

    I don’t ever want to get ahead of myself here, posting half-baked successes as if they were all star performances. Yet, back nearly two months ago now when I sat down at the computer and worked myself up from a “Hello World!” introduction to Rust Language programming to a rudimentary game loop, it was a long road ahead of me to a day like today.

    What’s special about today?

    Well, besides the fact that it is the day of St. Valentine and I am yet again sitting in a cafe writing about code, there is the simple success that as of a few more minor tweaks this morning I am about to hit an interesting sort of milestone.

    When I wrote that rudimentary code two months ago the thing that I wrote in a game loop was quite simple: a time-based cycle, looping through and counting off seconds passed, and at specific increments of time applying changes to data in a table.  That is an abstraction, tho. What I was actually trying to model and represent in code was the aging of a bundle of carrots.

    Yes, carrots. 

    You can put two and two together I assume. I’m building a game about a Science Fictional Supermarket and as such my game would obviously have something resembling a bundle of carrots and given that time passes in even most science fictional universes, said carrots must age. 

     Thus is the foundational premise of my game after all. You sell things in a store and the those things sell based on their quality and their quality is affected by what’s going on in the universe.  So, things like aging are one of those obvious things.

    Could I model an aging carrot? A carrot, getting stale and decreasing in quality and value is little more than a set of numbers representing those things, but the short answer was yes. Yes, I could. My little proof of concept code counted off the seconds and minutes and even an hour when I let it run, and after increments of time changes applied to those numbers representing my carrots changed to other numbers. Math. Imagination. Code.

    Then I dug in.

    If you’ve read any of these writings you already know that I’ve been plugging away and building rooms and doors and game clocks and npcs and art and sound checks and code efficiency debugging tools and piecing it all together.

    I’ve built a store and a warehouse on my screen, I’ve given controls to the little character to run around that space as time passes around him. I’ve given him virtual money and a place to spend it. I’ve enabled him to pick things up and carry them around, and then to set them down again somewhere else. I’ve put little virtual customers in the store walking around and getting in the way. I’ve layered a story over top of that with discoverable beats and unlockable help tips and a world stuffed with books that detail interesting backstories.  And then this week I added a sales loop that checks when the store is open and takes stuff that exists on the shelves and slowly sells it turning it all into profit. 

    And then today arrived. 

    I have one open ticket left in this milestone phase of my project tracking tool wherein I manage my efforts to make this silly game. I’ve worded it a bit different than this, but basically the ticket is: make the carrots age.

    Yeah, yeah. My proof of concept two months ago started with that first. But then I went back and built it all right building up to this point and… 

    I need to make my carrots get old. And everything else, too, obviously.  Age, go stale, decay, rot, et cetera. That is the one last underlying pretext of the game to complete the great big circle of my alpha-minimum-viable product game loop.  

    After today I don’t just have a part game. I have a game. 

    I mean, it may not be very good and it needs a lot of content and polish and tuning and tweaking, but the core of it will be there.

    Everything that follows will be enhancing that loop. Everything that follows will be making the loop more challenging and interesting as a game, adding obstacles to slow progress or challenges to keep it interesting or story to give it context or art, art, art so much art to give it depth.  Yes, there will be bugs. Yes, there will be inefficiencies that need to be tweaked. Yes, it will grow and shift and improve, but at the very core of my code there will be a game by the end of the day.

    That’s what’s special about today.

  • shortcuts & bottlenecks

    It has been literally a full week since I’ve posted an update and tho I wouldn’t say that I owe an explanation for that, there certainly is one. See, a lot of people juggle time management, balancing work and play and code and life. I am no different, obviously, but this past week has been one of those weeks when a lot of other things have sidelined the code-writing and the pixel-art-making and the usual hunkering down in the basement turning my sweat and tears into a silly little video game.

    I won’t go into details, but school and such account for most of it, and while as of yesterday I pushed through and submitted the last of a short list of assignments, to say I’ve dived headlong back into code would be slightly inaccurate, too.

    But then the whole thing seems strange at this stage because even though I haven’t been able to spend nearly as much time as I may like on actually writing code, I also seem to have come to the part of this development project where two things are true:

    1) what’s really slogging my progress is my ability to generate art, and

    2) most of the progress I am making is expanding and duplicating features.

    The first of those two statements seems pretty self-explanatory, right? I write some code for a player inventory and then I need to make art for the two hundred things that go in that inventory. I add a toolbelt, and now I need to draw all the tools. I added the ability to add decorative and interactive objects into playing field and now I need to draw dozens and dozens of interesting objects that might realistically populate the floor of a grocery store. My bottleneck there is art output, and I’m not an artist who has ever really been about volume production, so it all takes some mental shifting.

    The second statement is a little more vague, perhaps? I mean, the whole effort here has always been expanding features, incrementally adding functionality to the game world. 

    And yet, for a very long time that incremental enhancement was either entirely new code or entirely new functionality. Draw a room, add animations, add collisions, create database queries, respond to input. New. New. New.

    But lately I find that I now have kind of two tiers of code: (a) stuff I wrote way back that is foundational and important and has been tested and refined and tweaked and expanded, and (b) stuff that I am squeezing into the gaps anew. And to make it more interesting, a lot of those gaps are emerging through copying stuff I already wrote and using it in a slightly different way.  This is a good thing, I think. If you build a system and it works and it is something that can be stretched a bit and nudged a bit and reused so that you have two very similar systems leveraging some of the same resources and working in pretty much the same way but resulting in slightly different outcomes, then that’s a good design practice.

    An example might help here. Take my path grid code for example. 

    I got ambitious one weekend and diverted myself by working on something I should have left for a later phase: I built a path tracking algorithm for npcs. It’s not complex. To be fair, the whole thing could be expanded easily, but as it stands it is literally an invisible grid matrix that corresponds to each tile of a room map. The two are independent, but they are tethered together digitally in that when one moves the other moves, when one changes the other changes, that kinda thing.  The grid consists of  and X x Y size, and each “cell” contains a bit of data: planar coordinates that correspond to the map, a “type” and most importantly for my npcs, and “occupier” code. An NPC exists as a varible inside the grid “occupying” a cell when it is standing still, then checks a path to see if the next cell is occupied or not. If so it changes direction. If not, it occupies two cells for a moment as it moves from one to the next, then releases the one it left back to a cleared state. It sounds complex, but it took less lines of code to make it work that than to explain it here. I tested it. I pushed it. I have tweaked and solidified it. It works pretty well.

    And so rather than rewrite something entirely new for how objects exist in a room—sitting on shelves or on the floor as obstacles—I just duplicated some of my npc code and now, as far as the software is concerned, objects are just a kind of npc that lives on that same invisible grid occupying a cell.

    The original npc code took me over a week to write. 

    Building off of that code in the same amount of time I was able to add a store system, a player inventory and toolbelt, and an entire scheme of putting obstacles and objects in the room—all while I was deep in some school courses where I had rightly diverted eighty percent of my attentions.  I had once figured this second part would take me a month of coding. Instead, it just sort of was an oh-copy-paste-this-code-and it mostly worked.

    I like to think that was all good planning, but it was mostly just a bit of fortuitous flukey foresight.

    The short version of all this is that my code is sprinting because of these lucky shortcuts but now running into the bottleneck of my ability to art fast enough.

    I guess I need to spend more time drawing and less time writing long winded posts about it, huh?

  • some crazy game symphony

    I have recently been accused of writing things that no one understands.

    “I don’t even know what half those words mean.” A friend remarked. “All that stuff you post about your game.”

    The effort of trying to bring a glimpse of a guy trying to do some simple game design to the masses is as difficult as the coding, it seems.

    The problem is that coding and technical stuff is jargony. It is tough to describe complex things, after all, without falling into the easy rhythm of just using the complex words.

    And, it turns out, if that isn’t a metaphor to describe the challenges I encountered in my code this week, I don’t know what is.

    Falling back on the easy, I mean.

    It wasn’t so much that I shortcutted or made bad decisions, per se, but rather that in my effort to do something complex I described it to the compiler—I wrote code—in a way that, um, confused it a little bit.

    My code got just complex enough that I ran into one of those juicy jargony words that begrudge programmers all over the world: race conditions.

    Let’s back up a bit. What the hell is coding anyways?

    You probably know or have heard that computers speak binary. Zeros and ones. Right? And that is true. Virtually every computer program every built for every consumer product relies on binary computation.  (I could go on about quantum computers or analog computers or whatever, but let’s keep this simple, shall we?) Digital computers speak binary.

    I’d love to be able to spit out a string of zeros and ones long enough to fill a library and not make any mistakes and do so well enough that it results in the computer making a game called Pleck’s Mart that you all want to eventually play.  But I will never be able to do that. 

    I can, on the other hand, write down all those complex ideas in a text editor in a language called Rust (which I have been learning quite well) and then ask this little bit of software on my computer to turn it into that string of zeros and ones so that it becomes said game.

    That’s coding. Writing out complex instructions for a compiler to turn your plan into binary numbers.

    And knowing this, you should also know that this can fail in two basic ways: Either you can write code so bad and wrong that the compiler tells you it kinda sucks and you should fix this or fix that and go back and try again because it doesn’t understand—or, you can write code that makes enough sense to get translated but results in something unintended happening when the computer starts mathing and computing all those resulting zeros and ones. We call the first bad code and the second, usually, a bug.

    The first fail, bad code, happens to me a hundred times per day, and I go back and fix stuff. I mistyped a variable or forgot to make something mutable (flexable and changable in the system) or missed a semi-colon at the end of a statement or—the list goes on.

    The second fail happens alot too, but is occasionally more subtle in as much as you don’t notice that the results are wonky until you really do. Easy to spot bugs are incorrect coordinates on sprites or calling a valid but incorrect variable or switching the signs on a math calculation.  The hard ones are things like the thing that bit me in the butt this week: race conditions.

    To understand this you have to also understand something that is probably pretty basic but important to my point: computers are fast. Freaking fast, these days in particular, but they have always been way faster than we realize.

    You can look at this little video of my game that I recorded yesterday of things on the screen and realize that there are about five hundred individual images on the screen, each a file that needs to be loaded into memory, and simultaneously the computer is reading information from the screen, the mouse, the keyboard, my gampad controller, playing music, loading up individual click sounds for the little interactions, checking the math to see if anything I do causes any two of those little image files in the pretend space of the screen to crash into each other, and about a hundred other things I can’t even keep track of—and it is doing all of that on repeat over a hundred times per second.

    Per second!

    And I, the invisible conductor of this crazy digital symphony, need to to have staged all of that down to the millisecond.

    And when things are simple, nothing really deeply goes wrong. At least not wrong enough to matter.

    But then things get complex and—well, let’s go back to that symphony analogy: I play in an orchestra so believe me when I say it is easy for things to get out of sync. The timpani is pounding out a steady beat but then the clarinet comes in half a second late and the violas sitting next to the clarinets try to pace them, but the violins are watching the conductor and timing themselves to the baton, and then the trumpets who can’t hear anyone but themselves way at the back decide to wing it and jump in too. The result might be music, but it more likely will just become noise.

    One thing got ahead of the next thing and the thing that was supposed to be following in a planned order happened out of sync and—that’s kinda a race condition.

    In coding, as I understand it, a race condition is when the code is not exactly wrong, but you as the coder have not put in the right set of rules to stop things from getting out of sync. 

    On a small program you might not even notice.

    On a growing and complex program? Chaos ensues. If things don’t crash outright, then you suddenly have eighteen soundtracks playing because they are not properly being removed and replaced, or all the objects in your room spawn a mere half a second before the rest of the room making it look like ten cases of tomatoes just blipped and appeared in empty space for a moment, or else your player flashes brightly because the lighting effects took effect a beat too late to maintain the illusion of that shadow you had meticulously coded. But then, mostly, yeah, mostly it just crashes. Or bogs down to a crawl as eighty-seven thousand copies of your player sprite spawn into the program and the computer (as fast as it is) just throws in the towel because even it isn’t that fast.  And then it crashes anyways.

    These things are not laziness in coding, but they are me making assumptions about that long string of zeros and ones and assuming that the computer can make sense of them as much as I think it can without tripping over its digital shoelaces.

    They are adding a dozen more musicians to the orchestra and just hoping they will all keep perfect time.

    Thankfully Bevy, the game engine I am using, has mitigations for this. I have spent a few hours restructing my code to give it a little bit more of a compartmentalized order and some timing conditions. That, for people who thing I am being to jargony, just means that I can specifically tell the computer to wait for one thing to happen before starting something that is supposed to happen after it, and I can also tell something else to count to ten and hold its breath before doing something else. Like cues and an enforced script, mostly. Sheet music and each musician with their eyes glued to the conductor and noise cancelling headphones so that they can only hear themselves. No more winging it and hoping for the best.

    All of these challenges are themselves spawning out of something good, tho: progress. Real progress. The game is moving forward. As much as my code is occasionally tripping over itself, that can be managed and fixed, and the result still is that the game does something this week that it didn’t do last week. It’s progressing. 

    In this phase I have dug into objects: stuff on shelves, mostly. I built the core functionality that allows the little guy (who up until now was just walking around exploring) to order objects from the shop, carry them around in an inventory and put them onto shelves, pick them up again, and put them somewhere else. 

    And it is weirdly satisfying to organize cases of vegetables in the store or the warehouse. So long as the game isn’t racing and crashing that is.

  • this version life

    If you have been reading any of my posts on this project you may have noticed me writing a lot about version numbers.

    To many, versions are obvious from the outside but the nuances of how each project numbers their versions can differ.  I assume there is some level of standardization at big companies, maybe even between companies, but generally this is a simple way for me to track progress.

    For starters, it’s not a numeric decimal system. That is to say, while it uses numbers and decimals, it is not math. So Version 0.1 is different from Version 0.10, for example, it’s not an issue of significant digits. Rather, it’s a sub-versioning number, so: 

    Version 0 Subversion 1 is different from Version 0 Subversion 10. 

    As I write this I am in 0.3.6, which means I am in:

    Version 0 (pre-release)

    Subversion 3 (what I am calling my world-populating phase)

    Sub-subversion 6 (or cleanup on aisle 3)

    I could also suffix all that with the term alpha, meaning (and what I really am in is) that my current formal version should be called 0.3.6a.  But then, I haven’t actually released any code, so its a bit pointless telling you something that you can’t see or download may not work well on your personal machine because I haven’t tested it that far yet.

    I have noticed with my versioning system that a small trend is starting to emerge, tho. That is to say, the bigger the third number (ie the higher the sub-subversion) the more tedious the work.

    x.x.0 is a new phase.

    x.x.1 is me mucking around with big new systems and fun and trying out interesting new things.

    x.x.2 through 3 or 4 is more of the same but also fixing bugs and tweaking.

    I am now in a x.x.6 phase which is almost all bug-fixing, adjusting pixels left or right, recalculating math checks that I thought were working but could use fine tuning, that kind of thing. It’s sweeping up before we get to the next big feature push.

    I want to move into that next big feature push. Those are fun. Bug squashing can be satisfying, but progress is sooo incremental in the higher number sub-subversions that it’s almost toooo incremental. Progress is in the form of “I thought this worked but… uh oh… okay, now it seems to work but… uh oh…”

    Tweak. Squash. Nudge. Clean up.

    In version 0.3.x I have accomplished an incredible amount to bring the game to life as a world. The population of the space that I built in 0.2.x has left me with added dimensionality for the game, moving from a simple two-dimensional navigable grid to not just a grid with a third z-axis layer of depth orders and stacking logic for the sprites, but also a temporal dimension in the form of a game clock with days, months, seasons and year, a sleep cycle, and the mechanisms for ambiant lighting to change when the time of day changes. And all of that doesn’t even mention the fact that game now acutely takes place in that science-fictiony five-dimensional space of parallel dimensions.

    Still, polishing code in this late sub-subversion, zero point three point six, has me itching to move onto zero point four point one where I will get to dive into a stage that is all about building player complexity through adding functions, fleshing out the sprites designs, adding an inventory and a wallet, and a short list of other big things that will start to make it feel less like the little dude is just a ghost walking about and more like he has a point in the world. All of this is big, juicy, code for which I have big, juicy ideas filling my brain…

    But I gotta polish, tweak, squash, nudge and all that stuff first.

    That’s the version life.

  • incrementally npc

    In building this game world as it is, filled with floors and walls and shelves and light swtiches and everything else, I knew I was eventually going to run headlong into what I perceived as my biggest challenge: the NPC.

    What is an NPC? For all you non-gaming folks out there, the term NPC stands for Non Player Character, or anything in your game world that is for all intents and purposes “alive” and mobile. Mostly though, the term NPC refers to the people, animals and (in some games but so far not mine) monsters or enemies.

    The thing is, it is all fine and simple to build a wall or a shelf, but it’s a whole other undertaking to build in code something that has behaviours—behaviours like walking around the room and interacting with objects and having conversations with the player, et cetera, et cetera. 

    I mean, think about it this way: to move the player around the screen I have (of course) lots of hard rules built into the system about boundary collisions and input directions and all of that can be negotiated in real time by a human being playing the game with a brain inside their head poking at a keyboard.  

    But on the other hand, an NPC needs to be literally programmed to do things in the game. These are not magic or automatic. They are code, and carefully plotted tangles of logic loops. Like, simply to appear to move, an NPC needs to have a route to follow around the room, a kind of connect the dots map, and then of course to follow that map completely independently of whatever the player (with the aforementioned brain) is doing in the foreground and too, while everything else is going on. In every frame of game time, a hundred times per second, I need to have coded in a “what do I do now” kind of command that also tracks a “what have I already done” and a “what do I need to do next” and “where the heck am I in this multi-dimensional universe anyways” state of existence. 

    Sounds pretty straightforward, huh?

    To be fair, it is only just mathematics around geometry and timers and coordinate planes and incremental counters, joined together in an elaborate choreography upon an invisible stage that needs to itself be tracked and moved in perfect synchronization with the player movement and the more little factors that are considered the more lifelike it all appears until the player (and sometimes event the programmer) forgets that the little pixel art moving around the screen isn’t really a person or an animal and is instead a picture being projected in perfect and elaborate lockstep to everything else already going on.

    The game kinda resembles a digital layer cake of geometric planes. For our purposes in discussing the NPC challenge, there are three key layers: 

    1. the player layer on top which is little more than a picture (that never actually moves anywhere) of a little dude moving his legs or whatever, 
    2. the room plane on the bottom, which is a grid map to which every square of a matrix of about thirty by thirty is bolted an image of a single floor tiles or a single wall, maybe a single decoration or a single object, or aything else that doesn’t move, essentially a thousand times over to form a literal gridded map that comes together to make the picture of what looks like a furnished room, and 
    3. an NPC plane upon which the in-game life-forms persist through time and are continually moved  from square to square like upon an invisible chess board, revealed when they are in the same room as the player or hidden when not.  

    When the player moves anywhere—around the geometry of a room or through a door to another room—both the room plane and the NPC plane shift around on the screen.  It’s as if—to go back to the chess analogy—you were holding your player piece still in your hand just barely above the board and someone was shifting the board around under your piece.  And then you held your piece in the air while they swapped everything out for a new board from another game, over and over, every time you made your move in one game, swapping to the next board, for thirty five different boards. 

    Convoluted, huh? 

    It really kinda is, and so you see the challenge I faced.

    how does this all work, really tho?

    Like everything, though, I worked through this incrementally.:

    Can I spawn that middle layer? Yup.

    Now, can I spawn an NPC sprite onto that middle layer independent of the other two layers? Ok, that works, but it doesn’t move relative to the player.

    Okay, so can I make my NPC sprite seem to stand in one spot in the room? Yes. I lock the coordinate geometry of the NPC plane to the plane of the room.

    Next I need to make it move around realistically relative to the room, so can I do that? Well, I add a coordinate path vector and loop through that moving the NPC around on its own plane while tracking its progress along the track.

    Okay, can I do that with more than one NPC in different rooms? Sure. Add a conditional loop to spawn a second NPC linked to a different room id.

    Oops, now both NPCs appear in both rooms, each following their own path, can I fix that? Of course. I trigger a check and change in visiblity when whenever the player moves rooms. 

    Great, but now how do I interact with my new NPCs? Um. One more system to check if the player and the NPC “collide” geometrically in game plane maths and then pass that state along to the rest of the game to await further instruction.

    Yikes. It works.

    The result of all this is a complex—but actually robustly elegant-ish—tool that lets me spawn as many NPCs as I may need in the game simply by adding new “data” to a file with some simple starting and trigger variables. I even tested having 250 spiders walking around one room just to check and it seemed pretty solid.

    The whole process of building this game has been something like this. 

    Ask a question, then increment through the solution until something works, then refine until it works well. Then move onto the next question.

    Game design, huh?

  • frugally forwards

    The pursuit of phase Paranormal Pickle continues as I round off another development milestone this evening and creep closer to something that is actually, really, starting to look like a game.

    I will preface all of this with a bit of an anecdote on digital frugality.

    In this era of the robust availability of processing capacity it is easy to find people discussing frame rates and generous graphical outputs derived from access to huge quantities of processing power. The advantage to using a game engine is that I can work under the assumption that the people who built both Rust and Bevy have considered things like memory management and processing pipelines so that I don’t need to think too much about either.

    I mean, a little bit. I need to think about it some.

    But I was overthinking it and as I develop this game which has a very retro architecture and two-dimensional 8-bit vibe, I may have been leaning into those thoughts a little too agressively. 

    I found myself doing some back-of-a-napkin calculations about what a very conservative number of simultaneous processes and active game systems might be. Then I searched for something similar, looking for confirmation of my math maybe. And then I outright asked an AI bot what a modest number of live processes and spawned objects and active systems might be for a game written in Bevy and Rust.

    See, I had opened up my inspector tool and having spawned these generous tile-based rooms and layered those rooms with decorative objects and then animated those objects and then added collision to a bunch of those objects and then added a bunch more UI objects on top of that and all that was just to show the world and not actually calculate the game mechanics itself, I had come up with a number that to me looked daunting. At any given time, it turns out, I had somewhere between 1500 and 2000 spawned objects and systems.

    To be clear each of those systems might be very, very small. Displaying a 64×64 pixel sprite at position X,Y on the screen. Doing a simple geometric calculation. Incrementing a number in a counter. Saving something to the database. All small, but add them all up and you have (a) a game and (b) a lot of systems that run in a continual loop about a couple hundred times per second each.

    So how many are too many? I mean, I keep adding stuff and hoping that the game doesn’t suddenly drop to three frames per second because I’ve hit some limit.

    Well, the answer I got back from my back-of the napkin calculations suggested that I could probably run the game at 120 fps if I kept that spawned number under 25,000. 

    If I got up to 100,000 I was going to start noticing it eating up the processor, and if I happened to hit a million I may want to consider doing some optimization.

    The internet, AI, and everything else vaguely confirmed this.

    So, to be clear, even at my biggest, sprite-filled, action-packed room state, I was running at about 8% of my most conservative everything-is-humming-along estimate.  I mean, the proof is in the pudding, but the moral of this story is that I can probably stop being so digitally frugal and add a bit more life to the game.

    Which is exactly what I’ve been doing.

    I wrote a whole post on building my menu system (which to run compared to the game-proper processing power requirements is like comparing a pedal bike to a Harley motorcycle) so I won’t go into detail on that here.

    But I have also been doing a lot of design work. This phase was about furnishing and decorating and I’ve added a whole couple of categories for Things That Appear on the Screen (TM) like simple A/B state decorative objects  and this thing I’ve called lively decorations which are actively animated as part of the universe (slurping up some of that spare processing power, of course.) 

    In the background and to facilitate all these things I’ve had to implement and polish up a bunch of actual game systems, too. I mean, I wrote already about the game state stuff which facilitates the switching around between menus and the game, but I also added a clock to the game. The clock, of course, has a game built in, but it doesn’t specifically track anything besides a kind of this-app-has-been-running-for-this-long seconds counter. I added a clock in the sense that the game now tracks a 24-hour game cycle of days, hours and minutes. And not only does that time clock save routinely as part of the game state database save file, but it now makes the game feel like time is actually passing. You can open the menu and it now says something like “it’s 8:43 on day 2” of the game—which having a time clock might be important to things like having a store with open hours.  My kid asked me if I was going to make it so you need to sleep (a’la Stardew Valley, which I admit is a bit of a back-of-mind influence on a few of my design choices) and this is starting to make more and more sense, particularly if I will need to have a bunch of “nightly” calculations happen to my grocery inventory.

    So as you can see, things are taking some real shape here and chugging along a game is almost, kinda, sorta appearing. That feels real nice.

  • error, error on the wall

    I reached an interesting point in the development cycle that necessitated that I learn more about the root of the application.

    If that sounds a little sketchy for a programmer to, you know, not fully grasp the intracacies of the main() loop of the software, keep in mind that for most every simple program the main loop is simple, too. And even for a Bevy application, most every simple app you can build in that game library (or importantly for this anecdote, every online code sample) follows the same basic and simple structure: add a system to initiate, then start up, then update and run.

    And while up until now I have been building a pretty complex little game, the system upon which it runs has been very simple: Launch the game and the game launches. 

    Except, that’s not how games usually work. 

    You usually launch the game and at the very least a title card appears, and then often a main menu. The main menu is, of course, the important part.  And in game design speak, the main menu isn’t part of the game-proper, but a kind of pre-launch state.

    And similarly, another task I had set for this milestone was building an in-game menu.  Both of these things are part of the capital-G Game, but they are not part of the game, if you follow.

    In other words, I had to learn about game states, and the whole complexity in my main.rs file of conditionally running bits of the application depending on a game state. 

    And all this started off okay, too. I found some code samples, and dug through the API docs, and started building. And then? Then, well, I added a function to trigger the game state to switch to the menu state and put it into my game loop.  That’s to say, there are a bunch of little functions that are run over and over and over again, updating the graphics, checking the keyboard for input, monitoring the location of the character on the screen, etc, etc, and I needed to add another one that would check to see if the key that opens the menu had been pressed (and if so switch that game state over to the menu mode).

    After everything I’d built it was a simple little keyboard check, except when I ran the application I got a strange error:

    trait bounds were not satisfied
    
    rust error E0599

    Okay.

    I searched online. I dug through the API for the input commands I was using. I even asked ChatGPT for some ideas about why I might get that error from the very simple code snippet that I showed it.

    No help anywhere.

    Now to be clear, this little game I have been making is starting to get very complex. Lots of moving parts. Lots of systems that run sequentially or simultaenously or (now) conditionally.  And the game loop consists of a long list of check_this, animate_that, move_littledudearoundthescreen-type systems.

    I spent two hours digging and prodding and simplifying my new function. 

    No use.

    Then I tried putting in some code that I knew worked from another function, I mean, not just adding but completely replacing that new fn call temporarily with a different function’s guts.

    Nothing.

    And then I did something that any good debugger worth his salt should probably do: I started methodically flipping switches until the problem disappeared. And—well, that’s the odd part. The first switch I flipped, that is to say, the first thing I turned off—which happened to be an animation function—fixed the whole damn thing.

    It just suddenly worked—well, except for that animation function.

    Was something wrong with the animation function?

    I tried flipping the animation back on and then flipping something else off in it’s place, just to see.

    Now? Now the animation was working but the picker highlights were off and yet it still all (minus the picker highlights) worked without that error.

    So, naturally, I turned everything back on and—Error.

    Look. I had a hunch. There had been something I was suspicious about and yet no matter where I looked (or what AI bots I asked) I always got the same answer:

    How many systems can I add to an Update’s parameters. —I would ask or search or troll through message boards seeking a clue about.

    There is theoretically no limit.” —was always the answer.

    Except. And here is the suspicious thing—remember how I mentioned that my app was (up until now) pretty simplistic? Yeah. So, when I say simplistic what I’m really saying is that I had neither organized nor really done any management of my function groupings.  In fact, prior to adding that function that broke everything, my .add_system(Update… parameters for my game loop had exactly twenty functions being called from it. 

    My menucheck was number 21. 

    I spent a solid forty-five minutes breaking things up into categories and smaller chunks.  Add the room systems. Add the animation systems. Add the input monitoring systems. Five systems in one, eight in another, and so on, and so on, until there were those same twenty one orignal systems that had broken my original scheme but now organized into four separate Update calls.

    And?

    Well, I wouldn’t be writing a blog post about it if it hadn’t worked, now would I? I don’t know for sure if there is a function limit specifically or maybe if there is a character limit for the parameters, or if I tripped over some other invisible fence but whatever it was I seemingly had breached it and caused an error.  

    If you have come here to read a programming anecdote, that’s it. That’s how this works. That’s how a guy can bang his head on his desk for four hours on a Sunday afternoon trying to puzzle out something simple and yet completely unobvious, something that no one thought to document because programmers with more experience, maybe, would naturally organize things a bit more meticulously.

    Or, if you have come here because you are searching for a solution to that same problem and because I have helpfully copied the error messages and codes verbatim into the text to assist you with you own struggles, then cool. I hope this helps. And then drop a little love and check out my game.