Sunday, 10 April 2022

Chapter 23 // Exercise 5 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 5

Find a large email message file (thousands of messages) and then time it as written with a multimap and with multimap replaced by an unordered_multimap. Note that our application does not take advantage of the ordering of the multimap.


This one was interesting. I used my random email generator to create a text file with 5555 emails in it.

Then created 2 functions and timed them as he shows on page 1015.

The multimap took 12.591 seconds.
The unordered multimap took 12.48 seconds. 

Saturday, 9 April 2022

Chapter 23 // Exercise 4 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 4

Find a real email message file (containing real email messages) and modify the email example to extract subject lines from sender names taken as input from the user.


I converted an email from my own account to text (hotmail) and it was very basic with just
From: Name <email>
Sent: DD Month YYYY HH:MM
To: Name <email>
Subject: Subject Message

Message

When a message is forwarded it's exactly the same but Fw: is added after Subject:

So, seeing as how the next exercise needs a text file with thousands of messages I decided to quickly create a "random email generator": 

You can use this to create a text file containing as many email messages as you want for testing.

I then went about changing everything to use wide strings instead so most currency symbols would work. I briefly tried to make emojis work but couldn't be bothered going down that rabbit hole.




Thursday, 7 April 2022

Chapter 23 // Exercise 3 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 3

Modify the email example from section 23.4 to use regular expressions to find the subject and sender.


So for this I used the site Regex101 to help craft the regex I needed:

This site is great as it gives explanations of what each part of the regex is doing and you can step through matches in the debugger.

For the subject, I assumed that we are finding it only in English and based off the email examples in the section. I got a bit annoyed as apparently std::regex doesn't support the very handy lookbehind feature. So I ended up just searching for "Subject:" then creating a string with everything in the message line after those 9 characters.

I then did the same for the sender.


Friday, 18 March 2022

Chapter 23 // Exercise 2 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 2

Add a multimap and have it hold subjects. Let the program take an input string from the keyboard and print out every message with that string as its subject.


2 months after starting this chapter I had almost forgotten everything and this took me longer than expected.

The hard part had already been provided by Bjarne though so it was just a case of creating a new multimap that stores messages and subjects and loops through that instead if there is a match.

Thursday, 3 February 2022

[Dev Log] Generic Slenderman Clone Part 1 // UE5 & Blueprint

The next game on my list for the 12 months of games challenge is a straight up Slenderman clone. Slenderman is without a doubt one of my favourite games of all time due to the simplicity of the premise; you are chased around a forest by an A-Posing faceless man in a suit whilst collecting 8 items. I was always more of a console gamer and so I didn't know anything about the "indie" games scene and then 2013 hit with Slenderman and now I can't go back; indie horror games are my favourite genre.

So to ease myself into UE5 (and remind myself of how the editor works); I decided to make a straight up Slenderman clone. Once I've completed this version, I will then remake it using C++ instead of Blueprint.

In total there are 5 stages to this game, in this first part I'll be:
  1. Creating the "map" and first person mode
  2. Putting notes on the "map"
  3. Displaying the collected notes count
  4. Adding a way to collect notes
  5. Adding "slenderman"
  6. Creating a titlescreen and endscreen
  7. Creating an executable
So there will be a full "game" by the end of this stage (it helps keep me motivated) but when I say "map" I mean the default 3rd person map and "notes" will literally just be textured cubes from the starter content.

1 - Creating the "map" and first person mode
I've just synced UE5 at work and I did the "Your First Hour in UE5" tutorial from the Unreal Learning portal but other than I've not done much. I will say I like the interface upgrade and the darker colours. For this project I'm using the Early Access 2 version.

I started off with the third person project using Blueprint and starter content. My game will be imaginatively called "Default Unrealman".


I cleaned up the scene a bit by removing the text and moved things into folders. 

I added a hacky "line trace" to my character which is simply just a collision box shaped to a rectangle coming off the players face. It's not very efficient but I'm not making Halo so it doesn't really matter.


"True" first person mode is achieved my simply attaching the camera to the head socket and moving it so it's on the head. The rectangle trace is also connected to the head socket. I set the camera to move with the pawn rotation and then set the pawn rotation to use controller yaw; this way the camera doesn't do a 360 spin around the player but moves as the player moves.

2 - Putting Notes on The Map
I created a new blueprint actor for my notes which simply contains a cube with a texture on it from the starter content. The note contains a text variable with what to display on interaction and a collision box, I then placed 8 of them on the map.

3 - Displaying the Collected Notes Count
For this, I needed to override the current game mode. I created a new HUD class called BP_GameHUD. Then created a widget called W_GameHUD. BP_GameHUD contains a reference to W_GameHUD and a function that allows access to this widget.

With that out of the way, I added some text to the Widget and then added the widget to the viewport.


Currently this isn't interactable but it's simple enough to set up getters and setters in the widget to change this text.

4 - Collecting the Notes
This involved adding the usual "Press E to use" text to the screen whenever the player is looking at a note.  I added a new text component to the hud widget and 2 functions to set and stop displaying it.


Then I gave the note blueprint a reference to the hud widget and called these functions using when overlap begins and ends on the collision box. Now when playing the game it appears in the middle of the screen, directly where the player is looking and disappears when the collision stops. 

To "collect" the note, it removes the actor from the game when E key is released and to update the HUD widget, I added an int to BP_GameHUD and a function to increment which then updates the hud widget.



5 - Adding "Slenderman"
My version of slenderman is an A-Posing default unreal man:


UE5 has a couple of new components that you can add to actors called "InterpToMovement" and "RotatingMovement", however I'm going to do it the old old-fashioned way:



This will get replaced with a behaviour tree later on but for now it's fine.


Terrifying.

6 - Creating a Titlescreen and Endscreen
The most involved part of the process...at least there are widgets this time and I can just drag and move them around instead of manually typing in positions. Bless the editor. I hate doing UI stuff.

After much faffing about creating a new game mode for the menu screen and setting input controls for each screen. I finally had a "working" slenderman game....I mean technically it's a game.

7 - Creating an Executable

This was the most different part of the process from using UE4. Turns out I still haven't installed the Windows SDK on my pc; I've had it for almost a year now. The package and cook is in a completely different place as well and documentation links are broken. Very cool Epic.

For future reference, you need to install the specific .NET framework from here:

Then, just when I thought it was building, I needed to disable the Quixel Bridge plug-in due to some random shared pointer being null. I will say though Quixel did fix it back in October, I just haven't updated the Engine...

But eventually I got my application:



It's beautiful. 

It might not look like much but it's basically the bare bones of the game. Make it night time and add a spooky forest and it's pretty much done....OK maybe not completely. The next stage is to add the flashlight and sprint mechanics and make it night time. Then in Stage 3 I'll create the forest.