Coder Social home page Coder Social logo

User input events queue about ash HOT 6 CLOSED

richardlord avatar richardlord commented on September 25, 2024
User input events queue

from ash.

Comments (6)

BigPhilCombo avatar BigPhilCombo commented on September 25, 2024

User input events should just change a value on a component. The
appropriate systems will handle the component in the appropriate order.
On Jun 8, 2013 4:14 PM, "Gaen" [email protected] wrote:

Hi!

The thing that bothers me is that while all the systems operate within
main update loop, user input events such as clicks and key hits are
happening out of it. This means that a click, for example, can happen *
between* the updates. Or even if a user is fast enough, he can manage to
hit and release the mouse multipe times, still between the updates. And if
a user input handling system is checking inside it's update() if the button
is pressed, such clicks will be simply lost.

[image: clicks]https://f.cloud.github.com/assets/1899551/628051/28bcd172-d077-11e2-92ee-4027d4448f18.png

It would be great to have some util that collects such events into a queue
and then allows systems to handle them correctly.


Reply to this email directly or view it on GitHubhttps://github.com//issues/25
.

from ash.

Gaen avatar Gaen commented on September 25, 2024

Let's assume we have two asteroids overlapping each other, and click should destroy the asteroid. When user clicks twice in the area which belongs to both of the asteroids between the updates, some out-of-update-loop code will record two clicks into the first asteroid. After the update this asteroid will be destroyed by the first click and the second click will be lost, leaving the second asteroid intact. Or, if clicks are recorded into all asteroids that match the coordinates, both asteroids will be destroyed by the first click, which is wrong too.

But your answer gave me an idea to create some ClickComponent instance for every click and allow systems to iterate through ClickNodes, that might work.

from ash.

Gaen avatar Gaen commented on September 25, 2024

Here's the system I've implemented: https://gist.github.com/Gaen/5737335

It catches the events out-of-the-loop, converts them into entities and adds them to the engine, which allows other systems to process those events inside the loop and remove used events from the engine. The system itself executes in the loop after all input processing is done and removes all remaining event entities. So all mouse events live from the moment they happen to the mouse handling system update.

I don't think it's good for perfomance to create a new entity with a new component and then get it through the NodeList and destroy it for every mouse move, but at least it works.

from ash.

nadako avatar nadako commented on September 25, 2024

Wow dude, this looks so over-engineered. I'm not sure that it's a good idea to try to fit everything in the boundaries of ash style. You could just implement some kind of click manager that operates outside of system update loop, reacts to clicks and sets a "clicked" flag to a relevant asteroid entity component to be processed by the system later. And for your overlapping asteroids case, just get the first one without the "clicked" flag set and toggle it. KISS, you know :)

from ash.

Gaen avatar Gaen commented on September 25, 2024

After having a good sleep I've realized all the crazyness of my code (: Yeah, I'm gonna rewrite it into something simple.
But I don't like the idea of putting game-related click processing logic into click manager, because click can select something, or destroy something, or build something depending on context - these are different kinds of logic that should be in a different systems.
I still do like the idea of putting events into some queue, handling this queue by systems and then clearing it for every update. It just shouldn't work through the engine, simple vector is good enough.

from ash.

richardlord avatar richardlord commented on September 25, 2024

Since you implemented this outside of the core code and simply include one line in the core code to initialise it, I suggest there's no need to edit the core code at all, you can initialise your mouse tracking independently of the core code and there's no need to add it to the core project.

from ash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.