From caf6f881df78b99b2f62e21effc4025d1b5ad9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 23 Jul 2011 03:25:42 +0200 Subject: [PATCH] Minimize notes module. --- library/include/dfhack/modules/Notes.h | 40 ++++++++++------------ library/modules/Notes.cpp | 47 +++----------------------- plugins/notes.cpp | 8 ++--- 3 files changed, 25 insertions(+), 70 deletions(-) diff --git a/library/include/dfhack/modules/Notes.h b/library/include/dfhack/modules/Notes.h index bb95cd5d8..8339c1cdc 100644 --- a/library/include/dfhack/modules/Notes.h +++ b/library/include/dfhack/modules/Notes.h @@ -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* getNotes(); - - private: - struct Private; - Private *d; - + ~Notes(){}; + bool Finish() + { + return true; + } + std::vector* notes; }; } diff --git a/library/modules/Notes.cpp b/library/modules/Notes.cpp index aeb7902ef..293077a5d 100644 --- a/library/modules/Notes.cpp +++ b/library/modules/Notes.cpp @@ -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*) 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* 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*) ptr; -} - -bool Notes::Finish() -{ - return true; } diff --git a/plugins/notes.cpp b/plugins/notes.cpp index 989d3a348..32b436121 100644 --- a/plugins/notes.cpp +++ b/plugins/notes.cpp @@ -37,18 +37,18 @@ DFhackCExport command_result df_notes (Core * c, vector & parameters) c->Suspend(); DFHack::Notes * note_mod = c->getNotes(); - std::vector* note_list = note_mod->getNotes(); + std::vector* 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 & 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);