[Gcblue-commits] gcb_wx/src/database tcDatabaseIterator.cpp,NONE,1.1 tcOpticalDBObject.cpp,NONE,1.1
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-11-06 15:14:45
|
Update of /cvsroot/gcblue/gcb_wx/src/database In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31472/src/database Modified Files: tcBallisticDBObject.cpp tcDatabase.cpp tcESMDBObject.cpp tcGenericDBObject.cpp tcMissileDBObject.cpp tcRadarDBObject.cpp tcSensorDBObject.cpp Added Files: tcDatabaseIterator.cpp tcOpticalDBObject.cpp Log Message: Added optical sensor model, fixed generic model display for sensor tracks --- NEW FILE: tcDatabaseIterator.cpp --- /** ** @file tcDatabaseIterator.cpp */ /* Copyright (C) 2004 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" // precompiled header file #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "tcDatabaseIterator.h" #include "tcDatabase.h" #include "tcDatabaseObject.h" #ifdef _DEBUG #define new DEBUG_NEW #endif namespace Database { tcDatabase* tcDatabaseIterator::database = 0; void tcDatabaseIterator::First() { nSize = database->mcObjectData.GetCount(); nIterated = 0; if (nSize == 0) { currentPos = -1; currentObj = 0; nIterated = 1; return; } currentPos = database->mcObjectData.GetStartPosition(); Next(); } tcDatabaseObject* tcDatabaseIterator::Get() { return currentObj; } /** * Advance to next object in pool that meets filter criteria. If * no objects are found, set currentObj to NULL */ void tcDatabaseIterator::Next() { bool searching = true; while ((nIterated <= nSize) && searching) { long id; if (nIterated < nSize) // kind of a hack, nIterated > nSize is used for end condition { database->mcObjectData.GetNextAssoc(currentPos, id, currentObj); } nIterated++; if (PassesMask(currentObj)) { searching = false; // found eligible object } else { currentObj = 0; } } } bool tcDatabaseIterator::IsDone() { return (nIterated > nSize); } /** * Checks currentObj against mask (filtering) criteria. This is used * to iterate through a filtered set of objects. * @return true if current obj meets mask criteria, false otherwise */ bool tcDatabaseIterator::PassesMask(const tcDatabaseObject* obj) { if (obj == 0) return false; if (mask == 0) return true; bool coarsePasses = (obj->mnType & mask & 0xFFF0) != 0; bool finePasses = (obj->mnType & mask & 0x000F) != 0; // if mask has fine classification set then use it, otherwise ignore if (mask & 0x000F) { return coarsePasses && finePasses; } else { return coarsePasses; } } /** * @param classificationMask use 0 to pass all */ tcDatabaseIterator::tcDatabaseIterator(unsigned int classificationMask) : mask(classificationMask) { if (database == 0) { database = tcDatabase::Get(); } First(); } tcDatabaseIterator::~tcDatabaseIterator() { } } Index: tcESMDBObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcESMDBObject.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** tcESMDBObject.cpp 2 Nov 2004 04:23:55 -0000 1.7 --- tcESMDBObject.cpp 6 Nov 2004 15:13:41 -0000 1.8 *************** *** 1,6 **** ! /* ! ** tcESMDBObject.cpp ! ** ! ** Copyright (C) 2003 Dewitt Colclough (de...@tw...) ** All rights reserved. --- 1,6 ---- ! /** ! ** @file tcESMDBObject.cpp ! */ ! /* Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. *************** *** 28,33 **** #include "tcESMDBObject.h" ! #include "math_constants.h" ! #include "randfn.h" //#include "AError.h" #include "CsvTranslator.h" --- 28,34 ---- #include "tcESMDBObject.h" ! #include "tcESMSensor.h" ! //#include "math_constants.h" ! //#include "randfn.h" //#include "AError.h" #include "CsvTranslator.h" *************** *** 42,45 **** --- 43,54 ---- { + tcSensorState* tcESMDBObject::CreateSensor(tcGameObject* parent) + { + tcESMSensor* esm = new tcESMSensor(this); + esm->SetParent(parent); + + return esm; + } + void tcESMDBObject::PrintToFile(tcFile& file) { Index: tcSensorDBObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcSensorDBObject.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** tcSensorDBObject.cpp 2 Nov 2004 04:23:55 -0000 1.8 --- tcSensorDBObject.cpp 6 Nov 2004 15:13:41 -0000 1.9 *************** *** 1,6 **** ! /* ! ** tcSensorDBObject.cpp ! ** ! ** Copyright (C) 2003 Dewitt Colclough (de...@tw...) ** All rights reserved. --- 1,6 ---- ! /** ! ** @file tcSensorDBObject.cpp ! */ ! /* Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. *************** *** 27,37 **** #include "tcSensorDBObject.h" ! #include "math_constants.h" ! #include "randfn.h" #include "CsvTranslator.h" #include "common/tinyxml.h" #include "database/tcSqlReader.h" #include <sstream> #ifdef _DEBUG #define new DEBUG_NEW --- 27,40 ---- #include "tcSensorDBObject.h" ! //#include "math_constants.h" ! //#include "randfn.h" #include "CsvTranslator.h" #include "common/tinyxml.h" #include "database/tcSqlReader.h" + #include "tcSensorState.h" // for factory method + #include "tcGameObject.h" // for factory method #include <sstream> + #ifdef _DEBUG #define new DEBUG_NEW *************** *** 43,46 **** --- 46,55 ---- { + tcSensorState* tcSensorDBObject::CreateSensor(tcGameObject* parent) + { + return 0; + } + + void tcSensorDBObject::PrintToFile(tcFile& file) { Index: tcRadarDBObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcRadarDBObject.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** tcRadarDBObject.cpp 2 Nov 2004 04:23:55 -0000 1.13 --- tcRadarDBObject.cpp 6 Nov 2004 15:13:41 -0000 1.14 *************** *** 1,6 **** ! /** @file tcRadarDBObject.cpp */ ! /* ! ** Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. --- 1,6 ---- ! /** ! ** @file tcRadarDBObject.cpp */ ! /* Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. *************** *** 27,36 **** #include "tcRadarDBObject.h" ! #include "math_constants.h" ! #include "randfn.h" #include "CsvTranslator.h" #include "common/tinyxml.h" #include "database/tcSqlReader.h" #include <sstream> #ifdef _DEBUG --- 27,37 ---- #include "tcRadarDBObject.h" ! //#include "math_constants.h" ! //#include "randfn.h" #include "CsvTranslator.h" #include "common/tinyxml.h" #include "database/tcSqlReader.h" #include <sstream> + #include "tcRadar.h" #ifdef _DEBUG *************** *** 41,44 **** --- 42,53 ---- { + tcSensorState* tcRadarDBObject::CreateSensor(tcGameObject* parent) + { + tcRadar* radar = new tcRadar(this); + radar->SetParent(parent); + + return radar; + } + /******************************** tcRadarDBObject ***********************************/ *************** *** 57,61 **** if (anVersion <= VERSION_1_0_3) { ! tcDatabaseObject::Serialize(file,mbLoad,anVersion); if (mbLoad) { --- 66,70 ---- if (anVersion <= VERSION_1_0_3) { ! tcSensorDBObject::Serialize(file,mbLoad,anVersion); if (mbLoad) { Index: tcBallisticDBObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcBallisticDBObject.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** tcBallisticDBObject.cpp 2 Nov 2004 04:23:55 -0000 1.6 --- tcBallisticDBObject.cpp 6 Nov 2004 15:13:41 -0000 1.7 *************** *** 152,156 **** //TiXmlElement* localNode = ! node->InsertEndChild(TiXmlElement("sensor"))->ToElement(); //localNode->SetAttribute("maxRange_km" ,mfMaxRange_km); --- 152,156 ---- //TiXmlElement* localNode = ! node->InsertEndChild(TiXmlElement("ballistic"))->ToElement(); //localNode->SetAttribute("maxRange_km" ,mfMaxRange_km); --- NEW FILE: tcOpticalDBObject.cpp --- /** ** @file tcOpticalDBObject.cpp */ /* ** Copyright (C) 2003-2004 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 // _MSC_VER > 1000 #include "tcOpticalDBObject.h" #include "tcOpticalSensor.h" #include "common/tinyxml.h" #include "database/tcSqlReader.h" #include <sstream> #ifdef _DEBUG #define new DEBUG_NEW #endif namespace Database { tcSensorState* tcOpticalDBObject::CreateSensor(tcGameObject* parent) { tcOpticalSensor* optical = new tcOpticalSensor(this); optical->SetParent(parent); return optical; } /******************************** tcOpticalDBObject ***********************************/ void tcOpticalDBObject::PrintToFile(tcFile& file) { tcString s; tcDatabaseObject::PrintToFile(file); s.Format(" ref range: %3.1f km, night: %.2f, IR: %d\n", mfRefRange_km, nightFactor, isIR); file.WriteString(s.GetBuffer()); } int tcOpticalDBObject::Serialize(tcFile& file, bool mbLoad, UINT32 anVersion) { tcSensorDBObject::Serialize(file,mbLoad,anVersion); if (mbLoad) { file.Read(&mbDetectsSurface,sizeof(mbDetectsSurface)); file.Read(&mbDetectsAir,sizeof(mbDetectsAir)); file.Read(&mbDetectsGround,sizeof(mbDetectsGround)); file.Read(&isIR,sizeof(isIR)); file.Read(&nightFactor,sizeof(nightFactor)); } else { file.Write(&mbDetectsSurface,sizeof(mbDetectsSurface)); file.Write(&mbDetectsAir,sizeof(mbDetectsAir)); file.Write(&mbDetectsGround,sizeof(mbDetectsGround)); file.Write(&isIR,sizeof(isIR)); file.Write(&nightFactor,sizeof(nightFactor)); } return true; } /** * Loads/saves XML data for database object * @param load true to load, false to save */ void tcOpticalDBObject::SerializeXml(TiXmlElement* node, bool load) { if (load) return; // write only for now wxASSERT(node); TiXmlElement* localNode = node->InsertEndChild(TiXmlElement("radar"))->ToElement(); localNode->SetAttribute("detectsSurface", (int)mbDetectsSurface); localNode->SetAttribute("detectsAir", (int)mbDetectsAir); localNode->SetAttribute("detectsGround", (int)mbDetectsGround); localNode->SetAttribute("IsIR", (int)isIR); localNode->SetAttribute("NightFactor", nightFactor); tcSensorDBObject::SerializeXml(node, load); } /** * Adds sql column definitions to columnString. This is used for * SQL create table command */ void tcOpticalDBObject::AddSqlColumns(std::string& columnString) { tcSensorDBObject::AddSqlColumns(columnString); columnString += ","; columnString += "DetectsSurface number(1),"; columnString += "DetectsAir number(1),"; columnString += "DetectsGround number(1),"; columnString += "IsIR number(1),"; columnString += "NightFactor number(5)"; } void tcOpticalDBObject::ReadSql(tcSqlReader& entry) { tcSensorDBObject::ReadSql(entry); mbDetectsSurface = entry.GetInt("DetectsSurface") != 0; mbDetectsAir = entry.GetInt("DetectsAir") != 0; mbDetectsGround = entry.GetInt("DetectsGround") != 0; isIR = entry.GetInt("IsIR") != 0; nightFactor = entry.GetDouble("NightFactor"); } void tcOpticalDBObject::WriteSql(std::string& valueString) { tcSensorDBObject::WriteSql(valueString); std::stringstream s; s << ","; s << (long)mbDetectsSurface << ","; s << (long)mbDetectsAir << ","; s << (long)mbDetectsGround << ","; s << (long)isIR << ","; s << nightFactor; valueString += s.str(); } tcOpticalDBObject::tcOpticalDBObject() : tcSensorDBObject() { mzClass = "Default Optical"; mnClassID = DTYPE_OPTICAL; mfMaxRange_km = 20.0f; mfRefRange_km = 0.5f; mfFieldOfView_deg = 360.0f; mfScanPeriod_s = 5.0f; mbDetectsSurface = true; mbDetectsAir = true; mbDetectsGround = true; isIR = false; nightFactor = 1.0f; } tcOpticalDBObject::tcOpticalDBObject(tcOpticalDBObject& obj) : tcSensorDBObject(obj) { mnClassID = DTYPE_OPTICAL; mbDetectsSurface = obj.mbDetectsSurface; mbDetectsAir = obj.mbDetectsAir; mbDetectsGround = obj.mbDetectsGround; isIR = obj.isIR; nightFactor = obj.nightFactor; } tcOpticalDBObject::~tcOpticalDBObject() { } } Index: tcDatabase.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcDatabase.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** tcDatabase.cpp 2 Nov 2004 04:23:55 -0000 1.18 --- tcDatabase.cpp 6 Nov 2004 15:13:41 -0000 1.19 *************** *** 29,34 **** #include "tcDatabase.h" ! #include "math_constants.h" ! #include "randfn.h" #include "AError.h" #include <iostream> --- 29,33 ---- #include "tcDatabase.h" ! #include "AError.h" #include <iostream> *************** *** 42,45 **** --- 41,45 ---- #include "tcSensorDBObject.h" #include "tcRadarDBObject.h" + #include "tcOpticalDBObject.h" #include "tcESMDBObject.h" #include "tcFixedDBObject.h" *************** *** 47,50 **** --- 47,51 ---- #include "tcFlightportDBObject.h" #include "tcBallisticDBObject.h" + #include "tcDatabaseIterator.h" #include "common/tinyxml.h" #include "sqlite/sqlite_plus.h" *************** *** 69,72 **** --- 70,108 ---- } + + /** + * Should be called once after the database is loaded or modified + */ + void tcDatabase::BuildDictionaries() + { + nameToKey.clear(); + + std::map<std::string, long>::iterator mapIter; + + tcDatabaseIterator iter(0); + for (iter.First(); !iter.IsDone(); iter.Next()) + { + tcDatabaseObject* obj = iter.Get(); + wxASSERT(obj); + wxASSERT(obj->mnKey != -1); + + std::string className = obj->mzClass.mz; + + mapIter = nameToKey.find(className); + if (mapIter == nameToKey.end()) + { + nameToKey[className] = obj->mnKey; + } + else + { + fprintf(stderr, "Error - tcDatabase::BuildDictionaries - " + "duplicate class name in database (ignoring)\n"); + } + + } + + } + + /** * Serialization is replicated for each leaf class type. This *************** *** 229,232 **** --- 265,275 ---- else serializer.Save(); } + // tcOpticalDBObject + { + tcDBObjSerializerSql<tcOpticalDBObject> + serializer(this, sqlConnection, "optical"); + if (load) serializer.Load(); + else serializer.Save(); + } // tcAirDBObject { *************** *** 251,256 **** } ! ! } --- 294,298 ---- } ! BuildDictionaries(); } *************** *** 349,352 **** --- 391,401 ---- } break; + case DTYPE_OPTICAL: + { + tcOpticalDBObject* optical = new tcOpticalDBObject; + if (optical) {nResult = optical->Serialize(file,true,mnVersion);} + pdbobj = static_cast<tcDatabaseObject*>(pradar); + } + break; default: // error, unrecognized ClassID break; *************** *** 407,410 **** --- 456,465 ---- } break; + case DTYPE_OPTICAL: + { + tcOpticalDBObject* optical = dynamic_cast<tcOpticalDBObject*>(pdbobj); + if (optical) {nResult = optical->Serialize(file,false,mnVersion);} + } + break; default: // error, unrecognized ClassID break; *************** *** 996,999 **** --- 1051,1075 ---- tcDatabaseObject* tcDatabase::GetObject(std::string className) { + std::map<std::string, long>::iterator mapIter = nameToKey.find(className); + if (mapIter == nameToKey.end()) + { + fprintf(stderr, "Error - tcDatabase::GetObject - not found in nameToKey\n"); + return 0; + } + + 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(); *************** *** 1010,1013 **** --- 1086,1090 ---- } return NULL; // not found + #endif } Index: tcMissileDBObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcMissileDBObject.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** tcMissileDBObject.cpp 2 Nov 2004 04:23:55 -0000 1.11 --- tcMissileDBObject.cpp 6 Nov 2004 15:13:41 -0000 1.12 *************** *** 77,80 **** --- 77,101 ---- } + /** + * 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. + * Modified tcGenericDBObject method + * @see tcGenericDBObject::HasAllEmitters + * @return true if this database object has all of the emitters + */ + bool tcMissileDBObject::HasAllEmitters(std::vector<long>& emitters) + { + unsigned int nEmitters = emitters.size(); + + for (unsigned int k=0; k<nEmitters; k++) + { + long emitterId = emitters[k]; + + if (primarySeekerKey != emitterId) return false; + } + return true; + } + void tcMissileDBObject::PrintToFile(tcFile& file) { Index: tcGenericDBObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcGenericDBObject.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** tcGenericDBObject.cpp 2 Nov 2004 04:23:55 -0000 1.13 --- tcGenericDBObject.cpp 6 Nov 2004 15:13:41 -0000 1.14 *************** *** 82,85 **** --- 82,113 ---- } + /** + * 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; + } + void tcGenericDBObject::RandInit() { *************** *** 465,468 **** --- 493,519 ---- /** + * 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); + } + } + } + + /** * Adds sql column definitions to columnString. This is used for * SQL create table command |