diff --git a/CMakeLists.txt b/CMakeLists.txt index dbf44e847..4a5d6534b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ include_directories (${CMAKE_SOURCE_DIR}/dfhack/depends/argstream/) add_subdirectory (dfhack) #add_subdirectory (dfhack/python) -#add_subdirectory (dfhack/shm) +add_subdirectory (dfhack/shm) #FIXME: add exports for MSVC #add_subdirectory (dfhack/depends/md5) #add_subdirectory (dfhack/depends/tinyxml) diff --git a/dfhack/modules/Creatures.cpp b/dfhack/modules/Creatures.cpp index 98fecb8a6..81bbef4c3 100644 --- a/dfhack/modules/Creatures.cpp +++ b/dfhack/modules/Creatures.cpp @@ -111,6 +111,7 @@ Creatures::Creatures(DFContextPrivate* _d) creatures.name_words_offset = minfo->getOffset("name_words"); d->dwarf_race_index_addr = minfo->getAddress("dwarf_race_index"); d->dwarf_civ_id_addr = minfo->getAddress("dwarf_civ_id"); + /* // upload offsets to the SHM if(p->getModuleIndex("Creatures2010",1,d->creature_module)) { @@ -119,6 +120,7 @@ Creatures::Creatures(DFContextPrivate* _d) const uint32_t cmd = Creatures2010::CREATURE_INIT + (d->creature_module << 16); p->SetAndWait(cmd); } + */ d->Inited = true; } catch (Error::MissingMemoryDefinition&) @@ -158,6 +160,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball) if(!d->Started) return false; // SHM fast path Process * p = d->owner; + /* if(d->creature_module) { SHMCREATURESHDR->index = index; @@ -166,7 +169,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball) memcpy(&furball,SHMDATA(t_creature),sizeof(t_creature)); return true; } - + */ // non-SHM slow path memory_info * minfo = d->d->offset_descriptor; @@ -300,7 +303,7 @@ int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball, return -1; Process *p = d->owner; - + /* if(d->creature_module) { // supply the module with offsets so it can work with them @@ -317,7 +320,7 @@ int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball, memcpy(&furball,SHMDATA(void),sizeof(t_creature)); return SHMCREATURESHDR->index; } - else + else*/ { uint16_t coords[3]; uint32_t size = d->p_cre->size(); diff --git a/dfhack/shm/CMakeLists.txt b/dfhack/shm/CMakeLists.txt index 2638a7e89..83c3235f9 100644 --- a/dfhack/shm/CMakeLists.txt +++ b/dfhack/shm/CMakeLists.txt @@ -9,7 +9,7 @@ mod-maps.h SET(PROJECT_SRCS mod-core.cpp mod-maps.cpp -mod-creature40d.cpp +#mod-creature40d.cpp ) SET(PROJECT_HDRS_LINUX @@ -39,7 +39,7 @@ SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE ) LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS}) -IF(CMAKE_SIZEOF_VOID_P EQUAL 4) +#IF(CMAKE_SIZEOF_VOID_P EQUAL 4) IF(UNIX) add_definitions(-DLINUX_BUILD) SET(PROJECT_LIBS rt) @@ -51,4 +51,4 @@ IF(CMAKE_SIZEOF_VOID_P EQUAL 4) ADD_LIBRARY(SDL SHARED ${PROJECT_SRCS}) TARGET_LINK_LIBRARIES(SDL ${PROJECT_LIBS}) ENDIF(UNIX) -ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4) +#ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4) diff --git a/dfhack/shm/mod-core.cpp b/dfhack/shm/mod-core.cpp index 6a4397d1f..467a7a590 100644 --- a/dfhack/shm/mod-core.cpp +++ b/dfhack/shm/mod-core.cpp @@ -27,7 +27,7 @@ distribution. */ #include -#include "../library/integers.h" +#include "../include/integers.h" #include #include #include @@ -247,8 +247,8 @@ void InitModules (void) { // create the core module module_registry.push_back(InitCore()); - module_registry.push_back(DFHack::Maps::Init()); - module_registry.push_back(DFHack::Creatures::Init()); + module_registry.push_back(DFHack::Server::Maps::Init()); + //module_registry.push_back(DFHack::Server::Creatures::Init()); for(int i = 0; i < module_registry.size();i++) { fprintf(stderr,"Initialized module %s, version %d\n",module_registry[i].name.c_str(),module_registry[i].version); diff --git a/dfhack/shm/mod-creature40d.cpp b/dfhack/shm/mod-creature40d.cpp index 35b17b57f..f968483f8 100644 --- a/dfhack/shm/mod-creature40d.cpp +++ b/dfhack/shm/mod-creature40d.cpp @@ -6,6 +6,7 @@ #include "mod-core.h" #include "mod-creature40d.h" #include +#include #include #include @@ -14,7 +15,9 @@ extern char *shm; -namespace DFHack{ namespace Creatures{ // start of namespace +namespace DFHack{ + namespace Server{ + namespace Creatures{ // start of namespace #define SHMHDR ((shm_creature_hdr *)shm) #define SHMDATA(type) ((type *)(shm + SHM_HEADER)) @@ -191,4 +194,4 @@ DFPP_module Init( void ) return creatures; } -}} // end of namespace +}}} // end of namespace diff --git a/dfhack/shm/mod-maps.cpp b/dfhack/shm/mod-maps.cpp index dd00d2fb1..3e79d487e 100644 --- a/dfhack/shm/mod-maps.cpp +++ b/dfhack/shm/mod-maps.cpp @@ -1,13 +1,15 @@ #include #include +#include #include #include "shms.h" #include "mod-core.h" #include "mod-maps.h" #include +#include using namespace DFHack; -using namespace DFHack::Maps; +using namespace DFHack::Server::Maps; #include #include @@ -17,7 +19,9 @@ extern char *shm; //TODO: circular buffer streaming primitives required //TODO: commands can fail without the proper offsets. Hot to handle that? -namespace DFHack{ namespace Maps{ // start of namespace +namespace DFHack{ + namespace Server{ // start of namespace + namespace Maps{ // start of namespace #define SHMHDR ((shm_maps_hdr *)shm) #define SHMCMD ((shm_cmd *)shm)->pingpong @@ -68,7 +72,10 @@ inline void ReadBlockByAddress (void * data) memcpy(&(SHMDATA(mapblock40d)->biome_indices), ((char *) block) + offsets.biome_stuffs, sizeof(SHMDATA(mapblock40d)->biome_indices)); SHMDATA(mapblock40d)->blockflags.whole = *block->ptr_to_dirty; - SHMDATA(mapblock40d)->origin = (uint32_t)block; + SHMDATA(mapblock40d)->local_feature = *(int16_t *)((char*) block + offsets.local_feature_offset); + SHMDATA(mapblock40d)->global_feature = *(int16_t *)((char*) block + offsets.global_feature_offset); + + SHMDATA(mapblock40d)->origin = (uint32_t)(uint64_t)block; // this is STUPID SHMHDR->error = false; } else @@ -90,7 +97,7 @@ void ReadBlockByCoords (void * data) only Z blocks can have NULL pointers? TODO: verify */ mblock * *** mapArray = *(mblock * ****)offsets.map_offset; - SHMHDR->address = (uint32_t) mapArray[SHMHDR->x][SHMHDR->y][SHMHDR->z]; + SHMHDR->address = (uint32_t) (uint64_t) mapArray[SHMHDR->x][SHMHDR->y][SHMHDR->z];// this is STUPID ReadBlockByAddress(data); // I wonder... will this inline properly? } @@ -120,4 +127,4 @@ DFPP_module Init( void ) return maps; } -}} // end of namespace +}}} // end of namespace