1. Post #721
    Flubascrub
    Flubadoo's Avatar
    August 2009
    10,528 Posts
    #include <iostream>
    #include <string>
     
    using std::cin;
    using std::cout;
    using std::endl;
    using std::string;
     
    int main()
    {
        cout << "What is your name? " << endl;
        
        string name;
        cin >> name;
        
        const string greeting = "Hello, " + name + "!";
        
        cout << "How many spaces?" << endl;
        
        int pad;
        cin >> pad;
            
        const int rows = pad * 2 + 3;
        const string::size_type cols = greeting.size() + pad*2 + 2;
        
        cout << endl;
        
        for (int r = 0; r != rows; ++r){
        
            string::size_type c = 0;
            
            while (c != cols) {
                  
                  if (r == pad + 1 && c == pad + 1) {
                        cout << greeting;
                        c+= greeting.size();
                        } else {
                                
                                if (r == 0 || r == rows - 1 || c == 0 || c == cols - 1)
                                   cout << "*";
                                else
                                    cout << " ";
                                ++c;
                        }
                  }
            cout << endl;
        }
        system("pause");
        return 0;
    
    }
    

    Basically a modification of a program in C++, but I want to know a few things:

    1. What exactly does this do for the program in terms of it's job?
    Code:
    for (int r = 0; r != rows; ++r){
    . Why do I need to define what r is? I know how it works, but what's the point of seeing whether the # of rows is 0?

    2. If r and c are going to be 0, what's the point of checking whether # of rows is 0? Isn't that a bit useless?
    Reply With Quote Edit / Delete Windows 7 Qatar Show Events

  2. Post #722
    Gold Member
    Octave's Avatar
    January 2009
    2,530 Posts
    [cpp]
    Basically a modification of a program in C++, but I want to know a few things:

    1. What exactly does this do for the program in terms of it's job?
    Code:
    for (int r = 0; r != rows; ++r){
    . Why do I need to define what r is? I know how it works, but what's the point of seeing whether the # of rows is 0?

    2. If r and c are going to be 0, what's the point of checking whether # of rows is 0? Isn't that a bit useless?
    It doesn't check if r is 0; the single equals sign assigns 0 to r. So it's really saying r starts at 0 and increments whenever it isn't equal to rows.
    Reply With Quote Edit / Delete Linux United States Show Events

  3. Post #723
    Richy19's Avatar
    May 2010
    5,368 Posts
    It won't link properly without it for me.
    I've never actually done this, what does it change?
    Didnt they change it recently so that you have to define SFML_DYNAMIC?
    either way I define dynamic if im using dll and static if using static
    Reply With Quote Edit / Delete Windows XP United Kingdom Show Events

  4. Post #724
    Flubascrub
    Flubadoo's Avatar
    August 2009
    10,528 Posts
    It doesn't check if r is 0; the single equals sign assigns 0 to r. So it's really saying r starts at 0 and increments whenever it isn't equal to rows.
    So while r is not = to rows, it increments the value of r, but why is that necessary?
    Reply With Quote Edit / Delete Windows 7 Qatar Show Events

  5. Post #725
    sim642's Avatar
    July 2010
    1,039 Posts
    Didnt they change it recently so that you have to define SFML_DYNAMIC?
    either way I define dynamic if im using dll and static if using static
    It used to be SFML_DYNAMIC, but it was changed to SFML_STATIC. I remember it because this change affected my programs.
    Reply With Quote Edit / Delete Windows Vista Estonia Show Events Agree Agree x 1 (list)

  6. Post #726
    Gold Member
    WTF Nuke's Avatar
    March 2009
    4,424 Posts
    So while r is not = to rows, it increments the value of r, but why is that necessary?
    It's a loop, so while the value is not equal, then it will increment the value and then run the loop. So if row = 5, then it will run everything inside the loop 5 times, with r equaling 0,1,2,3,4.
    Reply With Quote Edit / Delete Windows 7 Canada Show Events Informative Informative x 1Late Late x 1 (list)

  7. Post #727
    Flubascrub
    Flubadoo's Avatar
    August 2009
    10,528 Posts
    It's a loop, so while the value is not equal, then it will increment the value and then run the loop. So if row = 5, then it will run everything inside the loop 5 times, with r equaling 0,1,2,3,4.
    But why is it necessary in the context of the program? When figuring out the number of rows, how does it add anything to it?
    Reply With Quote Edit / Delete Windows 7 Qatar Show Events

  8. Post #728
    Ask Rohan about rust keys!
    Bumrang's Avatar
    August 2011
    2,557 Posts
    If you truly want to start, I would go with C++. Why? For making games, it's the most used right now, and if your priority is learning a language that you can use for a job or something in the future, it's your best bet. While C++ does have quite a steep learning curve, it is nothing a beginner can't handle if they take baby steps.

    Personally right now I think you are sort of afraid of programming so you want to take a really easy language, but that wouldn't fit to what you wanted.

        Of course you could do Lua or Python and THEN move on to C++, but you said that you didn't want to "waste" your time learning a language if you aren't going to use it for a job in the future.    
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  9. Post #729
    bake someone a cake with laxatives and viagra and then they will have poopboners
    n0cturni's Avatar
    August 2007
    4,182 Posts
    Well, I don't necessarily need it for a job; I just want to be able to use it later on - I don't want it to become a "dead" or "unused" language 2 to 5 years from now.
    Reply With Quote Edit / Delete Linux United States Show Events Dumb Dumb x 1 (list)

  10. Post #730
    Ask Rohan about rust keys!
    Bumrang's Avatar
    August 2011
    2,557 Posts
    Well, I don't necessarily need it for a job; I just want to be able to use it later on - I don't want it to become a "dead" or "unused" language 2 to 5 years from now.
    I'm pretty sure Python or Lua aren't going to be dead in a few years, they still have a massive amount of people using them, and the numbers are growing.

    Really passionate about it? Go with C++.
    Still not so sure, or want to try it out before going to something serious? Python     or Lua if you want to be able to do stuff in Garry's Mod too.    

    Here's a little taste of what C++ is like at the very first stages (watch these videos and a few more after):


    These are links because I don't want to stretch the page:

    Number 2
    Number 3
    Number 4
    Reply With Quote Edit / Delete Windows 7 United States Show Events Useful Useful x 1 (list)

  11. Post #731
    I gave enough money to buy a soda.
    Funley's Avatar
    May 2010
    1,389 Posts
    Is it possible in XNA to load an image from the hard drive, not from the Content files and still get the file as a Texture2D.
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  12. Post #732
    NovembrDobby's Avatar
    April 2007
    1,138 Posts
    Is it possible in XNA to load an image from the hard drive, not from the Content files and still get the file as a Texture2D.
    Yep, Texture2D.LoadFromFile
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  13. Post #733
    I gave enough money to buy a soda.
    Funley's Avatar
    May 2010
    1,389 Posts
    Yep, Texture2D.LoadFromFile
    That simple? Oh i love XNA.
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  14. Post #734
    Gold Member
    Octave's Avatar
    January 2009
    2,530 Posts
    But why is it necessary in the context of the program? When figuring out the number of rows, how does it add anything to it?
    The number of rows seems to be already figured out, the loop is there so that the contents of the loop will be executed once for every row. It seems like it's printing rows of asterisks or something. So if there are 5 rows, it will execute that loop body 5 times and print 5 rows of asterisks.
    Reply With Quote Edit / Delete United States Show Events Programming King Programming King x 1 (list)

  15. Post #735

    January 2012
    414 Posts
    What's the name of the visual studio extension that shows the entire page of code on the right and a box highlighting what section of code you are looking at right now?
    Productivity Power Tools
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  16. Post #736
    Gold Member
    Parakon's Avatar
    November 2008
    8,520 Posts
    Ok so i figured out the dynamically naming bit. But i'm still having trouble, now my collision isn't picking anything up.

    Where the bullet is made and put into an array:

    Code:
    bullet = _root.attachMovie("bullet", "bull", _root.getNextHighestDepth());
    		bulletArray.push(["bull"+b])
    		b+=1
    Enemy getting hit:

    Code:
    	for (i = 0; i < _root.bulletArray.length; ++i)
    	{
    		if (this.hitTest(_root.bulletArray[i]))
    		{
    			_root.bulletArray[i]._x = -1000;
    			_root.bulletArray[i].dead = true;
    			this.hp -= 5;
    		}
    	}
    Still need help with this, I know i'm just missing something completely. But i've been trying to fix this for fucking days now.

    Basically it only checks the first bullet, and wont check the next until the first is destroyed, so if you miss the games broken.
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  17. Post #737
    Ask Rohan about rust keys!
    Bumrang's Avatar
    August 2011
    2,557 Posts
    Thanks, but I have Express edition, and it only works on Professional and above. Any alternative?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  18. Post #738
    Zyx
    Guest 3855 is lost and can't find the park exit
    Zyx's Avatar
    February 2005
    2,816 Posts
    Got a little problem with fullscreen applications in java.

    We're making fullscreen games in school now.
    At first I made a ScreenManeger that has a static method to enter fullscreen. That one is called OldGui.
    Then we had to make a GameFrame class extending JFrame that NewGui now extends.

    As far as I can see it's the same code just a different setup.

    Clicking on the JPanel will spawn 6000 sprites that animate and move aroundin both of the Guis.

    OldGui: 79-81ms to paint them all.
    NewGui: Ranging from 11-200ms to paint them all. Also throws a
    "java.lang.ClassCastException: [S cannot be cast to [I" exeption.

    Why it only happens in NewGui I have no idea, since they both use the same classes in the game package.

    If anyone want to check it out, this is the netbeans project: http://dl.dropbox.com/u/99717/Sprites.zip (Source files are in the Sprites/src folder)
    Reply With Quote Edit / Delete Windows 7 Show Events

  19. Post #739
    Gold Member
    MegaJohnny's Avatar
    April 2006
    5,140 Posts
    In C++, if an object (rather than a pointer to an object) is passed to a function, does it really create a copy of that object as it does with primitives?

    SFML has a lot of functions that take objects as arguments, should I be worrying about memory usage with the objects being copied? Or do they get destroyed automatically at the end of the function...
    Reply With Quote Edit / Delete Linux Russian Federation Show Events

  20. Post #740
    Richy19's Avatar
    May 2010
    5,368 Posts
    In C++, if an object (rather than a pointer to an object) is passed to a function, does it really create a copy of that object as it does with primitives?

    SFML has a lot of functions that take objects as arguments, should I be worrying about memory usage with the objects being copied? Or do they get destroyed automatically at the end of the function...
    It does indeed, however SFML takes in object references as arguments which means only its reference is passed.
    I.E
    blah(class & classReference){}
    Reply With Quote Edit / Delete Windows XP United Kingdom Show Events

  21. Post #741
    NovembrDobby's Avatar
    April 2007
    1,138 Posts
    In C++, if an object (rather than a pointer to an object) is passed to a function, does it really create a copy of that object as it does with primitives?

    SFML has a lot of functions that take objects as arguments, should I be worrying about memory usage with the objects being copied? Or do they get destroyed automatically at the end of the function...
    Be careful if you're passing 'heavy' objects around, like textures and images. You'll want to make sure you're passing those by ref or const reference.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Agree Agree x 1 (list)

  22. Post #742
    AtomiCasd's Avatar
    June 2011
    588 Posts
    In C++, if an object (rather than a pointer to an object) is passed to a function, does it really create a copy of that object as it does with primitives?

    SFML has a lot of functions that take objects as arguments, should I be worrying about memory usage with the objects being copied? Or do they get destroyed automatically at the end of the function...
    References are kinda like pointers but they aren't pointers, and if you think about storing them you're thinking about them in the wrong way. They function as an "alias" for the object that is being passed.
    If the function takes a reference, you just pass the object like this f(obj); and a refererence to that object gets passed automatically.

    You don't have to worry about anything since it happens automatically, but it's nice to know if the function passes a copy(nothing) or a reference (&) before you use it to avoid debugging problems.
    Reply With Quote Edit / Delete Windows 7 Norway Show Events

  23. Post #743
    Ask Rohan about rust keys!
    Bumrang's Avatar
    August 2011
    2,557 Posts
    I made this post in WAYWO but I think it's more suitable here:

    That would've been no use for me, the tutorial that I used for the base of the program wouldn't quite fit with breakout.

    I used this for starting my game but it all just spiraled down in the end.
    Why did I use it?

    Well, for me it was kinda like this: Lets say you have an idea for something to draw. You get out a piece of paper and get a pen but, you just can't put your pen down and actually start it.

    Same here, I didn't know which part of the program to start with. My last game (Pong) was a complete monstrosity     at least it was a full pong game even with changing ball speeds    . I had EVERYTHING in main.cpp. That's right, no classes. Not only that, but the movement didn't depend on time or framerate. So when I got off the slow laptop I was developing on and got on my desktop I couldn't even see the ball .

    So Facepunch, when you start a new game, what's the first thing you start with? That's pretty much all I need to start again right now.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  24. Post #744
    AtomiCasd's Avatar
    June 2011
    588 Posts
    Choose your library of choice. (i.e SFML)

    Game Manager(your main loop goes in this class, as with everything else), your main.cpp should only contain creating this class and calling its Run() function.
    GameStates (http://gamedevgeek.com/tutorials/man...e-states-in-c/)
    IntroState
    PlayState
    MenuState
    ...
    which contains these functions
    -Init
    -Input
    -Update
    -Draw
    -Cleanup

    Frame limiter(FPS) and pass frame delta time to update. SFML limits your framerate automatically but for physics and stuff you have to calculate the deltatime manually(curtime - lasttime)

    Implement a base entity class.

    Make game.

    Google everything, and look at articles explaining this subject. Browse forums for inspiration, i.e gamedev.net.
    Reply With Quote Edit / Delete Windows 7 Norway Show Events Useful Useful x 2 (list)

  25. Post #745
    Richy19's Avatar
    May 2010
    5,368 Posts
    Are there any other usefull plugins such as this one?
    Reply With Quote Edit / Delete Windows XP United Kingdom Show Events

  26. Post #746
    JohnnyOnFlame's Avatar
    February 2011
    2,079 Posts
    How does one rotate Normals in GLSL in order to have lightning correct in moving objects?
    Reply With Quote Edit / Delete Windows 7 Brazil Show Events

  27. Post #747
    Gold Member
    Smashmaster's Avatar
    April 2005
    1,505 Posts
    How does one rotate Normals in GLSL in order to have lightning correct in moving objects?
    We need more detail than that. You're most likely gonna need a matrix.

    Also, I need to address this.

    THIS:


    IS NOT THE SAME AS THIS:
    Reply With Quote Edit / Delete Windows 7 United States Show Events Funny Funny x 3Agree Agree x 2Dumb Dumb x 1Informative Informative x 1 (list)

  28. Post #748
    Gold Member

    March 2005
    3,028 Posts
    How does one rotate Normals in GLSL in order to have lightning correct in moving objects?
    You generate a rotation matrix from the object's orientation.
    If you're lazy you can take the upper-left 3x3 of the model/view matrix, but that will only work if you don't have any skew or nonuniform scale.
    Reply With Quote Edit / Delete Windows 7 Show Events Programming King Programming King x 1 (list)

  29. Post #749
    Gold Member
    Smashmaster's Avatar
    April 2005
    1,505 Posts
    You generate a rotation matrix from the object's orientation.
    If you're lazy you can take the upper-left 3x3 of the model/view matrix, but that will only work if you don't have any skew or nonuniform scale.
    This is the "What do you need help with" thread, so if he needs help with his spelling, I will provide.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Dumb Dumb x 2 (list)

  30. Post #750

    January 2012
    414 Posts
    Thanks, but I have Express edition, and it only works on Professional and above. Any alternative?
    Not especially, not for express at least, as express doesn't support addons. It's microsoft's gotcha for trying to get you to upgrade, along with limited mfc support and a ton of other shit.

    If you're in school, go to dreamspark, sign up with your school email, and get the full version.
    Reply With Quote Edit / Delete Windows 7 Canada Show Events Informative Informative x 1 (list)

  31. Post #751
    JohnnyOnFlame's Avatar
    February 2011
    2,079 Posts
    You generate a rotation matrix from the object's orientation.
    If you're lazy you can take the upper-left 3x3 of the model/view matrix, but that will only work if you don't have any skew or nonuniform scale.
    That worked, thanks alot!
    (No, I'll not use any skew/uniform stuff, I'll use fixed meshes.)
    Reply With Quote Edit / Delete Windows 7 Brazil Show Events

  32. Post #752
    Ask Rohan about rust keys!
    Bumrang's Avatar
    August 2011
    2,557 Posts
    Could you expand a little more? When I googled them all I got was some pastebin classes, no actual explanation.

    I marked it for you:

    Choose your library of choice. (i.e SFML)

    Game Manager(your main loop goes in this class, as with everything else), your main.cpp should only contain creating this class and calling its Run() function. So the only thing in main would be the Run() function and that's it? Really? Neat.
    GameStates (http://gamedevgeek.com/tutorials/man...e-states-in-c/)
    IntroState expand
    PlayState on
    MenuState these
    ...
    which contains these functions
    -Init
    -Input
    -Update expand on all of these as well, no luck with google, just like the last ones.
    -Draw
    -Cleanup

    Frame limiter(FPS) and pass frame delta time to update. SFML limits your framerate automatically but for physics and stuff you have to calculate the deltatime manually(curtime - lasttime)

    Implement a base entity class. When I googled this all I got was people asking how to make one, not what it is.

    Make game.

    Google everything, and look at articles explaining this subject. Browse forums for inspiration, i.e gamedev.net.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  33. Post #753
    italian
    TerabyteS_'s Avatar
    June 2011
    2,644 Posts
    I'm trying to learn how to create associations between objects in OOP. Say I have this diagram:



    Basically, any Workplace may have any number of Employees but an Employee may not work at more than one Workplace at the same time.

    What is the correct way to implement this in an object-oriented programming language?
    My guess is that the Workplace class should manage an array (or possibly a dynamic list) of Employee instances and expose methods to add or remove employees, which would naturally map them to said array.

    An Employee object, on its side, would have to be added to a Workplace object.

    Now that I think of it, though, there's a problem with the fact that the relationship from Employee to Workplace is not enforced in that multiple Workplaces could have the same instance of Employee added to them. How could I avoid that situation? Is my whole idea correct?
    Reply With Quote Edit / Delete Windows 7 Anonymous Proxy Show Events

  34. Post #754
    Yanukovich Style
    Dennab
    January 2008
    2,888 Posts
    Hey, I have a project in college to do, basically it's a program where it asks questions to user and user has to choose 1 out of 4 answers.
    So my quetion is: How or where should I stor - Question,Right answer, option1, option2, option3 and perhaps some more things. Should I use some kind of database? or can it be stored in text file which would be somehow read? I am using netbeans and it's java btw. Any ideas/suggestions?
    Reply With Quote Edit / Delete Windows 7 Ireland Show Events

  35. Post #755
    Zyx
    Guest 3855 is lost and can't find the park exit
    Zyx's Avatar
    February 2005
    2,816 Posts
    I'm trying to learn how to create associations between objects in OOP. Say I have this diagram:



    Basically, any Workplace may have any number of Employees but an Employee may not work at more than one Workplace at the same time.

    What is the correct way to implement this in an object-oriented programming language?
    My guess is that the Workplace class should manage an array (or possibly a dynamic list) of Employee instances and expose methods to add or remove employees, which would naturally map them to said array.

    An Employee object, on its side, would have to be added to a Workplace object.

    Now that I think of it, though, there's a problem with the fact that the relationship from Employee to Workplace is not enforced in that multiple Workplaces could have the same instance of Employee added to them. How could I avoid that situation? Is my whole idea correct?
    I'd say giving the Workplace a list/array/map of Employee and give the Employee a single Workplace variable.
    The method to add an employee in the Worplace should have an Employee as a parameter. The Workplace could then check that the employee.workplace == null.
    Reply With Quote Edit / Delete Windows 7 Show Events

  36. Post #756
    italian
    TerabyteS_'s Avatar
    June 2011
    2,644 Posts
    I'd say giving the Workplace a list/array/map of Employee and give the Employee a single Workplace variable.
    The method to add an employee in the Worplace should have an Employee as a parameter. The Workplace could then check that the employee.workplace == null.
    And then the workplace should do something like employee.workplace = this;?
    Reply With Quote Edit / Delete Windows 7 Anonymous Proxy Show Events

  37. Post #757
    Zyx
    Guest 3855 is lost and can't find the park exit
    Zyx's Avatar
    February 2005
    2,816 Posts
    And then the workplace should do something like employee.workplace = this;?
    //Method in the Workplace class
    public void addEmployee(Employee employee)
    {
        if(employee.getWorkPlace() == null)
        {
        employees.add(employee);
        employee.setWorkPlace(this);
        }
    }
    
    //Method in the Employee class
    public void setWorkPlace(Workplace workplace)
    {
        this.workplace = workplace;
    }
    
    

    Of course Workplace should have a method to remove an employee that also sets that employees workplace to null.
    Employees could also have a method that does the same thing.
    Reply With Quote Edit / Delete Windows 7 Show Events Friendly Friendly x 1 (list)

  38. Post #758
    -Kesil-'s Avatar
    February 2012
    87 Posts
    So my program will make 100 random points scattered over a 2d surface.
    From these points I need to generate shapes.

    This is an illustration of the 2 phases I need my program to go through.
    1.) Points
    2.) generating shapes

    I need the surface area to be limited to a certain amount (because the points at the edge can't expand forever)

    Is there an algorithm associated with this that someone can name for me?

    Reply With Quote Edit / Delete Windows 7 United States Show Events

  39. Post #759
    Flubascrub
    Flubadoo's Avatar
    August 2009
    10,528 Posts
    http://pastebin.com/v3bmNKk3

    I know the formatting is all wonky since all of the endls are in the wrong places, but this C++ program only prints out two integers at most, any idea why?
    Reply With Quote Edit / Delete Windows 7 Qatar Show Events

  40. Post #760
    Gold Member
    BackwardSpy's Avatar
    May 2008
    6,335 Posts
    So my program will make 100 random points scattered over a 2d surface.
    From these points I need to generate shapes.

    This is an illustration of the 2 phases I need my program to go through.
    1.) Points
    2.) generating shapes

    I need the surface area to be limited to a certain amount (because the points at the edge can't expand forever)

    Is there an algorithm associated with this that someone can name for me?

    Look into Voronoi diagrams.

    Edited:

    http://en.wikipedia.org/wiki/Voronoi_diagram
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Agree Agree x 3 (list)