Fix normal hooks.

develop
Petr Mrázek 2012-02-28 12:59:02 +01:00
parent 731472a478
commit 95ac3db542
5 changed files with 33 additions and 12 deletions

@ -56,6 +56,7 @@ using namespace DFHack;
#include "df/world_data.h" #include "df/world_data.h"
#include "df/interface.h" #include "df/interface.h"
#include "df/viewscreen_dwarfmodest.h" #include "df/viewscreen_dwarfmodest.h"
#include <df/graphic.h>
#include <stdio.h> #include <stdio.h>
#include <iomanip> #include <iomanip>
@ -771,6 +772,12 @@ void Core::Resume()
AccessMutex->unlock(); AccessMutex->unlock();
} }
int Core::TileUpdate()
{
//df::global::gps->;
return true;
}
// should always be from simulation thread! // should always be from simulation thread!
int Core::Update() int Core::Update()
{ {
@ -888,6 +895,7 @@ bool Core::ncurses_wgetch(int in, int & out)
return true; return true;
} }
//MEMO: return false if event is consumed
int Core::SDL_Event(SDL::Event* ev) int Core::SDL_Event(SDL::Event* ev)
{ {
// do NOT process events before we are ready. // do NOT process events before we are ready.

@ -60,7 +60,8 @@ DFhackCExport int egg_tick(void)
// hook - called before rendering // hook - called before rendering
DFhackCExport int egg_prerender(void) 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 // hook - called for each SDL event, returns 0 when the event has been consumed. 1 otherwise

@ -69,12 +69,18 @@ DFhackCExport void SDL_Quit(void)
static int (*_SDL_PollEvent)(SDL::Event* event) = 0; static int (*_SDL_PollEvent)(SDL::Event* event) = 0;
DFhackCExport int SDL_PollEvent(SDL::Event* event) 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); int orig_return = _SDL_PollEvent(event);
// if the event is valid, intercept if(!orig_return)
if( event != 0 ) return 0;
// otherwise we have an event to filter
else if( event != 0 )
{ {
DFHack::Core & c = DFHack::Core::getInstance(); 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; return orig_return;
} }

@ -413,17 +413,22 @@ DFhackCExport uint8_t * SDL_GetKeyState(int* numkeys)
return _SDL_GetKeyState(numkeys); return _SDL_GetKeyState(numkeys);
} }
static int (*_SDL_PollEvent)(SDL::Event *) = 0; // called by DF to check input events
DFhackCExport int SDL_PollEvent(SDL::Event * event) 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); int orig_return = _SDL_PollEvent(event);
// only send events to Core after we get first SDL_NumJoysticks call if(!orig_return)
// DF event loop is possibly polling for SDL events before things get inited properly return 0;
// SDL handles it. We don't, because we use some other parts of SDL too. // otherwise we have an event to filter
if(event != 0) else if( event != 0 )
{ {
DFHack::Core & c = DFHack::Core::getInstance(); 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; return orig_return;
} }

@ -131,7 +131,8 @@ namespace DFHack
private: private:
Core(); Core();
bool Init(); bool Init();
int Update (void); int Update (void);
int TileUpdate (void);
int Shutdown (void); int Shutdown (void);
int SDL_Event(SDL::Event* event); int SDL_Event(SDL::Event* event);
bool ncurses_wgetch(int in, int & out); bool ncurses_wgetch(int in, int & out);