Giter Site home page Giter Site logo

Multithreaded Pathfinding about barony HOT 3 CLOSED

turningwheel avatar turningwheel commented on August 11, 2024
Multithreaded Pathfinding

from barony.

Comments (3)

WALLOFJUSTICE avatar WALLOFJUSTICE commented on August 11, 2024

What would you say is the most performance demanding part of the pathfinding? I found with mob spawns of 15+ the frames would only drop some of the time, but obviously more consistently at higher amounts.

Every mob checks every entity on the map through it's WAIT and HUNT state until it finds something to interact with, could there be much of an improvement to limiting the search range to the vision distance before processing direction or the target light levels?

from barony.

SheridanR avatar SheridanR commented on August 11, 2024

I would absolutely start this task by sorting different object types into different lists entirely, rather than having one enormous list of entities which is crawled through linearly every time we want to look up the object. The dangerous part is that the pointers in the entity list are the only "owners" of the object right now, and if you add additional lists referencing the same objects then you can end up creating dead references if you change/remove the data. For this reason we'd need a shared pointer system, and I wouldn't necessarily use the one that comes stock with C++ (convenient as it is) though that would certainly be a start.

At that point, I would also go the extra mile and replace the entity lists with hash tables, where the entity uid effectively takes the place of the hash (thus acting as the key index for an array of lists). That would greatly improve entity lookup times, which is important for speeding up other areas of the code (though a bit tangential to this issue...)

Finally, you'd have to deal with thread-safety. How do you find the path while entities are still moving in the world and changing the terrain? It wouldn't be too difficult to generate and pass an obstacle map to the thread which it can then use to find the path, rather than working with the raw level data... in fact, that would solve most of your problems right there. For an example on how to copy and store level data in memory, you could reference the undo/redo functions for the editor in editor.cpp.

Those are my thoughts on this :)

from barony.

WALLOFJUSTICE avatar WALLOFJUSTICE commented on August 11, 2024

Well 2 years later.. I can say we finally got somewhere.
Pathfinding now uses "entities on tile" checking rather than looping through every entity at every tile, generatePathMaps() as such longer a big deal, no lag when mining blocks.
Lots of entity lists were replaced by a creature-list which only needs to traverse the 20-30 monsters on a map instead of 600 entities.

from barony.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.