Seite 296 von 340 ErsteErste ... 196 246 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 ... LetzteLetzte
Zeige Ergebnis 8.851 bis 8.880 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; Hi. I'm working on an XMB replacement (for me only, I'm not looking to release it unless I really feel ...

  
  1. #8851
    QJ Gamer Bronze
    Points: 5.826, Level: 49
    Level completed: 38%, Points required for next Level: 124
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Everywhere
    Beiträge
    206
    Points
    5.826
    Level
    49
    Downloads
    0
    Uploads
    0

    Standard

    Hi. I'm working on an XMB replacement (for me only, I'm not looking to release it unless I really feel like it..) and I was wondering if anyone knew of a good tutorial on file browsing? I've got most everything else down.

    I need to, for example, open up the music folder and read all the folders, then open one up and read all the files...

    I can work my way into figuring it out, but I really just need a hint or two about reading a folder's contents.

    Thanks.


    Geändert von chrisp6825 (08-05-2008 um 09:58 PM Uhr)
    Pokemon Islands in Development : Qj Forum | Google Forum | Probords Forum

  2. #8852
    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

    dirent.h, their's a psp specific one but dirent.h has never failed me before so and it's a good file browser
    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. #8853
    QJ Gamer Green
    Points: 13.013, Level: 74
    Level completed: 41%, Points required for next Level: 237
    Overall activity: 0%

    Registriert seit
    Apr 2006
    Beiträge
    0
    Points
    13.013
    Level
    74
    Downloads
    0
    Uploads
    0

    Standard

    This probably has an easy solution but: how can I check if a float actually does have a decimal and numbers following it? Like for example if the float had a value of 12 then I would do this:

    Code:
    printf("%.0f", myFloat);
    but if it held say 12.23 I would do:

    Code:
    printf("%.2f", myFloat);

  4. #8854
    QJ Gamer Green
    Points: 5.712, Level: 48
    Level completed: 81%, Points required for next Level: 38
    Overall activity: 0%

    Registriert seit
    Jul 2006
    Ort
    USA SC/NC
    Beiträge
    699
    Points
    5.712
    Level
    48
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Frenchb0ygenius Beitrag anzeigen
    This probably has an easy solution but: how can I check if a float actually does have a decimal and numbers following it? Like for example if the float had a value of 12 then I would do this:

    Code:
    printf("%.0f", myFloat);
    but if it held say 12.23 I would do:

    Code:
    printf("%.2f", myFloat);
    A quick and simple solution would be:
    Code:
    #define IsWholeNumber(x) ((x == (float)(int)x)?true:false)
    Code:
    if(IsWholeNumber(myFloat)) { }
    Of course the whole issue of .9999999 = 1.0 thing comes into play, but that shouldn't be too much of a problem assuming that you don't need that kind of precision.
    [CODE]Random Facts:
    irc://irc.malloc.us #wtf #**********
    [/CODE]

    [SIZE="6"][FONT="Century Gothic"][COLOR="Blue"][URL="http://forums.**********.net"]http://forums.**********.net[/URL][/COLOR][/FONT][/SIZE]

  5. #8855
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

  6. #8856
    QJ Gamer Green
    Points: 13.013, Level: 74
    Level completed: 41%, Points required for next Level: 237
    Overall activity: 0%

    Registriert seit
    Apr 2006
    Beiträge
    0
    Points
    13.013
    Level
    74
    Downloads
    0
    Uploads
    0

    Standard

    Thanks.

  7. #8857
    lol
    Points: 20.859, Level: 91
    Level completed: 2%, Points required for next Level: 491
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    Whittier, CA
    Beiträge
    5.791
    Points
    20.859
    Level
    91
    Downloads
    0
    Uploads
    0

    Standard

    0x1000 is kernel
    0 is user
    0x0800 is vsh

    What other ones are there?
    I seen applications with 0x3007 and they work as kernel.

  8. #8858
    QJ Gamer Green
    Points: 4.092, Level: 40
    Level completed: 72%, Points required for next Level: 58
    Overall activity: 0%

    Registriert seit
    Jul 2008
    Beiträge
    508
    Points
    4.092
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    How would I change a previously kernel proggy(prx) into a user mode. I've tried porting it, but it doesn't like to work.

  9. #8859
    QJ Gamer Bronze
    Points: 5.826, Level: 49
    Level completed: 38%, Points required for next Level: 124
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Everywhere
    Beiträge
    206
    Points
    5.826
    Level
    49
    Downloads
    0
    Uploads
    0

    Standard

    Thanks slicer4ever, that got me to where I wanted!

    But I have something weird going on...
    I made a function to find all the folders in "ms0:/music/" and it worked perfectly when I first tried it out, by printing each folder name onto the screen..

    Spoiler for click for code:
    Code:
    void getMusicFolders()
    {
    	extern int NumFolders;
    	extern DIR * dir_p;
    	extern struct dirent * dir_entry_p;
    	
    	dir_p = opendir("ms0:/music/");
    	NumFolders = 0;
    	
    	int i = 0;
    	for (i = 0; NULL != (dir_entry_p = readdir(dir_p)); i++) {
    		sprintf(temp,"%s", dir_entry_p->d_name); //format text to string.
    		printTextScreen(10, 60+ (i*10), temp, White); //print each folder's name on screen.
    		MusicFolder[i] = temp; // store each folder name into string array.
    	}
    	closedir(dir_p);
    }


    Untill I added the part with the array. The array is there to store each folder's name into an index. Well, when I print them onto the screen right before I add them to the array, it works perfect. Each folder's name shows up.

    But when I store them into the array, it populates the array, but every index is one name. Like, I have a folder named "Mitch Hedberg" and every index of MusicFolder is "Mitch Hedberg". When I print them before (w/out array), there's only one.

    Spoiler for click for code:
    Code:
    for (i = 0; NULL != (dir_entry_p = readdir(dir_p)); i++) {
    	sprintf(temp,"%s", dir_entry_p->d_name); //format text to string.
    	printTextScreen(10, 60+ (i*10), temp, White); //Normal folder name's.
    	MusicFolder[i] = temp; // Always is "Mitch Hedberg".
    }


    I don't understand how this happens, nothing is happening to temp between when I print them out, and when I store them..

    Sorry if I got confussing during this..
    Pokemon Islands in Development : Qj Forum | Google Forum | Probords Forum

  10. #8860
    Developer
    Points: 14.558, Level: 78
    Level completed: 27%, Points required for next Level: 292
    Overall activity: 0%

    Registriert seit
    Mar 2006
    Beiträge
    166
    Points
    14.558
    Level
    78
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von chrisp6825 Beitrag anzeigen

    But when I store them into the array, it populates the array, but every index is one name. Like, I have a folder named "Mitch Hedberg" and every index of MusicFolder is "Mitch Hedberg". When I print them before (w/out array), there's only one.

    Spoiler for click for code:
    Code:
    for (i = 0; NULL != (dir_entry_p = readdir(dir_p)); i++) {
    	sprintf(temp,"%s", dir_entry_p->d_name); //format text to string.
    	printTextScreen(10, 60+ (i*10), temp, White); //Normal folder name's.
    	MusicFolder[i] = temp; // Always is "Mitch Hedberg".
    }


    I don't understand how this happens, nothing is happening to temp between when I print them out, and when I store them..

    Sorry if I got confussing during this..
    ever heard of pointers?
    see it like this, temp is a char array it lies somewhere on the stack.
    whenever you find a directory it copies its name to the temp variable:
    sprintf(temp,"%s", dir_entry_p->d_name); //format text to string.
    now you add them to an array:
    MusicFolder[i] = temp;
    but it doesn't copy its name to MusicFolder, what is happening is that MusicFolder actually points to where the temp variable is on the stack.
    So whenever you access the MusicFolder variable for output it looks up what is stored in temp so of course if you loop through it you'll get the same last name over and over again ;)
    Look up on pointers if you don't understand what I'm talking about, this is a common mistake.
    What you want to do should look like this:
    Code:
    
    #define MAX_CHAR 32
    #define MAX_ENTRIES 256
    char MusicFolder[MAX_ENTRIES][MAX_CHAR];
    memset(MusicFolder,0,sizeof(MusicFolder));
    for (i = 0; NULL != (dir_entry_p = readdir(dir_p)); i++) {
    	printTextScreen(10, 60+ (i*10), temp, White); //Normal folder name's.
    strncpy(MusicFolder[i],dir_entry_p->d_name,MAX_CHAR-1);//you need to copy the dir name!
    }
    -=Double Post Merge =-
    for some reasons I can't edit my post, there's a little error in it, temp var isn't really needed, additionally some error checking to prevent buffer overflows:
    Code:
    #define MAX_CHAR 32
    #define MAX_ENTRIES 256
    char MusicFolder[MAX_ENTRIES][MAX_CHAR];
    memset(MusicFolder,0,sizeof(MusicFolder));
    for (i = 0; NULL != (dir_entry_p = readdir(dir_p)); i++) {
    if(i<MAX_ENTRIES)
    {
    strncpy(MusicFolder[i],dir_entry_p->d_name,MAX_CHAR-1);//you need to copy the dir name!
    printTextScreen(10, 60+ (i*10), MusicFolder[i], White); //Normal folder name's.
    }
    }
    Geändert von tommydanger (08-06-2008 um 08:19 PM Uhr) Grund: Automerged Doublepost
    robot mafia

  11. #8861
    QJ Gamer Bronze
    Points: 5.826, Level: 49
    Level completed: 38%, Points required for next Level: 124
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Everywhere
    Beiträge
    206
    Points
    5.826
    Level
    49
    Downloads
    0
    Uploads
    0

    Standard

    Ahh dangit!.. ya I knew that. But for some reason I didn't think of it. I read your first sentence and remembered. haha

    Thanks a ton though!

    Why did you do this though..?
    char MusicFolder[MAX_ENTRIES][MAX_CHAR];
    why would you do that instead of this..?
    char *MusicFolder[256];
    Pokemon Islands in Development : Qj Forum | Google Forum | Probords Forum

  12. #8862
    Developer
    Points: 14.558, Level: 78
    Level completed: 27%, Points required for next Level: 292
    Overall activity: 0%

    Registriert seit
    Mar 2006
    Beiträge
    166
    Points
    14.558
    Level
    78
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von chrisp6825 Beitrag anzeigen
    Ahh dangit!.. ya I knew that. But for some reason I didn't think of it. I read your first sentence and remembered. haha

    Thanks a ton though!

    Why did you do this though..?
    char MusicFolder[MAX_ENTRIES][MAX_CHAR];
    why would you do that instead of this..?
    char *MusicFolder[256];
    again read up on pointers
    the former defines an array with MAX_ENTRIES entries, each MAX_CHAR long, you can use strcpy to fill it with whatever you want.

    the latter is an array of 256 pointers!
    there isn't room to specifically store anything unless you allocate space for it or there is already some space to point to. neither is it the case in your example
    however if you do want to use the latter you have to use it like this:
    Code:
    for (i = 0; NULL != (dir_entry_p = readdir(dir_p)); i++) {
    if(i<MAX_ENTRIES && dir_entry_p->d_namelen<MAX_CHAR)
    {
    //you have to first allocate space to use it properly!
    MusicFolder[i] = (char)malloc(dir_entry_p->d_namlen+1);
    if(MusicFolder[i] != NULL)
    {
    strncpy(MusicFolder[i],dir_entry_p->d_name,MAX_CHAR-1);//you need to copy the dir name!
    printTextScreen(10, 60+ (i*10), MusicFolder[i], White); //Normal folder name's.
    }
    }
    }
    again, with some error checks also don't forget to free MusicFolder at the end to prevent memory leaks!
    I do not recommend the latter version unless you really have the knowledge to know what you're doing
    the first version without the pointer array is much more convenient for you, also you don't have to deal with memory allocation etc. it's the easier approach for what you want ;)
    robot mafia

  13. #8863
    QJ Gamer Bronze
    Points: 5.826, Level: 49
    Level completed: 38%, Points required for next Level: 124
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Everywhere
    Beiträge
    206
    Points
    5.826
    Level
    49
    Downloads
    0
    Uploads
    0

    Standard

    Oh ok, thanks!

    I guess I'm too used to Java.. where array[5][5] is a matrix, and all that other stuff...

    But, ya I'm looking into the example you gave me and trying to figure it all out.
    I pretty much understand what it's doing now.

    I never really had to deal with pointers much before, so it's still a bit new.
    And I'm used to strings, being just plain strings.

    haha but thanks for the help!
    Pokemon Islands in Development : Qj Forum | Google Forum | Probords Forum

  14. #8864
    Developer
    Points: 14.558, Level: 78
    Level completed: 27%, Points required for next Level: 292
    Overall activity: 0%

    Registriert seit
    Mar 2006
    Beiträge
    166
    Points
    14.558
    Level
    78
    Downloads
    0
    Uploads
    0

    Standard

    in c array[5][5] is a matrix too at least you can treat it as such ;)
    yes java is much easier in that sense as it doesn't deal with pointers, garbage collector and you can assign names just by doing string1 = string2 or string1 = "foobar"
    however you can do that in C++ too, not C where you have to use stringfunctions like strlen, strcpy, strcat,....
    In C a string is just an array with a NULL Byte at the end, and you have to treat it like an array but yeah any decent C book/tutorial will mention that at some point so go read it ;)
    robot mafia

  15. #8865
    QJ Gamer Bronze
    Points: 5.826, Level: 49
    Level completed: 38%, Points required for next Level: 124
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Everywhere
    Beiträge
    206
    Points
    5.826
    Level
    49
    Downloads
    0
    Uploads
    0

    Standard

    Well, I know a bit about strings in C already, I'm just not used to it.
    I figured that strings were like arrays of their own cause of how you can access them the same and it has the null byte..

    I've noticed that you can make a string without a null byte at the end though.. what happens when you do that?


    Java does have pointers too though, I just somehow managed to get by without actually knowing how to deal with them.. I remember my comp sci teacher talking about how if you don't do something, the variable will end up referencing the memory location, instead of just the value...
    But I'm getting the hang of it, and I'm sure it wont take long for me to get used to C.
    Pokemon Islands in Development : Qj Forum | Google Forum | Probords Forum

  16. #8866
    Developer
    Points: 14.558, Level: 78
    Level completed: 27%, Points required for next Level: 292
    Overall activity: 0%

    Registriert seit
    Mar 2006
    Beiträge
    166
    Points
    14.558
    Level
    78
    Downloads
    0
    Uploads
    0

    Standard

    Well in C Strings it's all about the NULL byte. It is used to determine the length.
    for example strcpy which copies one string to another, it does that by looping through the source string and copies till it encounters the null byte.
    The same if you want to output a string, if no null byte is present it will output chars till it finds the null byte, even if the outputted content doesn't belong to the string.
    so something like this will compile fine but is bound to crash:
    char foo[3];
    strcpy(foo,"AAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAA AAAAAA");
    even though foo is only 3 bytes long it tries to copy all of AAAAAA...to foo.
    So having a C string it is important/mandatory to have a null byte.
    You can see how the null byte functions by doing:
    char foo []= "Hallo";
    printf("%s\n",foo);
    foo[0] = '\0'
    printf("%s\n",foo);
    What do you see?
    :P
    robot mafia

  17. #8867
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Just use C++ strings and a Standard Library container, it will make your life so much easier for this.

  18. #8868
    Points: 3.340, Level: 35
    Level completed: 94%, Points required for next Level: 10
    Overall activity: 0%

    Registriert seit
    May 2007
    Beiträge
    31
    Points
    3.340
    Level
    35
    Downloads
    0
    Uploads
    0
    Geändert von ultimate-psp (08-07-2008 um 04:38 PM Uhr)

  19. #8869
    Banned for LIFE
    Points: 18.744, Level: 86
    Level completed: 79%, Points required for next Level: 106
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Ort
    East London, England
    Beiträge
    2
    Points
    18.744
    Level
    86
    Downloads
    0
    Uploads
    0

    Standard

    A good solution would be not to use graphics.c

  20. #8870
    Points: 3.340, Level: 35
    Level completed: 94%, Points required for next Level: 10
    Overall activity: 0%

    Registriert seit
    May 2007
    Beiträge
    31
    Points
    3.340
    Level
    35
    Downloads
    0
    Uploads
    0

    Standard

    Yeh thought about that but prefer to keep graphics.c if possible. Hope so!

  21. #8871
    Developer
    Points: 7.577, Level: 58
    Level completed: 14%, Points required for next Level: 173
    Overall activity: 0%

    Registriert seit
    Mar 2006
    Beiträge
    1.026
    Points
    7.577
    Level
    58
    Downloads
    0
    Uploads
    0

    Standard

    Search this thread. intraFont + graphics.c has been covered before.

    Check out my homebrew & C tutorials at http://insomniac.0x89.org/
    Coder formerly known as Insomniac197

    tshirtz: what is irshell ??
    Atarian_: it's where people who work for the IRS go when they die

  22. #8872
    Points: 3.340, Level: 35
    Level completed: 94%, Points required for next Level: 10
    Overall activity: 0%

    Registriert seit
    May 2007
    Beiträge
    31
    Points
    3.340
    Level
    35
    Downloads
    0
    Uploads
    0

    Standard

    Edit2: Damn got it working. :)

    Just added sceGuTexMode(GU_PSM_8888, 0, 0, 0); to intaFontPrint.

    Much thanks for the hint IWN!!!
    Geändert von ultimate-psp (08-07-2008 um 04:36 PM Uhr) Grund: Automerged Doublepost

  23. #8873
    QJ Gamer Silver
    Points: 6.763, Level: 54
    Level completed: 7%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jul 2006
    Beiträge
    413
    Points
    6.763
    Level
    54
    Downloads
    0
    Uploads
    0

    Standard

    Does anyone know how to enable USB during a homebrew app? I'm trying to make a nifty little app but I can't quite figure it out :/ I've been looking through the usb headers like pspusb.h..etc. but they all haven't helped at all, simply nothing happens.. :/

    Thanks in advance.
    Atheist, because I just won't believe in what doesn't show itself to me.

  24. #8874
    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

    their's a sample for the usb in the sdk samples, i suggest looking at that as a starting point
    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

  25. #8875
    QJ Gamer Silver
    Points: 6.763, Level: 54
    Level completed: 7%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jul 2006
    Beiträge
    413
    Points
    6.763
    Level
    54
    Downloads
    0
    Uploads
    0

    Standard

    Ah, thanks.
    Atheist, because I just won't believe in what doesn't show itself to me.

  26. #8876
    QJ Gamer Gold
    Points: 14.678, Level: 78
    Level completed: 57%, Points required for next Level: 172
    Overall activity: 0%

    Registriert seit
    Nov 2006
    Beiträge
    1.523
    Points
    14.678
    Level
    78
    Downloads
    0
    Uploads
    0

    Standard

    I have come to point where I have to switch from graphics.c to Oslib. Any Barebone/SIMPLEST blit tutorials?

  27. #8877
    Points: 2.658, Level: 31
    Level completed: 39%, Points required for next Level: 92
    Overall activity: 0%

    Registriert seit
    Apr 2008
    Beiträge
    47
    Points
    2.658
    Level
    31
    Downloads
    0
    Uploads
    0

    Standard

    If you're switching for the sake of getting a higher frame rate I'd recommend just trying to learn the GU functions. You can get a remarkably higher frame rate with two steps:

    *Use swizzling on your textures
    *Try to use only one command-list per frame. That means removing the sceGuStart/sceGuFinish/sceGuSync from your blitting functions and then starting the list yourself (sceGuStart(GU_DIRECT, list)) then doing all your blits and finishing the list (sceGuFinish(); sceGuSync(0,0)). If you do those two things you should get a massive speed boost. Also, if you're using libmad from the Yeldarb tuts, recompile it with the following CFLAGS added:

    -O3 -frename-registers -ffast-math -fomit-frame-pointer

    For another massive speed boost.

    I'm still somewhat new to the GU myself, but I've learned enough to bring my 40fps program to 200+fps despite around 400 blits per frame. There's also easy ways to optimize filled rects and text drawing. I can give you more info if you're interested.

    Oh, one other thing. The alpha-blit-to-screen function from graphics.c is actually faster than the non-alpha one.

    I'm in the process of writing a tutorial series for using the GU for 2D graphics. PM me if you'd like what I have so far.
    Geändert von Khatharr (08-12-2008 um 06:56 PM Uhr)

  28. #8878
    QJ Gamer Blue
    Points: 4.008, Level: 40
    Level completed: 29%, Points required for next Level: 142
    Overall activity: 0%

    Registriert seit
    Dec 2007
    Ort
    dfgd
    Beiträge
    66
    Points
    4.008
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    Hi again all, ive been doing some thinking about C and i was wondering on how u would go about calling like *functions* in c.
    here is an example:
    Code:
    int startmenu()
    {
    code here of what ever
    while (1)
    {
    loop stuff here
    }
    return 0;
    }
    
    
    int Game()
    {
    code here of what ever
    while (1)
    {
    loop stuff here
    }
    return 0;
    }
    
    
    int main() {
    
    scePowerSetClockFrequency(333, 333, 166);
    		  pspDebugScreenInit();
              SetupCallbacks();
    		  initGraphics();
    		  StartMenu();
    if (MainGame == 1) {
    Game();
    }
    
    		  
              return 0;
    }
    now it does main and it starts startmenu; but then how can i go from startmenu to game?

    well basically how can u go from main() to another function then to another then to maybe main again?
    sorry if you dont get me im not that brilliant at explaining things, thanks for any help in advance!

    Luke:Jump:
    Geändert von lukespalding (08-13-2008 um 04:35 AM Uhr) Grund: Automerged Doublepost

  29. #8879
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Calling functions with infinite loops inside other infinite loops in functions is an EXTREMELY bad idea. You eventual run out of stack memory and crash the game. In addition, it becomes nigh on impossible to exit cleanly in a sensible way.

    Use a state machine:

    (C code below)

    Code:
    #define MAIN_MENU 0
    #define MAIN_GAME 1
    
    int main()
    {
    	int currentState = MAIN_MENU;
    	int gameInProgress = 1;
    	
    	while( gameInProgress )
    	{
    		switch( currentState )
    		{
    		case MAIN_MENU:
    			{
    				if( /* player selects to play game * / )
    				{
    					currentState = MAIN_GAME;
    				}
    			} break;
    		case MAIN_GAME:
    			{
    			
    			} break;
    		default: break;
    		}
    	}
    	
    	return 0;		
    }

  30. #8880
    QJ Gamer Bronze
    Points: 8.665, Level: 62
    Level completed: 72%, Points required for next Level: 85
    Overall activity: 0%

    Registriert seit
    Mar 2007
    Beiträge
    758
    Points
    8.665
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    Couldn't you use an enum instead of the preprocessor there?
    Code:
    int main()
    {
      enum state { MAIN_MENU, MAIN_GAME };
      state currentState = MAIN_MENU;
      return 0;
    }


 

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:27 PM Uhr.

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