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; im not making a simple imaging program i just left the name as it is because it doesnt matter right ...
-
01-30-2006, 05:07 PM #31
im not making a simple imaging program i just left the name as it is because it doesnt matter right now i was just testing my code to see if everythin i was coding was already workin
and cud u explain wat wrote u got me confused
-
01-30-2006, 10:12 PM #32
thanks yel, every tut is comprehensicve and helpful. I am having one problem insignificant of a thread, and i was hoping that you guys could help me out. I have tried everything (even looking through the OG Keringham book) to find things on time. I am well aware of all the time functions and all that it can give me, but alas, it only goes down to seconds. is there any way to tell the psp to do something, say, every 1/4 of a second without measuring processor speeds and doing humgous math?
much thanks.
posted in right thread, sorry.
-
01-30-2006, 10:32 PM #33
- Registriert seit
- Nov 2005
- Beiträge
- 16
- Points
- 4.419
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Not sure what threading is available on the PSP, but you could just do the following
Zitat von orphan frequently
while (1)
{
spawn new thread; // i.e. your work
sleep(250);
}
Basically main loop just waits, then spawns new thread todo the work... but this solution assumes that the threads that is spawned would either not share resources with the next thread created (can od done though), or takes less than the sleep period to complete it's task.
-
01-30-2006, 11:18 PM #34
thanks, i think this will work, so 250 will be 1/4 a second?
-
01-31-2006, 03:14 AM #35Mushroom Man
- Registriert seit
- Sep 2005
- Ort
- UK
- Beiträge
- 318
- Points
- 7.283
- Level
- 56
- Downloads
- 0
- Uploads
- 0
The PSPs own API also has a sleep function which can be measured in nano instead of mili. sceKernelDelayThread(2500 00); = delay for 1/4 of a second.
-
02-01-2006, 07:22 AM #36words 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
wait so say i wanted a to dsiplay an image for say 5 seconds, what would i do? i cant seem to find a way, the closes ive gotten is this...
any help?Code:blitAlphaImageToScren(0, 0, width, height, variable*, posX, posY); for(i=0; i<15; i++) { sceDisplayWaitVblankStart(); }
...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-01-2006, 07:28 AM #37Developer

