Handmade Hero»Forums»Game
5 posts
Day 23 / 24 Looped Live Code Editing Super Fast & Small?
Edited by Salads on
EDIT: I just passed through the Q&A for the episode. It seems that we'll be using the entire block anyways, but will we be using more than the game_state for this functionality? Just hoping for some quality of life! :V

I've realized something that helped the playback file go to the KB range and the loading times become almost instant.

We've been writing the entire State->GameMemoryBlock (more than 1 GB) every time we enabled the loop in our BeginInputPlayback and BeginRecordingInput functions. But we don't use allot of that memory. So I tried instead doing this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
internal void
Win32BeginRecordingInput(win32_state *State, int InputRecordingIndex)
{

	State->InputRecordingIndex = InputRecordingIndex;

	char Filename[WIN32_STATE_FILENAME_COUNT];
	Win32GetInputFileLocation(State, InputRecordingIndex,
							  sizeof(Filename), Filename);

	State->RecordingHandle =
		CreateFileA(Filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);

	DWORD BytesToWrite = (DWORD)State->TotalSize;
	Assert(State->TotalSize == BytesToWrite);

	DWORD BytesWritten;
	WriteFile(State->RecordingHandle, (game_state *)State->GameMemoryBlock,
			  sizeof(game_state), &BytesWritten, 0);
}


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
internal void
Win32BeginInputPlayback(win32_state *State, int InputPlayingIndex)
{
	State->InputPlayingIndex = InputPlayingIndex;

	char Filename[WIN32_STATE_FILENAME_COUNT];
	Win32GetInputFileLocation(State, InputPlayingIndex,
							  sizeof(Filename), Filename);

	State->PlaybackHandle =
		CreateFileA(Filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);

	DWORD BytesToRead = (DWORD)State->TotalSize;
	Assert(BytesToRead == State->TotalSize);

	DWORD BytesRead;
	ReadFile(State->PlaybackHandle, (game_state *)State->GameMemoryBlock,
			  sizeof(game_state), &BytesRead, 0);
}


And it solved all my storage woes on my SSD and it was really fast! I'm not sure if later on when the game becomes more complex we will need more than the game state?
Mārtiņš Možeiko
2559 posts / 2 projects
Day 23 / 24 Looped Live Code Editing Super Fast & Small?
Edited by Mārtiņš Možeiko on
It was later changed to write and read only the actual size we use and not the whole allocated memory, so the process is much faster.
5 posts
Day 23 / 24 Looped Live Code Editing Super Fast & Small?
Edited by Salads on
thanks! does this mean only game_state needs to be saved? because I know theres both perm storage and transient storage and was wondering about that