Skip to content

Commit

Permalink
Map editor Fence creation
Browse files Browse the repository at this point in the history
  • Loading branch information
cybiosphere committed Feb 8, 2025
1 parent 6ec3209 commit ddb6592
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 89 deletions.
4 changes: 2 additions & 2 deletions WpCommon/inc/StartupHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ inline void createBiotopAndScenarioFromIniFile(const string& fileIni, CBiotop**
}
else
{
pBiotop = new CBiotop(50, 50, 3);
pBiotop = new CBiotop(100, 100, 3);
pBiotop->initGridEntity();
pBiotop->initGridDefaultLayerType();
pBiotop->initGridDefaultAltitude();
pBiotop->initGridEntity();
pBiotop->setDefaultEntitiesForTest();
}

Expand Down
1 change: 1 addition & 0 deletions WpEnvironment/inc/CBiotop.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ class DLL_CYBIOCORE_API CBiotop

void displayEntities(void);
void setDefaultEntitiesForTest(void);
void buildWoodenFence(Point_t startCoord, Point_t endCoord);

void deleteAllEntities(void);
void deleteAllMeasures(void);
Expand Down
117 changes: 43 additions & 74 deletions WpEnvironment/src/CBiotop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,100 +613,69 @@ void CBiotop::setDefaultEntitiesForTest(void)
// Seed the random generator
// srand( (unsigned)time(NULL) );

CGenome* pGenome1 = new CGenome(CLASS_NONE,"");
CGenome* pGenome2 = new CGenome(CLASS_NONE,"");
//CGenome* pGenome3 = new CGenome(CLASS_NONE,"");
//CGenome* pGenome4 = new CGenome(CLASS_NONE,"");
//CGenome* pGenome5 = new CGenome(CLASS_NONE,"");
CGenome* pGenome6 = new CGenome(CLASS_NONE,"");
//CGenome* pGenome7 = new CGenome(CLASS_NONE,"");
CGenome* pGenome8 = new CGenome(CLASS_NONE,"");
std::string pathName = m_DefaultFilePath + "/../DataScriptMammal/";
CBasicEntity* pNewEntity = NULL;

pGenome6->loadFromXmlFile("../DataScriptMammal/rock.xml");
pGenome8->loadFromXmlFile("../DataScriptMammal/wooden_fence.xml");

pGenome1->loadFromXmlFile("../DataScriptMammal/grassDry.xml");
pGenome2->loadFromXmlFile("../DataScriptMammal/grassDry2.xml");

Point_t coord = {10,10};
string name;

buildWoodenFence({ 1, 1 }, { 1, m_Dimension.y - 2 });
buildWoodenFence({ 1, 1 }, { m_Dimension.x - 2, 1 });
buildWoodenFence({ 1, m_Dimension.y - 2 }, { m_Dimension.x - 1, m_Dimension.y - 2 });
buildWoodenFence({ m_Dimension.x - 2, 1 }, { m_Dimension.x - 2, m_Dimension.y - 1 });

size_t i;
for (i=0; i<2; i++)
for (i = 0; i < 2; i++)
{
CGenome* pGenome = new CGenome(*pGenome6);
coord.x = 2 + getRandInt(60);
coord.y = 2 + getRandInt(40);
createAndAddEntity("rock",coord,2,pGenome);
}
for ( i=0; i<m_Dimension.y-1; i++)
{
CGenome* pGenome = new CGenome(*pGenome8);
coord.x = 0;
coord.y = i;
pNewEntity = createAndAddEntity("wooden_fence",coord,2,pGenome);
if (pNewEntity != NULL)
{
pNewEntity->setDirection(2);
}
}
for ( i=0; i<m_Dimension.y-1; i++)
{
CGenome* pGenome = new CGenome(*pGenome8);
coord.x = m_Dimension.x-3;
coord.y = i;
pNewEntity = createAndAddEntity("wooden_fence",coord,2,pGenome);
if (pNewEntity != NULL)
{
pNewEntity->setDirection(2);
}
}
for ( i=0; i<m_Dimension.x-2; i++)
{
CGenome* pGenome = new CGenome(*pGenome8);
coord.x = i;
coord.y = m_Dimension.y-2;
createAndAddEntity("wooden_fence",coord,2,pGenome);
}
for ( i=0; i<m_Dimension.x-2; i++)
{
CGenome* pGenome = new CGenome(*pGenome8);
coord.x = i;
coord.y = 0;
createAndAddEntity("wooden_fence",coord,2,pGenome);
}
for (i=1; i<m_Dimension.y/5; i++)
{
CGenome* pGenome = new CGenome(*pGenome6);
coord.x = getRandInt(m_Dimension.x) + 1;
coord.y = getRandInt(m_Dimension.y) + 1;
createAndAddEntity("rock",coord,2,pGenome);
createAndAddEntity("rock.xml", pathName, coord);
}

