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

@ -38,14 +38,6 @@ using namespace std;
#include "dfhack/modules/Notes.h" #include "dfhack/modules/Notes.h"
using namespace DFHack; using namespace DFHack;
struct Notes::Private
{
uint32_t notes_vector;
Process * owner;
bool Inited;
bool Started;
};
Module* DFHack::createNotes() Module* DFHack::createNotes()
{ {
return new Notes(); return new Notes();
@ -55,48 +47,17 @@ Notes::Notes()
{ {
Core & c = Core::getInstance(); Core & c = Core::getInstance();
d = new Private; notes = NULL;
d->owner = c.p;
d->Inited = d->Started = false;
VersionInfo * mem = c.vinfo; VersionInfo * mem = c.vinfo;
d->Inited = true;
try try
{ {
OffsetGroup * OG_Notes = mem->getGroup("Notes"); 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) catch(DFHack::Error::AllMemdef &e)
{ {
c.con << "Notes not available... " << e.what() << endl; notes = NULL;
d->Inited = false; cerr << "Notes not available... " << e.what() << endl;
}
}
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;
} }
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(); c->Suspend();
DFHack::Notes * note_mod = c->getNotes(); 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) if (note_list == NULL)
{ {
con << "No notes yet." << std::endl; con.printerr("Notes are not supported under this version of DF.\n");
c->Resume(); c->Resume();
return CR_OK; return CR_OK;
} }
if (note_list->empty()) if (note_list->empty())
{ {
con << "All notes deleted." << std::endl; con << "There are no notes." << std::endl;
c->Resume(); c->Resume();
return CR_OK; return CR_OK;
} }
@ -58,7 +58,7 @@ DFhackCExport command_result df_notes (Core * c, vector <string> & parameters)
{ {
t_note* note = (*note_list)[i]; 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 id: %d\n", note->id);
con.print("Note symbol: '%c'\n", note->symbol); con.print("Note symbol: '%c'\n", note->symbol);