• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Ty Typhoon
      I like to build my A - Team now.
       
      I need loyal people who can trust and believe in a dream.
      If you got time and no need for direct pay please contact me now.
       
      We cant pay now, you will recieve a lifetime percentage if the released game will give earnings. 
      If I get the best people together for a team, everything should be possible.
       
       
      What i need:
      - Programmer c++
      - Unity / Unreal - we must check whats possible, please share your experience with me.
      - Sculpter, 3D Artist
      - Animator
      - Marketing / Promotion 
       
       
      What i do:
      - Studio Owner
      - Director
      - Recruit exactly you
      - Sounddesign
      - Main theme composing
      - Vocals
      - Game design
      - Gun, swords, shields and weapon design
      - Character, plants and animal design
       
       
      Please dont ask about the Name of the Game, about Designs or Screenshots.
      The game will be defintitly affected about our and your skills if you join the team.
       
       
      Planned for the big Game:
      - 1st person shooter
      - online multiplayer
      - character manipulation
      - complete big open world with like lifetime actions and reactions
      - gunstore with many items to buy
      - many upgrades for players
      - specials like mini games
       
      So if you are interested in joining a team with a nearly complete game idea, contact me now and tell me what you can do.
       
      discord:
      joerg federmann composing#2898
       
       
    • By codelyoko373
      I wasn't sure if this would be the right place for a topic like this so sorry if it isn't.
      I'm currently working on a project for Uni using FreeGLUT to make a simple solar system simulation. I've got to the point where I've implemented all the planets and have used a Scene Graph to link them all together. The issue I'm having with now though is basically the planets and moons orbit correctly at their own orbit speeds.
      I'm not really experienced with using matrices for stuff like this so It's likely why I can't figure out how exactly to get it working. This is where I'm applying the transformation matrices, as well as pushing and popping them. This is within the Render function that every planet including the sun and moons will have and run.
      if (tag != "Sun") { glRotatef(orbitAngle, orbitRotation.X, orbitRotation.Y, orbitRotation.Z); } glPushMatrix(); glTranslatef(position.X, position.Y, position.Z); glRotatef(rotationAngle, rotation.X, rotation.Y, rotation.Z); glScalef(scale.X, scale.Y, scale.Z); glDrawElements(GL_TRIANGLES, mesh->indiceCount, GL_UNSIGNED_SHORT, mesh->indices); if (tag != "Sun") { glPopMatrix(); } The "If(tag != "Sun")" parts are my attempts are getting the planets to orbit correctly though it likely isn't the way I'm meant to be doing it. So I was wondering if someone would be able to help me? As I really don't have an idea on what I would do to get it working. Using the if statement is truthfully the closest I've got to it working but there are still weird effects like the planets orbiting faster then they should depending on the number of planets actually be updated/rendered.
    • By BenjaminBouchet
      Learning game development in Unreal Engine could be a daunting task for someone who don’t know where to start, and a cumbersome process if you don’t organize your progression correctly. One thing commonly known by experienced developers and by people unfamiliar with coding: mastering a development language is a long and difficult task.
      From blueprints to C++ in Unreal Engine
      If you want to learn fast, you need a good learning strategy. Unreal Engine contains a very powerful tool which you can use to learn C++ faster: its blueprint system. Blueprints are extremely easy to learn (and you may already have a good knowledge of them). Thus you can conveniently use them as a guide for writing code in C++. This is the reason why I am writing a tutorial series on how to make the transition from Unreal Engine blueprints to C++.
      Learn and practice C++
      Following this tutorial, you’ll acquire new concepts of C++ programming in every chapter. Then following chapters will give you reasons to reuse and practice those same concepts. There’s no better way to wire you brain.
      Link to the tutorial: [Tutorial] Learn C++ in Unreal Engine 4 by making a powerful camera
      Please do send me as much feedback as you want. I’ll be considering every constructive remarks and taking them into consideration. Your feedback will help me to improve and update the existing chapters and to make the next one better.

      View full story
    • By BenjaminBouchet
      Learning game development in Unreal Engine could be a daunting task for someone who don’t know where to start, and a cumbersome process if you don’t organize your progression correctly. One thing commonly known by experienced developers and by people unfamiliar with coding: mastering a development language is a long and difficult task.
      From blueprints to C++ in Unreal Engine
      If you want to learn fast, you need a good learning strategy. Unreal Engine contains a very powerful tool which you can use to learn C++ faster: its blueprint system. Blueprints are extremely easy to learn (and you may already have a good knowledge of them). Thus you can conveniently use them as a guide for writing code in C++. This is the reason why I am writing a tutorial series on how to make the transition from Unreal Engine blueprints to C++.
      Learn and practice C++
      Following this tutorial, you’ll acquire new concepts of C++ programming in every chapter. Then following chapters will give you reasons to reuse and practice those same concepts. There’s no better way to wire you brain.
      Link to the tutorial: [Tutorial] Learn C++ in Unreal Engine 4 by making a powerful camera
      Please do send me as much feedback as you want. I’ll be considering every constructive remarks and taking them into consideration. Your feedback will help me to improve and update the existing chapters and to make the next one better.
    • By mrDIMAS
      Hello everyone! I need to fill lua table with functions from script file like this:
      function init() end function update() end I need to create table on stack and fill it with this functions from specified file. How can I do this?
  • Advertisement
  • Advertisement

member variable initialization in the header...or not? :S

Recommended Posts

Here's my dilemma, I have this bunch of variable inside a class

protected:
	//Window
	HINSTANCE mhAppInstance{};
	HWND mhWindow{};
	std::string mWindowCaption{};
	UINT32 mClientWidth{};
	UINT32 mClientHeight{};
	bool mWindowed{};
	bool mMinimized{};
	bool mMaximized{};
	bool mResizing{};
	
	//Timer
	GameTimer mTimer{};
	bool mAppPaused{};

	//D3D 
	D3D_DRIVER_TYPE mDriverType{};
	ID3D11Device* mDevice{};
	ID3D11DeviceContext* mImmediateContext{};
	IDXGISwapChain* mSwapChain{};
	ID3D11Texture2D* mDepthStencilBuffer{};
	ID3D11RenderTargetView* mRenderTargetView{};
	ID3D11DepthStencilView* mDepthStencilView{};
	D3D11_VIEWPORT mScreenViewport{};
	
	//D3D Settings
	bool mEnable4xMsaa{};
	UINT m4xMsaaQuality{};

and I have all 0 initiazed them trough curly brackets, but now I was thinking to take it a step further and write inside the  curly brackets the initial state of my bools.

To me this seems perfect because I have a huge list of variables with all their starting states as soon as I open the header page without need to scroll up and down if I where to initialize them inside the cpp, so flipping pages is faster than scroll up and down (at least for me)...but despite this convenience that seems obvious to me, It seems like everyone go and initialize their variable in the constructor.

So I was wondering, I am doing it wrong and there are serious concerns and reason I should know about for not doing it in the way I am or is just a stylistic choice? (I don't think it is since too many people seems doing it that way...)

:)

Edited by MarcusAseth

Share this post


Link to post
Share on other sites
Advertisement

Initializing variables like that is only possible from C++11 and onwards. This might explain why you haven't seen it a lot.

There are times where it might be useful (if the variables should always be the same thing, i.e. not default to different things in different constructors/circumstances, etc.), and times were you cannot use it (depends on variables passed in, etc.).

Some more information about this here:

https://stackoverflow.com/questions/28413154/c-initializing-variables-in-header-vs-with-constructor

Share this post


Link to post
Share on other sites

I see. Christian Hackl in that link mention possible expensive recompilations if one where to change the initial value of a variable specified in a header file, so my super noob question is, there is a way for me inside Visual Studio 2017 to track this recompilation time so that I can do my experiments and just be aware of it? :S

Edit: oh wait, I can actually google that myself xD Pretty sure is a easy to find one

Edited by MarcusAseth

Share this post


