Using C# Scripting with the Entity Component System // Game Engine series

Поділитися
Вставка
  • Опубліковано 27 лип 2022
  • Stream ► / thecherno
    Support the series and Hazel! ► / thecherno
    Main Channel ► / thechernoproject
    Code ► github.com/TheCherno/Hazel (scripting branch)
    CHAPTERS
    #Hazel #GameEngineSeries

КОМЕНТАРІ • 35

  • @KennyTutorials
    @KennyTutorials Рік тому +1

    If I am not aware, if we do not hold script instance using mono_gc_handle_new, then after 50 or 60 seconds in runtime, mono will delete the script instance and crash. I think this is because we initialize the script on the c++ side and not in the c# scope. And in on runtime stop we have to release this gc handle so that mono GC can delete this object later. Peter knows about this problem, I think.

  • @zdspider6778
    @zdspider6778 Рік тому +1

    23:44 There's no need to use "fmt::format". The "std::string" class can append "const char*" as long as they're on the right:
    fullName += nameSpace;
    fullName += ".";
    fullName += name;

    • @ChernoUnplugged
      @ChernoUnplugged  Рік тому

      fmt::format is superior (performance-wise) and one line of code instead of the three that you've written. It's also just generally easier to read imo

  • @miko007
    @miko007 Рік тому +4

    i feel like the script component should take the actual c# source file as an argument and JIT compile it.
    the sole reason one would like to have a scripting language usually is the convenience of not having to compile while writing gameplay code.
    this "prebuild c# dll" feels a bit odd tbh...

    • @ryan6102
      @ryan6102 Рік тому +1

      iirc the end goal is that the engine will compile it for you after it detects changes to your C# code. Regardless, there isn't much difference, between an end-user compiling the DLL themselves vs the engine compiling it for you. I imagine it'll take the same amount of time.. one is just a different workflow. Although I see your point.

  • @thatguy7595
    @thatguy7595 Рік тому +5

    *Godot devs spending years on 4.0 Vulkan rewrite*
    Cherno: I'm going to do it in one day

  • @zdspider6778
    @zdspider6778 Рік тому

    1:21:56 Is there a particular reason why the EnTT id can't be used instead of an UUID? The underlying type is just a uint32_t if I'm not mistaken. Or can be statically casted as such. uint32_t gives you ~4.3 billion entities.
    I ended up completely removing the "ScriptClass" and "ScriptInstance" classes and just added the pointers (MonoClass*, MonoObject*, MonoMethod*) to the script component struct itself. And only storing MonoClass* pointers in that unordered map, no need for two unordered maps.
    So many functions that call other functions that call other functions that....... Don't these have a performance penalty?

    • @ChernoUnplugged
      @ChernoUnplugged  Рік тому +1

      - Entities aren't just created locally, they can be created all over the place - picture a team developing a game and constantly creating identifiers for assets, entities, scenes etc. So we definitely can't just use an ascending index like entt uses for identification, hence we use randomized IDs. Aside from that, with a 32-bit integer it's not that improbable to get a collision (meaning we create an entity with an ID that's already in use), which is why we use 64-bit identifiers
      - Ultimately no, there will be no performance penalty. This is just largely an abstraction we ourselves create, the compiler will inline most of these functions and they will all disappear into pretty much nothing. This has also partially been written with future features in mind

  • @Bodyja
    @Bodyja Рік тому

    Just like a side note, I like to check for non-empty c-str like this: if(str && *str)

  • @mr.mirror1213
    @mr.mirror1213 Рік тому +5

    3 6 0 p g a n g

  • @tiagocerqueira9459
    @tiagocerqueira9459 Рік тому

    Astigmatism tribute

  • @Bloodlinedev
    @Bloodlinedev Рік тому +2

    I'm with Jonathan Blow, after thinking about it I'd rather write everything in one language, both engine and game, and have a powerful visual/data driven scripting solution. Unity basically came to the same conclusion, but the performance of C# becomes a problem, hence the high speed C# with specialized compiler.
    Hot reloading C++ is possible. Access voilation as exception is possible. Yes, the std lib is shait. Yes, the syntax is shait. But for the engine you have to do your own libs anyway. And the syntax can be alleviated by exclusively using modern C++. And if that's not good enough I'd think about using a different language for the whole thing. Compile speed, if done right, should honestly not be a problem. My medium sized Unity project takes like 5-6 seconds to reload which feels like an eternity.

  • @hayrettinakl365
    @hayrettinakl365 Рік тому

    Thanks

  • @devinschlegel1763
    @devinschlegel1763 Рік тому +1

    is this missing from the github for anyone else?

    • @mjthebest7294
      @mjthebest7294 Рік тому

      Checkout the scripting branch

    • @devinschlegel1763
      @devinschlegel1763 Рік тому

      @@mjthebest7294 in the next stream he said he forgot to commit it, but thanks for the tip

    • @mjthebest7294
      @mjthebest7294 Рік тому +1

      @@devinschlegel1763 oh, excuse me, I misunderstood :) have a nice day ^^

  • @rdxrid
    @rdxrid Рік тому +7

    Hey Cherno, what do you think about C++ scripting? :)

    • @nexovec
      @nexovec Рік тому +1

      You wouldn't use C++ for scripting specifically, because it has following disadvantages:
      1. You have to rely on platform specific ways of dynamically linking the scripts to the engine (or some other complicated things).
      2. If you need a feature that is really performance critical, you can write it inside the engine directly using C++ anyway.
      3. C++ is hard and unpleasant to work with (But there haven't been any real alternatives until like a years ago)
      4. C++ ABI is a giant pain (never worked with it though, so don't listen to me).
      5. Some people say you likely should use neither scripting nor an engine at all and just make the game (yt: 'Jonathan Blow on scripting languages').

    • @rdxrid
      @rdxrid Рік тому

      @@nexovec I respectfully disagree with 3 & 4. Also your point 1, I've done it and it's not that hard :)
      Point 2: Everyone might not have access to the engine core
      Point 5: It's ok not to use an engine for solo projects. But when you need to be able to make a variety of games in it, you need one. + everyone is not a programmer ;)

    • @thatguy7595
      @thatguy7595 Рік тому

      What do you guys think about assembly scripting?

    • @rdxrid
      @rdxrid Рік тому

      @@koki10190 And I have done it in Windows :)

  • @lightknight876
    @lightknight876 Рік тому +2

    480p gang over here!!

  • @nexovec
    @nexovec Рік тому

    finally, HD.

  • @itr00ow93
    @itr00ow93 Рік тому +9

    360p gang

    • @p3rk4n27
      @p3rk4n27 Рік тому

      Nah, 144p

    • @itr00ow93
      @itr00ow93 Рік тому

      @@p3rk4n27 I don't even have 144p, only 360p

    • @ermilburn02
      @ermilburn02 Рік тому

      I'd almost rather watch it on Twitch until the HD version finishes processing.

    • @random_guy_on_the_internet69
      @random_guy_on_the_internet69 Рік тому

      @@itr00ow93 I have both

    • @limieon
      @limieon Рік тому

      Only 360p (I know that it's because the video is new)

  • @pavidloq
    @pavidloq Рік тому +2

    360p.

  • @phum1776
    @phum1776 Рік тому

    Why this recommend for musicians

    • @thatguy7595
      @thatguy7595 Рік тому +1

      UA-cam recommends diversifying your interests in case musicians were to go out of favor

    • @zdspider6778
      @zdspider6778 Рік тому

      Sea Sharp is a musical notation. Someone used that symbol in the chat (♯ vs #) and UA-cam picked it up, and now you're here. The algorithm will probably pick THIS comment up and add it to the mix.