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

Author Topic: Several performance problem!!!  (Read 2471 times)

0 Members and 1 Guest are viewing this topic.

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Several performance problem!!!
« on: December 14, 2008, 02:21:55 pm »
Im creating a gui lib for my game with sfml:

So, i have created the button and textbox, and if fully perfect.

So, im creating now the window class, that will create a window on screen.

But when i will draw the parts of the window, the problem occurr, too many memory is used and the game is so slowly...too slowly...

But, if i comment the lines that draw the sprite(sprite->draw), the game run normals, with good performance, with no problem.

The code is:

Code: [Select]

#include "Janela.h"

/**
 * Construtor
 */
gui::Janela::Janela(unsigned int posX, unsigned int posY, std::string titulo, float largura, float altura, bool modal, bool movel, std::string imagem)
{
    //inicializa atributos
    this->posX    = posX;
    this->posY    = posY;
    this->titulo  = titulo;
    this->largura = largura;
    this->altura  = altura;
    this->modal   = modal;
    this->movel   = movel;

    if (!this->img.LoadFromFile(imagem))
    {
        //não foi possível carregar a imagem
    }

    //inicializa SPRITEs
    this->sprtSuperiorEsquerdo.SetImage(this->img);
    this->sprtSuperiorMeio.SetImage(this->img);
    this->sprtSuperiorDireito.SetImage(this->img);
    this->sprtEsquerdo.SetImage(this->img);
    this->sprtDireito.SetImage(this->img);
    this->sprtFundo.SetImage(this->img);
    this->sprtInferiorEsquerdo.SetImage(this->img);
    this->sprtInferiorMeio.SetImage(this->img);
    this->sprtInferiorDireito.SetImage(this->img);

    //inicializa RECTs
    this->rectSuperiorEsquerdo = sf::IntRect(0,0,11,24);
    this->rectSuperiorMeio     = sf::IntRect(58,0,81,24);
    this->rectSuperiorDireito  = sf::IntRect(224,0,235,24);
    this->rectEsquerdo         = sf::IntRect(0,79,11,85);
    this->rectDireito          = sf::IntRect(224,79,235,85);
    this->rectFundo            = sf::IntRect(10,143,37,170);
    this->rectInferiorEsquerdo = sf::IntRect(0,171,6,177);
    this->rectInferiorMeio     = sf::IntRect(91,171,97,177);
    this->rectInferiorDireito  = sf::IntRect(229,171,235,177);

    //define RECTs
    this->sprtSuperiorEsquerdo.SetSubRect(this->rectSuperiorEsquerdo);
    this->sprtSuperiorMeio.SetSubRect(this->rectSuperiorMeio);
    this->sprtSuperiorDireito.SetSubRect(this->rectSuperiorDireito);
    this->sprtEsquerdo.SetSubRect(this->rectEsquerdo);
    this->sprtDireito.SetSubRect(this->rectDireito);
    this->sprtFundo.SetSubRect(this->rectFundo);
    this->sprtInferiorEsquerdo.SetSubRect(this->rectInferiorEsquerdo);
    this->sprtInferiorMeio.SetSubRect(this->rectInferiorMeio);
    this->sprtInferiorDireito.SetSubRect(this->rectInferiorDireito);

}

/**
 * Destrutor
 */
gui::Janela::~Janela()
{
    //dtor
}

/**
 * Método que desenha o objeto
 */
void gui::Janela::desenhar()
{
    if ( this->visivel == true )
    {
        //inicializa variáveis de uso
        float x, y, xFinal, yFinal;

        //desenha o fundo primeiro
        x = 0;
        y = 0;

        xFinal = (this->posX + this->largura);
        yFinal = (this->posY + this->altura);

        while( (x + this->posX) < xFinal)
        {

            while( (y + this->posY) < yFinal)
            {
                //valida pra ver se não vai estourar
                if ((x + this->posX + this->sprtFundo.GetSize().x) > xFinal)
                {
                    x = (x + this->posX + this->sprtFundo.GetSize().x) - xFinal;
                }

                if ((y + this->posY + this->sprtFundo.GetSize().y) > yFinal)
                {
                    y = (y + this->posY + this->sprtFundo.GetSize().y) - yFinal;
                }

                //desenha
                this->sprtFundo.SetPosition(x + this->posX, y + this->posY);
                gui::Core::app->Draw( this->sprtFundo );

                y += this->sprtFundo.GetSize().y;
            }

            x += this->sprtFundo.GetSize().x;
            y = 0;

        }

        //desenha bordas repetitivas

            //borda superior
            x = 0;
            y = 0;

            while( (x + this->posX) < xFinal)
            {
                if ((x + this->posX + this->sprtSuperiorMeio.GetSize().x) > xFinal)
                {
                    x = (x + this->posX + this->sprtSuperiorMeio.GetSize().x) - xFinal;
                }

                this->sprtSuperiorMeio.SetPosition(x + this->posX, this->posY);

                gui::Core::app->Draw( this->sprtSuperiorMeio );

                x += this->sprtSuperiorMeio.GetSize().x;
            }

        //desenha as bordas dos cantos
        this->sprtSuperiorEsquerdo.SetPosition( this->posX, this->posY );
        this->sprtSuperiorDireito.SetPosition( this->posX + this->largura - this->sprtSuperiorDireito.GetSize().x, this->posY );

        this->sprtInferiorEsquerdo.SetPosition( this->posX, this->posY + this->altura - this->sprtInferiorEsquerdo.GetSize().y );
        this->sprtInferiorDireito.SetPosition( this->posX + this->largura - this->sprtInferiorDireito.GetSize().x, this->posY + this->altura - this->sprtInferiorDireito.GetSize().y );

        gui::Core::app->Draw( this->sprtSuperiorEsquerdo );
        gui::Core::app->Draw( this->sprtSuperiorDireito );
        gui::Core::app->Draw( this->sprtInferiorEsquerdo );
        gui::Core::app->Draw( this->sprtInferiorDireito );


    }
}

/**
 * Método que verifica os status do teclado/mouse
 */
void gui::Janela::verificarInput()
{
    if ( this->visivel == true )
    {
        //
    }
}




What can be happen?

 

anything