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.


Topics - Ullaakut

Pages: [1]
1
Graphics / sf::Font generates strange behaviour
« on: June 22, 2015, 01:03:44 pm »
Hi,

I'm having issues with sf::Font and sf::Text instances.

My Interface class contains an instance of sf::Font, and at each loop turn, I instantiate an sf::Text using my previously loaded font. The problem is that even though the loading seems to work correctly, my game doesn't work and hangs in the networking part of my game loop.

If I comment the lines where the font is loaded, the problem disappears.. I can't figure out what could be the problem.

Here is my Interface class :

#include "Interface.hh"

Interface::Interface()
{
        if (!_font.loadFromFile(FONT))
           std::cerr << "Font loading failed" << std::endl;
}

Interface::~Interface() {}

void Interface::update(std::map<AObject::Objects, int> c)
{
        this->_content = c;
}

void Interface::draw(sf::RenderWindow *w, std::map<AObject::Objects, sf::Texture>& t, Team* team)
{
        sf::Sprite s;
        if (team != nullptr)
                {
                        sf::Text text(team->getId(), _font, 150);

                        text.setPosition(915, 380);
                        text.setColor(team->getColor());
                        text.setStyle(sf::Text::Regular);
                        w->draw(text);
                }
        s.setTexture(t[AObject::INTERFACE]);
        s.setPosition(900, 0);
        w->draw(s);
}
 

Everything works absolutely fine without the use of sf::Font and sf::Text in this part of the code.

Am I missing something obvious here? :/

EDIT: Valgrind seems to correct the strange behaviour but doesn't tell me where it happens

REEDIT: Problem solved, apparently an error in my Networking class was not causing any trouble before, but does when instantiating a sf::Font. The error has been deleted, and everything runs fine now. Sorry for the trouble :) This post can be deleted, it won't help anyone

Thanks

2
Window / [SOLVED] RenderWindow::dislay() takes 80ms
« on: June 20, 2015, 02:52:52 pm »
Hi,

I've got a performance issue: I'm working on an online graphical client which displays a map according to what the servers sends. The window has to display ~1500-2000 sprites at every frame, most of which does not change position nor texture.

The networking part takes 4µs in the loop, getting the objects from the EntitiesManager takes 35µs, drawing them takes also 4-5µs, but the call to RenderWindow::display() in the loop takes 80 000µs and therefore destroys my framerate.

What could be the reason of this problem? Too many sprites?

Here is my game loop:

// Launches the game
void GameEngine::run()
{
  while(_window.isOpen())
  {
    if (_em != nullptr && _em->isEnded())
      break;
    else if (_em != nullptr && _camera == nullptr)
      _camera = new ViewPoint(_em->getWidth(), _em->getHeight());
    sf::Event e;
    while (_window.pollEvent(e))
    {
      if (e.type == sf::Event::Closed)
        _window.close();
      if (e.type == sf::Event::MouseButtonPressed)
        selectTarget(e.mouseButton.x, e.mouseButton.y);
      if (e.type == sf::Event::KeyPressed)
        {
        if (e.key.code == sf::Keyboard::Escape)
          _window.close();
        if (e.key.code == sf::Keyboard::Left && _camera->getX() > 10)
          _camera->setPos(glm::vec2(_camera->getX() - 1, _camera->getY()));
        if (e.key.code == sf::Keyboard::Right && _camera->getX() < _em->getWidth() - 10)
          _camera->setPos(glm::vec2(_camera->getX() + 1, _camera->getY()));
        if (e.key.code == sf::Keyboard::Up && _camera->getY() > 10)
          _camera->setPos(glm::vec2(_camera->getX(), _camera->getY() - 1));
        if (e.key.code == sf::Keyboard::Down && _camera->getY() < _em->getHeight() - 10)
          _camera->setPos(glm::vec2(_camera->getX(), _camera->getY() + 1));
      }
    }
    _network->doSelect();
    if (_network->isAlive())
    {
      std::list<std::string> msg = _network->getMessages();
      for (auto it = msg.begin(); it != msg.end(); it++)
        {
          std::cout << *it << std::endl;
          if ((*it).compare("BIENVENUE") == 0)
            {
              _network->addMessage(ASK_EVERYTNG);
              std::cout << "Asking everything" << std::endl;
            }
          else
            _parser->parse(*it);
        }
    }
    else
    {
      std::cout << "Network dead" << std::endl;
      break;
    }

    // if (_camera->hasTarget())
      // _camera->updatePos();
    _window.clear();
    if (_em != nullptr && _camera != nullptr)
      drawMap();
    _window.display();
  }
  close(_server_fd);
}
 

(I know the networking/parsing part is kind of dirty but it's not the problem here :p)

Pages: [1]