for (i=0; i<2*m_Dimension.y; i++)
{
CGenome* pGenome = new CGenome(*pGenome1);
coord.x = getRandInt(m_Dimension.x) + 2;
coord.y = getRandInt(m_Dimension.y) + 2;
createAndAddEntity("grassDry",coord,1,pGenome);
createAndAddEntity("grassDry.xml", pathName, coord);
}
for (i=0; i<m_Dimension.x; i++)
{
CGenome* pGenome = new CGenome(*pGenome2);
//name.Format("grass%d",20+i);

coord.x = getRandInt(m_Dimension.x) + 1;
coord.y = getRandInt(m_Dimension.y) + 1;
createAndAddEntity("grassDry",coord,1,pGenome);
createAndAddEntity("grassDry2.xml", pathName, coord);
}

delete pGenome1;
delete pGenome2;
delete pGenome6;
delete pGenome8;
}

void CBiotop::buildWoodenFence(Point_t startCoord, Point_t endCoord)
{
std::string fenceFileName = "wooden_fence.xml";
std::string pathName = m_DefaultFilePath + "/../DataScriptMammal/";
Point_t coord;
CBasicEntity* pEntity;
if (startCoord.x == endCoord.x)
{
coord.x = startCoord.x;
for (int y = std::min(startCoord.y, endCoord.y); y < std::max(startCoord.y, endCoord.y); y++)
{
coord.y = y;
pEntity = createAndAddEntity(fenceFileName, pathName, coord);
if (pEntity)
{
pEntity->setDirection(2);
}
}
}
else if (startCoord.y == endCoord.y)
{
coord.y = startCoord.y;
for (int x = std::min(startCoord.x, endCoord.x); x < std::max(startCoord.x, endCoord.x); x++)
{
coord.x = x;
pEntity = createAndAddEntity(fenceFileName, pathName, coord);
if (pEntity)
{
pEntity->setDirection(0);
}
}
}
}

