How do I solve perf issues (real time tilemap grid update) ?

0 favourites
  • 5 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • Hi everyone !

    I have big performance issues with my current game project (a real time tactical game, with terrain invasion (like Splatoon or Starcraft's Zerg creep !)).

    100% CPU usage and 4~10 FPS.

    The game area is a 40x40 grid, made of 32x32 pixels Tiles (1280px wide)

    There is a 3D Array to save Race (humans, aliens,...), Type (hill, river, building,...) and Discovery Status (yes or no).

    And there is a Fog of War function : units explore to reveal the map, and all the tiles = PlayerRace are auto-discovered (on layout start if any, or at anytime).

    The goal : units move on a yet undiscovered and neutral map, and they can explore and invade tiles (=> the tile image changes according to the race it belongs).

    I first created the grid with sprites (using several animations and frames to display the various informations but there should be 5 races, with a lot of tiles each. One tilemap per race seems the best deal, for me). For now, I work with a single TileMap containing the 6 Race Color Tile Sprites and Fog Tile Sprite.

    But as I'm learning more and more about C2, I want to improve my event sheet with less events, and more complicated stuff (loop). I thought it'd be a good idea to use tilemap and For Each (already used and approved for my training game JumpLin Game (check my profile)).

    Now I don't know what to do to make this system work.

    The current code :

    (on start of layout, the array is filled with a "0" value. In 1D, it's for neutral ownership. In 2D for the basic environnement. In 3D for "undiscovered" status. And after that, the grid is filled with tiles, all neutral for now).

    Screenshots :

    The CPU killer code :

    Few adjustments. No more 100% CPU, 15FPS... but no tiles displayed X)

    For Each XYZ element :

    ___ check Z = 2 ||||||||||||||||||| Set Fog of War Tile Sprite

    ___ check value = undiscovered

    ___ check Z=2 |||||||||||||||| Set Race Tile Sprite (according to Z=0)

    ___ check value = discovered

    ___ check "Race on Tile = Player Race" ||||| Set Tile to discovered (in Z=2)

    ___ For Each FamilyUnits

    ________ -3 < X > +3 ||||||||||||||| Set Tile to discovered (in Z=2)

    ________ -3 < Y > +3

    All the planned functionalities are not yet added and it already doesn't work ! X)

    What can I do please ?

    Go back to Sprites, animations and frames ? (I don't think the problem is here...)

    Improve my usage of "For Each" loop ?

    Don't use a single Array ?

    Functions ?

    Thank you for your help ! I hope i've been clear (sorry for my bad english).

  • Not a 'functional' capx. Just demonstrating how to pick tiles, change tiles, pair an array with a tilemap, avoiding huge loops each tick .... ... .capx?dl=0

  • Thank you !!!! That's exactly what I was looking for

    Using local variables and loopindex to apply changes only on the concerned tiles, and apply tiles on an *area*.... I didn't know these techniques yet. Brilliant ideas !

    Thanks again. Go back to work

    However, I have few questions left :

    • The "For Each [Family]" pick all objects of the family and apply the action every tick. No need to add a "Every tick" condition. That's right ?
    • therefore, there's no need to set the same events on start of layout, as soon as there are active for every tick ?
    • Is it normal that the game runs slower in debug ? Moreover, I have 10fps with "inspect" window opened, and when i switch to "profile" window, 120fps are back. Usual too ?
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • More optimised trail. Now there is not 1 huge array iterating, max 12 tiles change in 1 tick. ... .capx?dl=0

    'For Each' runs every tick. And that is a loop each tick.

    In my capx, things got prepared in the 'start of layout'. The situation how it is before the player starts moving. That is essential. It also cages things that have to be done only once, effectively to only once.

    You will never ever see a good representation of the fps on the inspect page in the debugger. That is actual (Heisenberg principle) very normal. The debugger is a program that runs in the same time and in the same browser as the game. If the debugger has to calculate a lot, like representing an array each tick, the tick (containing games actions + debugger actions) gets longer, leading to a smaller fps.

    Use 'watch' or 'profile' to measure speed.

    Use 'inspect' (or things added to watch) to inspect values.

    I also have to add that when the debugger (in inspect mode) drops the fps to much, collisions, frame independed actions and frame independed behaviors will actual break.

  • Wow, this second file is more complicated... X) I didn't understand what you're doing... But anyway, the 1st one helped a lot and unlock my dev process ^_^

    It looks more complicated for almost the same result... What are the differences please ? And how could it help me in my game ?

    On start of layout, you place buildings, and unlock fog of war around friendly building. But after that, all the things with wallclocktime and Array... Didn't get it X)

    Are you adjusting the array size and values according to the tiles (type and position) around the player ? If so, that's clever. But it didn't suit to my game, where there are several units (like any tactical/RTS game, like Men of War, Company of Heroes, Starcraft,...)

    And thank you for your answer about For Each and Debug. I understand better now

    This project is very important to me. So... if I become popular with it, I will not forget your help ! ^_^

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