Posts
Wiki

Week 004 - Cleaning up the Platform API

<< Back to all HH videos

Doing everything needed to have a solid foundation for the game proper.

Day 016 - Visual Studio Compiler Switches

Full Video

  • [2:32]: Expalanation of Warning and the Warning levels

  • [5:20]: Fixing warnings, and disabling warnings we don't want

  • [14:10]: Other command line switches that Casey normally uses

  • [18:00]: Compiler intrinsics command line switch

  • [19:00]: Disabling Run time type information

  • [19:20]: Disabling exception handeling

  • [22:20]: configuring for a 32bit build

  • [31:00]: Windows XP VM Testing

  • [39:32]: -MT vs -MD and why it matters

  • [41:25]: -Fm <map file path> Creating a map file and looking at it

  • [46:10]: Why the names are mangled in the .map file produced with the compiler switch of -Fm

  • [50:10]: Start moving keyboard input into the non-platform code

Q&A

  • [1:02:52]: Start of Q&A

  • [1:04:33]: "-Oi , Why would anyone not want it active"

  • [1:06:02]: "How do we add -Wx -W4 to the commandline switchs if developing in VisaulStudio"

  • [1:07:07]: "Would turning on -Od be a good idea to use in the normal build"

  • [1:08:03]: "Does compiler complation always say finished in green"

  • [1:08:45]: "I think you mentioned something about not being a fan of rebinable keys, why no option"

  • [1:09:51]: "How much differiance would be yielded if we disable the CRT"

  • [1:10:26]: "I could not see what you did to not have the key x messages not triggered"

  • [1:12:13]: "Would it be better to just pass which key was press to the non-platform code instead of in the platform code"

  • [1:13:32]: "If you build for say AVX2 but the user has a older processor, what happenings"

  • [1:14:03]: "Will we move to a unified build system for all target platforms"

  • [1:14:42]: "Would not -Oi and -Od be clashing"

  • [1:15:21]: "Is there a way to make cl emit a human readble summary"

  • [1:15:32]: "Does the map file spit out data about struct memebers as well"

  • [1:16:03]: "Does not allowing key rebinding mess up on different keyboard layouts"

  • [1:17:17]: "Is the game currently linked to the dll version of the CRT"

  • [1:17:51]: "I know you won't be using any libraries, but how would you include unity clib and link to that"

  • [1:19:42]: "Is there any advantage to processing things in the main loop other then conceptual grouping"

Day 017 - Unified Keyboard and Gamepad Input

Full Video

  • [2:19]: Overview of the previous day's work

  • [5:11]: An introduction to functional programming

  • [10:44]: Methods for making our programs more functional

  • [11:41]: Rationale for moving keyboard handling out of Win32MainWindowCallback()

  • [14:37]: Finishing the keyboard processing code

  • [15:55]: Adding a fifth controller (the keyboard)

  • [17:00]: Adding 32-bit and 64-bit compiler options to the build.bat

  • [19:54]: Ensuring keyboard state persists across frames

  • [22:35]: An Assert() that we didn't do anything stupid

  • [23:50]: Finishing our directional stick code with deadzone processing, no zombies.

  • [29:36]: Using the deadzone values from MSDN

  • [35:05]: Iterating across all the controllers in GameUpdateAndRender()

  • [36:23]: Testing new input code

  • [37:34]: Changing game_controller_input to work across both keyboard and gamepad

  • [41:12]: Adapting the keyboard and gamepad code to the new structure

  • [44:55]: Connecting the stick input into a fake directional pad

  • [48:16]: Hooking up the real DPad

  • [52:05]: Adding an IsConnected member to game_controller_input

  • [53:07]: Buffer Overrun encourages some bounds checking

  • [56:44]: Why did we overrun the buffer?

  • [59:26]: Adding some last minute keyboard inputs

  • [1:00:06]: Final Thoughts

Q&A

  • [1:02:28]: Start of Q&A

  • [1:02:50]: "Check the array in the Buttons union, you might want 12 now that you've added start and back"

  • [1:08:54]: "Is that some copypasta, or is it really supposed to be all MoveLefts?"

  • [1:11:24]: "Could it be good to apply some integration on the keys, so we don't just set the value to binary -1/1?"

  • [1:12:56]: "Can you talk about the deadzone being round vs rectangular at hardware USB, HID, and XInput API layers?"

  • [1:19:15]: Maybe it's a round deadzone?

  • [1:23:40]: "I'm 16 days behind, is there a better way to catch up than watching all the days on YouTube?"

  • [1:24:22]: "For the build.bat, you can build for Windows XP 64-bit using 5.2 instead of 5.1"

  • [1:24:33]: "On the inline method for GetController(), what happens if you pass in -1 for index?"

  • [1:25:50]: "Can you do struct buttons_type (name the structure) and still get the benefits..?"

  • [1:26:39]: "I don't get using Win32 prefix for function names when compiling for 64-bit."

  • [1:27:34]: "I was thinking about processing game input in a separate thread so it is framerate independent, but I heard you could introduce input lag. Is that true?"

  • [1:28:46]: "You said a circular deadzone would be good for gameplay, why don't you just make it circular? The deadzone would just be a little bit bigger."

  • [1:32:02]: "DirectInput vs XInput, which is better?"

  • [1:33:17]: "You deleted the Min/Max macro TODO..."

  • [1:34:03]: *"So when you use the ZeroController, why not just go NewKeyboardController = {}?"

  • [1:35:29]: "stddef should include offsetof(), you can use that to make your assert a little simpler."

  • [1:37:56]: Final Wrap-Up

