Monday, December 21, 2020

A New PC And New Game Features

 A New PC

It has been quite a while since I posted an update on Survive And Thrive.  The game is progressing well, but I had to do a pause in order to take care of something that comes around about every eight to ten years for me.  I had reached the point where it was time to build a new PC!  This one was my fourth build.  I decided November was a good time to do it seeing how holiday sales were abundant.  I had determined to wait until Black Friday to ensure I was getting the best deals for the components.  That didn't happen though.

I started as I usually do by establishing a price target for this build.  When it comes to computers,  I have to set myself a price target, especially when building one.  There is always a cheaper option and there is always a more expensive one.  If I do not set a target, I will spend forever talking myself up to the next level for each component until the build is out of reach.  I have found over the years that a $2000 build is going to get me to that sweet spot in the technology curve where price and performance become balanced enough to take me forward another 8 to 10 years.  This one came in a little above that number but not by much.

A build requires the following components.  A case, a power supply, a motherboard, a processor, heat sink, memory modules, hard drives, an optical drive, a video monitor or two, and now more than ever, a video card.  Of course, an operating system is also needed.  I opted to keep using my existing keyboard and mouse.  The keyboard is a Logitech G710+ mechanical and I just love it!  A mouse is a mouse and ironically, mine died about three weeks after I finished the build.  In case you are interested, here is what I ended up with:

Case:  Antec Dark Phantom DP502 FLUX Mid Tower

Power Supply:  EVGA SuperNOVA 850 GA 80 Plus GOLD modular

Motherboard:  MSI MEG X570 UNIFY AM4 AMD

Processor: AMD Ryzen 7 3800XT 8-core, 16-thread Unlocked 4.38 Ghz.

Processor Heat Sink:  Noctua NH-U12S SE-AM4

Memory:  Corsair Vengeance RGB Pro 32GB 288 pin DDR4 3200

Hard Drives:  Samsung 970 EVO Plus SSD 1tb M.2 NVMe (primary), Samsung 970 EVO SSD 500gb  M.2 NVMe (development), Samsung 860 EVO SSD 1tb (gaming), Seagate ST3100 standard 1tb (archive) for 3.5tb total storage.  I pulled the latter two older drives from my old machine, which were not part of the build price.  I also dropped an optical drive into the build for OS install and also to provide capability to install older software.

Monitor:  GIGABYTE G27Q 27" 144hz 1440P IPS panel.  I also borrowed one of my existing monitors to use as a second.

Video Card:  MSI GeForce GTX 1660 TI PCI Express 3.0 GDDR6 6gig

Operating System:  Windows 10 Pro 64-bit

I had these all picked out and ready to purchase once I noticed them go on sale.  However, as I mentioned above, I had to modify my purchase strategy a bit.  A few weeks before Black Friday, things started to disappear from NewEgg and Amazon!  Some of the components went out of stock and others were backordered.  As I watched each day, I decided it was better to get what I wanted than to wait for a sale and have them snatched up from me.  Once they were back in stock, I did not hesitate to go ahead and get them.

Over the course of two weeks I was able to purchase all the components. I finished the build just before Thanksgiving.  I expect this new machine to carry me for the next 8-10 years.  The only part that I typically have to upgrade is the video card during the life of the PC.  I expect this one to be no different.  Once I had completed the new build and migrated my data over from the old PC, it was back to work on the game.

Game Time Simulation

I wrote a rudimentary day and night cycle quite a while back.  The Main Camera has a game object with a Light 2D (Experimental) Global light type component attached to it.  The only other light in my sandbox scene is one attached to the player prefab.  I fondly called it the Newbie Light since I plan to disable it at a certain difficulty level and/or after a certain amount of play time.  This is a survival game after-all.  It is also a Light 2D (Experimental) light but it is a Point light.

