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; Zitat von Raphael That's plain utter bull. malloc shouldn't be used inside inner loops of realtime-apps, yes, but even there ...
-
10-15-2006, 12:02 PM #1321QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Ok. Thank you. My format now will be
Zitat von Raphael
but without the linebreaks. This way artist and album names can be of any length and nothing will be cut. I think this is the most professional solutionCode:00517 // First line, number of artists (5 bytes) 016 // length of the first artist (3 bytes) A perfect circle // Name of the artist (#1) 3 // Albumcount 016 // length of the first album Emotive // Name of the album (#1) 016 // length of the second album Mer de noms // Name of the album (#2) 016 // length of the third album The thiteenth step // Name of the album (#3) 016 // length of the second artist Aphex Twin // Name of the artist (#2) 2 // albumcount 016 // length of the first album Come to daddy // Name of the album (#1) 016 // length of the second album Selected ambient works // Name of the album (#2) [...] // Name of the artist (#3)
-
10-15-2006, 12:29 PM #1322Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
using "graphics.h" in PSPGU
hi guys. i wanted to blit a png image of a crosshair in the center of my screen, but when i do it using PSPGU, the image doesnt show. is it posible to use graphics.h with pspgu? (also, the same thing happens when i use "printTextScreen()")
--------------------------------------------------------------------------------------
-
10-15-2006, 01:10 PM #1323sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
so ur saying text and images aren't rendering? Are you switching them from offscreen buffer to onscreen buffer?
-
10-15-2006, 02:21 PM #1324words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Grimfate - graphics.h/c IS GU. IF it's not showing up, either you arent translating into view of it, or not flipping the draw/display buffers.

...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
-
10-15-2006, 02:26 PM #1325AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
You also need to call initGraphics()...
-
10-15-2006, 04:25 PM #1326Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
all of you were right. i didnt call initGraphics or flipScreen. BUT, it still wont work. my current main function:
its compiles fine, but when i boot it, it just shows a blank screen. (its not crashing cause i can still exit by pressing "home".)Code:int main(void) { scePowerSetClockFrequency(333, 333, 166); pspDebugScreenInit(); SetupCallbacks(); initGraphics(); dList = memalign( 16, 640 ); fbp0 = 0; InitGU(); SetupProjection(); // SET CAMERA ONE POSITION // cameraOne.SetPos(model_x, model_y + 1, model_z, 0.0f, 1.0f, 0.5f, 0.0f, 1.0f, 0.0f); crossHair = loadImage("crossHair.png"); while (1) { DrawScene(); blitAlphaImageToScreen(0 ,0 ,32 , 32, crossHair, 224, 120); sceDisplayWaitVblankStart(); fbp0 = sceGuSwapBuffers(); flipScreen(); } sceGuTerm(); free( dList ); free( fbp0 ); return 0; }
now whats wrong?--------------------------------------------------------------------------------------
-
10-15-2006, 05:10 PM #1327words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Grimfate - You cant initlaize the GU twice. Your trying to take the easy way out by taking 2 differ GU setup functions thus casuing unknown errors (?). Since your making that FPS, i highly suggest you get off graphics.h/c (unless you want to do vectoring and whatnot with it somehow :X) and stay with raw GU. First, load and texturize an Ortho view crosshair (texturize a quad movable via analog stick).

...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
-
10-16-2006, 04:56 AM #1328QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Hi,
what's the quickest way to read bytes/chars x-y from a char-array? Is there a better way than using a for-loop?
-
10-16-2006, 05:40 AM #1329QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Whoever brought up that code for the command list setup should get slaughtered IMO. 640 bytes is in no way enough space to store commands as soon as you do more than drawing 10 images. It's nearly as annoying as the buffer = "myfile.png"; loadImage( buffer ); crap, only that this didn't cause any problems, it just was ugly.dList = memalign( 16, 640 );
Either your image isn't loaded correctly (wrong path/filename/anything) or anything GU specific isn't setup correctly (read further below).its compiles fine, but when i boot it, it just shows a blank screen.
Remove this line. And never do that again. You cannot free VRAM memory with the free function. Also you didn't allocate fbp0 with malloc in the first place anyway, so this is double-wrong.free( fbp0 );
Wrong. You can initialize the GU as often as you want and it will not cause any unknown errors, the only thing that happens is that all your states from the previous setup get reset to the defaults each time. Therefore the initGU() call will make the initGraphics() obsolete, which in turn might be the cause for the image not showing up (because some important setup is missing then, probably something like sceGuEnable(GU_TEXTURE_2D ) or alike).Grimfate - You cant initlaize the GU twice. Your trying to take the easy way out by taking 2 differ GU setup functions thus casuing unknown errors (?).
No, there's no quicker way. Any time you read an amount of data or search for an unknown position you ALWAYS need a loop. The question if there's a BETTER way on the other side depends on the needs, but most likely there's no "better" way in this case.what's the quickest way to read bytes/chars x-y from a char-array? Is there a better way than using a for-loop?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.
-
10-16-2006, 05:53 AM #1330QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Hm, wouldn't memcpy probably be faster? I mean I know the position (the offset and the length I want to read). If there's the a way to create a pointer that points to the point (omg my english *dies*), I mean a pointer that points to the offset where I want to read the string from, I could use memcpy to copy an excerpt from the string.
Like (reading array[5]-array[10]):
char * pArray = &array+5; // (pseudo-code)
memcpy(stringExcerpt, pArray, 5);
?
-
10-16-2006, 06:06 AM #1331QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Yes, that's true, I somewhat misunderstood your intention with "read x-y chars". If you want to copy some strings out of a longer one, that's the best (as in cleanest/best readable) way to go yes (if its faster depends on the length of the string to copy, because the overhead of the function call is not little and on the other side, memcpy also only does a loop [but optimized] - note though that all that is not really time-critical code, so it doesn't matter which solution you take, therefore the memcpy is still preferable).
Zitat von Lukeson
Well, at least the idea is right, the syntax not quite ;)
That's the same in one single line. Copys 5 bytes starting from position 5.Code:memcpy(stringExcerpt, &array[5], 5);
PS: You get my personal award for craziest funny sentence of the month
PPS: If you once really get into problems explaining yourself in english, you can always contact me in german too ;)If there's the a way to create a pointer that points to the point (omg my english *dies*)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.
-
10-16-2006, 07:06 AM #1332QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Thanks again, Raphael!
Now can somebody pls explain that errormessage to me?
Line 84:pspwamp_commands.c:84: error: 'for' loop initial declaration used outside C99 mode
Code:for(int i=1; i<=1; i++)
-
10-16-2006, 07:11 AM #1333AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
You need to set the std to c99. Simply open up your makefile and add -std=c99 to the CFLAGS.
You could also change it to
Code:int i; for(i=1; i<=1; i++)
-
10-16-2006, 07:16 AM #1334QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Thanks!
-
10-16-2006, 07:36 AM #1335
thats wierd i got that error to and i just made it a c++ file. and it was gone.
Zitat von Lukeson
-
10-16-2006, 07:58 AM #1336QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
C++ includes the C99 standard, that'swhy with C++ that won't occur.
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.
-
10-16-2006, 08:18 AM #1337QJ Gamer Platinum
- Registriert seit
- Dec 2005
- Ort
- h0000000rj
- Beiträge
- 12.867
- Points
- 57.528
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Code:for( leerlingen = 0; leerlingen < 21; ++leerlingen ) { cout << "geef de score van leerling " << leerlingen; cin >> punten[leerlingen-1]; cout << endl; }No... it increments before entering the loop, since the ++ is in the prefix position.
Zitat von head_54us
[I fail @ life]
-
10-16-2006, 08:43 AM #1338QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Over at php-resource.de (german) they say, you can simply send() a struct, recieve it, and, on the client, make it a struct again via a simple typeconversion. Can somebody confirm that?
-
10-16-2006, 08:54 AM #1339QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
No, the increment happens at the end of loop whether it is i++, ++i, i+=1 or i = i + 1. Seriously, try it.
Zitat von FreePlay
++i increments before the expression of i is evaluated
i++ increments after the expression of i is evaluated
Code:for( int i = 0; i < 10; ++i ) | | |--> Executed at the end of the loop | |--> Executed at the beginning of the loop |--> Is initialised on entry to the for loop blockGeändert von yaustar (10-16-2006 um 09:26 AM Uhr)
-
10-16-2006, 09:05 AM #1340QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Yes that's possible. It's as it stands there, data is just data, and a type or struct is just an interpretation of that data which can be exchanged (through typecasts).
Zitat von Lukeson
That's the typecast (from char* to struct libnet_ip_hdr*)./*packet von irgendwo her gelesen*/
/* packet ist vom typ char* */
struct libnet_ip_hdr *ip_h = (struct libnet_ip_hdr*)packet;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.
-
10-16-2006, 10:18 AM #1341QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
kewl sh*t!
-= Double Post =-
How do I allocate memory for multidimensional arrays? I have the following problem:
How do I create that album-array?Code:typedef struct { char * name; char * albums; } artist_entry; artist_entry artist_list[517]; for(i=0;i<=517;i++) { // find out artist name and length artist_list[i].name = (char*)malloc(artist_name_lenght+1); strcpy(artist_list[i].name, artist_name); artist_list[i].name[artist_name_lenght]='\0'; // find out number of albums, and album-names // make albums an array for X (3 for example) albums for(j=0;j<=X;j++) { artist_list[i].albums[j] = (char*)malloc(album_name_lenght+1); [...] } }Geändert von Lukeson (10-16-2006 um 10:18 AM Uhr) Grund: Automerged Doublepost
-
10-16-2006, 10:28 AM #1342QJ Gamer Platinum
- Registriert seit
- Dec 2005
- Ort
- h0000000rj
- Beiträge
- 12.867
- Points
- 57.528
- Level
- 100
- Downloads
- 0
- Uploads
- 0
That doesn't make any sense... In my experience, it executes the third argument of 'for' at the beginning of each iteration. I mean, you don't have to just increment a variable there... you can put any kind of code there you want.
Zitat von head_54us
[I fail @ life]
-
10-16-2006, 10:49 AM #1343QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Make that albums a double pointer, ie char** albums. Then before the inner for loop, allocate the albums array like that: artist_list[i].albums = malloc( X*sizeof(char*) );
Zitat von Lukeson
The rest is good already. Just be sure to free that array in the reverse order, ie first loop through albums[j] and free each and after that, free the albums.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.
-
10-16-2006, 10:49 AM #1344QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
crosspost
-
10-16-2006, 10:57 AM #1345QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
But headus is right there. The last part in the for loop is executed at the end, therefore it doesn't matter if the increment is prefixed or postfixed. You can easily try that by doing
Zitat von FreePlay
and it will print 0,1,2,Code:for (i=0;i<3;++i) printf("%i,", i);
then you can also try that to get absolutely sure that the stuff in the last part is executed AFTER the loop, by inserting another printf("++"); before the ++i. The output will now be 0,++1,++2,++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.
-
10-16-2006, 10:58 AM #1346QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Thanks for the quick answer, just one las question; How do I set the String-null-terminator? Lke this?
Code:for(j=0;j<=X;j++) { artist_list[i].albums[j] = (char*)malloc(album_name_length+1); strcpy(artist_list[i].albums[j], album_name); artist_list[i].albums[j][album_name_length]='\0'; }
-
10-16-2006, 11:04 AM #1347QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Yes, exactly.
Zitat von Lukeson
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.
-
10-16-2006, 11:26 AM #1348
How do i clean the screen? Or make it go to sleep after displaying some txt?
-
10-16-2006, 11:33 AM #1349QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
1.) clearScreen(RGB(0, 0, 0));
2.) sceKernelSleepThread();
-
10-16-2006, 11:35 AM #1350
Thank you :)
Zitat von Lukeson


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum