• sp3ctr4l@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    2
    ·
    2 months ago

    … Ok, that is legitimately impressive, from a technical standpoint.

    Lua is a high level, not exactly very ‘fast’, very performant language. It is designed to be very, very human readable, and coding noob friendly.

    Getting a 3D physics engine to work … in lua… is not something I would have thought possible.

    Usually you need to use a much lower level language to … actually do that.

    • everyonesconnected@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      0
      ·
      2 months ago

      So from what I can read, the Morrowind Script Extender uses LuaJIT instead of regular lua, which does tracing just-in-time compilation. Meaning, and I’m just paraphrasing wikipeda here, it compiles frequently executed sequeneces of operations into machine code.

      • sp3ctr4l@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        0
        ·
        edit-2
        2 months ago

        Now, that is a very relevant detail!

        I did not know LuaJIT was even a thing.

        Still probably not as performant as … C++ or Rust or something, that is totally precompiled… but that would explain how this is even possible, a 3D Lua based physics engine.

        Yeah, looks like LuaJIT passes a bunch of the Lua code into C, just good ole C, and then dynamically compiles it, then runs the ‘translated’ C code.

        That makes a lot more sense lol.

      • sp3ctr4l@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        0
        ·
        edit-2
        2 months ago

        I haven’t benchmarked anything in a while, so it is possible Lua is more performant now than it once was… but in my (out of date) experience, python is faster than Lua, and nearly every language that is actually compiled is… one or two or three orders of magnitude faster.

        Though it is also worth mentioning that Lua is fairly simple to plug in to some kind of database language, which can result in reasonably good performance in situations involving say… dynamically spawning or unspawning tons of inventory style minor items, or containers with them.

        Lua has been fast enough to handle a simple 2D physics engine… but this is the first time I am hearing of it handling 3D.

    • datavoid@lemmy.ml
      link
      fedilink
      English
      arrow-up
      0
      ·
      2 months ago

      It is designed to be very, very human readable, and coding noob friendly

      As someone who can’t wrap my head around lua syntax, I will have to assume I simply have too much coding experience

      • sp3ctr4l@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        0
        ·
        2 months ago

        I know what you mean lol, but Lua is very noob friendly… it goes fairly far out of its way to make many common functions and data types as compatible with each other as possible… so thats another way it is generally more slow, but also more forgiving, won’t just totally error out and be frustrating to a beginner coder.

      • gradual@lemmings.world
        link
        fedilink
        English
        arrow-up
        0
        ·
        2 months ago

        Yeah, I remember using LUA back in the day for gmod.

        Hands down one of the shittiest languages I ever touched, right down there with PHP.

        Really puts into perspective how stupid developers can be when deciding the tools that they use.

    • gamer@lemm.ee
      link
      fedilink
      English
      arrow-up
      0
      ·
      2 months ago

      Imma be the guy and drop an ackshually

      • Nothing about Lua would make it difficult to implement a physics engine in it compared to other languages
      • The hardest part would be integrating with Morrowind’s systems. If the engine doesn’t expose e.g. collision geometry to scripts in an efficient way, then you’ll run into some real challenges
      • Even without LuaJIT, there’s no reason to expect performance so bad you can’t implement realtime rigid body physics. Interpreted Lua is fast, but even if it wasn’t, a 60 fps performance target for physics is not tough to achieve at all
      • sp3ctr4l@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        0
        ·
        edit-2
        2 months ago

        Nothing about Lua would make it difficult to implement a physics engine in it compared to other languages.

        Correct, but said implementation will be orders of magnitude slower than implementing at a lower level… meaning you cannot handle lots of objects, you can only handle a few, and only with a few players if this is all networked… otherwise you get massive physics calculation innacuracy, terrible performance spikes, crashes, and if networked, server hangs/stalls, huge desync, etc.

        The hardest part would be integrating with Morrowind’s systems. If the engine doesn’t expose e.g. collision geometry to scripts in an efficient way, then you’ll run into some real challenges.

        I mean… that is true, that having to emulate collision meshes/hulls would be less efficient than just actually having direct access to them… but that would be the case with any language, and Lua is still much slower at any real time collision mesh/hull emulation than doing the same in a lower level language.

        Even without LuaJIT, there’s no reason to expect performance so bad you can’t implement realtime rigid body physics. Interpreted Lua is fast, but even if it wasn’t, a 60 fps performance target for physics is not tough to achieve at all.

        You say that, but I’ve never seen it done well in a way that can scale for many tens or hundreds or thousands of 3D physics calls in a complex single player scenario, or a multiplayer scenario where you now also have to account for networked synchronization.

        Not saying its impossible, just saying it… I’ve never seen anyone pull off an efficient and accurate 3D physics engine in Lua, untill now with this LuaJIT implementation.

        If you can show me a high performance 3d physics engine written entirely in just straight up Lua, well please do show me, and share with the class.

        My guess would be that it would be constrained to either specific physics scenarios, as in, wouldn’t have as full a realistic physics feature set… wouldn’t handle well a lot of simultaneous intersctions… but I’m open to being surprised.

        Like uh, Godot’s Jolt physics are written in C++…

        …and while this used to basically be an addon, that was better than Godot’s default physics engine…

        …even Jolt isn’t nearly as efficient or accurate as say, Valve’s implementation of Havok in Source.

        Godot has been catching up with Unity on this physics engine performance front, but Unity still has the performance edge by a bit, and neither are close to Source.

        And these are all C++ physics implementations, to the best of my knowledge.

        • gamer@lemm.ee
          link
          fedilink
          English
          arrow-up
          0
          ·
          2 months ago

          Correct, but said implementation will be orders of magnitude slower than implementing at a lower level…

          “order of magnitude” typically means 10x. A reasonable Lua implementation of rigidbody physics isn’t going to be 10+ times slower than an equivalent C++ version. C++ provides a lot more tools for optimization than Lua, so you’re unlikely to find a truly apples-to-apples comparison showing the difference between a Lua and C++ that isn’t a benchmark of the particular algorithms in the implementations.

          To be clear, I’m not saying Lua is faster or as fast as C++, just that you’re making it sound as if Lua is too slow for something like this. I know this isn’t a programming community, but we’re talking about programming languages, so I feel compelled to point stuff like this out.

          meaning you cannot handle lots of objects, you can only handle a few, and only with a few players if this is all networked… otherwise you get massive physics calculation innacuracy, terrible performance spikes, crashes, and if networked, server hangs/stalls, huge desync, etc.

          None of this is true.

          … than just actually having direct access to them… but that would be the case with any language …

          It is specifically a problem with embeddable languages like Lua because they’re limited by what is exposed to its VM and how. In the context of modding physics into Morrowind, it’s possible that not everything you’d need is cleanly exposed through Lua (which afaik is implemented with a third party plugin and not natively supported).

          Not saying its impossible, just saying it… I’ve never seen anyone pull off an efficient and accurate 3D physics engine in Lua, untill now with this LuaJIT implementation.

          At the risk of sounding like a dick, I think you’re bullshitting. I doubt you’ve ever seen any physics engine implemented in Lua before, much less benchmarked them or evaluated them for their “efficient” and “accurate” qualities (which are meaningless terms). Lua physics engines certainly exist, but they’re mostly gimmicks interesting to developers to study/learn as there aren’t many real world use cases for something like that. There are few reasons to choose that over a C++ physics library, not because Lua is slow, but simply because C++ is faster, and the libraries are typically much more mature and feature-rich.

      • Zahille7@lemmy.world
        link
        fedilink
        English
        arrow-up
        0
        ·
        2 months ago

        Project Zombie and GMod both use Lua scripts. GMod is also one of the best physics sandboxes imo, and has like the most mods on the workshop ever.

        • Leuthil@lemmy.world
          link
          fedilink
          English
          arrow-up
          0
          ·
          edit-2
          2 months ago

          The physics in GMod isn’t implemented in Lua though. It was already part of the Source engine.

          Unless GMod isn’t referring to Garry’s Mod.

        • sp3ctr4l@lemmy.dbzer0.com
          link
          fedilink
          English
          arrow-up
          0
          ·
          2 months ago

          Project…Zombie?

          Do you mean Zomboid?

          If so, Zomboid isn’t … the physics aren’t done in Lua.

          The base of the game is written in C++, and then certain parts of that are exposed to modders via an API that works with Lua.

          https://expertbeacon.com/is-project-zomboid-java/

          The physics engine is written in C++.

          Because Lua is waaay too slow, and even compiled Java is about 4x as slow as C++.