|
@@ -1,30 +1,42 @@
|
|
1
|
+#include "Platform/Platform.hpp"
|
|
2
|
+#include <Agents/Agent.hpp>
|
1
|
3
|
#include <Agents/Perception/Perception.hpp>
|
2
|
4
|
#include <Environment/PictureEnvironment.hpp>
|
3
|
5
|
|
|
6
|
+const sf::Vector2f DEFAUMT_SIMZE = sf::Vector2f(800, 600);
|
4
|
7
|
int PERCEPTION_SIZE = 4;
|
5
|
8
|
|
6
|
9
|
PictureEnvironment::PictureEnvironment()
|
7
|
10
|
{
|
8
|
11
|
}
|
9
|
12
|
|
10
|
|
-PictureEnvironment::PictureEnvironment(std::string& iFilePath, sf::RenderWindow* iWindow)
|
|
13
|
+PictureEnvironment::PictureEnvironment(std::string& iFilePath, sf::RenderWindow* iWindow, util::Platform* iPlatform) :
|
|
14
|
+ fSize(iWindow->getSize())
|
11
|
15
|
{
|
|
16
|
+
|
12
|
17
|
fFilePath = iFilePath;
|
|
18
|
+ //sf::Texture fLoadedImage;
|
|
19
|
+ if (!fTextureImage.loadFromFile(fFilePath))
|
|
20
|
+ {
|
|
21
|
+ std::cout << "\n COULDNT LOAD PICTURE\n";
|
|
22
|
+ }
|
|
23
|
+ fImage = fTextureImage.copyToImage();
|
13
|
24
|
|
14
|
25
|
//memccpy(&fFilePath, &iFilePath, *iFilePath., 10);
|
15
|
26
|
std::cout << "Environement pour " << fFilePath;
|
16
|
|
-
|
|
27
|
+ fPlatform = iPlatform;
|
17
|
28
|
fWindow = iWindow;
|
|
29
|
+ float screenScalingFactor = fPlatform->getScreenScalingFactor(fWindow->getSystemHandle());
|
|
30
|
+ fWindow->create(sf::VideoMode(800.0f * screenScalingFactor, 600.0f * screenScalingFactor), "SFML works!");
|
|
31
|
+ fPlatform->setIcon(fWindow->getSystemHandle());
|
|
32
|
+ fInitialSize.x = 800.0f * screenScalingFactor;
|
|
33
|
+ fInitialSize.y = 600.0f * screenScalingFactor;
|
|
34
|
+ //fShape = sf::RectangleShape(fSize);
|
|
35
|
+ fShape = sf::RectangleShape(DEFAUMT_SIMZE);
|
18
|
36
|
|
19
|
|
- fShape = sf::CircleShape(fWindow->getSize().x / 2);
|
20
|
37
|
fShape.setFillColor(sf::Color::White);
|
21
|
38
|
|
22
|
|
- sf::Texture shapeTexture;
|
23
|
|
- if (!shapeTexture.loadFromFile(fFilePath))
|
24
|
|
- {
|
25
|
|
- std::cout << "\n COULDNT LOAD PICTURE\n";
|
26
|
|
- }
|
27
|
|
- fShape.setTexture(&shapeTexture);
|
|
39
|
+ fShape.setTexture(&fTextureImage);
|
28
|
40
|
}
|
29
|
41
|
|
30
|
42
|
Perception PictureEnvironment::getPerception(int iX, int iY)
|
|
@@ -35,6 +47,19 @@ Perception PictureEnvironment::getPerception(int iX, int iY)
|
35
|
47
|
return vPerception;
|
36
|
48
|
}
|
37
|
49
|
|
|
50
|
+void PictureEnvironment::makeAgents(int iNumber)
|
|
51
|
+{
|
|
52
|
+ Agent vTmpAgent;
|
|
53
|
+ fAgents = std::list<Agent>(iNumber);
|
|
54
|
+ fAgentsIterator = fAgents.begin();
|
|
55
|
+
|
|
56
|
+ for (int i = 0; i < iNumber; i++)
|
|
57
|
+ {
|
|
58
|
+ vTmpAgent = Agent(this);
|
|
59
|
+ fAgents.insert(fAgentsIterator, vTmpAgent);
|
|
60
|
+ }
|
|
61
|
+}
|
|
62
|
+
|
38
|
63
|
bool PictureEnvironment::loop()
|
39
|
64
|
{
|
40
|
65
|
if (fWindow->isOpen())
|
|
@@ -44,16 +69,15 @@ bool PictureEnvironment::loop()
|
44
|
69
|
if (fEvent.type == sf::Event::Closed)
|
45
|
70
|
fWindow->close();
|
46
|
71
|
}
|
47
|
|
- fShape = sf::CircleShape(fWindow->getSize().x / 2);
|
48
|
|
- fShape.setFillColor(sf::Color::White);
|
49
|
72
|
|
50
|
|
- sf::Texture shapeTexture;
|
51
|
|
- if (!shapeTexture.loadFromFile(fFilePath))
|
|
73
|
+ fAgentsIterator = fAgents.begin();
|
|
74
|
+ for (uint i = 0; i < fAgents.size(); i++)
|
52
|
75
|
{
|
53
|
|
- std::cout << "\n COULDNT LOAD PICTURE\n";
|
|
76
|
+ fAgentsIterator->loop();
|
54
|
77
|
}
|
55
|
|
- fShape.setTexture(&shapeTexture);
|
56
|
78
|
|
|
79
|
+ fTextureImage.loadFromImage(fImage);
|
|
80
|
+ fShape.setTexture(&fTextureImage);
|
57
|
81
|
fWindow->clear();
|
58
|
82
|
fWindow->draw(fShape);
|
59
|
83
|
fWindow->display();
|
|
@@ -64,4 +88,20 @@ bool PictureEnvironment::loop()
|
64
|
88
|
return false;
|
65
|
89
|
}
|
66
|
90
|
return true;
|
|
91
|
+}
|
|
92
|
+
|
|
93
|
+void PictureEnvironment::displayLockInput()
|
|
94
|
+{
|
|
95
|
+ fWindow->create(sf::VideoMode(fInitialSize.x, fInitialSize.y), "Last peek");
|
|
96
|
+ fWindow->clear();
|
|
97
|
+ fWindow->draw(fShape);
|
|
98
|
+ fWindow->display();
|
|
99
|
+ int i;
|
|
100
|
+ std::cin >> i;
|
|
101
|
+}
|
|
102
|
+
|
|
103
|
+void PictureEnvironment::paint(int iX, int iY, const sf::Color iColour)
|
|
104
|
+{
|
|
105
|
+ //std::cout << "juste avant : " << iX << " et " << iY;
|
|
106
|
+ fImage.setPixel(iX, iY, iColour);
|
67
|
107
|
}
|