I'm a gameplay programmer
focused on developing
engaging and unique experiences!

My Resume Learn more

Assignment 09

This assignment had us create binary files out of human-readable files for our effects, mirroring what we did for our meshes. Agan, the result looks no different from last time, but all the effects are now stored in a binary file behind the scenes. Try it out here!

The controls are the same as last time where you can move the camera forward/backward by using the Up/Down Arrows and Left/Right using the Left/Right Arrows. You can also move the cube Up/Down using the W/S keys and Left/Right using the A/D keys.

Effect File

Here's an example of an effect as a human-readable file:

	path_vertexShader = "Shaders/Vertex/standard.shader",
	path_fragmentShader = "Shaders/Fragment/animated.shader",
	AlphaTransparency = true,
	DepthBuffering = true,
	DrawBothTriangleSides = true,

Here's the same effect as a binary file:

Our run-time code knows where the second path begins because we store the length of the first path as a value before the first path. We also store the second path directly after the first path so that we just use that value as an offset to the second path. This trades space for time, which is optimal for run-time performance.

The path I store uses $(GameInstallDir)/data, where the /data is appended at build time. This allows the run-time code to instantly use the path without needing to prepend data/ to it, which is another space versus time trade off. By storing data/ in front of our path in the binary file, the file size increases while our load time decreases.

Reading Binary Effect Files

This is the code to load a binary file and extract effect values:

eae6320::Platform::sDataFromFile dataFromFile;
	eae6320::Platform::LoadBinaryFile(i_effectPath, dataFromFile);

	auto currentOffset = reinterpret_cast<uintptr_t>( dataFromFile.data );
	const auto finalOffset = currentOffset + dataFromFile.size;

    const auto vertexShaderPathSize = *reinterpret_cast<uint16_t*>( currentOffset );

	currentOffset += sizeof( vertexShaderPathSize );
    const auto renderStateBits = *reinterpret_cast<uint8_t*>( currentOffset );

	currentOffset += sizeof( renderStateBits );
	char* vertexShaderPath = reinterpret_cast<char*>( currentOffset );

	currentOffset += vertexShaderPathSize * sizeof( char );
	char* fragmentShaderPath = reinterpret_cast<char*>( currentOffset );

No Comments Yet.

Leave a comment