diff --git a/library/Core.cpp b/library/Core.cpp index 1d577bfb2..859a8c348 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -56,6 +56,7 @@ using namespace DFHack; #include "df/world_data.h" #include "df/interface.h" #include "df/viewscreen_dwarfmodest.h" +#include #include #include @@ -771,6 +772,12 @@ void Core::Resume() AccessMutex->unlock(); } +int Core::TileUpdate() +{ + //df::global::gps->; + return true; +} + // should always be from simulation thread! int Core::Update() { @@ -888,6 +895,7 @@ bool Core::ncurses_wgetch(int in, int & out) return true; } +//MEMO: return false if event is consumed int Core::SDL_Event(SDL::Event* ev) { // do NOT process events before we are ready. diff --git a/library/Hooks-egg.cpp b/library/Hooks-egg.cpp index 34b31d225..e9b84cd06 100644 --- a/library/Hooks-egg.cpp +++ b/library/Hooks-egg.cpp @@ -60,7 +60,8 @@ DFhackCExport int egg_tick(void) // hook - called before rendering DFhackCExport int egg_prerender(void) { - return true; + DFHack::Core & c = DFHack::Core::getInstance(); + return c.TileUpdate(); } // hook - called for each SDL event, returns 0 when the event has been consumed. 1 otherwise diff --git a/library/Hooks-linux.cpp b/library/Hooks-linux.cpp index 9ceeeff60..aeb719b84 100644 --- a/library/Hooks-linux.cpp +++ b/library/Hooks-linux.cpp @@ -69,12 +69,18 @@ DFhackCExport void SDL_Quit(void) static int (*_SDL_PollEvent)(SDL::Event* event) = 0; DFhackCExport int SDL_PollEvent(SDL::Event* event) { + pollevent_again: + // if SDL returns 0 here, it means there are no more events. return 0 int orig_return = _SDL_PollEvent(event); - // if the event is valid, intercept - if( event != 0 ) + if(!orig_return) + return 0; + // otherwise we have an event to filter + else if( event != 0 ) { DFHack::Core & c = DFHack::Core::getInstance(); - return c.SDL_Event(event, orig_return); + // if we consume the event, ask SDL for more. + if(!c.SDL_Event(event)) + goto pollevent_again; } return orig_return; } diff --git a/library/Hooks-windows.cpp b/library/Hooks-windows.cpp index 920673c9b..c4e0f0a38 100644 --- a/library/Hooks-windows.cpp +++ b/library/Hooks-windows.cpp @@ -413,17 +413,22 @@ DFhackCExport uint8_t * SDL_GetKeyState(int* numkeys) return _SDL_GetKeyState(numkeys); } -static int (*_SDL_PollEvent)(SDL::Event *) = 0; -DFhackCExport int SDL_PollEvent(SDL::Event * event) +// called by DF to check input events +static int (*_SDL_PollEvent)(SDL::Event* event) = 0; +DFhackCExport int SDL_PollEvent(SDL::Event* event) { + pollevent_again: + // if SDL returns 0 here, it means there are no more events. return 0 int orig_return = _SDL_PollEvent(event); - // only send events to Core after we get first SDL_NumJoysticks call - // DF event loop is possibly polling for SDL events before things get inited properly - // SDL handles it. We don't, because we use some other parts of SDL too. - if(event != 0) + if(!orig_return) + return 0; + // otherwise we have an event to filter + else if( event != 0 ) { DFHack::Core & c = DFHack::Core::getInstance(); - return c.SDL_Event(event, orig_return); + // if we consume the event, ask SDL for more. + if(!c.SDL_Event(event)) + goto pollevent_again; } return orig_return; } diff --git a/library/include/Core.h b/library/include/Core.h index 0b5423de7..107dd2fce 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -131,7 +131,8 @@ namespace DFHack private: Core(); bool Init(); - int Update (void); + int Update (void); + int TileUpdate (void); int Shutdown (void); int SDL_Event(SDL::Event* event); bool ncurses_wgetch(int in, int & out);