I mean, here so that you can see the whole picture:
LoadingScreens.cpp
#include "stdafx.h"
#include "LoadingScreens.h"
void LoadingScreens::Display(_LST ST,EngineWindow& glWindow)
{
IsLoading=true;
LoadingScreen CurrLoadScreen;
switch(ST){
case GNS_Cold:
CurrLoadScreen = GNS_Cold_F();
break;
default:
return;
}
LoadingScreens loadingScreens;
auto RunLoadingScreenT = std::mem_fn(&LoadingScreens::RunLoadingScreen);
std::thread t(RunLoadingScreenT,loadingScreens,CurrLoadScreen,glWindow);
}
LoadingScreens::LoadingScreen LoadingScreens::GNS_Cold_F()
{
LoadingScreen GNS_Cold_LS;
GNS_Cold_LS.LST_Alias = LoadingScreens::_LST::GEN_Cold;
GNS_Cold_LS.IsStatic = true;
GNS_Cold_LS.ResourcePath = "Resource/LoadingScreens/Genesis/Cold/Loading_Main.png";
return GNS_Cold_LS;
}
void LoadingScreens::RunLoadingScreen(LoadingScreen LS,EngineWindow& glWindow) //This should run in a thread.
{
if(LS.IsStatic){
sf::Sprite LSS;
LSS.setTexture(texture.getTexture(LS.ResourcePath));
LSS.setPosition(glWindow.GetCenter().x,glWindow.GetCenter().y);
glWindow.draw(LSS);
glWindow.display();
}else{
sfe::Movie LSM;
if(!LSM.openFromFile(LS.ResourcePath))
{
return;
}
LSM.setPosition(glWindow.GetCenter().x,glWindow.GetCenter().y);
LSM.play();
while(IsLoading)
{
glWindow.draw(LSM);
glWindow.display();
}
}
}
LoadingScreens.h
#ifndef LOADINGSCREENS_H
#define LOADINGSCREENS_H
#include "stdafx.h"
#include "SpriteUtilities.h"
#include <SFML\Graphics.hpp>
#include <thread>
#include <sfeMovie\Movie.hpp>
#include <functional>
class LoadingScreens{
Texture texture;
public:
enum _LST{GNS_Cold,GNS_Anim,GEN_Cold,GEN_Anim,LVL_GEN_Cold,LVL_GEN_Anim};
void Display(_LST,EngineWindow&);
void Recall();
private:
struct LoadingScreen
{
public:
_LST LST_Alias;
std::string ResourcePath;
bool IsStatic;
bool IsGeneric;
std::string Args;
};
bool IsLoading;
LoadingScreen GNS_Cold_F();
void RunLoadingScreen(LoadingScreen,EngineWindow&);
};
#endif
I mean. I really don't see why this is not working at this point. I personally think this should have worked a long time ago. but as always, I am missing some small key of information that's probably ruining the entire thing.
EDIT
So I have it working with:
std::thread t(&LoadingScreens::RunLoadingScreen,&loadingScreens,CurrLoadScreen,glWindow);
But now I get errors from a sf::NonCopyable. So It must be trying to make a copy of "glWindow" but glWindow has inheritance with sf::renderWindow which explains where the error comes from. Is there a way to pass it as a reference?
EDIT
AHA! I knew it! I feel so proud. XD std::ref, I love you.
I will now continue to learn about functors and base C++ knowledge.