Removed Device struct from controller device

This commit is contained in:
Devine Lu Linvega 2023-01-01 11:37:34 -08:00
parent 062bbac37d
commit 9aefeebf25
3 changed files with 23 additions and 36 deletions

View File

@ -2,8 +2,7 @@
#include "controller.h" #include "controller.h"
/* /*
Copyright (c) 2021 Devine Lu Linvega Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick
Copyright (c) 2021 Andrew Alderwick
Permission to use, copy, modify, and distribute this software for any Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -14,39 +13,29 @@ WITH REGARD TO THIS SOFTWARE.
*/ */
void void
controller_down(Device *d, Uint8 mask) controller_down(Uxn *u, Uint8 *d, Uint8 mask)
{ {
if(mask) { if(mask) {
d->dat[2] |= mask; d[2] |= mask;
uxn_eval(d->u, GETVECTOR(d)); uxn_eval(u, GETVEC(d));
} }
} }
void void
controller_up(Device *d, Uint8 mask) controller_up(Uxn *u, Uint8 *d, Uint8 mask)
{ {
if(mask) { if(mask) {
d->dat[2] &= (~mask); d[2] &= (~mask);
uxn_eval(d->u, GETVECTOR(d)); uxn_eval(u, GETVEC(d));
} }
} }
void void
controller_key(Device *d, Uint8 key) controller_key(Uxn *u, Uint8 *d, Uint8 key)
{ {
if(key) { if(key) {
d->dat[3] = key; d[3] = key;
uxn_eval(d->u, GETVECTOR(d)); uxn_eval(u, GETVEC(d));
d->dat[3] = 0x00; d[3] = 0x00;
}
}
void
controller_special(Device *d, Uint8 key)
{
if(key) {
d->dat[4] = key;
uxn_eval(d->u, GETVECTOR(d));
d->dat[4] = 0x00;
} }
} }

View File

@ -1,6 +1,5 @@
/* /*
Copyright (c) 2021 Devine Lu Linvega Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick
Copyright (c) 2021 Andrew Alderwick
Permission to use, copy, modify, and distribute this software for any Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -10,7 +9,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE. WITH REGARD TO THIS SOFTWARE.
*/ */
void controller_down(Device *d, Uint8 mask); void controller_down(Uxn *u, Uint8 *d, Uint8 mask);
void controller_up(Device *d, Uint8 mask); void controller_up(Uxn *u, Uint8 *d, Uint8 mask);
void controller_key(Device *d, Uint8 key); void controller_key(Uxn *u, Uint8 *d, Uint8 key);
void controller_special(Device *d, Uint8 key);

View File

@ -411,13 +411,13 @@ handle_events(Uxn *u)
mouse_scroll(u, devmouse->dat, event.wheel.x, event.wheel.y); mouse_scroll(u, devmouse->dat, event.wheel.x, event.wheel.y);
/* Controller */ /* Controller */
else if(event.type == SDL_TEXTINPUT) else if(event.type == SDL_TEXTINPUT)
controller_key(devctrl, event.text.text[0]); controller_key(u, devctrl->dat, event.text.text[0]);
else if(event.type == SDL_KEYDOWN) { else if(event.type == SDL_KEYDOWN) {
int ksym; int ksym;
if(get_key(&event)) if(get_key(&event))
controller_key(devctrl, get_key(&event)); controller_key(u, devctrl->dat, get_key(&event));
else if(get_button(&event)) else if(get_button(&event))
controller_down(devctrl, get_button(&event)); controller_down(u, devctrl->dat, get_button(&event));
else else
do_shortcut(u, &event); do_shortcut(u, &event);
ksym = event.key.keysym.sym; ksym = event.key.keysym.sym;
@ -425,17 +425,17 @@ handle_events(Uxn *u)
return 1; return 1;
} }
} else if(event.type == SDL_KEYUP) } else if(event.type == SDL_KEYUP)
controller_up(devctrl, get_button(&event)); controller_up(u, devctrl->dat, get_button(&event));
else if(event.type == SDL_JOYAXISMOTION) { else if(event.type == SDL_JOYAXISMOTION) {
Uint8 vec = get_vector_joystick(&event); Uint8 vec = get_vector_joystick(&event);
if(!vec) if(!vec)
controller_up(devctrl, (0x03 << (!event.jaxis.axis * 2)) << 4); controller_up(u, devctrl->dat, (0x03 << (!event.jaxis.axis * 2)) << 4);
else else
controller_down(devctrl, (0x01 << ((vec + !event.jaxis.axis * 2) - 1)) << 4); controller_down(u, devctrl->dat, (0x01 << ((vec + !event.jaxis.axis * 2) - 1)) << 4);
} else if(event.type == SDL_JOYBUTTONDOWN) } else if(event.type == SDL_JOYBUTTONDOWN)
controller_down(devctrl, get_button_joystick(&event)); controller_down(u, devctrl->dat, get_button_joystick(&event));
else if(event.type == SDL_JOYBUTTONUP) else if(event.type == SDL_JOYBUTTONUP)
controller_up(devctrl, get_button_joystick(&event)); controller_up(u, devctrl->dat, get_button_joystick(&event));
/* Console */ /* Console */
else if(event.type == stdin_event) else if(event.type == stdin_event)
console_input(u, event.cbutton.button); console_input(u, event.cbutton.button);