Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add timing control over sensors #254

Merged
merged 2 commits into from
Sep 25, 2024

Conversation

crashkonijn
Copy link
Owner

@crashkonijn crashkonijn commented Sep 24, 2024

Timers can now be added to sensors, to limit how often it is run.

public static class SensorTimer
{
    public static AlwaysSensorTimer Always { get; } = new AlwaysSensorTimer();
    public static OnceSensorTimer Once { get; } = new OnceSensorTimer();
    public static IntervalSensorTimer Interval(float interval) => new IntervalSensorTimer(interval);
}

public class AlwaysSensorTimer : ISensorTimer
{
    public bool ShouldSense(ITimer timer)
    {
        return true;
    }
}

public class OnceSensorTimer : ISensorTimer
{
    public bool ShouldSense(ITimer timer)
    {
        if (timer == null)
            return true;

        return false;
    }
}

public class IntervalSensorTimer : ISensorTimer
{
    private readonly float interval;

    public IntervalSensorTimer(float interval)
    {
        this.interval = interval;
    }

    public bool ShouldSense(ITimer timer)
    {
        if (timer == null)
            return true;

        if (timer.GetElapsed() >= this.interval)
            return true;

        return false;
    }
}
using CrashKonijn.Agent.Core;
using CrashKonijn.Goap.Core;
using CrashKonijn.Goap.Runtime;

namespace CrashKonijn.Goap.Demos.Simple.Goap.Sensors.Target
{
    [GoapId("Simple-TransformSensor")]
    public class AgentSensor : LocalTargetSensorBase
    {
        public override ISensorTimer Timer { get; } = SensorTimer.Once;

        public override void Created()
        {
        }

        public override void Update()
        {
        }

        public override ITarget Sense(IActionReceiver agent, IComponentReference references, ITarget target)
        {
            return new TransformTarget(agent.Transform);
        }
    }
}

@crashkonijn crashkonijn mentioned this pull request Sep 24, 2024
@crashkonijn crashkonijn merged commit 7d080bc into feature/v2.2 Sep 25, 2024
1 check passed
@crashkonijn crashkonijn deleted the feature/add-timing-controll-over-sensors branch September 25, 2024 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant