heavy events every second instead of every tick

0 favourites
  • 3 posts
From the Asset Store
Very simple code without excess options (15 events for server and 11 events for client)
  • This blog post by Ashleyhttps://www.construct.net/en/blogs/construct-official-blog-1/optimisation-dont-waste-time-768

    does this suggestion:

    Here is my question:

    Assuming you do the check every second instead of every tick (and the seconds are in sync per instance not offset to each other) wouldn't you instead of having a lower framerate overall, just end up with a stutter every second.

    And going of the idea that a lower, consistent framerate is more desirable than a faster but inconsistent framerate, wouldn't this be a worse experience?

    Or am I misunderstanding how the cpu handles these tasks and how they affect the framerate?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well check for collisions every second wont work anyway.

    You would miss collisions.

    Then a little less for is overlapping, maybe.

    With something like bullet you could check by step, but the most effective methods are reducing objects, and area.

  • That blog post was written a decade ago (!) and was mainly trying to make a different point about not fussing over pointless performance questions - there's more useful and more up-to-date advice in the manual section on Performance Tips.

    The specific example with collision checks was probably made redundant by the subsequent collision cells optimisation, which is far faster, assuming the objects are all reasonably spread out. It completely avoids the N x N collision checks scenario.

    However there are still other ways you can end up with, say, 10000 tasks that you want to perform every tick. It's true that if you can't do that in one frame, then doing it irregularly will jank. Here are some better ideas:

    • Only do some of the tasks, rather than all (e.g. for content on screen or near the viewport, rather than across the whole layout)
    • Lazy-compute things when actually needed - i.e. don't do any of the tasks, but if you detect that 100 of them need doing in response to some player input, perform those on demand
    • Spread the tasks out by rotating through them, e.g. doing 1000 tasks per tick, meaning it takes 10 ticks to rotate through all 10000 tasks. (Note however this adds a subtle framerate dependence, so it may have to be designed carefully.)
    • Redesign things so you don't need to do that in the first place (which depends on what exactly you're doing)
    • If you're willing to write JS code, you could start a Web Worker and crunch through all the tasks in parallel to the game running without affecting the framerate at all. (The Pathfinding behavior adopts this approach internally so expensive pathfinding calculations don't affect the framerate, no matter how heavy the workload.) Not all types of tasks lend themselves to this approach though.

    In general, be a little wary of advice from posts that are many years old! Things change a lot over time.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)