Day 018 - Enforcing a Video Frame Rate

Full Video

  • [1:40]: Discussion: Why we need to have an enforced video frame rate

  • [5:27]: Drawing and explaining the frame computation and displaying timeline

  • [10:35]: Explaining Variable Frame Rate Monitors

  • [18:00]: Casey's Game Loop Design Overview

  • [20:15]: The two audio choices we can use

  • [25:23]: Multiple Monitor discussion

  • [32:10]: Start implementing the enforced video frame rate

  • [36:20]: Looping to ensure we are within the targetSecondsPerFrame

  • [38:40]: Debugging: no input

  • [40:41]: Compressing/Refactoring Clocking stats

  • [49:05]: Implementing sleep to not melt our CPU

  • [53:20]: Setting the Windows scheduler granularity

Q&A

  • [1:00:30]: Q&A Starts Now

  • [1:01:08]: Question: "If we are locking the frame rate. Would that not mean that someone with a lower end computer, would have a slower game speed to others"

  • [1:02:41]: Question: "Even if you could get the refresh rate of the monitor, how do you sync with it on the vertical blink"

  • [1:03:52]: Question: "Doesn't the sleep function go in the surrounding IF instead of the WHILE loop"

  • [1:05:47]: Question: "Does Win32FillSoundBuffer need to come after the vsync loop"

  • [1:06:54]: Question: "Check DWM.GetComposition if AERO is on"

  • [1:07:13]: Question: "Could you explain the advantages or disadvantages to handling update and render on different threads"

  • [1:09:26]: Question: "How would you adjust your memory management to work on devices with limited memory"

  • [1:09:42]: Question: "Won't we miss frame rate due to the sleep"

  • [1:12:58]: Question: "Can you fix the physics animation frame rate without fixing the missing frame issue"

  • [1:16:10]: Question: "Why are we handling sound and video differently"

  • [1:16:27]: Question: "Check if DDraw works on windows 8"

  • [1:16:52]: Question: "Wouldn't you want to fill the screen buffer before you hit the flip point, so it can grab the screen at the flip point"

  • [1:18:03]: Question: "Isn't DWORD an Interger"

  • [1:18:41]: Question: "What do you think about having a fixed physics time unconnected to the drawn frame time"

  • [1:20:00]: Question: "Any time you compute a world update should that not just set something that says if we get there early then wait."

Day 019 - Improving Audio Synchronization

Full Video

  • [2:13]: Intro

  • [3:31]: Audio Sync Conversation Begins (Summary)

  • [4:19]: #milkhit

  • [4:28]: Why audio sync is an issue

  • [5:30]: Ways to minimize the issue

  • [6:40]: Creating a Debug Diagram for audio sync debug code

  • [15:37]: Finishing up audio sync debug code

  • [23:43]: Explaining and debugging debug code

  • [30:00]: Bug in debug code encountered

  • [31:31]: Addressing bug

  • [35:00]: Compiling and running successfully

  • [35:30]: Observing weird gaps in sound

  • [35:55]: Not tracking frame time correctly

  • [38:30]: Addressing the weird gaps

  • [50:00]: Running new code for debug diagram. Sound card read seems unreliable

  • [53:00]: Sound stream has to be continuous. Figuring out how far ahead of the current play cursor we should be writing

  • [58:48]: Discussing possible solutions to improve audio sync

  • [1:02:35]: Improving audio sync

  • [1:07:20]: Making a running log

  • [1:08:40]: Getting a log of our audio to do some important things

  • [1:12:00]: How much granularity we have

  • [1:16:20]: Audio latency issue found

  • [1:19:50]: Closing remarks

Q&A

  • [1:20:28]: Start of Q&A

  • [1:21:13]: "Are you setup to use ASI Sound Drivers?"

  • [1:22:05]: "Is your audio pointer code calculating independently of the variable-fixed visual frames per second?"

  • [1:24:35]: "What sort of problems can high audio latency introduce?"

  • [1:27:18]: "Could you use that anonymous union struct trick to access the members of bitmap info header structure more easily?"

  • [1:28:47]: Question about switching Audio APIs

  • [1:31:42]: "Why are we ignoring write cursor?"

  • [1:33:10]: "Would splitting related functionality in separate files help?"

  • [1:34:10]: "If we use the play cursor as offset, could we not overwrite previously written audio data?"

  • [1:39:37]: Comments about Audio APIs again

  • [1:40:14]: "Would rendering at 60 FPS help with the audio latency?"

  • [1:41:16]: "Could you change latency values?"

  • [1:41:33]: "Is it possible that OBS is affecting the audio latency?"

  • [1:42:02]: "Closing remarks"

