Using c++ and using it as a WebAssembly module in Construct 3?

1 favourites
  • 11 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • Hi everyone, has anyone used c++ in construct 3? I suppose it is possible to do it through WebAssembly and js modules. If it is possible, it will be very good!

    c++ works more efficiently than js in several times (sometimes up to 10 times better), it can greatly increase the performance of games!

    Tagged:

  • You’ll need a bad bottleneck to make doing that worthwhile.

  • Yes, you can use WebAssembly - there's even an example of loading WASM.

    However it will not make your game 10x faster. Well-written JavaScript code is exceptionally fast with modern JIT compilers, and can get surprisingly close to the performance of compiled C++. The blog post Is WebAssembly magic performance pixie dust? covers this well - it depends a lot on precisely what you're doing, but the differences are often surprisingly small and WebAssembly is not necessarily even going to always be faster.

  • Ashley Hello! Thank you, we've already done it and we're testing it now. We're just trying to create a game that can handle 1000 moving objects decently, we've already used a few solutions, they were more efficient than the box2d physics, but still very bad on weak devices. And honestly c++ is our last option, we don't know what to do anymore :(

  • 1000 moving objects are quite a lot. Even vampire survivors has "only" about 250 enemies visible at once with very simple logic/sprites, and that game starts chugging hard still if a lot is going on even on reasonably strong machines. It's quite the CPU bottleneck. But I'm curious how your testing goes and if you can achieve better performance like that.

  • WackyToaster I know, it does sound intimidating. But for example, survivor io can handle several thousand enemies. I think this can be achieved, and we will try to get to at least 700 enemies, we are trying to find a way, maybe Ashley can tell us something.

  • It depends on what you're doing, but merely having 1000 objects is not actually that much for Construct - it's more than capable of handling that many objects. For example this blog post demonstrates that even old mobile devices can handle around 10,000 sprites on-screen and still hit 60 FPS.

    If you're using performance-intensive features like Physics, then it may be a different story. But Physics already uses a C++ engine compiled to WebAssembly, so it's probably already about as fast as a native engine.

    Perhaps the problem is the game design, if you're doing something inefficient like nested loops. It depends on your project and it's hard to say more without seeing exactly what you're doing, but Construct is definitely capable of handling 1000 objects smoothly.

  • I haven't played that game, but just from taking a brief look at it... are you sure there are "several thousand enemies" at once? The game states that it has thousands of different enemy types, but that doesn't mean there's a thousand of them running around on the screen at a time. It looks very much to be in the same ballpark as vampire survivors of having maybe a few hundret or so.

    I think some things that can help you are possibly:

    1. web workers for multi-threading construct.net/en/make-games/manuals/construct-3/scripting/guides/creating-workers

    2. Object pooling

    I'd say you could try and split the enemy logic up into batches of ~200 and put them in individual workers. Though admittedly I have no idea if that is a nonsense idea or a good idea, I have no experience in that regard. It just seems like one of the things I'd try and see if it works or not. :V

    And object pooling to avoid having to create hundrets if not thousands of instances every second.

  • Perhaps the problem is the game design, if you're doing something inefficient like nested loops. It depends on your project and it's hard to say more without seeing exactly what you're doing, but Construct is definitely capable of handling 1000 objects smoothly.

    The type of game usually boils down to requiring a ton of collision checks.

    • all enemies with player
    • all enemies with all enemies
    • all enemies with all player projectiles
    • (optional) all enemy projectiles with player

    Doing this every tick, for 1k enemies is heavy. That's another thing that could be done... limiting the tickrate of the collision detection. Instead of doing it every tick, doing it, say, every 0.033 seconds which is equivalent of doing it at 30 fps. 30fps may be perfectly sufficient for this, but you'll have to interpolate the movement otherwise it will also move at 30 fps.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • WackyToasterYes I'm sure of it, there are really a lot of enemies, on the first level with about 10 minutes they go thousands, it certainly does not work perfectly there are also lags, but there are a lot of objects! And thanks for the tips, we will try to apply a lot of things to get good results!

  • Ashley Yes, it seems very effective, but here, for example, objects are static and do not interact with each other. For example, we tried to use the example from R0J0hound(https://www.construct.net/en/forum/construct-3/how-do-i-8/avoid-overlapping-sprites-178823), it works more efficiently than physics, but it is still not able to produce 60 fps at 1000 objects on my PC, while your test with pigs my pc can withstand at 50k objects.

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