Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Servant of the Lord

Member Since 24 Sep 2005
Offline Last Active Today, 12:21 AM

#5197708 how to pass global struct into my class function?

Posted by Servant of the Lord on 11 December 2014 - 07:55 PM

structs and classes are virtually identical. Both can contain functions and variables (and both can use inheritance).
The difference between them is that structs are 'public' by default (but can have private members), and classes are 'private' by default (but can have public members).
 
 

btw what do you mean by the inclusion guards ( #ifdef BLAH_H / #pragma once)? I have no idea what those are/do but the code seems to be working fine without them..

 

It's working fine for the moment, but can unexpectedly mess up later when you add more files to your project. Here's why:

C++ compiles files in multiple steps. At a basic level, most C++ compilers compile your code like this:
 
For every .cpp file, pre-process the text in the .cpp files to resolve any macros and defines and includes, then convert the pre-processed text to abstract code. Once all the .cpp files have been compiled to abstract code, combine and compile all the abstract code into binary/assembly/executable files.
 
There are two things to notice here:
1) C++ only compiles the source files (not the headers)
2) C++ compiles each source file independently of each other.
 
Because C++ compilers compile each source file independently, if we declare "struct World" in one .cpp file, other .cpp files don't know anything about "struct World" and give compiler errors because "it doesn't exist" as far as that file's compilation can see.
 
Oops. So what now? Every file that wants to use 'struct World' must declare it. We don't want to have to manually re-write the details of struct World over and over. So instead, we put it into a header file.
 
Header files aren't compiled directly. Compilers don't really know about header files.
 
When you say #include, what you're really saying is, "copy and paste the header file into this location before compiling".
So we write the details of struct World in the header file, and make any interested .cpp file #include struct World's header file.
 
But now we run into a different problem. Imagine we have two more headers, that both use World.
Player.h includes World.h
Monster.h includes World.h
and main.cpp includes both Player.h and Monster.h
 
When main.cpp is compiled, Player.h will be copied into main.cpp before being turned into assembly, and World.h was already copied into Player.h. So main.cpp has World.h's code copied into it.
But main.cpp also #includes Monster.h, and Monster.h also includes World.h.
So World.h's code gets copied twice into main.cpp.
 
When you do something like this in your code:

struct World
{
    //Stuff...
};
 
//More stuff...
 
struct World //AGAIN!
{
    //Stuff...
};

 
...you get error messages; you can't declare the same struct twice!
 
To prevent this from happening, we use inclusion guards.
We wrap the content of World.h so that it only gets copies once for every .cpp that (indirectly) includes it.
 
Using the preprocessor language that runs before the code is turned into assembly, we say:

#ifndef NAME     /If Not Defined: NAME
#define NAME    //Define: NAME
 
//...header content goes here...
 
