Hey there, I've migrated to SFML not long ago and am an amateur programmer who is trying to make his own small game.
I'm doing good progress on the basic stuff, but as I'm looking forward and trying to decide how to best build my game I ran into a few things I'm insecure about.
I'd love some guidance on a few things:
1) How well does SFML handle multiple threads? Is there a limit as to how many threads can run at the same time or does it drastically impair performance, even if most threads are sleeping?
The reason why I'm asking is that I want to construct event-driven functions for certain things.
E.g. I want to be able to hook a certain function to a custom event like the player figure reaching a certain point on the map.
The called function could then send a radio message to the help, sleep for a few seconds and then send a second message. For that sleeping I'd need to thread all of these functions.
They'd generally not do a lot of stuff, as the performance-heavy chunk of the game is being taken care of in the main thread. They'd mostly serve to set-off in-game events and stuff.
2) I am already implementing a save/load function to store and read map files which contain the terrain data for each game level.
But I was wondering if there is a way to do the same for scripts.
Let's take the above example: In one level I want to send some messages to the player once he reaches a certain point. No problem. But when he plays a different level there are other things meant to happen.
The easiest way to manage this is to just create all the relevant functions for all levels in some cpp file and call them depending on the loaded level.
But in this case they'd clutter up the game.exe and I'd have to change the source code everytime I wanted to change any level's scripts.
So instead I'd like to be able to load the scripts from seperate files, like being able to dynamically load and unload cpp files (which probably won't work).
However, I have absolutely no idea how to do that.
The only thing that comes to my mind is creating a completely new small scripting language which is then read by the game and evaluated, but that's a HUGE amount of work.
3) My map has a tile-base terrain similar to a chess board with 19x25 squares. I noticed that, when drawing all these sprites, the game's frame rate goes down to about 23 (before that it was 60).
I'm running Win 7 x64 on a pretty decent computer and I updated my graphic drivers just a day ago - so at least this shouldn't be an issue.
However I can't believe that drawing a couple of small sprites is supposed to have such a high impact.
Are there any other things I can do to squeeze some better performance out of that?
Here's basically how I'm drawing it:
void draw(){
//This sprite array probably shouldn't be constructed everytime this function runs
//but only once - but I doubt that this alone is a great performance hit.
sf::Sprite sp[2] = { sf::Sprite(SomeTerrainImage),
sf::Sprite(SomeOtherTerrainImage) };
int i=0;
//map[][] is a char array containing the terrain type of each square.
//Depending on it's value the game should draw a different tile image.
for(short wi=0; wi < w; wi++){
for(short hi=0; hi < h; hi++){
i=map[hi][wi];
sp[i].SetPosition(hi*32.f, wi*32.f);
window->Draw(sp[i]);
}
}
}
4) Last but not least; I've asked a question in
http://www.sfml-dev.org/forum/viewtopic.php?t=3718 which still baffles me. An answer to that would be great!
Many thanks in advance for some enlightenment!
~s3r