Sign in to follow this  
nbertoa

Unity [C++] Compilation and default values problem.

Recommended Posts

nbertoa    1022
Hi community. I have a class Shooter and its constructor's declaration is:
//Shooter.h

Shooter(int health=0, float speed=250.0f, float jumpPower=600.0f, int    munitions=1);

As you can see, each argument has its default value. I have a class Level and in its private part has:
// Level.h that includes "Shooter.h"


private:

    Shooter m_mainCharacter;

And its constructor definition is:
// Level.cpp that includes "Level.h"

Level() : m_mainCharacter(1, 300.0f) 
{

   // Irrelevant things

}

Hence, in its initialization list I don't put a value for jumpPower, then jumpPower takes its default value. The problem is the following: Suppose I modify the default value for jumpPower in Shooter.h. When I compile and run the application there isn't a change!!!! But if I make an irrelevant change in Level.cpp like a newline, or space, etc, when I recompile and run, the behavior is the correct.

Share this post


Link to post
Share on other sites
Rattenhirn    3114
This has nothing to do with default parameters.

Use a build environment that has a (working) dependency checker, like, er, well, I can't even think of one that doesn't...
Maybe you're using broken makefiles?

Share this post


Link to post
Share on other sites
Rattenhirn    3114
Very weird. Visual Studio's dependency checking is usually solid and the only way to screw it up that I am aware makes it recompile everything all the time. And that's obviously not your problem...

Share this post


Link to post
Share on other sites
Nypyren    12074
Something is confusing the dependency checker... which usually works the other way around like Rattenhirn said.


Do you have multiple files with the name "Level.h" or "Shooter.h" anywhere else in your project or directory structure that the dependency checker might be looking at, which are different from what the compiler ends up including?

Share this post


Link to post
Share on other sites
nbertoa    1022
I discovered the reason, but it's SO WEIRD!!!!!

If I change the default value for jumpPower in Shooter.h the compiler output is:

------ Build started: Project: CaperucitaPlusPlus, Configuration: Debug Win32 ------
Compiling...
Shooter.cpp
Generating Code...
Skipping... (no relevant changes detected)
Level.cpp
mainLevel.cpp
Linking...
Embedding manifest...
Build log was saved at "file://d:\NicoDocs\Programming\SFML\CaperucitaPlusPlus\CaperucitaPlusPlus\Debug\BuildLog.htm"
CaperucitaPlusPlus - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Apparently the compiler skips Level.cpp compilation because for him "no relevant changes detected".
But if I put a newline, or space in Shooter.h, A REAL IRRELEVANT CHANGE!!!! the compiler output is:

------ Build started: Project: CaperucitaPlusPlus, Configuration: Debug Win32 ------
Compiling...
Shooter.cpp
Generating Code...
Compiling...
Level.cpp
mainLevel.cpp
Generating Code...
Linking...
Embedding manifest...
Build log was saved at "file://d:\NicoDocs\Programming\SFML\CaperucitaPlusPlus\CaperucitaPlusPlus\Debug\BuildLog.htm"
CaperucitaPlusPlus - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Then we can see that Level.cpp compiles and the result is what I need.


JAJAJAJAJA I don't know what to say!!!! Changing a value is less relevant than a newline or space?

Share this post


Link to post
Share on other sites
Codeka    1239
You can turn of the build dependency engine, which will cause it to rebuild all .cpp files that include a header file you've modified. In your project properties, under C/C++, Code Generation, change the "Enable Minimal Rebuild" option to 'No'.

In general, you shouldn't have to do this, though, since the Visual Studio engine is usually pretty good. The main things that tend to confuse it is if your files have timestamps that are in the future or really far in the past, You might want to just double-check that. There could also be preprocessor definitions which confuse the dependency engine, I'm not too sure... but definitely the option I mentioned above will work around the problem.

Share this post


Link to post
Share on other sites
blackbird04217    144
I'm posting because I've experienced a similar, though different problem, as far as the building dependencies goes, although in quite a different fashion. This was like a year ago, but lesson learned. I was working on a rather large project, where there were files that required a complete build of the project, a lot longer than the minimal rebuild necessary.

