redesign: Agents

This commit is contained in:
h z
2025-02-27 15:39:28 +00:00
parent 8df4ebb6d5
commit e90f701bd5
15 changed files with 166 additions and 144 deletions

45
src/Agents/World.cs Normal file
View File

@@ -0,0 +1,45 @@
using Godot;
using Polonium.Resources;
namespace Polonium.Agents;
public abstract partial class World : Node
{
private WorldModel Model { get; set; }
public HashSet<Agent> Agents { get; } = new();
public Knowledge CommonKnowledge { get; set; }
public override void _Ready()
{
Model = GetNode<WorldModel>("WorldModel");
CommonKnowledge = GetNode<Knowledge>("CommonKnowledge");
Model.CommonKnowledgeUpdated += CommonKnowledgeUpdated;
Model.PrivateKnowledgeUpdated += ForwardPrivateKnowledgeUpdated;
base._Ready();
}
public void RegisterAgent(Agent agent)
{
Agents.Add(agent);
agent.ActionExecuted += Model.ActionExecuted;
}
public virtual void Enter()
{
PoloniumRegistry.Instance.CurrentWorld = this;
}
public virtual void Exit()
{
PoloniumRegistry.Instance.CurrentWorld = null;
}
public void CommonKnowledgeUpdated(KnowledgePatch update) => update.Patch(CommonKnowledge);
public void ForwardPrivateKnowledgeUpdated(SignalHeader header, KnowledgePatch update)
{
foreach (Agent receiver in header.ResolveReceivers())
receiver.UpdateKnowledge(update);
}
}