A downloadable game

About the Assignment

This assignment is about figuring a way to submit and cache data needed to render a frame and also making the application respond to user input. There are two threads running in the application, we’ve to make sure that the data is getting read and written to the correct thread data.

Screenshots


Default state with blue background

 

 Two objects with unique effects

   One of the object not being drawn (On Input Space)

 


Two objects with the same effect (On Input Left Control)

 

 

How I finished the assignment

I started off by moving the effect and object data to the Application(cMyGame.cpp) from the Engine(Graphics.cpp). Once I got that running, I made the Object and Effect classes reference counted. It took me a while to understand that the incrementing and decrementing of the reference count has to be done explicitly. I ran into some cleanup errors but eventually figured out by decrementing the reference count at the end of the render frame and for each and every object and effect. Then I tried submitting the background color, this again was straightforward once I read the corresponding section in the Assignment details. Final part of the assignment was to respond based on User input, this was pretty straightforward after looking at the code for exiting the game.

Why we have to submit the data the way we do to render a frame?

We’ve to cache the data needed to render a frame because the two threads running at the same time might override the data if it is not cached. The Application thread might write something to the data that is being used by the render thread.

Here is the code that submits the Background color and object effect pair


First I store the object effect pair in a array called s_cachedObjectEffectPairs based on the input received.I populate the underlying effect and object pointers of an ObjectEffectPair to the data I chose.


And then when the data is ready to be submitted i.e., when SubmitDataToBeRendered is called I use the s_cachedObjectEffectPairs array to submit the object effect pair to the Graphics. Background color is directly sent from the SubmitDataToBeRendered function.


This is how my ObjectEffectPair struct looks like


 

Size of my 3D object representation is 24 Bytes in Direct3D and 16 Bytes in OpenGL. My Object data looks like below


I couldn’t think of any way to make it any less because it’s the least amount of data that needs to be saved. I could make it more by reordering the variables in such a way that the 2 uint16_t’s won’t be sequential.

Size of my Effect representation is 16 Bytes in Direct3D and 20 Bytes in OpenGL. I couldn’t think of any way to make it more or less. Below is the representation of my Effect


My struct that stores the data required to render a frame looks like this. It has a size of 200 bytes. Each objectEffectPair has two pointers one to the object and one to the effect, that’s a total of 16 bytes. I don’t think I need to consider the actual size of the object or effect cause we’re not storing that data. Along with this there are two pointers that point to this struct data.


Download

Download
Download Zip 167 kB

Leave a comment

Log in with itch.io to leave a comment.