[Gcblue-commits] gcb_wx/src/database tcSensorPlatformDBObject.cpp,NONE,1.1 tcDatabase.cpp,1.22,1.23
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-03-04 00:47:01
|
Update of /cvsroot/gcblue/gcb_wx/src/database In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11821/src/database Modified Files: tcDatabase.cpp tcGenericDBObject.cpp Added Files: tcSensorPlatformDBObject.cpp Log Message: Better sensor ageout behavior, more ai work, misc cleanup Index: tcGenericDBObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcGenericDBObject.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** tcGenericDBObject.cpp 2 Mar 2005 22:28:42 -0000 1.20 --- tcGenericDBObject.cpp 4 Mar 2005 00:46:16 -0000 1.21 *************** *** 2,6 **** ** @file tcGenericDBObject.cpp */ ! /* Copyright (C) 2003 Dewitt Colclough (de...@tw...) ** All rights reserved. --- 2,6 ---- ** @file tcGenericDBObject.cpp */ ! /* Copyright (C) 2003-2005 Dewitt Colclough (de...@tw...) ** All rights reserved. *************** *** 113,143 **** } - /** - * This checks that the database object has all of the emitters in the - * emitters vector. Somewhat expensive, nEmitters * nSensors - * comparisons for positive result, fewer for negative result. - * @return true if this database object has all of the emitters - */ - bool tcGenericDBObject::HasAllEmitters(std::vector<long>& emitters) - { - unsigned int nEmitters = emitters.size(); - if ((int)nEmitters > mnNumSensors) return false; - - /* watch out for problems with this lazy init done inside this method - ** sensorId will not be available until this is called first */ - if (sensorId.size() == 0) UpdateSensorList(); - - for (unsigned int k=0; k<nEmitters; k++) - { - bool bFound = false; - long emitterId = emitters[k]; - for (int n=0; (n<mnNumSensors) && !bFound; n++) - { - if (sensorId[n] == emitterId) bFound = true; - } - if (!bFound) return false; - } - return true; - } /** --- 113,116 ---- *************** *** 185,189 **** mnNumLaunchers = 0; mnNumMagazines = 0; - mnNumSensors = 0; flightportClass = ""; } --- 158,161 ---- *************** *** 205,208 **** --- 177,182 ---- file.WriteString(s.GetBuffer()); } + + tcSensorPlatformDBObject::PrintToFile(file); for(int i=0; i<mnNumMagazines; i++) *************** *** 250,258 **** ! file.Read(&mnNumSensors,sizeof(mnNumSensors)); ! for(i=0;i<mnNumSensors;i++) ! { ! file.Read(&maSensorClass[i],sizeof(tcDBString)); ! } } else --- 224,229 ---- ! // sensor serialization not supported ! wxASSERT(false); } else *************** *** 285,293 **** } ! file.Write(&mnNumSensors,sizeof(mnNumSensors)); ! for(i=0;i<mnNumSensors;i++) ! { ! file.Write(&maSensorClass[i],sizeof(tcDBString)); ! } } return true; --- 256,261 ---- } ! // sensor serialization not supported ! wxASSERT(false); } return true; *************** *** 329,344 **** } } ! mnNumSensors = 0; ! for(i=0;i<MAXSENSORS;i++) ! { ! float az; ! *csv >> s; ! *csv >> az; ! if (s.size() > 0) ! { ! maSensorClass[mnNumSensors] = s.c_str(); ! sensorAz[mnNumSensors++] = az; ! } ! } wxASSERT(false); // need magazine code --- 297,303 ---- } } ! ! tcSensorPlatformDBObject::SerializeCSV(csv, mbLoad); ! wxASSERT(false); // need magazine code *************** *** 391,407 **** wxASSERT(false); // need magazine code ! for(i=0;i<MAXSENSORS;i++) ! { ! if (i<mnNumSensors) ! { ! *csv << string(maSensorClass[i].mz); ! *csv << sensorAz[i]; ! } ! else ! { ! *csv << ""; ! *csv << ""; ! } ! } size_t nAnimations = animationInfo.size(); for(size_t i=0;i<MAXANIMATIONS;i++) --- 350,355 ---- wxASSERT(false); // need magazine code ! tcSensorPlatformDBObject::SerializeCSV(csv, mbLoad); ! size_t nAnimations = animationInfo.size(); for(size_t i=0;i<MAXANIMATIONS;i++) *************** *** 473,482 **** } ! for(i=0;(i<mnNumSensors)&&(i<MAXSENSORS);i++) ! { ! TiXmlElement* childNode = node->InsertEndChild(TiXmlElement("sensor"))->ToElement(); ! childNode->SetAttribute("class", maSensorClass[i].mz); ! childNode->SetAttribute("az", sensorAz[i]); ! } for(std::vector<animationDBInfo>::iterator iter = animationInfo.begin() --- 421,427 ---- } ! ! tcSensorPlatformDBObject::SerializeXml(node, load); ! for(std::vector<animationDBInfo>::iterator iter = animationInfo.begin() *************** *** 519,530 **** *csv << s.GetBuffer(); } ! for(i=0;i<MAXSENSORS;i++) ! { ! tcString s; ! s.Format("Sensor%d",i+1); ! *csv << s.GetBuffer(); ! s.Format("Sensor%d-angle",i+1); ! *csv << s.GetBuffer(); ! } wxASSERT(false); // need magazine code --- 464,469 ---- *csv << s.GetBuffer(); } ! ! tcSensorPlatformDBObject::WriteCSVHeader(csv); wxASSERT(false); // need magazine code *************** *** 544,569 **** } ! /** ! * Updates sensorId vector with database ids for each sensor ! */ ! void tcGenericDBObject::UpdateSensorList() ! { ! sensorId.clear(); ! for(int n=0; n<mnNumSensors; n++) ! { ! std::string sensorClass = maSensorClass[n].mz; ! tcDatabaseObject* obj = database->GetObject(sensorClass); ! if (obj) ! { ! sensorId.push_back(obj->mnKey); ! } ! else ! { ! fprintf(stderr, "Error - tcGenericDBObject::UpdateSensorList - sensor %s not found\n", ! sensorClass.c_str()); ! sensorId.push_back(-1); ! } ! } ! } /** --- 483,487 ---- } ! /** *************** *** 609,628 **** { tcString s; ! s.Format("M%d_class varchar(30),", i+1); ! columnString += s.GetBuffer(); ! } ! ! for(i=0;i<MAXSENSORS;i++) ! { ! tcString s; ! s.Format("S%d_class varchar(30),",i+1); ! columnString += s.GetBuffer(); ! ! s.Format("S%d_az number(8)",i+1); columnString += s.GetBuffer(); ! if (i < MAXSENSORS - 1) columnString += ","; } } --- 527,540 ---- { tcString s; ! s.Format("M%d_class varchar(30)", i+1); columnString += s.GetBuffer(); ! if (i < MAXMAGAZINES - 1) ! { ! columnString += ","; ! } } + tcSensorPlatformDBObject::AddSqlColumns(columnString); } *************** *** 693,718 **** } ! ! // read sensors ! mnNumSensors = 0; ! for(i=0;i<MAXSENSORS;i++) ! { ! std::string sensorClass; ! tcString s; ! ! s.Format("S%d_class", i+1); ! sensorClass = entry.GetString(s.GetBuffer()); ! ! if (sensorClass.size() > 0) ! { ! maSensorClass[mnNumSensors] = sensorClass.c_str(); ! ! s.Format("S%d_az", i+1); ! sensorAz[mnNumSensors++] = entry.GetDouble(s.GetBuffer()); ! } ! ! } ! ! } --- 605,609 ---- } ! tcSensorPlatformDBObject::ReadSql(entry); } *************** *** 746,750 **** int i; ! for(i=0;i<MAXLAUNCHERS;i++) { if (i < mnNumLaunchers) --- 637,641 ---- int i; ! for(i=0; i<MAXLAUNCHERS; i++) { if (i < mnNumLaunchers) *************** *** 765,800 **** if (i < mnNumMagazines) { ! s << "'" << string(maMagazineClass[i].mz) << "',"; } else { ! s << "'',"; } - } - - - for(i=0;i<MAXSENSORS;i++) - { - if (i<mnNumSensors) - { - s << "'" << string(maSensorClass[i].mz) << "',"; - s << sensorAz[i]; - } - else - { - s << "'',"; - s << "0"; - } - if (i < MAXSENSORS - 1) s << ","; - } - valueString += s.str(); ! } ! tcGenericDBObject::tcGenericDBObject() : tcDatabaseObject() { mnClassID = DTYPE_GENERIC; --- 656,680 ---- if (i < mnNumMagazines) { ! s << "'" << string(maMagazineClass[i].mz) << "'"; } else { ! s << "''"; } + if (i < MAXMAGAZINES - 1) + { + s << ","; + } + } valueString += s.str(); ! ! tcSensorPlatformDBObject::WriteSql(valueString); } ! tcGenericDBObject::tcGenericDBObject() : tcDatabaseObject(), ! tcSensorPlatformDBObject() { mnClassID = DTYPE_GENERIC; *************** *** 815,820 **** mfRange_km = 0; mnNumLaunchers = 0; ! mnNumMagazines = 0; ! mnNumSensors = 0; flightportClass = ""; animationInfo.clear(); --- 695,699 ---- mfRange_km = 0; mnNumLaunchers = 0; ! mnNumMagazines = 0; flightportClass = ""; animationInfo.clear(); *************** *** 822,826 **** tcGenericDBObject::tcGenericDBObject(tcGenericDBObject& obj) ! : tcDatabaseObject(obj) { mnClassID = DTYPE_GENERIC; --- 701,705 ---- tcGenericDBObject::tcGenericDBObject(tcGenericDBObject& obj) ! : tcDatabaseObject(obj), tcSensorPlatformDBObject(obj) { mnClassID = DTYPE_GENERIC; *************** *** 842,846 **** mnNumLaunchers = obj.mnNumLaunchers; mnNumMagazines = obj.mnNumMagazines; ! mnNumSensors = obj.mnNumSensors; int i; for(i=0;i<mnNumLaunchers;i++) --- 721,725 ---- mnNumLaunchers = obj.mnNumLaunchers; mnNumMagazines = obj.mnNumMagazines; ! int i; for(i=0;i<mnNumLaunchers;i++) *************** *** 855,864 **** } - for(i=0;i<MAXSENSORS;i++) - { - maSensorClass[i] = obj.maSensorClass[i]; - sensorAz[i] = obj.sensorAz[i]; - } - flightportClass = obj.flightportClass; animationInfo.clear(); --- 734,737 ---- --- NEW FILE: tcSensorPlatformDBObject.cpp --- /** ** @file tcSensorPlatformDBObject.cpp */ /* Copyright (C) 2005 Dewitt Colclough (de...@tw...) ** All rights reserved. ** This file is part of the Global Conflict Blue (GCB) program. ** GCB is free software; you can redistribute it and/or modify ** it under the terms of version 2 of the GNU General Public License as ** published by the Free Software Foundation. ** GCB is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** You should have received a copy of the GNU General Public License ** along with GCB; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "stdwx.h" #if _MSC_VER > 1000 #pragma warning(disable:4786) // suppress warning for STL bug in VC6, see Q167355 in the MSDN Library. #endif #include "tcSensorPlatformDBObject.h" #include "tcDatabase.h" #include "math_constants.h" #include "randfn.h" #include "CsvTranslator.h" #include "common/tinyxml.h" #include "common/tcFile.h" #include "database/tcSqlReader.h" #include "database/CsvTranslator.h" #include <sstream> #ifdef _DEBUG #define new DEBUG_NEW #endif using namespace std; namespace Database { /** * This checks that the database object has all of the emitters in the * emitters vector. Somewhat expensive, nEmitters * nSensors * comparisons for positive result, fewer for negative result. * @return true if this database object has all of the emitters */ bool tcSensorPlatformDBObject::HasAllEmitters(std::vector<long>& emitters) { unsigned int nEmitters = emitters.size(); size_t nSensors = sensorClass.size(); if ((int)nEmitters > nSensors) return false; /* watch out for problems with this lazy init done inside this method ** sensorId will not be available until this is called first */ if (sensorId.size() == 0) UpdateSensorList(); for (unsigned int k=0; k<nEmitters; k++) { bool bFound = false; long emitterId = emitters[k]; for (size_t n=0; (n<nSensors) && !bFound; n++) { if (sensorId[n] == emitterId) bFound = true; } if (!bFound) return false; } return true; } void tcSensorPlatformDBObject::PrintToFile(tcFile& file) { } int tcSensorPlatformDBObject::SerializeCSV(Database::CsvTranslator *csv, bool mbLoad) { if (mbLoad) { sensorClass.clear(); sensorAz.clear(); sensorId.clear(); for(int i=0; i<MAXSENSORS; i++) { std::string s; float az; *csv >> s; *csv >> az; if (s.size() > 0) { sensorClass.push_back(s); sensorAz.push_back(az); } } } else { size_t nSensors = sensorClass.size(); for(size_t i=0; i<MAXSENSORS; i++) { if (i<nSensors) { *csv << sensorClass[i]; *csv << sensorAz[i]; } else { *csv << ""; *csv << ""; } } csv->WriteLine(); } return 1; } /** * Loads/saves XML data for database object * @param load true to load, false to save */ void tcSensorPlatformDBObject::SerializeXml(TiXmlElement* node, bool load) { if (load) return; // write only for now wxASSERT(node); for(size_t i=0;(i<sensorClass.size())&&(i<MAXSENSORS);i++) { TiXmlElement* childNode = node->InsertEndChild(TiXmlElement("sensor"))->ToElement(); childNode->SetAttribute("class", sensorClass[i]); childNode->SetAttribute("az", sensorAz[i]); } } int tcSensorPlatformDBObject::WriteCSVHeader(Database::CsvTranslator *csv) { int i; for(i=0;i<MAXSENSORS;i++) { tcString s; s.Format("Sensor%d",i+1); *csv << s.GetBuffer(); s.Format("Sensor%d-angle",i+1); *csv << s.GetBuffer(); } csv->WriteLine(); return 1; } /** * Updates sensorId vector with database ids for each sensor */ void tcSensorPlatformDBObject::UpdateSensorList() { sensorId.clear(); tcDatabase* database = tcDatabase::Get(); for(size_t n=0; n<sensorClass.size(); n++) { tcDatabaseObject* obj = database->GetObject(sensorClass[n]); if (obj) { sensorId.push_back(obj->mnKey); } else { fprintf(stderr, "Error - tcSensorPlatformDBObject::UpdateSensorList - sensor %s not found\n", sensorClass[n].c_str()); sensorId.push_back(-1); } } } /** * Adds sql column definitions to columnString. This is used for * SQL create table command */ void tcSensorPlatformDBObject::AddSqlColumns(std::string& columnString) { columnString += ","; for(int i=0;i<MAXSENSORS;i++) { tcString s; s.Format("S%d_class varchar(30),",i+1); columnString += s.GetBuffer(); s.Format("S%d_az number(8)",i+1); columnString += s.GetBuffer(); if (i < MAXSENSORS - 1) columnString += ","; } } void tcSensorPlatformDBObject::ReadSql(tcSqlReader& entry) { sensorClass.clear(); sensorAz.clear(); sensorId.clear(); for(int i=0;i<MAXSENSORS;i++) { std::string className; tcString s; s.Format("S%d_class", i+1); className = entry.GetString(s.GetBuffer()); if (className.size() > 0) { sensorClass.push_back(className); s.Format("S%d_az", i+1); sensorAz.push_back(entry.GetDouble(s.GetBuffer())); } } } void tcSensorPlatformDBObject::WriteSql(std::string& valueString) { std::stringstream s; s << ","; for(size_t i=0; i<MAXSENSORS; i++) { if (i < sensorClass.size()) { s << "'" << sensorClass[i] << "',"; s << sensorAz[i]; } else { s << "'',"; s << "0"; } if (i < MAXSENSORS - 1) s << ","; } valueString += s.str(); } tcSensorPlatformDBObject::tcSensorPlatformDBObject() { } tcSensorPlatformDBObject::tcSensorPlatformDBObject(tcSensorPlatformDBObject& obj) : sensorClass(obj.sensorClass), sensorAz(obj.sensorAz), sensorId(obj.sensorId) { } tcSensorPlatformDBObject::~tcSensorPlatformDBObject() { } } Index: tcDatabase.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcDatabase.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** tcDatabase.cpp 5 Dec 2004 02:49:47 -0000 1.22 --- tcDatabase.cpp 4 Mar 2005 00:46:16 -0000 1.23 *************** *** 1072,1076 **** * @return NULL if not found */ ! tcDatabaseObject* tcDatabase::GetObject(std::string className) { std::map<std::string, long>::iterator mapIter = nameToKey.find(className); --- 1072,1076 ---- * @return NULL if not found */ ! tcDatabaseObject* tcDatabase::GetObject(const std::string& className) { std::map<std::string, long>::iterator mapIter = nameToKey.find(className); *************** *** 1082,1113 **** return GetObject(mapIter->second); - #if 0 - tcDatabaseIterator iter(0xFFF0); - for (iter.First(); !iter.IsDone(); iter.Next()) - { - tcDatabaseObject* obj = iter.Get(); - wxASSERT(obj); - wxASSERT(obj->mnKey != -1); - - std::string className = obj->mzClass.mz; - - - - - tnPoolIndex nPoolSize = mcObjectData.GetCount(); - tnPoolIndex key = mcObjectData.GetStartPosition(); - tcDatabaseObject *obj; - - for (int i=0;i<nPoolSize;i++) - { - key = mcObjectData.GetNextKey(key); - if (mcObjectData.Lookup(key,obj)==false) {return NULL;} // error - if (className == obj->mzClass.mz) - { - return obj; - } - } - return NULL; // not found - #endif } --- 1082,1085 ---- |