[video member=cmuratori stream_platform=twitch stream_username=handmade_hero project=code title="Grid Partitioning for Overlap Testing" vod_platform=youtube id=BCiQcL_6ceM annotator=Miblo] [0:09][Recap and set the stage for the day] [1:53][Run the game and see where we left off] [4:05][handmade_entity.cpp: Toggle off the volume highlighting in UpdateAndRenderEntities()] [4:33][Lose the hoodie][quote 500] [4:51][Run the game and consider putting good data into the sorting routine so that it can do stable sorts] [5:58][Consider how to proceed] [7:33][Determine to solve our n^2 problem] [9:56][Blackboard: The problem with determining which sprites overlap] [12:23][Blackboard: Grid Partitioning as a way to mitigate routines proportionate to n^2] [14:21][Blackboard: Testing for overlap in one dimension] [17:44][Blackboard: How to do this bucketing, or spatial partitioning] [20:08][Blackboard: Breaking up each entity] [20:47][Blackboard: Creating a more hierarchical notion of what the space looks like] [24:07][Blackboard: Quadtree, KD Tree and BSP Tree] [26:50][Blackboard: Favouring a very simple grid bucketing scheme] [29:48][Run the game and consider how expensive the BuildSpriteGraph() is] [32:10][Start with something fairly stupid][quote 501] [32:25][handmade_render.cpp: Introduce sort_grid_entry struct and make BuildSpriteGraph() record if a sprite occupies a grid square] [37:58][handmade_render.cpp: Consider some immediate possibilities for optimisation] [39:59][handmade_render.cpp: Consider making RecursiveFrontToBack() not create the edges of the graph] [42:25][handmade_render.cpp: Introduce GetGridSpan()] [47:19][Blackboard: Adding edges from the perspective of grid testing] [50:35][handmade_render.cpp: Make GetGridSpan() bin the incoming screen area versus the total screen area] [53:38][handmade_render.cpp: Make BuildSpriteGraph() compute the InvCellDim] [56:24][handmade_render.cpp: Make GetGridSpan() work a little differently] [59:59][Run the game and note that we are now bucketing] [1:00:22][Q&A] [1:01:26][@themikedx][Using the grid system, do you think that would be good to use for pixel perfect collision?] [1:01:51][Blackboard: Determining whether rectangles and then possibly pixels intersect] [1:03:54][@thesizik][Why not have the debug overlay render to a separate layer, and have it draw in the order submitted instead of wasting time sorting?] [1:05:40][@thesizik][I think a sort-free mode would work well with the cutscene as well] [1:07:10][@roam00010011][Missed the stream again, why do you not use the summed rectangle of the hero sprites for draw sorting, and draw the individual parts in a set order?] [1:08:25][@fyoucon][Something exciting happening over at Molly Rocket?] [1:08:39][@dan020][Can using C programming optimize the game more than C++?] [1:12:55][@uplinkcoder][RTTI] [1:14:09][Wind it down] [/video]