Without touching "World.h" the compiler would detect it had changed and needed to be recompiled, which meant every file needed to be compiled. This took much more time than needed, especially when World.h shouldn't require that. The problem ended up being the fact that I had changed my computers date, accidentally while looking at the calendar, and the date/time of the World.h was changed. Therefor the compiler always thought the file was new, and needed to be rebuilt.

The same thing can happen in reverse; the compiler not building a file even when you are making changes, likely because of the same effect - although I don't know the specifics of this case I've experienced it as well. The previous case is easier since the time you last saved the file is newer than the current time and it thinks it needs to be rebuilt.

Just a heads up for people who get attracted to this thread from the contents within.

Share this post


Link to post
Share on other sites
Zahlman    1682
Or you could, you know, learn how makefiles work... :) (Although I have no idea how you'd make an IDE like VC++ talk to external build tools like automake :/)

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

Sign in to follow this  

  • Similar Content

    • By drcrack
      Hey
      I'm developing a game inspired by World of Warcraft PvP
      Key features:
      — It's not an MMORPG, you don't need to level up and gear up your characters
      — Many different rated and casual gamemodes: duels, 2v2 and 3v3 arenas, battlegrounds, deathmatches
      — Built-in voice and matchmaking without a party (if you don't want to push serious rating)
      — Non-targeting combat system
      Sign up for beta here: https://goo.gl/forms/IYSAQtiRXQVY2B192
      Duels:
      3v3 with bots: 
      More videos coming soon!
    • By Affgoo
      About us:
      We are a team of 14 developers developing multiple mid scope games both are over halfway complete. We polish all of our games and focus on quality.


      We are a small team, everyone currently on the team and future teammates must be interested in game development as a whole and not just one role, being a small indie company it is very important that you can wear a few hats and not just one. Everyone on our team is a game dev.

      looking for:
      3d Artist (hand painting a huge plus)
      3d Animator
      entry level Software engineer with reasonable skills in c# / shaders. 

      ^ requirement for all positions: A true love of game development and to be very self motivated.
      We are a very active team, you must be too. 


      If interested or for more information add me on skype: nicholas.boucher4


      Atlas Sentry art style: (art complete)(code complete)
      http://www.slidedb.com/games/atlas-sentry

      Rat n Gat art style: In Devlopment

    • By EvaBalikova
      Main menu in Feudal Alloy. 
      twitter
    • By Jcyshadow97
      Hi guys,i m looking for someone that can work with me on a "top-down" multiplayer fps as 2d and 3d artist.I used photon server and i can take the part of programming.For now i made only the basic gameplay of the game that include shooting,switch weapon and and damage player.If someone can help me please contact me via e mail: 270514974@libero.it.
      I really appreciate your collaboration and hope you have a good day.....
      Thanks for you time to read the post
      At the bottom i attach some screenshot of the current game,i m sorry that i can't attach a video...



    • By Raptor42
      I'm looking to form a new game development team, mostly for training purposes.
      About me:
      I'm a student - Unity C# developer, who worked part-time in this industry for a couple of years already. I've been a lead developer in many "random collab groups" as well as a few companies. I specialize in creating 2D games for Android, but I'm looking forward to trying out new things - especially 3D development.
      Currently, I've got one Android game close to a release so I'd work for this team in my spare time. 
      About the project:
      I've been thinking about creating a simple tycoon-like simulation game for Android (and PC eventually), inspired by the Game Dev Story (initially released by Kairosoft in 1997) https://en.wikipedia.org/wiki/Game_Dev_Story 
      I haven't done much planning though, therefore I'm looking forward to hearing out your ideas.
      Right now, I've only created a test 3D scene using placeholder models and implemented a simple pathfinding system for me to play around with:
      https://i.imgur.com/xAd0l4o.png
      https://i.imgur.com/nHZerOT.png
      I'm looking to work with people who are:
      - willing to take a position of a: 3D modeller/2D artist/Designer
      - not necessarily very experienced, but eager to learn and improve their skills
      - active - check in at least once a day
      If you'd like to apply for a different position which I didn't list here, you are welcome to contact me as well.
      While this project is created mostly for learning purposes, if we ever get to release it and generate any revenue - you will recieve a certain percentage of it.
       
      To Apply:
      Send an email to rk.softwaredev@gmail.com
      Introduce yourself and attach an example of your work (if you have any)
  • Popular Now