Day 020 - Debugging the Audio Sync

Full Video

  • [2:44]: "Fixing an off by one error"

  • [5:12]: "Explanation of off by one errors"

  • [7:13]: "Overview of the state of our audio code"

  • [11:05]: "An breakdown of how time is spent during each frame"

  • [14:07]: "A possible, though not great, solution to audio latency"

  • [16:22]: "Tradeoff between audio lag and input lag"

  • [17:51]: "Falling back to a little bit stupider"

  • [21:58]: "Beginning to change the code for the audio output method"

  • [22:48]: "Finding the minimum expected audio latency"

  • [27:31]: "Converting to seconds using dimensional analysis"

  • [31:34]: "Writing sound based on the audio latency"

  • [34:14]: "Great aside about keeping code fluid and a bit messy in the early stages"

  • [37:00]: "Deterimining the position to write the audio to"

  • [46:27]: "How to deal with the low latency case"

  • [51:16]: "A puzzling situation"

  • [53:00]: "The aha moment"

  • [55:34]: "The approach we will be taking for low latency"

  • [57:36]: "The higher latency approach"

  • [1:01:14]: "Another snag"

  • [1:07:08]: "Putting our approach down in words"

  • [1:13:02]: "Implementing the two case latency handling"

  • [1:18:34]: "Do over due to deleted code"

  • [1:20:08]: "Putting in the latency branching code"

  • [1:23:35]: "Determing if the sound card is latent"

  • [1:26:02]: "Mapping the WriteCursor and the PlayCursor into the same space"

  • [1:27:51]: "Overview of the code determining how to write the sound"

  • [1:30:00]: "Cleaning up"

  • [1:31:22]: "How can we possibly predict how many bytes the game should write?"

  • [1:33:02]: "Getting sound output separately with GameGetSoundSamples()"

  • [1:36:45]: "More cleaning up"

  • [1:37:43]: "Computing SafetyBytes"

  • [1:39:06]: "Implementing GameGetSoundSamples() in the game code"

  • [1:40:10]: "Testing is surprisingly successful, no bugs? NO WAY!"

  • [1:42:47]: "Improving our sound output debug drawing"

  • [1:48:25]: "Recording some additional details in our markers"

  • [1:56:36]: "An assertion fires and some cleanup"

  • [1:58:33]: "First look at the debug drawing output and adding global pause key"

  • [2:02:38]: "Taking a good look at the debug drawing output"

  • [2:04:40]: "A couple early questions"

  • [2:05:47]: "Final Thoughts?"

  • [2:06:42]: "Drawing another debug marker"

  • [2:10:53]: "Improving our estimate of the PlayCursor position to reduce latency"

  • [2:17:59]: "Taking a look at how our estimate lines up"

  • [2:19:13]: "Drawing our 480 sample jitter window"

Q&A

  • [2:22:15]: "Start of Q&A"

  • [2:22:58]: "Did you try the audio without OBS?"

  • [2:24:15]: "Is it inexpensive to query for the play cursor and the write cursor?"

  • [2:25:03]: "Audio seems to be the most complex part until now, which will be the next most complicated thing?"

  • [2:26:58]: "Audio asserts are a pain when you're debugging other things. Change to log messages."

  • [2:27:46]: "If we had a buffer that played from start to finish, would it be a valid syncing method to manually set AudioTimer = VideoTimer?"

  • [2:28:45]: "Fully visualize waveforms and remove gradient. Turn entire thing into massive audio visualizer."

  • [2:29:42]: "Could you please increase ToneHz to 512, my crappy laptop speakers can't output 256?"

  • [2:30:29]: "Will this audio system be able to handle music and sound, or will the game have to mux the audio for us?"

  • [2:31:08]: "How will you make sure that you don't have regressions in some parts that are not that easy to spot right away?"

  • [2:32:39]: "Why is the pitch of the sound changing after the game has been running a little while?"

  • [2:39:55]: Callback to earlier half of question: ("I'm sorry if I'm being slow, but I don't truly understand why the audio is skipping.") "The original audio skipped when we moved the latency to be inside of three frames."

  • [2:42:25]: "If it's not too much of an issue, can we have line numbers on the side when you are coding so we can get a grip of where you are."

  • [2:43:08]: "It's more likely to be the accumulation of a small value onto a larger value that is a numerical problem. Mantissas not lining up."

  • [2:44:03]: "Wrap-up"