[Interested?] OldSchool Library

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Josh1billion
Posts: 32
Joined: Tue Jul 12, 2005 8:45 am
Location: Wisconsin, USA
Contact:

Post by Josh1billion »

Nice library, first of all.

I have some problems that you might be able to help me with. First of all, I'm using C++, and no, this isn't about the bool thing (I already fixed that by deleting the "typedef short bool" line and replacing "bool" with "short" throughout the rest of that file).

Note that various examples from the site (such as the sprite example) DO compile and link without any problems.

I have a few different C++ source files (.cpp), and I include <oslib/oslib.h> into all three of them. But, this causes errors in the linker (after compiling), saying that it's trying to redefine stuff like "osl_intKeys" and "osl_powerCallBack." Removing the #include <oslib/oslib.h> line from two of the three C++ source files fixes the problem... but, of course, that's not a solution.

Here are the errors, I'm using the new Win32 dev environment that came out today (see PSP Updates).
mario.o:(.bss+0x0): multiple definition of `osl_intKeys'
main.o:(.bss+0x30): first defined here
mario.o:(.sbss+0x0): multiple definition of `osl_keys'
main.o:(.sbss+0x4): first defined here
mario.o:(.sbss+0x4): multiple definition of `osl_powerCallback'
main.o:(.sbss+0x8): first defined here
world.o:(.bss+0x8): multiple definition of `osl_intKeys'
main.o:(.bss+0x30): first defined here
world.o:(.sbss+0x0): multiple definition of `osl_keys'
main.o:(.sbss+0x4): first defined here
world.o:(.sbss+0x4): multiple definition of `osl_powerCallback'
main.o:(.sbss+0x8): first defined here
/cygdrive/c/pspdev/bin/../lib/gcc/psp/4.0.2/../../../../psp/lib/crt0.o: In funct
ion `_main':
/home/loser/newtoolchain/pspsdk/src/startup/crt0.c:86: undefined reference to `m
ain'
collect2: ld returned 1 exit status
make: *** [test.elf] Error 1
Josh1billion - PHP, C++, PSP programmer.
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

you cannot define multiple times ...this is not just OS lib problem
just have one file where you keep the defines ...ex. defines.h
and have other source include that one and it should be fine
10011011 00101010 11010111 10001001 10111010
User avatar
Josh1billion
Posts: 32
Joined: Tue Jul 12, 2005 8:45 am
Location: Wisconsin, USA
Contact:

Post by Josh1billion »

I didn't define those, they're inside of oslib/oslib.h

edit: It seems this is merely a C++ compatibility issue. I'm looking forward to the next release.. :)
Josh1billion - PHP, C++, PSP programmer.
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

hey, love the lib, nothing better for 2d games, which people should make anyways. But I've run into a problem. I can't get diagonal control checking with the dpad or the anolog nub.

Code: Select all

int a;
oslReadKeys&#40;&#41;;
//joystick
for &#40;a=60;a<=120;a+=60&#41;			
&#123;
	if &#40;osl_keys->analogX > a&#41; &#123;
		//Do something
	&#125; else if &#40;osl_keys->analogY > a&#41; &#123;
		//Do something
	&#125; else if &#40;osl_keys->analogX < -a&#41; &#123;
		//Do something
	&#125; else if &#40;osl_keys->analogY < -a&#41; &#123;
		//Do something
	&#125; else &#123;
	//Do something when the stick isn't moved
	&#125;
&#125;
But when I add something like

Code: Select all

if &#40;osl_keys->analogX > a && osl_keys->analogY > a&#41; &#123;
//do something when analog
&#125;
it won't work. help please?
johnsto
Posts: 30
Joined: Wed Jan 18, 2006 8:52 am

Post by johnsto »

The problem is you're treating X and Y as if they're the same thing... try this instead:

Code: Select all

