Skip to content

Commit

Permalink
Get rid of a bunch of things. Simpler map segment update mechanism.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterix committed Feb 27, 2012
1 parent 0947632 commit ca35c82
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 754 deletions.
8 changes: 1 addition & 7 deletions Block.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef BLOCK_H
#define BLOCK_H
#pragma once

#include "common.h"
#include "SpriteObjects.h"
Expand Down Expand Up @@ -156,8 +155,3 @@ bool hasBuildingIdentity(Block* b, uint32_t index, int buildingOcc);
bool hasBuildingOfIndex(Block* b, uint32_t index);
bool wallShouldNotHaveBorders( int in );
void drawFloorBlood ( Block *b, int32_t drawx, int32_t drawy );

ALLEGRO_COLOR getSpriteColor(t_subSprite &sprite, DFHack::t_matglossPair material, DFHack::t_matglossPair layerMaterial, DFHack::t_matglossPair veinMaterial);
ALLEGRO_COLOR getSpriteColor(t_SpriteWithOffset &sprite, DFHack::t_matglossPair material, DFHack::t_matglossPair layerMaterial, DFHack::t_matglossPair veinMaterial);

#endif
36 changes: 0 additions & 36 deletions Constructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,3 @@ void changeConstructionMaterials(WorldSegment* segment, vector<df::construction>
}
}


bool IDisConstruction(int in){
switch(in){
case 495: //constructed pillar
case 496: //constructed wall rd2
case 497: //constructed wall r2d
case 498: //constructed wall r2u
case 499: //constructed wall ru2
case 500: //constructed wall l2u
case 501: //constructed wall lu2
case 502: //constructed wall l2d
case 503: //constructed wall ld2
case 504: //constructed wall lrud
case 505: //constructed wall rud
case 506: //constructed wall lrd
case 507: //constructed wall lru
case 508: //constructed wall lud
case 509: //constructed wall rd
case 510: //constructed wall ru
case 511: //constructed wall lu
case 512: //constructed wall ld
case 513: //constructed wall ud
case 514: //constructed wall lr

case 493: //constructed floor detailed

case 494: //constructed fortification

case ID_CNSTR_STAIR_UPDOWN:
case ID_CNSTR_STAIR_DOWN:
case ID_CNSTR_STAIR_UP:
return true;
break;
}
return 0;
}
3 changes: 0 additions & 3 deletions Constructions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#pragma once


bool IDisConstruction(int in);

void changeConstructionMaterials(WorldSegment* segment, vector<df::construction>* allConstructions);
10 changes: 4 additions & 6 deletions Creatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ ALLEGRO_USTR* bufferToUstr(const char* buffer, int length)
return temp;
}

