Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Messages - snoozer87

Pages: [1]
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 :)

2
Graphics / Re: SFML 2.0 Slow loading textures from file
« on: June 05, 2012, 05:09:41 pm »
I see, so doing this would be better practice?

AllTextures.push_back(t_pPlayerPawnBarrow.loadFromFile(".//Resources//PlayScreen//barrow.png"));

*EDIT*
Wait, now that I see the code it looks wrong. Either it won't work, or it'll be exactly the same as before probably :)

*EDIT2*
Nvm that would never work ...

3
Graphics / Re: SFML 2.0 Slow loading textures from file
« on: June 05, 2012, 04:37:59 pm »
Unless vector.push_back creates a copy, I'm not copying the textures. the reason I'm doing is this is so I can easily pass all textures to my main thread :).

In my main thread I put all textures in local variables, so I can use them and then I clean up the passed vector (freeing memory).

Example

Loadingthread
Code: [Select]
....
//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);

Main thread
Code: [Select]
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);
}

4
Graphics / SFML 2.0 Slow loading textures from file
« on: June 05, 2012, 03:11:32 pm »
Dear community,

I'm writing an application that has to load a lot of 'HI-RES' textures in (1280x800), 35 of them at the moment. This is an application that has to work on a windows 7 tablet and I have noticed it takes a quite a long time to load in all of them (aprox. 30 to 60 seconds).

I just want to know if this is normal and if not, what is the best way to load in textures (at the moment I am loading all of them in a separate thread while showing a loading screen in the main one). At the end I place all textures into a Vector, which allocated to the right size (maybe this is slowing things down, but I don't think so as I tried putting the vector code in comments);

An example:
void ThreadLoading::loadGame(){
        t_All_Textures.clear();
        s_All_Sprites.clear();
        t_All_Textures.reserve(35);
        s_All_Sprites.reserve(2);
       
        //TEXTURES
        //Global background
        t_pPlayBackground.loadFromFile(".//Resources//PlayScreen//background.png");

        //Status ribbons (Available,owned and sold)
        t_pStatusAvailable.loadFromFile(".//Resources//PlayScreen//available.png");
        t_pStatusOwned.loadFromFile(".//Resources//PlayScreen//owned.png");
        t_pStatusSold.loadFromFile(".//Resources//PlayScreen//sold.png");
        t_pStatusFree.loadFromFile(".//Resources//PlayScreen//available.png");

        //Normal property/chance/community chest backgrounds
        t_pProperty0.loadFromFile(".//Resources//PlayScreen//0.png");
        t_pProperty1.loadFromFile(".//Resources//PlayScreen//1.png");
        t_pProperty2.loadFromFile(".//Resources//PlayScreen//2.png");
        t_pProperty3.loadFromFile(".//Resources//PlayScreen//3.png");
        t_pProperty4.loadFromFile(".//Resources//PlayScreen//4.png");
        t_pProperty5.loadFromFile(".//Resources//PlayScreen//5.png");
        t_pProperty6.loadFromFile(".//Resources//PlayScreen//6.png");
        t_pProperty7.loadFromFile(".//Resources//PlayScreen//7.png");
        t_pProperty8.loadFromFile(".//Resources//PlayScreen//8.png");
        t_pProperty9.loadFromFile(".//Resources//PlayScreen//9.png");
        t_pProperty10.loadFromFile(".//Resources//PlayScreen//10.png");
       
        //Buy backgrounds
        t_pProperty1_buy.loadFromFile(".//Resources//PlayScreen//1b.png");
        t_pProperty3_buy.loadFromFile(".//Resources//PlayScreen//3b.png");
        t_pProperty5_buy.loadFromFile(".//Resources//PlayScreen//5b.png");
        t_pProperty6_buy.loadFromFile(".//Resources//PlayScreen//6b.png");
        t_pProperty8_buy.loadFromFile(".//Resources//PlayScreen//8b.png");
        t_pProperty9_buy.loadFromFile(".//Resources//PlayScreen//9b.png");

        //Buyerror backgrounds
        t_pProperty1_buyError.loadFromFile(".//Resources//PlayScreen//1eb.png");
        t_pProperty3_buyError.loadFromFile(".//Resources//PlayScreen//3eb.png");
        t_pProperty5_buyError.loadFromFile(".//Resources//PlayScreen//5eb.png");
        t_pProperty6_buyError.loadFromFile(".//Resources//PlayScreen//6eb.png");
        t_pProperty8_buyError.loadFromFile(".//Resources//PlayScreen//8eb.png");
        t_pProperty9_buyError.loadFromFile(".//Resources//PlayScreen//9eb.png");

        //Playermenu background, different colours for each player
        t_pPlayerMenu1.loadFromFile(".//Resources//PlayScreen//playermenu1.png");
        t_pPlayerMenu2.loadFromFile(".//Resources//PlayScreen//playermenu2.png");
        t_pPlayerMenu3.loadFromFile(".//Resources//PlayScreen//playermenu3.png");
        t_pPlayerMenu4.loadFromFile(".//Resources//PlayScreen//playermenu4.png");

        //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");
....
 

Best regards
Yannick

5
Ok, I tried this now
Code: [Select]
RulesScreen::RulesScreen(){
sf::Thread th(&RulesScreen::loadThread,this);
}

But now I get an access violation here:

Code: [Select]
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...

6
Dear community,

At the moment I am trying to load my resources in separate thread so that I can show a loading screen in the mean time, everything works, however I had to make all resources global variables (textures/sprites/...). This is probably very bad practice and I would like to know how work with namespaces and threads.

To clarify, this is my current method and it works:

RulesScreen.h
Code: [Select]
#ifndef _RULESSCREEN_H_
#define _RULESSCREEN_H_
#define MAXPANELS 4
#include "GameScreen.h"

class RulesScreen : public GameScreen{
public:
...
protected:
...
private:
.....

sf::Thread *th;
        ....
};
#endif

RulesScreen.cpp
Code: [Select]
//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();
}

However, when I change this code to the more conventional method:

RULESCREEN.H
Code: [Select]
...
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.CPP
Code: [Select]
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();
}

