1. SDL_GetMouseState - solved

Hi

Firstly I have solved the problem of getting mouse info from the SDL_Event union in a completely different way, but this has got me conceptually bugged

In C

int mx, my, mouseState; 
 
mouseState = SDL_GetMouseState(&mx, &my); 
 
//mouse position = mx,my 

What this does is create integers mx and my, then gives the function the address of these integers, GetMouseState puts these values into mx and my. C provides an easy method of sending the address of the integers in memory - pass by reference I think.

in eu

include SDL ....etc 
 
--relevant lines from SDL_mouse.e 
export constant xSDL_GetMouseState = define_c_func(sdl,"+SDL_GetMouseState",{C_POINTER,C_POINTER},C_UINT) 
public function SDL_GetMouseState(atom x,atom y) 
	return c_func(xSDL_GetMouseState,{x,y}) 
end function 
 
 
integer mx, my, mouseState 
 
mouseState = SDL_GetMouseState(????mx, ????my) 
 

How do I, can I, send the address of these variables to the C function.

One possible work aroud (untested, just thought of it) would be to create a structure, and send the address of the variables, then peek the structure. Will try that tomorrow.

Chris

new topic     » topic index » view message » categorize

2. Re: SDL_GetMouseState - Solved

Hi,

yup, that idea works perfectly.

------------------------------------------------------------ 
--note these are decalared outside of the function, so don't need to keep recreating them 
atom mousePtr = allocate_struct(SDL_Point) 
atom Amx, Amy 
--this way - create and SDL_Point structure, and pass those addresses to the SDL_GetMouseState function 
Amx = mousePtr 
Amy = mousePtr + sizeof(C_UINT32) 
function scanMouse_b(atom e) 
------------------------------------------------------------ 
sequence scanned = repeat(0, sizeof(SDL_Event)) 
integer event_type = peek_type(e, C_UINT32) 
integer mx, my, mouseState 
 
mouseState = SDL_GetMouseState(Amx,Amy) 
 
mx = peek4u(Amx) 
my = peek4u(Amy) 
 
printf(1, "%d     , %d     \n", {mx,my}) 
 
return eMouse 
end function 
 

And also note the use of ffi - I understand it so much better now, and much easier than before. You're not allowed to change it Greg.

Cheers

Chris

new topic     » goto parent     » topic index » view message » categorize

3. Re: SDL_GetMouseState - Solved

ChrisB said...

Hi,

yup, that idea works perfectly.

------------------------------------------------------------ 
--note these are decalared outside of the function, so don't need to keep recreating them 
atom mousePtr = allocate_struct(SDL_Point) 
atom Amx, Amy 
--this way - create and SDL_Point structure, and pass those addresses to the SDL_GetMouseState function 
Amx = mousePtr 
Amy = mousePtr + sizeof(C_UINT32) 
function scanMouse_b(atom e) 
------------------------------------------------------------ 
sequence scanned = repeat(0, sizeof(SDL_Event)) 
integer event_type = peek_type(e, C_UINT32) 
integer mx, my, mouseState 
 
mouseState = SDL_GetMouseState(Amx,Amy) 
 
mx = peek4u(Amx) 
my = peek4u(Amy) 
 
printf(1, "%d     , %d     \n", {mx,my}) 
 
return eMouse 
end function 
 

And also note the use of ffi - I understand it so much better now, and much easier than before. You're not allowed to change it Greg.

Cheers

Chris

That's great Chris! SDL is currently on 2.26.2, I think I have that version updated for the SDL2 wrapper. Hopefully Greg makes his return soon. Getting Euphoria up to date is important.

new topic     » goto parent     » topic index » view message » categorize

4. Re: SDL_GetMouseState - Solved

Hi Andy

Thankyou.

Just to let you know, I'm currently working my way through Lazyfoo's tutorial (up to 19, skipped a few, now working on 24), but along the way I've had to make some drastic changes to your library. Namely going through every file and changing the passing of a type (SDL_Rect) to the wrapped function to a pointer (to the SDL_Rect for instance), adding in directly accessing the SDL_Event union to find various bits and pieces of activity, adding in in the missing includes into SDL.e, and replacing the joystick functions with Mics (updated) joystick include (much much easier to use, and couldn't get the SDL libs to work), and SDL_mixer's function for sound with your SoLoud library (works very nicely thanks). Could have used fmod, but the license is a bit convoluted.

