Re: SDL Event Help

new topic     » goto parent     » topic index » view thread      » older message » newer message
Icy_Viking said...

As I'm getting my updated SDL2 wrapper ready, I'm having a bit of trouble with even functions. Perhaps a fresh pair of eyes can help me out.

Icy_Viking said...
ChrisB said...

SDL_pollevent returns the pointer to the SDL_Event, and out of that you want to retrieve SDL_Event.type, and if that's SDL_QUIT then quit. Luckily it looks like it's the first element of the union, so just retrieve that! Simple (?!)

Thanks Chris. However I think the issue is from trying to assign the sequence value(event) to an atom value(SDL_QUIT). There is probably a work-around or something I'm missing, I just haven't figured it out, yet. You're on the right track though, I'm basiclly trying to convert that C code to Eu code.

There are two things going on here:

1. You are mixing structure values and pointers. The SDL event functions use the parameter SDL_Event * event which indicates a pointer to an SDL_Event struct. I had added allocate_struct() and peek_struct()/poke_struct() to help with this.

2. You have declared SDL_Event as a structure but it is actually a union. I have not added any support for unions at this time. I'm considering renaming define_c_type() to define_c_struct() and then add define_c_union() but this is still TBD.

The difference between structures and unions is that structures are a sequential set of unique values (one after the other offset by their size) while unions are a collapsed set of potential values (one value with several possible interpretations). The size of a structure is the sum of all its sizes but the size of a union is simply the largest size of any of its members. So there aren't thirty members to SDL_Event, there's only one but it could be any of the thirty listed.

This is a great example of why this is all still in the prototyping phase. I'm not able to come up with and test all of the potential uses for FFI but you're running it through several trials and when it fails, we can pivot accordingly before anything becomes to permanent. At this point we need go back and to rethink how to declare and differentiate structures from unions. I'd also like to make accessing structure members easier so we're not left with just referencing members as foo[1], etc.

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu