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; not sure...you have to make sure you are sprintf'ing to update buffer[], everytime you change the score var, then print ...
-
02-08-2006, 08:31 PM #61QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
not sure...you have to make sure you are sprintf'ing to update buffer[], everytime you change the score var, then print it out.
As far as animations, yeah theoretically an array of images should be fine, then have a for loop to blit it, with vsyncwaits in there to control how fast the animation is....I was having problems getting it running stable that way. So instead I just loaded all the animation pics up seperately and wrote out a long ass function to play the animation (refering to the explosion when you die in my helicopter game) Works good for me, if not the best way...
PSN: Shatterdome
-
02-08-2006, 09:27 PM #62words 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
ok, now how do i do an array, like int array() { or what?

...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
-
02-08-2006, 10:35 PM #63Developer

- Registriert seit
- Jun 2005
- Ort
- Sydney, Australia
- Beiträge
- 128
- Points
- 5.116
- Level
- 45
- Downloads
- 0
- Uploads
- 0
SG57 -
Check out Google, as C on the PSP is much the same as C on the PC, so any standard array tutorial will work on PSP, but to get you started -
And for a multidimensional array -Code:int ia[6] = {0, 1, 2, 3, 4, 5}; // initialise array and put numbers into it OR int x[6]; // init array int x[4] = 2; // put a number only in #4 of the array
This looks like a good tutorial for arrays - http://vergil.chemistry.gatech.edu/r...al/arrays.htmlCode:int psp_resolution[480][272];
Developer of Airstrike
-
02-08-2006, 11:01 PM #64Developer

- Registriert seit
- Jun 2005
- Ort
- Sydney, Australia
- Beiträge
- 128
- Points
- 5.116
- Level
- 45
- Downloads
- 0
- Uploads
- 0
Shatterdome, it does support the use of seperate channels but from what I've seen it only supports a single stream at a time :Argh:
Sorry about that. I'm not sure if it's possible, but John_K ported it specifically for his Media Center, so chances are if it was he skipped over it just because it was easier and he simply didn't need it.
My suggestion would probably be to use Mp3 for the background music / person's PSP/MUSIC and use another library for the sound effects.
If anyone else has any better suggestions, feel free to save the day =)
-PS-
I'm working on getting a simple file browser for Mp3's, so that a user can select an Mp3 from their MUSIC folder to play. First off, if anyone has already done it, and are fine to release the source code, please do, or if else, I'll release my source code when I'm done with it.Developer of Airstrike
-
02-12-2006, 10:10 AM #65QJ Gamer Green
- Registriert seit
- Jan 2006
- Beiträge
- 4.289
- Points
- 25.223
- Level
- 95
- Downloads
- 0
- Uploads
- 0
Well, lostjared released his reuseable file browser, but he uses SDL and it confuses me, otherwise I would implement it in my programs...
-
02-12-2006, 12:20 PM #66QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
I guess SDL doesn't support MP3's ? I am more interested in getting custom soundtracks in my game right now, over sound effects anyways...
I'm gonna take a look into how hard it would be to write a file browser....as long as the psp has functions to get a list of files in a directory or something similar, it wouldn't be too hard...PSN: Shatterdome
-
02-13-2006, 05:27 PM #67QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
Hey all....does anyone have any working examples of writing and reading binary or even text files from the ms ?
I'm using some code that works compiled on the pc to read and write from a file, but for some reason when compiling on the psp it disorts numbers... heres what i'm using...
Code:void savehighscores(void) { FILE * savegame; savegame = fopen("savegame.dat","w"); int i; rewind(savegame); for(i=0;i<10;i++) { fputc(highscores[i],savegame); } fclose(savegame); } void loadhighscores(void) { FILE * savegame; int i; savegame = fopen("savegame.dat","r"); rewind(savegame); // do for(i=0;i<10;i++) { highscores[i] = fgetc(savegame); } // while(feof(savegame) == 0); fclose(savegame); }
It writes to a file, but when it writes it changes the integers I have in there, and seems to read those changed integers fine...tis strange, any ideas ?
thxPSN: Shatterdome
-
02-13-2006, 06:31 PM #68words 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
i dunno, but i can use that read from a .txt file, will it work for reading? Ill test it, also, hwo do i make an animation?!?!?!?!?
i know its an array but i need an example!! i have blooked everywhere!! heres waht i know, i just tested this for an images actual dimensions
theres an example of what i was trying it gave me warnings for the array[0] and array[1] calls, is that right?Code:int array[1][0, 1][175, 125] int main() { blitAlphaImageToScreen(0, 0, array[0], array[1], ya, yax, yay); }
...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
-
02-13-2006, 06:44 PM #69Developer

- Registriert seit
- Jun 2005
- Ort
- At my house...
- Beiträge
- 886
- Points
- 8.360
- Level
- 61
- Downloads
- 0
- Uploads
- 0
For animation use a timer and then for every 5 or so #s blit a pic and clear. Sorry i am on my psp.
-
02-13-2006, 06:47 PM #70QJ Gamer Green
- Registriert seit
- Jan 2006
- Beiträge
- 4.289
- Points
- 25.223
- Level
- 95
- Downloads
- 0
- Uploads
- 0
edit: NVM
-
02-14-2006, 03:05 AM #71Developer

- Registriert seit
- Oct 2005
- Beiträge
- 408
- Points
- 7.058
- Level
- 55
- Downloads
- 0
- Uploads
- 0
I don't think you can trust fgetc and fputc to store numeric data unless you convert it to strings first. Fread and fwrite store binary or text more efficiently and you'll read the same thing you write.
Zitat von Shatterdome
Example:
fwrite(highscores, sizeof(highscores), 10, savegame);
This will write the entire high score list in one line. Fread is basically the same.
-
02-14-2006, 01:12 PM #72QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
Thanks man, works perfect now...strang thing is fgetc and fputc do deal with ints even though it's called put char, and those functions worked fine on the PC with saving the stats of a character created by a random roller, but just wouldn't work on the psp for some reason...
Regardless, fwrite and read will do just fine, as I always will know how much data i'm reading and writing...PSN: Shatterdome
-
02-14-2006, 04:49 PM #73words 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
ok, about my animation problem anyone? Twenty 2, you gave me how to do it, but i want an array because its easier right? and what about my array i posted code problem? how do i call things from my array? I just wish there was a good tutorial

...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
-
02-14-2006, 04:53 PM #74Developer

- Registriert seit
- Jun 2005
- Ort
- At my house...
- Beiträge
- 886
- Points
- 8.360
- Level
- 61
- Downloads
- 0
- Uploads
- 0
you just call the number in the array with its number...and instead of using sprite1 and sprite2 for each blit, you just use the array.
-
02-14-2006, 08:53 PM #75QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
sg57, just google arrays + c and you will get tons of tuts, it's one of the more basic data types (althought technically not, but when you think abouts classes, structures and linked lists, it's a little mundane :P )
int array[10];
is an array with 10 spots labeled 0-9, array[1] = 2; sets the 2nd value of array to 2, array[0] accesses the first value, array[9] the last, for loops are a good way of traversing arrays...there.
Now anyone have any problems installing libmad ? I checked it out and when I goto to make it, before having to copy any file it says i'm missing FPM or something...attached a screen cap of the error....i'm just trying to rebuild the pspsdk to see if it does anything, but maybe it's a common error, i'm hoping :P
Nevermind, much googling later I solved it...Geändert von Shatterdome (02-15-2006 um 01:25 AM Uhr)
PSN: Shatterdome
-
02-15-2006, 05:37 PM #76words 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
Thanks Shatterdome, i'll google arrays later, but all I wanted to know was how to call something in an array, so what you put should work if I made array[0-2] = blitAlphaImageToScreen(ya da ya da); then just say something like:
That would make my animation go forever and change frames every 100 vblanks? Unless someone else has a better animation engine/effect?Code:for(i=0; i<93479; i--) { sceKernelDelayThread(100); array[0]; sceKernelDelayThread(100); array[1]; sceKernelDelayThread(100); array[2]; }
...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
-
02-16-2006, 02:12 AM #77QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
You have the right idea, but arrays can't hold functions, only data types, so you're looking at...
and you would make array[] an array of images...I was having problems doing that so I didn't use an array (for the explosion in my helicopter game), but in theory it should work fine...Code:for(i=0; i<93479; i--) { sceKernelDelayThread(100) ; blitimage(x,y,array[0],x,y); sceKernelDelayThread(100) ; blitimage(x,y,array[1],x,y); sceKernelDelayThread(100) ; blitimage(x,y,array[2],x,y);}PSN: Shatterdome
-
02-16-2006, 07:44 AM #78words 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
ya, I noticed that, in your helicopter game, you had like 5 images of the explosion, and you had one of my own .mp3 playing? how? So, I can mkae
that would assign the 3 images to an array, then blit the first one, and later, have the loop increase to the array thing, thus making an animation? How'd you do an animation for your explosion? Should I use a string instead? Or make a pointer to my images that happens to be inside the array also?Code:char/int explosion[2]; char/int explosion[0] = blitalphaImageToScreen(); char/int explosion[1] = blitAlphaImageToScreen(); char/int explosion[2] = blitAlphaImageToScreen(); while(1) { blitAlphaImageToScreen(0, 0, 32, 32, explosion[0], and so on?); explosion[++]; if(explosion[2] >= [3]) { explosion[2] = explosion[0]; } }
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
02-16-2006, 05:09 PM #79Developer

- Registriert seit
- Jun 2005
- Ort
- Sydney, Australia
- Beiträge
- 128
- Points
- 5.116
- Level
- 45
- Downloads
- 0
- Uploads
- 0
Not quite right there SG57...
That's the way I'd do it. You have to understand explosion[number] implies that you need to input a number, it doesn't take any other form of input, so it'd just give you an error and say '++ not valid blah blah blah'Code:int x = 0; while(1) { blitAlphaImageToScreen(0, 0, 32, 32, explosion[x], and so on?); x++; if(x > 3) { x = 0; }
Still though, with that code there, unless you're just doing a concept, it really doesn't work that well...
The two main problems :
You're in a while loop which won't let you do anything else at the moment, this would be placed somewhere in your main loop.
Especially in this setup the images would flash by much too fast, I'm talking tenths of a second total here.
Solutions :
Because my main loop runs at a pretty specific interval, I use that loop as the loop for my animations.
To get the images to hold a bit longer however, I had something similar to -
Obviously thats pseudo code, you need to reword a few things, but yeah.Code:int anim = 1; int frame = 0; while (1) { // other code / codes here // imagine there are 5 frames in our animation if (frame > 6 && anim == 1) { // change frame here to effect how long it's displayed frame = 0; x++; } else frame++; if (anim == 1) blitAlphaImageToScreen(0, 0, 32, 32, explosion[x], etc); if (x > 5) { x = 0; anim = 0; } // saying if x > 5 our animation is over // other code / codes here }Developer of Airstrike
-
02-16-2006, 07:20 PM #80words 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
Ok, I think I get it, but if I put blitAlphaImageToScreen(); anywhere after the flipScreen();, I'm going to get flashy effects. Maybe I'll do something like,
This might be the one (if it works) that I will use. It loads all the images, blits explosion1, then the timer increases, and if the timer goes over 300 but under 600, then the explosion1, switches to explosion2, then if the timer goes over 600, explosion2 = explosion3, and if the timer goes over 900, then the timer is reset and it changes the explosion3, back to explosion1.Code:Image* explosion1; Image* explosion2; Image* explosion3; //LOAD ALL THE IMAGES AND DEFINE THEM (JUST DON'T BLIT THEM) int time =0; void explosion = explosion1; while(1) { blitAlphaImageToScreen(0, 0, 32, 32, explosion, ya da ya da); time++: if(time > 300 && time < 600) { explosion = explosion2; } else if(explosion >= 600) { explosion = explosion3; } else if(time > 900) { time = 0; } flipScreen(); }
...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
-
02-18-2006, 11:50 AM #81QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
Yeah, this is where having the process of one frame of your program down is stone helps...
such as every frame program..
gets user input
figures out what to do with it
updates players and objects x y positions
checks for collisions
draws everything
goto begining
Also like smerity said, it depends on how often your looping etc...
for an explosion you probably only want to blit it when a missile colides with something...for me it was easy because it was only when the player died, so when the player died I just transfered control of the loop to my playerdead() function which then just needed to draw all the buildings where they were last and then draw the explosion. and I could control how fast it plays with waitforscreens...
Having an animated character or an explosion that will play as everything else moves around it is a little trickier....in that case you would probably have to count your frames and impose a FPS limiter so that animations weren't playing too quickly, because you can't use waitforscreens to slow down the explosion animation because it would slow down everything else as well....something i'm not looking forward to but am going to tackle in my next game
PSN: Shatterdome
-
02-18-2006, 01:46 PM #82words 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
Ok, I'll use you rexplosion example for mine. But how would I get the last screen that was shown to display? Maybe just make everything that's moving, have the speed of 0, then everything will stop. I can easily have the explosion animation blit ontop of what's dieing.

...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
-
02-18-2006, 03:54 PM #83QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
in that case you need to...
draw everything without movement - what you want blowing up
then draw first explosion
then flip
wait for x amount of vsync
then repeat and increment the explosion to 2nd, 3rd, 4th etcPSN: Shatterdome
-
02-19-2006, 10:59 PM #84words 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
Ok, im just going to test an animation program for a bullet and a gun. Ill have X fire a bullet. Ill have UP rotate the gun. Now, I think I understand the animation well enough to make the bullet "blit" at the end of the gun and have a little twisting effect. But I'm left in the dark when it comes to rotation an image. Cant even begin where to start. Ill search my cygwin files and stuf for something that rotates. But in the meantime, anyone know so I can save my self the trouble?

...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
-
02-19-2006, 11:44 PM #85Developer

- Registriert seit
- Jun 2005
- Ort
- Sydney, Australia
- Beiträge
- 128
- Points
- 5.116
- Level
- 45
- Downloads
- 0
- Uploads
- 0
SG57 -
Rotation of images is a bit of a stickler... Very hard to get right...
Two main ways I looked at doing it -
The First Way - Our Friends Sine and Cosine

That was an earlier WIP of my rotation function. I've now gotten rid of the lines (they were because I didn't put 'if (x>imgx)' and 'if (y>imgy)' and also added a filter to remove the aliasing...
What I did behind that was use a pretty standard rotation algorithm (I got it from a huge Computer Graphics book I have, covers 2D and 3D concepts, but it's the same algorithm as the one used here
That actually ends up working fine. The problem (as always) is with the memory used in the process. For every pixel that is rotated, the pixel from the first image must be retrieved, and then the pixel in the next image has to be placed in the relevant spot. This ended up choking the VRAM and I ended up with v. slow (1 FPS) performance.Code:int angle = 180, imgx = 100, imgy = 100; if ( angle != 0 ) { int yx = 0; int xx = 0; int px = 0; int py = 0; int color; while (yx < imgy){ while (xx < imgx){ int xi = xx - (imgx/2); int yi = yx - (imgy/2); px = xi*cos(angle) - yi*sin(angle) + (imgx/2); py = xi*sin(angle) + yi*cos(angle) + (imgy/2); color = getPixelImage( px, py, cannon_o); putPixelImage(color, xx, yx, cannon); xx++; } // x < xx=0; yx++; } // y < } // if angle ! 0
NOTE - If you don't need performance / need to change the image's rotation every second, this is still a pretty good way to do it.
The Second Way - Rotating the Vertices of which the image resides
Dr Watson gave me a link to his game library, StarBugz game prototype and engine (using Gu) with source
Background - Most graphics libraries used with PSP coding atm pastes an image onto a plane (texture onto a quad) and displays it like that. That means that you can support alpha and all that other jazz whilst it being extremely fast (as it uses the GPU)
Having a look in there, I discovered he used a very clever short cut. Instead of rotating the image before hand, you just rotate the plane (quad) of which the image is on. This means that the GPU does all the work, and the GPU is very efficient at such transformations.
Only problem? Dr Watson's code is in C++ ^_^
The graphics library used by Yeldarb et al uses the same concept as Dr Watson's however, and so you can rotate the vertices of the plane, thus rotating the texture (image)
NOTE - You can rotate the vertices (just point <x, y>) using the same algorithm as above, except replace imgx, imgy for vertx, verty or similar.
At that point however, school started back up and I haven't really had a chance to code O_O
I'm sure there are other techniques, but they were the ones I looked at so far...
Good luck, may have to scratch up on your math for this one...Developer of Airstrike
-
02-20-2006, 12:12 AM #86words 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
I never really noticd this Smerity, but Me and You are the only ones that actually stay up as some of the late members. The only reason I am up so late, is because I want to learn more about coding, and I don't have school tomorrow (presidents day).
ON TOPIC: So, your saying that you got your Airstrike rotating barrell working? Or are you still working on it? Also, when rotating, does it rotate the offsets? So I can have the bullet come out of the offset value where the end of the barrel is, cause in alot of shooters, they have a little ship thin going around, then multiple directions to shoot it from. That Geometry type shooter thing, that one has a rotating image that shoots from the 'barrel' so im assuming that the offset values rotate too, that way Ican assign the launching of the bullet from the offset value at the dn of the barrel.
Hopefully you stay up a little late tonight Smerity, that way if I have questions you can hopefully answer them ?
...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
-
02-20-2006, 01:33 AM #87Developer

- Registriert seit
- Jun 2005
- Ort
- Sydney, Australia
- Beiträge
- 128
- Points
- 5.116
- Level
- 45
- Downloads
- 0
- Uploads
- 0
You really have to specify the technique you mean SG57.
For example, offsets won't work in technique 1, but in technique 2 they will.
On the Airstrike gun barrel, still working on it, but the concept is sound, just haven't had enough time recently to implement it.
Off topic - Only 8:30 atm, but yes, I have stayed up very late coding, most devs have, it's just the whole timezone that distorts the sense that people are staying up late.Developer of Airstrike
-
02-20-2006, 02:15 AM #88words 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
Well, it's 2:13 am, here.
Well, if you think my idea of having a barrell moving and something launching from it via an offset, what was your idea for a moving barrel, and still be able to launch stuff from it? In your game, your going to have to do something like that you know...
...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
-
02-20-2006, 02:48 AM #89Developer

- Registriert seit
- Jun 2005
- Ort
- Sydney, Australia
- Beiträge
- 128
- Points
- 5.116
- Level
- 45
- Downloads
- 0
- Uploads
- 0
Dude, I have no clue what you're on about, please explain.
Do you mean offset as in where the object is emitted from?
If so, it's v. easy, find a point just infront of the cannon and apply the exact same rotations to it as you do the cannon...Developer of Airstrike
-
02-20-2006, 06:35 AM #90words 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
I am going to make the barrell all its own image and rotate it on the actual 'cannon' body, just by making that one end a half circle, but i just need to know how to rotate an image 1 *, then I can make a 'for' statement and rotate it as much as I want. So basically, does anyone have a working rotating function that I can put into a prototype to call easily like:
Something of the sort...Code:int rotateImage(int width, int height, some other stuff) { do the fancy stuff here. return NewImage; }
...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


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