I'm in the early stages of a game I would love to create and i'm trying to work out how the game program should be structured (classes, headers etc). I'm using C++ and SFML for this project.
Let me first by showing you my basic image of the structure. Don't pay attention to MainMenuState.cpp and NewGameState.cpp
Game.cpp will have an instance of all those services, it will also have the MainMenuState, NewGameState and LevelState. Now here is my problem.
Game.cpp will have a method that will call the RenderService.RenderWindow, I'm trying to work out exactly how I should code this method? Should I pass in an arrayList of sf::sprites? If I do this, the LevelState.cpp will need an ArrayList of sf::Sprites. which will be updated on each game step. But lets say the Hero.cpp has 1 sf::Sprite. the Map.cpp has 20 sf::sprites and Monster.cpp has 1 sf::Sprite. this would mean I have to pass 22 sf::Sprites back to the RenderService every game step (60fps). so that is 1320 sf::Sprites per second back to the RenderService. I understand game structure is a very hard thing to do and hard to implement correctly, because there isn't a "set" way. I have created a Vector which holds sf::Sprites and every time I call my Render function I clear the vector before so everything is removed for memory. This works fine. Would that be the answer? But as I stated before is passing a lot of sf::Sprites to be rendered ok?
P.S.
Here is my simple SFML program to test this
#include <SFML/Graphics.hpp>
#include "ImageService.h"
#include "DisplayObject.h"
#include "Enums.h"
ImageService is;
DisplayObject displayObject;
int main()
{
sf::RenderWindow window(sf::VideoMode(1024, 768), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
is.Images[image1].loadFromFile("ship1.tga");
displayObject.sprite.setTexture(is.Images[displayObject.spriteType]);
std::vector<sf::Sprite> displayObjects;
while (window.isOpen())
{
displayObjects.clear();
displayObjects.push_back(displayObject.sprite);
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
//Draw out the selected sprites
for (int i = 0; i < displayObjects.size(); i++)
{
window.draw(displayObjects.at(i));
}
window.display();
}
return 0;
}
Let me know if you would like me to explain any part of my program