Please please please don't think I'm I'm putting down your not inconsiderable work to produce the wrappers, but the corrections I've made means I've got a (nearly) fully functional SDL wrapper now.

Taking this forward, I'm going to write a wrapper for this to make SDL use even easier, (harking back to Aku's Musubi for SDL1), and hopefully producing a game creation system that'll introduce Eu to new programmers. I'm going to call it EDL (Easy sDL), to move all the sound opening, sprite and graphic opening operations to the background, yet still maintaining the ability to use SDL in it's 'raw' form.

eg handle = EDL_openBackground("graphic.jpg")
EDL_bltBackground(handle)

and that's it your background will be displayed.

I'm also going to make a recommendation that SDL be included in the standard Euphoria distribution now, whether EDL is included or not, as let's face it SDL is the de facto graphic library for game creation and other gaphical stuff.

Cheers

Chris

new topic     » goto parent     » topic index » view message » categorize

5. Re: SDL_GetMouseState - Solved

ChrisB said...

Hi Andy

Thankyou.

Just to let you know, I'm currently working my way through Lazyfoo's tutorial (up to 19, skipped a few, now working on 24), but along the way I've had to make some drastic changes to your library. Namely going through every file and changing the passing of a type (SDL_Rect) to the wrapped function to a pointer (to the SDL_Rect for instance), adding in directly accessing the SDL_Event union to find various bits and pieces of activity, adding in in the missing includes into SDL.e, and replacing the joystick functions with Mics (updated) joystick include (much much easier to use, and couldn't get the SDL libs to work), and SDL_mixer's function for sound with your SoLoud library (works very nicely thanks). Could have used fmod, but the license is a bit convoluted.

Please please please don't think I'm I'm putting down your not inconsiderable work to produce the wrappers, but the corrections I've made means I've got a (nearly) fully functional SDL wrapper now.

Taking this forward, I'm going to write a wrapper for this to make SDL use even easier, (harking back to Aku's Musubi for SDL1), and hopefully producing a game creation system that'll introduce Eu to new programmers. I'm going to call it EDL (Easy sDL), to move all the sound opening, sprite and graphic opening operations to the background, yet still maintaining the ability to use SDL in it's 'raw' form.

eg handle = EDL_openBackground("graphic.jpg")
EDL_bltBackground(handle)

and that's it your background will be displayed.

I'm also going to make a recommendation that SDL be included in the standard Euphoria distribution now, whether EDL is included or not, as let's face it SDL is the de facto graphic library for game creation and other gaphical stuff.

Cheers

Chris

When I first wrote my SDL wrapper, I was using Euphoria 4.0.5. and there was no FFI library. Then I upgraded to Euphoria 4.1.0 beta 2 and was able to use some of the better features that version of Euphoria provided. Then here we are now and Greg wrote FFI for Euphoria. I used FFI to help with the structs in Euphoria. I'm not sure if you've noticed, but I did change the SDL wrapper of mine and update as I found better ways of wrapping functions and structs. You can view my changes on the github repo.

Though I am curious about your project. Do you have a repo where I can see it? I also like how you are making it easy to code.

new topic     » goto parent     » topic index » view message » categorize

6. Re: SDL_GetMouseState - Solved

Hi Andy, not as yet, I don't get on well with Github.

Once I've gone through a few more Lazyfoos, I'll send you a zip. I think the Lazyfoos make great introductions to SDL, and show just how close your library is to the C library. I have emailed him asking for permission, but have as yet received nothing, but as I have given him complete attribution, and am not actually using his work or claiming it as my own, I would hope he doesn't mind.

Cheers

Chris

new topic     » goto parent     » topic index » view message » categorize

7. Re: SDL_GetMouseState - Solved

ChrisB said...

Hi Andy, not as yet, I don't get on well with Github.

Once I've gone through a few more Lazyfoos, I'll send you a zip. I think the Lazyfoos make great introductions to SDL, and show just how close your library is to the C library. I have emailed him asking for permission, but have as yet received nothing, but as I have given him complete attribution, and am not actually using his work or claiming it as my own, I would hope he doesn't mind.

Cheers

Chris

Alrighty, sounds good, Chris.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu