C++ Test Review

Just some scattered notes for test review. Object Composition Object memory is stored contiguously. If an object has pointers, those pointers are still stored contiguously but point to wherever the data is. Object Ownership One simple approach is to say that whatever creates the object becomes the owner of the object Thus, it becomes responsible for deleting it Inheritance Polymorphism Zombie* bob = new Zombie("Bob"); Zombie* sally = new ZombieSoldier("Sally", 100); bob->attack(); // prints "Bob throws a punch" sally->attack(); // prints "Sally throws a punch" // wait... // ...............?! Objects have static binding by default in cpp. For dynamic binding, methods must have the virtual keyword. static binding by default does offer better performance. ...

October 16, 2023

Satisfying 2D Movement

I’m in the middle of working on my first mainline c++ project at school. We’re tasked with making a simple vertical spaceship shooter using c++ with SDL and some pre-made assets to form the game. At the moment, I’ve set up most of the classes I will need and have a simple ship that renders onto the screen. Naive Movement My first iteration of ship movement does have some forward thinking but allowing ship movement to continue by holding down keys. Using SDL polling, it’s easy to want to bind movement directly to each game iteration and triggering of the SDL keydown event. The problem is, standard keyboards when held have a delay on the first press before sending keyevents on every frame. What that looks like is the shape making a quick jerk, then pause, then start gliding across the screen. ...

October 13, 2023

Portrait Action Mobile Games

As I was looking for games to play during my bus rides, I realized the convenience of being able to play phone games one-handed, or just simply in portrait mode. It’s a lot more comfortable to hold, especially in tighter environments like a bus. There’s lot’s of options for this but they mostly amount to puzzle games and such. Instead, I wanted something more actiony and rpg-like I could play in that format. Most action games are played in landscape as they tend to require more complex controls that aren’t condusive to the portrait play area. That’s fine and all but I just never was able to fully enjoy action games to that depth on a mobile format. Trying to fit complex inputs onto a touchscreen just isn’t that great of an experience so I tend to avoid playing them. Instead, what I want is an in-depth action, portrait-mode, mobile game with simple controls yet engaging gameplay. A big ask huh? ...

October 11, 2023

C++ A Personal Guide

A compilation of various features and gotchas I’ve encountered while studying C++. Instantiating Object Member Variables When to Use Initializer Lists Intializer lists offer a secondary method of initializer member variables for a class. A question comes up of why would we use this method as opposed to initializing the variables on declaration of just in the constructor. Below are a few core purposes. Initialize Const Members You could initialize these on declaration but what if you we want to pass in their values as arguments to the constructor. Okay, then we can move it to the constructor. Nope, it’s a const variable so it can’t be modified. ...

October 4, 2023

Pianotypes Devlog 5

Not many code changes as of late but I’ve been more active on one of the packages I’m using to play sound, smplr. It’s such an amazing package for playing instrument sounds with an incredibly simple and powerful api. Kudos to danigb. A bunch of new changes were made recently that have added some awesome features as well as some bugs I found while using them. Note Scheduling Throughput The first change was a tweak to note scheduling that fixes an issue of the web audio getting overloaded and introducing lot’s of static. ...

October 1, 2023

Habits and Goals and Gratitude

Having Goals I have goals and I like the fact that I do. It makes me feel like I have purpose, that I have some direction I need to follow. However, it often feels suffocating, demotivating, it makes me feel envious of others, it makes me feel that I’m unaccomplished or that I’m falling behind because of I haven’t done enough. These are the feelings of having goals. But how do you achieve goals. Well you work towards them obviously! It’s always an incremental step towards success and rarely ever an overnight one. Whether it’s career goals, financial goals, or creative goals, it takes work to get there. This brings me to habits. If you want to be an artist they say you gotta draw everyday, if you want to be an engineer, you gotta study the math and science, if want to become a world-class swimmer. Well you go to train and compete constantly. ...

September 28, 2023

Stack and Heap

Declaring Data Structures on the Heap https://stackoverflow.com/questions/8036474/when-vectors-are-allocated-do-they-use-memory-on-the-heap-or-the-stack vector<Type> vect; will allocate the vector, i.e. the header info, on the stack, but the elements on the free store (“heap”). vector<Type> *vect = new vector<Type>; allocates everything on the free store (except vect pointer, which is on the stack). vector<Type*> vect; will allocate the vector on the stack and a bunch of pointers on the free store, but where these point is determined by how you use them (you could point element 0 to the free store and element 1 to the stack, say). ...

September 27, 2023

Useful Linear Algebra

Dot Product Find the interior angle between two vectors $$ A\cdot B = |A||B|cos\theta $$ $$ \theta = \arccos(\dfrac{A\cdot B}{|A||B|}) $$ $$ where\ A\cdot B = A_x \times A_y + B_x \times B_y $$ Cross Product Get perpendicular vector from two vectors Find area created by two vectors (for 2D, parallelogram area, for 3D, parallelepiped area) This is the magnitude of perpendicular vector Matrix Multiplication There is a formula for calculating the resultant matrix from a matrix multiplication. ...

September 25, 2023

Dot Product and How it Relates to Light

What Matters The dot product has a bunch of properties when you use it’s raw scalar output but honestly most of the times you will use the dot product is to find the angle between two vectors by rearranging to equation as follows $$ A\cdot B = |A||B|cos\theta $$ $$ \theta = \arccos(\dfrac{A\cdot B}{|A||B|}) $$ $$ where\ A\cdot B = A_x \times A_y + B_x \times B_y $$ In games, this equation is used exhaustively to calculate light projections and field of view. ...

September 14, 2023

Signed Ints and Two's Complement

Two’s Complement Representation Why We Use It In c++, signed integers are represented in two’s complement notation. Before I get to how that notation works, I want to explain why we use it. Comparing both representations, -1 would look like this // Decimal 4294967295 // Binary Signed Int 10000000000000000000000000000001 // Two's Complement Signed Int 11111111111111111111111111111111 The normal signed binary representation is pretty easily understood if you know what a sign bit is. You just have the typical binary for 1 with the most significant bit being the sign bit to indicate that it’s negative. Then why the heck do we use two’s complement instead? Isn’t it just more confusing? ...

September 12, 2023