diff --git a/CMakeLists.txt b/CMakeLists.txt index da91da79b..f5fb83b31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 .) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 428c3f498..3f672eba9 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -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 diff --git a/library/Core.cpp b/library/Core.cpp index 4b58cf49a..1d577bfb2 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -851,6 +851,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 +888,12 @@ bool Core::ncurses_wgetch(int in, int & out) return true; } -int Core::SDL_Event(SDL::Event* ev, int orig_return) +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 +914,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... } diff --git a/library/Hooks-egg.cpp b/library/Hooks-egg.cpp new file mode 100644 index 000000000..34b31d225 --- /dev/null +++ b/library/Hooks-egg.cpp @@ -0,0 +1,91 @@ +/* +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 +#include +#include +#include +#include +#include +#include + +#include "Core.h" +#include "Hooks.h" +#include + +// 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) +{ + return true; +} + +// 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; +} diff --git a/library/Hooks-linux.cpp b/library/Hooks-linux.cpp index 69bb9f228..9ceeeff60 100644 --- a/library/Hooks-linux.cpp +++ b/library/Hooks-linux.cpp @@ -43,31 +43,6 @@ distribution. #include "Hooks.h" #include -/* - * 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 * *******************************************************************************/ diff --git a/library/Hooks-windows.cpp b/library/Hooks-windows.cpp index da95f395b..920673c9b 100644 --- a/library/Hooks-windows.cpp +++ b/library/Hooks-windows.cpp @@ -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 diff --git a/library/PlugLoad-linux.cpp b/library/PlugLoad-linux.cpp new file mode 100644 index 000000000..aaf7b2c33 --- /dev/null +++ b/library/PlugLoad-linux.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "DFHack.h" +#include "Core.h" +#include "Hooks.h" +#include + +/* + * 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); + } +} \ No newline at end of file diff --git a/library/PlugLoad-windows.cpp b/library/PlugLoad-windows.cpp new file mode 100644 index 000000000..eadc9343d --- /dev/null +++ b/library/PlugLoad-windows.cpp @@ -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 +#include +#include +#include +#include "Core.h" +#include "Hooks.h" +#include + +#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); + } +} \ No newline at end of file diff --git a/library/include/Core.h b/library/include/Core.h index 74a47387f..0b5423de7 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -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() @@ -127,7 +133,7 @@ namespace DFHack bool Init(); int Update (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 diff --git a/library/include/Hooks.h b/library/include/Hooks.h index f01d58c07..418a5ce3b 100644 --- a/library/include/Hooks.h +++ b/library/include/Hooks.h @@ -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); + diff --git a/package/linux/egghack b/package/linux/egghack new file mode 100755 index 000000000..1ce583ceb --- /dev/null +++ b/package/linux/egghack @@ -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! :)