I had several goals for a Game Time Simulation (GTS).  Many survival games use the concept of survival days rather than a typical calendar approach.  This decision is subject to change, but for now I want to do the same.  Simple enough, the game begins on Day 1.  Another goal was being able to control the game speed during certain events.  For example, sleeping will occur at an advanced rate.  Crafting items will also cause the game time to advance at a much faster rate.  The GTS can be set to one of fifteen speeds.  A setting of 1 will progress the game clock at the normal rate and 15 will speed up that rate 15X when necessary.  Different events will advance the clock at different rates.  Another configurable option for a custom game will be to select sunrise and sunset times.  The defaults for a standard game are sunset beginning at 6PM and sunrise at 6AM.

I wanted the clock to be presented as a simple string value in the game UI without using C# DateTime types.  Seconds are really not shown and I know from my day job as a software engineer that DateTime calculations are costly compared to just building a string value.  It is simple enough to simulate.  The following method takes in the calculated hour and minute values from the GTS with the hours ranging from 0 to 23.  The method returns a nicely formatted 12 hour time string with AM and PM designations.  

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
private string FormatGameTime(int hour, int minute)
{
	if (hour == 0)
		return $"{hour + 12}:{minute:00} AM";
	else if (hour < 12)
		return $"{hour}:{minute:00} AM";
	else if(hour == 12)
		return $"{hour}:{minute:00} PM";
	else
		return $"{hour - 12}:{minute:00} PM";
}

Since the GTS is built on the 24 hour variation by default, building that string is a single line of code.

1
DateTimeDisplay.text = $"Day: {day} Time: {hour:00}:{minute:00}";

Day-Night Cycle

The GTS gave some sense of purpose to my existing day and night cycle once I had completed refactoring to accommodate the clock display. The sunrise and sunset events at this stage only involve incrementally adjusting the sun light's intensity along with the Newbie light's intensity in a smooth transition from one light source to the other.  During testing, I discovered that activating and deactivating the 2D light sources in the scene after they reached their polar intensities caused major issues with the game's framerate.  It was so different that daytime clock ticks were visibly slower than nighttime.  At first I did not know why.  After some time working through this, I was able to realize a stabilized framerate by simply leaving both lights set to active but adjusting the intensity to 0f to simulate turning off rather than actually setting them to disable.  I never realized how much lighting impacts a scene!  I know it is lighting because unchecking the object in the scene is the only thing necessary to produce the issue. Plus, I have reference objects on the script, so my code is not doing any kind of tag searching to locate them.  In fact, to date, I believe I have not used a single GameObject.FindGameObjectsWithTag method.  Searching thousands of objects in the scene is  not to be considered a best-practice in my book.

Tree Shadows

With light sources changing, I thought it would be appropriate to introduce some shadows.  Survive And Thrive is mostly a 2D, orthographic, oblique-perspective game, but I wanted to explore some ways to alter that perspective just a little to add a sense of one more dimension.  Swapping z-axis values on the player and the tree on the player's tile is one way to present a less flat game world and allows the player to walk in front and behind trees.  Another is the use of shadows.  While digging around Unity's API, I discovered the URP 2D lighting system comes with a component that somewhat simulates shadows.  It is called the Shadow Caster 2D (Experimental) component.  I decided to experiment with it.  

Shadow Caster 2D (Experimental)

Please excuse the baked shadows of this tree.  If you have been reading along, you know I took photos of real trees to use for the game trees.  I didn't bother removing them. While configuring the shadow Shape (the white square in the image above), it was only necessary to make it the same width as the tree trunk and roughly a square.  It simulates the shadow being cast from the base of the tree in a quite basic way.  The shadows are cast upon the tilemap tiles when the player's Newbie Light gets close.  The shadow stretches opposite the player's position to the tree and into infinity.  I wish it were more like the shape of the tree, but it will have to do for now unless I find the time to write something custom or find a product on the Asset Store that works better.  I will leave you with a screenshot of the night shadows and a sneak-peek at some of the new features I am currently working on.

Tree Shadows

Until next time...

No comments:

Post a Comment

Feel free to leave a comment. All comments are moderated.