Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 30 Dec 2000
Online Last Active Today, 10:46 AM

#5202914 Next Logical Step...

Posted by nobodynews on 08 January 2015 - 02:33 PM

Even more important, how do you know that trick will actually be faster than using an intermediate variable? It's bad to assume you actually know what's better than the compiler because in a lot of cases you don't, in fact, know better.

#5200827 Pressure equation (gravity force at lattitude 45*degs) <- what does that...

Posted by nobodynews on 30 December 2014 - 10:36 AM

The equation to determine gravity at a given latitude is supposedly:



However, i also checked the actual US Standard Atmosphere 1976 document (available here) and on the pdf page 19 they describe the value of g0 chosen for use in that equation.


Of course these are all estimates anyway, so unless you care about < 1% error it probably doesn't matter much.

#5198357 C++ Number guessing

Posted by nobodynews on 15 December 2014 - 11:27 AM

Other suggestions going forward:


1. put system("cls") in its own function named something like clearScreen. That way it's not only self-documenting, but it allows you to change how you clear the screen in the future.


2. You mean "lose" not "loose". And "your" not "tour" Minor gripes, but it's always good to strive for polished language.


3. Speaking of self-documenting, some of your comments are too obvious. If you have a function named displayMenu then having a comment saying to display the menu to the user isn't too helpful. Since displayMenu only does one thing the function name provides enough information that having a comment is unnecessary.


4. Like you did with getting the menu selection, why not do the same with getting a guess?


5. This isn't very important right now either, but there's an issue with the distribution of your random number. Let's say for the sake of argument that rand gives you a number between 0 and 149. If that happens then your rand()%100 will mean numbers between 0 and 49 will occur twice as often as numbers between 50 and 99. In reality the probability of each number occurring for you will be more even than that, but it won't be as even as it could be. The generic code using rand() to generate an integer range between min and max is:


int(((double) rand() / (RAND_MAX+1)) * (max-min+1) + min)


What this does is convert the original rand() integer to a double, then scales the range from 0 to RAND_MAX to 0 and 1. RAND_MAX is a constant supplied by the compiler containing the largest random number it will give you. Next, this floating point range is scaled back up to an integer range with a spread between min and max, in your case you'll get numbers 0 thru 99, inclusive (inclusive meaning both 0 and 99 are included). Then the spread is offset by the minimum range you want, in this case 1, to get the range 1 to 100, inclusive.


So in your case it would be:

int randomNumber = int(((double) rand() / (RAND_MAX+1)) * (100) + 1);


Although you might want to make the generic version into a function for the sake of re-usability. Then you could call, for example, randomRange(1, 100) or randomRange(-10, 10). If you changed the variable types of min and max to be doubles instead of integers you could even do randomRange(0.1, 0.5).

#5198250 VERY weird error. Structs in std::vector being updated more than once

