Seite 246 von 340 ErsteErste ... 146 196 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 296 ... LetzteLetzte
Zeige Ergebnis 7.351 bis 7.380 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; I havn't got access to my codes at the moment, but I was wondering if it was possible to store ...

  
  1. #7351
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    I havn't got access to my codes at the moment, but I was wondering if it was possible to store the data of the screen display buffer in memory using the graphics.c...

    I want to make a function that will read the current thing on screen, and store it away for use later, I thought it would be as simple as just using getVramDisplayBuffer but I realised this only returns a pointer, and that the display buffer constantly changing means the data is changed too, I need to keep that data, I was thinking about using malloc to make the memory, but I'm not sure off the top of my head what arguments to use, so if anyone knows how to do this (or an easier way) I'd love to hear it :)

    Sorry if I explained that badly, or just rambled, I just hope I got my question across properly.

    Also, has anyone got an code showing how to mount flash2 as read/write as I can't find the arguments required, I assumed flash2 but it returned the nodev error, I also tried assigning it incase it wasn't already assigned, again no luck, so any pointers on this would be aprechiated.

    -Aura


    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  2. #7352
    Your Fate is Grim...
    Points: 11.640, Level: 70
    Level completed: 98%, Points required for next Level: 10
    Overall activity: 0%

    Registriert seit
    Oct 2005
    Beiträge
    2.269
    Points
    11.640
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Auraomega
    I havn't got access to my codes at the moment, but I was wondering if it was possible to store the data of the screen display buffer in memory using the graphics.c...

    I want to make a function that will read the current thing on screen, and store it away for use later, I thought it would be as simple as just using getVramDisplayBuffer but I realised this only returns a pointer, and that the display buffer constantly changing means the data is changed too, I need to keep that data, I was thinking about using malloc to make the memory, but I'm not sure off the top of my head what arguments to use, so if anyone knows how to do this (or an easier way) I'd love to hear it :)

    Sorry if I explained that badly, or just rambled, I just hope I got my question across properly.

    Also, has anyone got an code showing how to mount flash2 as read/write as I can't find the arguments required, I assumed flash2 but it returned the nodev error, I also tried assigning it incase it wasn't already assigned, again no luck, so any pointers on this would be aprechiated.

    -Aura
    i havent done much about screen buffers, but this would be my guess:

    Code:
    1. Get the pointer.
    2. malloc(sizeof(*pointer)); // Dont know if this would work exactly //
    3. memcpy(from pointer to malloc'd memory);
    --------------------------------------------------------------------------------------

  3. #7353
    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

    haven't tested it but this should do it aswell
    u32 buffer[512x272] //buffer to store whole screenbuffer
    memcpy(buffer,0x04000000, 512*272) //copy framebuffer content to buffer
    //done
    robot mafia

  4. #7354
    Ænima
    Points: 6.447, Level: 52
    Level completed: 49%, Points required for next Level: 103
    Overall activity: 0%

    Registriert seit
    Sep 2007
    Beiträge
    587
    Points
    6.447
    Level
    52
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von tommydanger
    haven't tested it but this should do it aswell
    The screen is only 480*272. Any reason why you chose 512 instead of 480?
    [IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]

    Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.

  5. #7355
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Judas
    The screen is only 480*272. Any reason why you chose 512 instead of 480?
    I'm back :)

    Actually, you are both wrong, it should be 512*272*4...

    Code:
    #define FRAMEBUFFER_SIZE (PSP_LINE_SIZE*SCREEN_HEIGHT*4)
    I'm crashing at the moment using the codes posted above, I'm not sure if its the memory constraint or not, I'll work at it a little more, if it still crashes I'll post the code and see if anyone else can see what I'm doing wrong (if anything).

    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  6. #7356
    QJ Gamer Silver
    Points: 14.087, Level: 77
    Level completed: 10%, Points required for next Level: 363
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Germany
    Beiträge
    926
    Points
    14.087
    Level
    77
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Auraomega
    I'm back :)

    Actually, you are both wrong, it should be 512*272*4...

    Code:
    #define FRAMEBUFFER_SIZE (PSP_LINE_SIZE*SCREEN_HEIGHT*4)
    No. Tommydanger was right (apart from the memcpy's last parameter). He created an array of u32s, so the size was in fact 512*272*4. Anyway, it crashes, because the buffer is created on stack and the stack is not large enough for that. Either make the declaration static or use malloc.
    Also, you could get weird results if you're reading back the framebuffer while it is currently being rendered too. So you'd probably be best off mutexing the memcpy or disabling interrupts during the time and make sure it happens after the rendering of the screen has finished (by hooking sceDisplaySetFramebuf or sceGuSync).
    Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
    Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
    Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
    Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.

  7. #7357
    QJ Gamer Silver
    Points: 8.717, Level: 62
    Level completed: 89%, Points required for next Level: 33
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Ort
    Melbourne, Australia
    Beiträge
    1.773
    Points
    8.717
    Level
    62
    My Mood
    Amused
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von BigSanFrey
    Anyway i have a problem. My "game" is meant to show 4 little squares with a cross in it (this is the picture ). But number four does not show, it shows if i have the
    Code:
        int StarX4 = GetRandomNum(331, 416);
        int StarY4 = GetRandomNum(1, 272);
    set to
    Code:
        int StarX4 = GetRandomNum(3, 40)
        int StarY4 = GetRandomNum(1, 272);
    Or if i collect star number 2 :Argh:...

    Here is my code (in a spoiler)
    Spoiler for Code:
    Code:
    int main(void) {
        SetupCallbacks();
        initGraphics();
        SceCtrlData pad;
        int ok = 1;
        int x0 = 100;
        int y0 = 100;
        int x0Height = 10;
        int x0Width = 10;
    
    	// Load background
        Image* Background;
        Background = loadImage("./Images/Background.png");
    	// Load face
        Image* Face;
        Face = loadImage("./Images/face.png");
    	// Load square
        Image* Square1;
        Square1 = loadImage("./Images/1.png");
    	// Load square
        Image* Square2;
        Square2 = loadImage("./Images/2.png");
    	// Load square
        Image* Square3;
        Square3 = loadImage("./Images/3.png");
    	// Load square
        Image* Square4;
        Square4 = loadImage("./Images/4.png");
    	// Load wall
        Image* Wall;
        Wall = loadImage("./Images/spr_wall.png");
    
        int StarX1 = GetRandomNum(1, 110);
        int StarY1 = GetRandomNum(1, 272);
    
        int StarX2 = GetRandomNum(111, 220);
        int StarY2 = GetRandomNum(1, 272);
    
        int StarX3 = GetRandomNum(221, 330);
        int StarY3 = GetRandomNum(1, 272);
    
        int StarX4 = GetRandomNum(331, 416);
        int StarY4 = GetRandomNum(1, 272);
    
    
        while(1) {
    
    	sceCtrlReadBufferPositive(&pad, 1);
    
    	blitAlphaImageToScreen(0, 0 , 480, 272, Background, 0, 0);
    
    
          if ((x0 >= (StarX1 - 5) && x0 <= (StarX1 + 5)) && ((y0 >= (StarY1 - 5) && y0 <= (StarY1 + 5))) ) {
    	StarX1 = GetRandomNum(1, 110);
    	StarY1 = GetRandomNum(1, 272);
          }
          else if ((x0 >= (StarX2 - 5) && x0 <= (StarX2 + 5)) && ((y0 >= (StarY2 - 5) && y0 <= (StarY2 + 5))) ) {
    	StarX2 = GetRandomNum(111, 220);
    	StarY2 = GetRandomNum(1, 272);
          }
          else if ((x0 >= (StarX3 - 5) && x0 <= (StarX3 + 5)) && ((y0 >= (StarY3 - 5) && y0 <= (StarY3 + 5))) ) {
    	StarX3 = GetRandomNum(221, 330);
    	StarY3 = GetRandomNum(1, 272);
          }
          else if ((x0 >= (StarX4 - 5) && x0 <= (StarX4 + 5)) && ((y0 >= (StarY4 - 5) && y0 <= (StarY4 + 5))) ) {
    	StarX4 = GetRandomNum(331, 416);
    	StarY4 = GetRandomNum(1, 272);
          }
    
    	// reset the square
          if(pad.Buttons & PSP_CTRL_SELECT) {
    	x0 = 100;
    	y0 = 100;
          }
    
          *Just some up down movements here*
          *Just some up down movements here*
          *Just some up down movements here*
    
    	// If the square is at the end of the screen (left side) set it to 0
          if(x0 < 0) {
    	    x0 = 0;
          }
    	// Otherwise if the square is at the end of the screen (right side) set it to 430 (screen width minus the square width)
          else if(x0 > ((480 - 64) - x0Width)) {
    	    x0 = ((480 - 64) - x0Width);
          }
    
    	// If the square is at the top of the screen set it to 0
          if(y0 < 0) {
    	    y0 = 0;
          }
    	// Otherwise if the square is at the bottom of the screen set it to 222 (screen height minus the square height)
          else if(y0 > (272 - x0Height)) {
    	    y0 = (272 - x0Height);
          }
    	// draw our little square and star!
          if(ok >= 1){
    	blitAlphaImageToScreen(0, 0, 10, 10, Face, x0, y0);
    	blitAlphaImageToScreen(0, 0, 10, 10, Square1, StarX1, StarY1);
    	blitAlphaImageToScreen(0, 0, 10, 10, Square2, StarX2, StarY2);
    	blitAlphaImageToScreen(0, 0, 10, 10, Square3, StarX3, StarY3);
    	blitAlphaImageToScreen(0, 0, 10, 10, Square4, StarX4, StarY4);
    
    	blitAlphaImageToScreen(0, 0, 64, 480, Wall, 416, 0);
    
          }
    
    	 sceDisplayWaitVblankStart();
    	 flipScreen();
        }	
    
        sceKernelSleepThread();
        return 0;
    }
    Anyone? It has been five days since I originally posted..
    WHA!?

  8. #7358
    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

    What is your code in GetRandomNum? Chances are that the function is not returning correct values.

  9. #7359
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Raphael
    No. Tommydanger was right (apart from the memcpy's last parameter). He created an array of u32s, so the size was in fact 512*272*4. Anyway, it crashes, because the buffer is created on stack and the stack is not large enough for that. Either make the declaration static or use malloc.
    Also, you could get weird results if you're reading back the framebuffer while it is currently being rendered too. So you'd probably be best off mutexing the memcpy or disabling interrupts during the time and make sure it happens after the rendering of the screen has finished (by hooking sceDisplaySetFramebuf or sceGuSync).
    Argh, brain isn't functioning today. It was the stack, once I allocated more to the thread it stopped crashing, but instead it appears to be reverting to a mix of old images blitted to the screen, I think I've done something wrong with assigning the buffer to the image->data.

    Code:
    u32 buffer = (void*)malloc(512*272*4);
        
        Image* screen;
        screen = createImage(480, 272);
    
        while(1)
        {
             sceCtrlPeekBufferPositive(&pad, 1);
             if(pad.Buttons & PSP_CTRL_SELECT)
             {
                memcpy(buffer, 0x04000000, 512*272*4);
                screen->data = buffer;
    When I then blit screen to the screen it gives me a mix of whats already there, the "PSPLink Bootstrap TyRaNiD (c) 2k7 Version v3.0" but instead of it being white it gives it with the colours of the picture that was on screen the previous time.

    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  10. #7360
    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

    Zitat Zitat von Raphael
    Also, you could get weird results if you're reading back the framebuffer while it is currently being rendered too. So you'd probably be best off mutexing the memcpy or disabling interrupts during the time and make sure it happens after the rendering of the screen has finished (by hooking sceDisplaySetFramebuf or sceGuSync).
    Quoted for emphasis.

    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

  11. #7361
    QJ Gamer Silver
    Points: 14.087, Level: 77
    Level completed: 10%, Points required for next Level: 363
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Germany
    Beiträge
    926
    Points
    14.087
    Level
    77
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Auraomega
    "PSPLink Bootstrap TyRaNiD (c) 2k7 Version v3.0" but instead of it being white it gives it with the colours of the picture that was on screen the previous time.

    -Aura
    That sounds as if you just draw the image with alpha transparency - however the framebuffers alpha channel is not useable, so you need to disable blending. If that's not the case - refer to my previous posts hint (which IWN quoted).
    Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
    Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
    Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
    Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.

  12. #7362
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Insert_Witty_Name
    Quoted for emphasis.
    Yeah I made sure nothing was writing the to buffer while I was doing so (I suspended all the threads doing this).

    Thank you Raphael, for some odd reason I was trying to use alpha, after reviewing the code I have disabled this and it now works fine

    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  13. #7363
    QJ Gamer Blue
    Points: 8.686, Level: 62
    Level completed: 79%, Points required for next Level: 64
    Overall activity: 45,0%

    Registriert seit
    Jan 2006
    Ort
    CO
    Beiträge
    150
    Points
    8.686
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard psp-config help

    Ok so I was installing cygwin and then pspdev I made the changes I needed to cygwin.bat ie.

    set path=%path%;C:/cygwin/usr/local/pspdev/bin
    set PSPSDK=C:/cygwin/usr/local/pspdev

    But what I did by accident "so stupid" I typed

    set path=%/path%;C:/.......
    That dang forward slash some how got saved. So when I compile I get an error that says.
    /c/cygwin/usr/local/pspdev/psp/sdk/lib/build.mak: No such file or directory.
    I know theres a fix, I found it a long long time ago. All day I've been searching with no results this time. Yes I have done this before :Argh:
    I will definitely write it down this time around. If anyone knows the syntax to fix this I would appreciate it. Thats all I can remember about fixing it was typeing something in the command prompt. And just to let you know I have reinstalled cygwin, made both PATH and PSPSDK Environment Variables.

    Plus how can you get a clean uninstall of cygwin? That might just be my best bet since I can't find my answer. Hope I made sence I'm a little angry with myself at the moment.

    ::Edit::
    Found out about the cygwin uninstall all through there sites FAQ... duh! Talk about an off day.
    ...gezz All I had to do is type this into the command prompt.
    set PATH=c:/cygwin/usr/local/pspdev/bin;%PATH%
    set PSPDEV=c:/cygwin/usr/local/pspdev
    Dont know why it wouldn't fix its self through Environmental Varibles Settings..??
    Geändert von HYde (01-02-2008 um 10:31 PM Uhr)

  14. #7364
    QJ Gamer Silver
    Points: 8.717, Level: 62
    Level completed: 89%, Points required for next Level: 33
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Ort
    Melbourne, Australia
    Beiträge
    1.773
    Points
    8.717
    Level
    62
    My Mood
    Amused
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von yaustar
    What is your code in GetRandomNum? Chances are that the function is not returning correct values.
    Code:
    int GetRandomNum(int lo, int hi)
    {
     SceKernelUtilsMt19937Context ctx;
     sceKernelUtilsMt19937Init(&ctx, time(NULL)); //SEED TO TIME
     u32 rand_val = sceKernelUtilsMt19937UInt(&ctx);
     rand_val = lo + rand_val % hi;
     return (int)rand_val;
    }
    is my GetRandomNum function
    WHA!?

  15. #7365
    QJ Gamer Silver
    Points: 14.087, Level: 77
    Level completed: 10%, Points required for next Level: 363
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Germany
    Beiträge
    926
    Points
    14.087
    Level
    77
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von BigSanFrey
    Code:
    int GetRandomNum(int lo, int hi)
    {
     SceKernelUtilsMt19937Context ctx;
     sceKernelUtilsMt19937Init(&ctx, time(NULL)); //SEED TO TIME
     u32 rand_val = sceKernelUtilsMt19937UInt(&ctx);
     rand_val = lo + rand_val % hi;
     return (int)rand_val;
    }
    is my GetRandomNum function
    That will give you a random number in range [lo, lo+hi-1].

    What you probably want is return (lo + (rand_val % (hi - lo + 1)));
    Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
    Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
    Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
    Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.

  16. #7366
    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

    Zitat Zitat von BigSanFrey
    Code:
    int GetRandomNum(int lo, int hi)
    {
     SceKernelUtilsMt19937Context ctx;
     sceKernelUtilsMt19937Init(&ctx, time(NULL)); //SEED TO TIME
     u32 rand_val = sceKernelUtilsMt19937UInt(&ctx);
     rand_val = lo + rand_val % hi;
     return (int)rand_val;
    }
    is my GetRandomNum function
    Thought as much, I fixed this 5 days ago:
    http://forums.qj.net/f-psp-developme...4/page732.html
    C/C++ Programming Help Thread

  17. #7367
    QJ Gamer Silver
    Points: 8.717, Level: 62
    Level completed: 89%, Points required for next Level: 33
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Ort
    Melbourne, Australia
    Beiträge
    1.773
    Points
    8.717
    Level
    62
    My Mood
    Amused
    Downloads
    0
    Uploads
    0

    Standard

    sorry!!
    I searched for a random number generator in the earlier parts of this thread and it gave me pretty much that exact code.. weird (and stupid of me!)
    WHA!?

  18. #7368
    QJ Gamer Silver
    Points: 10.921, Level: 69
    Level completed: 18%, Points required for next Level: 329
    Overall activity: 0%

    Registriert seit
    May 2006
    Ort
    Behind you.
    Beiträge
    1.814
    Points
    10.921
    Level
    69
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von yaustar
    Can you post the full error and the block of code that produces it?

    If you want to be even more clever with the GetRandomNum (and because it is in C), you can try this:
    Code:
    SceKernelUtilsMt19937Context InitialiseMtContext()
    {
        SceKernelUtilsMt19937Context ctx;
        sceKernelUtilsMt19937Init(&ctx, time(NULL));
    
        return ctx;
    }
    
    int GetRandomNum(int lo, int hi)
    {
        static SceKernelUtilsMt19937Context ctx = InitialiseMtContext();
    
        int rand_val = (int)sceKernelUtilsMt19937UInt(&ctx);
        rand_val = lo + ( rand_val % (hi-lo) );
        return rand_val;
    }
    
    int main()
    {
        // get random number
        GetRandomNum( 0, 100 ); // ctx gets initialised here the first time the function is called
        GetRandomNum( 0, 100 ); // but not here
        GetRandomNum( 0, 100 ); // nor here
    
        return 0;
    }
    Please note, that if I was using C++, I wouldn't have written this code like this. I would use a class.
    Ok, i tried that, but i get the error for the static line: "initializer element is not constant".
    Calypso - Enjoy the excellent 2D space shooter:
    http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195

    "Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)

  19. #7369
    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

  20. #7370
    QJ Gamer Silver
    Points: 10.921, Level: 69
    Level completed: 18%, Points required for next Level: 329
    Overall activity: 0%

    Registriert seit
    May 2006
    Ort
    Behind you.
    Beiträge
    1.814
    Points
    10.921
    Level
    69
    Downloads
    0
    Uploads
    0

    Standard

    Will this work then:

    Code:
    int GetRandomNum(int lo, int hi)
    {
        static SceKernelUtilsMt19937Context ctx;
        sceKernelUtilsMt19937Init(&ctx, time(NULL));
    
        int rand_val = (int)sceKernelUtilsMt19937UInt(&ctx);
        rand_val = lo + ( rand_val % (hi-lo) );
        return rand_val;
    }
    Edit: Never mind, i was being an idiot. That doesn't work. I found it out. :)
    Calypso - Enjoy the excellent 2D space shooter:
    http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195

    "Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)

  21. #7371
    It's good to be free...
    Points: 10.420, Level: 67
    Level completed: 93%, Points required for next Level: 30
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Beiträge
    2.440
    Points
    10.420
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Code:
    SceKernelUtilsMt19937Context InitialiseMtContext()
    {
        SceKernelUtilsMt19937Context ctx;
        sceKernelUtilsMt19937Init(&ctx, time(NULL));
    
        return ctx;
    }
    
    int GetRandomNum(int lo, int hi)
    {
        static int initialized = 0;
        static SceKernelUtilsMt19937Context ctx;
        if(!initialized) {
            ctx = InitialiseMtContext();
            initialized = 1;
        }
    
        int rand_val = (int)sceKernelUtilsMt19937UInt(&ctx);
        rand_val = lo + ( rand_val % (hi-lo) );
        return rand_val;
    }
    
    int main()
    {
        // get random number
        GetRandomNum( 0, 100 ); // ctx gets initialised here the first time the function is called
        GetRandomNum( 0, 100 ); // but not here
        GetRandomNum( 0, 100 ); // nor here
    
        return 0;
    }
    Here's a hack-y way to do it.
    pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ

  22. #7372
    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

    Zitat Zitat von TMNT
    Ok, i tried that, but i get the error for the static line: "initializer element is not constant".
    It is something to do with the array in the struct ctx so copying by value is invalid.

    Code:
    int GetRandomNum(int lo, int hi)
    {
        static int initialized = 0;
        static SceKernelUtilsMt19937Context ctx;
        if(!initialized) 
        {
             sceKernelUtilsMt19937Init(&ctx, time(NULL));
            initialized = 1;
        }
    
        int rand_val = (int)sceKernelUtilsMt19937UInt(&ctx);
        rand_val = lo + ( rand_val % (hi-lo) );
        return rand_val;
    }
    
    int main()
    {
        // get random number
        GetRandomNum( 0, 100 ); // ctx gets initialised here the first time the function is called
        GetRandomNum( 0, 100 ); // but not here
        GetRandomNum( 0, 100 ); // nor here
    
        return 0;
    }

  23. #7373
    Developer
    Points: 3.206, Level: 35
    Level completed: 4%, Points required for next Level: 144
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Beiträge
    74
    Points
    3.206
    Level
    35
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von TMNT
    Ok, i tried that, but i get the error for the static line: "initializer element is not constant".
    uh...you're passing the whole struct back? You do realise that SceMt19937Context is 625 Bytes in size.

    Also, while Mersenne Twister is good and one of the best prng's there are. It's a lot quicker and more convenient to use the psp's hardware prng. Either via the VFPU's rand registers, or the KIRK crypto engine.

    Fortunately, SCE provides a nifty api to access the crypt hw.

    int sceDdrdbPrngen(u8 *rand);

    You dont have to seed it (KIRK is initialised automatically on boot) and is a pure hw based prng so will be a lot faster (although the exact algo used is unknown - naturally, considering its from the security engine).

    It normally returns 20 bytes, but if you only need 0-100 just take a single byte and scale it.
    PSP PRX LibDoc's Lives On!
    http://silverspring.lan.st/

    My new home:
    http://my.malloc.us/silverspring/

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

    Zitat Zitat von SilverSpring
    uh...you're passing the whole struct back? You do realise that SceMt19937Context is 625 Bytes in size.
    I was, (it is my original re-done code), since it only happens once throughout the life of the program, it isn't that big of a deal.

  25. #7375
    QJ Gamer Silver
    Points: 10.921, Level: 69
    Level completed: 18%, Points required for next Level: 329
    Overall activity: 0%

    Registriert seit
    May 2006
    Ort
    Behind you.
    Beiträge
    1.814
    Points
    10.921
    Level
    69
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von yaustar
    It is something to do with the array in the struct ctx so copying by value is invalid.

    Code:
    int GetRandomNum(int lo, int hi)
    {
        static int initialized = 0;
        static SceKernelUtilsMt19937Context ctx;
        if(!initialized) 
        {
             sceKernelUtilsMt19937Init(&ctx, time(NULL));
            initialized = 1;
        }
    
        int rand_val = (int)sceKernelUtilsMt19937UInt(&ctx);
        rand_val = lo + ( rand_val % (hi-lo) );
        return rand_val;
    }
    
    
    int main()
    {
        // get random number
        GetRandomNum( 0, 100 ); // ctx gets initialised here the first time the function is called
        GetRandomNum( 0, 100 ); // but not here
        GetRandomNum( 0, 100 ); // nor here
    
        return 0;
    }

    That's giving me random number outside my max and min values.
    Calypso - Enjoy the excellent 2D space shooter:
    http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195

    "Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)

  26. #7376
    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

    Zitat Zitat von TMNT
    That's giving me random number outside my max and min values.
    That is impossible. What numbers are you passing in and what are you getting out? Are you sure you are using the right random values ? E.g. Passing in 0 to 480 but setting it to the Y position of an object instead of X?

    Write a test program that is just the random number function being called a 1000 times that spits out an error message if it goes beyond the range of the min and max values.

  27. #7377
    QJ Gamer Silver
    Points: 10.921, Level: 69
    Level completed: 18%, Points required for next Level: 329
    Overall activity: 0%

    Registriert seit
    May 2006
    Ort
    Behind you.
    Beiträge
    1.814
    Points
    10.921
    Level
    69
    Downloads
    0
    Uploads
    0

    Standard

    I just finished doing that. I even checked the values and everything. Even then, some of the values are going outside the min and max!

    This is the wierdest problem i have ever had. However, this works perfectly:

    Code:
    int GetRandomNum(int lo, int hi)
    {
        SceKernelUtilsMt19937Context ctx;
        sceKernelUtilsMt19937Init(&ctx, time(NULL));
    
        int rand_val = (int)sceKernelUtilsMt19937UInt(&ctx);
        rand_val = lo + ( rand_val % (hi-lo) );
        return rand_val;
    }
    I'm just going to stick with this...
    My main question is, how do i make a tile system?
    Calypso - Enjoy the excellent 2D space shooter:
    http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195

    "Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)

  28. #7378
    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

    Look at all the examples out their....That should give you an idea.
    Or you can think about what a tile system does and make one...

  29. #7379
    QJ Gamer Silver
    Points: 10.921, Level: 69
    Level completed: 18%, Points required for next Level: 329
    Overall activity: 0%

    Registriert seit
    May 2006
    Ort
    Behind you.
    Beiträge
    1.814
    Points
    10.921
    Level
    69
    Downloads
    0
    Uploads
    0

    Standard

    Do you have a link to the examples?

    Side note:

    OMFG!!!! I got my mp3 decoding code to work!!!!!!!!! Yes!!! Now i don't have to worry about all that lagging!!!
    Calypso - Enjoy the excellent 2D space shooter:
    http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195

    "Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)

  30. #7380
    Ænima
    Points: 6.447, Level: 52
    Level completed: 49%, Points required for next Level: 103
    Overall activity: 0%

    Registriert seit
    Sep 2007
    Beiträge
    587
    Points
    6.447
    Level
    52
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von TMNT
    Do you have a link to the examples?

    Side note:

    OMFG!!!! I got my mp3 decoding code to work!!!!!!!!! Yes!!! Now i don't have to worry about all that lagging!!!
    A tile engine is very easy to make. Search for a Lua version, and get the basic idea. From there, it'll be easy to port to C.
    [IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]

    Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.


 

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

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