redesign: Agents
This commit is contained in:
45
src/Agents/World.cs
Normal file
45
src/Agents/World.cs
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user