Then I get this error:
error C2064: term does not evaluate to a function taking 0 arguments

Any ideas on how to do this the right way?

Best regards
Yannick

7
System / Re: Passing variable to external thread class
« on: April 25, 2012, 09:34:03 am »
Alright, sry for bothering you so much, but how would you do it then. Because now I tried this and the exe still does nothing:

caller.h
Code: [Select]
...
private:
ThreadClass *threadc;
sf::Thread *th;

caller.cpp
Code: [Select]
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();
}
}

**EDIT

MY apologies, I forgot to add my fade.png to the release map :s. But is my code correct, or is there a cleaner and better way to do it?

8
System / Re: Passing variable to external thread class
« on: April 25, 2012, 09:19:17 am »
I've changed them to global variables, but for some reason it works in VS2010 release mode, but when I try the .Exe it doesn't work. I should clarify that the not working is the fact that the thread doesn't seem to start and thus the screen is not faded.

Code: [Select]
//Global variables
ThreadClass threadc(IntroScreen::Instance());
sf::Thread th(&ThreadClass::run,&threadc);

9
System / Re: Passing variable to external thread class
« on: April 25, 2012, 12:29:32 am »
Alright, I got it running but my thread is blocking the caller and so the caller waits on the thread to be finished, which makes it not a thread at all :p.

Caller (does the sfml drawing and stuff) introScreen.cpp
Code: [Select]
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;
}

Thread.h
Code: [Select]
#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;
};

Thread.ccp
Code: [Select]
#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;
}
}
}

Is this the right way to do it and if so, what am I doing wrong?

Best regards

10
System / Passing variable to external thread class
« on: April 24, 2012, 11:44:41 pm »
How would the procedure work in the tutorials for an external thread class (SFML 2.0), like the code below:

Thread.ccp
Code: [Select]
#include "globalInclude.h"

class ThreadClass{
public:
void run(){
//NEED to use a variable that is passed from introductionState.cpp
}

private:
sf::Uint8 mAlpha;
};

introductionState.ccp
Code: [Select]

//VARIABLE TO BE PASSED
sf::uint8 alpha

...
...

void IntroScreen::TransitionOut(){

ThreadClass threadc;
sf::Thread th(&ThreadClass::run,&threadc);
th.launch();
transition=true;
}

Best regards

11
SFML wiki / Re: sfeMovie project [v1.0 RC1 available]
« on: April 21, 2012, 02:51:07 am »
I'm sorry to bother you again, but I just rebuild the whole project and I selected to build all the codecs (to be sure). Sadly enough, the problem persists and I cannot load avi or flv files :(.

I'm aware that avi and flv are containers, so maybe the underling codec is not supported :).

12
SFML wiki / Re: sfeMovie project [v1.0 RC1 available]
« on: April 20, 2012, 08:09:26 pm »
Thanks a lot for the info, I just thought about rebuilding myself, so my apologies for the rather stupid question :p.

13
SFML wiki / Re: sfeMovie project [v1.0 RC1 available]
« on: April 20, 2012, 04:52:30 pm »
Alright, your project looks really good and it would be perfect for showing an intro. However, the function movie.openFromFile(...) never seems to work, I've tried with all sorts of formats now (.avi and flv for example) and it just never loads...

I also don't get any errors or debug information... Any idea what the problem is? Do I need to doo something with ffmpeg first or is it enough to link against the sfe-movie.lib and add the .dlls to the project?

Best regards

*EDIT*

Tried an ogg file and that loads perfectly (only audio)

*EDIT2*
Video ogg works aswell, everything else fails :(

Pages: [1]