FAForever Forums
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Login
    The current pre-release of the client ("pioneer" in the version) is only compatible to itself. So you can only play with other testers. Please be aware!

    Supcom/Moho engine rewrite

    Scheduled Pinned Locked Moved Contribution
    75 Posts 37 Posters 4.6k Views 12 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      hobosapien
      last edited by

      God DAMN this is AWESOME

      S 1 Reply Last reply Reply Quote 0
      • X Offline
        Xiaomi
        last edited by Xiaomi

        @slightlygrilled Hi. I'm very interested in the technical details:

        • Is the simulation single-threaded?
        • Did you use ECS?
        • How much slower is fixed-point math?
        S 1 Reply Last reply Reply Quote 0
        • S Offline
          SlightlyGrilled @Xiaomi
          last edited by

          @Xiaomi Always happy to talk tech πŸ™‚

          is the simulation single-threaded?
          Hell no! πŸ˜„ I want every core i paid for to be used!
          However to be a bit more technical, there are parts that are threaded, and there are parts that are single threaded.

          So the tick runs in stages, which you can see listed here:
          https://github.com/ThomasMonkman/rts-core-engine/blob/develop/docs/architecture/sim.md#the-tick
          normally the way it works is, each stage has calculations done in rust in a threadpool, then lua callbacks happen

          so you end up with a spiky pattern of cpu usage,

          rust multicore --> lua single thread -> rust multicore -> lua single thread

          this is just the nature of how the game was designed, and i am staying combatible to supreme commanders lua.

          I do have ideas for a threadpool lua api, that modders and such could use at will to distribute work to as many cores as they please.

          steps that are expensive enough to justify giving work to a threadpool have that work split up across how ever many cores you have.

          you can see this talked about in this post
          https://forum.faforever.com/post/75138

          with the image below you can see the thread usage

          • each row is a thread
          • workers 0-17 is the general thread pool (i have an 18 core machine)
          • there is a dedicated sim thread
          • dedicated threads for each window/screen
          • 6 render worker threads (these and the window threads have higher OS priority so the sim can't stave out the graphics from actually appearing...)

          you can see in the screenshot below (this is a 64k airfight so its extremely taxing on the lua)
          also its super pixerlated...
          the movement, intel, weapons, projectiles, and transfer sim state to the renderer are all threaded

          cb590dcb-adea-49c4-b710-00301d0fcbbe-image.png

          Not to say this couldn't be improved though! always want more core usage!

          Did you use ECS?
          No, right at the very start i looked at it, and as much as i think its a fantastic data structure, it just doesn't fit supcoms design, as remember i wanted it to be a drop in replacement.
          And in the lua phases there is a ton of random access.

          I do however take in to account the ideas of ECS in terms of cpu cache awareness, and all the "hot" data (data that is accessed in tight loops) is all packed in to dense arrays, with "cold" data stored elsewhere.

          Fixed point vs floating point

          I just ran a quick benchmark for you, of course this is a mirco benchmark, so take with a massive massive grain of salt, as normal code isn't like this, but its the raw numbers.

          β”‚ Operation β”‚ Fx (I32F32) β”‚ f32 β”‚ f64 β”‚ Fx vs f32 β”‚
          β”‚ add β”‚ 0.48 ns β”‚ 0.49 ns β”‚ 0.50 ns β”‚ ~1Γ— β”‚
          β”‚ mul β”‚ 0.50 ns β”‚ 0.49 ns β”‚ 0.49 ns β”‚ ~1Γ— β”‚
          β”‚ div β”‚ 3.9 ns β”‚ ≀0.49 ns β”‚ ≀0.49 ns β”‚ β‰₯8Γ— β”‚
          β”‚ sqrt β”‚ 5.4 ns β”‚ ≀0.48 ns β”‚ ≀0.47 ns β”‚ β‰₯11Γ— β”‚
          β”‚ atan2 β”‚ 12.9 ns β”‚ 2.1 ns β”‚ 4.6 ns β”‚ ~6Γ— β”‚
          β”‚ sin_cos β”‚ 10.4 ns β”‚ 2.3 ns β”‚ 3.5 ns β”‚ ~5Γ— β”‚
          β”‚ vec3 normalise β”‚ 15.5 ns β”‚ 1.0 ns β”‚ 1.1 ns β”‚ ~16Γ— β”‚
          β”‚ quat multiply β”‚ 5.5 ns β”‚ 1.1 ns β”‚ 1.6 ns β”‚ ~5Γ— β”‚

          as you can see it depends what you are doing.

          But what i would say, from my posts above, i don't really believe it matters even though floating point is faster, my engine is still super fast, and im almost fully limited by the single thread nature of supcoms lua.

          X 1 Reply Last reply Reply Quote 0
          • S Offline
            SlightlyGrilled @hobosapien
            last edited by

            @hobosapien Thank you πŸ™‚

            1 Reply Last reply Reply Quote 0
            • S Offline
              SlightlyGrilled @The_Janitor
              last edited by

              @The_Janitor Can you send me the log file please? it should be right next to the exe πŸ™‚

              The_JanitorT 1 Reply Last reply Reply Quote 1
              • S Offline
                SlightlyGrilled @IndexLibrorum
                last edited by

                @IndexLibrorum Hello! I think i have actually spoke to you a bit on the discord, when I've posted links, i think you had ideas on the keyframe stuff with the replays right? well know there in! 🐷

                I'm always happy to chat tech, or anything like that πŸ™‚

                On the speeding up tests, that's actually a great idea and didn't occur to me! thank you πŸ™‚
                I spent a bit of effort to load in the maps as fast as possible before, a main bottleneck for me is some of fafs start up lua is quite slow, although i did some work to speed that up, and the tests do run faster now.
                In reality i run the tests in parallel without the window, that i just measured, completes in 9.49 seconds on my machine.

                I did the screen recording just for visuals πŸ˜›

                But faster is always better!

                1 Reply Last reply Reply Quote 1
                • The_JanitorT Offline
                  The_Janitor @SlightlyGrilled
                  last edited by

                  @SlightlyGrilled
                  https://limewire.com/d/DWWf2#9gbKJxH9UW
                  game.log is uploaded on the link, text size too big to place here, sorry.

                  Secure the kill and send it off.

                  S 2 Replies Last reply Reply Quote 0
                  • S Offline
                    SlightlyGrilled @IndexLibrorum
                    last edited by

                    @IndexLibrorum you peaked my interest on the map loading, so i went and actually timed it.

                    Both the total time with graphics running in a window.
                    and if i run it headless without the graphics.

                    Theta Passage (SCMP_012), 5 km
                    total 0.89 s | map textures ready 0.71 s | sim running 0.75 s
                    (headless total 0.47 s)

                    Open Palms (SCMP_007), 10 km
                    total 0.93 s | map textures ready 0.80 s | sim running 0.78 s
                    (headless total 0.50 s)

                    Seton's Clutch (SCMP_009), 20 km
                    total 1.04 s | map textures ready 0.88 s | sim running 0.87 s
                    (headless total 0.58 s)

                    Gentleman's Reef (SCMP_005), 40 km
                    total 1.38 s | map textures ready 0.87 s | sim running 1.20 s
                    (headless total 0.83 s)

                    Betrayal Ocean (SCMP_029), 81 km
                    total 1.51 s | map textures ready 1.06 s | sim running
                    (headless total 0.91 s)

                    Frostmill Ruins (SCMP_030), 81 km
                    total 1.51 s | map textures ready 1.02 s | sim running 1.34 s
                    (headless total 0.94 s)

                    Debris (X1MP_012), 81 km
                    total 1.45 s | map textures ready 1.21 s | sim running
                    (headless total 0.82 s)

                    1 Reply Last reply Reply Quote 1
                    • S Offline
                      SlightlyGrilled @The_Janitor
                      last edited by

                      @The_Janitor Thanks I will have a look!

                      1 Reply Last reply Reply Quote 0
                      • S Offline
                        SlightlyGrilled @Dim-A-miD
                        last edited by

                        @Dim-A-miD yeah its super cool!

                        In case three isn’t enough and you’d like to bring the total to five...

                        I think this, and your link goes way over my head? πŸ˜„

                        1 Reply Last reply Reply Quote 0
                        • S Offline
                          SlightlyGrilled @The_Janitor
                          last edited by

                          @The_Janitor ok found it, i will release a new version that fixes this, but in the mean time, in your mod folder you have a file mods/auto-upgrading mass extractors.7z

                          my engine is picking this up and thinking its a zip file. if you move that file it should work πŸ™‚

                          but i will also fix this in the next version.

                          The_JanitorT 1 Reply Last reply Reply Quote 0
                          • The_JanitorT Offline
                            The_Janitor @SlightlyGrilled
                            last edited by

                            @SlightlyGrilled said:

                            @The_Janitor ok found it, i will release a new version that fixes this, but in the mean time, in your mod folder you have a file mods/auto-upgrading mass extractors.7z

                            my engine is picking this up and thinking its a zip file. if you move that file it should work πŸ™‚

                            but i will also fix this in the next version.

                            Confirmed, that did it! Game lunches now, thanks!

                            Secure the kill and send it off.

                            1 Reply Last reply Reply Quote 0
                            • X Offline
                              Xiaomi @SlightlyGrilled
                              last edited by Xiaomi

                              fd9e8224-29f0-43cb-86fe-2d5f3bbe542f-image.png
                              @slightlygrilled I see that the lua calls are grouped. I thought there would be a lot of small callback calls and everything would look like "Swiss cheese" XD. So does it queue up the lua callback calls and execute them together?

                              @SlightlyGrilled said:

                              No, right at the very start i looked at it, and as much as i think its a fantastic data structure, it just doesn't fit supcoms design

                              Could you provide more details? Why did you abandon ecs?

                              S 1 Reply Last reply Reply Quote 0
                              • S Offline
                                SlightlyGrilled @Xiaomi
                                last edited by SlightlyGrilled

                                @Xiaomi you can see under lua weapon events, there is the number 13k, that's the individual lua callbacks, I'm just not zoomed in enough to see.
                                And again under lua projectile impacts another ~3k

                                So yes the general setup is rust systems calculate everything, then apply the effects.

                                Actually now I'm looking I need to check that weapon step, and whether its unmarked lua, or native code. Thanks for the curiosity!

                                Ok an update on that, i went and had a look, and it could totally disappear! here you go πŸ™‚ thank you!

                                ad4b6242-b73b-45a8-9591-81e8c83acd8d-image.png

                                This brought the 64k air fight from 307ms a tick to 270ms! (although not in that screenshot, but as an average, Tracy does also slow down the game alittle)

                                On ECS, so from my understanding, ecs is really great when you have tight data you want to iterate very fast, moving as little data as possible from ram to cpu cache.

                                Like if you want to move over every entities health and add regen.

                                It's also great as an abstraction allowing separate systems to just deal with the data they want to deal with, they don't need to know about everything else, they just want to know health, and health regen etc...

                                However in supcom, there is a huge amount of lua, and it's structured around being able to access any of the state at any point.

                                So to this effect, i just store entities (units etc..) in a dense array, and lookup almost instantly by id/index.

                                Another issue is the sim is deterministic, which means i need fixed iteration order, and when looking at the ecs around, they didn't guaranty fixed order, when components where added or removed.

                                This was ages ago i made this choice though, so i could be miss remembering it, or it just straight wrong!

                                And if i do get cache bottle necks on tight systems, i can always move to separate arrays for different parts of the data.

                                Good questions though! happy to discuss more if you have more questions/ideas πŸ™‚

                                1 Reply Last reply Reply Quote 0
                                • SaverS Offline
                                  Saver
                                  last edited by

                                  Hi, do you have any installation guides explaining how I can set up and test your engine? I'm not very familiar with this area.

                                  Thanks for all your great work!

                                  auch mal fΓΌnf gerade sein lassen

                                  M 1 Reply Last reply Reply Quote 0
                                  • X Offline
                                    Xiaomi
                                    last edited by Xiaomi

                                    image.png
                                    @slightlygrilled Am I imagining it, or have we already hit the "ceiling" of the old engine architecture?

                                    To get a noticeable boost, there needs to be the ability to call lua callbacks from workers. And an additional worker for Lua scripts wouldn't hurt either....
                                    This is a big architectural challenge.
                                    But for that the project needs to be rewritten. Although maybe ai agents could handle it XD.

                                    S 1 Reply Last reply Reply Quote 0
                                    • M Offline
                                      MayeulC @Saver
                                      last edited by MayeulC

                                      @Saver this should probably be written in a document somewhere, but:

                                      1. Grab the latest release from the GitHub releases page
                                        a. The most recent one should be on top (biggest version number)
                                        b. look at "assets" at the bottom. You may need to expand the list.
                                        c. Grab the one for the correct platform (windows x64, Macos, etc)
                                      2. Extract it somewhere
                                      3. Launch the executable, it should auto detect the original game and FAF locations if they are installed (if auto detection fails, they can be specified manually, but it's a tad more complex).
                                      4. Bonus: a game.log file is created next to it. Upload it of you encounter any issues.
                                      1 Reply Last reply Reply Quote 1
                                      • S Offline
                                        SlightlyGrilled
                                        last edited by SlightlyGrilled

                                        A new version! (now working with faf 3841!)

                                        https://github.com/ThomasMonkman/rts-core-engine/releases/tag/v0.2.1

                                        Lua Debugging

                                        Thinking of developers, both for the game and modding, i have added debugging! you can see in the video below

                                        • breakpoints
                                        • conditional breakpoints
                                        • seeing variables
                                        • running code live in the console, such as in the video with SetHealth on the scout

                                        https://youtu.be/EZGhvC2t4Uk

                                        a9f6f45e-50b2-4efb-9548-d9295013842c-image.png

                                        this can even be used to debug mods! here is me stepping in to the hooked files of the RNGAI mod (credit to @relent0r)
                                        https://youtu.be/3pvMWk2clw0

                                        3bbeaa29-c283-46e7-9895-e373949dde72-image.png

                                        to try this your self, you can look here
                                        https://github.com/ThomasMonkman/rts-core-engine/blob/main/docs/guides/debugging-lua.md

                                        Improving the stats bar:

                                        The stats I use to see at a glance the performance of the game, both sim and rendering, but it was messy, time for a face lift. Thanks to @MayeulC for prompting and giving ideas for this work.

                                        33bc4a48-40c3-472d-b78b-1dcbe15bf08a-image.png

                                        hover on fps
                                        03eae585-6263-4639-bd48-0994bf1efabd-image.png

                                        hover on sim
                                        200b5f63-b83d-41bd-b412-662871149d22-image.png

                                        and to show off the networking, a very cool networking simulator, now you can pretend to be in Australia (or further) even if your not!
                                        8141d268-89d1-42fd-8d6a-e5c5215a76d6-image.png

                                        Next a series of bug fixes

                                        • Units turn for factory roll off
                                        • Trees now correctly blown away by explosions
                                        • Functions implemented that RNGAI used, which means RNGAI now works :), thanks relent0r
                                        • Mods and maps are loaded with case insentivity, so they now load on linux
                                        • Tree correctly blow away from explosions!
                                        • Blast damage now impacts shields
                                        • Diskwatch now reloads lua,textures,models, etc...
                                        • A vault folder without maps/ or mods/ still mounts
                                        • Closing the second monitor's window closes only that window, instead of shutting the game
                                        • Selection brackets are centred on the mesh, and range rings scale with the map when zoomed out
                                        • Intel is now fully parallel
                                        • Follow weapons are also now fully parallel
                                        • Improvements in movement with turning and corners
                                        • Aircraft refuel while being repaired, and dock at the nearest air staging platform
                                        • Eco stall for both mass and energy now handle like the base game

                                        Also thanks to:

                                        • MayeulC a PR for improving issue onboard, and for detailed bug reports
                                        • relent0r and an94 for bug reports
                                        1 Reply Last reply Reply Quote 1
                                        • S Offline
                                          SlightlyGrilled @Xiaomi
                                          last edited by

                                          @Xiaomi So yes your right, i think I'm approaching the ceiling on what can be done, although I'm sure there are always clever tricks to go further.

                                          Do bare in mind though that, that trace is a 64k air battle, the normal balance of the game simply doesn't run in to that kind of unit count, even if you played with 64 players.

                                          I do think a lua thread pool api could be introduced similar to love2d , but that would really only help with big chunks of work like ai and such.

                                          with this i would imagine some task api where you opt in to certain data (unit position, eco, intel, etc...) to be copied over to an isolated lua thread, then you would set a duration of ticks for the work to be completed in, such that it remains deterministic, if it hasn't completed in time the sim would wait.

                                          something a bit like this in the sim (this is pseudo code just to illustrate the idea)

                                          
                                          
                                          -- Plain-data arguments, deep-copied at post time
                                          local taskArgs = {
                                              thing = 5,
                                          }
                                          
                                          local dueInTicks = 10
                                          
                                          -- Which parts of the sim to copy over
                                          local unitsView = {
                                              fields     = { 'Position', 'Army', 'BlueprintId', 'Health' },
                                              categories = categories.MOBILE,
                                              armies     = 'enemies',
                                          }
                                          
                                          local access = {
                                              Units    = unitsView,
                                              Terrain  = true, 
                                              PathGrid = { 'Land', 'Amphibious' }, 
                                              Economy  = 'own',
                                          }
                                          
                                          -- Which task to run: a module path and a function in it
                                          local taskModule   = '/mods/myai/lua/tasks/threat.lua'
                                          local taskFunction = 'Compute'
                                          
                                          local pending = Pool.PostTask(taskModule, taskFunction, taskArgs, dueInTicks, access)
                                          
                                          -- do more stuff
                                          
                                          local ok, result = Pool.WaitForTask(pending)  -- resumes at exactly post tick + 10
                                          

                                          then the worker script

                                          
                                          function Compute(args, View)
                                              local units = View.Units
                                              local count = units.Count()
                                          
                                              for i = 1, count do
                                                  local position = units.Position(i)
                                                  local health   = units.Health(i)
                                                  -- do stuff thats slow...
                                              end
                                          
                                              return args.thing * 42  -- plain data, handed back at the due tick
                                          end
                                          
                                          

                                          This has the advantage of allowing devs in the lua to break up work in to as many threads as they see fit, and with so many cores now available, more tasks are always better.

                                          https://love2d.org/wiki/love.thread

                                          There is also robloxs thread model where you can have read only access in parallel, and write access is then serialised.

                                          https://create.roblox.com/docs/scripting/multithreading


                                          but yes you are right, it is in conflict with how supcom was made, perhaps another possibility would be to allow some wasm runtime (still allowing scripting of a sorts, just compiled), but I'm not sure if those are actually that much faster than the luau vm.

                                          of course you could move the whole game to native code, but then you lose modding and such...

                                          interesting none the less

                                          1 Reply Last reply Reply Quote 0
                                          • X Offline
                                            Xiaomi
                                            last edited by

                                            @slightlygrilled Do you have an understanding of when your project will be ready for testing in fa-develop? For example, the developers of the project https://github.com/Draiget/faf-re believe that within 3 months the project will be ready for deployment. What are your estimates? It would be nice if you provided some competition.

                                            S 1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better πŸ’—

                                            Register Login
                                            • First post
                                              Last post