size_t CBiotop::getNbOfEntities()
{
Expand Down
6 changes: 3 additions & 3 deletions WpGenetic/src/CGene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ bool CGene::tryMutation()
size_t dataByteId = getRandInt(m_RawData.size()-1);
int dataBitId = getRandInt(7);
m_RawData[dataByteId] ^= (1<<dataBitId);
CYBIOCORE_LOG(" GENETIC - Mutation type Random bit on gene: %s\n", getLabel().c_str());
CYBIOCORE_LOG(" GENETIC- Mutation type Random bit on gene: %s\n", getLabel().c_str());
resu = true;
break;
}
Expand All @@ -1020,7 +1020,7 @@ bool CGene::tryMutation()
if ( ((addVal<0)&&(m_RawData[dataByteId]>0)) || ((addVal>0)&&(m_RawData[dataByteId]<0xFF)) )
{
m_RawData[dataByteId] += addVal;
CYBIOCORE_LOG(" GENETIC - Mutation type Increment byte +1 or -1 on gene: %s\n", getLabel().c_str());
CYBIOCORE_LOG(" GENETIC- Mutation type Increment byte +1 or -1 on gene: %s\n", getLabel().c_str());
resu = true;
}
else
Expand All @@ -1038,7 +1038,7 @@ bool CGene::tryMutation()
if ( ( (addVal<0)&&(pWordData[dataByteId]>-addVal) ) || ( (addVal>0)&&(pWordData[dataByteId]<(0xFFFF-addVal)) ) )
{
pWordData[dataByteId] += addVal;
CYBIOCORE_LOG(" GENETIC - Mutation type Increment 2bytes +1 or -1 on gene: %s\n", getLabel().c_str());
CYBIOCORE_LOG(" GENETIC- Mutation type Increment 2bytes +1 or -1 on gene: %s\n", getLabel().c_str());
resu = true;
}
else
Expand Down
4 changes: 2 additions & 2 deletions WpGenetic/src/CPairOfChromosome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ CPairOfChromosome::CPairOfChromosome(CPairOfChromosome& mother, CPairOfChromosom
string crossedStr;
m_pMaterChromosome = new CChromosome(m_IdNumber);
getCrossedChromosomeStr(mother, crossedStr);
CYBIOCORE_LOG(" GENETIC - Crossover on mother pair %u\n", m_IdNumber);
CYBIOCORE_LOG(" GENETIC- Crossover on mother pair %u\n", m_IdNumber);
m_pMaterChromosome->buildGenesFromStringData(crossedStr);
}
else if (testChance(50.0))
Expand All @@ -82,7 +82,7 @@ CPairOfChromosome::CPairOfChromosome(CPairOfChromosome& mother, CPairOfChromosom
string crossedStr;
m_pPaterChromosome = new CChromosome(m_IdNumber);
getCrossedChromosomeStr(father, crossedStr);
CYBIOCORE_LOG(" GENETIC - Crossover on father pair %u\n", m_IdNumber);
CYBIOCORE_LOG(" GENETIC- Crossover on father pair %u\n", m_IdNumber);
m_pPaterChromosome->buildGenesFromStringData(crossedStr);
}
else if (testChance(50.0))
Expand Down
5 changes: 4 additions & 1 deletion WpGui/inc/BiotopDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class CBiotopDisplay
void SetSelectedEntityId(entityIdType id) {m_nSelectedEntityId = id;};
void SetLButtonIsDown(bool isDown) {m_bLButtonIsDown = isDown;};
void SetNbRefreshPerStep (int nbRefresh) {m_nbRefreshPerStep = nbRefresh;};
void SetClickStartGridCoord(size_t x, size_t y) { m_clickStartGridCoord = { x,y }; }
void SetMapEditorModeLine(bool isActive) { m_bMapEditorModeLine = isActive; };

//Attributes
protected:
Expand All @@ -77,7 +79,8 @@ class CBiotopDisplay
entityIdType m_nFocusedEntityId;
bool m_bLButtonIsDown;
int m_nbRefreshPerStep;

Point_t m_clickStartGridCoord;
bool m_bMapEditorModeLine{ false };
};

#endif // !defined(AFX_BIOTOPDISPLAY_INCLUDED_)
2 changes: 1 addition & 1 deletion WpGui/inc/BiotopDisplayMFC.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class CBiotopDisplayMFC : public CBiotopDisplay

//Attributes
protected:

int m_nBitmapNumberY;
int m_nBitmapNumberX;
int m_nBitmapPixSizeY;
Expand All @@ -52,6 +51,7 @@ class CBiotopDisplayMFC : public CBiotopDisplay

double m_ZoomFactor;
bool m_SatelliteView;
Point_t m_MouseCoord;

// Operations
public:
Expand Down
5 changes: 4 additions & 1 deletion WpGui/inc/BiotopView.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class CBiotopView : public CScrollView

protected:
void UpdateDisplayZoomRate();
void ManageMapEditorMode(CPoint& point);
void ManageMapEditorModeStep1(CPoint& point);
void ManageMapEditorModeStep2(CPoint& point);
void BuildFenceFromStartGridCoord(Point_t endGridCoord);

//Attributes
protected:
Expand All @@ -70,6 +72,7 @@ class CBiotopView : public CScrollView
Point_t m_MenuSelCoord;
double m_zoomFactor;
double m_SpeedRate;
Point_t m_ClickDownGridCoord{ 0,0 };

LARGE_INTEGER m_SysTicksPrevSecEnd;
bool m_IdleDisplayMode;
Expand Down
17 changes: 17 additions & 0 deletions WpGui/src/BiotopDisplayMFC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ void CBiotopDisplayMFC::RedrawScene()
}
}

