Merge remote-tracking branch 'upstream/master'

develop
Mike Stewart 2012-02-28 09:16:46 -08:00
commit e117d8d98c
11 changed files with 298 additions and 73 deletions

@ -40,9 +40,11 @@ add_definitions(-DDFHACK_VERSION="${DFHACK_VERSION}")
IF(UNIX)
# put the lib into DF/hack
SET(DFHACK_LIBRARY_DESTINATION hack)
SET(DFHACK_EGGY_DESTINATION libs)
ELSE()
# windows is crap, therefore we can't do nice things with it. leave the libs on a nasty pile...
SET(DFHACK_LIBRARY_DESTINATION .)
SET(DFHACK_EGGY_DESTINATION .)
ENDIF()
# external tools will be installed here:
SET(DFHACK_BINARY_DESTINATION .)

@ -103,9 +103,6 @@ modules/World.cpp
modules/Graphic.cpp
)
SET(PROJECT_HDRS_LINUX
)
SET(PROJECT_HDRS_WINDOWS
include/wdirent.h
)
@ -113,18 +110,31 @@ include/wdirent.h
SET(PROJECT_SRCS_LINUX
Console-linux.cpp
Hooks-linux.cpp
PlugLoad-linux.cpp
Process-linux.cpp
)
SET(PROJECT_SRCS_WINDOWS
Console-windows.cpp
Hooks-windows.cpp
PlugLoad-windows.cpp
Process-windows.cpp
)
SET(PROJECT_SRCS_LINUX_EGG
Console-linux.cpp
Hooks-egg.cpp
PlugLoad-linux.cpp
Process-linux.cpp
)
IF(UNIX)
LIST(APPEND PROJECT_HDRS ${PROJECT_HDRS_LINUX})
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_LINUX})
OPTION(BUILD_EGGY "Make DFHack strangely egg-shaped." OFF)
IF(BUILD_EGGY)
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_LINUX_EGG})
ELSE()
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_LINUX})
ENDIF()
ELSE()
LIST(APPEND PROJECT_HDRS ${PROJECT_HDRS_WINDOWS})
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_WINDOWS})
@ -174,9 +184,13 @@ ENDIF()
ADD_LIBRARY(dfhack SHARED ${PROJECT_SRCS})
ADD_DEPENDENCIES(dfhack generate_headers)
IF(WIN32)
SET_TARGET_PROPERTIES(dfhack PROPERTIES OUTPUT_NAME "SDL" )
ENDIF()
IF(BUILD_EGGY)
SET_TARGET_PROPERTIES(dfhack PROPERTIES OUTPUT_NAME "egg" )
else()
IF(WIN32)
SET_TARGET_PROPERTIES(dfhack PROPERTIES OUTPUT_NAME "SDL" )
ENDIF()
endif()
#effectively disables debug builds...
SET_TARGET_PROPERTIES(dfhack PROPERTIES DEBUG_POSTFIX "-debug" )
@ -188,15 +202,23 @@ IF(UNIX)
install(PROGRAMS ${dfhack_SOURCE_DIR}/package/linux/dfhack
DESTINATION .)
ELSE()
# On windows, copy the renamed SDL so DF can still run.
install(PROGRAMS ${dfhack_SOURCE_DIR}/package/windows/SDLreal.dll
DESTINATION ${DFHACK_LIBRARY_DESTINATION})
if(NOT BUILD_EGGY)
# On windows, copy the renamed SDL so DF can still run.
install(PROGRAMS ${dfhack_SOURCE_DIR}/package/windows/SDLreal.dll
DESTINATION ${DFHACK_LIBRARY_DESTINATION})
endif()
ENDIF()
#install the main lib
install(TARGETS dfhack
LIBRARY DESTINATION ${DFHACK_LIBRARY_DESTINATION}
RUNTIME DESTINATION ${DFHACK_LIBRARY_DESTINATION})
if(NOT BUILD_EGGY)
install(TARGETS dfhack
LIBRARY DESTINATION ${DFHACK_LIBRARY_DESTINATION}
RUNTIME DESTINATION ${DFHACK_LIBRARY_DESTINATION})
else()
install(TARGETS dfhack
LIBRARY DESTINATION ${DFHACK_EGGY_DESTINATION}
RUNTIME DESTINATION ${DFHACK_EGGY_DESTINATION})
endif()
#install the offset file
install(FILES xml/symbols.xml
DESTINATION ${DFHACK_DATA_DESTINATION}) #linux: share/dfhack
@ -204,6 +226,7 @@ install(FILES xml/symbols.xml
install(FILES ../dfhack.init-example
DESTINATION ${DFHACK_BINARY_DESTINATION})
# Unused for so long that it's not even relevant now...
if(BUILD_DEVEL)
if(WIN32)
install(TARGETS dfhack

@ -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()
{
@ -851,6 +858,7 @@ int Core::Shutdown ( void )
return -1;
}
// FIXME: this is HORRIBLY broken
// from ncurses
#define KEY_F0 0410 /* Function keys. Space for 64 */
#define KEY_F(n) (KEY_F0+(n)) /* Value of function key n */
@ -887,12 +895,13 @@ bool Core::ncurses_wgetch(int in, int & out)
return true;
}
int Core::SDL_Event(SDL::Event* ev, int orig_return)
//MEMO: return false if event is consumed
int Core::SDL_Event(SDL::Event* ev)
{
// do NOT process events before we are ready.
if(!started) return orig_return;
if(!started) return true;
if(!ev)
return orig_return;
return true;
if(ev && ev->type == SDL::ET_KEYDOWN || ev->type == SDL::ET_KEYUP)
{
SDL::KeyboardEvent * ke = (SDL::KeyboardEvent *)ev;
@ -913,7 +922,7 @@ int Core::SDL_Event(SDL::Event* ev, int orig_return)
hotkey_states[ke->ksym.sym] = false;
}
}
return orig_return;
return true;
// do stuff with the events...
}