bool IsCreatureVisible( t_unit* c ){
bool IsCreatureVisible( df::unit* c ){
if( config.show_all_creatures ) return true;

if( c->flags1.bits.dead )
Expand Down Expand Up @@ -333,17 +333,15 @@ void ReadCreaturesToSegment( DFHack::Core& DF, WorldSegment* segment)

t_unit *tempcreature = new t_unit();
df::unit *unit_ptr = 0;
/*for (uint32_t index = 0; index < numcreatures ; index++)
{
Creatures->ReadCreature( index, *tempcreature );*/
uint32_t index = 0;
while((index = DFHack::Simple::Units::GetCreatureInBox( index, &unit_ptr, x1,y1,z1,x2,y2,z2)) != -1 )
{
DFHack::Simple::Units::CopyCreature(unit_ptr,*tempcreature);
index++;
// if the creature isn't visible, we need not process it further.
if( !IsCreatureVisible( tempcreature ) )
if( !IsCreatureVisible( unit_ptr ) )
continue;
// make a copy of some creature data
DFHack::Simple::Units::CopyCreature(unit_ptr,*tempcreature);
// Acquire a cube element thingie!
Block* b = segment->getBlock (tempcreature->x, tempcreature->y, tempcreature->z );
// If we failed at that, make a new one out of fairy dust and makebelieve ;)
Expand Down
147 changes: 73 additions & 74 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ using namespace std;

extern ALLEGRO_FONT *font;

WorldSegment* viewedSegment;
WorldSegment* altSegment;
SegmentWrap* map_segment;
int DisplayedSegmentX;
int DisplayedSegmentY;
int DisplayedSegmentZ;
Expand Down Expand Up @@ -111,12 +110,7 @@ void draw_borders(float x, float y, uint8_t borders)
draw_diamond(x-4, y+4, al_map_rgb(0,0,0));

}
void swapSegments(void)
{
WorldSegment* backupSegment = viewedSegment;
viewedSegment = altSegment;
altSegment = backupSegment;
}

ALLEGRO_COLOR operator*(const ALLEGRO_COLOR &color1, const ALLEGRO_COLOR &color2)
{
ALLEGRO_COLOR temp;
Expand Down Expand Up @@ -344,14 +338,15 @@ void DrawCurrentLevelOutline(bool backPart){
}
}

void drawDebugCursorAndInfo(){
void drawDebugCursorAndInfo(WorldSegment * segment)
{
if((config.dfCursorX != -30000) && config.follow_DFcursor)
{
int x = config.dfCursorX;
int y = config.dfCursorY;
int z = config.dfCursorZ;
correctBlockForSegmetOffset(x,y,z);
correctBlockForRotation( x, y, z, viewedSegment->rotation);
correctBlockForRotation( x, y, z, segment->rotation);
debugCursor.x = x;
debugCursor.y = y;
debugCursor.z = z;
Expand All @@ -366,7 +361,7 @@ void drawDebugCursorAndInfo(){
//al_draw_bitmap_region(IMGObjectSheet, sheetx * SPRITEWIDTH, sheety * SPRITEHEIGHT, SPRITEWIDTH, SPRITEHEIGHT, point.x - SPRITEWIDTH/2, point.y - (WALLHEIGHT), 0);

//get block info
Block* b = viewedSegment->getBlockLocal( debugCursor.x, debugCursor.y, debugCursor.z+viewedSegment->sizez-2);
Block* b = segment->getBlockLocal( debugCursor.x, debugCursor.y, debugCursor.z+segment->sizez-2);
int i = 10;
draw_textf_border(font, al_map_rgb(255,255,255), 2, al_get_bitmap_height(al_get_target_bitmap())-20-(i--*al_get_font_line_height(font)), 0, "Block 0x%x", b);

Expand Down Expand Up @@ -707,31 +702,33 @@ void drawDebugCursorAndInfo(){
// "base: %d %d %d ", b->basetile, b->basecon.type, b->basecon.index );
}

void DrawMinimap(){
int size = 100;
//double oneBlockInPixels;
int posx = al_get_bitmap_width(al_get_target_bitmap())-size-10;
int posy = 10;
void DrawMinimap(WorldSegment * segment)
{
int size = 100;
//double oneBlockInPixels;
int posx = al_get_bitmap_width(al_get_target_bitmap())-size-10;
int posy = 10;

if(!viewedSegment || viewedSegment->regionSize.x == 0 || viewedSegment->regionSize.y == 0){
draw_textf_border(font, al_map_rgb(255,255,255), posx, posy, 0, "No map loaded");
return;
}
if(!segment || segment->regionSize.x == 0 || segment->regionSize.y == 0)
{
draw_textf_border(font, al_map_rgb(255,255,255), posx, posy, 0, "No map loaded");
return;
}

oneBlockInPixels = (double) size / viewedSegment->regionSize.x;
//map outine
int mapheight = (int)(viewedSegment->regionSize.y * oneBlockInPixels);
al_draw_rectangle(posx, posy, posx+size, posy+mapheight, al_map_rgb(0,0,0),0);
//current segment outline
int x = (size * (viewedSegment->x+1)) / viewedSegment->regionSize.x;
int y = (mapheight * (viewedSegment->y+1)) / viewedSegment->regionSize.y;
MiniMapSegmentWidth = (viewedSegment->sizex-2) * oneBlockInPixels;
MiniMapSegmentHeight = (viewedSegment->sizey-2) * oneBlockInPixels;
al_draw_rectangle(posx+x, posy+y, posx+x+MiniMapSegmentWidth, posy+y+MiniMapSegmentHeight,al_map_rgb(0,0,0),0);
MiniMapTopLeftX = posx;
MiniMapTopLeftY = posy;
MiniMapBottomRightX = posx+size;
MiniMapBottomRightY = posy+mapheight;
oneBlockInPixels = (double) size / segment->regionSize.x;
//map outine
int mapheight = (int)(segment->regionSize.y * oneBlockInPixels);
al_draw_rectangle(posx, posy, posx+size, posy+mapheight, al_map_rgb(0,0,0),0);
//current segment outline
int x = (size * (segment->x+1)) / segment->regionSize.x;
int y = (mapheight * (segment->y+1)) / segment->regionSize.y;
MiniMapSegmentWidth = (segment->sizex-2) * oneBlockInPixels;
MiniMapSegmentHeight = (segment->sizey-2) * oneBlockInPixels;
al_draw_rectangle(posx+x, posy+y, posx+x+MiniMapSegmentWidth, posy+y+MiniMapSegmentHeight,al_map_rgb(0,0,0),0);
MiniMapTopLeftX = posx;
MiniMapTopLeftY = posy;
MiniMapBottomRightX = posx+size;
MiniMapBottomRightY = posy+mapheight;
}

void DrawSpriteFromSheet( int spriteNum, ALLEGRO_BITMAP* spriteSheet, ALLEGRO_COLOR color, float x, float y, Block * b, float in_scale){
Expand Down Expand Up @@ -834,41 +831,36 @@ void DoSpriteIndexOverlay()
paintboard();
}

void paintboard(){
uint32_t starttime = clock();
//al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA);
//if(!buffer)
// buffer = al_create_bitmap(al_get_display_width(al_get_current_display()), al_get_display_height(al_get_current_display()));
//if(al_get_bitmap_width(buffer) != al_get_display_width(al_get_current_display()) || al_get_bitmap_height(buffer) != al_get_display_height(al_get_current_display()))
//{
// al_destroy_bitmap(buffer);
// buffer = al_create_bitmap(al_get_display_width(al_get_current_display()), al_get_display_height(al_get_current_display()));
//}
//ALLEGRO_BITMAP * backup = al_get_target_bitmap();
//al_set_target_bitmap(buffer);
//al_set_separate_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, ALLEGRO_ONE, ALLEGRO_ONE);
//al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, al_map_rgba(255, 255, 255, 255));
int op, src, dst, alpha_op, alpha_src, alpha_dst;
al_get_separate_blender(&op, &src, &dst, &alpha_op, &alpha_src, &alpha_dst);
al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO,ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
al_clear_to_color(al_map_rgba(0,0,0,0));
if(!config.transparentScreenshots)
al_clear_to_color(al_map_rgb(config.backr,config.backg,config.backb));
al_set_separate_blender(op, src, dst, alpha_op, alpha_src, alpha_dst);

//clear_to_color(buffer,makecol(12,7,49)); //this one is calm and nice

if( viewedSegment == NULL ){
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, "Could not find DF process");
return;
}
void paintboard()
{
uint32_t starttime = clock();

al_lock_mutex(viewedSegment->mutie);
int op, src, dst, alpha_op, alpha_src, alpha_dst;
al_get_separate_blender(&op, &src, &dst, &alpha_op, &alpha_src, &alpha_dst);
al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO,ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
if(config.transparentScreenshots)
{
al_clear_to_color(al_map_rgba(0,0,0,0));
}
else
{
al_clear_to_color(al_map_rgb(config.backr,config.backg,config.backb));
}
al_set_separate_blender(op, src, dst, alpha_op, alpha_src, alpha_dst);

viewedSegment->drawAllBlocks();
// lock segment for painting and retrieve it.
map_segment->lock();
WorldSegment * segment = map_segment->get();
if( segment == NULL )
{
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, "Could not find DF process");
map_segment->unlock();
return;
}
segment->drawAllBlocks();
if (config.show_osd) DrawCurrentLevelOutline(false);

DebugInt1 = viewedSegment->getNumBlocks();
DebugInt1 = segment->getNumBlocks();

uint32_t DrawTime = clock() - starttime;

Expand All @@ -892,14 +884,14 @@ void paintboard(){
draw_textf_border(font, al_map_rgb(255,255,255), 10,al_get_font_line_height(font), 0, "%i,%i,%i, r%i, z%i", DisplayedSegmentX,DisplayedSegmentY,DisplayedSegmentZ, DisplayedRotation, config.zoom);

if(config.debug_mode){
draw_textf_border(font, al_map_rgb(255,255,255), 10, 3*al_get_font_line_height(font), 0, "Map Read Time: %dms", viewedSegment->read_time);
draw_textf_border(font, al_map_rgb(255,255,255), 10, 4*al_get_font_line_height(font), 0, "Map Beautification Time: %ims", viewedSegment->beautify_time);
draw_textf_border(font, al_map_rgb(255,255,255), 10, 3*al_get_font_line_height(font), 0, "Map Read Time: %dms", segment->read_time);
draw_textf_border(font, al_map_rgb(255,255,255), 10, 4*al_get_font_line_height(font), 0, "Map Beautification Time: %ims", segment->beautify_time);
draw_textf_border(font, al_map_rgb(255,255,255), 10, 2*al_get_font_line_height(font), 0, "FPS: %.2f", 1.0/time_since_last_frame);
draw_textf_border(font, al_map_rgb(255,255,255), 10, 5*al_get_font_line_height(font), 0, "Draw: %ims", DrawTime);
draw_textf_border(font, al_map_rgb(255,255,255), 10, 6*al_get_font_line_height(font), 0, "D1: %i", blockFactory.getPoolSize());
draw_textf_border(font, al_map_rgb(255,255,255), 10, 7*al_get_font_line_height(font), 0, "%i/%i/%i, %i:%i", contentLoader->currentDay+1, contentLoader->currentMonth+1, contentLoader->currentYear, contentLoader->currentHour, (contentLoader->currentTickRel*60)/50);
draw_textf_border(font, al_map_rgb(255,255,255), 10, 8*al_get_font_line_height(font), 0, "%i Sprites drawn, %i tiles drawn, %.1f sprites per tile.", config.drawcount, config.tilecount, ((float)config.drawcount/(float)config.tilecount));
drawDebugCursorAndInfo();
drawDebugCursorAndInfo(segment);
}
config.drawcount = 0;
config.tilecount = 0;
Expand All @@ -926,11 +918,9 @@ void paintboard(){
draw_textf_border(font, al_map_rgb(255,255,255), al_get_bitmap_width(al_get_target_bitmap())/2,top, ALLEGRO_ALIGN_CENTRE, "Reloading every %0.1fs", (float)config.automatic_reload_time/1000);
}
al_hold_bitmap_drawing(false);
DrawMinimap();
DrawMinimap(segment);
}
//al_set_target_bitmap(backup);
//al_draw_bitmap(buffer, 0, 0, 0);
al_unlock_mutex(viewedSegment->mutie);
map_segment->unlock();
al_flip_display();
}

Expand Down Expand Up @@ -1210,8 +1200,11 @@ void saveImage(ALLEGRO_BITMAP* image){
al_save_bitmap(filename, image);
}

//FIXME: filled with black magic
void dumpSegment()
{
return;
/*
al_lock_mutex(config.readMutex);
//back up all the relevant values
Expand Down Expand Up @@ -1251,7 +1244,7 @@ void dumpSegment()
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));
ALLEGRO_BITMAP * volume = al_create_bitmap(segment->sizex, (segment->sizez * segment->sizey));
if(!volume)
{
DFConsole->printerr("Failed to create volumetric image.");
Expand Down Expand Up @@ -1283,9 +1276,14 @@ void dumpSegment()
config.lift_segment_offscreen = tempLift;
al_unlock_mutex(config.readMutex);
*/
}

void saveMegashot(bool tall){
// FIXME: even more black magic.
void saveMegashot(bool tall)
{
return;
/*
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...");
Expand Down Expand Up @@ -1365,6 +1363,7 @@ void saveMegashot(bool tall){
config.lift_segment_offscreen = tempLift;
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, ALLEGRO_COLOR tint)
Expand Down
8 changes: 5 additions & 3 deletions GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void pointToScreen(int *inx, int *iny, int inz);
Crd2D WorldBlockToScreen(int32_t x, int32_t y, int32_t z);
Crd2D LocalBlockToScreen(int32_t x, int32_t y, int32_t z);
void DrawCurrentLevelOutline(bool backPart);
void DrawMinimap();
void DrawMinimap(WorldSegment *);
void paintboard();
void draw_textf_border(const ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, float y, int flags, const char *format, ...);
void draw_text_border(const ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, float y, int flags, const char *ustr);
Expand All @@ -28,8 +28,10 @@ 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, ALLEGRO_COLOR tint);
extern WorldSegment* viewedSegment;//current, loaded
extern WorldSegment* altSegment;//background

/// currently visible map segment
extern SegmentWrap* map_segment;

extern int DisplayedSegmentX;
extern int DisplayedSegmentY;
extern int DisplayedSegmentZ;
Expand Down
Loading

0 comments on commit ca35c82

Please sign in to comment.