Write Up 04



























Press Escape to quit the application.


Assignment04 brought with it the task of moving all of the previous sprite and effect objects from Graphics.cpp into the Example game project. I had a lot of fun figuring out how to move things around.


The following is code from the interface that was implemented to clear the screen with a different color:

//User specify's the background clear color



The following code shows how the user submits a sprite and its effect:


//Render the sprite pairs





The sprites and effects are pointers at first that then call the factory function to be created in memory. This occurs in the Initialize() function of the ExampleGame.cpp file. All the sprite pointers and effect pointers are member variables of ExampleGame.


Another important objective of this assignment was to make use of threads to handle application data and render data separately. The sprite and effect data has to be cached in the application thread originally to then be swapped with the render data to be rendered in Graphics.cpp’s RenderFrame() function. This is to run both processes in parallel so that the application thread can work on its data while the render thread does the same with its data. Caching the data allows both threads to have references to the data so that there is no risk of it going away between the time that it is requested and when it is received by the thread. Swapping the data between both threads ensures they both run independently for as long as possible.


The code above passes the sprite pointer and effect pointer to two vectors located in the sDataRequiredToRenderAFrame struct. A for loop adds the sprite pointer and effect pointer the amount of times the pair is instructed to be drawn. This is specified by the third parameter.


A sprite takes up 12 bytes of memory on x86 and 24 bytes of memory on x64.


An effect takes up 16 bytes of memory on x86 and 48 bytes of memory on x64.

To make the effect smaller, I would make its member variables pointers and place the render state pointer first since it is the largest of the three and it’s alignment in memory needs to be a multiple of its size.


To make the sprite smaller, I would make all its member variables pointers and place the ones that occupy the most memory first and then the ones that occupy the least memory.

The time it took me to complete this assignment was 10 hours.