Aeternalis Evolution, a custom-engine persistent evolutionary MMO. This first commit establishes the project skeleton: - Architecture and design docs: project vision, system overview, engineering constitution, roadmap, 19 ADRs, and the simulation, world, network, persistence and infrastructure architectures. - Headless engineering proof: deterministic synthetic particles, component lifecycle, explicit PRNG streams, canonical snapshots and restored execution. - Build and tooling: CMake 3.28+ / Ninja presets, C++23 feature check, clang-format and clang-tidy config, format check script, Windows check script, and a Docker build context. - Tests: unit tests, benchmarks, a snapshot fuzz target and CLI integration wiring. No gameplay, renderer, network service or running deployment yet. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
48 lines
1.7 KiB
C++
48 lines
1.7 KiB
C++
#include "evo/simulation/world.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <limits>
|
|
|
|
namespace evo {
|
|
std::expected<EntityId, Error> SimulationWorld::create_entity(Position2 position) {
|
|
if (position.x.value >= domain_extent_mm || position.y.value >= domain_extent_mm) {
|
|
return std::unexpected{Error::invalid_position};
|
|
}
|
|
if (entities_.size() >= max_entities) {
|
|
return std::unexpected{Error::entity_limit};
|
|
}
|
|
if (next_id_ == std::numeric_limits<std::uint64_t>::max()) {
|
|
return std::unexpected{Error::id_exhausted};
|
|
}
|
|
const EntityId id{next_id_};
|
|
Random derivation{seed_ ^ (id.value * 0xd1b54a32d192ed03ULL)};
|
|
entities_.push_back(EntityState{id, position, Random{derivation.next()}});
|
|
++next_id_; // Publish only after successful allocation/construction.
|
|
return id;
|
|
}
|
|
|
|
std::expected<void, Error> SimulationWorld::remove_entity(EntityId id) {
|
|
const auto found = std::ranges::lower_bound(entities_, id, {}, &EntityState::id);
|
|
if (found == entities_.end() || found->id != id) {
|
|
return std::unexpected{Error::entity_not_found};
|
|
}
|
|
entities_.erase(found);
|
|
return {};
|
|
}
|
|
|
|
std::expected<void, Error> SimulationWorld::tick() noexcept {
|
|
if (tick_.value == std::numeric_limits<std::uint64_t>::max()) {
|
|
return std::unexpected{Error::tick_exhausted};
|
|
}
|
|
for (auto& entity : entities_) {
|
|
auto& position = entity.position;
|
|
position.x.value =
|
|
(position.x.value + entity.random.ternary() + domain_extent_mm - 1U) % domain_extent_mm;
|
|
position.y.value =
|
|
(position.y.value + entity.random.ternary() + domain_extent_mm - 1U) % domain_extent_mm;
|
|
}
|
|
++tick_.value;
|
|
return {};
|
|
}
|
|
} // namespace evo
|