Bonjour, je rencontre depuis quelque jours des problèmes auquel je n'avait pas été confronté jusque là : (les erreurs affichés n'ont pas lieu d'être lorsque je regarde mon code)
Après quelque recherche je suspecte mes directives d'inclusion d'être les responsables mais rien à faire, ce schéma est il normal ?
Main.h
Main.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 #include <SFML/Graphics.hpp> #include <stdlib.h> #include <iostream> #include "World.h" #include "Element.h" using namespace sf; using namespace std;
World.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 #include "Main.h" void renderingThread(RenderWindow* window) { World * world = new World(); world->addElement(new Element(world, world->getTextureFromName("1"), "1", *new Vector2f(200, 200))); while (window->isOpen()) { window->clear(); for (vector<Sprite *>::iterator it = world->getSpriteArray()->begin(); it != world->getSpriteArray()->end(); it++) { window->draw(**it); } window->display(); } } int main() { RenderWindow window(VideoMode(800, 600), "OpenGL"); window.setActive(false); Thread thread(&renderingThread, &window); thread.launch(); while (window.isOpen()) { Event event; while (window.pollEvent(event)) { if (event.type == Event::Closed) window.close(); } } return 0; }
World.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #pragma once #include "Main.h" class World { private: map<string, string> * textureName; map<string, Texture *> * textureArray; map<string, Element *> * elementArray; vector<Sprite *> * spriteArray; public: World(); ~World(); void addElement(Element * element); vector<Sprite *> * getSpriteArray(); Texture * getTextureFromName(string name); };
Element.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 #include "World.h" World::World() { /********************************** Chargement des textures en mémoire **********************************/ // Création du tableau associatif : idTetxure -> fichierTexture this->textureName = new map<string, string>(); // Création du tableau associatif : idTexture -> pointeurTexture // Remplissage tableau associatif : idTexture -> fichierTexture this->textureName->insert(pair<string, string>("1", "1.png")); this->textureName->insert(pair<string, string>("2", "2.png")); this->textureName->insert(pair<string, string>("3", "3.png")); this->textureName->insert(pair<string, string>("4", "4.png")); // Remplissage tableau associatif : idTexture -> pointeurTexture for (map<string, string>::iterator it = this->textureName->begin(); it != this->textureName->end(); it++) { Texture * texture = new Texture(); texture->loadFromFile(it->second); this->textureArray->insert(pair<string, Texture *>(it->first, texture)); } // Suppression du tableau associatif : idTetxure -> fichierTexture delete this->textureName; /********************************************************************************************************/ // Création du tableau associatif : idElement -> pointeurElement this->elementArray = new map<string, Element *>(); // Création du tableau : pointeurSprite this->spriteArray = new vector<Sprite *>(); } World::~World() { for (map<string, Texture *>::iterator it = this->textureArray->begin(); it != this->textureArray->end(); it++) { delete it->second; } delete this->textureArray; } void World::addElement(Element * element) { this->elementArray->insert(pair<string, Element *>(element->getID(), element)); this->spriteArray->push_back(element->getSprite()); } vector<Sprite *> * World::getSpriteArray() { return this->spriteArray; } Texture * World::getTextureFromName(string name) { return this->textureArray->at(name); }
Element.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #pragma once #include "Main.h" class Element { private: string id; Sprite sprite; public: Element(World * world, Texture * texture, string id, Vector2f &position); ~Element(); string getID(); Sprite * getSprite(); };
Je ne vois vraiment pas ce qui cloche dans ce code, merci de vos réponses.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #include "Element.h" Element::Element(World * world, Texture * texture, string id, Vector2f &position) { this->id = id; Sprite sprite(*texture); sprite.setPosition(position); this->sprite = sprite; world->addElement(this); } Element::~Element() { } string Element::getID() { return this->id; } Sprite * Element::getSprite() { return &this->sprite; }
Partager