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; Gah.. I hate structs (I am a C++ man) Either use Code: typedef { char * name; int num_albums; char ...
-
10-17-2006, 01:17 PM #1381QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Gah.. I hate structs (I am a C++ man)
Either use
orCode:typedef { char * name; int num_albums; char ** albums; } artist_entry; int get_artists_from_server(int socket, struct artist_entry * artist_list) { [...] artist_list = (artist_entry *)realloc(artist_list, atoi(num_artists)*sizeof(artist_entry)); [...] int i,j; for(i=0; i<atoi(num_artists); i++) { [...] artist_list[i].name = (char*)malloc(artist_name_lenght+1); //l.104 [...] } }
Code:typedef struct artist_entry_struct{ char * name; int num_albums; char ** albums; } artist_entry; int get_artists_from_server(int socket, artist_entry * artist_list) { [...] artist_list = (artist_entry *)realloc(artist_list, atoi(num_artists)*sizeof(artist_entry)); [...] int i,j; for(i=0; i<atoi(num_artists); i++) { [...] artist_list[i].name = (char*)malloc(artist_name_lenght+1); //l.104 [...] } }
-
10-17-2006, 01:37 PM #1382QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
You are typedef'ing your struct therefore you don't need the "struct" specifier on the parameters. Read up on typedefs again. You have two possibilities:
Change all "struct artist_entry" parameters to "artist_entry" only, or change your declaration into "struct artist_entry { ..... };"
EDIT: Heh, basically the same is written on the site from headus' link earlier I just noticed. Read that page, seriously.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-18-2006, 04:58 AM #1383QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Works now, thank you!
Same here, but my fist tries using C++ on the PSP failed miserably!Gah.. I hate structs (I am a C++ man)
-= Double Post =-
PS: Does anyone have an explanation for my first problem?
http://forums.qj.net/f-psp-developme...e138.html#1376Geändert von Lukeson (10-18-2006 um 04:58 AM Uhr) Grund: Automerged Doublepost
-
10-18-2006, 05:41 AM #1384QJ Gamer Green
- Registriert seit
- Aug 2006
- Ort
- Swansea, Wales Firmwire: 3.03OE-C
- Beiträge
- 985
- Points
- 10.114
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Ive got a problem with the TIFF USB, when I run the application it wont activate the USB Port for it. Any help?
[RIGHT][FONT=Comic Sans MS][SIZE=3][COLOR=darkorange][B]Stand your ground and fight.[/B][/COLOR][/SIZE][/FONT][/RIGHT]
[RIGHT][URL="http://forums.qj.net/showthread.php?t=4394"][SIZE=1][COLOR=black]Piracy Policy[/COLOR][/SIZE][/URL][SIZE=1][COLOR=black] | [/COLOR][/SIZE][URL="http://forums.qj.net/showthread.php?t=2189&highlight=Ultimate"][SIZE=1][COLOR=black]Ultimate Guide[/COLOR][/SIZE][/URL][SIZE=1][COLOR=black] | [/COLOR][/SIZE][URL="http://forums.qj.net/showthread.php?p=13162#post13162"][SIZE=1][COLOR=black]Posting Guidelines[/COLOR][/SIZE][/URL][/RIGHT]
[RIGHT][SIZE=1][COLOR=black]First person to downgrade PSP v2.80[/COLOR][/SIZE][/RIGHT]
-
10-18-2006, 07:00 AM #1385QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
This is so wierd, when I use for(i=1; i<515; i++) he prints all 514 artists and their albums, but after the function has finished (I print 'Closing connection') right after it, he prints another 3 albums! That's impossible!
Zitat von Lukeson
And if I say for(i=1; i<=514; i++) he only does 26 albums! This is crazy...
-
10-18-2006, 10:34 AM #1386QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Is your program multithreaded?
-
10-18-2006, 11:04 AM #1387QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
I use threads, but I only start 1 thread...
-
10-18-2006, 11:32 AM #1388QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
If you mean, you have the main thread and start a new thread, your program is multithreaded and explains why you see the status of the socket closing before the function finishes.
One thread is dealing with printing the artists/albums (and is given it faster then it can print it), the other thread closes the socket.
-
10-18-2006, 11:37 AM #1389AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
His problem was that it printed stuff that really shouldn't be there (the three albums), I believe atleast.
Zitat von head_54us
-
10-18-2006, 11:43 AM #1390QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Hmm.. hell, if all else fails, debug the damn thing. Step through the code and check the data as it is recieved.
-
10-18-2006, 07:47 PM #1391QJ Gamer Blue
- Registriert seit
- Aug 2006
- Beiträge
- 145
- Points
- 4.580
- Level
- 43
- Downloads
- 0
- Uploads
- 0
My background switcher wont work
I have three backgrounds in an Images/Backgrounds/ directory:
Back1.png
Back2.png
Back3.png
I tried using an array but that didn't work, and heres how I load it:
My currentBack variable:Code:Image* Background = loadImage("./Images/Backgrounds/Back1.png");
And heres where supposadly when I pres the Right Trigger its suppose to switch:Code:int currentBack = 1;
It just stays the same, and it wont ever switch!! Ive tried almost everything here! And heres where I try to blit my Background variable to the screen:Code:if((pad.Buttons & PSP_CTRL_RTRIGGER) && (currentBack == 1)) { Background = loadImage("./Images/Backgrounds/Back2.png"); currentBack = currentBack+1; } if((pad.Buttons & PSP_CTRL_RTRIGGER) && (currentBack == 2)) { Background = loadImage("./Images/Backgrounds/Back3.png"); currentBack = currentBack+1; } if((pad.Buttons & PSP_CTRL_RTRIGGER) && (currentBack == 3)) { Background = loadImage("./Images/Backgrounds/Back1.png"); currentBack = 1; }
Help!Code:blitAlphaImageToScreen(0, 0, 480, 272, Background, 0, 0);
-
10-18-2006, 08:38 PM #1392AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
You sure you called flipScreen(); right after the blitAlphaImageToScreen(.. .)?
EDIT: Oh, I thought it always stayed black...
-
10-18-2006, 08:39 PM #1393Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
Create an array of 3 Images and load them all up beforehand.
In your button press check just change the currentBack variable.
In your blitting function just use the position in the array ie.
You also should initialise the currentBack variable to 0, as arrays are indexed from 0 to limit-1.Code:blitAlphaImageToScreen(0, 0, 480, 272, Background[currentBack], 0, 0);

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
-
10-18-2006, 08:43 PM #1394words 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
Seems more logical to load all 3 images, and switch the background according to the variable... If var = 1, have background 1blit, if var=2, have background 2 blit, etc...

...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-19-2006, 07:25 AM #1395QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
What's faster? For an iPod-style menu I need to draw those little arrows

Is it faster to blit each arrow to the screen (the single small image), or blit one big image with all arrows to the screen, not showing the arrows where there's no menuitem? (Was that understandable?)
-= Double Post =-
I assume the latter is faster. Also I need to leave a bit of the screen black.

What's the fastest way to do that? Drawing a white rectangle and leaving it black? I heard that is pretty slow. Is there a better way?Geändert von Lukeson (10-19-2006 um 07:25 AM Uhr) Grund: Automerged Doublepost
-
10-19-2006, 09:12 AM #1396QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
You should try out more than asking questions for everything you want to do. It's not hard implementing both methods for both cases and checking wich is faster.
Drawing rectangles is faster than drawing textures (images), as long as you do it with GU.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-19-2006, 09:49 AM #1397QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
These are my first steps in C, I'm still very 'careful', wanting to have confirmed every step I take. But I must confess I could have answered these questions myself, I didn't really think before writing them (a behavoir which I always which I always gripe PHP-noobs about...). :/ SorryYou should try out more than asking questions for everything you want to do.
-
10-19-2006, 10:01 AM #1398AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
EDIT: Never mind... I was just being stupid... >_<
-
10-19-2006, 10:59 AM #1399QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Well, I have no problem with that, because I don't have to answer your questions :P It's only that you will learn much more, when you try around and find a solution/answer yourself (because you also learn things that don't have to do with the actual solution - as in this case you would know how to do the imperfect solution too, plus how to bench the code)
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-19-2006, 11:24 AM #1400QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
true true...
-
10-19-2006, 02:12 PM #1401sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
Ok, youresame told me to tell you this
Zitat von Lukeson
Not sure what it means, do you?....>
-
10-19-2006, 02:16 PM #1402AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
It's faster to blit the arrows separately.
-
10-19-2006, 03:20 PM #1403Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
ok.i have a bullet class, and i want to use an array with bullets is it, but its giving me errors. my code:
Code:Image * player; Image * bullet; Image * cursor; int crossPressed = 1; int currentBullet = 1; class bullet { public: int x; int y; int fire; float angle; int speed; }; bullet hBullet[]; int main(void) { pspDebugScreenInit(); SetupCallbacks(); initGraphics(); SceCtrlData pad; player = loadImage("player.png"); bullet = loadImage("bullet.png"); cursor = loadImage("cursor.png"); while (1) { sceCtrlReadBufferPositive(&pad, 1); sceDisplayWaitVblankStart(); flipScreen(); } return 0; }
but it gives me this error:
and here is line 66:Code:main.cpp:66: error: 'bullet' does not name a type make: *** [main.o] Error 1
Code:bullet hBullet[];
what wrong?--------------------------------------------------------------------------------------
-
10-19-2006, 03:30 PM #1404words 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
Im sure you can convert that to a structure...
That will make it work. But, thats not really what you asked, rather an alternative if your in a hurry. Hope someone answers your question! (oh and maybe a google search on classes will help?)Code:typedef struct bullet { int x; int y; int fire; float angle; int speed; } bullet;
...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-19-2006, 03:36 PM #1405QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
You have to declare how many bullets you want in the array. You can't just use xxxxxxx[]. It has to be xxxxxxxxxx[4].
When you create an array, you have to declare the size of it on construction.
-
10-19-2006, 03:49 PM #1406Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von head_54us
nope, still the same error. i definied it like this now:
Code:bullet hBullet[9];
--------------------------------------------------------------------------------------
-
10-19-2006, 03:53 PM #1407QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Is the file a .cpp? Do you have any other errors? Is this all in one file?
The code itself is fine. I have just checked.
-
10-19-2006, 04:08 PM #1408Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von head_54us
lol, i figured it out. i was declaring bullet as an image as well. i changed that, and it fixed it, BUT, now im getting linkning errors:
i haven included graphics.h in my main file as well as my makefile. here is my make file:Code:main.o: In function `main': main.cpp:(.text+0xe8): undefined reference to `initGraphics()' main.cpp:(.text+0xf4): undefined reference to `loadImage(char const*)' main.cpp:(.text+0x108): undefined reference to `loadImage(char const*)' main.cpp:(.text+0x11c): undefined reference to `loadImage(char const*)' main.cpp:(.text+0x140): undefined reference to `flipScreen()' collect2: ld returned 1 exit status make: *** [hello.elf] Error 1
whats wrong now??? (btw, is it just me, or does cygwin seem to hate me?)Code:TARGET = BulletTest OBJS = main.o graphics.o framebuffer.o CFLAGS = -O2 -G0 -Wall CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti ASFLAGS = $(CFLAGS) LIBDIR = LIBS = -lpspgu -lpng -lpsppower -lz -lm LDFLAGS = EXTRA_TARGETS = EBOOT.PBP PSP_EBOOT_TITLE = TestOne PSPSDK=$(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak
--------------------------------------------------------------------------------------
-
10-19-2006, 04:10 PM #1409QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
It is saying that the functions have been declared and used but not defined. Are they in graphics and/or framebuffer source files?
-
10-19-2006, 04:16 PM #1410Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von head_54us
yep. all in there--------------------------------------------------------------------------------------


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