Jan 12, 2017

Development Snapshot 16

The main issue I ran into this snapshot was inflexibility of old code. I ended up having to revisit alot of code that is over 3 years old. That code was unable to be extended without introducing a horrific mess, so I took the high road and invested some time refactoring those ugly parts. This cost me some time, but the end result was worth it.

The majority of work this time was in the graphics area. I overhauled the look of the UI somewhat, replacing the WindowsXP-like windows with something a little bit more modern (in my opinion). I also rewrote a large section of my render loop in an effort to reduce frequent state changes. Instead of just blasting out draw calls, switching shaders and such on the fly, I now enqueue render jobs that are sorted to minimise changes where possible.

Skinning System


This was the major piece of work this snapshot. The first task was creating a rigged model in Blender.  I took my existing quick and dirty model and threw together a simple bone structure (after I watched a few blender tutorials). This fell together quicker than I anticipated, which perfectly set me up for bitter disappointment when I failed at the next few hurdles....

Next was modifying my collada importer to support bones. My previous implementation was done strangely to say the least. Looking at the code again after several years, I drastically rewrote it to be more flexible, and added the bone/joint data parsing as well. I lost a bit of time debugging why all the transform matrices had no translation component before I finally realised that collada matrices are Column-Major and I was assuming Row-Major. Once I got that fixed, the matrices looked right.

Then I had to rewrite my model class to handle the fact that there will be joints pushing and pulling the vertices all over the place, instead of being static. My previous incarnation of my model class was a hastily slapped together mess that came out of an attempt to get the code working again after one of my aggressive refactoring efforts over the years. I treated it as such and gutted it, also making it work nicely with my new render job system.

I then added in the vertex blending code. To aid debugging other parts of the skinning chain, I decided to implement software tranformation of the vertices, rather than use the vertex shader at this stage. (It's much easier to inspect values if they are in the CPU vs the GPU). The only bit of excitement here was initially my bone indices were off by 1, leading to the following image:

That sweet looking cape is actually his mangled torso.

After fixing that I decided that visualising the bones and joints would make it much easier to debug the vertex blending. I got really messed up by this. No matter what I did, the bones wouldn't render right when moved. I got the joints rendering correctly in their bind pose, but anything else and it would stretch at a weird angle. It took me several days of hair pulling, but the problem turned out to be the order of some matrix multiplications.

I knew I needed to multiply the joint's bind-pose Transform Matrix (BPTM) by the desired transform (Y), (in this case, a simple rotation), but whatever order I used, eg:  Y x BPTM or BPTM x Y, the end result was not right. Then it suddenly occurred to me that the bind-pose transform matrix is actually composed of a rotation and translation, and there was a 3rd place I hadn't tried putting the Transform multiply... in between! So I decomposed BPTM into R x T and put Y in the middle : R x Y x T, and holy crap... Success!

At this point I realised the next step of creating an animation system was going to have to wait until the next snapshot, which was disappointing.  On the plus side, the model's vertices are being transformed as per the skinning equation, and is rendering correctly, which I'm pretty pleased with.


Waypoints


To close out the snapshot I also overhauled the look of the player's waypoints. I'm not completely happy with the look yet, but its a great improvement over the temp graphics that I've had in there for several years now. It also forced me break down the paths into runs of straights and turns, which will be required for smooth walking animations later on.

Original style waypoints


New style waypoints


Next Snapshot


For Snapshot 17, the animation system is high on the list. There's quite a few sub-tasks to tackle though, so I'm not sure if I'll get through them all. The toughest stuff should be behind me, but I'll see what happens.

Dec 22, 2016

Development Snapshot 15

In this latest snapshot my main focus was on further survival-related mechanics, such as food and water borne illness, as well as typical game functionality such as loading and saving the game. The snapshot took a bit longer than anticipated, as I also did a complete refactor on my user input system, which ended up creating some nasty bugs.

The end result is much cleaner and is not bound to the keyboard or mouse devices directly anymore, meaning I can inject faked keyboard or mouse events really easily, which is great for testing.

Food and Water-borne Illness


The main survival mechanic I implemented this time is Food and Water-borne illnesses. Basically, if you don't cook meat before eating or decide to drink from a random puddle you'll probably become sick. The consequences could be dire as this type of illness lasts several hours and during that time your food and water usage rates are increased.

Not quite sure about the wording at this stage.

I've also introduced the ability for effects to debuff the maximum value of stats. This makes for some interesting consequences. Starvation now reduces your maximum health by 20%, and dehydration reduces it by 40%. These two effects can combine (for a net loss of 60%), making you more likely to be killed by pretty much everything.

I like the nuance of the maximum value reduction because it enforces an immediate penalty eg: loss of health when the current value is clamped to the new maximum. For example, Food Poisoning lowers your maximum food by 50%, meaning you'll get the "hungry" debuff. Since your max food was lowered you cannot eat food to remove the debuff. You'll have to wait for the food poisoning to wear off. In this fashion, debuffs can trigger other debuffs causing an escalation of problems.

Another significant change to game mechanics is that health no longer regenerates passively all the time. Health regen now only occurs while you are sleep, which gives a further reason for players to not avoid it for too long.

With these changes in mind, I've grown to dislike the energy stat again. I think I've added and removed it 2 or 3 times since I started the project, and I've convinced myself to get rid of it for good. The Energy stat's role in the player character's economy was mainly to force the player to rest or sleep periodically, and ensure they can't work non stop for hours without consequences. Penalising this behaviour can now be achieved in different ways, so its largely unnecessary.

I'm planning to introduce another stat in the future that model's the player's need for shelter in a survival situation. This stat is related to surviving in cold or very hot conditions. More to come on that in the future.

Save/Load


Saving turned out to be pretty easy. I'd already written most of that code previously when I overhauled my serialisation system a little while back. However, it seems I'd only half-finished the loading code as it turned out to be full of bugs and took quite some time to get under control. But now it is possible to save and load the game state. Hurray!

The game currently works in a partial client/server configuration. Eventually the server will be used by the client for all game logic, but at present it's just responsible for generating the world and then going to sleep. The client then takes over and does all the simulation. The save gamestate code should be run against the server, but it doesn't have the latest information as entity updates are not yet flowing back to the server (perhaps in a future snapshot). So for now the save code runs against the client gamestate.

In theory, having access to save/load should also help debugging, as I don't have to start from a blank canvas every time I want to start up the game.

Onwards to Snapshot 16!


Snapshot 16 is going to feature some graphical overhauls to the game. The most significant of which is starting work on a skeletal animation system, so our poor protagonist can finally put his arms down and walk like a human. 

I'm very excited about this, as it's long overdue. I started building the basics of this a few years ago but abandoned it and moved on to more interesting things. In fact, there are several partially implemented bone/animation related classes tucked away in the source code that haven't been used for several years. I suspect I'll end up throwing most of it away to be honest.

Another upgrade is making the waypoint system work a bit nicer. The main problem is that it only ever displays the waypoints after its done a full plot of the path using A*. So if you decide to change direction midway through a tile movement it can be up to a second before it clears the existing waypoint path, plots a new one, and then draws the new path in the world. This lag between clicking on a tile and a marker appearing there is disconcerting to the player, and shouldn't be too hard to tweak to feel punchier.

On the survival front, I'm planning to implement poisonous foods such as mushrooms or berries. If the player character has a sufficiently high survival skill they should have no trouble identifying which is safe to eat and which is deadly. 

Nov 19, 2016

Development Snapshot 14

Snapshot 14 (S14) is officially done.

As part of my attempt to get my project back on track I decided to limit the scope of each snapshot. In the past I'd planned for 6-8 week development cyles, which (due to lack of discipline) wound up overrunning and being more like 12+ weeks. This time round I tried to restrict myself to just 2 weeks. I ran into some unexpected hurdles that pushed that time out a bit, but S14 came in at just over 3 weeks. Hurrah!

What did I achieve in Snapshot 14? 


About half the time was spent on refactoring and improving existing code. I've learnt a great deal about writing better code in the last year, and there's plenty of poorly thought out design in my codebase. This is a legacy of the fact that I'm a much better developer now than when I started the project 6 years ago.

I made good on my promise to start building parts of the system which are essential for the game to be releasable. Eg: the ability for the player to die.

(work in progress)

Starvation and Dehydration are now actual threats in the game. The way it works is as follows:  Living creatures have health, food and water stats. Creatures will be able to consume food or drink that will instantly affect their food or water levels, but health can only be regenerated naturally.

The player's health, water and food display

While alive, creatures consume food and water. These rates are dependant on factors such as the activity level of the creature and the ambient temperature. Once the creature runs out of one of the resources, the amount consumed (plus a penalty) is instead taken from the creature's health.

I'm still tuning the rate at which it occurs, but for a player at full health its something like 2 days without water or 5 days without food before death occurs. Obviously if you're already injured and you're out of both food and water it's going to be considerably shorter.

I'm hoping to make the game less about combat and more about other interactions, such as exploration, negotiation, stealth etc. Since you can't instantly regenerate health, the way players approach combat will need to be more tactical. eg: Taking an enemy by surprise and knowing when to retreat. In addition, NPC's will be less likely to resort to deadly violence unless desperate as they value their lives and the lives of their families.

What's in store for Snapshot 15?


Next I'm going to expand the eating and drinking system to include food and water borne illnesses, such as eating uncooked meat or drinking contaminated water. Also on the agenda will be the ability to save and load the game. Most of the code is already in place to serialise and deserialise the gamestate, however its not being persisted to disk yet.

It's not a huge amount of effort, which is probably why I've put it off, but its essential for Release Ready status.  As previously stated my plan is to drag the game up to a point where I can start making test builds publicly available. Its quite a way off, but at least I'm now heading in that direction!

Nov 7, 2016

Basic Survival

So, as previously mentioned I've spent the last few weeks refactoring my codebase to remove ugly static references. I also improved the design of a few important modules, and overall I think the results are very positive. There's still a bit of work to do in this area, but the parts involved I've planned to completely rewrite in the future anyway, so I'm comfortable leaving some ugly code in there for the short to medium term. Note to future Chris: hahahahaha suck it!

What's next? Addressing the lack of focus on the important elements of a survival game. For example, being able to die. In the early game there are 3 big threats to survival ; Lack of shelter, lack of water and lack of food.

Shelter


The most critical factor is shelter. Humans can survive several days without water and a week without food, but extremes of temperature can kill you in hours. Staying cool in the heat and warm and dry in the cold will be vitally important if you expect to survive.

The easiest way to shelter from the elements will be to find a natural cave or a ruined building. In some cases you may have to clear out its existing inhabitants first. If such a shelter is not available, the player may have to construct something.

The simplest structures the player can build will be little more than a few strategically arranged tree branches. This will stop light rain and give the player some shade from the sun, but they are fragile and will be easily destroyed by moderate winds. Since they only provide partial protection from the chilling effects of wind, a campfire will be essential for surviving the night.

Once the player gains access to better materials and tools they will be able to build more permanent structures such as huts that will also keep in warmth and provide protection from other threats such as wild animals.

Clothing will also influence your ability to stay warm. Being caught in the rain or falling into water is a nuisance when you live in suburbia and can pop home to change your clothing, but in a survival situation it can be fatal. Better find somewhere to get out of the rain and get a campfire lit before the chilling effects sap your strength.

Water


Lack of water is the next most critical survival factor. Depending on the weather and exertion levels, humans need somewhere between 2 and 5 litres of water a day. Once the player has a shelter sorted out, finding (and maintaining) a source of fresh water will be the player's most pressing daily need.

In the early game the player may be scavenging water from whatever sources they can. If the player is lucky it will be a freely flowing river. If not, it may be a stagnant muddy pool with any number of pathogens lurking within.

Recognising if a source of water is safe to drink will be a vital skill. Contracting a water borne illness will only accelerate your dehydration and leave you vulnerable to other afflictions. The safest option will be to boil your drinking water, but this may not be possible if the player can't find a suitable container or a way to start a fire.

Food


Food is the final factor. There is less urgency to this one, but it cannot be ignored completely. There will be many food sources available to the player depending on their skill level. In the early game it will be edible plants and less palatable options such as insects. This will only get the player so far though. If the player wants to survive long term, fishing, hunting and trapping will provide improved sources of food if the player has the necessary skills and equipment.

As with water, food borne illness will be constant threat, so avoid spoiled food and cook things prior to eating.

Final Thoughts


In reality if you're in trouble you'll probably die from a combination of these factors.

Without food you may lack the energy to build a shelter. Without shelter your hands may become numb with cold and you're unable to start a fire. Without fire you shiver through the cold night and are unable to boil your drinking water before consumption.

Your thirst has been quenched, but you're exhausted from lack of food. You're approaching the beginnings of hypothermia and you've just started having stomch cramps, nausea, vomiting and dizziness.

Sometimes life is cruel.