Seite 337 von 340 ErsteErste ... 237 287 327 328 329 330 331 332 333 334 335 336 337 338 339 340 LetzteLetzte
Zeige Ergebnis 10.081 bis 10.110 von 10174

C/C++ Programming Help Thread

This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Beat_Bob - In your position, accessing a method or variable of some object declared as the following will cause your ...

  
  1. #10081
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    Beat_Bob - In your position, accessing a method or variable of some object declared as the following will cause your problem.
    Code:
    player blah(); // bad definition
    ...
    blah.method(); // this line will raise the error
    blah.X = 10; // and this...
    If a constructor of the object has no parameters, you should NOT use parenthesis in it's declaration, write it rather as:
    Code:
    player blah;
    ...
    blah.method();
    blah.X = 10;



    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  2. #10082
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    Zitat Zitat von Beat_Bob Beitrag anzeigen
    Why cant I access the x member in my class: player ?
    C++ code - 52 lines - codepad

    I get this error:
    Code:
    main.cpp:27: error: request for member 'x' in 'myPlayer', which is of non-class
    type 'player ()()'
    beat_bob, this is one that you could actually test with codepad itself:

    C++ code - 18 lines - codepad

    hope this helps

    edit: sg beat me=-(
    1. Failed....again...
    2. http://slicer.gibbocool.com/ stay updated on all my projects
    3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been

  3. #10083
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    damn right I beat you just like last night ohhhhhhh :humped:

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  4. #10084
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    Zitat Zitat von SG57 Beitrag anzeigen
    damn right I beat you just like last night ohhhhhhh :humped:
    epic pic, just...epic, o and **** you:Jump:
    1. Failed....again...
    2. http://slicer.gibbocool.com/ stay updated on all my projects
    3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been

  5. #10085
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    In the function:
    extern void fillScreenRect(Color color, int x0, int y0, int width, int height);

    What would I place for the color parameter?
    Lets say I wanted..red for example?
    Would it be a string? "FF0000"

  6. #10086
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    no, u'd pass in a Color struct

    IIRC, something like:

    Color c(255,0,0,255);
    fillScreenRect(c, 0,0,100,100);

    but it's been a long time since i've used graphics.h, so might not be correct
    1. Failed....again...
    2. http://slicer.gibbocool.com/ stay updated on all my projects
    3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been

  7. #10087
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    Oh okay thanks.
    Well also I've got yet another error:
    Code:
    player.cpp: In function 'void Step()':
    player.cpp:9: error: 'x' was not declared in this scope
    player.cpp:10: error: 'y' was not declared in this scope
    C++ code - 23 lines - codepad

    What's the dillio?

  8. #10088
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    You need to declare that Step is in the player namespace somehow to access the variable within that namespace.
    Code:
    void player::Step()  { blah blah }

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  9. #10089
    Developer
    Points: 8.092, Level: 60
    Level completed: 72%, Points required for next Level: 58
    Overall activity: 0%

    Registriert seit
    Jul 2008
    Ort
    Grand Rapids! MI
    Beiträge
    125
    Points
    8.092
    Level
    60
    Downloads
    5
    Uploads
    2

    Standard

    Zitat Zitat von SG57 Beitrag anzeigen
    lilmnm - It isn't part of the SDK, it is part of stdlib. Its not that it 'will' overflow, its just a good habit and to be consciously aware of what might happen.

    Practical use: I used a 256 long buffer for a texture filepath that ended up being like 300 characters long after all was done with it from the relative sub-directories. I couldn't figure out 'why' it was failing to load until I realized it was cutting off the final few chars of the filename. If I hadn't of used snprintf, it would've been a buffer overflow with undefined behavior. Instead I simply printed the buffer out to the debug stream and sure enough I saw it was missing the last half of the filename. Then I simply upped the buffer to 400 in size.
    thats why the buffer there has extra space so there wont be no overflow its simply security and if that fails then no big just bring the size up more to a reasonable about but for simple debug text you should have a problem with overflow (unless i guess it had a bug in the program where it trys loading more then you want to into the buffer then i guess there can be a overflow) but i never had a problem with it its kinda basic math each letter or symbol would equal one byte you set the size of the buffer in bytes so you should always but a few extra bytes into the buffer then logically needed to cope with over flow. now for the function you answered my question and yes stdlib is part of the SDK just not the PSPSDK that file is imported to help the PSPSDK to compile and thats still pretty much answered my question what file it is in

  10. #10090
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    Now I get this:
    Code:
    main.cpp: In function 'int main()':
    main.cpp:32: error: initializer expression list treated as compound expression
    main.cpp:32: warning: left-hand operand of comma has no effect
    main.cpp:32: warning: right-hand operand of comma has no effect
    main.cpp:32: warning: right-hand operand of comma has no effect
    main.cpp:34: warning: statement is a reference, not call, to function 'fillScr
    nRect'
    main.cpp:34: warning: statement has no effect
    main.cpp:34: warning: left-hand operand of comma has no effect
    main.cpp:34: warning: right-hand operand of comma has no effect
    main.cpp:34: warning: right-hand operand of comma has no effect
    main.cpp:34: warning: right-hand operand of comma has no effect
    C++ code - 62 lines - codepad

  11. #10091
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    alright, i looked up the graphics.h, in graphics.h underneath:

    Code:
    #define A(color) ((u8)(color >> 24 & 0xFF))
    #define B(color) ((u8)(color >> 16 & 0xFF))
    #define G(color) ((u8)(color >> 8 & 0xFF))
    #define R(color) ((u8)(color & 0xFF))
    add:
    Code:
    #define RGBA(r,g,b,a) ((r)<<24|(g)<<16|(b)<<8|a)
    then it'll work
    1. Failed....again...
    2. http://slicer.gibbocool.com/ stay updated on all my projects
    3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been

  12. #10092
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    lilmnm - That extra space is a technical waste despite how virtually minuscule it is since you are expecting a 3 digit number tops yet you're compensating for some 7 digit number. Apply that to something with a substantial size like a texture or uncompressed audio and that won't work. Besides, when an exploiter pokes around and makes the sceGetCpuClockSpeed or w/e function return a large 32 bit integer value (10,000,000+) your buffer will overflow and you will get undefined behavior as a result.

    These Saved Game exploits and the infamous Twilight Hack in Zelda on the Wii are all caused by programmers that do **** just like that. You get to name your horse in Zelda Twilight Princess. Max characters are something like 15. "Cool we'll just have the OSK max out the character entry at 15." Logically there is no way to make it overflow in code. Well when the saved data got hacked and the horse name changed to "asdbasfjaksdjfksjdfksajd fksjfksjfiwjef" it overflowed the buffer and oh geez the Wii is now a piracy machine. Look at the libtiff exploit NUMEROUS times on PSP, GTA exploit, Lumines exploit, Gripshift exploit, the list goes on. Hell even the KXploit if you have been around long enough for that. Did you know PacMan does this as well? They use an unsigned char as the level variable. An unsigned char can hold at max 256 values (starting at 0) so when you get to the 256th level it overflows and the undefined behavior that occurs is half hte level is distorted to hell. Those are all stupid programming mistakes that a simple snprint instead of sprint (or something similar obviously, depends on the data type) would've prevented. It reads in the name from the saved data file and puts it into the 'name' buffer, if you will. If it doesn't limit the name to the size of the buffer, you get your overflow.

    It might not be so black and white for integers but like so many exploits involving literal strings there is no limit to the length to receive. You can size that char array up all you want until it corrupts the stack for all I care but I could just keep appending 'asdfasdf'.

    There is no safer way to prevent undefined behavior then to prevent the processes that cause it.
    sprintf reads the formatted string buffer into the destination buffer.
    snprintf will read, at most, 'n' number of bytes from the formatted string buffer into the destination buffer.

    The whole point is to operate using good habits. These overflows might never happen if you use dynamically allocated variables such as STL containers but its still better to be safe then sorry. (I'm sure Sony management got pissed at GTA for what they did hah)
    Geändert von SG57 (04-14-2010 um 08:45 PM Uhr)

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  13. #10093
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    Got it.
    Well i've got another problem (of course).

    My while(1) loop seems to crash my PSP (I have to restart it)
    C++ code - 48 lines - codepad

    Even without that function in it, it still crashes.
    All the function does is increase 2 members (x and y) of that class by 2.

  14. #10094
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    it doesn't crash, it just never exits out of the loop, that's the problem
    1. Failed....again...
    2. http://slicer.gibbocool.com/ stay updated on all my projects
    3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been

  15. #10095
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    How would I fix it?

  16. #10096
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    don't go into an infinite loop

    while(1) basically says keep doing whatever is in my {}'s until u say break, nothing well break out of it unless u call break, or make the while loop dependent on a variable that u can change i.e:

    Code:
    int i=0;
    bool done=false;
    while(!done){
       i++;
       if(i==10) done=true;
    }
    printf("%d\n",i);
    of course it'd be easier to use a for loop for what i demonstrated, but this is to show the concept, u could also do:

    Code:
    int i=0;
    while(i){
       i++;
       if(i==10) break;
    }
    printf("%d\n",i);
    1. Failed....again...
    2. http://slicer.gibbocool.com/ stay updated on all my projects
    3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been

  17. #10097
    QJ Gamer Green
    Points: 2.003, Level: 27
    Level completed: 2%, Points required for next Level: 147
    Overall activity: 0%

    Registriert seit
    Jun 2009
    Beiträge
    61
    Points
    2.003
    Level
    27
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von lilmnm Beitrag anzeigen
    because the way scePowerGetCpuClockFreque ncy(); was set up was to return the cpu to a buffer or t fill in the variable and %d is the variable that is being represented in the printf because we dont know what the CPU speed is so we find out what it is then return it to the variable


    the way you should use it is by

    Code:
    int CPUClock[17]; //buffer to save the info
    sprintf(CPUclock, "CPU: %d", scePowerGetCpuClockFrequency()); //Only prints out the CPU speed i.e. 333 or 222
    A better way is to show both the CPU speed and the BUS speed and heres how
    Code:
    int CPUClock[17]; //buffer to save the info
    //this following line will print out the CPU and the BUS speed i.e. 333/166 or 222/111
    sprintf(CPUclock, "CPU/BUS: %d/%d", scePowerGetCpuClockFrequency(), scePowerGetBusClockFrequency());
    Dont forget to add #include <psppower.h> to the main.c and or main.h if you have one for the cpu stuff and add
    -lpsppower to the LIBS = line in your make file

    hope i explained it clearly enough if it doesn't make any sense then ask another question and ill clarify it
    Ty, but that wasn't really my question I was wondering how to use it with printtextscreen cause I never saw it but i tough it should be possible

  18. #10098
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    LegendMythe - You would use the char buffer (not int buffer that he mistakenly used) with the print text screen function after formatting it.
    Code:
    char text[9];
    snprintf(text, 9, "CPU: %d", scePowerGetCpuClockFrequency());
    printTextScreen(x, y, text, RGBA(255,255,255,255));

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  19. #10099
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    Okay thanks.
    Also, how do I access members from outside of a class?

    Ex:
    I have a variable:
    int x;

    in my main.cpp file

    Lets say I had a class in myclass.cpp, how would I access that variable 'x' ?

    main.cpp:
    int x;

    myclass.cpp:

    #include myclass.h
    y = main.cpp.x;

    How do I do it?

  20. #10100
    Developer
    Points: 8.092, Level: 60
    Level completed: 72%, Points required for next Level: 58
    Overall activity: 0%

    Registriert seit
    Jul 2008
    Ort
    Grand Rapids! MI
    Beiträge
    125
    Points
    8.092
    Level
    60
    Downloads
    5
    Uploads
    2

    Standard

    Zitat Zitat von SG57 Beitrag anzeigen
    LegendMythe - You would use the char buffer (not int buffer that he mistakenly used) with the print text screen function after formatting it.
    Code:
    char text[9];
    snprintf(text, 9, "CPU: %d", scePowerGetCpuClockFrequency());
    printTextScreen(x, y, text, RGBA(255,255,255,255));
    yeah thats one thing i forgot to fix when i was typing the function sorry

  21. #10101
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    Beat_Bob - What you want would involve using the 'extern' keyword and another source file and it gets ugly fast. You could wrap your main 'program' into a class of its own (normally called 'Game' or 'GameEngine') with a 'setX' function then have a function in your myclass function take the GameEngine class as a parameter and call 'setX' from that. Or you could have the 'myclass' class have a function that takes a pointer to an integer which then alters it that way, but really - it is exceptionally good design to make a class should directly manipulate its own members. So the variable 'x' should be within the 'myclass' class and that class should handle directly manipulating it. You can make a pair of 'helper' methods for that class to 'get' the x value for say drawing at that x position later on, you'd have a 'get' function in the 'myclass' class that would return a constant reference to it.
    Code:
    // myclass.h
    class myclass
    {
      private:
        int x;
      
      public:
        myclass() : x(0)
        {}
    
        void setX(const int& k) { x = k; }
        const int& getX() const { return x; }
    };
    Then later on in main.cpp
    Code:
    myclass object;
    ...
    object.setX(240);
    ...
    printTextScreen(object.getX(), 0, "asdf", RGBA(0,0,0,0));

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  22. #10102
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    umm, sg, why are u using an &?, it's an single int....
    1. Failed....again...
    2. http://slicer.gibbocool.com/ stay updated on all my projects
    3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been

  23. #10103
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    Using references in C++ is a good early habit to get into, though you are right since they are more for larger containers than an integer but still...

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  24. #10104
    QJ Gamer Green
    Points: 2.003, Level: 27
    Level completed: 2%, Points required for next Level: 147
    Overall activity: 0%

    Registriert seit
    Jun 2009
    Beiträge
    61
    Points
    2.003
    Level
    27
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von SG57 Beitrag anzeigen
    LegendMythe - You would use the char buffer (not int buffer that he mistakenly used) with the print text screen function after formatting it.
    Code:
    char text[9];
    snprintf(text, 9, "CPU: %d", scePowerGetCpuClockFrequency());
    printTextScreen(x, y, text, RGBA(255,255,255,255));
    Ty but doesn't that has to be "sprintf" instead of "snprintf"?
    and my program chrashes how should i use it like this?

    Code:
    #include <psppower.h>
    #include <pspkernel.h>
    #include <pspdisplay.h>
    #include <pspctrl.h>
    #include "graphics.h"
    #include "callback.h"
    #include <stdio.h>
    
    int main () {
    
    SetupCallbacks();
        initGraphics();
    
        SceCtrlData pad, lastpad;
    
        sceCtrlReadBufferPositive(&lastpad, 1);
    while(1) {
          sceCtrlReadBufferPositive(&pad, 1);
    
          if(pad.Buttons != lastpad.Buttons) {
          lastpad = pad;
    if (pad.Buttons & PSP_CTRL_CROSS) {
    
    char text[9];
    sprintf(text, 9, "CPU: %d", scePowerGetCpuClockFrequency());
    printTextScreen(x, y, text, RGBA(255,255,255,255));
    
    }
    }
    }
    return 0;
    }
    Geändert von LegendMythe (04-16-2010 um 03:06 AM Uhr)

  25. #10105
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    LegendMythe -

    We literally just got done talking about it lilmnm and I.. did you not read those posts? The reason its crashing is because you changed snprintf to sprintf but you didn't remove the second argument that is specifically for snprintf and that is how many bytes to read from the formatted string, so its actually expecting a pointer to the first character of the formatting string but getting an integer pointing to who knows where in temporary memory.

    The reason the compiler won't catch this is because the variable argument symbol ... allows anything but sprintf expects a string and you as the programmer must give it what it wants (this wouldn't have happened if you would've just stayed with snprintf since it expects an integer as 2nd and would call an error if not supplied). Either use snprintf or remove the second argument from your current code.

    --------
    in an unrelated turn of events...

    5,000th post! Just shy of 5 years, that means I'm making over a 1000 posts a year muaha.
    Geändert von SG57 (04-16-2010 um 07:56 AM Uhr)

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  26. #10106
    QJ Gamer Green
    Points: 2.003, Level: 27
    Level completed: 2%, Points required for next Level: 147
    Overall activity: 0%

    Registriert seit
    Jun 2009
    Beiträge
    61
    Points
    2.003
    Level
    27
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von SG57 Beitrag anzeigen
    LegendMythe -

    ...

    --------
    in an unrelated turn of events...

    5,000th post! Just shy of 5 years, that means I'm making over a 1000 posts a year muaha.
    srry I was to lazy to read everything, ty to explain it to a noob(me) :)

  27. #10107
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    Zitat Zitat von LegendMythe Beitrag anzeigen
    I was to lazy to read everything

    You did say thank you, so you get the not-so-bad implied facepalm.

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  28. #10108
    QJ Gamer Green
    Points: 2.003, Level: 27
    Level completed: 2%, Points required for next Level: 147
    Overall activity: 0%

    Registriert seit
    Jun 2009
    Beiträge
    61
    Points
    2.003
    Level
    27
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von SG57 Beitrag anzeigen
    You did say thank you, so you get the not-so-bad implied facepalm.
    lol

  29. #10109
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    Err not sure if that's what I meant.
    This is what I want to do actually though.

    Let's say I wanted to access my pad variable in main.cpp from my player.cpp file:
    SceCtrlData pad;

    So that way, I could make a function in player (a loop):
    void Step(){
    if(pad.Buttons & PSP_CTRL_WHATEVER){
    //do something with player depending on pad's button state
    }

    }

    And I could just call step in main.cpp.
    However, pad does not exist in player.cpp, it is only local to main.cpp

    So what would I do?

  30. #10110
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    You would do:
    Code:
    // main.cpp
    if (pad.Buttons & PSP_CTRL_WHATEVER)
    {
      player.Step();
    }
    I recommend having 3 main functions in your main source file so things don't get ugly once your game starts evolving. Input, Update and Draw. Each one handles only things that fit into their category. All input related code goes in Input, all input-related code is completely game specific and will probably never be re-used in another game. All 'logical' code from collision detection to a simple counter increment expression to advanced A.I.. All drawing related code goes in the Draw function. The Update and Drawing method will have code that can be re-used in other games. Then your main loop looks something like:
    Code:
    while(1)
    {
      Input();
      Update();
      Draw();
    }
    Other naming patterns exist, such as Input, Processing and Output (since that is what you're doing essentially) and HandleEvents, Think, Display (also what you're doing). I prefer the code I showed for no particular reason, I guess because I devised it on my own years ago before reading a single game design article. I was sick of messy code so I split it into those 3.

    Anyways, Classes should always try and be both platform and game independent. This allows for better code re-usability and it helps break your game up into smaller more manageable chunks allowing you to add to your game easier. The idea is that you should be able to take the Ball class from a Pong game and use it in a Breakout game with little to no change since their functionality is practically the same. 9 times out of 10 you are better off re-writing the game's source from scratch anyways but helpful classes and templates are almost always brought over. For example, I have a Fader class I use for transitions to fade the screen to black or white.

    Now obviously there will be a point at which a class object is too game specific and it can't be re-used (such as an Enemy class, most Enemies aren't too similar from game to game when we talk about AI, scripting, abilities, etc.). Since all Input is game specific, putting game specific code in a non-game specific class is counter intuitive and defeats the whole purpose... Instead, make a method that carries out what you want (ie, Step) and have the game specific code run it if it wants to. In this case, if you are pressing UP or whatever, you call the step function.

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here



 

Tags for this Thread

Forumregeln

  • Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
  • Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
  • Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
  • Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.
  •  





Alle Zeitangaben in WEZ -8. Es ist jetzt 09:15 PM Uhr.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © , Caputo Media, LLC. All Rights Reserved. Cluster .