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/interface.h"
#include "df/viewscreen_dwarfmodest.h"
#include <df/graphic.h>
#include <stdio.h>
#include <iomanip>
@ -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.

@ -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

@ -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;
}

@ -413,17 +413,22 @@ DFhackCExport uint8_t * SDL_GetKeyState(int* numkeys)
return _SDL_GetKeyState(numkeys);
}
static int (*_SDL_PollEvent)(SDL::Event *) = 0;
// 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;
}

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