VOGONS


Reply 21 of 39, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

> but this code makes the keyboard freak out and doesn't help smoothing CPU usage

I missed that SDL_EventState does the mask-generation already, so
the SDL_JOYEVENTMASK should be replaced by
SDL_JOYAXISMOTION | SDL_JOYBALLMOTION | SDL_JOYHATMOTION | SDL_JOYBUTTONDOWN | SDL_JOYBUTTONUP

Reply 22 of 39, by h-a-l-9000

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Nope, doesn't work.
Neither does

SDL_EventState(
SDL_EVENTMASK(SDL_JOYAXISMOTION) |
SDL_EVENTMASK(SDL_JOYBALLMOTION) |
SDL_EVENTMASK(SDL_JOYHATMOTION) |
SDL_EVENTMASK(SDL_JOYBUTTONDOWN) |
SDL_EVENTMASK(SDL_JOYBUTTONUP),
SDL_ENABLE);

nor

SDL_EventState(SDL_JOYAXISMOTION,SDL_ENABLE);
SDL_EventState(SDL_JOYBALLMOTION,SDL_ENABLE);
SDL_EventState(SDL_JOYHATMOTION,SDL_ENABLE);
SDL_EventState(SDL_JOYBUTTONDOWN,SDL_ENABLE);
SDL_EventState(SDL_JOYBUTTONUP,SDL_ENABLE);

1+1=10

Reply 23 of 39, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Dunno then, don't have an analog joystick to test.
Does the keyboard work at least (in the 2nd version you posted,
the first one does the same bad thing as my first code snippet).

Reply 25 of 39, by ykhwong

User metadata
Rank Oldbie
Rank
Oldbie

Does this code work?

--- ./src/gui/sdlmain.cpp	Fri Jul  7 16:07:56 2006
+++ ./src/gui/sdlmain.cpp Fri Jul 7 16:06:24 2006
@@ -1646,8 +1646,12 @@
static Bit8u laltstate = SDL_KEYUP;
static Bit8u raltstate = SDL_KEYUP;

+int poll_delay=0;
+
void GFX_Events() {
SDL_Event event;
+ int time=SDL_GetTicks();
+
while (SDL_PollEvent(&event)) {
switch (event.type) {
#ifdef WIN32
@@ -1929,6 +1935,15 @@
}
}
break;
+ case SDL_JOYAXISMOTION:
+ case SDL_JOYBALLMOTION:
+ case SDL_JOYHATMOTION:
+ case SDL_JOYBUTTONDOWN:
+ case SDL_JOYBUTTONUP:
+ if (time-poll_delay>20) {
+ SDL_EventState(SDL_EVENTMASK(SDL_JOYAXISMOTION) | SDL_EVENTMASK(SDL_JOYBALLMOTION) | SDL_EVENTMASK(SDL_JOYHATMOTION) | SDL_EVENTMASK(SDL_JOYBUTTONDOWN) | SDL_EVENTMASK(SDL_JOYBUTTONUP),SDL_ENABLE);
+ } else SDL_EventState(SDL_EVENTMASK(SDL_JOYAXISMOTION) | SDL_EVENTMASK(SDL_JOYBALLMOTION) | SDL_EVENTMASK(SDL_JOYHATMOTION) | SDL_EVENTMASK(SDL_JOYBUTTONDOWN) | SDL_EVENTMASK(SDL_JOYBUTTONUP),SDL_IGNORE);
+ break;
case SDL_MOUSEMOTION:
HandleMouseMotion(&event.motion);
break;

Reply 27 of 39, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

> Does this code work?

Well you're effectively kicking out the joystick, as it is only re-enabled in
the (not anymore called) SDL_JOYxyz events.

> no, keys are rarely recognized

That's really odd. Could be that they're flushing the event queue when
calling SDL_EventState, so maybe we shouldn't call the ENABLE that
often but only once.

Reply 28 of 39, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

That is like the following:

static int poll_delay=0;
static bool poll_ignoring=false;

...

and at the end (!) of GFX_Events() :

	int time=SDL_GetTicks();
if (time-poll_delay>20) {
poll_delay=time;
SDL_EventState(SDL_JOYAXISMOTION | SDL_JOYBALLMOTION | SDL_JOYHATMOTION | SDL_JOYBUTTONDOWN | SDL_JOYBUTTONUP, SDL_ENABLE);
poll_ignoring=false;
} else {
if (!poll_ignoring) {
poll_ignoring=true;
SDL_EventState(SDL_JOYAXISMOTION | SDL_JOYBALLMOTION | SDL_JOYHATMOTION | SDL_JOYBUTTONDOWN | SDL_JOYBUTTONUP, SDL_IGNORE);
}
}

Seems to work (keyboard-wise) though it might still loose keys. The modified
sdl.dll might still be the preferred option.

Reply 29 of 39, by h-a-l-9000

User metadata
Rank DOSBox Author
Rank
DOSBox Author

It doesn't help the joystick.
There is something strange about this SDL stuff...
SDL_JOYAXISMOTION is defined as 8, SDL_JOYBALLMOTION as 9 and so on.
ORing all these constants does not really make sense to me. They overlap. But also SDL_EVENTMASK(SDL_JOYAXISMOTION) does not work (SDL_EVENTMASK(x) is defined as 1<<x) because SDL_EventState only takes uint8 as first parameter and 1<<8 is too big.

1+1=10

Reply 31 of 39, by h-a-l-9000

User metadata
Rank DOSBox Author
Rank
DOSBox Author

That helps the CPU usage, but input (joy and key) behaves really bad now. Joystick keeps moving, buttons don't always respond and the same with the keyboard keys.
It's worse on a slower computer.

1+1=10

Reply 32 of 39, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Yes, as i said the clearing of the event buffer in SDL_EventState() is pretty
bad (that's why i always tried the oring of events...) thus my idea is not
really usefull. Guess the SDL_EventState() function should be called only
once at program start, and not repeatedly.

Reply 33 of 39, by h-a-l-9000

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Hmm interesting comment.

/*
* Enable/disable joystick event polling.
* If joystick events are disabled, you must call SDL_JoystickUpdate()
* yourself and check the state of the joystick when you want joystick
* information.
* The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE.
*/
extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);

1+1=10

Reply 37 of 39, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

well we can just do that on a joystick port write (or the bios call)

That way we are really the same as a pc.

Water flows down the stream
How to ask questions the smart way!

Reply 39 of 39, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

well the remapping of joysticks is currently not supported.
It was the diea, but we still have to figure out some sort of directional feeling as well when mapping it to the keyboard.
Maybe with some define or so.

Water flows down the stream
How to ask questions the smart way!