- Registriert seit
- Jan 2006
- Beiträge
- 223
- Points
- 4.667
- Level
- 43
- Downloads
- 0
- Uploads
- 0
when doing infinte loops, it's actually better to use a blank for loop, or, sigh, gotos.
Zitat von ipod
The reason for this is so that it doesn't perform a check to see if the statement is true when looping. Infinite loops doesn't need this. Maybe the compiler optimizes this, I don't know, but for max performance, I would do it this way:
Code:for( ; ; ) { spawn new thread; // i.e. your work sleep(250); }Saying that Java is nice because it works on all OS's is like saying that anal sex is nice because it works on all genders
-
02-01-2006, 04:16 PM #38words 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, that kinda helps me, i dunno really, im working on a side scrolling backround, but i cant load an image with bigger width than 500, how can i do such a thing? may be if i blit the image and if this object goes on this certain pixel line, then it blits the image 1 pixel to the right and blit the new backround under it to take up hte bladc space, anyone have a good example of a side scrolling backround? like the one in little fighter? except thats in lua, so maybe just something so if an image/something goes on a certain pixel, than itll scroll? i dunno just asking some random questions

...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-02-2006, 02:13 PM #39QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
Does anyone know how I can do the equivalent of
using the sceKernelAllocPartitionMe mory (); function ??Code:firstpointball = malloc( sizeof(struct pointball) );
I understand some of the variables it's asking for, but not sure what I should have in there for partitionid and name...
The snippet of code is creating a new node on a linked list, and because i'm using malloc I think it's affecting it's combatibility with 2.1+
Also, if Fanjita see's this thread, what limitations are there for programming 2.1+ or are they the same as 2.0 ?PSN: Shatterdome
-
02-02-2006, 05:08 PM #40words 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 also wish to know tis fanjita, should more than the PSP_MODULE, Kernel Calls,etc. be removed?

...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-02-2006, 06:03 PM #41Mushroom Man
- Registriert seit
- Sep 2005
- Ort
- UK
- Beiträge
- 318
- Points
- 7.283
- Level
- 56
- Downloads
- 0
- Uploads
- 0
2.0+ proofing is also a subject I'm very interested in. It seems the calls mapped in the toolchain are very hit and miss when it comes to coding software that will work with Fanjitas loader. Trial and error is the only way I guess, bar delving into the toolchain to check out what is causing problems :o.
-
02-03-2006, 04:39 AM #42QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
Yeah, unfortunately all I have is a 1.5....
There is a thread on ps2dev.org on how to program for the 2.0, just not sure if it's the same for 2.1+...
For 2.0 the biggest thing is not to call kernel access (But even one of my games which I was calling kernel acces too loaded once in awhile, but I was just passing the parameter, not actually doing anything with the kernel access)
Then for stability he says to use scemempartitionalloc instead of the malloc that is in the new libc, but the sce function asks for a few extra parameters/variables then malloc, which just needs the size of the memory to set aside....ill let you know if I hear anything...PSN: Shatterdome
-
02-03-2006, 08:03 PM #43words 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, hope u get an answer for us soon seeing as how i want to try to complie one of my demos for 2.0 support and see what happens, the inly thing im really doing is calling PSP_MODULE, ill remove it adn then itl work on 2.0 + right

...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-04-2006, 08:10 AM #44
Headers
i have been looking through peoples codes and ive noticed tha certain people tend to write header files for their projects.. i was just wondering what the purpose of writing a header was??
-
02-04-2006, 09:11 AM #45QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
Depends how many different functions you are using, and in what categories.
If you've created 100 functions to handle gameplay, such as fighting, deteriming damage, level up...etc. It's usually a good idea not to clutter up your main.c, you create a fightfuncts.c with all your code in it, then a fightfuncts.h with your function prototypes, include it in your main.c. Then when you want to change something to do with fighting, you look through the fightfunct.c/h instead of trying to sort through a super huge main.c
I've yet to make a big enough program to warrant that yet though :P Although you can do it with any # of functions just for good practice and to keep things neat...PSN: Shatterdome
-
02-04-2006, 09:14 AM #46
oo i c now thx alot
-
02-04-2006, 10:47 AM #47words 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 call that calling functions from other source files, i have like 5 other source files other than my main.c, 1 for credits, one for game, one for debug, one for options, and 1 for menu, and chingwyn, i think i found a good gravity, i got to talkto u somewhere about it to see what you think, AIM, msn, pm, 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-07-2006, 12:48 PM #48words 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, back with another problem needing an answer, i have a score (not really but for example use it), and say i wanted to print it to the screen, but it has a variable in it (%i), so far get it? Ok, i call printf("iasjdkfsjk %i", score); ok, now this works, except it just scrolls by really fast by the screen with this black bar under it, i want it to just stay where i put, but i nat no matter what, so i looked in graphics.h and found printtextimage or whatever and it works!, but it is behind the images before it a little bit and i cant use an integer call or anythng in it, anyone want to point in the right direction for printing text to the screen above multiple images, that can hold an integer argument? also, one more question, how do i get .mp3 music to stop and not play and not freeze and such if i go back and forth etween source files in a game?

...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-07-2006, 12:49 PM #49QJ Gamer Green
- Registriert seit
- Jan 2006
- Beiträge
- 4.289
- Points
- 25.223
- Level
- 95
- Downloads
- 0
- Uploads
- 0
How do you get MP3s in a game period?
Geändert von soccerPMN (05-06-2006 um 07:54 PM Uhr)
QJ loads way 2 slow & the theme is ugly as hell, gone are the glory days
-
02-07-2006, 03:17 PM #50QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
SG57, use...
brightred can be replaced with an RGB value, but I find it easier to define the colours I want at the begining, after your #include's and #defines like...Code:char buffer[100]; (I use a large number to be safe) sprintf(buffer,"Score: %i",playerone.score); printTextScreen(300,10,buffer,brightred);
orCode:Color brightred = RGB(200, 0, 0);
Values are 1-255 as you may know...if you have photoshop or another image prog you can usually pic a color, then in one of the windows it should say the RGB value...in case you are looking for a specific colour...Code:Color brightblue = RGB( 0, 0,200);
As far as making sure the score is on top of everything, just make sure it's the last thing drawn before you flipscreen();
MP3's...no clue, yet to learn me that...Geändert von Shatterdome (02-07-2006 um 03:19 PM Uhr)
PSN: Shatterdome
-
02-07-2006, 03:20 PM #51words 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
no whats weird? i just did that and learned how to do that, but didnt try and i fixed the MP3 thing without ur help ( you were too slow), but as for that, ill try it out and then probably relase another of my demos just for laughs, you ahve to see this lol, your a cat dodging huge fireballs, but i cnat get collisio detection
any help? just use fireballx and firerebally as those co-ordinates and catx and caty for the cats, the dimensions of the fireblal is 60 x 60 and cat is 32 x 32 thanks!

...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-07-2006, 03:23 PM #52QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
oh well...then just look at this then...
http://www.gamedev.net/reference/art...article735.aspPSN: Shatterdome
-
02-07-2006, 03:26 PM #53QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
oh and i'll have to get you to learn me how to get mp3's running once I get to that point in my game...although I guess it would be something I should implement asap, make sure it doesn't effect anything else. What .h file do you use for that ?
PSN: Shatterdome
-
02-07-2006, 03:30 PM #54words 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, quick tut
Zitat von soccerPMN
1. svn co svn://svn.pspdev.org/psp/trunk/libmad
cd libmad
make
manually install the include folder and .a file to its place
2. download mp3player.h and mp3player.c from that one thread a while back
3.
thats about it, in the makefile add mp3player.h to the object line,Code:#include <pspaudio.h> #include <pspaudiolib.h> #include "mp3player.h" int main() { pspAudioInit(); MP3_Init(1); MP3_Load("yourmp3namehere.mp3"); while(1) { do what ever you want and stuff MP3_Play(); } }
add -lpspaudio and -lpspaudiolib and -lmad to the libs line, and thas about it
but if u wnat to stop the music, aminly so the psp doesnt freeze for whe going from the main gmae nad menuj and back, then go into the mp3player.h and add 'extern void MP3_FreeTune();' that other tut thing didnt have that so nothing ever worked when quiting! pretty bad tut if u ask me but it worked after i fixed my own
...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-07-2006, 03:45 PM #55QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
Seems simple enough...guess this is only good for BG music though and not SFX...I'm a little wary on clocking up to 333 just to get music going as well...as right now i'm running my game at 11mhz and want to keep it as low as possible, just slowly clocking it up when I add something that slows it down...so I guess I should look into how to play wavs, or some other uncompressed sound file...
PSN: Shatterdome
-
02-07-2006, 04:53 PM #56words 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
o, then get SDL and SDL_mixer and look thro the .h file of wav and walaa. thats what i did, its kinda confusing but it works

...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, 04:16 AM #57Developer

- Registriert seit
- Jun 2005
- Ort
- Sydney, Australia
- Beiträge
- 128
- Points
- 5.116
- Level
- 45
- Downloads
- 0
- Uploads
- 0
Also Shatterdome, if you want the Mp3 to stop after it has run once, put this into a loop somewhere in your code -
Essentially, libmad has a variable eos (end of stream) to indicate when an Mp3 has finished. eos is 1 when it has just finished.Code:if (MP3_EndOfStream() == 1) MP3_Stop();
On the CPU side of things, 333 Mhz was just to be safe so that people could do pretty much whatever they wanted and not complain that the Mp3 playing made their app slow. I believe that libmad is quite reasonably efficient, and I know for certain it works at 222 Mhz. Give the lower speeds a try and if they work, all good. Your mileage may vary depending on bitrate etc however.
SG57 -
Yes, I apologise once again for the bad tutorial, I am working with Yeldarb to improve it. This was how the libmad library was called upon at svn.pspdev.org, but that is no excuse for not noticing the deficiencies.but if u wnat to stop the music, aminly so the psp doesnt freeze for whe going from the main gmae nad menuj and back, then go into the mp3player.h and add 'extern void MP3_FreeTune();' that other tut thing didnt have that so nothing ever worked when quiting! pretty bad tut if u ask me but it worked after i fixed my own
Please however, if you did something to help improve the source code, send me a note and from it you'll help others. How will the tutorial improve if we hide behind a sort of closed source mentality?
Anyway, thanks for working that problem through.
Also, to note, Mp3_FreeTune is called on when using Mp3_Exit, so you don't really need to call on them seperately.Developer of Airstrike
-
02-08-2006, 07:21 AM #58words 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 was thinking back on ur tut, and u put MP3_Stop(); then MP3_FreeTune(); but MP3_FreeTune(); was an implicate call, meaning it wasnt defined in the header when i looked at it, so i searched thro the mp3player.c and found the MP3_FreeTune() function and then i just defined the MP3_FreeTune(); in the header and it worked fine, now this MP3_Exit however, im not seeing it in the header, so im going to search thro the .c again and find it, and u left out ALOT of functions to define in hte header, i was seeing a lot of things u cna do with the mp3player.c, but you didnt define them in hte header, thus meaning people cant use em!, i might just fix it up completely then do what i can
Zitat von Smerity
ok, my question, is there anyway i could make like an options.txt as an options menu kinda? meaning itll erad it, then if ackround option is 1 then itll blit this backround, but if its 0, hten itll blit the other backround, get it?
...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, 03:43 PM #59QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.492
- Points
- 9.457
- Level
- 65
- Downloads
- 0
- Uploads
- 0
That's good to know, so feasibly you could play sound effects with it...but would that effect the bgmusic ? is it possible to load different mp3's onto different channels ? Then just have one for music and one for sound effects ?
Then it'd be a matter of finding a decent sounding but still low bitrate setting so that maybe the psp doesn't even have to be at 222....
I'm just thinking about it now...2 more days and I get a week off from school and i'm gonna hit my game hard...PSN: Shatterdome
-
02-08-2006, 08:22 PM #60words 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, 2 more problems needing answers, 1st, when ever i try what u said shatterdome, it displays on the top of all my pictures fine, and the variable will show, as 0 to start, but it wont increase, even if i put X = score++;, probably menaing the text wont refresh thus meaning the variable wont increase, unless, its the variable its selfs problem because i put if score = 10, hen do menu(); which would take u to the main emnu and it wshould, but it doesntmeaning the int wont go up or move at all, i dunno ill work on it
2nd, i need help on animation arrays, meaning i ahve 3 images, how could i set them up in an array and blit 1 at a time infinintly making the image an animation? i knwo its possible but how? thanks...
...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