Seventh Week
Project Introduction
This week, I started optimizing the code for branchless programming as much as possible. I tried three different ways including Type erasure, unreal scene component, and function pointer array. In the end, I choose to use the Array of function pointer to solve the problem.
Type Erasure
The first approach I tried is using type erasure, which is a way to bind multiple unrelated types behind a single non-templated class. I spent several hours studying the type erasure topic and tried to implement it in Unreal C++. But I got several errors that involve several problems including Unreal USTRUCT cannot be inside of the USTRUCT and the unique pointer cannot be a UPROPERTY. It also crashed in the engine even after the code compile. After several hours of trying, I tried to approach a different solution.
Unreal Scene Component
I started to research some probability inside of Unreal functions. And I notice they have a components system that can let users assign to any actor and do the corresponding behavior the component code does. I successfully built a component derived from the scene component which you can spawn any actor from it. And I think it will be a cool way to spawn different cameras too.
However it causes a new problem since it only spawns the camera after play, so the user cannot see any behavior in the editor.
Array of Function pointers
Since the virtual camera has the enum of which mode they were on, so to avoid using switch statements, building array of function pointers might be a good way. I built three different array which includes: Construction for a look at, and Updates for look at and Aiming. Each array will have the accordingly order of function pointers as the enum index.
After the implementation, We only need to call the function from the function array without any addition switch checking.
To solve this problem, I spent lots of time researching a possible solution. And since Unreal C++ is quite different from traditional C++, I meet lots of errors while trying to implement a simple example of a concept.
I also tried to rebuild the camera shake at the beginning of the week, but since the camera shake control by camera manager which associate player. However, having a player link up with the camera is not the intention of the virtual camera. So I move the camera shake task after the cinemachine brain and I hope I can hook up the camera manager with cinemachine brain.
More thoughts
There's another way to solve this problem which is to make an interface for the camera and make multiple camera child classes derived from it. I haven't tried this one cause it will involve lots of time in refactoring the code but it will be a good way to solve this problem too.
Next Week Plan
After refactoring the code, I'm going to work on the Cinemachine brain and start to build the first function - Priotiry function of the brain.
Aryna Ou