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!


nobodynews

Member Since 30 Dec 2000
Online Last Active Today, 04:17 PM

#5218817 c++ count lines in txt file and then read these lines without reopening a file

Posted by nobodynews on 24 March 2015 - 10:30 AM


i know i know but i wanted that everybody willl understand why i dont want to use it. i found it really slow loading 'big' model files.

You said you don't want to use vector because when loading big model files you found it slow. The implication given the topic being that your models were text files, because why else bring up an unrelated topic? Loading text and binary are different processes most of the time. It's like complaining about not liking the beach and we asked why and you said it was because one time someone threw dirt in your face and the beach has sand which is like dirt. Even if dirt and sand are similar the problem isn't the dirt/sand it's the person that threw the dirt in your face.

 

In this case, if you found std::vector slow when loading a big file then it was because of how you were using std::vector not because of std::vector being inherently slow. Learn how to use std::vector properly and your issue will go away.




#5213452 Real time multi-key input handling in console?

Posted by nobodynews on 27 February 2015 - 10:08 PM

(MS-DOS, right?)

Not really




#5209098 Does games that were writen in "c" will be processed faster then...

Posted by nobodynews on 06 February 2015 - 11:50 AM

Here's some harsh info: if you haven't released a game you don't have end users. Basically, the best languages are the ones you know because knowing the language helps you finish games and finishing games gives you end users.

 

Given it's possible to write slow code in C and it's possible to write fast code in C++ (and vice versa) I say you're better off not worrying about small speed differences (which mostly come down to programmer skill) and instead pick the more productive language. If you don't actually know either language then between the two I'd pick C++ because I think most people will be more productive in C++ because of its standard library. If you include other languages then I'd suggest C# or Python to start with.




#5208902 3D video game in C++ with OpenGL and DirectX 10

Posted by nobodynews on 05 February 2015 - 10:45 AM

Uh, I'd suggest Community Edition over the Express editions.




#5207213 Encapsulation through anonymous namespaces

Posted by nobodynews on 28 January 2015 - 11:57 AM

Weird. I think this stackoverflow question discusses this. The response says that when ~Instance() is defined inline it 'might cause problems'. Try moving the destructor definition outside of class Instance.




#5203337 About computer instruction in relation to RAM consumption

Posted by nobodynews on 10 January 2015 - 03:19 PM

As Alvaro said you should read up on how computers work. But here goes.

 

1. Theoretically I'm sure someone could make a CPU that gets instructions from a HDD instead of RAM, but in that case the CPU would just be treating the HDD as very slow RAM. You may be thinking that the program should be separate from the data instead of treated as data. This is actually done in some architectures, mostly for microcontrollers where there will only ever be one program and no OS. In this case the entire program would be stored in Flash (often set to read-only after the program is loaded) and the CPU would treat Flash as being from memory address 0xEFFF to 0xFFFF. and RAM from 0x0000 to 0x1000, and IO and configuration registers from 0x1000 to 0x1100 (all values made up and not based on any particular architecture).

 

2. There really isn't a relationship between size of an instruction and time to execute it, especially with modern processors which do very complicated things with reordering instructions anyway. There might be benefit to smaller instructions so there are fewer cache misses if the code itself takes up less RAM.

 

3. Adding something to the stack takes up stack RAM, but the RAM used by the stack is dedicated to the stack, usually at a preallocated size. Your program isn't supposed to ever use the RAM allocated to the stack except when used as the stack. So even if your program pops the data from the stack your program still won't use it as generic RAM. There are likely ways to change your program's stack size at the linkage stage. For example, read this MSDN article for the MSVC++ way to do this.

 

4. RAM is always a potential issue. RAM is probably not the first place most people will look when worrying about speed, but it is potentially something that could help. Sometimes using more RAM will make things faster (by using an algorithm which needs more RAM) sometimes using less will help (perhaps if you get more cache misses because of too much RAM being used).

 

5. Bottlenecks can be processor related or GPU related or bandwidth related or RAM related. They all play their parts depending on what you're doing and the system the code is running on.

 

6. I think you're blatantly misunderstanding this. A millisecond is more than a nanosecond. You're confusing speed (a rate) with time to accomplish something. If I can run a mile in 4 minutes that's the same as saying I can run a mile at 15MPH which is faster than someone who can run a mile in 6 minutes or 10 MPH. Lower time, faster rate.

 

7. It could be that your program is very efficient or very inefficient. Since we don't know what it's doing or even what kind of processor it is we can't possibly guess. If you made a basic clone of Super Mario Bros from the NES with the same resolution and type of pixel art and it was taking up 100MB and used 14% of a modern CPU that might be a sign your code isn't very efficient. If your 'clone' used much higher resolution sprites with 3d effects, more enemies, larger maps, and more eye candy then 100MB and 14% CPU might be decent. We can't know given the information you gave.




#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:

http://en.wikipedia.org/wiki/Gravity_of_Earth#Latitude_model

 

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;
            iterator++)
        {
            particleList[iterator].lifeTime -= 1.0f;
            if(particleList[iterator].lifeTime <= 0.0f)
            {
                std::swap(particleList[iterator], particleList[particleList.size() - 1]);
                particleList.pop_back();
                iterator--;
            }
            else
            {
            }

            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 = 70 -> WM_WINDOWPOSCHANGING

uMsg = 70 -> WM_WINDOWPOSCHANGING

uMsg = 28 -> WM_ACTIVATEAPP

uMsg = 134 -> WM_NCACTIVATE

uMsg = 127 -> WM_GETICON

uMsg = 127 -> WM_GETICON

uMsg = 127 -> WM_GETICON

uMsg = 6 -> WM_ACTIVATE

uMsg = 641 -> WM_IME_SETCONTEXT

uMsg = 642 -> WM_IME_NOTIFY

uMsg = 7 -> WM_SETFOCUS

uMsg = 133 -> WM_NCPAINT

uMsg = 20 -> WM_ERASEBKGND

uMsg = 71 -> WM_WINDOWPOSCHANGED

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

etc

 

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;
            BetaFunction(alpha);
            GammaFunction(alpha);
        }

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

        static void GammaFunction(AlphaClass alpha)
        {
            Console.WriteLine(alpha.x);
        }
    }

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.




PARTNERS