summaryrefslogtreecommitdiff
path: root/MapLoading.cpp
diff options
context:
space:
mode:
authorJapa2011-07-20 15:59:11 +0000
committerJapa2011-07-20 15:59:11 +0000
commitaee9dc6758120d57a8fabc013a16c82f6682099c (patch)
tree7d2ddd6cabb61e948d5cd19f7838ab313ac1c6e9 /MapLoading.cpp
parent3eacec9eef6da5e6ce6f7d966a6b601f6268557c (diff)
downloadstonesense-aee9dc6758120d57a8fabc013a16c82f6682099c.tar.gz
stonesense-aee9dc6758120d57a8fabc013a16c82f6682099c.tar.bz2
stonesense-aee9dc6758120d57a8fabc013a16c82f6682099c.tar.xz
Got some sort of functionality out of DFapi. this means an empty window.
Diffstat (limited to 'MapLoading.cpp')
-rw-r--r--MapLoading.cpp273
1 files changed, 91 insertions, 182 deletions
diff --git a/MapLoading.cpp b/MapLoading.cpp
index b096f5e..692ea97 100644
--- a/MapLoading.cpp
+++ b/MapLoading.cpp
@@ -8,8 +8,7 @@
#include "Creatures.h"
#include "ContentLoader.h"
-static DFHack::Context* pDFApiHandle = 0;
-static DFHack::ContextManager* DFMgr = 0;
+static DFHack::Core* pDFApiHandle = 0;
static DFHack::Process * DFProc = 0;
const VersionInfo *dfMemoryInfo;
bool memInfoHasBeenRead;
@@ -23,7 +22,6 @@ struct segParams
int sizex;
int sizey;
int sizez;
- ALLEGRO_MUTEX * m_connection;
bool thread_connect;
bool is_connected;
} parms;
@@ -204,7 +202,7 @@ bool areNeighborsVisible(t_designation designations[16][16],int x,int y)
return false;
}
-void ReadCellToSegment(DFHack::Context& DF, WorldSegment& segment, int CellX, int CellY, int CellZ,
+void ReadCellToSegment(DFHack::Core& DF, WorldSegment& segment, int CellX, int CellY, int CellZ,
uint32_t BoundrySX, uint32_t BoundrySY,
uint32_t BoundryEX, uint32_t BoundryEY,
uint16_t Flags/*not in use*/,
@@ -219,15 +217,13 @@ void ReadCellToSegment(DFHack::Context& DF, WorldSegment& segment, int CellX, in
return;
//boundry check
- int celldimX, celldimY, celldimZ;
- Maps->getSize((unsigned int &)celldimX, (unsigned int &)celldimY, (unsigned int &)celldimZ);
- if( CellX < 0 || CellX >= celldimX ||
- CellY < 0 || CellY >= celldimY ||
- CellZ < 0 || CellZ >= celldimZ )
+ int cellDimX, cellDimY, cellDimZ;
+ Maps->getSize((unsigned int &)cellDimX, (unsigned int &)cellDimY, (unsigned int &)cellDimZ);
+ if( CellX < 0 || CellX >= cellDimX ||
+ CellY < 0 || CellY >= cellDimY ||
+ CellZ < 0 || CellZ >= cellDimZ )
return;
- if(!(DF.isSuspended()))
- DisplayErr("DF isn't suspended! something is very very wrong!");
- if(!Maps->isValidBlock(CellX, CellY, CellZ))
+ if(!Maps->getBlock(CellX, CellY, CellZ))
return;
@@ -245,22 +241,30 @@ void ReadCellToSegment(DFHack::Context& DF, WorldSegment& segment, int CellX, in
uint8_t regionoffsets[16];
t_temperatures temp1, temp2;
DFHack::mapblock40d mapBlock;
- std::vector<DFHack::dfh_plant> plants;
+ std::vector<df_plant *> * plants;
Maps->ReadTileTypes(CellX, CellY, CellZ, (tiletypes40d *) tiletypes);
Maps->ReadDesignations(CellX, CellY, CellZ, (designations40d *) designations);
Maps->ReadOccupancy(CellX, CellY, CellZ, (occupancies40d *) occupancies);
Maps->ReadRegionOffsets(CellX,CellY,CellZ, (biome_indices40d *)regionoffsets);
Maps->ReadTemperatures(CellX, CellY, CellZ, &temp1, &temp2);
Maps->ReadBlock40d(CellX, CellY, CellZ, &mapBlock);
- Maps->ReadVegetation(CellX, CellY, CellZ, &plants);
+ Maps->ReadVegetation(CellX, CellY, CellZ, plants);
//read local vein data
- vector <t_vein> veins;
- vector <t_frozenliquidvein> ices;
- vector <t_spattervein> splatter;
- vector <t_grassvein> grass;
+ vector <t_vein * > veins;
+ vector <t_frozenliquidvein * > ices;
+ vector <t_spattervein * > splatter;
+ vector <t_grassvein * > grass;
+ vector <t_worldconstruction * > worldconstructions;
+ Maps->SortBlockEvents(
+ CellX,
+ CellY,
+ CellZ,
+ &veins,
+ &ices,
+ &splatter,
+ &grass,
+ &worldconstructions);
-
- Maps->ReadVeins(CellX,CellY,CellZ,&veins,&ices,&splatter,&grass);
uint32_t numVeins = (uint32_t)veins.size();
//parse cell
@@ -296,10 +300,10 @@ void ReadCellToSegment(DFHack::Context& DF, WorldSegment& segment, int CellX, in
//b->grassmats.clear();
for(int i = 0; i < grass.size(); i++)
{
- if(grass[i].intensity[lx][ly] > 0 && b->grasslevel == 0)//b->grasslevel)
+ if(grass[i]->intensity[lx][ly] > 0 && b->grasslevel == 0)//b->grasslevel)
{
- b->grasslevel = grass[i].intensity[lx][ly];
- b->grassmat = grass[i].material;
+ b->grasslevel = grass[i]->intensity[lx][ly];
+ b->grassmat = grass[i]->material;
//b->grasslevels.push_back(grass[i].intensity[lx][ly]);
//b->grassmats.push_back(grass[i].material);
}
@@ -311,61 +315,46 @@ void ReadCellToSegment(DFHack::Context& DF, WorldSegment& segment, int CellX, in
long blue=0;
for(int i = 0; i < splatter.size(); i++)
{
- if(splatter[i].mat1 == MUD)
+ if(splatter[i]->mat1 == MUD)
{
- b->mudlevel = splatter[i].intensity[lx][ly];
+ b->mudlevel = splatter[i]->intensity[lx][ly];
}
- else if(splatter[i].mat1 == ICE)
+ else if(splatter[i]->mat1 == ICE)
{
- b->snowlevel = splatter[i].intensity[lx][ly];
+ b->snowlevel = splatter[i]->intensity[lx][ly];
}
- else if(splatter[i].mat1 == VOMIT)
+ else if(splatter[i]->mat1 == VOMIT)
{
- b->bloodlevel += splatter[i].intensity[lx][ly];
- red += (127 * splatter[i].intensity[lx][ly]);
- green += (196 * splatter[i].intensity[lx][ly]);
- blue += (28 *splatter[i].intensity[lx][ly]);
+ b->bloodlevel += splatter[i]->intensity[lx][ly];
+ red += (127 * splatter[i]->intensity[lx][ly]);
+ green += (196 * splatter[i]->intensity[lx][ly]);
+ blue += (28 *splatter[i]->intensity[lx][ly]);
}
- else if(splatter[i].mat1 == ICHOR)
+ else if(splatter[i]->mat1 == ICHOR)
{
- b->bloodlevel += splatter[i].intensity[lx][ly];
- red += (255 * splatter[i].intensity[lx][ly]);
- green += (255 * splatter[i].intensity[lx][ly]);
- blue += (255 * splatter[i].intensity[lx][ly]);
+ b->bloodlevel += splatter[i]->intensity[lx][ly];
+ red += (255 * splatter[i]->intensity[lx][ly]);
+ green += (255 * splatter[i]->intensity[lx][ly]);
+ blue += (255 * splatter[i]->intensity[lx][ly]);
}
- else if(splatter[i].mat1 == BLOOD_NAMED)
+ else if(splatter[i]->mat1 == BLOOD_NAMED)
{
- b->bloodlevel += splatter[i].intensity[lx][ly];
- red += (150 * splatter[i].intensity[lx][ly]);
- //green += (0 * splatter[i].intensity[lx][ly]);
- blue += (24 * splatter[i].intensity[lx][ly]);
+ b->bloodlevel += splatter[i]->intensity[lx][ly];
+ red += (150 * splatter[i]->intensity[lx][ly]);
+ //green += (0 * splatter[i]->intensity[lx][ly]);
+ blue += (24 * splatter[i]->intensity[lx][ly]);
}
- else if(splatter[i].mat1 == BLOOD_1
- || splatter[i].mat1 == BLOOD_2
- || splatter[i].mat1 == BLOOD_3
- || splatter[i].mat1 == BLOOD_4
- || splatter[i].mat1 == BLOOD_5
- || splatter[i].mat1 == BLOOD_6)
+ else if(splatter[i]->mat1 == BLOOD_1
+ || splatter[i]->mat1 == BLOOD_2
+ || splatter[i]->mat1 == BLOOD_3
+ || splatter[i]->mat1 == BLOOD_4
+ || splatter[i]->mat1 == BLOOD_5
+ || splatter[i]->mat1 == BLOOD_6)
{
- b->bloodlevel += splatter[i].intensity[lx][ly];
- if(splatter[i].mat2 == 206) //troll
- {
- //red += (0 * splatter[i].intensity[lx][ly]);
- green += (255 * splatter[i].intensity[lx][ly]);
- blue += (255 * splatter[i].intensity[lx][ly]);
- }
- else if(splatter[i].mat2 == 242) //imp
- {
- //red += (0 * splatter[i].intensity[lx][ly]);
- //green += (0 * splatter[i].intensity[lx][ly]);
- //blue += (0 * splatter[i].intensity[lx][ly]);
- }
- else
- {
- red += (150 * splatter[i].intensity[lx][ly]);
- //green += (0 * splatter[i].intensity[lx][ly]);
- blue += (24 * splatter[i].intensity[lx][ly]);
- }
+ b->bloodlevel += splatter[i]->intensity[lx][ly];
+ red += (150 * splatter[i]->intensity[lx][ly]);
+ //green += (0 * splatter[i]->intensity[lx][ly]);
+ blue += (24 * splatter[i]->intensity[lx][ly]);
}
}
if(b->bloodlevel)
@@ -454,12 +443,12 @@ void ReadCellToSegment(DFHack::Context& DF, WorldSegment& segment, int CellX, in
// DANGER: THIS CODE MAY BE BUGGY
// This was apparently causing a crash in previous version
// But works fine for me
- uint16_t row = veins[i].assignment[ly];
+ uint16_t row = veins[i]->assignment[ly];
bool set = (row & (1 << lx)) != 0;
if(set){
- rockIndex = veins[i].type;
+ rockIndex = veins[i]->type;
b->veinMaterial.type = INORGANIC;
- b->veinMaterial.index = veins[i].type;
+ b->veinMaterial.index = veins[i]->type;
b->hasVein = 1;
}
else
@@ -539,9 +528,9 @@ void ReadCellToSegment(DFHack::Context& DF, WorldSegment& segment, int CellX, in
}
//add trees and other vegetation
- for(int i = 0; i < plants.size(); i++)
+ for(int i = 0; i < plants->size(); i++)
{
- Block* b = segment.getBlock( plants[i].sdata.x, plants[i].sdata.y, CellZ);
+ Block* b = segment.getBlock( plants->at(i)->x, plants->at(i)->y, plants->at(i)->z);
if(b && (
(tileTypeTable[b->tileType].shape == TREE_DEAD) ||
(tileTypeTable[b->tileType].shape == TREE_OK) ||
@@ -551,8 +540,8 @@ void ReadCellToSegment(DFHack::Context& DF, WorldSegment& segment, int CellX, in
(tileTypeTable[b->tileType].shape == SHRUB_OK)
))
{
- b->tree.type = plants[i].sdata.type;
- b->tree.index = plants[i].sdata.material;
+ b->tree.type = plants->at(i)->type;
+ b->tree.index = plants->at(i)->material;
}
}
}
@@ -574,7 +563,7 @@ bool checkFloorBorderRequirement(WorldSegment* segment, int x, int y, int z, dir
}
-WorldSegment* ReadMapSegment(DFHack::Context &DF, int x, int y, int z, int sizex, int sizey, int sizez){
+WorldSegment* ReadMapSegment(DFHack::Core &DF, int x, int y, int z, int sizex, int sizey, int sizez){
uint32_t index;
clock_t start_time = clock();
DFHack::Maps *Maps;
@@ -608,7 +597,7 @@ WorldSegment* ReadMapSegment(DFHack::Context &DF, int x, int y, int z, int sizex
WriteErr("DFhack exeption: %s\n", e.what());
}
//DFHack::Vegetation *Veg;
- //if(!config.skipVegetation)
+ //if(!skipVegetation)
//{
// try
// {
@@ -617,7 +606,7 @@ WorldSegment* ReadMapSegment(DFHack::Context &DF, int x, int y, int z, int sizex
// catch (exception &e)
// {
// WriteErr("DFhack exeption: %s\n", e.what());
- // config.skipVegetation = true;
+ // skipVegetation = true;
// }
//}
DFHack::Constructions *Cons;
@@ -684,15 +673,10 @@ WorldSegment* ReadMapSegment(DFHack::Context &DF, int x, int y, int z, int sizex
//return new blank segment
return new WorldSegment(x,y,z + 1,sizex,sizey,sizez + 1);
}
- if( IsConnectedToDF() == false){
- DisconnectFromDF();
- //return new blank segment
- return new WorldSegment(x,y,z + 1,sizex,sizey,sizez + 1);
- }
//read memory info
if( memInfoHasBeenRead == false){
- dfMemoryInfo = DF.getMemoryInfo();
+ dfMemoryInfo = DF.vinfo;
memInfoHasBeenRead = true;
}
@@ -705,23 +689,23 @@ WorldSegment* ReadMapSegment(DFHack::Context &DF, int x, int y, int z, int sizex
//Read Number of cells
- int celldimX, celldimY, celldimZ;
- Maps->getSize((unsigned int &)celldimX, (unsigned int &)celldimY, (unsigned int &)celldimZ);
+ int cellDimX, cellDimY, cellDimZ;
+ Maps->getSize((unsigned int &)cellDimX, (unsigned int &)cellDimY, (unsigned int &)cellDimZ);
//Store these
- config.cellDimX = celldimX * 16;
- config.cellDimY = celldimY * 16;
- config.cellDimZ = celldimZ;
+ cellDimX = cellDimX * 16;
+ cellDimY = cellDimY * 16;
+ cellDimZ = cellDimZ;
//bound view to world
- if(x > celldimX * CELLEDGESIZE -sizex/2) DisplayedSegmentX = x = celldimX * CELLEDGESIZE -sizex/2;
- if(y > celldimY * CELLEDGESIZE -sizey/2) DisplayedSegmentY = y = celldimY * CELLEDGESIZE -sizey/2;
+ if(x > cellDimX * CELLEDGESIZE -sizex/2) DisplayedSegmentX = x = cellDimX * CELLEDGESIZE -sizex/2;
+ if(y > cellDimY * CELLEDGESIZE -sizey/2) DisplayedSegmentY = y = cellDimY * CELLEDGESIZE -sizey/2;
if(x < -sizex/2) DisplayedSegmentX = x = -sizex/2;
if(y < -sizey/2) DisplayedSegmentY = y = -sizey/2;
//setup new world segment
WorldSegment* segment = new WorldSegment(x,y,z,sizex,sizey,sizez);
- segment->regionSize.x = celldimX * CELLEDGESIZE;
- segment->regionSize.y = celldimY * CELLEDGESIZE;
- segment->regionSize.z = celldimZ;
+ segment->regionSize.x = cellDimX * CELLEDGESIZE;
+ segment->regionSize.y = cellDimY * CELLEDGESIZE;
+ segment->regionSize.z = cellDimZ;
segment->rotation = DisplayedRotation;
//read world wide buildings
@@ -846,7 +830,7 @@ WorldSegment* ReadMapSegment(DFHack::Context &DF, int x, int y, int z, int sizex
//Read Vegetation
//uint32_t numtrees;
- //if(!config.skipVegetation)
+ //if(!skipVegetation)
//{
// try
// {
@@ -875,7 +859,7 @@ WorldSegment* ReadMapSegment(DFHack::Context &DF, int x, int y, int z, int sizex
// catch(exception &err)
// {
// WriteErr("DFhack exeption: %s\n", err.what());
- // config.skipVegetation = true;
+ // skipVegetation = true;
// }
//}
@@ -1118,43 +1102,7 @@ void beautify_Segment(WorldSegment * segment)
TMR1_STOP;
}
-
-bool ConnectDFAPI(DFHack::Context* pDF){
- try
- {
- pDF->Attach();
- }
- catch(exception & err)
- {
- WriteErr("DFhack exeption: %s \n", err.what());
- return false;
- }
- catch(...)
- {
- return false;
- }
- //in case DF has locked up, force it's thread to resume
- pDF->ForceResume();
- return pDF->isAttached();
-}
-
-void DisconnectFromDF(){
- if(pDFApiHandle){
- //pDFApiHandle->getMaps()->DestroyMap();
- //in case DF has locked up, force it's thread to resume
- pDFApiHandle->ForceResume();
- pDFApiHandle->Detach();
- delete pDFApiHandle;
- pDFApiHandle = 0;
- }
-}
-
-bool IsConnectedToDF(){
- if(!pDFApiHandle) return false;
- return pDFApiHandle->isAttached();
-}
-
-void FollowCurrentDFWindow( )
+void FollowCurrentDFWindow()
{
int32_t newviewx;
int32_t newviewy;
@@ -1215,7 +1163,7 @@ void FollowCurrentDFWindow( )
}
}
-void FollowCurrentDFCenter( )
+void FollowCurrentDFCenter()
{
int32_t newviewx;
int32_t newviewy;
@@ -1250,13 +1198,8 @@ void FollowCurrentDFCenter( )
void read_segment( void *arg)
{
static bool firstLoad = 1;
- //al_lock_mutex(config.readMutex);
- //al_wait_cond(config.readCond, config.readMutex);
- if(parms.is_connected == 0)
- {
- DFProc->attach();
- parms.is_connected = 1;
- }
+ //al_lock_mutex(readMutex);
+ //al_wait_cond(readCond, readMutex);
config.threadstarted = 1;
if(altSegment)
{
@@ -1283,12 +1226,6 @@ void read_segment( void *arg)
config.threadstarted = 0;
pDFApiHandle->Resume();
beautify_Segment(altSegment);
- if(parms.thread_connect == 0)
- {
- DFProc->detach();
- parms.is_connected = 0;
- al_unlock_mutex(parms.m_connection);
- }
if(viewedSegment)
al_lock_mutex(viewedSegment->mutie);
swapSegments();
@@ -1301,8 +1238,8 @@ static void * threadedSegment(ALLEGRO_THREAD *thread, void *arg)
while(!al_get_thread_should_stop(thread))
{
read_segment(arg);
- //al_unlock_mutex(config.readMutex);
- //al_rest(config.automatic_reload_time/1000.0);
+ //al_unlock_mutex(readMutex);
+ //al_rest(automatic_reload_time/1000.0);
}
return 0;
}
@@ -1312,9 +1249,6 @@ void reloadDisplayedSegment(){
bool firstLoad = (pDFApiHandle == 0);
if(pDFApiHandle == 0)
{
- parms.m_connection = al_create_mutex();
- parms.is_connected = 0;
- al_lock_mutex(parms.m_connection);
al_clear_to_color(al_map_rgb(0,0,0));
draw_textf_border(font, al_map_rgb(255,255,255),
al_get_bitmap_width(al_get_target_bitmap())/2,
@@ -1322,28 +1256,8 @@ void reloadDisplayedSegment(){
ALLEGRO_ALIGN_CENTRE, "Connecting to DF...");
al_flip_display();
memInfoHasBeenRead = false;
- DFMgr = new ContextManager("Memory.xml");
- try
- {
- pDFApiHandle = DFMgr->getSingleContext();
- pDFApiHandle->Attach();
- pDFApiHandle->Detach();
- }
- catch (exception& e)
- {
- WriteErr("No Dwarf Fortress executable found\n");
- WriteErr("DFhack exeption: %s\n", e.what());
- delete( pDFApiHandle );
- pDFApiHandle = 0;
- return ;
- }
- al_unlock_mutex(parms.m_connection);
- }
- DFHack::Context& DF = *pDFApiHandle;
- if(DFProc == 0)
- {
- DFProc = DF.getProcess();
}
+ DFHack::Core& DF = *pDFApiHandle;
TMR1_START;
#ifndef RELEASE
@@ -1353,20 +1267,15 @@ void reloadDisplayedSegment(){
if (timeToReloadConfig)
{
parms.thread_connect = 0;
- al_lock_mutex(parms.m_connection);
- DF.Attach();
DF.Suspend();
contentLoader.Load(DF);
timeToReloadConfig = false;
//DF.Resume();
- DFProc->detach();
- parms.thread_connect = 1;
- al_unlock_mutex(parms.m_connection);
}
//G->Start();
- //G->ReadViewScreen(config.viewscreen);
- //config.menustate = G->ReadMenuState();
+ //G->ReadViewScreen(viewscreen);
+ //menustate = G->ReadMenuState();
//G->Finish();
//dispose old segment
@@ -1387,8 +1296,8 @@ void reloadDisplayedSegment(){
config.threadmade = 1;
}
}
- //if(config.threadstarted)
- // al_join_thread(config.readThread, NULL);
+ //if(threadstarted)
+ // al_join_thread(readThread, NULL);
parms.x = DisplayedSegmentX;
parms.y = DisplayedSegmentY;
@@ -1403,7 +1312,7 @@ void reloadDisplayedSegment(){
read_segment(NULL);
- //al_broadcast_cond(config.readCond);
+ //al_broadcast_cond(readCond);
//if(!viewedSegment || viewedSegment->regionSize.x == 0 || viewedSegment->regionSize.y == 0)
//{