@ -0,0 +1,92 @@
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <string>
#include <map>
#include "Core.h"
#include "Hooks.h"
#include <iostream>
// hook - called before rendering
DFhackCExport int egg_init(void)
{
// reroute stderr
freopen("stderr.log", "w", stderr);
// we don't reroute stdout until we figure out if this should be done at all
// See: Console-linux.cpp
fprintf(stderr,"dfhack: hooking successful\n");
return true;
}
// hook - called before rendering
DFhackCExport int egg_shutdown(void)
{
DFHack::Core & c = DFHack::Core::getInstance();
return c.Shutdown();
}
// hook - called for each game tick (or more often)
DFhackCExport int egg_tick(void)
{
DFHack::Core & c = DFHack::Core::getInstance();
return c.Update();
}
// hook - called before rendering
DFhackCExport int egg_prerender(void)
{
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
DFhackCExport int egg_sdl_event(SDL::Event* event)
{
// if the event is valid, intercept
if( event != 0 )
{
DFHack::Core & c = DFHack::Core::getInstance();
return c.SDL_Event(event);
}
return true;
}
// return this if you want to kill the event.
const int curses_error = -1;
// hook - ncurses event, -1 signifies error.
DFhackCExport int egg_curses_event(int orig_return)
{
/*
if(orig_return != -1)
{
DFHack::Core & c = DFHack::Core::getInstance();
int out;
return c.ncurses_wgetch(orig_return,);
}*/
return orig_return;
}

@ -43,31 +43,6 @@ distribution.
#include "Hooks.h"
#include <iostream>
/*
* Plugin loading functions
*/
namespace DFHack
{
DFLibrary * OpenPlugin (const char * filename)
{
dlerror();
DFLibrary * ret = (DFLibrary *) dlopen(filename, RTLD_NOW);
if(!ret)
{
std::cerr << dlerror() << std::endl;
}
return ret;
}
void * LookupPlugin (DFLibrary * plugin ,const char * function)
{
return (DFLibrary *) dlsym((void *)plugin, function);
}
void ClosePlugin (DFLibrary * plugin)
{
dlclose((void *) plugin);
}
}
/*******************************************************************************
* SDL part starts here *
*******************************************************************************/
@ -94,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;
}

