generate walls space separately during bake rather than every frame
This commit is contained in:
parent
ffa3378a54
commit
de86e12ba0
60
src/pp/pp.c
60
src/pp/pp.c
@ -1196,7 +1196,7 @@ P_Constraint *P_NextConstraint(P_Constraint *c)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Space
|
//~ Space
|
||||||
|
|
||||||
P_Space P_SpaceFromFrame(Arena *arena, P_Frame *frame)
|
P_Space P_SpaceFromEnts(Arena *arena, P_Frame *frame)
|
||||||
{
|
{
|
||||||
P_Space space = Zi;
|
P_Space space = Zi;
|
||||||
TempArena scratch = BeginScratch(arena);
|
TempArena scratch = BeginScratch(arena);
|
||||||
@ -1241,9 +1241,24 @@ P_Space P_SpaceFromFrame(Arena *arena, P_Frame *frame)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Generate wall shapes from tiles
|
EndScratch(scratch);
|
||||||
// TODO: Cache walls in separate space
|
return space;
|
||||||
|
}
|
||||||
|
|
||||||
|
P_Space P_SpaceFromWalls(Arena *arena, P_Frame *frame)
|
||||||
{
|
{
|
||||||
|
P_Space space = Zi;
|
||||||
|
TempArena scratch = BeginScratch(arena);
|
||||||
|
P_World *world = frame->world;
|
||||||
|
space.dims = VEC2I32(P_WorldPitch, P_WorldPitch);
|
||||||
|
i64 cells_count = P_WorldPitch * P_WorldPitch;
|
||||||
|
space.cells = PushStructs(arena, P_SpaceCell, cells_count);
|
||||||
|
|
||||||
|
Rng2 space_aabb = RNG2(
|
||||||
|
VEC2(0, 0),
|
||||||
|
VEC2(P_WorldPitch, P_WorldPitch)
|
||||||
|
);
|
||||||
|
|
||||||
Enum(WallDir)
|
Enum(WallDir)
|
||||||
{
|
{
|
||||||
WallDir_None,
|
WallDir_None,
|
||||||
@ -1264,14 +1279,6 @@ P_Space P_SpaceFromFrame(Arena *arena, P_Frame *frame)
|
|||||||
i64 walls_count = 0;
|
i64 walls_count = 0;
|
||||||
GenWall *first_wall = 0;
|
GenWall *first_wall = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// FIXME: Iterate to pitch + 1
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//- Generate horizontal walls
|
//- Generate horizontal walls
|
||||||
for (i32 tile_y = 0; tile_y < P_TilesPitch + 1; ++tile_y)
|
for (i32 tile_y = 0; tile_y < P_TilesPitch + 1; ++tile_y)
|
||||||
{
|
{
|
||||||
@ -1396,8 +1403,6 @@ P_Space P_SpaceFromFrame(Arena *arena, P_Frame *frame)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
EndScratch(scratch);
|
EndScratch(scratch);
|
||||||
return space;
|
return space;
|
||||||
@ -1407,7 +1412,7 @@ P_SpaceCell P_SpaceCellFromPos(P_Space *space, Vec2 pos)
|
|||||||
{
|
{
|
||||||
P_SpaceCell result = Zi;
|
P_SpaceCell result = Zi;
|
||||||
pos = AddVec2(pos, VEC2(P_WorldPitch / 2.0, P_WorldPitch / 2.0));
|
pos = AddVec2(pos, VEC2(P_WorldPitch / 2.0, P_WorldPitch / 2.0));
|
||||||
if (pos.x >= 0 && pos.x < P_WorldPitch && pos.y >= 0 && pos.y < P_WorldPitch)
|
if (pos.x >= 0 && pos.x < space->dims.x && pos.y >= 0 && pos.y < space->dims.y)
|
||||||
{
|
{
|
||||||
i64 cell_idx = FloorF32(pos.y) * P_WorldPitch + FloorF32(pos.x);
|
i64 cell_idx = FloorF32(pos.y) * P_WorldPitch + FloorF32(pos.x);
|
||||||
result = space->cells[cell_idx];
|
result = space->cells[cell_idx];
|
||||||
@ -1562,7 +1567,7 @@ P_World *P_AcquireWorld(void)
|
|||||||
world->arena = arena;
|
world->arena = arena;
|
||||||
}
|
}
|
||||||
world->frames_arena = AcquireArena(Gibi(64));
|
world->frames_arena = AcquireArena(Gibi(64));
|
||||||
world->statics_arena = AcquireArena(Gibi(64));
|
world->bake_arena = AcquireArena(Gibi(64));
|
||||||
|
|
||||||
world->first_frame = &P_NilFrame;
|
world->first_frame = &P_NilFrame;
|
||||||
world->last_frame = &P_NilFrame;
|
world->last_frame = &P_NilFrame;
|
||||||
@ -2044,13 +2049,23 @@ void P_StepFrame(P_Frame *frame)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////
|
||||||
|
//- Bake world
|
||||||
|
|
||||||
|
{
|
||||||
|
u64 desired_bake_hash = world->tiles_hash;
|
||||||
|
if (desired_bake_hash != world->baked_hash)
|
||||||
|
{
|
||||||
|
ResetArena(world->bake_arena);
|
||||||
|
world->walls_space = P_SpaceFromWalls(world->bake_arena, frame);
|
||||||
|
world->baked_hash = desired_bake_hash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
//- Build pre-solve space
|
//- Build pre-solve ents space
|
||||||
|
|
||||||
P_Space space = P_SpaceFromFrame(scratch.arena, frame);
|
|
||||||
|
|
||||||
|
P_Space ents_space = P_SpaceFromEnts(scratch.arena, frame);
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
@ -2077,7 +2092,13 @@ void P_StepFrame(P_Frame *frame)
|
|||||||
{
|
{
|
||||||
for (i32 query_x = query_rect.p0.x; query_x < query_rect.p1.x; ++query_x)
|
for (i32 query_x = query_rect.p0.x; query_x < query_rect.p1.x; ++query_x)
|
||||||
{
|
{
|
||||||
P_SpaceCell cell = P_SpaceCellFromPos(&space, VEC2(query_x, query_y));
|
P_SpaceCell cells[] = {
|
||||||
|
P_SpaceCellFromPos(&ents_space, VEC2(query_x, query_y)),
|
||||||
|
P_SpaceCellFromPos(&world->walls_space, VEC2(query_x, query_y)),
|
||||||
|
};
|
||||||
|
for (i64 cell_idx = 0; cell_idx < countof(cells); ++cell_idx)
|
||||||
|
{
|
||||||
|
P_SpaceCell cell = cells[cell_idx];
|
||||||
for (P_SpaceEntry *space_entry = cell.first; space_entry; space_entry = space_entry->next)
|
for (P_SpaceEntry *space_entry = cell.first; space_entry; space_entry = space_entry->next)
|
||||||
{
|
{
|
||||||
Rng2 aabb1 = P_BoundingBoxFromShape(space_entry->shape);
|
Rng2 aabb1 = P_BoundingBoxFromShape(space_entry->shape);
|
||||||
@ -2246,6 +2267,7 @@ void P_StepFrame(P_Frame *frame)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
//- Prune constraints
|
//- Prune constraints
|
||||||
|
|||||||
10
src/pp/pp.h
10
src/pp/pp.h
@ -267,6 +267,7 @@ Struct(P_SpaceCell)
|
|||||||
|
|
||||||
Struct(P_Space)
|
Struct(P_Space)
|
||||||
{
|
{
|
||||||
|
Vec2I32 dims;
|
||||||
P_SpaceCell *cells;
|
P_SpaceCell *cells;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -330,7 +331,6 @@ Struct(P_World)
|
|||||||
{
|
{
|
||||||
Arena *arena;
|
Arena *arena;
|
||||||
Arena *frames_arena;
|
Arena *frames_arena;
|
||||||
Arena *statics_arena;
|
|
||||||
|
|
||||||
u64 seed;
|
u64 seed;
|
||||||
RandState rand;
|
RandState rand;
|
||||||
@ -344,6 +344,11 @@ Struct(P_World)
|
|||||||
i64 frame_bins_count;
|
i64 frame_bins_count;
|
||||||
P_FrameBin *frame_bins;
|
P_FrameBin *frame_bins;
|
||||||
|
|
||||||
|
//- Baked data
|
||||||
|
Arena *bake_arena;
|
||||||
|
P_Space walls_space;
|
||||||
|
u64 baked_hash;
|
||||||
|
|
||||||
u64 tiles_hash;
|
u64 tiles_hash;
|
||||||
u8 *tiles;
|
u8 *tiles;
|
||||||
};
|
};
|
||||||
@ -603,7 +608,8 @@ P_Constraint *P_NextConstraint(P_Constraint *c);
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Space
|
//~ Space
|
||||||
|
|
||||||
P_Space P_SpaceFromFrame(Arena *arena, P_Frame *frame);
|
P_Space P_SpaceFromEnts(Arena *arena, P_Frame *frame);
|
||||||
|
P_Space P_SpaceFromWalls(Arena *arena, P_Frame *frame);
|
||||||
P_SpaceCell P_SpaceCellFromPos(P_Space *space, Vec2 pos);
|
P_SpaceCell P_SpaceCellFromPos(P_Space *space, Vec2 pos);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user