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 - Krypt0n

Pages: [1]
1
Graphics / Re: Extreme Speed loss
« on: May 04, 2012, 06:17:22 pm »
Don't create them dynamically, there's no need to.

No, I meant this:
Code: [Select]
for(int i=0;i<5;++i)
for(int j=0;j<5;++j)
mRooms.push_back(new Room(10,10,10*i,10*j));
How am I able to do this without pointers?


Topic related:
The fps drop really nerves me. if noone knows how to fix this, I'll switch to sdl

2
Graphics / Re: Extreme Speed loss
« on: May 03, 2012, 07:36:22 pm »
Where is the vector filled? Any why std::vector<Room*> instead of std::vector<Room>?
In the function Game::Genworld() wich is called in the constructor and builds 25 rooms.
Room* because i dont know how to create objects dynamically  without the new operator
Quote
int **walkmap;
Looks dangerous. Why no containers? Use new and delete as rarely as possible.
works perfectly

Quote
mRooms.at(i)

I'll change this to iterators
Quote
int Init(sf::RenderWindow* nWindow);
Why don't you use the constructor?
because I wanted to return an errorvalue when an image wasnt found.(Image loading is done inside this)
approx. 12 10x10px Images

Everything works fine in the first few seconds. My problem is that after this timespan it spends a lot of time with memory operations (like free or malloc) in RenderWindow::draw()

3
Graphics / Re: Extreme Speed loss
« on: May 03, 2012, 04:26:55 pm »
main.cpp:
Code: [Select]

string strfromint(int input)
{
stringstream inputs;
inputs<<input;
return inputs.str();
}

int main()
{
Game mGame;
Draw mDraw;
        sf::RenderWindow window(sf::VideoMode(640, 480), "SFML works!");
        mDraw.Init(&window);
sf::Text text("Hello SFML");
sf::Clock mClock;
mClock.restart();
    while (window.isOpen())
    {
        sf::Event event;
        if (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
text.setString(strfromint((int)mClock.getElapsedTime().asMilliseconds()));
               mClock.restart();

window.clear();
mGame.DrawGame(&mDraw);
                window.draw(text);
                window.display();
    }

    return 0;
}

Game.h
Code: [Select]
class Game{
std::vector<Room*> mRooms;
public:
void Game::DrawGame(Draw *nDraw){
for(unsigned int i=0;i<mRooms.size();++i)
mRooms.at(i)->DrawRoom(nDraw);
}
};

Room.h
Code: [Select]
class Room{
private:
int sizex;
int sizey;
int posx;
int posy;
int **tilemap;
int **walkmap;
public:
Room(int sx,int sy,int px,int py)
       {sizex=sx;
sizey=sy;
posx=px;
posy=py;
tilemap=new int*[sizey];
for(int i=0;i<sizey;++i)
tilemap[i]=new int[sizex];
for(int i=0;i<sizex;++i)
for(int j=0;j<sizey;++j)
tilemap[j][i]=10;

walkmap=new int*[sizey];
for(int i=0;i<sizey;++i)
walkmap[i]=new int[sizex];
for(int i=0;i<sizex;++i)
for(int j=0;j<sizey;++j)
walkmap[j][i]=0;
        };
~Room();
void DrawRoom(Draw* nDraw)
        {
            for(int i=0;i<sizex;++i)
for(int j=0;j<sizey;++j)
nDraw->DrawTile(tilemap[j][i],i+posx,j+posy);
         }
};
Code: [Select]
class Draw {
private:
vector<sf::Texture> mTiles;
public:
int Init(sf::RenderWindow* nWindow);
void DrawTile(int number,int x,int y);
};
shortend unimportant parts and added  function definitions to declarations

4
Graphics / Re: Extreme Speed loss
« on: May 03, 2012, 07:10:57 am »
this is used to draw tiles on the screen:
Code: [Select]
void Draw::DrawTile(int number, int x, int y){
sf::Sprite tex(mTiles.at(number));
tex.setPosition((float)x*10,(float)y*10);
mWindow->draw(tex);
}

mTiles is a vector<sf::Texture>. Textures are loaded using:
Code: [Select]
void Draw::LoadTile(const string str){
sf::Image texture;
sf::Texture ftexture;

texture.loadFromFile(str);
sf::Color ColorKey(255,255,255);
texture.createMaskFromColor(ColorKey);

ftexture.loadFromImage(texture);
mTiles.push_back(ftexture);
}

In the mainloop is:
Code: [Select]
window.clean()
DrawTiles() //Draws the Tiles I want to draw
window.display()

(rest is like the example code http://www.sfml-dev.org/documentation/2.0/)

the fps drop occures instantly after a not reproducable timespan

5
Graphics / Re: Extreme Speed loss
« on: May 02, 2012, 07:56:03 pm »
I know that debugging builds aren't meant to have a great perfromance, but the drop from 125 to 5 fps isnt normal, is it?
(I wasn't able to reproduce the fps drop with a release build)

6
Graphics / Extreme Speed loss
« on: May 02, 2012, 05:49:04 pm »
Hi,

I'm using SFML in my newest project for basic graphic input/output.
I'm using RenderWindow::draw to draw about 100 10x10px Tiles.
(Using vs2008/sfml 2RC/ setup like tutorial)
After a variable timespan(more then 20s) the time used to draw these, changes from 8ms to 200ms, what totally breaks the useage.
When I stop the programm while debugging, the callstacks often reffers to basic memory operations executed during RenderWindow::draw.
How can I fix this enormous speed loss?

(sorry for bad english)
Greetings Krypt0n

Pages: [1]
anything