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

Search



Quick Links

User menu

Not signed in.

Misc Menu