question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about which system to use

See original GitHub issue

Hi,

I was wondering whether it would be better to use an IExecuteSystem or a ReactiveSystem? I think a ReactiveSystem is more optimised but I’m not sure.

using System.Collections.Generic;
using Entitas;
using Entitas.CodeGeneration.Attributes;
using UnityEngine;

namespace Assets.Sources.Physics.Logic
{
    public class GravitySystem : ReactiveSystem<GameEntity>
    {
        private float m_gravity = .98f;
        public GravitySystem(Contexts contexts) : base(contexts.game)
        {
        }

        protected override ICollector<GameEntity> GetTrigger(IContext<GameEntity> context)
        {
            return context.CreateCollector(GameMatcher.OnGround.Removed(), GameMatcher.Velocity.Added());
        }

        protected override bool Filter(GameEntity entity)
        {
            return entity.isOnGround == false;
        }

        protected override void Execute(List<GameEntity> entities)
        {
            foreach (var entity in entities)
            {
                var velocity = Vector2.zero;

                if (entity.hasVelocity)
                {
                    velocity = new Vector2(entity.velocity.x,entity.velocity.y);
                }

                if (velocity.y < m_gravity)
                {
                    velocity.y += m_gravity;
                }

                entity.ReplaceVelocity(velocity.x, velocity.y);
            }
        }
    }
}

Cheers

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
FNGgamescommented, Feb 6, 2018

Advantage of GetEntities() is that it’s always exactly up to date so there’s no need for the extra logic performed in .Filter() in an RS - presence of the components from your group is guarenteed as long as you consume the entities right after you call GetEntities().

1reaction
svanderweelecommented, Feb 6, 2018

Didn’t think of it like that, thanks man!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Questions to Ask About Systems - Project 2061
a. When this system is working, what does it do? b. For this system to work, must it receive any input? c. What,...
Read more >
The collaboration system user interface:10 questions you ...
Here are 10 questions you can ask about a collaboration system you are considering to see if it will really capture the hearts...
Read more >
9 questions to ask when implementing a new IT system
9 questions to ask when implementing a new IT system · 1. What problem are we planning to solve? · 2. What are...
Read more >
7 Questions to Ask End Users Before Choosing a New ...
7 Questions to Ask End Users Before Choosing a New Software System · What do you like about our current system? · How...
Read more >
Questionnaire for determining usability of a system
Using a rating system based on the Likert Scale is a very common and valid approach. Quoting Wikipedia:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found