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

Pages: [1]
1
General / [Threading] findPath
« on: December 20, 2012, 08:37:54 pm »
Hello,

Currently I have a pathfind algorithm for a set of enemies, which uses quite alot of resources and CPU time. So before I ran the algorithm each frame, causing alot of FPS lag. So I made a class with a thread, that takes care of the calculation.
So here's a sketch of what I have:
Npc class
class NPC {
public:
      void setPath(std::vector<Node*>);
      void walkPath();
      ....
private:
     std::vector<Node*> m_path;
}

void walkPath() {
   if(m_path.size() >= 2) {
        walkToNode(m_path.at(1));
}
 

Now for each new NPC I create, I create a thread managing the path calculations
Thread
class Thread {
private:
    m_player;
    m_enemy;
}

void Thread::run() {
    sf::Mutex mutex;
   
    mutex.lock();
   
    std::vector<Node*> path = findPath(m_enemy, m_player);
    m_enemy->setPath(path);
   
    mutex.unlock();
}
 

that's a pretty rought sketch, but you see what I mean.
Also, with the walkPath method, I just always walk to the second element because, by the time the enemy gets there, i'll probably have a new path, calculated from the node the enemy arrives on and just goes from there

Right now, the program just crashes when I use the thread instead of calculating the path each frame due to a segmentation fault. I don't know what I'm doing wrong...

Please help me, thanks!

2
General / [Weird] Linking problems
« on: December 12, 2012, 05:13:50 pm »
Hello, I'm trying out SFML for the first time and everything worked fine, with the example code. So then I started integrating it with my project and came across a really weird problem. So I started with this piece of code:
#include <SFML/Window.hpp>

/*
 * @brief Main function, entry point
 *
 * @return      Exit code
 */


int main() {
        sf::Window window;
        return 0;
}
 

And got the following errors:
Quote
/usr/local/lib/libsfml-window.so: undefined reference to `sf::Clock::Reset()'
/usr/local/lib/libsfml-window.so: undefined reference to `sf::Unicode::UTF8Offsets'
/usr/local/lib/libsfml-window.so: undefined reference to `sf::Clock::Clock()'
/usr/local/lib/libsfml-window.so: undefined reference to `sf::Clock::GetElapsedTime() const'
/usr/local/lib/libsfml-window.so: undefined reference to `sf::Unicode::UTF8TrailingBytes'
/usr/local/lib/libsfml-window.so: undefined reference to `sf::Sleep(float)'

Now, I 'fixed' it like so:
#include <SFML/Window.hpp>

/*
 * @brief Main function, entry point
 *
 * @return      Exit code
 */


int main() {
        sf::Clock testClock; //this fixed the problem???!!!!
        sf::Window window;
        return 0;
}
 



it builds fine, no errors at all...

Someone please help me?

By the way, I'm using SFML 1. 6 on an Ubuntu machine

Pages: [1]
anything