136
General / Re: SFML 2.0 Static Debug Libraries, warning LNK4098,, Not sure what the issue is...
« on: July 11, 2012, 08:01:08 pm »I'm not sure if it's a good idea to use stdafx.h and _tmain(), is this even in the standard?
But your problem lies somewhere else and that is global variables!
You're defining and initializing your render window in the global scope. Using global variables should always be avoided, unless you really know what you're doing. Initializing in the global scope will lead to undefined behaviour, so it's a big DON'T.
Redesign your class to include the render window instead of hosting it in the global scope!
I figured that the stdafx.h and the tmain was fine. I was unaware of the concerns around it since VS2010 put it in automatically. Is there anything you would recomend to standardize it?
About the global variable. I was attempting to follow a tutorial that had it as a global variable. I'm not sure why they made it global since it didn't seem to be used anywere else besides the main class, and was just transfered from method to method outside of the main class.
I also was a bit un aware that it as a global variable would make it so un predictable.
When you say "include" the render window instead of "hosting" it what do you mean by that? Just launch the render window normally and pass it on to methods that require it manually instead of using a global variable?
EDIT
#include "stdafx.h"
#include "Genesis.h"
#include "BetweenScreens.h"
#include "SplashScreen.h"
//Entry Point
int _tmain(int argc, _TCHAR* argv[])
{
Genesis::Initialize();
return 0;
}
//Initial Method
void Genesis::Initialize(void)
{
if(_engineState != Genesis::InitialLoad)
return;
sf::RenderWindow mainWindow(sf::VideoMode(1024,786,32),"Genesis");
_engineState = Genesis::Starting;
//Throwing a initial loading screen.
BetweenScreens::ColdLoadingScreen(mainWindow);
while(!isClosing())
{
EngineStateCollaborator();
}
}
void Genesis::EngineStateCollaborator(void)
{
switch (_engineState){
case Genesis::Starting:
showSplashScreen();
break;
case Genesis::Menu:
break;
}
}
void Genesis::showSplashScreen(void)
{
//Not implamented yet.
}
bool Genesis::isClosing(void)
{
if(_engineState == Genesis::Closing)
return true;
else
return false;
}
Genesis::EngineState Genesis::_engineState = InitialLoad;
#include "Genesis.h"
#include "BetweenScreens.h"
#include "SplashScreen.h"
//Entry Point
int _tmain(int argc, _TCHAR* argv[])
{
Genesis::Initialize();
return 0;
}
//Initial Method
void Genesis::Initialize(void)
{
if(_engineState != Genesis::InitialLoad)
return;
sf::RenderWindow mainWindow(sf::VideoMode(1024,786,32),"Genesis");
_engineState = Genesis::Starting;
//Throwing a initial loading screen.
BetweenScreens::ColdLoadingScreen(mainWindow);
while(!isClosing())
{
EngineStateCollaborator();
}
}
void Genesis::EngineStateCollaborator(void)
{
switch (_engineState){
case Genesis::Starting:
showSplashScreen();
break;
case Genesis::Menu:
break;
}
}
void Genesis::showSplashScreen(void)
{
//Not implamented yet.
}
bool Genesis::isClosing(void)
{
if(_engineState == Genesis::Closing)
return true;
else
return false;
}
Genesis::EngineState Genesis::_engineState = InitialLoad;
That seemed to work flawlessly. Thank you for your help! Let me know if there is anything else you would recommend as I'm still trying to learn the proper ways of doing things.