Precompiled Headers | Game Engine series

Поділитися
Вставка
  • Опубліковано 27 лип 2024
  • Patreon ► / thecherno
    GitHub repository ► github.com/TheCherno/Hazel
    Instagram ► / thecherno
    Twitter ► / thecherno
    Discord ► thecherno.com/discord
    Series Playlist ► thecherno.com/engine
    Gear I use:
    -----------------
    BEST laptop for programming! ► geni.us/pakTES
    My FAVOURITE keyboard for programming! ► geni.us/zNhB
    FAVOURITE monitors for programming! ► geni.us/Ig6KBq
    MAIN Camera ► geni.us/t6xyDRO
    MAIN Lens ► geni.us/xGoDWT
    Second Camera ► geni.us/CYUQ
    Microphone ► geni.us/wqO6g7K

КОМЕНТАРІ • 99

  • @TheCherno
    @TheCherno  5 років тому +21

    Thanks for watching guys, hope you enjoyed the video! Next episode is already available for Patrons on www.patreon.com/posts/23219836 ❤️

  • @yayl661
    @yayl661 5 років тому +45

    Been here since 2012 with your Java game development series. Just went back and is watching it yet again. Love your videos and keep up the good work :)

  • @shavais33
    @shavais33 3 роки тому +15

    Cherno was wise to deal with this at this point. I didn't separate my engine (into its own project) from my game, and I shut off precompiled headers because I was getting errors about them that I didn't feel like bothering with. After a while my build starting taking quite a while. Way too long. It was really painful, making a little change, and then waiting.. watching.. each file.. take.. multiple seconds.. to.. compile....
    So at one point I spent Several Hours separating my engine from my game, and converting both over to using a .pch. In the engine project I put all the externals into it, and in the game project I put the engine .h's in there, too. Wow, the compile time was a snap after that. It was like a 50x or 100x improvement or something. It wasn't like 20% or 30% better, it was like 10,000% better. Probably a bunch of that I guess is because the engine was by far and away the biggest part of the game at that point.

    • @nullbeyondo
      @nullbeyondo 3 роки тому +1

      I'm sure you've learned a lot and gained experience even if it was painful for you at first. That's a way to learn.

  • @briggsmedia4045
    @briggsmedia4045 5 років тому +1

    I cant wait to start following this series. I'm getting ready for my CPA and CPP and pretty much learning everything except for multithreading. Its one thing to make a few simple apps and another to actually apply c++ on a large scale. atleast for me. awesome work!

  • @kristofgyorffi7703
    @kristofgyorffi7703 3 роки тому +2

    Somebody give this man a medal.

  • @OTC-X1Spacecrafts
    @OTC-X1Spacecrafts 5 років тому +13

    Having just now successfully compiled the project fully. I can say, I really preferred your previous method of instruction. To say this was a challenge...is a severe understatement. I literally wanted to go chain smoke and I quit smoking years ago.

  • @AnythingSoupVODS
    @AnythingSoupVODS 7 місяців тому +3

    I'm not sure about anyone else, but trying to add precompiled headers completely broke my project, 7+ hours of working through everything went down the drain. Be careful to not brick your work like I did!! Hopefully it works out for everyone else lol

    • @stephenyork7318
      @stephenyork7318 Місяць тому +1

      So you weren't using source control then?

  • @_3clipse_
    @_3clipse_ 4 роки тому +1

    I must have drunk the cool-aid... I have started pushing my hand towards the screen at the end of the vids in response...

  • @VladimirDemidovIllusiveMan
    @VladimirDemidovIllusiveMan 3 роки тому +12

    After removing every @/include from every .h file and after adding @/include "hzpch.h" in application.cpp and log.cpp I get 25 errors in Event.h and other .h files that are related to event management (basicly for that I removed all the includes). In @ The Cherno said that it's ok to include the pch file in header files, which I did. I included hzpch.h in Event.h and it fixed all the errors.

  • @ryanbinter2447
    @ryanbinter2447 5 років тому +1

    if you put your logger class in your precompiled header (since you wont change it much) should logger.cpp have #include pch.h? and would logger.cpp be using precompiled headers or would it be set to "not using precompiled headers"?

    • @teiroberts5330
      @teiroberts5330 4 роки тому

      Including. It's the same as when you do #include "headerfile.h" in the source file, except that the #include is in another file

  • @Dante3085
    @Dante3085 4 роки тому +1

    I feel like it's a little weird getting the needed header files like for Event.h by including the precompiled header in Application.h where ApplicationEvent.h is also included later. Feels kind of messy to me. Is that normal ?

    • @_3clipse_
      @_3clipse_ 4 роки тому +1

      Have you watched the Precompiled Headers video? It is part of the C++ series and gives a very good idea of why they are being used.

  • @marotonin7620
    @marotonin7620 3 роки тому +4

    How can I add precompiled header file into a file inside subdirectory? if I use "../pch.h" it won't recognize it it needs to be "pch.h"

    • @VladimirDemidovIllusiveMan
      @VladimirDemidovIllusiveMan 3 роки тому +2

      I had troubles with that as well. Here are the solutions I found to be helpful.
      1. 6:26 make sure that src is in the compiler's include paths. If your pch files are in src as well, then you will be able to use #include "pch.h".
      2. You can also see properties of the log.cpp and application.cpp and in C/C++ -> Precompiled Headers change the Precompiled header file from hzpch.h (default stdafx.h) to ../hzpch.h (just add the "../" in front).
      The second solution is bad though, you will need to change every .cpp precompiled header file, so better use source folder in the compiler's include path.

  • @sgolym
    @sgolym 5 років тому

    I like the new format because it allows you to edit and reedit what you've written without worrying about explaining changes in the video. For these videos I'd rather see a complete, well layed-out concept than "good enough but I'm not changing it since I'm already at 50 min.."

  • @Dante3085
    @Dante3085 4 роки тому +2

    4:50 Can somebody explain to me why he puts in the full path at pchsource "Hazel/src/hzpch.cpp" but only "hzpch.h" at pchheader ?

    • @_3clipse_
      @_3clipse_ 4 роки тому

      He puts in the full path on the premake5 file because that file is instructing the VS compiler to build the solution and it needs the path to be able to do that. he includes hzpch.h in the cpp file because Visual Studio requires that to make a pch file.

  • @junker1128
    @junker1128 5 місяців тому +3

    If anyone had bunch of errors appear while trying to run it after this video, even when the build goes smoothly. Try including "hzpch.h" inside "Event.h". I still don't know why its happening, but my problem got solved.

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

    Adding hzpch.h and .cpp generated all kinds of errors. I did what phee3D said and it works fine now.

  • @bollebips9491
    @bollebips9491 5 років тому +2

    What is the benefit of the whole premake way of creating your project as oppose to just changing the VS project settings directly?

    • @TheCherno
      @TheCherno  5 років тому +20

      Premake can generate many project types, like Xcode or cmake or make files, not just Visual Studio projects. This is important for when we want to support other platforms like Mac and Linux.

  • @miteshsharma3106
    @miteshsharma3106 5 років тому +1

    Why not just use force include instead of including the precompiled header file in each cpp?

  • @johnrussell6971
    @johnrussell6971 4 роки тому +2

    Why does including spdlog.h take so long when compiling a source, and why does the precompiled header not make it faster?

    • @joannam.170
      @joannam.170 3 роки тому

      I was also wondering why that is the case. spdlog does not seem to be small (in terms of lines of code) but maybe I just do not know what a big library is. Or the compiler already optimizes some parts? Would be nice to know

  • @sakuraema914
    @sakuraema914 3 роки тому +2

    Including the pch inside Application.cpp ends up with Sandbox.cpp cannot build as it doesn't include the pch. I have to include the pch into the Appication.h to build Sandbox.cpp.
    Is it a convention or are there any benefits of including the pch inside .cpp but not .h files because the cherno intended to do that I guess?

    • @watchcrap1
      @watchcrap1 11 місяців тому +1

      probably better to include it at the top of your Hazel.h file - the header file while is included in your sandbox cpp file

  • @kite4kin
    @kite4kin 4 роки тому +1

    I am getting errors in SPDLOG after adding pre compiled headers :/ pattern_formatter-inl.h(881): error C2589: '(': illegal token on right side of '::' .i realised it was some error with windows.f MAX macro so I make my own function for max min in pattern_formatter-inl.h and used that

    • @brionholland7739
      @brionholland7739 4 роки тому

      I'm running into the same error, how exactly did you solve this issue?

  • @alooyeg
    @alooyeg 3 роки тому

    cool

  • @bacontf2
    @bacontf2 5 років тому

    Not quite sure what I've done wrong but after creating the pre-compiled header in premake, spdlog has started throwing a bunch of nonsense compilation errors in its own code. I get about 30 errors when I try to build. I had a quick look through Github but I couldn't find anything different to what I've written. Any ideas?

    • @alpasfly
      @alpasfly 5 років тому

      Same problem here. If anyone finds out what's the problem please let us know

    • @marklinton4567
      @marklinton4567 5 років тому +2

      The problem is that including windows.h defines macros for min and max. That macro causes some code in spdlog to be corrupted and you get build errors. I mentioned it on Github a few weeks ago and the spdlog author altered his code to resolve the macro issue. Updating spdlog to a more recent version will fix the issue.

    • @alpasfly
      @alpasfly 5 років тому

      @@marklinton4567 how do you update it? going to the spdlog folder and pulling from github? I've never used a submodule before haha (btw thank you very much, I was completely lost)

    • @marklinton4567
      @marklinton4567 5 років тому +1

      go into your submodule dicrectory (hazel\hazel\vendor\spdlog) and type the following two commands "git checkout v1.x" and then "git pull"

  • @alejandrosalamanca242
    @alejandrosalamanca242 5 років тому +2

    I have a problem I don't understand I did the exact same thing than in the video but I got a bunch of errors related with the libraries not included and I could not figure out, then I decided to add "hzpch.h" to the Sandbox application and now it works and I don't understand why when you didn't add it a worked for you.

    • @rynho7255
      @rynho7255 5 років тому

      Problably something with your premake file.

    • @chris_burrows
      @chris_burrows 5 років тому

      @@rynho7255 Was it? cause mine is doing the same and my premake file is fine.

    • @MyGameDevPal
      @MyGameDevPal 5 років тому +5

      @@chris_burrows You gotta add the precompiled header to the base event header "Event.h"

    • @thomasfrans1185
      @thomasfrans1185 3 роки тому

      For other people who come accross errors, I found it helpfull to look at the commits to Hazel on GitHub and see if he made changes after the video. (this one was added in the next commit for example)

  • @joelincz8314
    @joelincz8314 2 роки тому

    weird I have to add also an include to hzpch.h in events.h or it won't compile for me....I must have done something wrong...

  • @_Nerdiful_
    @_Nerdiful_ 5 років тому +6

    Having an issue where std::string and std::stringstream cannot be used in my MouseEvent.h and KeyEvent.h files but is fine in the ApplicationEvent.h file.

    • @shavais33
      @shavais33 3 роки тому

      is the precompiled header included at the top of the MouseEvent.h or MouseEvent.cpp? Does your precompiled header file #include ?

    • @_Nerdiful_
      @_Nerdiful_ 3 роки тому

      @@shavais33 Don't know, the hard drive I was using at the time was lost

    • @shavais33
      @shavais33 3 роки тому

      @@_Nerdiful_ 1 year. Have you seen my brain? I. I have no words.

    • @NathanKopilec
      @NathanKopilec 3 роки тому +4

      #include "hzpch.h" in your Event.h file

  • @jessefinnegan1719
    @jessefinnegan1719 3 роки тому +1

    For some reason when I did this, I had to add #include "hepch.h" to Event.h to get things to work right, which I didn't see you do. Did I do something wrong? Edit: My bad. I wrote the wrong file name for the header

    • @blenderalien
      @blenderalien 3 роки тому

      Same for me what exactyl did you do wrong? thx

    • @brno322
      @brno322 6 місяців тому

      I got this too and would like to know why

  • @cicciobombo7496
    @cicciobombo7496 5 років тому +1

    Do you have any idea if there is some software for linux kinda like cmake that let's you compile without having to write make files?
    I use VSCode and for very small projects gcc it's fine, with big ones is usually smart to use cmake or similars but for medium-sized projects i'd like to skip the hassle of writing cmakefiles and not having to write an endless g++ command
    Is there a way i can tell to the pc "here, inside this folder there is everything you need, figure it out yourself"? Pretty much like what VS does when you press F5

    • @nikoszervo
      @nikoszervo 5 років тому

      search for plugins but i thing there aren't any. You need to use an IDLE like code blocks which includes a automatic way of compiling source files. Or you can make one program by yourself, to search recursively inside a project directory for source files and generate a makefile. I think GNUS automake utilities let you do something like that.

    • @sconosciutosconosciuto2196
      @sconosciutosconosciuto2196 4 роки тому +1

      I'm in your same situation, how have you done?

    • @nikoszervo
      @nikoszervo 3 роки тому

      By the way you can use premake too lol :p Premake comes for Linux too and can generate a makefiles too!

  • @obi1jim316
    @obi1jim316 5 років тому +1

    Editing the premake lua file always makes me nervous because I named files differently. I do appreciate the video was short and straight to the point. So far, I'm doing good... yep all good. Actually, its around this point where I end up hitting a "wall." Things are going well with the programming, that I feel like I'm going to stubble on a problem that I just can't fix. I've been anticipating this "wall" to hit me, but so far, I've been able to keep up (at least in getting my code to compile correctly). I'm still hopeful that I will make it to the end of this series; I want to, I need to. Another video down and a lot more to go...we can do this. I'll see you on the next video's comment section.

    • @JoseRodriguez-rx4ck
      @JoseRodriguez-rx4ck 4 роки тому

      my advice, do as he does, not because of The Cherno, but for every tutorial, I lernt this the hard way, using my coding style and naming conventions, but when things get complicated it is hard to fix and follow the instructor.

  • @furkancanturan9904
    @furkancanturan9904 5 років тому

    Do you recommend using DLLs rather than PCH? I want to make my engine as modular as possible (for the sake of faster compiles and code pureness) and want to use one of them. DLLs sounds like much easier to manage I couldn't find any resource about writing a DLL and using it in a C++ project in Visual Studio. I would appreciate if you have one, thanks in advance

    • @rynho7255
      @rynho7255 5 років тому

      Turns out we ARE compiling Hazel library into a DLL, but we are also using precompiled headers. The two go along as we use precompiled headers to fasten Hazel compile time and DLL file to fasten Sandbox compile time (it would take longer with static linking)

  • @felix8103
    @felix8103 23 дні тому

    I don't know if anyone's going to reply to this comment after 5 years but anyways... so far, I have been following google's style guidelines for C++. According to the style guide and I think it is logical that the header files should be self-contained, and to make it self-contained, everyone includes the headers that are being used by their header files. However, I noticed that you removed the #include lines from the header files and instead include the precompiled headers into the source files directly... isn't that kind of wrong or something? I only discoved the precompiled headers and now it is confusing me since I include everything necessary to my header files.
    What I am asking is, is there a way to keep the header files self-contained and use precompiled header files? Perheps including pch.h in the project's header files?

  • @jerms_mcerms9231
    @jerms_mcerms9231 4 роки тому

    Adding the pre compiled headers completely destroyed my solutions. I got so many errors I ended up getting a C1903 "unable to recover from previous errors; stopping compilation". I'm not sure what went wrong

    • @jerms_mcerms9231
      @jerms_mcerms9231 4 роки тому

      part of it was adding my pch header to events.h but now I'm getting a bunch of spd log errors. Removing the windows.h from the pch didn't fix it

    • @jerms_mcerms9231
      @jerms_mcerms9231 4 роки тому

      I must've fat fingered it and some how removed Core.h (aka Base.h) from Log.h

  • @mimoshpisholack
    @mimoshpisholack 3 роки тому

    I also forced to use the hzpch header on the SandboxApp.cpp too, otherwise it would generate 25 unrelated error on the Hazel engine itself... :/

    • @mimoshpisholack
      @mimoshpisholack 3 роки тому

      is it regular?

    • @wiiion1256
      @wiiion1256 3 роки тому

      @@mimoshpisholack i get the same error, did you fix it?

    • @mimoshpisholack
      @mimoshpisholack 3 роки тому

      @@wiiion1256 Unfortunately due to lack of time issue, I didn't continue with videos, but I had some error, which I could fix by checking the past commits, mentioned under some of these videos...

  • @tuni7264
    @tuni7264 5 років тому

    r u going to use opengl or Vulkan or both as a renderer?

  • @Xxp0r
    @Xxp0r 5 років тому

    Opinion on Bazel.build?

  • @alpasfly
    @alpasfly 5 років тому

    Is anyone else getting an error saying "fatal error C1854: can't override precmpiled header"? I can't build the Engine project with the PCH option enabled

    • @alpasfly
      @alpasfly 5 років тому

      Just in case anyone else runs into the same issue: deleting the bin-int folder and recompiling seems to have fixed it

  • @pulkitkhagta4218
    @pulkitkhagta4218 5 років тому +8

    I did exactly as in the video but i am getting errors with all the header file in the Events directory but if i add "include "hzpch.h " " in Events.h header file , the problem seems to resolve. But in video it's not added so i don't understand what i did wrong that i got this error.

    • @bidkonic
      @bidkonic 5 років тому

      You are not alone here.

    • @Maddin0816
      @Maddin0816 5 років тому +2

      Having the same problem here.. The only thing he builds is the "Hazel" project, and NOT the Sandbox. I think that's why he doesnt recognize the missing include.

    • @trevorclelland9458
      @trevorclelland9458 5 років тому +23

      Removing #include "Events/Event.h" from Application.h solved this for me. If you followed Cherno's GitHub diffs for the Event System video, you probably have the same error. It seems like this was an unnecessary include. You get errors in Events/Events.h because (unlike the .cpp files) Application.h doesn't include hzpch.h before including Events.h

    • @seopi
      @seopi 4 роки тому +1

      @@trevorclelland9458 Thanks!!

    • @noesechet1026
      @noesechet1026 4 роки тому

      @@trevorclelland9458 you are a legend

  • @kruplattila
    @kruplattila 3 роки тому

    That's not a cross-platform solution, is it?

    • @krupt5995
      @krupt5995 2 роки тому +1

      No but using premake you can make it available to other platforms as well

  • @Thiago1337
    @Thiago1337 5 років тому +1

    Hello Cherno, what's your name my man?

    • @SuviTuuliAllan
      @SuviTuuliAllan 5 років тому +1

      It's Inigo Montoya.

    • @coltonmcgraw5328
      @coltonmcgraw5328 5 років тому +2

      Yan Chernovic (I'm 99.9% sure that I spelled the last name wrong.) :P

    • @almicc
      @almicc 5 років тому +2

      Yan Chernikov
      (from his Github profile)

  • @joahimwionek714
    @joahimwionek714 5 років тому +1

    It would be very nice if you stay a bit longer with 2d graphics. I could not find any information how to create a renderer that allows us to efficiently use different shaders, do stuff like gradient, rounding corners and more nice things that would make our game/ui superb.

  • @INeedAttentionEXE
    @INeedAttentionEXE 5 років тому

    I think I’ve learned to be addicted to optimizing code. I spent hours adding a configuration class/file and making stuff look nice.
    Totally random comment but with how you program it makes me aspire to make the best code I can.

  • @doctorwin64
    @doctorwin64 3 роки тому

    tooooo hard to follow

  • @kirafortherescue7756
    @kirafortherescue7756 5 років тому +1

    Can you put any background music in the video like on 3-9% volume? That'd make it relaxing or maybe more energetic; That depends on the music for sure; So we can concentrate on the tutorial without getting tired since music also gives us some kind of energy besides, i.e coffee.

  • @saskiafalken6350
    @saskiafalken6350 3 роки тому

    *adding precompiled headers hehe FU! viewers!* *spdlog not found and 40 other random errors teeehee*