int a;
oslReadKeys&#40;&#41;;
//joystick
for &#40;a=60;a<=120;a+=60&#41;			
&#123;
	if &#40;osl_keys->analogX > a&#41; &#123;
		//Do something
	&#125; else if &#40;osl_keys->analogX < -a&#41; &#123;
		//Do something
	&#125; else &#123;
		// stick not moved sideways
	&#125;

	if &#40;osl_keys->analogY > a&#41; &#123;
		//Do something
	&#125;  else if &#40;osl_keys->analogY < -a&#41; &#123;
		//Do something
	&#125; else &#123;
		 // stick not moved upwards or downwards
	&#125;

&#125;
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

Ok, now how do I add the diagonal checks?
johnsto
Posts: 30
Joined: Wed Jan 18, 2006 8:52 am

Post by johnsto »

Zettablade wrote:really. it doesn't look like that would solve it. But what ever. i'll try it.
No it won't solve it. It's just to point you in the right direction. I don't know enough about what you're trying to do to solve it.
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

I've pretty much got a little guy running around one screen, and I need him to run diagonally.
johnsto
Posts: 30
Joined: Wed Jan 18, 2006 8:52 am

Post by johnsto »

Zettablade wrote:I've pretty much got a little guy running around one screen, and I need him to run diagonally.
Ok, in that case the code I posted should definitely help you.

The problem was that your code was basically only checking if the joystick had moved up OR down OR left OR right. It wouldn't detect if the joystick had moved up AND left for example, because all the checks were in the same 'if' block, and as soon as one of those was true, it stopped checking the rest.
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

ok

Post by Zettablade »

so, now i just add all the diagonal checks in a sperate if block and it should work? Same with the dpad right?
Wait, I just realized something. If it checked for diagonal at the beginning of an if block with everything in it, shouldn't it work?
johnsto
Posts: 30
Joined: Wed Jan 18, 2006 8:52 am

Re: ok

Post by johnsto »

Zettablade wrote:so, now i just add all the diagonal checks in a sperate if block and it should work? Same with the dpad right?
Well, I spose that's one way of doing it.

The code I showed you basically did two things - first it checks if the joystick has moved sideways. Then it checks if it has moved vertically.

If in the sideways bit you put your "move character left/right" code, and in the vertical bit you put in your "move character up/down" code, then that's all you need. If the joystick is moved sideways and vertically, both parts of your code will execute (which will move your character left/right AND up/down) and the character will move diagonally.
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Re: ok

Post by Zettablade »

johnsto wrote:
Zettablade wrote:so, now i just add all the diagonal checks in a sperate if block and it should work? Same with the dpad right?
Well, I spose that's one way of doing it.

The code I showed you basically did two things - first it checks if the joystick has moved sideways. Then it checks if it has moved vertically.

If in the sideways bit you put your "move character left/right" code, and in the vertical bit you put in your "move character up/down" code, then that's all you need. If the joystick is moved sideways and vertically, both parts of your code will execute (which will move your character left/right AND up/down) and the character will move diagonally.
But it's a little different when you need to show visuals of them running diagonally. As I said before, if it checked for diagonal at the beginning of an if block with everything in it, shouldn't it work?
johnsto
Posts: 30
Joined: Wed Jan 18, 2006 8:52 am

Re: ok

Post by johnsto »

Zettablade wrote: But it's a little different when you need to show visuals of them running diagonally. As I said before, if it checked for diagonal at the beginning of an if block with everything in it, shouldn't it work?
Yep, it is and yes that should work if you do the if-statements right. It's pretty untidy (imo) but it should work.

Code: Select all

	if &#40;osl_keys->analogX > a && osl_keys->analogY > a&#41; &#123;
		// up-right
	&#125; else if &#40;osl_keys->analogX < -a && osl_keys->analogY > a&#41; &#123;
		// up-left
	&#125; else if &#40;osl_keys->analogX > a && osl_keys->analogY < -a&#41; &#123;
		// down-right
	&#125; else if &#40;osl_keys->analogX < -a && osl_keys->analogY < -a&#41; &#123;
		// down-left
	&#125; else if &#40;osl_keys->analogX > a&#41; &#123;
		// right
	&#125; else if &#40;osl_keys->analogY > a&#41; &#123;
		// up
	&#125; else if &#40;osl_keys->analogX < -a&#41; &#123;
		// left
	&#125; else if &#40;osl_keys->analogY < -a&#41; &#123;
		// down
	&#125; else &#123;
	   //nothing
	&#125; 

