Input Polling | Game Engine series

Поделиться
HTML-код
  • Опубликовано: 25 ноя 2024

Комментарии • 96

  • @TheCherno
    @TheCherno  5 лет назад +13

    Thanks for watching guys, hope you enjoyed the video! Code for this video will be up on GitHub in a couple of days, give it a try yourself in the meantime! Next episode is already available for Patrons at www.patreon.com/posts/24599249 ❤️

    • @thommybaez5286
      @thommybaez5286 5 лет назад +1

      TheChernoProject can you make a new java game tutorial but like that also talking about items and how to add an inventory and also a better collision detection (maybe aabb collision detection)

    • @thommybaez5286
      @thommybaez5286 5 лет назад +1

      Thx

    • @hannesblack6949
      @hannesblack6949 5 лет назад +1

      @TheChernoProject. I forked the repo and cloned it, but the external dependencies are missing. Do i need to download them seperately?

    • @carlosgarciavigoa7937
      @carlosgarciavigoa7937 5 лет назад +1

      @@hannesblack6949 Just-> git clone in the same folder is easy!

  • @magictrickdev
    @magictrickdev 4 года назад +21

    13:00 For anyone curious: The final keyword can be specified to the compiler that the virtual method you're overriding can't be overwritten in derivative classes. You call also specify it on the class level as well, meaning that the class can no longer be derived from. Useful if you're making a bottom level implementation that you know you won't be changing. This was added in C++11.

    • @m96fa40
      @m96fa40 8 месяцев назад +1

      I love people with valuable information like you, thanks a lot!

  • @Corgamos
    @Corgamos 5 лет назад +4

    This was one of the best episodes of the series, really well explained, not super fast, live coding with some breaks for explaination.
    Cherno, well done! :)

  • @thehambone1454
    @thehambone1454 5 лет назад +3

    So glad that I am not the only one who is interested in writing custom engines :)

  • @theo-dr2dz
    @theo-dr2dz Год назад +4

    The polymorphism is not necessary here (neither in the window class). The platform will not be decided at runtime, it's known at compile time. So no need at all for runtime polymorphism.
    What he could do (and would be better) is to make an implementation class for every supported platform and include the correct one through the preprocessor. That has zero overhead (virtual functions do have overhead) and the code is simpler.

  • @懋张
    @懋张 4 года назад +1

    Thank you Cherno! Your series helps me out!

  • @arcangel964
    @arcangel964 3 года назад +1

    Polling for yr own sanity sounds wonderfully insane. Hehe

  • @davidledger5941
    @davidledger5941 5 лет назад +16

    Great video as always. But, what about:
    enum class MouseButton : int
    {
    Left,
    Right,
    Middle
    };

    • @SkillTrailMalefiahs
      @SkillTrailMalefiahs 5 лет назад +2

      need explicit
      MouseButton::Left // sucess
      Left // wrong

    • @davidledger5941
      @davidledger5941 5 лет назад +4

      @@SkillTrailMalefiahs Yeah, I like the context, it makes code more readable as you can usually understand enum class function arguments without reading the function signiture, docs or implementation.

  • @CBayonaP
    @CBayonaP 2 года назад +5

    Actually, at 22:00, to access values of a pair you can simply do pair.first or pair.second depending on which element you want to access

    • @123akash121
      @123akash121 Год назад

      believe me dude he has 10x more C++/Programming knowledge than you, he knows that you can do that, he doesnt like it from a code style point of view because it litters the code. The man has built a fully functioning, feature packed game engine ALL ON HIS OWN, you dont think he knows that? I'm not saying he is the be all end all authority when it comes to anything related to programming but you can assume a seasoned programmar like him knows trivial things like that

    • @dylanclarke9497
      @dylanclarke9497 11 месяцев назад +2

      @@123akash121 Bit of a weirdly defensive attitude to a comment with a helpful tip; doesn't need to be something Cherno doesn't already know for it to be helpful to others. I used discards in place of the variable that wasn't returned from the pair i.e `auto[_, x] = ...` which is an even cleaner way of writing it imo but it wasn't mentioned in this video. Not really an issue though because like you said yourself these are trivial things and you can't expect someone building a game engine by themselves to be able to address or do every trivial thing right if they're busy working on a fully featured engine. You took a really weird view on this guy sharing some knowledge as if the great Cherno himself was offended that his knowledge of std::pair was questioned (yet he's actively encourages these types of discussions from what I've seen). If you don't find value in a comment that's cool, but this is a series for beginners making their own game engine, so tips like what this guy originally posted will be of help to someone.

    • @SPL1NTER_SE
      @SPL1NTER_SE 7 месяцев назад +1

      @@123akash121 Were you on your period while writing this?

  • @retroryuu7254
    @retroryuu7254 5 лет назад +7

    I hope Senpai updates the Repository! x3

  • @TheFluffyOtter
    @TheFluffyOtter 5 лет назад +5

    Such a sad face on the thumbnail 😂 great tutorial though as always

  • @majedhk5460
    @majedhk5460 5 лет назад +4

    I can’t wait ,to see how your game engine will look like ! 🤔😴

    • @nullbeyondo
      @nullbeyondo 3 года назад +5

      I'm from the future; It looks awesome!

  • @dawid4450
    @dawid4450 4 года назад +2

    I have a question, at 22:50 why do we need to declare type (Input*) again? and if s_Instance is a private member of an Input class why do we have access to this?

  • @Arteko77
    @Arteko77 4 года назад +3

    How did you do that multi select and remove thing in 17:50 ?

  • @yuno3364
    @yuno3364 3 года назад +1

    should WindowsInput be a final?

  • @armaanc.684
    @armaanc.684 Год назад +5

    For anyone getting an error where the s_Instance conversion from Input* to WindowsInput* is inaccessible, make sure to put public before Input in WindowsInput.h

  • @BlindDemon24
    @BlindDemon24 2 года назад +2

    What is the reason to have
    public:
    inline static bool IsKeyPressed(int keycode) { return s_Instance->IsKeyPressedImpl(keycode); }
    and
    protected:
    virtual bool IsKeyPressedImpl(int keycode) = 0;
    when it could have been only:
    public:
    virtual bool IsKeyPressedImpl(int keycode) = 0;
    ?

    • @cyqry
      @cyqry 2 года назад +4

      Judging by the other comments, the impl versions (short for "implementation) are meant to be used for specific WIndow types, so for example GLFW or HWINDOW. So you would call the IsKeyPressed function which would then call the appropriate implementation that has more platform specific code.

  • @universalkey5451
    @universalkey5451 5 лет назад +1

    Why do we have to make a separate class for input while we can just use the event system to poll input?

  • @yessicasd9402
    @yessicasd9402 3 года назад +1

    I don't get from where is called the Input* Input::s_Instace = new WindowsInput(); if the only file we are including in the Application.cpp is the Input.h

  • @0ichigan06
    @0ichigan06 5 лет назад +3

    So, this whole static - instance thing in input is just a workaround, because it is not possible to override static functions?

    • @Aluminum0013
      @Aluminum0013 4 года назад +2

      No, you can override static functions. This is called a singleton, and is used to prevent holding information in a static only class.

  • @Corgamos
    @Corgamos 5 лет назад +3

    Ok, can somebody once again explain to me, why Cherno created two versions of all the methodes (normal ones and ones with Impl at the end)?

    • @beyondhelp
      @beyondhelp 4 года назад +1

      Same

    • @42mix22
      @42mix22 4 года назад +8

      The methods with Impl at the end are supposed to be overriden and implemented for each platform

  • @eddieh7962
    @eddieh7962 5 лет назад +17

    ok i can understand the programming but how tf does he type so efficiently

  • @pradhivrddhi-research7489
    @pradhivrddhi-research7489 Год назад

    Hello Cherno, thanks for this series, I appreciate it. I wanted to ask for your reason as to why you are using the name GetMousePosition instead of just GetCursorPos like GLFW?

  • @moonding3979
    @moonding3979 5 лет назад +2

    This is my earliest comment for your video hihihi

  • @haos4574
    @haos4574 4 года назад +1

    instead of returning a void pointer, maybe we can typedef a PlatformWindow, like #if GLFW typedef PlatformWindow GlfwWindow* #else typedef PlatformWindow void*

  • @miloz1950
    @miloz1950 4 года назад +2

    I really think I did everything correct, but suddenly at the end when I'm launching the entire project and hovering mouse over the window it throws an error: Debug Assertion Failed! from the sandbox.exe from file: "minkernel/crts/ucrt/src/appcrt/heap/debug_heap.cpp" Line 996. Expression: __acrt_first_block == header. It doesn't occur when the "PushLayer(new ExampleLayer());" is commented. So after some time i noticed that the error started occuring after changing all buildoptions in premake file to runtime and staticruntime. Somebody maybe knows how to fix it? I can provide more information if it will be necessary.

    • @miloz1950
      @miloz1950 4 года назад +5

      So it works fine with "buildoptions "/MDd"", but with "runtime "Debug"" it throws an error (in Debug profile).

    • @神经大
      @神经大 3 года назад +1

      I have the same problem! May I ask you have fixed it?

    • @miloz1950
      @miloz1950 3 года назад +1

      I'm sorry but I don't remember what I've done to fix it.

    • @berrymix3282
      @berrymix3282 3 года назад +2

      Uhm, idk if you're still have this problem, but solution is the following:
      make shure you've removed staticruntime line in every other section but "project" (and it has to be toggled "off") in premake file.

    • @cyqry
      @cyqry 2 года назад +2

      @@miloz1950 Hazel itself is a library (dll file) while Sandbox is an application (exe file).
      /MD and /MDd are the library build options while /MT and MTd are the multi-threaded application build options.
      Cherno did a video in the playlist already discussing this, I believe its in the Github video. Not much code going on in it, its a talking video so I think a lot of people may have skipped over it.
      I would need to check again to be certain but there are TWO lines needed to properly set it. One sets the debug/release state (that lowercase d after the MD/MT) while the other determines if its a library or executable.

  • @PradhiVrddhi-Research
    @PradhiVrddhi-Research Год назад

    Hello Cherno, Thanks for these videos, I appreciate them quite a lot. I believe that if I started with some other started point I would have given up already. I have a question to ask about this video. I could not help but asking, why you are using the name GetMousePosition instead of GetCursorPos like GLFW?

    • @dylanclarke9497
      @dylanclarke9497 11 месяцев назад +1

      GetCursorPos is an alright name but not as descriptive as GetMousePosition imo, both mean the same though so it just boils down to personal preference :).

    • @PradhiVrddhi-Research
      @PradhiVrddhi-Research 10 месяцев назад

      @@dylanclarke9497 Thanks, I guess GetCursorPos might also be more specific to GLFW and the attempt here is to make it more general.

  • @PflanzenChirurg
    @PflanzenChirurg 5 лет назад +1

    Still here!

  • @foureverfour4
    @foureverfour4 4 года назад +1

    do you ever explain how to change screen coordinates to world coordinates for the cursor position?

  • @greenb1ade
    @greenb1ade 5 лет назад +1

    How and where did you learn how to code?

    • @k1ng121
      @k1ng121 5 лет назад +5

      I learned it all from watching yt videos and google. :D

    • @lewisnorth1188
      @lewisnorth1188 5 лет назад +4

      He went to university and did a lot of research and practice there I think

    • @stephen9849
      @stephen9849 4 года назад +5

      From DanisTutorials

  • @watchcrap1
    @watchcrap1 Год назад

    so confused how he could just use "auto [x, y] = Input::GetMousePosition(); " in the Run loop, how is the Input class aware of the functions we implemented on the WindowsInput? I get we overrode the Implementations on WindowInput, but I would have expected to have to use auto [x, y] = WindowsInput::GetMousePosition();

    • @Brad_Script
      @Brad_Script 10 месяцев назад

      in WindowsInput.cpp @23:28 he assigns a new WindowsInput object to Input's static s_Instance variable :
      Input *input::s_Instance = new WindowsInput();

  • @daniilblagiy8741
    @daniilblagiy8741 5 лет назад +1

    Please push the code on github.

  • @gideonunger7284
    @gideonunger7284 5 лет назад +1

    12:36 then make it final? thats what its for

    • @gideonunger7284
      @gideonunger7284 5 лет назад +1

      @@marklinton4567 final is pretty basic tho right? if you are already learning about virtual and override final should be included

    • @gideonunger7284
      @gideonunger7284 5 лет назад +1

      @@marklinton4567 ind thats pretty much exactly what final is for. it doesnt make sense to inherit from windows input

    • @jamesmnguyen
      @jamesmnguyen 5 лет назад +1

      I use final override anywhere applicable.

  • @yousafe0
    @yousafe0 5 лет назад +2

    you never called delete on s_Instance

    • @TheCherno
      @TheCherno  5 лет назад +12

      Why would we need to? There's one instance of it across the entire process, and it exists for the lifetime of the application.

    • @gideonunger7284
      @gideonunger7284 5 лет назад +2

      @@TheCherno Sure but that relies on the os to reclaim the process memory. I dont think that then ever calls the destructor of input instance. that might not cause issues now but a poblem could only be one refactor away. If it was a smart pointer it would be properly cleaned up on shutdown

    • @davidste60
      @davidste60 5 лет назад +1

      @@gideonunger7284 - What kind of problem?

    • @gideonunger7284
      @gideonunger7284 5 лет назад +1

      @@davidste60 Depends on the destructor.

    • @davidste60
      @davidste60 5 лет назад

      @@gideonunger7284 - How can it if the destructor is not called?

  • @thomasknapp7807
    @thomasknapp7807 5 лет назад +1

    I stated this series a couple of months late. I am current at video 9, "Event System", and am having trouble getting the code for that episode, along with spdlog, from the GitHub repository using git. git keeps complaining with fairly terse statements. Might anyone suggest a source for learning how to use GitHub, especially for cloning or downloading older versions of the code? Thanks.

    • @voxelrifts
      @voxelrifts 4 года назад +1

      Check the older commits. Sry for Late reply. :)

  • @simonkgothatso7236
    @simonkgothatso7236 5 лет назад +1

    Hello am new to the channel and i just feel like The compiler that you are using is too complicated for my liking. I find CodeBlocks easy and to the point. Nonetheless, i love what you are doing hands down. Keep on sharing @TheChernoProject👍🏻👍🏻👍🏻

  • @rikseth9606
    @rikseth9606 5 лет назад +1

    Why don't you use Directx?

    • @nikoszervo
      @nikoszervo 5 лет назад +9

      Because people who watch these series and use Linux would not be able to follow along.

    • @bies_moron4404
      @bies_moron4404 5 лет назад +3

      1. Windows only
      2. Harder than OpenGL