1
Graphics / Re: SFML 2.0 Slow loading textures from file
« on: June 05, 2012, 05:34:15 pm »
K I'm using pointers now, so the vector will copy the pointer, but not the whole object
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
....
//Player pawns
t_pPlayerPawnCar.loadFromFile(".//Resources//PlayScreen//car.png");
t_pPlayerPawnIron.loadFromFile(".//Resources//PlayScreen//iron.png");
t_pPlayerPawnHat.loadFromFile(".//Resources//PlayScreen//hat.png");
t_pPlayerPawnBarrow.loadFromFile(".//Resources//PlayScreen//barrow.png");
.....
t_All_Textures.push_back(t_pPlayerPawnCar);
t_All_Textures.push_back(t_pPlayerPawnIron);
t_All_Textures.push_back(t_pPlayerPawnHat);
t_All_Textures.push_back(t_pPlayerPawnBarrow);
....
m_pScreen->setResources(t_All_Textures);
void PlayScreen::setResources(std::vector<sf::Texture> AllTextures){
....
m_carPawn=AllTextures[15];
m_ironPawn=AllTextures[16];
m_hatPawn=AllTextures[17];
m_barrowPawn=AllTextures[18];
....
//CLEANUP AND FREE MEMORY
AllTextures.clear();
std::vector<sf::Texture>().swap(AllTextures);
}
RulesScreen::RulesScreen(){
sf::Thread th(&RulesScreen::loadThread,this);
}
void RulesScreen::Init(sf::RenderWindow* SFMLView1){
....
m_pSFML_VIEW=SFMLView1;
if(!loaded){
th->launch();
}
m_pSFML_VIEW->setActive(); //ACCESS VIOLATION
}
I'm probably partly on the right track here...
#ifndef _RULESSCREEN_H_
#define _RULESSCREEN_H_
#define MAXPANELS 4
#include "GameScreen.h"
class RulesScreen : public GameScreen{
public:
...
protected:
...
private:
.....
sf::Thread *th;
....
};
#endif
//GLOBAL VARIABLES
sf::Texture t_mBackground;
sf::Sprite s_mBackground;
bool loaded; //LOADED BOOLEAN, IF THE SCREEN IS LOADED ALREADY, DON'T LOAD IT AGAIN
void loadThread(){
if(!loaded){
//LOADING TEXTURES
t_mBackground.loadFromFile(".//Resources//globalbackground.png");
//LOAD TEXTURES INTO SPRITES
s_mBackground.setTexture(t_mBackground);
//SET SPRITE POSITION
s_mBackground.setPosition(0,0);
loaded=true;
}
}
RulesScreen::RulesScreen(){
th=new sf::Thread(&loadThread);
}
void RulesScreen::Init(sf::RenderWindow* SFMLView1){
th->launch();
}
...
private:
sf::Texture t_mBackground;
sf::Sprite s_mBackground;
bool loaded; //LOADED BOOLEAN, IF THE SCREEN IS LOADED ALREADY, DON'T LOAD IT AGAIN
...
void loadThread();
RulesScreen::RulesScreen(){
th=new sf::Thread(&RulesScreen::loadThread);
}
void RulesScreen::loadThread(){
if(!loaded){
//LOADING TEXTURES
t_mBackground.loadFromFile(".//Resources//globalbackground.png");
//LOAD TEXTURES INTO SPRITES
s_mBackground.setTexture(t_mBackground);
//SET SPRITE POSITION
s_mBackground.setPosition(0,0);
loaded=true;
}
}
void RulesScreen::Init(sf::RenderWindow* SFMLView1){
th->launch();
}
...
private:
ThreadClass *threadc;
sf::Thread *th;
void IntroScreen::Init(sf::RenderWindow* SFMLView1){
...
threadc=new ThreadClass(this);
th=new sf::Thread(&ThreadClass::run,threadc);
...
}
void IntroScreen::TransitionOut(){
if(!transition){
transition=true;
th->launch();
}
}
//Global variables
ThreadClass threadc(IntroScreen::Instance());
sf::Thread th(&ThreadClass::run,&threadc);
void IntroScreen::TransitionOut(){
if(!transition){
transition=true;
ThreadClass threadc(this);
sf::Thread th(&ThreadClass::run,&threadc);
th.launch();
}
}
void IntroScreen::setFadeAmount(sf::Uint8 alpha){
mfade_alpha=alpha;
}
#include "globalInclude.h"
#include "GameScreen.h"
class ThreadClass{
public:
ThreadClass(GameScreen* pScreen);
ThreadClass();
void run();
private:
sf::Uint8 mAlpha;
sf::Clock mFadeClock;
GameScreen* m_pScreen;
};
#include "ThreadClass.h"
ThreadClass::ThreadClass(GameScreen* pScreen){
m_pScreen=pScreen;
mAlpha=0;
}
ThreadClass::ThreadClass(){
mAlpha=0;
}
void ThreadClass::run(){
bool done=false;
while(!done){
if(mAlpha!=255){
if(mFadeClock.getElapsedTime().asMilliseconds()>500){
if((255-mAlpha)<60){
mAlpha=255;
done=true;
}else{
mAlpha+=60;
}
//m_pScreen->setFadeAmount(mAlpha);
mFadeClock.restart();
}
}else{
done=true;
}
}
}
#include "globalInclude.h"
class ThreadClass{
public:
void run(){
//NEED to use a variable that is passed from introductionState.cpp
}
private:
sf::Uint8 mAlpha;
};
//VARIABLE TO BE PASSED
sf::uint8 alpha
...
...
void IntroScreen::TransitionOut(){
ThreadClass threadc;
sf::Thread th(&ThreadClass::run,&threadc);
th.launch();
transition=true;
}