// Draw Map Editor helpers
if (m_bMapEditorModeLine)
{
coordX = m_nBitmapPixSizeX * m_clickStartGridCoord.x - visibleCoordX;
coordY = m_pView->GetTotalSize().cy - m_nBitmapPixSizeY * (m_clickStartGridCoord.y + 2) - visibleCoordY;
pDc->Draw3dRect(coordX, coordY, m_nBitmapPixSizeX, m_nBitmapPixSizeY, 0x00DBD8F8, 0x000ECECF);
coordX += m_nBitmapPixSizeX / 2;
coordY += m_nBitmapPixSizeY / 2;
pDc->MoveTo(coordX, coordY);
pDc->LineTo(m_MouseCoord.x, m_MouseCoord.y);
}

// Restore the old bitmap
pDc->SelectObject(bmpPrevious);

Expand Down Expand Up @@ -419,6 +431,11 @@ void CBiotopDisplayMFC::RefreshSceneIdleNoCPU()

void CBiotopDisplayMFC::OnMouseMove(CPoint point)
{
if (m_bLButtonIsDown)
{
m_pView->Invalidate();
}
m_MouseCoord = { (size_t)point.x, (size_t)point.y };
}

void CBiotopDisplayMFC::ScrollToGridCoord(Point_t centerPos)
Expand Down
40 changes: 35 additions & 5 deletions WpGui/src/BiotopView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,17 @@ void CBiotopView::OnTimer(UINT_PTR nIDEvent)
void CBiotopView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_pBioDisplay->SetLButtonIsDown(true);
ManageMapEditorMode(point);
m_ClickDownGridCoord = m_pBioDisplay->GetGridCoordFromScreenPos(point);
m_pBioDisplay->SetClickStartGridCoord(m_ClickDownGridCoord.x, m_ClickDownGridCoord.y);
ManageMapEditorModeStep1(point);
CView::OnLButtonDown(nFlags, point);
}

void CBiotopView::OnLButtonUp(UINT nFlags, CPoint point)
{
m_pBioDisplay->SetLButtonIsDown(false);

m_pBioDisplay->SetMapEditorModeLine(false);
ManageMapEditorModeStep2(point);
CView::OnLButtonUp(nFlags, point);
}

Expand Down Expand Up @@ -441,7 +444,7 @@ void CBiotopView::OnMouseMove(UINT nFlags, CPoint point)
if ((nFlags & MK_LBUTTON) != 0)
{
m_pBioDisplay->SetLButtonIsDown(true);
ManageMapEditorMode(point);
ManageMapEditorModeStep1(point);
}
else
{
Expand Down Expand Up @@ -1052,7 +1055,7 @@ void CBiotopView::OnAppMonitorSpecieBiomass()
theApp.updateAllBiotopNewMeasures();
}

void CBiotopView::ManageMapEditorMode(CPoint& point)
void CBiotopView::ManageMapEditorModeStep1(CPoint& point)
{
MapEditorModeType_e editorMode = theApp.GetMapEditorMode();
if (editorMode > MAP_EDITOR_MODE_NONE)
Expand All @@ -1075,7 +1078,34 @@ void CBiotopView::ManageMapEditorMode(CPoint& point)
case MAP_EDITOR_MODE_GROUND_ROCK:
m_pBiotop->setGridGroundTypeRock(gridCoord.x, gridCoord.y);
break;
case MAP_EDITOR_MODE_FENCE:
m_pBioDisplay->SetMapEditorModeLine(true);
break;
}

}
}

void CBiotopView::ManageMapEditorModeStep2(CPoint& point)
{
MapEditorModeType_e editorMode = theApp.GetMapEditorMode();
if (editorMode > MAP_EDITOR_MODE_NONE)
{
Point_t gridCoord{ m_pBioDisplay->GetGridCoordFromScreenPos(point) };
switch (editorMode)
{
case MAP_EDITOR_MODE_FENCE:
BuildFenceFromStartGridCoord(gridCoord);
break;
}
}
}

void CBiotopView::BuildFenceFromStartGridCoord(Point_t endGridCoord)
{
m_pBiotop->buildWoodenFence(m_ClickDownGridCoord, endGridCoord);
m_pBioDisplay->RedrawScene();
}




0 comments on commit ddb6592

Please sign in to comment.