Posted by nobodynews on 15 December 2014 - 12:28 AM

        for(unsigned int iterator = 0;
            iterator < currentSize;
            particleList[iterator].lifeTime -= 1.0f;
            if(particleList[iterator].lifeTime <= 0.0f)
                std::swap(particleList[iterator], particleList[particleList.size() - 1]);

            particleList[iterator].y += 0.01f;

            currentSize = particleList.size();

You should consider using your debugger and stepping through the code. I think I have a handle on what might be going on though. First, let's say you have particleList[0].lifeTime == 1.0f and then you enter this loop. iterator is 0 so particleList[0].lifeTime will decrement to lifeTime 0.0f so you swap and pop the element then decrement interator to -1. Then you access particleList[-1].y which doesn't exist so who knows what your program will do if it tries to access that memory.


Now, I also think this bug is causing your issues with the weird multiple increases. If particleList[0].lifeTime == 2.0f and particleList[1].lifeTime == 1.0f then at the start of the loop when iterator == 0, particleList[0] will remain in the list and particleList[0].y will increment by 0.01f. iterator will increment to 1. So next particleList[1] will be swapped and deleted because its lifetime reaches 0. When this happens, iterator is set to 0 and particleList[0].y will increment by 0.01f again for 0.02f total.


So, exercise for the reader: solve this bug!

#5198149 Order of winapi functions at compile time and runtime, and message loop

Posted by nobodynews on 14 December 2014 - 11:53 AM

Basically everything you described is run-time behavior, either initialization or normal program execution. If you want to know more about the difference between 'compile time' and 'run time' this stack overflow discussion might be informative.


(In fact there is no way for me to intact with it except a close, minimise, or resize)

You can also move your mouse around the window as well as in-and-out of the window. You can gain or lose focus of the window. And more that I'm not even thinking of. Of course what is really happening is Windows is interacting with your application, not you the user. The user interacts with Windows and Windows decides what to send to the program to handle and most of the time the program just says "ok Windows, I heard you. Now you take care of this message for me." That's what DefWindowProc is for. Of course, being the OS, Windows cares about more than the user so there were more messages than you thought. particularly during initialization. This link purports to list Windows messages and what the messages map to; it seems pretty accurate. So, based on your list of message numbers I found the corresponding message name and linked to MSDN so you can quickly reference the documentation on what the message is for:


uMsg = 36 -> WM_GETMINMAXINFO (addendum)

uMsg = 129 -> WM_NCCREATE

uMsg = 131 -> WM_NCCALCSIZE

uMsg = 1 -> WM_CREATE

uMsg = 24 -> WM_SHOWWINDOW




uMsg = 134 -> WM_NCACTIVATE

uMsg = 127 -> WM_GETICON

uMsg = 127 -> WM_GETICON

uMsg = 127 -> WM_GETICON

uMsg = 6 -> WM_ACTIVATE


uMsg = 642 -> WM_IME_NOTIFY

uMsg = 7 -> WM_SETFOCUS

uMsg = 133 -> WM_NCPAINT

uMsg = 20 -> WM_ERASEBKGND


uMsg = 5 -> WM_SIZE

uMsg = 3 -> WM_MOVE


As I said, most of the time you just want Windows to handle these for you.

#5197637 Need Guidance and Advice

Posted by nobodynews on 11 December 2014 - 12:36 PM

As for a level designer what does that entail, I've always had a vision that I would love to work as a person who has the overall idea for a game, writes out the script and then works with the programmers to get it realized however I always assumed you needed to be adept in animation , is this true at all?


As Josh said, that job doesn't really exist. In any case, that's not what a level designer does. A level designer generally takes assets made by other people and combines them into the 'level' the player is at in the game. Easier said than done though. The good news is that while it's still an artistic endeavor, the craft is different than what you probably experienced with 'drawing' so you might have the skills for it.

#5193303 Question with regards to my video game

Posted by nobodynews on 17 November 2014 - 02:53 PM

Each item will have certain attributes to describe the item. These attributes could include weapon type, weapon strength, and model name associated with the weapon. These attributes can either be generated randomly (based on conditions like player's level or item location) or the item could be created manually and stored in a file somewhere on the player's hard drive. In either case, at some point this information is stored in computer memory after being generated or loaded from file. So say on the computer harddrive there was a file which describes the following weapon:


Name: Sword of Swordliness

Type: Sword

Associated Model: swordliness1.model

Damage Modifer: 25

Cost: 5

DropRate: 3%


Then the merchant might have a list of items like this stored somewhere:

Sword of Swordliness

Mace of Pepperspray

Death Chicken

Harbinger of Satan



The player would go the merchant and then the merchant file would be opened and the code would go through it and go "This merchant has Sword of Swordliness. Let me look for that in that other list, the list. Found Sword of Swordliness in that list. This item uses the model named swordliness1.model. Let me open that model and display it to the user". Then the code continues and does that for all items in that merchants list. After the user selects the items they wanted and exits, the code says "remove this merchant from memory" and that step would then go through all items that were loaded and the remove THEM from memory. The model would only be in memory when there is a reason to display it. When it needs to be displayed again it gets loaded again. Of course its usually more complicated than this. Sometimes the programmer doesn't remove stuff from memory that isn't used either on purpose or on mistake. Loading something from a file takes time so programmers like to keep stuff in memory when possible, but since memory is limited they have to figure out how to balance this.


Ok now all that said let me try answering your actual questions.


1. The source of the data is up to the programmer and there's an infinite number of ways it can be done. Anything from the game scanning its directory for files it knows how to read to all data being hardcoded in the code. The files could be html. They could be xml. They could be binary blobs of data generated by tools created by yet other programmers.

2. Probably. Depends on what engine you're using and the programmer of said engine. As I said above, most any game worth its salt wouldn't even load the model unless there was a reason to.

3. They'll be stored on the harddrive waiting until something decides to display them.


Question: are you using a game creation engine like Unity? If so you might want to specify the engine so you can get more specific responses.


edit: formatted post

#5193266 Magical mysterious impossible null reference exception

Posted by nobodynews on 17 November 2014 - 09:42 AM

First, are you sure the object 'parts' in both methods are in fact the same object? Consider this example snippit of a console program:

    class AlphaClass
        public int x;

    class Program
        static void Main(string[] args)
            AlphaClass alpha = null;

        static void BetaFunction(AlphaClass alpha)
            alpha = new AlphaClass();
            alpha.x = 10;

        static void GammaFunction(AlphaClass alpha)

This will crash on Console.WriteLine because the alpha in BetaFunction is a different alpha from GammaFunction.

#5193181 Question with regards to my video game

Posted by nobodynews on 16 November 2014 - 08:55 PM

A lot of this depends on how realistic you want the game to be. If you want it to be very realistic you wouldn't even give the player the ability to hold 20 weapons in their inventory. It would be more like Gears of War style where you can hold a few guns and those get 'stored' on the character's back in designated spots when not in use. Less realistic methods would just draw the currently held weapon and ignore the 'inventory' entirely, unless the user is in a menu where they can see all items in their possession. This would be more like Fallout 3 (and newer). The only impact having a large inventory has in the Fallout universe is at a certain point the player would slow down if they had too much stuff.

If you're asking how this is handled from a programming perspective: it's whatever the programmer decides. Nothing is ever drawn to the screen unless the programmer accounts for it. Where do the 20 weapons go? No where. They are just a small list of data. Its similar to a shopping list in that it's all just references to the real thing... or in a game's case, references to the model and animation.

So for merchants if you have weapons you'd need to come up with the right lists. If you don't want all their inventory out at all times you have to decide what weapons you want out, when. These lists might be as simple as text files. Formatted properly, the programmer can interpret them so the game decides when the merchant can display them.

Hope this helps a little. Without more specific information it's hard to tell what you're looking for.

#5193030 Best Way to Learn 3D Computer Graphics? Help!

Posted by nobodynews on 15 November 2014 - 04:28 PM

I think most likely they meant "personal". I could see how a non-native speaker might use "private" instead of the more apt "personal". Or even a native speaker just having a brain-fart.

#5192457 Building A Game Engine + Game

Posted by nobodynews on 12 November 2014 - 12:44 PM

Call me old fashioned, but only wimps have to rely on an engine

You're old-fashioned. Seriously though, no need to resort to name calling. No one insulted you, they were just disagreeing. You don't serve your arguments very well by being so judgmental of people who do it differently than you would. As for Tim Sweeney, if he came to me back in day saying he had no experience programming and he wanted to make a game engine I'd have said "what's a game engine?" because they didn't really exist back then. Tim Sweeney got where he is by being into programming a young age and working on it for years and making more and more complex games as he went on. Back then just making a text based game was impressive because that's all anyone was making. It's easy to be enthusiastic when you have little competition and expectations were low from consumers. Not to mention he had been into computers and programming for around 20 years before Unreal was released. All that being said I think the 'build a kitchen' analogy was weak. A better analogy might be growing your own ingredients to be a chef. Believe it or not there are chefs who do this! But I wouldn't call a chef who doesn't do that a 'wimp'. I think it's macho posturing to insist there's one true way to make games and those who don't do it that way aren't good enough. If the OP wants to make engines I say go for it and if they just want to use Unity go for that too and if they start one way and switch later because they realize they'd prefer the other way, I say go for that too.

#5189816 Finished c++ primer plus and console. Now I want to make a 2D tile game!

Posted by nobodynews on 28 October 2014 - 04:29 PM

Far be it from me to tell someone who *wants* to learn Win32 to not learn it, but for a beginner who wants to make a 2d tile game? Using something like SDL or SFML makes about 10x more sense than Win32.

#5189437 Questions from a newcomer

Posted by nobodynews on 27 October 2014 - 10:36 AM

You'll have to be a little more specific. What would your role be in the creation of that kind of game? Do you want to be the lead who guides a team of people in making a game of that style/scale? Do you want to be the guy that figures out the technology behind the scenes on how to display the graphics? Do you want to be the guy that decides what those graphics looks like? Do you want to write the storylines the player experiences when playing the game? I'm guessing you want to be the visionary since you indicated you wanted to create the game rather than saying you wanted to just work on making a game for someone. Usually the lead person comes about because they either helped someone else with their games or because they made their own games. Either way you need skills applicable to the creation of a video game. These are of course usually either programming or artistic roles. Of course it's never a bad idea to know a little about programming when you're an artist or a little about being an artist when you're a programmer. If you want to go the programming route you should pick up a programming language (there's plenty of topics about that). If you want to go the artistic route you could look into modeling programs such as Blender and find modding communities for games you like so you can show off your skills as you learn how to model, for example. In any case you want to make a portfolio of completed projects. "Here's what I was able to program!" "Here's what I was able to draw!" "Here's what I was able to model!" For programming you'll likely progress from making text-only programs to 2-d graphical programs to 3-d programs. You'll learn mathematics such as trigonometry and linear algebra as you go along. Hopefully some of that is helpful.

#5186522 where are the 4 addresses of an integer

Posted by nobodynews on 12 October 2014 - 12:01 PM

What language? Probably C or C++, but I don't like being a mind reader. I believe you are trying to ask how to get the memory address of each memory element (call it a byte) in an integer, assuming that integer uses 4 bytes to compose that integer. I say "assuming" because, although it is common for int to have a size of 4, it isn't guaranteed to be. Since this sounds like homework I'm afraid I'm not going to directly answer your question. Instead, I will point out that you should consider the address-of operator operator, '&'. Once you know the address of a variable, do you know how to get the following address of that int? It would be 4 bytes following, right? What if you had 'char n' , got the address, and then got the following address? It would be 1 byte following, right? Is there a way you can get the address of an int and treat it like you got the address of a char?


Hopefully by understanding the answer to the first question the answer to the second will be easier to comprehend and answer.

#5186519 how to redimensione (ReDim) an array in C++

Posted by nobodynews on 12 October 2014 - 11:50 AM

You don't; not directly. You use std::vector.