#endif NAME  //End our preprocessor if-statement

 
Because NAME has to be a unique name in your project (and unique from any #defines in any 3rd-party header file your project includes), it's common practice to make NAME be in-all-caps the name of your header file, followed by _H and prefixed with a prefix unique to your project.
 
Something like this:

#ifdef PROJECTNAME_HEADERNAME_H
#define PROJECTNAME_HEADERNAME_H
 
//...content inside Headername.h
 
#endif

 
Alternatively, instead of all that #ifdef/#define/#endif stuff, you can just simply write "#pragma once" at the top of every one of your header files.
 
#pragma is for compiler-specific commands, and 'once' is the command being passed to the compiler.
 
#pragma not actually an standard C++ feature - it's a specific thing compilers can choose to implement - but almost every major modern compiler does implement it, so you're almost certainly on safe ground.
 
I personally continue to use #ifdef / #define / #endif in my projects, but I feel increasingly silly for doing so. laugh.png




#5197516 One Time per Press Events vs. Continuous Events

Posted by Servant of the Lord on 10 December 2014 - 11:35 PM

No problem - glad to help. smile.png

 

One last bit of advice: Try to keep your drawing, event, and updating code separate from each other. Things get messy when you interweave drawing with updating and events.

 

Overall, my main loop is broken into three* conceptual phases:

 - First I React() to incoming events, changing the logical state of the game. (LeftArrowKey was pressed, so 'MoveLeft' is set to true)

 - Then I Update(elapsedTime) based on the passage of time. (Since 'MoveLeft' is true, playerPos += (elapsedTime * MovementSpeed)  )

 - Then I Draw() the current state. Draw(player, to the screen, at playerPos)

 

*Actually, I use four phases. But the fourth phase, "Think()", is really just a subset of Update() and probably unnecessary.

 

There are other ways to lay out your main loop, but for 2D games this works fine. The important thing is you try to keep your code clean and organized. It's a habit you have to teach yourself over time.

As your project grows in scope, messy code will get messier; it won't suddenly become clean. And the messier it is, the more bugs get introduced. And the messier it is, the harder it is to locate and fix those bugs.

Clean code still has bugs, but less of them, and they are easier (but still not always easy) to fix.

 

Don't worry about your code not being perfect overnight - but the sooner you begin to take small steps to keep your code clean as you write the code, the more likely you'll be able to finish your projects instead of having to burn them down because of too many "impossible to fix" bugs.

(I found Code Complete: 2nd Edition to be very instrumental in pointing me in the right direction)

 

Good luck on your programming endeavors!




#5197496 One Time per Press Events vs. Continuous Events

Posted by Servant of the Lord on 10 December 2014 - 08:43 PM

SDL_KeyboardEvent has a repeat flag, so that just be very useful.

 

I generally don't like key repeat. For actions you want to repeat, I'd use the method you are currently using. For actions you only want to run once per press, use SDL_Event. For actions that depend on state, I manage that state using variables.

 

Enabling the repeat flag messes that up. It's good for things like GUI applications, but not so good for game development.




#5197493 One Time per Press Events vs. Continuous Events

Posted by Servant of the Lord on 10 December 2014 - 08:23 PM

"Continuous" actions can be tested every frame using the array of key states like you are currently doing.

 

Non-continuous actions need to react to events - see SDL_Event for more info.

 

If you only ever want to let the player activate a specific switch once, your code needs to keep track of your switch's state, and only take action on the event, only if the switch is in a valid state.

 

For example, you probably don't want the players to be able to shoot as fast as they can click. Instead, guns have delays between firing. So a player needs to be able to shoot on the event, only if enough time has passed since the previous fire. You have to have your code manage the 'state' of your guns.




#5196884 Trademark database

Posted by Servant of the Lord on 07 December 2014 - 07:22 PM

For example i want to make a game that is called "scrolls" but im not sure if this word isnt trademarked already (i know it is, notch probably has it), can and where i could find this out:?

Notch was sued by Bethesda because of the similarity to 'The Elderscrolls: _________' series of games; which is an excellent example of, "Is it similar to someone else's trademarks?"

 

Before you bash Bethesda too much, companies are required to defend their trademarks or they lose ownership of them. Same with Nintendo suing people for Mario or Pokemon games - the more people that make games without permission and without Nintendo taking action, the less control and legal ownership Nintendo has over their own property.

 

Another thing, lets say that the trademark exist, lets say the word is "Lazy potatoes" (just an example), i want to use this for a pc game, but i find out that this is already a trademark but it is used by some chips (food) manufacturer, so its just some stupid food, it doesnt have anything to do with games. Could i use it for a game? I gues what im asking is, if the trademarks are somehow tied to the "field" in which the owners has bussines (law, finance, entertainment, food, drugs, car, real estate etc...)?

 

Yes, to an extent. There can theoretically be multiple "Super Cool _______" companies ("Super Cool Drycleaners", "Super cool motel", "Super cool internet server provider!", "Bob's supercool mail delivery service"), because those are common english words that are commonly put together in that manner but are all in different industries.

 

Even so, companies don't need to be actually in violation to sue each other. I can sue someone for breathing. That doesn't mean I'd win, but it'd still be a huge nuisance for the person being sued.

 

When filing the paperwork to create their company, the two college student founders of Google accidentally misspelled the word they were trying to spell (Googol). They found out later that this was actually beneficial to them, because by (accidentally) creating a unique word, or unique spelling, it strengthened their trademark. Nobody can use 'Google' for anything, regardless of what industry. You can't make Google Burgers, for example, because 'google' wasn't a word that existed until Google was founded.

 

Had they named themselves Googol, they would've still had control over that name in the software industry, and related industries, but some bank could've created a "Googol saving account", as long as they weren't intentionally trying to capitalize off of Googol Software's popularity.

 

As an example of a company that doesn't have a unique name, Apple Software uses 'Apple' as it's trademark... but 'Apple' is a common english word. Apple Software only has control of that trademark in the software and computer hardware industry.

 

Apple Corps (the Beatle's recording studio) has control of it in the music industry, so when Apple Software got into the music business with iPods and iTunes, Apple Corps sued Apple Computer, and it was a long, expensive, messy legal battle. Had Apple Software chose a more original name for their company when founding it, they could've saved themselves hundreds of millions of dollars in settlements and lawyer costs over the years.

 

There are also apple grocery stores - in Kansas City, there's a Cosentino's Apple Market chain of grocery stores with at least three branches. Apple Software, despite now having retail stores for their computer products, can't do a thing about that. Try making a Cosentino's Google Market grocery store, however, and you'd get sued into smithereens, because 'Google' is a unique word with unique spelling.

 

Even things like the Macintosh name? Macintosh is a popular and common name for a specific type of apple fruit. Apple's marketing team probably felt they were being clever with the name. Apple's legal team probably groaned. Nothing is preventing anyone from creating a Macintosh Airlines, or Apple Jets (though they may have trouble naming an airport 'Apple' wink.png)

 

Obligatory: I am not a lawyer, consult a real lawyer before making important long-lasting business decisions such as naming your company or flagship products.




#5196719 A casual puzzle game about stained glass windows.

Posted by Servant of the Lord on 06 December 2014 - 06:25 PM

I enjoyed it.

 

The word "bordering" makes sense to me. Other games (using pen and paper) I played as a child used the concept of bordering.

 

I like the idea of stain glass windows, but I found that white flickering to be annoying.




#5196716 how to pass global struct into my class function?

Posted by Servant of the Lord on 06 December 2014 - 06:07 PM

You'll need to create the struct in a header file. Not every .cpp needs a .h, and not every .h needs a .cpp.
 
Create a header that defines DrawWorld. and make map.cpp include it. map.h can just pre-declare DrawWorld like:

struct DrawWorld;

Also, you'll want to pass in your variable by const reference ( generateMap2(const DrawWorld &drawWorld); ) unless you intend to edit it within the function, in-which case you'll want to pass it by regular reference.
 
You don't want to actually declare an instance of your DrawWorld struct in the global scope (only define the struct). It'd be better if it is declared within main() or elsewhere, and passed to the functions that need it.
 
Finally, DrawWorld is not too great of a type name or instance name. It sounds like an action (Draw the world) so it sounds more like a function name instead of a type or instance name. For example, 'World', or 'DrawSettings' would be more descriptive. That's my personal opinion, anyway.
 
 
So basically, you have:

 

DrawWorld.h:

//Your struct "definition":
struct DrawWorld //Or a better name
{
    //...
};

 Map.h:

//Your struct pre-declaration (since we haven't yet #included DrawWorld.h)
struct DrawWorld;
 
class Map
{
     public:
     void someFunction(const DrawWorld &drawWorld); //Or just: (DrawWorld &drawWorld), if you want to edit it within the function.
};

 
 Map.cpp:

#include "Map.h" //Include this file's header.
#include "DrawWorld.h" //Include the full definition, since we want to use it in this file.
 
void Map::someFunction(const DrawWorld &drawWorld)
{
     //....
}

 
 Main.cpp:

#include "Map.h" //Include the header, since we want to use Map
#include "DrawWorld.h" //Include the header, since we want to use DrawWorld.
 
int main()
{
     DrawWorld drawWorld;
     Map myMapInstance;
 
     myMapInstance.someFunction(drawWorld);
     
     return 0;
}

Note: I skipped the inclusion guards ( #ifdef BLAH_H / #pragma once) out of laziness. You'll still need to use those in your actual code.




#5196663 Can this RPG mechanic work?

Posted by Servant of the Lord on 06 December 2014 - 12:24 PM

Sounds vaguely like a Mario & Luigi RPG game of some sort. They often play around with Mario and Luigi doing different things or swapping between modes.

 

Have you played The World Ends With You? In that game, using the Nintendo DS's dual-screens, each character is fighting on a different screen.

 

It sounds like the mechanic could work - but execution is everything.

 

Swapping stats sounds like it removes each prince's individuality - I, as a player, no longer need to care about the differences between them. In my mind they then become one character in two bodies, rather than two unique characters. This may be what you are going for, plot-wise*, but makes the game less interesting, character-wise.

 

*Cliched plot twist: they aren't really twins, they are same person who got split apart in two or more bodies.

 

I've played RPG games and majority of them are pretty much the same. 

 

By "the same", do you mean they have ceased to be enjoyable to you, or that they weren't really enjoyable to you in the first place?

 

Why have they ceased to be enjoyable? Have your tastes in genre changed, or have you just played similar RPGs so much that you feel like you're just replaying the same game over and over?

 

What parts have ceased to be enjoyable? How would you go about improving - or removing - those parts?

How can you take the RPG genre and distill it, refine it, build upon it, polish it, and improve it?

 

 

 

So I want to do something new to the genre.

 

Are you doing something different just for the sake of being different, or are you trying to do something better and make things more enjoyable?

 

Different doesn't always mean better. Different doesn't always mean enjoyable. Sometimes they can be improvements, other times they are just gimmicks that are entertaining for one game, but aren't really lasting improvements to the genre. Which is fine - the occasional gimmick-game can be enjoyable. Are you designing a gimmick game?




#5196644 Intros

Posted by Servant of the Lord on 06 December 2014 - 11:19 AM

Now as you might know is the library I use DirectX. I have to be true now ... I didn't really read the licens agreement sad.png . It just took too much time and I thought, that it is every time the same thing. Like don't use this library to proram killing drones, hacks, viruses(doesnt even makes sense), and so on.


There are variations per license that are important to know. Some licenses require you to release your game's sourcecode for free (GPL for instance), others don't require that (LGPL or MIT for example).

But now where can I find the different licens to accept ?

Most libraries, like DirectX, only have one license. Some libraries have multiple licenses you can choose from. DirectX isn't one of those.

And could I add the DirectX intro, just to let it look more professional ? Because I think every really good games has this one in.

Not unless the license gives you permission to. Using their logo on your game without permission may imply to players that they "approve" of your game.
 

Now does somebody here know which "don't do this!" DirectX has ?

As far as I can tell, you can use DirectX for free, even commercially. However, you can't use their logo without Microsoft's permission.


#5196641 The magical games atmosphere ?

Posted by Servant of the Lord on 06 December 2014 - 11:16 AM

I think it's possible that the time doesn't decide if a game is good. Maybe it's me because, I played a game where I had to kill, search, hide, sneak, ... before. Maybe the teenagers today feel like we couple of years ago ?
I have to figure that out, but how ? biggrin.png


SunAndShadows and myself suggested how in our previous posts. smile.png 
 

Now I stangly hate the system of DLC's and this stuff.
 
I think, when you buy a game for more than 30 bucks(you say this in america, right ?), you shouldn't have to play anything to get a complete. What DLC's actually do is cutting a game in pieces. The biggest part is sold as game, the remain is sold as DLC.

Yes, new games cost $60 bucks in the United States, for most major consoles.

DLC can be abused, but so can other forms of monetization.

Not all DLC is bad. In the days of yore, we called DLC "expansions", and they were popular. For example, Age of Empires was famous for their expansions. Expansions are only large DLCs with a different name came on discs.

 

It's not the method used, but how the methods are used. What content is being delivered? And at what price?
 

Also this monthly paiment is not good at all. I mean .. you bought it !


Certainly, I wasn't say it was good, I was merely pointing out monthly payments (and even hourly payments!) is something they used to do alot. I'm saying it's not modern payment schemes that are bad just because they are modern, and old payment schemes that are good just because they are old - rather, it's whether or not the payment scheme is "abusive" (subjective), and whether the game itself is "worth" it (even more subjective).

For example, I spent hundreds of hours (>250 hours) playing cooperative Dungeon Defenders on Steam. The game cost me $20, I think. I don't normally buy DLC (most of the time, my personal opinion is the DLC is crap), but I bought DLC for this game to buy additional content for something that had already proved its worth. Very few games have I spent 250 hours on (maybe six or seven games total in my life were that enjoyable). Ofcourse, it helps that it was cooperative. wink.png




#5196554 The magical games atmosphere ?

Posted by Servant of the Lord on 05 December 2014 - 09:44 PM

So what I mean with atmosphere is what makes the difference between this good old games, everybody loved and the new sucking(I'm sorry for that) games like "Call of Duty - Ghosts",

If you think ALL old games were good, and ALL new games are bad, then you're stuck. Obviously you can't go into the past and make your game.

Or, maybe the difference isn't directly decided by what time period the game was developed in. If so, you're in luck. wink.png 
 

I don't wanna say they are really bad, I mean they are playable, but they don't have this magical something, what makes we love them. This warm feeling, when playing them and the feeling to be part of something, maybe even to be in a place for a special time ?


If you think ALL the games you played when you were young are "good" (and not just because you were experiencing them for the first time), and ALL games you've played as an adult are "bad", well, the good news is that there is a new generation for who that "magic" isn't yet lost. The bad news is, you can't go into the past and be a kid again, so you'll never experience that magic again. 

Or, maybe the difference isn't directly decided by what age you were when you played the game. If so, you're in luck. tongue.png 
 

So my game, I'm working on is about a really complicated, realistic and hard space MMO. But WITHOUT any kinds of DLCs, ingame buys, buy to win and all of that new "inovations".


If you think that the monetization scheme games use are what makes them "good" or "bad", then you're out of business. Are "insert another coin to play for 30 more seconds" arcade machine, "Pay $10 for an hour of online time" multi-user dungeons, "Pay a recurring fee of $15" MMOs, "Pay $500 for a console, and $100 for each game and just replay the same game over and over" consoles, really the defining quality of what makes a good game? After all, that's how they used to do it. And apparently, old = good.
 
Or, maybe the difference isn't directly decided by how the game makes money. If so, you're in luck. laugh.png 
 

http://media.moddb.com/images/downloads/1/69/68747/swjkaspd_1.jpg
http://i1-games.softpedia-static.com/screenshots/Star-Wars-Jedi-Knight-Jedi-Academy_13.jpg
and so on ..
 
so and that are the new ones with bad atmosphere :
http://gearnuke.com/wp-content/uploads/2014/09/cod-Advanced-Soldier.jpg
http://static4.gamespot.com/uploads/screen_kubrick/1365/13658182/2622075-callofduty_advancedwarfare_multiplayer_cod_aw_riot_slam+dunk.jpg
http://www.vgamerz.com/wp-content/uploads/2014/05/call-of-duty-advanced-warfare-3.jpg


If you think all single-player 3rd-person semi-popular Star Wars action games are good, and all multi-player first-person mainstream modern-day semi-futuristic military first-person shooter games are bad, then you're out of luck, because you can't license the Star Wars franchise for your game - EA has an exclusive contract for Star Wars games, for the next ten years.

Or, maybe the difference isn't directly decided by the [number of active players], [camera perspective], [popularity], [setting and franchise], and [gameplay genre]. If so, you're in luck.

 

If you are wanting an answer to the "magic", you'll have to look deeper than merely bashing games you don't like (but millions do), and praising games you have happened to enjoy.

 

As a designer, you'll want to be able to play and examine the good parts of games, even if you don't like the game. I don't mean make yourself blind to the flaws - rather, I mean attune your eyes to see the strengths hidden admist the flaws. My favorite games, and yours also, are very flawed.

 

To cut through your own biases, you could make a list of what about Jedi Academy you enjoyed, and what about Jedi Academy you didn't enjoy. (Or was Jedi Academy 100% perfect in every way? If the answer to that is 'Yes', then your emotions are still fogging up your game designer lenses)

 

Next, make a list of what about Call of Duty: Advanced Warfare you don't like, and what about Call of Duty: Advanced Warfare you do like. (Or was Call of Duty: Advanced Warfare 100% bad in every way? If the answer to that is 'Yes', then your emotions are still fogging up your game designer lenses)

 

Then, find another Call of Duty game that you do like (or as close a game as possible that you enjoy), and contrast it with Call of Duty, making a list of what you like and what you didn't like. 

Similarly, find another Starwars action game that you don't like (or as close a game to Jedi Academy as possible that you don't like), and contrast it with Jedi Academy, making a list of what you like and don't like. For example, The Forced Unleashed (I'm assuming you dislike that game - if not, find one that you don't like). Comparing what you like (and dislike) about Jedi Academy with what you dislike (and like) about The Forced Unleashed would be an excellent design excessive. Have you played the game called Outcast (not the starwars one)? What parts of Outcast do you find yourself enjoying, and what parts do you dislike? How's that compare and line up with Jedi Academy?

 

Also, seeing as it's related, I posted some of my thoughts (two years ago) about what I think strengthens game atmosphere in this journal entry. Obviously it's subjective, but how would you reorder those attributes that compose the atmosphere, and which would you add to, or remove from, that list?




#5196534 Intros

Posted by Servant of the Lord on 05 December 2014 - 06:29 PM

For all the middleware you use, whether SDL, SFML, DirectX, OpenGL, PhysX, Unity, Unreal, whatever, you need to know what those licenses require of you.

 

SDL, SFML, DirectX, OpenGL don't require you to show anything at startup. You still need to read their licenses (or get someone to explain them to you) because they may require something else - like making your game opensource, for example, or prohibiting commercializing your game.

 

Every library you use has a list of "You can't do this", "You must do that" requirements. Licenses are legal agreements: For the convenience of using a specific library, you agree to the terms of that library. Some libraries have more than one set of licenses, and you get to choose (or pay to use) which one you want.

 

Thankfully, most libraries use the same four or five licenses, so once you learn what those few licenses mean, you automatically understand what is required/blocked by almost any library you encounter.

 

Some of the licenses have very acceptable terms. Whether those terms work for your particular project depends on the nature of your project.

In general, the MIT license is very friendly, and the LGPL has a few constraints but is perfectly acceptable. GPL is to be avoided like the plague when it comes to games.

Still, they have a few minor requirements that you need to understand: None of those three require you to show logos or do any extra programming work, but they do have a couple things they don't allow you to do, and a few things you are required to do.

 

Right now you are probably banging your head on the desk saying, "I just want to make a freakin` game! How'd lawyers and laws and governments get involved!? This is dumb!laugh.png

 

In actuality, it's not hard to learn (everything looks confusing the first time you see it!), and you don't have to take any law courses to understand it. You can learn it piece by piece as you go, it's not something you have to really study or waste time on.

 

All you really need to learn is, "For <license A> I can't do X. Gotcha.", "For <license B> I have to include q and y", and "My goals aren't compatible with <license C>, so I better not use that specific library."

Just minor "rules" you gradually pick up for commonly used licenses - you don't actually need to learn how to read the legal jargon.




#5196350 NULL vs nullptr

Posted by Servant of the Lord on 04 December 2014 - 06:15 PM

I use nullptr everywhere, but I admit NULL or 0 would be just as good except in a few corner cases, as long as you are consistent.

 

Also, with '0', I can't tell if function parameters are taking a pointer or an integer, which is occasionally annoying, so I prefer NULL over 0, if I can't use nullptr.

 

One annoyance in C++11, is you can't use nullptr for pure virtual functions. sad.png

virtual void MyMemberFunc() = nullptr; //Nope!

(yea, I know the virtual func isn't a pointer; still, I'd like it, or a keyword, anyway)




#5195997 Help building Boost binaries...

Posted by Servant of the Lord on 02 December 2014 - 08:25 PM

Aren't you supposed to type "bootstrap.bat msvc"?

 

Building boost is a little complicated for me personally. This is how I normally go about doing it: (notes I made for myself the last time I compiled boost. It was version 1.56)

First go to: ".\tools\build\v2\engine\"
Excute: "built.bat mingw" from the command line.
Go to ".\tools\build\v2\engine\bin.ntx86\" and copy b2.exe and bjam.exe to ".\" (the root boost directory)

Then call: "b2 --layout=tagged toolset=gcc threading=multi link=shared variant=debug,release address-model=32" from the commandline.

It's the steps bootstrap.bat normally takes for you, but I ran into errors with bootstrap.bat in the past that I couldn't figure out, so that's why I went about it differently.

 

Since you are using Visual Studio, you'd probably need to do "built.bat msvc" in the second line, and "toolset=msvc" in the fourth line (just guessing!). The fourth line can also be modified to suite your tastes in how the libraries are compiled and named.

 

It usually takes some mucking around before I can get Boost compiled. Best of luck! tongue.png

 

PS: It takes an hour or more to compile. You can specify just the libraries you want to build, if you don't want to compile the whole shebang.




#5195967 C++: Easiest way to implement an in-game Time/Date system?...

Posted by Servant of the Lord on 02 December 2014 - 04:36 PM

C++ chrono library (part of the standard)
 
If you want to measure the passage of time while your game is running (for day/night cycles), you get the current session time using std::chrono::steady_clock()  (probably; if it has a resolution suitable for your game mechanics. Otherwise, go with std::chrono::high_resolution_clock()). When your user's session begins, get the start time, and when you need to calculate how much time has passed, get the current time. The amount of time passed is (startTime - currentTime).
 
If you want to measure bigger jumps of time, for example the passage of time while the user is logged off, use something like std::chrono::system_clock() to get the real-life year/month/day/hour/minute time once when the user very first starts a new game ("originalNewGameStartTime"), and then get it again every additional time he loads the game to ("currentSessionStartTime").


amountOfRealLifeTimeThatPassed = (currentSessionStartTime - originalNewGameStartTime);
currentInGameTime = SomeFormula(amountOfRealLifeTimeThatPassed);
The key point to recognize in both these situations is that you don't actually care (and don't want to know) the values of the times of your measurements. You only want to know the duration between the two measurements.

For example, if you start your game and try to measure the number of milliseconds, the raw measurement you get give you a seemingly arbitrary value like 735343434. It doesn't matter what value they give you, what matters is the amount of time between startOfMeasurements and endOfMeasurements.
(end - start) = interval

start = doesn't matter
end = doesn't matter
interval = what you care about 





PARTNERS