summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Mrázek2012-03-10 18:48:13 +0100
committerPetr Mrázek2012-03-10 18:48:13 +0100
commitf05386bae01d1840bdc889f30253ed50ee892860 (patch)
treeb5c0745c84c4d2a69c0e93aa9db8148eeb2eb740
parent96bbfa604d1835df993602cbf46ca6bb0a28e6bd (diff)
downloadstonesense-f05386bae01d1840bdc889f30253ed50ee892860.tar.gz
stonesense-f05386bae01d1840bdc889f30253ed50ee892860.tar.bz2
stonesense-f05386bae01d1840bdc889f30253ed50ee892860.tar.xz
Plugin API changes
No more Core propagation!
-rw-r--r--BlockCondition.cpp4
-rw-r--r--ConditionalSprite.cpp4
-rw-r--r--ContentBuildingReader.cpp4
-rw-r--r--ContentLoader.cpp38
-rw-r--r--ContentLoader.h3
-rw-r--r--CreatureConfiguration.cpp4
-rw-r--r--GUI.cpp27
-rw-r--r--GUI.h6
-rw-r--r--GameBuildings.cpp2
-rw-r--r--MapLoading.cpp49
-rw-r--r--MapLoading.h2
-rw-r--r--UserInput.cpp18
-rw-r--r--common.h6
-rw-r--r--main.cpp71
14 files changed, 110 insertions, 128 deletions
diff --git a/BlockCondition.cpp b/BlockCondition.cpp
index 57c20f1..8932de1 100644
--- a/BlockCondition.cpp
+++ b/BlockCondition.cpp
@@ -101,7 +101,7 @@ MaterialTypeCondition::MaterialTypeCondition(const char* strValue, const char* s
subtype = lookupMaterialIndex( value, strSubtype);
if (subtype == INVALID_INDEX)
{
- WriteErr("Material subtype not found in MaterialTypeCondition: %s\n", strSubtype);
+ LogError("Material subtype not found in MaterialTypeCondition: %s\n", strSubtype);
//make material never match;
value = INVALID_INDEX;
}
@@ -324,7 +324,7 @@ bool NotConditionalNode::addCondition(BlockCondition* cond)
{
if (childcond != NULL)
{
- WriteErr("Too many condition elements for NotConditionalNode\n");
+ LogError("Too many condition elements for NotConditionalNode\n");
return false;
}
childcond = cond;
diff --git a/ConditionalSprite.cpp b/ConditionalSprite.cpp
index 0327a23..5c6c692 100644
--- a/ConditionalSprite.cpp
+++ b/ConditionalSprite.cpp
@@ -97,7 +97,7 @@ bool SpriteBlock::copyToBlock(Block* b)
bool SpriteBlock::addCondition(BlockCondition* cond){
if (conditions != NULL)
{
- WriteErr("Too many condition elements for SpriteBlock\n");
+ LogError("Too many condition elements for SpriteBlock\n");
return false;
}
conditions = cond;
@@ -145,7 +145,7 @@ bool RotationBlock::copyToBlock(Block* b)
}
bool RotationBlock::addCondition(BlockCondition* cond){
- WriteErr("Condition elements not permitted for RotationBlock\n");
+ LogError("Condition elements not permitted for RotationBlock\n");
return false;
}
diff --git a/ContentBuildingReader.cpp b/ContentBuildingReader.cpp
index 41c2b92..31836f8 100644
--- a/ContentBuildingReader.cpp
+++ b/ContentBuildingReader.cpp
@@ -224,8 +224,8 @@ bool includeFile(SpriteNode* node, TiXmlElement* includeNode, SpriteBlock* &oldS
if(!loadOkay)
{
contentError("Include failed",includeNode);
- WriteErr("File load failed: %s\n",configfilepath);
- WriteErr("Line %d: %s\n",doc.ErrorRow(),doc.ErrorDesc());
+ LogError("File load failed: %s\n",configfilepath);
+ LogError("Line %d: %s\n",doc.ErrorRow(),doc.ErrorDesc());
return false;
}
elemParent = hDoc.FirstChildElement("include").Element();
diff --git a/ContentLoader.cpp b/ContentLoader.cpp
index 739ed6a..48ed0a0 100644
--- a/ContentLoader.cpp
+++ b/ContentLoader.cpp
@@ -86,7 +86,7 @@ void DumpPrefessionNamesToDisk(vector<string> material, const char* filename){
}
fclose(fp);
}
-bool ContentLoader::Load( DFHack::Core& DF){
+bool ContentLoader::Load(){
/*draw_textf_border(font,
al_get_bitmap_width(al_get_target_bitmap())/2,
al_get_bitmap_height(al_get_target_bitmap())/2,
@@ -112,11 +112,11 @@ bool ContentLoader::Load( DFHack::Core& DF){
try
{
- Mats = DF.getMaterials();
+ Mats = Core::getInstance().getMaterials();
}
catch(exception &e)
{
- WriteErr("DFhack exeption: %s\n", e.what());
+ LogError("DFhack exeption: %s\n", e.what());
}
if(!config.skipCreatureTypes)
{
@@ -126,7 +126,7 @@ bool ContentLoader::Load( DFHack::Core& DF){
}
catch(exception &e)
{
- WriteErr("DFhack exeption: %s\n", e.what());
+ LogError("DFhack exeption: %s\n", e.what());
config.skipCreatureTypes = true;
}
}
@@ -138,7 +138,7 @@ bool ContentLoader::Load( DFHack::Core& DF){
}
catch(exception &e)
{
- WriteErr("DFhack exeption: %s\n", e.what());
+ LogError("DFhack exeption: %s\n", e.what());
config.skipCreatureTypesEx = true;
}
}
@@ -150,7 +150,7 @@ bool ContentLoader::Load( DFHack::Core& DF){
}
catch(exception &e)
{
- WriteErr("DFhack exeption: %s\n", e.what());
+ LogError("DFhack exeption: %s\n", e.what());
config.skipDescriptorColors = true;
}
}
@@ -158,7 +158,7 @@ bool ContentLoader::Load( DFHack::Core& DF){
{
if(!Mats->CopyInorganicMaterials(this->inorganic))
{
- WriteErr("Missing inorganic materials!\n");
+ LogError("Missing inorganic materials!\n");
config.skipInorganicMats = true;
}
}
@@ -166,19 +166,11 @@ bool ContentLoader::Load( DFHack::Core& DF){
{
if(!Mats->CopyOrganicMaterials(this->organic))
{
- WriteErr("Missing organic materials!\n");
+ LogError("Missing organic materials!\n");
config.skipOrganicMats = true;
}
}
Buildings::ReadCustomWorkshopTypes(custom_workshop_types);
- try
- {
- contentLoader->MemInfo = DF.vinfo;
- }
- catch(exception &e)
- {
- WriteErr("DFhack exeption: %s\n", e.what());
- }
if(professionStrings.empty())
{
FOR_ENUM_ITEMS(profession, i)
@@ -277,7 +269,7 @@ bool ContentLoader::parseContentIndexFile( const char* filepath )
string line;
ifstream myfile( filepath );
if (myfile.is_open() == false){
- WriteErr( "Unable to load config index file at: %s!\n", filepath );
+ LogError( "Unable to load config index file at: %s!\n", filepath );
return false;
}
LogVerbose("Reading index at %s...\n", filepath);
@@ -312,7 +304,7 @@ bool ContentLoader::parseContentIndexFile( const char* filepath )
if (!getLocalFilename(configfilepath,line.c_str(),filepath))
{
- WriteErr("File name parsing failed on %s\n",line.c_str());
+ LogError("File name parsing failed on %s\n",line.c_str());
continue;
}
//WriteErr("but it's all fucked here: %s\n",configfilepath);
@@ -324,17 +316,17 @@ bool ContentLoader::parseContentIndexFile( const char* filepath )
{
LogVerbose("Reading xml %s...\n", configfilepath);
if (!parseContentXMLFile(configfilepath))
- WriteErr("Failure in reading %s\n",configfilepath);
+ LogError("Failure in reading %s\n",configfilepath);
}
else if (strcmp(extension,".txt") == 0)
{
LogVerbose("Reading index %s...\n", configfilepath);
if (!parseContentIndexFile(configfilepath))
- WriteErr("Failure in reading %s\n",configfilepath);
+ LogError("Failure in reading %s\n",configfilepath);
}
else
{
- WriteErr("Invalid filename: %s\n",configfilepath);
+ LogError("Invalid filename: %s\n",configfilepath);
}
}
myfile.close();
@@ -352,7 +344,7 @@ bool ContentLoader::parseContentXMLFile( const char* filepath ){
TiXmlDocument doc( filepath );
if(!doc.LoadFile())
{
- WriteErr("File load failed: %s\n", filepath);
+ LogError("File load failed: %s\n", filepath);
return false;
}
TiXmlHandle hDoc(&doc);
@@ -440,7 +432,7 @@ const char* getDocument(TiXmlNode* element)
void contentError(const char* message, TiXmlNode* element)
{
- WriteErr("%s: %s: %s (Line %d)\n",getDocument(element),message,element->Value(),element->Row());
+ LogError("%s: %s: %s (Line %d)\n",getDocument(element),message,element->Value(),element->Row());
}
// converts list of characters 0-5 into bits, ignoring garbage
diff --git a/ContentLoader.h b/ContentLoader.h
index 91c839d..ff5e50d 100644
--- a/ContentLoader.h
+++ b/ContentLoader.h
@@ -27,7 +27,7 @@ public:
ContentLoader(void);
~ContentLoader(void);
- bool Load( DFHack::Core& DF);
+ bool Load();
bool reload_configs();
@@ -44,7 +44,6 @@ public:
vector<string> professionStrings;
std::map <uint32_t, std::string> custom_workshop_types;
- VersionInfo *MemInfo;
DFHack::Materials * Mats;
std::vector<t_matgloss> organic;
std::vector<t_matglossInorganic> inorganic;
diff --git a/CreatureConfiguration.cpp b/CreatureConfiguration.cpp
index 2713780..93452cb 100644
--- a/CreatureConfiguration.cpp
+++ b/CreatureConfiguration.cpp
@@ -66,7 +66,7 @@ int translateProfession(const char* currentProf)
return j;
}
}
- WriteErr("Unable to match profession '%s' to anything in-game\n", currentProf);
+ LogError("Unable to match profession '%s' to anything in-game\n", currentProf);
return INT_MAX; //if it is left at INVALID_INDEX, the condition is ignored entierly.
}
@@ -137,7 +137,7 @@ bool addSingleCreatureConfig( TiXmlElement* elemCreature, vector<vector<Creature
if (customStr != NULL)
{
- WriteErr("custom: %s\n",customStr);
+ LogError("custom: %s\n",customStr);
}
const char* sexstr = elemVariant->Attribute("sex");
diff --git a/GUI.cpp b/GUI.cpp
index cc54e45..693909b 100644
--- a/GUI.cpp
+++ b/GUI.cpp
@@ -397,7 +397,7 @@ void DrawCurrentLevelOutline(bool backPart){
}
}
-void drawDebugCursorAndInfo(WorldSegment * segment, DFHack::Core * c)
+void drawDebugCursorAndInfo(WorldSegment * segment)
{
using df::global::ui;
@@ -461,7 +461,7 @@ void drawDebugCursorAndInfo(WorldSegment * segment, DFHack::Core * c)
auto Actual_building = virtual_cast<df::building_actual>(b->building.info.origin);
if(!Actual_building)
break;
- c->Suspend();
+ CoreSuspender csusp;
Actual_building->contained_items.size(); //Item array.
std::string BuildingName;
Actual_building->getName(&BuildingName);
@@ -483,7 +483,6 @@ void drawDebugCursorAndInfo(WorldSegment * segment, DFHack::Core * c)
Actual_building->contained_items[index]->item->getStackSize()>1?stacknum:"",
(Actual_building->contained_items[index]->use_mode == 2?" [B]":""));
}
- c->Resume();
}
break;
case ui_sidebar_mode::ViewUnits:
@@ -989,7 +988,7 @@ void DrawSpriteIndexOverlay(int imageIndex){
}
-void DoSpriteIndexOverlay(DFHack::Core * c)
+void DoSpriteIndexOverlay()
{
DrawSpriteIndexOverlay(-1);
int index = 0;
@@ -1018,10 +1017,10 @@ void DoSpriteIndexOverlay(DFHack::Core * c)
}
//redraw screen again
al_clear_to_color(al_map_rgb(config.backr,config.backg,config.backb));
- paintboard(c);
+ paintboard();
}
-void paintboard(DFHack::Core * c)
+void paintboard()
{
uint32_t starttime = clock();
@@ -1081,7 +1080,7 @@ void paintboard(DFHack::Core * c)
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(segment, c);
+ drawDebugCursorAndInfo(segment);
}
config.drawcount = 0;
config.tilecount = 0;
@@ -1226,10 +1225,10 @@ int loadImgFile(const char* filename)
test = al_create_bitmap(config.imageCacheSize,config.imageCacheSize);
if(test)
{
- WriteErr("%i works.\n", config.imageCacheSize);
+ LogError("%i works.\n", config.imageCacheSize);
break;
}
- WriteErr("%i is too large. chopping it.\n", config.imageCacheSize);
+ LogError("%i is too large. chopping it.\n", config.imageCacheSize);
config.imageCacheSize = config.imageCacheSize / 2;
}
foundSize = true;
@@ -1261,10 +1260,12 @@ int loadImgFile(const char* filename)
LogVerbose("New image: %s\n",filename);
if(currentCache < 0)
{
+ // FIXME: this is some really weird logic.
IMGCache.push_back(al_create_bitmap(config.imageCacheSize, config.imageCacheSize));
if(!IMGCache[0])
{
- DFConsole->printerr("Cannot create bitmap sized %ix%i, please chose a smaller size",config.imageCacheSize,config.imageCacheSize);
+ // FIXME: so, what happens when al_create_bitmap fails? rainbows and unicorns?
+ LogVerbose("Cannot create bitmap sized %ix%i, please chose a smaller size",config.imageCacheSize,config.imageCacheSize);
}
currentCache = IMGCache.size() -1;
LogVerbose("Creating image cache #%d\n",currentCache);
@@ -1339,9 +1340,9 @@ int loadImgFile(ALLEGRO_PATH* filepath)
return loadImgFile(al_path_cstr(filepath, ALLEGRO_NATIVE_PATH_SEP));
}
*/
-void saveScreenshot(DFHack::Core * c){
+void saveScreenshot(){
al_clear_to_color(al_map_rgb(config.backr,config.backg,config.backb));
- paintboard(c);
+ paintboard();
//get filename
char filename[20] ={0};
FILE* fp;
@@ -1364,7 +1365,7 @@ void saveScreenshot(DFHack::Core * c){
al_set_target_bitmap(temp);
if(!config.transparentScreenshots)
al_clear_to_color(al_map_rgb(config.backr,config.backg,config.backb));
- paintboard(c);
+ paintboard();
al_save_bitmap(filename, temp);
al_set_target_bitmap(al_get_backbuffer(al_get_current_display()));
al_destroy_bitmap(temp);
diff --git a/GUI.h b/GUI.h
index 3c2087e..add378f 100644
--- a/GUI.h
+++ b/GUI.h
@@ -8,7 +8,7 @@ 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(WorldSegment *);
-void paintboard(DFHack::Core * c);
+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);
void draw_ustr_border(const ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, float y, int flags, const ALLEGRO_USTR *ustr);
@@ -21,9 +21,9 @@ void DrawSpriteFromSheet( int spriteNum,ALLEGRO_BITMAP* spriteSheet, ALLEGRO_COL
ALLEGRO_BITMAP * CreateSpriteFromSheet( int spriteNum, ALLEGRO_BITMAP* spriteSheet);
ALLEGRO_BITMAP* load_bitmap_withWarning(const char* path);
void DrawSpriteIndexOverlay(int i);
-void DoSpriteIndexOverlay(DFHack::Core * c);
+void DoSpriteIndexOverlay();
void loadGraphicsFromDisk();
-void saveScreenshot(DFHack::Core * c);
+void saveScreenshot();
void saveMegashot(bool tall);
void dumpSegment();
void saveImage(ALLEGRO_BITMAP* image);
diff --git a/GameBuildings.cpp b/GameBuildings.cpp
index d896b55..ab53a8c 100644
--- a/GameBuildings.cpp
+++ b/GameBuildings.cpp
@@ -135,7 +135,7 @@ void loadBuildingSprites ( Block* b)
bool foundBlockBuildingInfo = false;
if (b == NULL)
{
- WriteErr("Null Block skipped in loadBuildingSprites\n");
+ LogError("Null Block skipped in loadBuildingSprites\n");
return;
}
BuildingConfiguration* generic = NULL, *specific = NULL, *custom = NULL;
diff --git a/MapLoading.cpp b/MapLoading.cpp
index 1fd62f1..d67fcdd 100644
--- a/MapLoading.cpp
+++ b/MapLoading.cpp
@@ -11,10 +11,11 @@
#include <df/plant.h>
#include <df/effect.h>
+/*
static DFHack::Core* pDFApiHandle = 0;
static DFHack::Process * DFProc = 0;
const VersionInfo *dfMemoryInfo;
-bool memInfoHasBeenRead;
+bool memInfoHasBeenRead;*/
bool connected = 0;
bool threadrunnng = 0;
segParams parms;
@@ -616,10 +617,10 @@ bool checkFloorBorderRequirement(WorldSegment* segment, int x, int y, int z, dir
}
-WorldSegment* ReadMapSegment(DFHack::Core &DF, int x, int y, int z, int sizex, int sizey, int sizez){
+WorldSegment* ReadMapSegment(int x, int y, int z, int sizex, int sizey, int sizez){
uint32_t index;
clock_t start_time = clock();
- DFHack::Materials *Mats = DF.getMaterials();
+ DFHack::Core & DF = Core::getInstance();
DFHack::World *Wold = 0;
if(!config.skipWorld)
@@ -655,12 +656,6 @@ WorldSegment* ReadMapSegment(DFHack::Core &DF, int x, int y, int z, int sizex, i
return new WorldSegment(x,y,z + 1,sizex,sizey,sizez + 1);
}
- //read memory info
- if( memInfoHasBeenRead == false){
- dfMemoryInfo = DF.vinfo;
- memInfoHasBeenRead = true;
- }
-
//if (timeToReloadConfig)
//{
// contentLoader->Load(DF);
@@ -704,7 +699,7 @@ WorldSegment* ReadMapSegment(DFHack::Core &DF, int x, int y, int z, int sizex, i
vector< vector <uint16_t> > layers;
if(!Maps::ReadGeology( layers ))
{
- WriteErr("Can't get region geology.\n");
+ LogError("Can't get region geology.\n");
}
//read cursor
@@ -1059,23 +1054,25 @@ void read_segment( void *arg)
return;
static bool firstLoad = 1;
config.threadstarted = 1;
-
- pDFApiHandle->Suspend();
- if (firstLoad || config.follow_DFscreen)
+ WorldSegment * segment = 0;
+ // Suspended block
{
- firstLoad = 0;
- if (config.track_center)
- {
- FollowCurrentDFCenter();
- }
- else
+ CoreSuspender suspend;
+ if (firstLoad || config.follow_DFscreen)
{
- FollowCurrentDFWindow();
+ firstLoad = 0;
+ if (config.track_center)
+ {
+ FollowCurrentDFCenter();
+ }
+ else
+ {
+ FollowCurrentDFWindow();
+ }
}
+ segment = ReadMapSegment(parms.x, parms.y, parms.z,parms.sizex, parms.sizey, parms.sizez);
+ config.threadstarted = 0;
}
- WorldSegment * segment = ReadMapSegment(*pDFApiHandle, parms.x, parms.y, parms.z,parms.sizex, parms.sizey, parms.sizez);
- config.threadstarted = 0;
- pDFApiHandle->Resume();
beautify_Segment(segment);
map_segment->lock();
WorldSegment* old_segment = map_segment->swap(segment);
@@ -1099,11 +1096,9 @@ static void * threadedSegment(ALLEGRO_THREAD *read_thread, void *arg)
return 0;
}
-void reloadDisplayedSegment(DFHack::Core * c){
+void reloadDisplayedSegment(){
//create handle to dfHack API
static bool firstLoad = 1;
- DFHack::Core & DF = *c;
- pDFApiHandle = c;
TMR1_START;
#ifndef RELEASE
@@ -1113,7 +1108,7 @@ void reloadDisplayedSegment(DFHack::Core * c){
if (timeToReloadConfig)
{
parms.thread_connect = 0;
- contentLoader->Load(DF);
+ contentLoader->Load();
timeToReloadConfig = false;
}
diff --git a/MapLoading.h b/MapLoading.h
index cc5906d..c3d2292 100644
--- a/MapLoading.h
+++ b/MapLoading.h
@@ -11,7 +11,7 @@
inline bool IDisWall(int in);
inline bool IDisFloor(int in);
-void reloadDisplayedSegment(DFHack::Core * DF);
+void reloadDisplayedSegment();
void beautify_Segment(WorldSegment * segment);
void DisconnectFromDF();
diff --git a/UserInput.cpp b/UserInput.cpp
index 4f7d190..45a83c6 100644
--- a/UserInput.cpp
+++ b/UserInput.cpp
@@ -198,7 +198,7 @@ void doKeys(){
}
}
-void doKeys(int Key, DFHack::Core * c)
+void doKeys(int Key)
{
al_get_keyboard_state(&keyboard);
if(Key == ALLEGRO_KEY_ENTER){
@@ -210,7 +210,7 @@ void doKeys(int Key, DFHack::Core * c)
timeToReloadSegment = true;
}
if(Key == ALLEGRO_KEY_D){
- paintboard(c);
+ paintboard();
}
if(Key == ALLEGRO_KEY_G){
//contentLoader.reload_configs();
@@ -291,11 +291,11 @@ void doKeys(int Key, DFHack::Core * c)
else if (al_key_down(&keyboard,ALLEGRO_KEY_ALT) || al_key_down(&keyboard,ALLEGRO_KEY_ALTGR))
dumpSegment();
else
- saveScreenshot(c);
+ saveScreenshot();
}
if(Key == ALLEGRO_KEY_PAD_PLUS){
config.automatic_reload_time += config.automatic_reload_step;
- paintboard(c);
+ paintboard();
initAutoReload();
}
if(Key == ALLEGRO_KEY_PAD_MINUS && config.automatic_reload_time){
@@ -309,7 +309,7 @@ void doKeys(int Key, DFHack::Core * c)
}
else
initAutoReload();
- paintboard(c);
+ paintboard();
}
if(Key == ALLEGRO_KEY_F9)
{
@@ -321,22 +321,22 @@ void doKeys(int Key, DFHack::Core * c)
if(Key == ALLEGRO_KEY_PAD_8){
config.follow_DFcursor = false;
debugCursor.y--;
- paintboard(c);
+ paintboard();
}
if(Key == ALLEGRO_KEY_PAD_2){
config.follow_DFcursor = false;
debugCursor.y++;
- paintboard(c);
+ paintboard();
}
if(Key == ALLEGRO_KEY_PAD_4){
config.follow_DFcursor = false;
debugCursor.x--;
- paintboard(c);
+ paintboard();
}
if(Key == ALLEGRO_KEY_PAD_6){
config.follow_DFcursor = false;
debugCursor.x++;
- paintboard(c);
+ paintboard();
}
if(Key == ALLEGRO_KEY_F10)
diff --git a/common.h b/common.h
index 52f29ab..0ee8145 100644
--- a/common.h
+++ b/common.h
@@ -164,7 +164,7 @@ class SegmentWrap;
//main.cpp
void correctBlockForSegmetOffset(int32_t& x, int32_t& y, int32_t& z);
-void WriteErr(const char* msg, ...);
+void LogError(const char* msg, ...);
void LogVerbose(const char* msg, ...);
void SetTitle(const char *format, ...);
@@ -196,7 +196,7 @@ void correctBlockForRotation(int32_t& x, int32_t& y, int32_t& z, unsigned char r
//from UserInput.cpp
void doKeys();
-void doKeys(int key, DFHack::Core * c);
+void doKeys(int key);
void initAutoReload();
void abortAutoReload();
@@ -260,7 +260,5 @@ enum MAT_BASICS
extern int randomCube[RANDOM_CUBE][RANDOM_CUBE][RANDOM_CUBE];
-extern DFHack::Console * DFConsole;
-
ALLEGRO_COLOR premultiply(ALLEGRO_COLOR input);
using namespace std;
diff --git a/main.cpp b/main.cpp
index d1f9b54..9c78e33 100644
--- a/main.cpp
+++ b/main.cpp
@@ -59,8 +59,6 @@ int mouse_x, mouse_y, mouse_z;
unsigned int mouse_b;
bool key[ALLEGRO_KEY_MAX];
-DFHack::Console * DFConsole;
-
/// main thread of stonesense - handles events
ALLEGRO_THREAD *stonesense_event_thread;
bool redraw = true;
@@ -71,7 +69,7 @@ ALLEGRO_BITMAP* load_bitmap_withWarning(const char* path)
img = al_load_bitmap(path);
if(!img)
{
- DFConsole->printerr("Cannot load image: %s\n", path);
+ LogError("Cannot load image: %s\n", path);
al_set_thread_should_stop(stonesense_event_thread);
return 0;
}
@@ -80,7 +78,7 @@ ALLEGRO_BITMAP* load_bitmap_withWarning(const char* path)
}
-void WriteErr(const char* msg, ...){
+void LogError(const char* msg, ...){
va_list arglist;
va_start(arglist, msg);
// char buf[200] = {0};
@@ -137,7 +135,7 @@ void correctBlockForSegmetOffset(int32_t& x, int32_t& y, int32_t& z){
z -= DisplayedSegmentZ - 1; // + viewedSegment->sizez - 2; // loading one above the top of the displayed segment for block rules
}
-bool loadfont()
+bool loadfont(DFHack::color_ostream & output)
{
ALLEGRO_PATH * p = al_create_path_for_directory("stonesense");
if(!al_join_paths(p, config.font))
@@ -148,7 +146,7 @@ bool loadfont()
font = al_load_font(al_path_cstr(p, ALLEGRO_NATIVE_PATH_SEP), config.fontsize, 0);
if (!font)
{
- DFConsole->printerr("Cannot load font: %s\n", al_path_cstr(p, ALLEGRO_NATIVE_PATH_SEP));
+ output.printerr("Cannot load font: %s\n", al_path_cstr(p, ALLEGRO_NATIVE_PATH_SEP));
al_destroy_path(p);
return false;
}
@@ -156,13 +154,13 @@ bool loadfont()
return true;
}
-void benchmark(DFHack::Core * c){
+void benchmark(){
DisplayedSegmentX = DisplayedSegmentY = 0;
DisplayedSegmentX = 110; DisplayedSegmentY = 110;DisplayedSegmentZ = 18;
uint32_t startTime = clock();
int i = 20;
while(i--)
- reloadDisplayedSegment(c);
+ reloadDisplayedSegment();
FILE* fp = fopen("benchmark.txt", "w" );
if(!fp) return;
@@ -230,7 +228,7 @@ void drawcredits()
* little CPU time. See main() to see how the event sources and event queue
* are set up.
*/
-static void main_loop(ALLEGRO_DISPLAY * display, ALLEGRO_EVENT_QUEUE *queue, ALLEGRO_THREAD * main_thread, DFHack::Console & con, DFHack::Core * core)
+static void main_loop(ALLEGRO_DISPLAY * display, ALLEGRO_EVENT_QUEUE *queue, ALLEGRO_THREAD * main_thread, DFHack::color_ostream & con)
{
ALLEGRO_EVENT event;
while (!al_get_thread_should_stop(main_thread))
@@ -247,16 +245,16 @@ static void main_loop(ALLEGRO_DISPLAY * display, ALLEGRO_EVENT_QUEUE *queue, ALL
drawcredits();
}
else if( timeToReloadSegment ){
- reloadDisplayedSegment(core);
+ reloadDisplayedSegment();
al_clear_to_color(al_map_rgb(config.backr,config.backg,config.backb));
- paintboard(core);
+ paintboard();
timeToReloadSegment = false;
animationFrameShown = true;
}
else if (animationFrameShown == false)
{
al_clear_to_color(al_map_rgb(config.backr,config.backg,config.backb));
- paintboard(core);
+ paintboard();
animationFrameShown = true;
}
doKeys();
@@ -282,7 +280,7 @@ static void main_loop(ALLEGRO_DISPLAY * display, ALLEGRO_EVENT_QUEUE *queue, ALL
case ALLEGRO_EVENT_DISPLAY_RESIZE:
if(!al_acknowledge_resize(event.display.source))
{
- DFConsole->printerr("Failed to resize diplay");
+ con.printerr("Failed to resize diplay");
return;
}
timeToReloadSegment = true;
@@ -295,7 +293,7 @@ static void main_loop(ALLEGRO_DISPLAY * display, ALLEGRO_EVENT_QUEUE *queue, ALL
int h = al_get_bitmap_height(bb);
config.screenHeight = h;
config.screenWidth = w;
- WriteErr("backbuffer w, h: %d, %d\n", w, h);
+ LogError("backbuffer w, h: %d, %d\n", w, h);
}
#endif
/* ALLEGRO_EVENT_KEY_DOWN - a keyboard key was pressed.
@@ -309,7 +307,7 @@ static void main_loop(ALLEGRO_DISPLAY * display, ALLEGRO_EVENT_QUEUE *queue, ALL
}
else
{
- doKeys(event.keyboard.keycode, core);
+ doKeys(event.keyboard.keycode);
redraw = true;
}
break;
@@ -343,8 +341,8 @@ static void main_loop(ALLEGRO_DISPLAY * display, ALLEGRO_EVENT_QUEUE *queue, ALL
//replacement for main()
static void * stonesense_thread(ALLEGRO_THREAD * main_thread, void * parms)
{
- DFHack::Core * c = (DFHack::Core * )parms;
- DFConsole->print("Stonesense launched\n");
+ color_ostream_proxy out(Core::getInstance().getConsole());
+ out.print("Stonesense launched\n");
config.debug_mode = false;
config.hide_outer_blocks = false;
@@ -390,7 +388,7 @@ static void * stonesense_thread(ALLEGRO_THREAD * main_thread, void * parms)
initRandomCube();
loadConfigFile();
init_masks();
- if(!loadfont())
+ if(!loadfont(out))
{
stonesense_started = 0;
return NULL;
@@ -405,13 +403,13 @@ static void * stonesense_thread(ALLEGRO_THREAD * main_thread, void * parms)
int revision = (version >> 8) & 255;
int release = version & 255;
- DFConsole->print("Using allegro version %d.%d.%d r%d\n", major, minor, revision, release);
+ out.print("Using allegro version %d.%d.%d r%d\n", major, minor, revision, release);
int gfxMode = config.Fullscreen ? ALLEGRO_FULLSCREEN : ALLEGRO_WINDOWED;
al_set_new_display_flags(gfxMode|ALLEGRO_RESIZABLE|(config.opengl ? ALLEGRO_OPENGL : 0)|(config.directX ? ALLEGRO_DIRECT3D_INTERNAL : 0));
display = al_create_display(config.screenWidth, config.screenHeight);
if (!display) {
- c->con.printerr("al_create_display failed\n");
+ out.printerr("al_create_display failed\n");
stonesense_started = 0;
return NULL;
}
@@ -419,14 +417,14 @@ static void * stonesense_thread(ALLEGRO_THREAD * main_thread, void * parms)
{
if (!al_install_keyboard())
{
- DFConsole->printerr("Stonesense: al_install_keyboard failed\n");
+ out.printerr("Stonesense: al_install_keyboard failed\n");
}
}
if(!al_is_mouse_installed())
{
if (!al_install_mouse())
{
- DFConsole->printerr("Stonesense: al_install_mouse failed\n");
+ out.printerr("Stonesense: al_install_mouse failed\n");
}
}
SetTitle("Stonesense");
@@ -450,7 +448,7 @@ static void * stonesense_thread(ALLEGRO_THREAD * main_thread, void * parms)
ALLEGRO_EVENT_QUEUE *queue;
queue = al_create_event_queue();
if (!queue) {
- c->con.printerr("al_create_event_queue failed\n");
+ out.printerr("al_create_event_queue failed\n");
stonesense_started = 0;
return NULL;
}
@@ -487,7 +485,7 @@ static void * stonesense_thread(ALLEGRO_THREAD * main_thread, void * parms)
timeToReloadSegment = true;
// enter event loop here:
- main_loop(display, queue, main_thread, c->con, c);
+ main_loop(display, queue, main_thread, out);
// window is destroyed.
al_destroy_display(display);
@@ -514,19 +512,19 @@ static void * stonesense_thread(ALLEGRO_THREAD * main_thread, void * parms)
IMGIcon = 0;
delete contentLoader;
contentLoader = 0;
- DFConsole->print("Stonesense shutdown.\n");
+ out.print("Stonesense shutdown.\n");
stonesense_started = 0;
return NULL;
}
//All this fun DFhack stuff I gotta do now.
-DFhackCExport command_result stonesense_command(DFHack::Core * c, std::vector<std::string> & params);
+DFhackCExport command_result stonesense_command(color_ostream &out, std::vector<std::string> & params);
//set the plugin name/dfhack version
DFHACK_PLUGIN("stonesense");
//This is the init command. it includes input options.
-DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
+DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("stonesense","Start up the stonesense visualiser.",stonesense_command));
@@ -535,13 +533,13 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
}
//this command is called every frame DF.
-DFhackCExport command_result plugin_onupdate ( Core * c )
+DFhackCExport command_result plugin_onupdate ( color_ostream &out )
{
return CR_OK;
}
//And the shutdown command.
-DFhackCExport command_result plugin_shutdown ( Core * c )
+DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{
if(stonesense_event_thread)
al_join_thread(stonesense_event_thread, NULL);
@@ -550,40 +548,39 @@ DFhackCExport command_result plugin_shutdown ( Core * c )
}
//and the actual stonesense command. Maybe.
-DFhackCExport command_result stonesense_command(DFHack::Core * c, std::vector<std::string> & params)
+DFhackCExport command_result stonesense_command(color_ostream &out, std::vector<std::string> & params)
{
if(stonesense_started)
{
- c->con.print("Stonesense already running.\n");
+ out.print("Stonesense already running.\n");
return CR_OK;
}
stonesense_started = true;
- DFConsole = &(c->con);
if(!al_is_system_installed())
{
if (!al_init()) {
- DFConsole->printerr("Could not init Allegro.\n");
+ out.printerr("Could not init Allegro.\n");
return CR_FAILURE;
}
if (!al_init_image_addon())
{
- DFConsole->printerr("al_init_image_addon failed. \n");
+ out.printerr("al_init_image_addon failed. \n");
return CR_FAILURE;
}
if (!al_init_primitives_addon()) {
- DFConsole->printerr("al_init_primitives_addon failed. \n");
+ out.printerr("al_init_primitives_addon failed. \n");
return CR_FAILURE;
}
al_init_font_addon();
if (!al_init_ttf_addon())
{
- DFConsole->printerr("al_init_ttf_addon failed. \n");
+ out.printerr("al_init_ttf_addon failed. \n");
return CR_FAILURE;
}
}
- stonesense_event_thread = al_create_thread(stonesense_thread, (void * )c);
+ stonesense_event_thread = al_create_thread(stonesense_thread, (void*) &out);
al_start_thread(stonesense_event_thread);
return CR_OK;
}