store some kind of byte order mark?
+ world and player names should be normalized so they can safely
+ be used in path names
+
networking
definitely needs throttling for the internets
players stats (who's connected, their ping, and game-relevant
things) should be sent to clients
+ some method for authenticating a player might be nice
+
+ maybe stale and inexistent chunks should be visualized (e.g. by
+ drawing a semi-transparent box around them)
+
threading
(clientside) networking and disk IO are prime candidates for threading
// LOS test, assumes all entities are see-through
WorldCollision col;
- if (world.Intersection(aim, glm::mat4(1.0f), reference, col) && col.depth < dist) {
+ if (world.Intersection(aim, reference, col) && col.depth < dist) {
continue;
}
return false;
}
WorldCollision col;
- if (world.Intersection(aim, glm::mat4(1.0f), reference, col) && col.depth < dist) {
+ if (world.Intersection(aim, reference, col) && col.depth < dist) {
return false;
}
return true;
void PlayerController::UpdatePlayer() noexcept {
if (dirty) {
Ray aim = player.Aim();
- if (!world.Intersection(aim, glm::mat4(1.0f), player.GetEntity().ChunkCoords(), aim_world)) {
+ if (!world.Intersection(aim, player.GetEntity().ChunkCoords(), aim_world)) {
aim_world = WorldCollision();
}
- if (!world.Intersection(aim, glm::mat4(1.0f), player.GetEntity(), aim_entity)) {
+ if (!world.Intersection(aim, player.GetEntity(), aim_entity)) {
aim_entity = EntityCollision();
}
if (aim_world && aim_entity) {
(idx / (side * side))
);
}
- glm::mat4 ToTransform(const RoughLocation::Fine &pos, int idx) const noexcept;
+ /// get a chunk-local transform for block at given position and index
+ /// (position and index are redundant)
+ glm::mat4 ToTransform(const RoughLocation::Fine &position, int index) const noexcept;
+ /// same as above, but also apply offset to given reference
+ glm::mat4 ToTransform(const ExactLocation::Coarse &ref, const RoughLocation::Fine &pos, int idx) const noexcept;
ExactLocation::Fine ToSceneCoords(const ExactLocation::Coarse &base, const ExactLocation::Fine &pos) const noexcept {
return ExactLocation::Fine((position - base) * ExactLocation::Extent()) + pos;
bool Intersection(
const Ray &ray,
- const glm::mat4 &M,
+ const ExactLocation::Coarse &reference,
float &dist
) const noexcept {
- return blank::Intersection(ray, Bounds(), M, &dist);
+ return blank::Intersection(ray, Bounds(), Transform(reference), &dist);
}
+ /// check if given ray intersects any block of this chunk
+ /// given reference indicated the chunk offset of the ray in world space
bool Intersection(
const Ray &,
- const glm::mat4 &M,
+ const ExactLocation::Coarse &reference,
WorldCollision &) noexcept;
bool Intersection(
void Position(const ExactLocation::Coarse &pos) noexcept { position = pos; }
const ExactLocation::Coarse &Position() const noexcept { return position; }
+
glm::mat4 Transform(const ExactLocation::Coarse &offset) const noexcept {
return glm::translate((position - offset) * ExactLocation::Extent());
}
/// check if this ray hits a block
/// depth in the collision is the distance between the ray's
/// origin and the intersection point
- /// M is the global transform for given reference chunk
+ /// reference is the chunk offset of the ray in world space
bool Intersection(
const Ray &,
- const glm::mat4 &M,
const ExactLocation::Coarse &reference,
WorldCollision &);
/// check if this ray hits an entity
/// intersections with the reference are not tested
- /// M is the global transform for the chunk of given reference entity
+ /// the ray is assumed to be in world space offset by entity's chunk coords
bool Intersection(
const Ray &,
- const glm::mat4 &M,
const Entity &reference,
EntityCollision &);
bool Chunk::Intersection(
const Ray &ray,
- const glm::mat4 &M,
+ const ExactLocation::Coarse &reference,
WorldCollision &coll
) noexcept {
int idx = 0;
}
float cur_dist;
glm::vec3 cur_norm;
- if (type.shape->Intersects(ray, M * ToTransform(RoughLocation::Fine(x, y, z), idx), cur_dist, cur_norm)) {
+ if (type.shape->Intersects(ray, ToTransform(reference, RoughLocation::Fine(x, y, z), idx), cur_dist, cur_norm)) {
if (cur_dist < coll.depth) {
coll.block = idx;
coll.depth = cur_dist;
return glm::translate(ToCoords(pos)) * BlockAt(idx).Transform();
}
+glm::mat4 Chunk::ToTransform(const ExactLocation::Coarse &ref, const RoughLocation::Fine &pos, int idx) const noexcept {
+ return glm::translate(ExactLocation::Fine((position - ref) * ExactLocation::Extent()) + ToCoords(pos)) * BlockAt(idx).Transform();
+}
+
BlockLookup::BlockLookup(Chunk *c, const RoughLocation::Fine &p) noexcept
: chunk(c), pos(p) {
bool World::Intersection(
const Ray &ray,
- const glm::mat4 &M,
const ExactLocation::Coarse &reference,
WorldCollision &coll
) {
for (Chunk &cur_chunk : chunks) {
float cur_dist;
- if (cur_chunk.Intersection(ray, M * cur_chunk.Transform(reference), cur_dist)) {
+ if (cur_chunk.Intersection(ray, reference, cur_dist)) {
candidates.push_back({ &cur_chunk, cur_dist });
}
}
for (Candidate &cand : candidates) {
if (cand.dist > coll.depth) continue;
WorldCollision cur_coll;
- if (cand.chunk->Intersection(ray, M * cand.chunk->Transform(reference), cur_coll)) {
+ if (cand.chunk->Intersection(ray, reference, cur_coll)) {
if (cur_coll.depth < coll.depth) {
coll = cur_coll;
}
bool World::Intersection(
const Ray &ray,
- const glm::mat4 &M,
const Entity &reference,
EntityCollision &coll
) {
}
float cur_dist;
glm::vec3 cur_normal;
- if (blank::Intersection(ray, cur_entity.Bounds(), M * cur_entity.Transform(reference.ChunkCoords()), &cur_dist, &cur_normal)) {
+ if (blank::Intersection(ray, cur_entity.Bounds(), cur_entity.Transform(reference.ChunkCoords()), &cur_dist, &cur_normal)) {
// TODO: fine grained check goes here? maybe?
if (cur_dist < coll.depth) {
coll.entity = &cur_entity;