Revived the SHM. Seems to be working, but needs a fair bit of changes.

develop
Petr Mrázek 2010-05-24 03:07:13 +02:00
parent 7ed5350315
commit 5e65f5568b
6 changed files with 30 additions and 17 deletions

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

@ -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();

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

@ -27,7 +27,7 @@ distribution.
*/
#include <stdio.h>
#include "../library/integers.h"
#include "../include/integers.h"
#include <stdlib.h>
#include <string.h>
#include <string>
@ -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);

@ -6,6 +6,7 @@
#include "mod-core.h"
#include "mod-creature40d.h"
#include <DFTypes.h>
#include <modules/Creatures.h>
#include <string.h>
#include <malloc.h>
@ -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

@ -1,13 +1,15 @@
#include <string>
#include <vector>
#include <map>
#include <integers.h>
#include "shms.h"
#include "mod-core.h"
#include "mod-maps.h"
#include <DFTypes.h>
#include <modules/Maps.h>
using namespace DFHack;
using namespace DFHack::Maps;
using namespace DFHack::Server::Maps;
#include <string.h>
#include <malloc.h>
@ -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