[Gcblue-commits] gcb_wx/src/database tcSonarDBObject.cpp,NONE,1.1 tcDatabase.cpp,1.20,1.21 tcStoresD
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-12-02 04:18:13
|
Update of /cvsroot/gcblue/gcb_wx/src/database In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31820/src/database Modified Files: tcDatabase.cpp tcStoresDBObject.cpp Added Files: tcSonarDBObject.cpp Log Message: Sonar work --- NEW FILE: tcSonarDBObject.cpp --- /** ** @file tcSonarDBObject.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" #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 "tcSonarDBObject.h" #include "tcSonar.h" #include "common/tinyxml.h" #include "database/tcSqlReader.h" #include <sstream> //#include "tcSonar.h" #ifdef _DEBUG #define new DEBUG_NEW #endif namespace Database { /** * Calculate parameters based on database values. * e.g. alpha, attenuation coefficient */ void tcSonarDBObject::CalculateParams() { // Thorp eqn float freq_avg_kHz = 0.0005 * (minFrequency_Hz + maxFrequency_Hz); if (freq_avg_kHz < 0) freq_avg_kHz = 2.0f; float f2 = freq_avg_kHz * freq_avg_kHz; alpha = (0.1f * f2 / (1.0 + f2)) + (40.0f * f2 / (4100.0f + f2)) + (2.75e-4f * f2) + 0.003; alpha *= 1.0936133f; // convert dB/kyd to dB/km } tcSensorState* tcSonarDBObject::CreateSensor(tcGameObject* parent) { tcSonar* sonar = new tcSonar(this); sonar->SetParent(parent); return sonar; } /** * workaround for write serialization issue * @return true if db obj is a leaf obj */ bool tcSonarDBObject::IsLeaf() const { return mnClassID == DTYPE_SONAR; } /** * */ void tcSonarDBObject::PrintToFile(tcFile& file) { tcString s; tcSensorDBObject::PrintToFile(file); s.Format(" SL: %f, passive: %d, alpha: %f dB/km\n", SL, isPassive, alpha); file.WriteString(s.GetBuffer()); } /** * */ int tcSonarDBObject::Serialize(tcFile& file, bool mbLoad, UINT32 anVersion) { if (anVersion <= VERSION_1_0_3) { tcSensorDBObject::Serialize(file, mbLoad, anVersion); if (mbLoad) { wxASSERT(false); } else { wxASSERT(false); } return true; } else { tcSensorDBObject::Serialize(file,mbLoad,anVersion); if (mbLoad) { wxASSERT(false); } else { wxASSERT(false); } return true; } } /** * Loads/saves XML data for database object * @param load true to load, false to save */ void tcSonarDBObject::SerializeXml(TiXmlElement* node, bool load) { if (load) return; // write only for now wxASSERT(node); TiXmlElement* localNode = node->InsertEndChild(TiXmlElement("sonar"))->ToElement(); localNode->SetAttribute("SL", SL); localNode->SetAttribute("DI", DI); localNode->SetAttribute("DT", DT); localNode->SetAttribute("DTr", DTr); localNode->SetAttribute("minFrequency_Hz", minFrequency_Hz); localNode->SetAttribute("maxFrequency_Hz", maxFrequency_Hz); localNode->SetAttribute("isPassive", (int)isPassive); localNode->SetAttribute("audioFile", audioFile.c_str()); tcSensorDBObject::SerializeXml(node, load); } /** * Adds sql column definitions to columnString. This is used for * SQL create table command */ void tcSonarDBObject::AddSqlColumns(std::string& columnString) { tcSensorDBObject::AddSqlColumns(columnString); columnString += ","; columnString += "SL number(4),"; columnString += "DI number(4),"; columnString += "DT number(4),"; columnString += "DTr number(4),"; columnString += "minFrequency_Hz number(5),"; columnString += "maxFrequency_Hz number(5),"; columnString += "isPassive number(1),"; columnString += "audioFile varchar(30)"; } void tcSonarDBObject::ReadSql(tcSqlReader& entry) { tcSensorDBObject::ReadSql(entry); SL = entry.GetDouble("SL"); DI = entry.GetDouble("DI"); DT = entry.GetDouble("DT"); DTr = entry.GetDouble("DTr"); minFrequency_Hz = entry.GetDouble("minFrequency_Hz"); maxFrequency_Hz = entry.GetDouble("maxFrequency_Hz"); isPassive = entry.GetInt("isPassive") != 0; audioFile = entry.GetString("audioFile"); } void tcSonarDBObject::WriteSql(std::string& valueString) { tcSensorDBObject::WriteSql(valueString); std::stringstream s; s << ","; s << SL << ","; s << DI << ","; s << DT << ","; s << DTr << ","; s << minFrequency_Hz << ","; s << maxFrequency_Hz << ","; s << (long)isPassive << ","; s << "'" << audioFile.c_str() << "'"; valueString += s.str(); } tcSonarDBObject::tcSonarDBObject() : tcSensorDBObject(), SL(10), DI(3), DT(3), DTr(3), minFrequency_Hz(2000), maxFrequency_Hz(3000), isPassive(false) { mzClass = "Default Sonar"; mnClassID = DTYPE_SONAR; mfMaxRange_km = 10.0f; mfRefRange_km = 1.0f; mfFieldOfView_deg = 90.0f; mfScanPeriod_s = 4.0f; CalculateParams(); } tcSonarDBObject::tcSonarDBObject(tcSonarDBObject& obj) : tcSensorDBObject(obj), SL(obj.SL), DI(obj.DI), DT(obj.DT), DTr(obj.DTr), minFrequency_Hz(obj.minFrequency_Hz), maxFrequency_Hz(obj.maxFrequency_Hz), isPassive(obj.isPassive) { mnClassID = DTYPE_SONAR; CalculateParams(); } tcSonarDBObject::~tcSonarDBObject() { } } Index: tcDatabase.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcDatabase.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** tcDatabase.cpp 29 Nov 2004 03:55:04 -0000 1.20 --- tcDatabase.cpp 2 Dec 2004 04:17:24 -0000 1.21 *************** *** 43,46 **** --- 43,47 ---- #include "tcOpticalDBObject.h" #include "tcESMDBObject.h" + #include "tcSonarDBObject.h" #include "tcFixedDBObject.h" #include "tcAirDBObject.h" *************** *** 273,276 **** --- 274,284 ---- else serializer.Save(); } + // tcSonarDBObject + { + tcDBObjSerializerSql<tcSonarDBObject> + serializer(this, sqlConnection, "sonar"); + if (load) serializer.Load(); + else serializer.Save(); + } // tcAirDBObject { Index: tcStoresDBObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcStoresDBObject.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tcStoresDBObject.cpp 29 Nov 2004 03:55:05 -0000 1.1 --- tcStoresDBObject.cpp 2 Dec 2004 04:17:24 -0000 1.2 *************** *** 42,45 **** --- 42,55 ---- { + /** + * workaround for write serialization issue + * @return true if db obj is a leaf obj + */ + bool tcStoresDBObject::IsLeaf() const + { + return mnClassID == DTYPE_STORES; + } + + void tcStoresDBObject::PrintToFile(tcFile& file) { *************** *** 192,196 **** s << ","; ! s << "'" << displayName << "',"; s << capacity << ","; s << moveTime << ","; --- 202,206 ---- s << ","; ! s << "'" << displayName.c_str() << "',"; s << capacity << ","; s << moveTime << ","; |