Game Engineering II Assignment 4
Last week. We discussed about multi-threading and how to pass data between threads. Usually, we use thread lock to prevent data conflict, but Tony said it is too much for this assignment. Instead, we use buffers to pass data from the game application thread to the graphic thread. Also, we are using reference counters to track our meshes and effects.
Now, the game application and graphic engine run in different threads, which will likely cause data conflict or mismatch when using the same variables. It usually causes unexpected and hard-to-chase problems. Why does using two buffers solve this problem? The first buffer, "s_dataBeingRenderedByRenderThread," contains things that have already been stabled and are ready to be rendered. The second buffer, "s_dataBeingSubmittedByApplicationThread," includes variables submitted by the game application, and it is free to be changed by the application at any time. At the beginning of the render function, we swap the two buffers so data in the s_dataBeingSubmittedByApplicationThread will be stable and stored in the s_dataBeingRenderedByRenderThread, waiting for render. We clean the s_dataBeingRenderedByRenderThread at the end of every render loop so that it won't cause any memory leaks.
The size of the cMesh is 36 bytes in OpenGL and is 56 bytes in D3D. It is bigger than the last assignment because we added a reference counter. However, I removed the mesh file path from the class and let it pass to the Initialization function. It is easy to make this bigger because you can store unnecessary things like pointers to buffers. We can move some member variables like m_vertexArray to a struct and keep a pointer to the struct in the cMesh, decreasing the size of cMesh. But those data still occupy memory so it won't make a big difference.
The size of the cEffect is 16 bytes in OpenGL and 56 bytes in D3D. The reason remains the same as the previous assignment. The answer to "Is there any way that you could make it smaller?" is the same as the cMesh. We can't make these member variables disappear from the program because they are necessary.
The total memory you have budgeted for my Graphics project for data to render frames is 16 bytes. This number doesn't include the size of the array of sEffectMeshPair because it will change by how many objects we will render. If we use two objects in the scene, that will take 68 bytes in OpenGL and 144 bytes in D3D, and so on.
Controls:
Press Enter to slow the time by 66% and release it to return to the normal rate. Press ESC to exit the game. Press E to switch the objects.
Click here to download the game.
Oscar Zuo
U1418006