X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2Fworld.cpp;h=bf68a9eca412f295c977e486c465e0794025366a;hb=6513b55584093a86ce1e369e054263dd75c295c8;hp=d933dc4ec77f86d913d2cd66de5ced6e4a19d65f;hpb=6a3227ca747d0598711f7354cd39897184e9fe6a;p=blank.git diff --git a/src/world/world.cpp b/src/world/world.cpp index d933dc4..bf68a9e 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -179,7 +179,6 @@ EntityDerivative Entity::CalculateStep( next.pos.block += delta.position * dt; next.velocity += delta.velocity * dt; limit(next.velocity, max_vel); - world.ResolveWorldCollision(*this, next); next.AdjustPosition(); EntityDerivative out; @@ -780,12 +779,22 @@ bool World::Intersection( const ExactLocation::Coarse &reference, WorldCollision &coll ) { + // only consider chunks of the idex closest to reference + // this makes the ray not be infinite anymore (which means it's + // actually a line segment), but oh well + ChunkIndex *index = chunks.ClosestIndex(reference); + if (!index) { + return false; + } + candidates.clear(); - for (Chunk &cur_chunk : chunks) { + // TODO: convert to coords based iteration and trim based + // on ray direction + for (Chunk *cur_chunk : *index) { float cur_dist; - if (cur_chunk.Intersection(ray, reference, cur_dist)) { - candidates.push_back({ &cur_chunk, cur_dist }); + if (cur_chunk && cur_chunk->Intersection(ray, reference, cur_dist)) { + candidates.push_back({ cur_chunk, cur_dist }); } } @@ -841,7 +850,7 @@ bool World::Intersection(const Entity &e, const EntityState &s, std::vector &col ) { + // this only works if box's diameter is < than 16 + ExactLocation::Coarse begin(reference - 1); + ExactLocation::Coarse end(reference + 2); + bool any = false; - for (Chunk &cur_chunk : chunks) { - if (manhattan_radius(cur_chunk.Position() - reference) > 1) { - // chunk is not one of the 3x3x3 surrounding the entity - // since there's no entity which can extent over 16 blocks, they can be skipped - // TODO: change to indexed (like with entity) - continue; - } - if (cur_chunk.Intersection(box, M, cur_chunk.Transform(reference), col)) { - any = true; + for (ExactLocation::Coarse pos(begin); pos.z < end.z; ++pos.z) { + for (pos.y = begin.y; pos.y < end.y; ++pos.y) { + for (pos.x = begin.x; pos.x < end.x; ++pos.x) { + Chunk *chunk = chunks.Get(pos); + if (chunk && chunk->Intersection(box, M, chunk->Transform(reference), col)) { + any = true; + } + } } } return any; @@ -1060,7 +1072,7 @@ void World::RenderDebug(Viewport &viewport) { PrimitiveMesh debug_mesh; PlainColor &prog = viewport.WorldColorProgram(); for (const Entity &entity : entities) { - debug_buf.OutlineBox(entity.Bounds(), glm::vec4(1.0f, 0.0f, 0.0f, 1.0f)); + debug_buf.OutlineBox(entity.Bounds(), glm::tvec4(255, 0, 0, 255)); debug_mesh.Update(debug_buf); prog.SetM(entity.Transform(players.front().GetEntity().ChunkCoords())); debug_mesh.DrawLines();