载入中...
搜索中...
未找到
GrowthSystem.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4#include "common/Result.h"
5#include "common/Time.h"
8#include "growth/Organism.h"
9
10#include <cstdint>
11
12namespace eve::growth {
13
20public:
21 GrowthWorld() = default;
22
24 [[nodiscard]] Result<void> setSecondsPerSimDay(double seconds) noexcept;
25 [[nodiscard]] double secondsPerSimDay() const noexcept { return secondsPerSimDay_; }
26
28 void setRngSeed(std::uint64_t seed) noexcept { rngSeed_ = seed; }
29 [[nodiscard]] std::uint64_t rngSeed() const noexcept { return rngSeed_; }
30
31 [[nodiscard]] GrowthCalendar& calendar() noexcept { return calendar_; }
32 [[nodiscard]] const GrowthCalendar& calendar() const noexcept { return calendar_; }
33 [[nodiscard]] GrowthEventLog& events() noexcept { return events_; }
34 [[nodiscard]] const GrowthEventLog& events() const noexcept { return events_; }
35
40 [[nodiscard]] Result<void> step(const SimulationStep& step);
41
46 [[nodiscard]] Result<void> advanceDays(double days);
47
52 [[nodiscard]] Result<void> tryBreed(Organism& carrier, Organism& partner);
53
59 [[nodiscard]] Result<void> tryReproduce(Organism& organism);
60
62 void resetForTests();
63
65 [[nodiscard]] static GrowthWorld& instance();
67 static void resetInstance();
68
69private:
70 friend class Organism;
71
72 void applyDaySlice(Organism& organism, double days, std::int64_t dayIndexForHash);
73 void drainNeeds(Organism& organism, const SpeciesDef& species, double days);
74 [[nodiscard]] double growthMultiplier(Organism& organism, const SpeciesDef& species);
75 void advanceGrowth(Organism& organism, const SpeciesDef& species, double days);
76 void advanceDisease(Organism& organism, const SpeciesDef& species, double days, std::int64_t dayIndexForHash);
77 void advanceProduce(Organism& organism, const SpeciesDef& species, double days);
78 void advanceReproduction(Organism& organism, const SpeciesDef& species, double days);
79 [[nodiscard]] Result<void> spawnOffspring(Organism& parent, const SpeciesDef& species, int count);
80 void emit(GrowthEventKind kind, Organism& organism, std::string detail);
81
82 GrowthCalendar calendar_;
83 GrowthEventLog events_;
84 double secondsPerSimDay_ = 60.0;
85 double dayFraction_ = 0.0;
86 std::uint64_t rngSeed_ = 1;
87};
88
89} // namespace eve::growth
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
const ColourScope * parent
int detail
Move-only, checked operation results for the common layer.
std::string kind
int count
Common time values and an injectable deterministic simulation clock.
uint32_t seed
Definition TreeMesh.cpp:276
float step
Definition TreeMesh.cpp:451
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Injected simulation calendar owned by GrowthWorld.
Append-only event log cleared explicitly (economy-style).
Owner of calendar, RNG seed, and the sole simulation advance path.
GrowthEventLog & events() noexcept
const GrowthEventLog & events() const noexcept
std::uint64_t rngSeed() const noexcept
double secondsPerSimDay() const noexcept
const GrowthCalendar & calendar() const noexcept
void setRngSeed(std::uint64_t seed) noexcept
Deterministic seed for disease / yield hash streams.
GrowthCalendar & calendar() noexcept
Growth short-root entity for any configured lifeform.
Definition Organism.h:29
GrowthEventKind
Kind of a deterministic growth lifecycle event.
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158
Static species definition — fully data-driven life cycle.
Definition Species.h:81