Skip to content

Commit

Permalink
AutoSave specie
Browse files Browse the repository at this point in the history
  • Loading branch information
cybiosphere committed Oct 13, 2024
1 parent f2967a7 commit d3005ce
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
14 changes: 10 additions & 4 deletions WpCommon/inc/StartupHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ inline void createBiotopAndScenarioFromIniFile(const string& fileIni, CBiotop**
CScenarioPlayer* pScenarioPlayer{ nullptr };
char resuBuffer[512];

int resu = getStringSectionFromFile("CYBIOSPHERE", "Biotop", "", resuBuffer, 512, fileIni);
getStringSectionFromFile("CYBIOSPHERE", "Biotop", "", resuBuffer, 512, fileIni);
string biotopName = resuBuffer;
clearWindowsEolIfNeeded(biotopName);

if (biotopName != "")
{
string resuDataPath;
pBiotop = new CBiotop(0, 0, 0);
bool resu = getStringSectionFromFile("CYBIOSPHERE", "DataPath", "", resuBuffer, 512, fileIni);
getStringSectionFromFile("CYBIOSPHERE", "DataPath", "", resuBuffer, 512, fileIni);
resuDataPath = resuBuffer;
clearWindowsEolIfNeeded(resuDataPath);
if (resuDataPath != "")
Expand All @@ -104,14 +104,14 @@ inline void createBiotopAndScenarioFromIniFile(const string& fileIni, CBiotop**
}

pScenarioPlayer = new CScenarioPlayer(pBiotop);
resu = getStringSectionFromFile("CYBIOSPHERE", "Scenario", "", resuBuffer, 512, fileIni);
getStringSectionFromFile("CYBIOSPHERE", "Scenario", "", resuBuffer, 512, fileIni);
string scenarioName = resuBuffer;
clearWindowsEolIfNeeded(scenarioName);

if (scenarioName != "")
{
string resuDataPath;
bool resu = getStringSectionFromFile("CYBIOSPHERE", "DataPath", "", resuBuffer, 512, fileIni);
getStringSectionFromFile("CYBIOSPHERE", "DataPath", "", resuBuffer, 512, fileIni);
resuDataPath = resuBuffer;
clearWindowsEolIfNeeded(resuDataPath);
if (resuDataPath != "")
Expand All @@ -124,6 +124,12 @@ inline void createBiotopAndScenarioFromIniFile(const string& fileIni, CBiotop**
pScenarioPlayer->NextCmdNextSecond();
}

string resuSpecieName;
getStringSectionFromFile("CYBIOSPHERE", "AutoSaveSpecie", "", resuBuffer, 512, fileIni);
resuSpecieName = resuBuffer;
if (resuSpecieName != "")
pBiotop->setAutoSaveSpecieName(resuSpecieName);

*pNewBiotop = pBiotop;
*pNewScenarioPlayer = pScenarioPlayer;
}
Expand Down
3 changes: 3 additions & 0 deletions WpEnvironment/inc/CBiotop.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class DLL_CYBIOCORE_API CBiotop
bool m_bColorizeSearch;
CGene m_GeneToMark{};
bool m_bMarkDominantAlleleOnly{ false };
string m_AutoSaveSpecieName{ "" };

//---------------------------------------------------------------------------
// associations
Expand Down Expand Up @@ -434,6 +435,7 @@ class DLL_CYBIOCORE_API CBiotop
CGeoMapPopulation* getGeoMapSpecieByIndex(size_t index);
void saveAllGeoMapsInFile(string fileNameWithPath);
void saveAllRecordsInFiles();
void saveAllEntitiesOfSpecie(string specieName);

private:
timeCountType getNextSmallestTimeCountInAllMeasures(timeCountType previousSmallestTimeCount);
Expand Down Expand Up @@ -521,6 +523,7 @@ class DLL_CYBIOCORE_API CBiotop
bool getMarkDominantAlleleOnly();
void setGlobalGridDimension(size_t dimX, size_t dimY);
void setGlobalGridCoordOffset(Point_t startingCoord);
void setAutoSaveSpecieName(string specieName);

}; // end CBiotop

Expand Down
34 changes: 30 additions & 4 deletions WpEnvironment/src/CBiotop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ CBiotop* CBiotop::extractNewBiotopFromArea(Point_t startCoord, size_t dimX, size
|| ((startCoord.x + dimX) > m_Dimension.x) || ((startCoord.y + dimY) > m_Dimension.y))
{
CYBIOCORE_LOG_TIME(m_BioTime);
CYBIOCORE_LOG("ERROR - Try to exctract Arean with invalid coord\n");
CYBIOCORE_LOG("ERROR - Try to exctract Arean with invalid coord startX=%u sizeX=%u\n", startCoord.x, dimX);
return NULL;
}

Expand Down Expand Up @@ -752,12 +752,12 @@ size_t CBiotop::getNbOfMinerals()
return (tempCount);
}

size_t CBiotop::getNbOfSpecieEntities(string& SpecieName)
size_t CBiotop::getNbOfSpecieEntities(string& specieName)
{
size_t tempCount = 0;
for (CBasicEntity* pEntity : m_tEntity)
{
if ((pEntity->getSpecieName() == SpecieName) && (pEntity->isAlive() || (pEntity->getStatus() == STATUS_STATIC)))
if ((pEntity->getSpecieName() == specieName) && (pEntity->isAlive() || (pEntity->getStatus() == STATUS_STATIC)))
tempCount++;
}
return (tempCount);
Expand Down Expand Up @@ -1706,11 +1706,15 @@ void CBiotop::nextDay(void)
m_BioTime.years++;
}

// Automatic metric record in files every 2 days
// Automatic metric records
if ((m_BioTime.days % 2) == 1)
{
saveAllRecordsInFiles();
}
if ((m_AutoSaveSpecieName != "") && ((m_BioTime.days % 100) == 0))
{
saveAllEntitiesOfSpecie(m_AutoSaveSpecieName);
}
}

void CBiotop::nextHourForAllEntities(void)
Expand Down Expand Up @@ -2349,6 +2353,22 @@ void CBiotop::saveAllRecordsInFiles()
saveAllGeoMapsInFile(geomapFileName);
}

void CBiotop::saveAllEntitiesOfSpecie(string specieName)
{
string path = m_DefaultFilePath + "/AutoSave/";
CYBIOCORE_LOG_TIME(m_BioTime);
CYBIOCORE_LOG("BIOTOP - Save all entities of specie name %s path %s\n", specieName.c_str(), path.c_str());

for (CBasicEntity* pCurEntity : m_tEntity)
{
if (pCurEntity->getSpecieName() == specieName)
{
string entityFileName{ path + pCurEntity->getLabel() + ".xml"};
pCurEntity->saveInXmlFile(entityFileName);
}
}
}

//===========================================================================
// Event management
//===========================================================================
Expand Down Expand Up @@ -3213,3 +3233,9 @@ void CBiotop::setGlobalGridCoordOffset(Point_t startingCoord)
m_GlobalStepCoordOffset.x = startingCoord.x * NB_STEPS_PER_GRID_SQUARE;
m_GlobalStepCoordOffset.y = startingCoord.y * NB_STEPS_PER_GRID_SQUARE;
}

void CBiotop::setAutoSaveSpecieName(string specieName)
{
m_AutoSaveSpecieName = specieName;
}

0 comments on commit d3005ce

Please sign in to comment.