Link to post
Share on other sites

If you have the initialization in the header, every file that includes that header will have to be recompiled if you change the value. 

As for tracking it, just hit compile and see how long it takes.

Share this post


Link to post
Share on other sites

Apparently I had the compile time turned off by default (default VS2017 setting), according to Peter Mortensen  the procedure to show it is 

Menu Tools  Options  Projects and Solutions  VC++ Project Settings  Build Timing 

Nice! :D

Edited by MarcusAseth

Share this post


Link to post
Share on other sites

Small followup, after long reasoning I might have discovered my style for initializing the varibles in a header, and I may also discovered that I have some OCD problems :D

Rules:

1)Variable names line up under each section, same for the initialization brackets

2) 1 space between the longest type name of a section(marked by a comment) and variable name

3) only nullptr and true/false allowed inside brackets(for now, this may change)

4)initialization brackets line up based on the longest variable name

protected:
	//Window
	HINSTANCE    mhAppInstance { nullptr };
	HWND	     mhWindow	   { nullptr };
	std::string  mWindowCaption{};
	UINT32       mClientWidth  {};
	UINT32       mClientHeight {};
	bool         mWindowed	   { true }; //CARE: at the moment we are not actually changing this when not windowed
	bool         mMinimized	   { false };
	bool         mMaximized	   { false };
	bool         mResizing	   { false };

	//Timer
	GameTimer  mTimer    {};
	bool       mAppPaused{ false };

	//D3D 
	ID3D11Device*		mDevice		   { nullptr };
	ID3D11DeviceContext*    mImmediateContext  { nullptr };
	IDXGISwapChain*         mSwapChain	   { nullptr };
	ID3D11Texture2D*	mDepthStencilBuffer{ nullptr };
	ID3D11RenderTargetView* mRenderTargetView  { nullptr };
	ID3D11DepthStencilView* mDepthStencilView  { nullptr };
	D3D11_VIEWPORT	        mScreenViewport    {};

	//D3D Settings
	bool mEnable4xMsaa  { true };
	UINT m4xMsaaQuality {};

 

Edited by MarcusAseth

Share this post


Link to post
Share on other sites

Note that the initialization has a cost. It is small, but it exists.  You can often do the initialization at the same cost -- and possibly at a lower cost -- with your constructor.

 

Why do you need to initialize mWindowCaption? It is a std::string, it comes properly initialized to empty all by itself. 

Are there items on that list that are initialized or set to specific values at other times? For example, you probably are setting the application pointer, the width and height, and a few other D3D values immediately after construction. Why do you blank those out and pay the cost of assigning to them twice?  If proper usage requires you to set them to a value before they are otherwise used, initializing them to a value such as zero or null and then immediately writing to them a second time with the expected value is wasteful. 

Share this post


Link to post
Share on other sites

My only argument would be that I'm not confident enough I'll remember to initialize everything and I always assume I will fuck up so I just want a second line of defense by just putting { } in front of every variable I declare and not have to think about it anymore. 

But is a weak argument I know :P

 

Quote

You can often do the initialization at the same cost -- and possibly at a lower cost -- with your constructor.

You mean before the constructor body like

A::A(int value) : variable(value)  // <---this on the left
{

}

or inside the constructor body? Or is the same thing? :S

Edited by MarcusAseth

Share this post


Link to post
Share on other sites

That means with the constructor initializer list. That is the constructorname : variable(value) thing you've got up there.  Be certain they are in the same order as they exist in the class.  

Initializing them inside the body takes place after the others, so putting it in the body also incurs the cost of multiple initializations for types that have initializers/constructors.

Initializing them the way you are doing it now does have the benefit of ensuring a value is assigned, at the risk of potentially paying the cost multiple times.  If you're fine with the cost and don't trust yourself, what you've got can work.  

Share this post


Link to post
Share on other sites

That's useful information :P

By the way, I'm pretty sure I won't stick with this way of initializate things for long, I will grow past it pretty soon, :D  performance first.

Edited by MarcusAseth

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Advertisement