Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
peterix committed Oct 23, 2011
2 parents 96877f1 + c9b8b38 commit 8a907d1
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 50 deletions.
26 changes: 26 additions & 0 deletions Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,32 @@ void Block::DrawRamptops()
}
}

void Block::DrawPixel(int drawx, int drawy)
{
ALLEGRO_COLOR temp;
if(floorType > 0 || wallType > 0 || ramp.type > 0 || stairType > 0)
{
al_put_pixel(drawx, drawy, lookupMaterialColor(this->material.type, this->material.index));
}
if(this->water.index)
{
if(this->water.type == 0) //water
al_draw_pixel(drawx, drawy, al_map_rgba_f(0.6f, 0.85f, 0.92f, (float)water.index / 7.0f));
else
al_draw_pixel(drawx, drawy, al_map_rgba_f(1.0f, 0.5f, 0.15f, (float)water.index / 7.0f));
}
//Grass
if(grasslevel > 0 && (
(tileTypeTable[floorType].material == GRASS) ||
(tileTypeTable[floorType].material == GRASS2) ||
(tileTypeTable[floorType].material == GRASS_DEAD) ||
(tileTypeTable[floorType].material == GRASS_DRY)))
{
temp = lookupMaterialColor(WOOD, grassmat);
al_draw_pixel(drawx, drawy, al_map_rgba_f(temp.r,temp.g, temp.b, (float)grasslevel/100.0f));
}
}

bool hasWall(Block* b){
if(!b) return false;
return b->wallType > 0;
Expand Down
1 change: 1 addition & 0 deletions Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class Block
void Draw();
void Drawcreaturetext();
void DrawRamptops();
void DrawPixel(int drawx, int drawy);

uint16_t temp1;
uint16_t temp2;
Expand Down
113 changes: 99 additions & 14 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,8 +1083,81 @@ void saveImage(ALLEGRO_BITMAP* image){
};
al_save_bitmap(filename, image);
}
void saveMegashot(){

void dumpSegment()
{
al_lock_mutex(config.readMutex);

//back up all the relevant values
Crd3D tempSize = config.segmentSize;
int tempViewx = DisplayedSegmentX;
int tempViewy = DisplayedSegmentY;
bool tempFollow = config.follow_DFscreen;
int tempLift = config.lift_segment_offscreen;
int currentFlags = al_get_new_bitmap_flags();
//now make them real big.
config.follow_DFscreen = false;
config.lift_segment_offscreen = 0;
parms.x = 0;
parms.y = 0;
parms.z = config.cellDimZ - 1;
parms.sizex = config.cellDimX;
parms.sizey = config.cellDimY;
parms.sizez = config.cellDimZ;

read_segment(NULL);
//get filename
char filename[20] ={0};
FILE* fp;
int index = 1;
//search for the first screenshot# that does not exist already
while(true){
sprintf(filename, "screenshot%i.png", index);

fp = fopen(filename, "r");
if( fp != 0)
fclose(fp);
else
//file does not exist, so exit loop
break;
index++;
};
int tempFlags = al_get_new_bitmap_flags();
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);

ALLEGRO_BITMAP * volume = al_create_bitmap(viewedSegment->sizex, (viewedSegment->sizez * viewedSegment->sizey));
if(!volume)
{
DFConsole->printerr("Failed to create volumetric image.");
al_set_new_bitmap_flags(tempFlags);
return;
}

ALLEGRO_BITMAP * backup = al_get_target_bitmap();
al_set_target_bitmap(volume);

al_clear_to_color(al_map_rgba(0,0,0,0));
viewedSegment->drawPixels();

al_save_bitmap(filename, volume);
al_destroy_bitmap(volume);

al_set_target_bitmap(backup);
al_set_new_bitmap_flags(tempFlags);

//restore everything that we changed.
config.segmentSize = tempSize;
DisplayedSegmentX = tempViewx;
DisplayedSegmentY = tempViewy;
config.follow_DFscreen = tempFollow;
config.lift_segment_offscreen = tempLift;

al_unlock_mutex(config.readMutex);
}