I can't remember properly, but I think full X/Y on the analog stick is not equivalent to full X or full Y (because it's circular), so you might want to reduce the granularity of your if-loop to something much less. (i.e. the value in 'a' might be too large for the diagonal value checks)
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

That worked, thanks.

Now I need to swizzled an image. how do i do that?
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

meh, i changed my last post, just thought i'de bump it up for attention.
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

You can use the following: oslCreateSwizzledImage, oslSwizzleImage (currently works only if imgSrc != imgDst, so you should use the other).

Sorry for not being very active, I just finished my exams, and I'm trying to fix a weird bug that provokes random crashes. I've reread my code 10 times and found nothing bad, and I'm not even sure if it doesn't come from my application which uses OSLib (but shouldn't, it's very simple), or even from the compiler itself.
So it's why I'm asking you: has anyone had random crashes (works for a build, crashes the other, or gets graphic corruption, flickering, etc.) when using OSLib? I really need your experience (even if it worked properly all the time).
Also, if anyone wants to help me fixing this issue, please PM me or post here, it would be very kind of you ;)

Thanks in advance
Sorry for my bad english
Image Oldschool library for PSP - PC version released
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

Brunni wrote:You can use the following: oslCreateSwizzledImage, oslSwizzleImage (currently works only if imgSrc != imgDst, so you should use the other).

Sorry for not being very active, I just finished my exams, and I'm trying to fix a weird bug that provokes random crashes. I've reread my code 10 times and found nothing bad, and I'm not even sure if it doesn't come from my application which uses OSLib (but shouldn't, it's very simple), or even from the compiler itself.
So it's why I'm asking you: has anyone had random crashes (works for a build, crashes the other, or gets graphic corruption, flickering, etc.) when using OSLib? I really need your experience (even if it worked properly all the time).
Also, if anyone wants to help me fixing this issue, please PM me or post here, it would be very kind of you ;)

Thanks in advance
It's nice to meet you. I love your lib! It's the best in the world.
Now that i've said that, can you give me a quick example of using oslCreateSwizzled Image.
and one last thing. I can totally relate to having flickering/disappearing images. it happens all the time. I've got it fixed right now, but if you want, i can tell you what's happened and what i did to fix it.
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

ok, finally got the image swizzled. But i heard that you can bypass image size restrictions by swizzling. How do i do that?
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