@ -35,24 +35,6 @@ distribution.
#include "tinythread.h"
#include "modules/Graphic.h"
/*
* Plugin loading functions
*/
namespace DFHack
{
DFLibrary * OpenPlugin (const char * filename)
{
return (DFLibrary *) LoadLibrary(filename);
}
void * LookupPlugin (DFLibrary * plugin ,const char * function)
{
return (void *) GetProcAddress((HMODULE)plugin, function);
}
void ClosePlugin (DFLibrary * plugin)
{
FreeLibrary((HMODULE) plugin);
}
}
/*************************************************************************/
// extremely boring wrappers beyond this point. Only fix when broken
@ -431,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;
}

@ -0,0 +1,44 @@
#include <stdio.h>
#include <dlfcn.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <vector>
#include <string>
#include <map>
#include "DFHack.h"
#include "Core.h"
#include "Hooks.h"
#include <iostream>
/*
* Plugin loading functions
*/
namespace DFHack
{
DFLibrary * OpenPlugin (const char * filename)
{
dlerror();
DFLibrary * ret = (DFLibrary *) dlopen(filename, RTLD_NOW);
if(!ret)
{
std::cerr << dlerror() << std::endl;
}
return ret;
}
void * LookupPlugin (DFLibrary * plugin ,const char * function)
{
return (DFLibrary *) dlsym((void *)plugin, function);
}
void ClosePlugin (DFLibrary * plugin)
{
dlclose((void *) plugin);
}
}

@ -0,0 +1,55 @@
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#define DFhackCExport extern "C" __declspec(dllexport)
#include <windows.h>
#include <stdint.h>
#include <vector>
#include <string>
#include "Core.h"
#include "Hooks.h"
#include <stdio.h>
#include "tinythread.h"
#include "modules/Graphic.h"
/*
* Plugin loading functions
*/
namespace DFHack
{
DFLibrary * OpenPlugin (const char * filename)
{
return (DFLibrary *) LoadLibrary(filename);
}
void * LookupPlugin (DFLibrary * plugin ,const char * function)
{
return (void *) GetProcAddress((HMODULE)plugin, function);
}
void ClosePlugin (DFLibrary * plugin)
{
FreeLibrary((HMODULE) plugin);
}
}

@ -77,6 +77,12 @@ namespace DFHack
friend int ::SDL_PollEvent(SDL::Event *);
friend int ::SDL_Init(uint32_t flags);
friend int ::wgetch(WINDOW * w);
friend int ::egg_init(void);
friend int ::egg_shutdown(void);
friend int ::egg_tick(void);
friend int ::egg_prerender(void);
friend int ::egg_sdl_event(SDL::Event* event);
friend int ::egg_curses_event(int orig_return);
public:
/// Get the single Core instance or make one.
static Core& getInstance()
@ -125,9 +131,10 @@ namespace DFHack
private:
Core();
bool Init();
int Update (void);
int Update (void);
int TileUpdate (void);
int Shutdown (void);
int SDL_Event(SDL::Event* event, int orig_return);
int SDL_Event(SDL::Event* event);
bool ncurses_wgetch(int in, int & out);
Core(Core const&); // Don't Implement
void operator=(Core const&); // Don't implement

@ -50,3 +50,21 @@ DFhackCExport int SDL_PollEvent(SDL::Event* event);
DFhackCExport int SDL_Init(uint32_t flags);
DFhackCExport int wgetch(WINDOW * win);
// hook - called early from DF's main()
DFhackCExport int egg_init(void);
// hook - called before rendering
DFhackCExport int egg_shutdown(void);
// hook - called for each game tick (or more often)
DFhackCExport int egg_tick(void);
// hook - called before rendering
DFhackCExport int egg_prerender(void);
// hook - called for each SDL event, can filter both the event and the return value
DFhackCExport int egg_sdl_event(SDL::Event* event);
// hook - ncurses event. return -1 to consume
DFhackCExport int egg_curses_event(int orig_return);

@ -0,0 +1,7 @@
#!/bin/sh
DF_DIR=$(dirname "$0")
cd "${DF_DIR}"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"./stonesense/deplibs":"./hack/deplibs"
export SDL_DISABLE_LOCK_KEYS=1 # Work around for bug in Debian/Ubuntu SDL patch.
#export SDL_VIDEO_CENTERED=1 # Centre the screen. Messes up resizing.
./libs/Dwarf_Fortress $* # Go, go, go! :)