Minimize notes module.

develop
Petr Mrázek 2011-07-23 03:25:42 +02:00
parent 35cf108040
commit caf6f881df
3 changed files with 25 additions and 70 deletions

@ -23,20 +23,19 @@ namespace DFHack
{
// First note created has id 0, second has id 1, etc. Not affected
// by lower id notes being deleted.
uint32_t id;
uint32_t id; // 0
uint8_t symbol; // 4
uint8_t unk1; // alignment padding?
uint16_t foreground; // 6
uint16_t background; // 8
uint16_t unk2; // alignment padding?
uint8_t symbol;
uint8_t unk1;
uint16_t foreground;
uint16_t background;
uint16_t unk2;
std::string name; // C
std::string text; // 10
std::string name;
std::string text;
uint16_t x;
uint16_t y;
uint16_t z;
uint16_t x; // 14
uint16_t y; // 16
uint16_t z; // 18
// Is there more?
};
@ -52,17 +51,12 @@ namespace DFHack
{
public:
Notes();
~Notes();
bool Finish();
// Returns NULL if there's no notes yet.
std::vector<t_note*>* getNotes();
private:
struct Private;
Private *d;
~Notes(){};
bool Finish()
{
return true;
}
std::vector<t_note*>* notes;
};
}

@ -38,14 +38,6 @@ using namespace std;
#include "dfhack/modules/Notes.h"
using namespace DFHack;
struct Notes::Private
{
uint32_t notes_vector;
Process * owner;
bool Inited;
bool Started;
};
Module* DFHack::createNotes()
{
return new Notes();
@ -55,48 +47,17 @@ Notes::Notes()
{
Core & c = Core::getInstance();
d = new Private;
d->owner = c.p;
d->Inited = d->Started = false;
notes = NULL;
VersionInfo * mem = c.vinfo;
d->Inited = true;
try
{
OffsetGroup * OG_Notes = mem->getGroup("Notes");
d->notes_vector = OG_Notes->getAddress("vector");
notes = (std::vector<t_note*>*) OG_Notes->getAddress("vector");
}
catch(DFHack::Error::AllMemdef &e)
{
c.con << "Notes not available... " << e.what() << endl;
d->Inited = false;
}
}
Notes::~Notes()
{
delete d;
}
std::vector<t_note*>* Notes::getNotes()
{
if (!d->Inited)
{
Core & c = Core::getInstance();
c.con << "Notes not available... " << endl;
return NULL;
notes = NULL;
cerr << "Notes not available... " << e.what() << endl;
}
uint32_t ptr = d->notes_vector;
if ( *( (uint32_t*) ptr) == 0)
// Notes vector not set up yet.
return NULL;
return (std::vector<t_note*>*) ptr;
}
bool Notes::Finish()
{
return true;
}

@ -37,18 +37,18 @@ DFhackCExport command_result df_notes (Core * c, vector <string> & parameters)
c->Suspend();
DFHack::Notes * note_mod = c->getNotes();
std::vector<t_note*>* note_list = note_mod->getNotes();
std::vector<t_note*>* note_list = note_mod->notes;
if (note_list == NULL)
{
con << "No notes yet." << std::endl;
con.printerr("Notes are not supported under this version of DF.\n");
c->Resume();
return CR_OK;
}
if (note_list->empty())
{
con << "All notes deleted." << std::endl;
con << "There are no notes." << std::endl;
c->Resume();
return CR_OK;
}
@ -58,7 +58,7 @@ DFhackCExport command_result df_notes (Core * c, vector <string> & parameters)
{
t_note* note = (*note_list)[i];
con.print("Note at: %d/%d/%d\n", note->x, note->y, note->z);
con.print("Note %x at: %d/%d/%d\n",note, note->x, note->y, note->z);
con.print("Note id: %d\n", note->id);
con.print("Note symbol: '%c'\n", note->symbol);