Thank you. I didn't even know that the image size could be bypassed by swizzling (and I seriously doubt from it), so I can't help you, sorry. Basically, the advantage of swizzling is the speed (but it's only for fixed images).
And can you explain please what was your flickering problem?
Sorry for my bad english
Image Oldschool library for PSP - PC version released
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

Brunni wrote:Thank you. I didn't even know that the image size could be bypassed by swizzling (and I seriously doubt from it), so I can't help you, sorry. Basically, the advantage of swizzling is the speed (but it's only for fixed images).
And can you explain please what was your flickering problem?
For some reason it was flickering and such. So after a lot of debugging and such I figured it out.

Code: Select all

int main&#40;int argc, char* argv&#91;&#93;&#41;
&#123;
	//Initialization
	oslInit&#40;0&#41;;					//The lib
	oslInitGfx&#40;OSL_PF_8888, 1&#41;; //Gfx
	oslInitConsole&#40;&#41;;			//Text
	//Main loop
	while &#40;!osl_quit&#41;
	&#123;
		oslSwapBuffers&#40;&#41;;
		oslStartDrawing&#40;&#41;;
		oslSetDrawBuffer&#40;OSL_SECONDARY_BUFFER&#41;;
		//diplay the images and such
		oslEndDrawing&#40;&#41;;
		oslSyncFrame&#40;&#41;;
	&#125;
	oslEndGfx&#40;&#41;;
	oslWaitVSync&#40;&#41;;
	oslQuit&#40;&#41;;
	return 0;
&#125;
Hope this helps. Anything to improve this lib. If you wanna see the full code, I can pm it to you.
Also, Does anyone know how to load an image saved as a .c file and blit it to the screen? I'de really like to know.
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

Image size restriction is an hardware PSP limit. Loading from a file or data won't change anything ;-)
Else, do you know what this does?
oslSetDrawBuffer(OSL_SECONDARY_BUFFER);
It sets up to draw on the currently visible screen buffer, making double-buffering useless, it's why you got flickering ;-)
I was talking about random crashes ^^
I'm still testing to find this problem, but that's not easy :-(
Source will be released soon, I have to finalize this newer version (which will have C++ support, Windows version, optimizations and some new things) and clean it, but if you really need it, you can still ask the temporary version to me ^^
You can also ask for new features, but keep in mind that OSLib was designed to be simple and extensible, but especially fast and lightweight.
Sorry for my bad english
Image Oldschool library for PSP - PC version released
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

Brunni wrote:Image size restriction is an hardware PSP limit. Loading from a file or data won't change anything ;-)
Else, do you know what this does?
oslSetDrawBuffer(OSL_SECONDARY_BUFFER);
It sets up to draw on the currently visible screen buffer, making double-buffering useless, it's why you got flickering ;-)
I was talking about random crashes ^^
I'm still testing to find this problem, but that's not easy :-(
Source will be released soon, I have to finalize this newer version (which will have C++ support, Windows version, optimizations and some new things) and clean it, but if you really need it, you can still ask the temporary version to me ^^
You can also ask for new features, but keep in mind that OSLib was designed to be simple and extensible, but especially fast and lightweight.
Ok, now it makes sense.

Anyways I've decided to just load it in seperate images instead of a sprite sheet. :P Take that file restriction...:'(
So I loaded it as an array. I have a little guy that's supposed to run around. problem is, when the the image number on the array changes, and changes the the image, the x/y cords don't same the same for all the images. so, how do I make a global y/x cord that works for all the images in the array.
Last edited by Zettablade on Wed Jun 21, 2006 4:48 pm, edited 2 times in total.
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

wow, my last post was a big giant garble of un readable content. lol
Well, I've changed it. mods may delete this if they see fit.
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

I don't really understand your question, but oslDrawImageXY (passing your global x/y pos each time) might be the answer :p
Sorry for my bad english
Image Oldschool library for PSP - PC version released
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

Brunni wrote:I don't really understand your question, but oslDrawImageXY (passing your global x/y pos each time) might be the answer :p
lol either way, that probably is the answer.
I'll try that in a second.

Edit:: yeah it worked. The images all move together now. lol. I'm loving oslib more and more each and every day.
Edit:: I added some sound to the program. I'm using the .bgm file from your maps & sound sample program. It loads and plays the bgm file, but music slow, scratchy, and unreconizable. what's does this mean?
Some thing I've found is that the audoi plays correctly, but only when assigned to play after a button press. I dunno why? Brunni?
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

Bumped!
jsharrad
Posts: 100
Joined: Thu Oct 20, 2005 3:06 am

Post by jsharrad »

Is it possible to use this with wifi? I am switching to a user thread after the wifi is setup but my psp locks up when I blit an image (loading the image works fine)
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

jsharrad wrote:Is it possible to use this with wifi? I am switching to a user thread after the wifi is setup but my psp locks up when I blit an image (loading the image works fine)
Hmm...I would assume it is. You can use the pspsdk in conjunction with this so you should be able to. if not, then I'm screwed, because my game will neverhave online play, which I plan to base it on. :p
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

Update!!!
*Should* fix the following:
            - Conditional: 2.01+ support
            - No more random crashes
            - C++ support
It also adds some undocumented features, wait for the definitive version until they are ;-)
I've still not added the source, I'll do it for the definitive release.
Please report me whether it works on 2.01/2.5/2.6, or if you got any problem with it. Download.
Last edited by Brunni on Mon Jun 26, 2006 6:43 pm, edited 1 time in total.
Sorry for my bad english
Image Oldschool library for PSP - PC version released
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

sweet! hope you get the english docs finished soon. i have a bug to report though. on a 2.6, it crashes on the exit.
Post Reply