game loops and setting up sfml

Pages: 12
1) So I have a quick question about game loops. Is it better to do a
1
2
3
4
5
6
7
8
9
10
11
12
bool shouldExit == false;
while (shouldExit == false)
{
... // program

//psuedo
// playAgain?
// if playAgain is yes
      // return true;
// if playAgain is no
      // return false;
}

or would it be better to do something like a do-while loop so:
1
2
3
4
5
6
do
{
    // program
    // ask user to play again and check to see if they want to...
    // return true if yes or false if no
}while(playAgain == true)


2) I'm running into issues setting up sfml for the first time. I followed this step by step http://www.sfml-dev.org/tutorials/1.6/start-vc.php, and when i tried to run their simple program I tried to run it and it gave some issue with the sfml-system.dll and the source says that you need to include it in the executable directory, how do I find the executable directory? A step by step to get there would be much appreciate. Thanks in advance!
1) There's no difference. However, you should write while (!shouldExit) and while (playAgain).
2) The executable should be somewhere in the project's folder (possibly in a subdirectory called bin or dist).
by the way, line 1: bool shouldExit == false;. You're confusing assignment with comparison.
oh oops, i meant to write bool shouldExit = false;

@Athar

When I try to compile it, it gives this error.

stflTest.exe - System Error
The program can't start because sfml system.dll is missing from your computer. Try re-installing the program to fix this problem.


When it says to re-install the program is that refering to re-installing visual studio (since that's what i'm using)? or is there a way around re-installing it. I mean if I'm gonna have to re-install it might as well look into visual studio 10 right? since right now i just have 8
Last edited on
No, do not reinstall Visual Studio.

The problem is that you need to have your SFML dlls in a folder that the system will find when it runs your program.

This will either be:

1) In the same folder as the .exe
2) In your Windows/system32/ folder


I recommend option #2, that way you won't have this same problem with future SFML projects.
now it says
the application was unable to start correctly (0xc00000ba).
what do I do about this?
Did you really follow the step by step directions on that site? =x because I did that and it worked fine.

In particular... did you notice this part?

Important: for the Debug configuration, you have to link with the debug versions of the libraries, which have the "-d" suffix (sfml-system-d.lib in this case). If you don't, you may get undefined behaviours and crashes.

Though a simple lib, SFML's awfully hard to set up if it's your first go at it. Visual Studio has lots of tedious settings that you've got to be familiar with.
Post the code you're compiling, maybe the error you're getting is a source issue.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <SFML/System.hpp>
#include <iostream>


int main()
{
	sf::Clock Clock;
	while(Clock.GetElapsedTime() < 5.f)
	{
		std::cout << Clock.GetElapsedTime() << std::endl;
		sf::Sleep(0.5f);
	}

	return 0;
}


i don't understand what it's talking about with the -d suffix and what not. i'm still new to all of this. and yes i did see that line.
Last edited on
Oh right, those.
There's two ways to 'connect' your project to SFML, they're called static and dynamic linking. Static linking is where all of SFML, or any other lib, would be copied into your executable. On the other hand, dynamically linking means you have to include the .dll files in the same directory as your executable, because it doesn't copy them, rather depends on the external file. ... Or it's the other way around. I've always gotten those two terms mixed up.
Anyway, the way SFML has it organized is it made a few different version of the .lib files. ones with the '-s' prefix mean they'll be linked statically (generally, i never use these, it racks up the size of me .exe). The '-d' tag means Debug, which i've never used either, though i'm sure it has a purpose. Having no tag implies that the lib will be linked dynamically, which is what I always use.

Generally, you won't need any of the tags. In the project options tab, under linker->input, in the Additional Dependencies box, you'll need 'sfml-system.lib', and that's it.
Last edited on
@Thumper I did do the sfml-system.lib, and i get the error, before it said the sfml system-dll was missing. Now it's giving me the other error, and i'm not sure what the problem is. It never gets to the program, just dies. is that because it's not sfml-system-d.lib?
It shouldn't be because you're not using sfml-system-d.lib, and now I've no idea why your code isn't running.
I guess we have to wait 'till the SFML master Disch wakes up. Or someone else that's run into this before comes along.
Thumper wrote:
Anyway, the way SFML has it organized is it made a few different version of the .lib files. ones with the '-s' prefix mean they'll be linked statically (generally, i never use these, it racks up the size of me .exe)


I prefer static linking whenever reasonable, as it makes distribution much simpler.


And in fact, linking statically might solve this problem. I suspect it's because he's linking to the wrong DLL.


ERanz21 wrote:
i don't understand what it's talking about with the -d suffix and what not.


There was a step when you want into project settings and typed "sfml-system.lib" in. This tells VS to link to SFML.

The thing is, your project has 2 builds: one is "Release" and one is "Debug". The Dubug build is slower and bigger, but allows for you do run the debugger which lets you set breakpoints and stuff. The "Release" build is smaller/faster and is intended to be the program you distribute to other people.


SFML also has "Debug" and "Release" versions. What I suspect is happening is you are building a Debug program and linking to the Release version of SFML -- which can cause your program to crash.

For your Debug build, you need to link to the Debug SFML. You do this by linking to "sfml-system-d.lib" instead.

Try changing that and see if it works.


EDIT:

ERanz21 wrote:
is that because it's not sfml-system-d.lib?


yes ;P

EDIT2: also lol @ me being the SFML master XD
Last edited on
@Dish
Fair enough. When i static link sometimes i get these nasty link errors, so i just don't bother.
and *slaps face* I hadn't thought of that. I set my builds to release subconciously.
EDIT: 'cos you are. And jump on IRC if you're gonna be on a bit longer, i'm bored out of my mind.
Last edited on
I tried to switch it to sfml-system-d.lib and it said that it didn't exist... gah.
before you continue, see if that's even the problem or if we're chasing our tail.

Try switching to Release. Then build and run and see if it works. If it does, then you'll need to compile the debug SFML libs.
well the sfml-sytem.lib is in both and gives the error. If it's the -d one it says that it doesn't exist. Both meaning debug and release.
Maybe the binaries are just incompatible with the version of the compiler you're using. Try recompiling SFML.

Throw out the SMFL DLLs you have now. Get this instead:

http://sourceforge.net/projects/sfml/files/sfml/1.6/SFML-1.6-sdk-windows-vc2008.zip/download


Open the SFML solution and go to Build | Batch Build | Select All | Build

It'll make a bunch of new SFML Dlls. Use those instead.


I'm 99.9999% sure it will work after that.
that's the one i was using, and it doesn't work. Does it have to be in the same folder as where i have my programs, or does it have to be in the visual studio folder, if there is one, lol?
the .dll's need to be in the same folder your program is, or in \system32.
Pages: 12