Changes between Initial Version and Version 1 of Develop/Drafts/EventDrivenInputSystem


Ignore:
Timestamp:
Oct 8, 2016, 5:08:54 PM (7 years ago)
Author:
pulkomandy
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Develop/Drafts/EventDrivenInputSystem

    v1 v1  
     1= Introduction =
     2
     3The current input system in GrafX2 uses a polling scheme like it was done in the DOS days. This worked fine at the time, but it nows feel a bit limitating. This page gathers ideas and technical solutions to improve that and get something better. Objectives include :
     4  * Don't block the mouse even when the program is really busy with something (like 24bit image color reduction)
     5  * Don't have the mouse cursor lag behind even if there is an expensive drawing op running
     6  * Allow for some multitasking so the mouse can still move while playing an animation at a constant framerate
     7
     8
     9= Details =
     10The main idea is to replace SDL_PollEvent with SDL_WaitEvent in get_input. This allows to make the function block and exit only when there is an usefull event, without any "busy waiting" on our side. Less CPU usage, less code, everyone is happy. However this has one drawback : the blocking function will make things like airbrush not work if you don't move the mouse.
     11
     12To avoid that, we need a new event created by software to be generated at a constant rate a bit like a VBL retrace interrupt (without the VBL retrace). This can be done with an SDL timer sending an SDL_PushEvent. The timer could also call some other functions directly for high-precision asynchronous timed things like playing an animation.
     13
     14= Mouse cursor thread =
     15Have a thread handle mouse cursor movements. It can take care of merging mouse events if needed/wanted, displaying only the cursor, and let the current operation draw the heavy things below.
     16Need to be really carefull to not allow muliple operation to be started at the same time.
     17This thread can also poll the keyboard and be used to add a shortcut to undo a long running operation (like rendering of a distortion for an animation once you see it's going to look really wrong and want to change it anyway).
     18
     19= Heavy multithreading =
     20Add support for multiple thread to use the full power of modern multicore computers. For example 24-bit color reduction could benefit from that and be made about twice as fast (both palette generation (only the cluster list needs locking) and image reduction (no locking needed if the threads work on different parts of the picture).
     21It needs proper locking on screen access for some things however, like any threading (also applies for the mouse thread). So beware. Excessive locking will make it not-so-usefull.
     22
     23Lua scripts could also run from threads (only one script at a time as the Lua interpreter is not fully safe, I fear) and do thing in realtime for an animation, for example (like altering the pixel data).
     24
     25= Event locking =
     26Instead of calling get_input explicitly, everything could just block on a semaphore or a condition variable that would be released when an event occurs. Same apply for the "Wait_VBL"-synced things. It avoid playing with getticks and all this stuff. Everyone would lock on a condition variable, then the "VBL" timer would send a global signal to tell them to go ahead.
     27
     28= SDL support =
     29SDL provides timers, threads, semaphores, and all that stuff. So all of this can be done in a proper portable way.