void saveMegashot(bool tall){
config.showRenderStatus = true;
al_lock_mutex(config.readMutex);
draw_textf_border(font, al_map_rgb(255,255,255), al_get_bitmap_width(al_get_target_bitmap())/2, al_get_bitmap_height(al_get_target_bitmap())/2, ALLEGRO_ALIGN_CENTRE, "Saving large screenshot...");
al_flip_display();
char filename[20] ={0};
Expand All @@ -1103,30 +1176,36 @@ void saveMegashot(){
};
int timer = clock();
//back up all the relevant values
Crd3D tempSize = config.segmentSize;
Crd3D backupsize = config.segmentSize;
int tempViewx = DisplayedSegmentX;
int tempViewy = DisplayedSegmentY;
int tempViewz = DisplayedSegmentZ;
bool tempFollow = config.follow_DFscreen;
int tempLift = config.lift_segment_offscreen;
int currentFlags = al_get_new_bitmap_flags();
//now make them real big.
config.follow_DFscreen = false;
config.lift_segment_offscreen = 0;
int bigImageWidth = (config.cellDimX * TILEWIDTH);
int bigImageHeight = ((config.cellDimX + config.cellDimY) * TILEHEIGHT / 2) + ((config.segmentSize.z - 1) * BLOCKHEIGHT);
config.segmentSize.x = config.cellDimX + 2;
config.segmentSize.y = config.cellDimY + 2;
if(tall)
config.segmentSize.z = DisplayedSegmentZ + 1;
int bigImageWidth = (config.cellDimX * TILEWIDTH);
int bigImageHeight = ((config.cellDimX + config.cellDimY) * TILEHEIGHT / 2) + ((config.segmentSize.z - 1) * BLOCKHEIGHT);
parms.sizex = config.segmentSize.x;
parms.sizey = config.segmentSize.y;
parms.sizez = config.segmentSize.z;
DisplayedSegmentX = -1;
DisplayedSegmentY = -1;
parms.x = DisplayedSegmentX;
parms.y = DisplayedSegmentY;
parms.z = DisplayedSegmentZ;
//Rebuild stuff
//reloadDisplayedSegment();
read_segment(NULL);
//Draw the image and save it
//al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA);
//al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
bigFile = al_create_bitmap(bigImageWidth, bigImageHeight);
if(bigFile)
{
WriteErr("\nSaving large screenshot to %s\n", filename);
DFConsole->print("\nSaving large screenshot to %s\n", filename);
al_set_target_bitmap(bigFile);
if(!config.transparentScreenshots)
al_clear_to_color(al_map_rgb(config.backr,config.backg,config.backb));
Expand All @@ -1135,21 +1214,27 @@ void saveMegashot(){
al_set_target_bitmap(al_get_backbuffer(al_get_current_display()));
al_destroy_bitmap(bigFile);
timer = clock() - timer;
WriteErr("Took %ims\n", timer);
DFConsole->print("Took %ims\n", timer);
}
else
{
WriteErr("Failed to take large screenshot. try using software mode\n");
DFConsole->printerr("Failed to take large screenshot. try using software mode\n");
}
//restore everything that we changed.
config.segmentSize = tempSize;
config.segmentSize = backupsize;
parms.sizex = config.segmentSize.x;
parms.sizey = config.segmentSize.y;
parms.sizez = config.segmentSize.z;
DisplayedSegmentX = tempViewx;
DisplayedSegmentY = tempViewy;
DisplayedSegmentZ = tempViewz;
parms.x = DisplayedSegmentX;
parms.y = DisplayedSegmentY;
parms.z = DisplayedSegmentZ;
config.follow_DFscreen = tempFollow;
config.lift_segment_offscreen = tempLift;
//al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY);
al_set_new_bitmap_flags(currentFlags);
config.showRenderStatus = false;
al_unlock_mutex(config.readMutex);
}

void draw_particle_cloud(int count, float centerX, float centerY, float rangeX, float rangeY, ALLEGRO_BITMAP *sprite)
Expand Down
3 changes: 2 additions & 1 deletion GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ void DrawSpriteIndexOverlay(int i);
void DoSpriteIndexOverlay();
void loadGraphicsFromDisk();
void saveScreenshot();
void saveMegashot();
void saveMegashot(bool tall);
void dumpSegment();
void saveImage(ALLEGRO_BITMAP* image);
void draw_particle_cloud(int count, float centerX, float centerY, float rangeX, float rangeY, ALLEGRO_BITMAP *sprite);
extern WorldSegment* viewedSegment;//current, loaded
Expand Down
20 changes: 7 additions & 13 deletions MapLoading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@ const VersionInfo *dfMemoryInfo;
bool memInfoHasBeenRead;
bool connected = 0;
bool threadrunnng = 0;
struct segParams
{
int x;
int y;
int z;
int sizex;
int sizey;
int sizez;
bool thread_connect;
bool is_connected;
} parms;
segParams parms;

inline bool IDisWall(int in){
//if not a custom type, do a lookup in dfHack's interface
Expand Down Expand Up @@ -696,6 +686,9 @@ WorldSegment* ReadMapSegment(DFHack::Core &DF, int x, int y, int z, int sizex, i
cellDimX = cellDimX * 16;
cellDimY = cellDimY * 16;
cellDimZ = cellDimZ;
config.cellDimX = cellDimX;
config.cellDimY = cellDimY;
config.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;
Expand Down Expand Up @@ -1249,9 +1242,10 @@ static void * threadedSegment(ALLEGRO_THREAD *thread, void *arg)
{
while(!al_get_thread_should_stop(thread))
{
al_lock_mutex(config.readMutex);
read_segment(arg);
//al_unlock_mutex(readMutex);
//al_rest(automatic_reload_time/1000.0);
al_unlock_mutex(config.readMutex);
al_rest(config.automatic_reload_time/1000.0);
}
return 0;
}
Expand Down
16 changes: 16 additions & 0 deletions MapLoading.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,20 @@ void beautify_Segment(WorldSegment * segment);
void DisconnectFromDF();
bool IsConnectedToDF();

void read_segment( void *arg);

extern const VersionInfo *dfMemoryInfo;

struct segParams
{
int x;
int y;
int z;
int sizex;
int sizey;
int sizez;
bool thread_connect;
bool is_connected;
};

extern segParams parms;
39 changes: 22 additions & 17 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
Welcome to Stonesense Slate(2.2)
Welcome to Stonesense Felsite(3.1)

Thank you for trying out our little visualizer,
as always, we appreciate any feedback.

Please note, that for the time being Stonesense Slate ONLY supports DF 31_1, through 31_16.
Make sure you have DF running, with your game loaded.
Please note, that for the time being Stonesense Felsite ONLY supports DF 31_25.

IF Stonesense should at any time lock up, it might happen that DF freezes.
If this happens just kill of the Stonesense.exe process (if it didn't die on itself)
and use the dfunstuck.exe utility supplied with this distribution.
To run stonesense, Copy DFHack into the dwarf fortress folder, and run DwarfFortress.exe.
When DFHack console appears, type in stonesense and press enter.

--== Configuration ==--

Expand All @@ -29,18 +27,21 @@ PG UP/PG Down: Move up and down
1 and 2: Increase/decrease Z depth shown
Enter: Rotate view 90 degrees
ESC: Exit program
U: Toggle Stockpiles
I: Toggle Zones
C: Toggle Truncated Walls
F: Toggle Follow Mode
H: Toggle Hidden Blocks
B: Toggle Blacked Out Areas
S: Toggle Single Layer View
N: Toggle Creature Names
M: TOggle Creature Emotion Icons
F2: Screenshot mode/Hide Display Overlays
U: Toggle stockpiles.
I: Toggle zones.
C: Toggle truncated walls.
F: Toggle follow mode.
H: Toggle hidden blocks.
B: Toggle blacked out areas.
S: Toggle single layer view.
N: Toggle creature names.
M: Toggle creature emotion icons.
O: Toggle occlusion culling.
F2: Screenshot mode/hide display overlays
F5: Save Screenshot
CTRL + F5: Save Screenshot of entire fortress
CTRL + F5: Save Screenshot of entire fortress with the current Z level settings.
CTRL + SHIFT + F5: Save a screenshot of the entire fortress from the current top Z level down to the bottom of the map.
ALT + F5: Save a volumetric thing I'm testing out.
Numpad + and -: Increase/Decrease AutoReload Rate
CTRL + navigation: Adjusts follow mode offset

Expand All @@ -61,6 +62,10 @@ holding Ctrl while using the keyboard window movement keys.

When you turn on cursor follow mode, the debug cursor will follow the DF cursor when it exists.

-- Occlusion Culling --

There is an experimental feature that hides blocks that are not visible, for a speed increase.
This is a work in progress, and very buggy. It can be turned off with 'o', if something is missing.
--== Contacts ==--

Stonesense mailing list:
Expand Down
13 changes: 8 additions & 5 deletions UserInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,15 @@ void doKeys(int Key)
timeToReloadSegment = true;
}
if(Key == ALLEGRO_KEY_F5){
if (!(al_key_down(&keyboard,ALLEGRO_KEY_LCTRL) || al_key_down(&keyboard,ALLEGRO_KEY_RCTRL)))
if (al_key_down(&keyboard,ALLEGRO_KEY_LCTRL) || al_key_down(&keyboard,ALLEGRO_KEY_RCTRL))
if (al_key_down(&keyboard,ALLEGRO_KEY_LSHIFT) || al_key_down(&keyboard,ALLEGRO_KEY_RSHIFT))
saveMegashot(true);
else
saveMegashot(false);
else if (al_key_down(&keyboard,ALLEGRO_KEY_ALT) || al_key_down(&keyboard,ALLEGRO_KEY_ALTGR))
dumpSegment();
else
saveScreenshot();
else{
saveMegashot();
}

}
if(Key == ALLEGRO_KEY_PAD_PLUS){
config.automatic_reload_time += config.automatic_reload_step;
Expand Down
12 changes: 12 additions & 0 deletions WorldSegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,15 @@ bool WorldSegment::CoordinateInsideSegment(uint32_t x, uint32_t y, uint32_t z){
if( (int32_t)z < this->z || (int32_t)z >= this->z + this->sizez) return false;
return true;
}

void WorldSegment::drawPixels()
{
for(int32_t vsx=0; vsx < this->sizex; vsx++)
for(int32_t vsy=0; vsy < this->sizey; vsy++)
for(int32_t vsz=0; vsz < this->sizez; vsz++)
{
Block *b = getBlockLocal(vsx,vsy,vsz);
if (b)
b->DrawPixel(vsx, (vsz*this->sizey) + vsy);
}
}
1 change: 1 addition & 0 deletions WorldSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class WorldSegment{
Block* getBlock(uint32_t index);
void addBlock(Block* b);
void drawAllBlocks();
void drawPixels();
bool CoordinateInsideSegment(uint32_t x, uint32_t y, uint32_t z);
};

Expand Down

0 comments on commit 8a907d1

Please sign in to comment.