Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -12,16 +12,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
/// Implements a naiive-AF hashing algorithm for Vector2 class
|
||||
/// So we can use it as unique keys in std::unordered_map
|
||||
template<>
|
||||
struct std::hash<Vector2i>
|
||||
{
|
||||
std::size_t operator()(const Vector2i& k) const
|
||||
{
|
||||
return k.x; //Math::Pow(k.x, 3) + Math::Pow(k.y, 2);
|
||||
// Read 2x int32_t into one int64_t and return std::hash<int64_t> to prevent collisions.
|
||||
// This doesn't really gain any performance until you zoom out a lot.
|
||||
return std::hash<int64_t>()(((int64_t) k.x << 32) | ((int64_t) k.y));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -176,7 +174,6 @@ namespace CaveGame::Core {
|
||||
}
|
||||
virtual void AutoSave();
|
||||
|
||||
bool ValidCoords(const Vector2i &cell) const;
|
||||
protected:
|
||||
std::vector<Entity*> entities;
|
||||
const std::filesystem::path worlds {"worlds"};
|
||||
|
@@ -106,25 +106,13 @@ namespace CaveGame::Core
|
||||
}
|
||||
|
||||
Chunk* World::GetChunkAtCell(const Vector2i& cell) {
|
||||
if (ValidCoords(cell))
|
||||
if (HasChunkAtCell(cell))
|
||||
return loaded_chunks.at(cell);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool World::ValidCoords(const Vector2i& cell) const {
|
||||
if (Math::Floor(cell.x) != cell.x || Math::Floor(cell.y) != cell.y) {
|
||||
// TODO: Implement ostream on Vector2i
|
||||
//std::cerr << "Invalid cell coordinate: " << cell << ", must be whole numbers!";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool World::HasChunkAtCell(const Vector2i &cell) const {
|
||||
if (ValidCoords(cell))
|
||||
return loaded_chunks.contains(cell);
|
||||
return false;
|
||||
return loaded_chunks.contains(cell);
|
||||
}
|
||||
|
||||
std::unordered_map<Vector2i, Chunk*> World::GetChunkList() { return loaded_chunks; }
|
||||
@@ -183,7 +171,7 @@ namespace CaveGame::Core
|
||||
|
||||
if (HasChunkAtCell(chunkCoords))
|
||||
return loaded_chunks.at(chunkCoords)->GetTileUpdateFlag(tileCoords.x, tileCoords.y);
|
||||
|
||||
// This is bad.
|
||||
}
|
||||
|
||||
Vector2 World::ToUnitDirection(float rotation) {
|
||||
|
Reference in New Issue
Block a user