From 7ce31ae48369c502f2e170d2db5f00b160e89515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 12 Nov 2009 17:50:50 +0000 Subject: [PATCH] shallow copy fix from belal --- library/DFHackAPI.cpp | 7 +-- library/DFProcess.cpp | 14 ++--- library/DFTypes.h | 116 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 127 insertions(+), 10 deletions(-) diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index 3ebc5bb2a..39debc14f 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -372,9 +372,10 @@ bool API::ReadStoneMatgloss(vector & stones) int matgloss_colors = minfo->getOffset("matgloss_stone_color"); DfVector p_matgloss = d->dm->readVector(matgloss_address + matgloss_offset, 4); - stones.clear(); - - for (uint32_t i = 0; i< p_matgloss.getSize();i++) + int size = p_matgloss.getSize(); + stones.resize(0); + stones.reserve(size); + for (uint32_t i = 0; i< size;i++) { uint32_t temp; // read the matgloss pointer from the vector into temp diff --git a/library/DFProcess.cpp b/library/DFProcess.cpp index 9d4bbfe52..82ac00365 100644 --- a/library/DFProcess.cpp +++ b/library/DFProcess.cpp @@ -71,6 +71,7 @@ void Process::setMemFile(const string & memf) */ +/* //TODO: rewrite this. really. It's ugly as hell. bool isStopped(pid_t pid) { @@ -99,7 +100,7 @@ bool isStopped(pid_t pid) cerr << "couldn't open file " << filename << "assuming process stopped" << endl; return true; } - +*/ bool Process::attach() { int status; @@ -109,6 +110,7 @@ bool Process::attach() { return false; } + /* if(!isStopped(my_handle)) { // kill (SIGSTOP) @@ -126,6 +128,7 @@ bool Process::attach() //cout << "wait step" << endl; } } + */ //usleep(10000); //cout << "Attach: after conditional stop" << endl; // can we attach? @@ -138,7 +141,6 @@ bool Process::attach() } //usleep(10000); //cout << "Attach: after ptrace" << endl; - /* while(true) { // we wait on the pid @@ -156,8 +158,8 @@ bool Process::attach() { break; } - }*/ - // cout << "Managed to attach to pid " << my_handle << endl; + } + // cout << "Managed to attach to pid " << my_handle << endl; int proc_pid_mem = open(memFile.c_str(),O_RDONLY); if(proc_pid_mem == -1) @@ -209,8 +211,8 @@ bool Process::detach() g_pProcess = NULL; g_ProcessHandle = 0; // continue, wait for it to recover - kill(my_handle,SIGCONT); - while (isStopped(my_handle)); + // kill(my_handle,SIGCONT); + // while (isStopped(my_handle)); //usleep(10000); // we finish return true; diff --git a/library/DFTypes.h b/library/DFTypes.h index 4ccc28688..300595787 100644 --- a/library/DFTypes.h +++ b/library/DFTypes.h @@ -384,6 +384,19 @@ struct t_labor { string name; uint8_t value; + t_labor() { + value =0; + } + t_labor(const t_labor & b){ + name=b.name; + value=b.value; + } + t_labor & operator=(const t_labor &b){ + name=b.name; + value=b.value; + return *this; + } + }; struct t_skill { @@ -391,6 +404,25 @@ struct t_skill uint16_t id; uint32_t experience; uint16_t rating; + t_skill(){ + id=rating=0; + experience=0; + } + t_skill(const t_skill & b) + { + name=b.name; + id=b.id; + experience=b.experience; + rating=b.rating; + } + t_skill & operator=(const t_skill &b) + { + name=b.name; + id=b.id; + experience=b.experience; + rating=b.rating; + return *this; + } }; struct t_trait @@ -398,6 +430,22 @@ struct t_trait uint16_t value; string displayTxt; string name; + t_trait(){ + value=0; + } + t_trait(const t_trait &b) + { + name=b.name; + displayTxt=b.displayTxt; + value=b.value; + } + t_trait & operator=(const t_trait &b) + { + name=b.name; + displayTxt=b.displayTxt; + value=b.value; + return *this; + } }; struct t_creature @@ -410,7 +458,7 @@ struct t_creature t_creaturflags2 flags2; string first_name; string nick_name; - string last_name; + //string last_name; string trans_name; string generic_name; string generic_squad_name; @@ -429,6 +477,72 @@ struct t_creature vector skills; vector traits; vector labors; + t_creature() { + x=y=z=0; + type=happiness=id=agility=strength=toughness=money=0; + squad_leader_id = -1; + sex=0; + } + t_creature(const t_creature & b) + { + x = b.x; + y = b.y; + z = b.z; + type = b.type; + flags1 = b.flags1; + flags2 = b.flags2; + first_name = b.first_name; + nick_name = b.nick_name; + //string last_name; + trans_name = b.trans_name; + generic_name = b.generic_name; + generic_squad_name = b.generic_squad_name; + trans_squad_name = b.trans_squad_name; + profession = b.profession; + custom_profession = b.custom_profession; + current_job = b.current_job; + happiness = b.happiness; + id = b.id; + agility = b.agility; + strength = b.strength; + toughness = b.toughness; + money = b.money; + squad_leader_id = b.squad_leader_id; + sex = b.sex; + skills = b.skills; + traits = b.traits; + labors = b.labors; + } + t_creature & operator=(const t_creature &b) + { + x = b.x; + y = b.y; + z = b.z; + type = b.type; + flags1 = b.flags1; + flags2 = b.flags2; + first_name = b.first_name; + nick_name = b.nick_name; + //string last_name; + trans_name = b.trans_name; + generic_name = b.generic_name; + generic_squad_name = b.generic_squad_name; + trans_squad_name = b.trans_squad_name; + profession = b.profession; + custom_profession = b.custom_profession; + current_job = b.current_job; + happiness = b.happiness; + id = b.id; + agility = b.agility; + strength = b.strength; + toughness = b.toughness; + money = b.money; + squad_leader_id = b.squad_leader_id; + sex = b.sex; + skills = b.skills; + traits = b.traits; + return *this; + } }; // TODO: research this further? consult DF hacker wizards?