Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multithreading #75

Open
8 tasks
fgenesis opened this issue Jan 13, 2021 · 0 comments
Open
8 tasks

Multithreading #75

fgenesis opened this issue Jan 13, 2021 · 0 comments

Comments

@fgenesis
Copy link
Member

Aquaria is inherently a single-threaded game but there are some areas that can be MT'd.

I'd like to use tws instead of fumbling with threads directly. One IO thread, #cores worker threads.

List of ideas, to-be-extended:

  • Do NOT want to MT OpenGL. No GL function call on any other thread than main!

  • Texture batch loading. Loading PNGs takes forever. On game start and when a map is loaded, the game loads in a ton of textures. The IO should be done by an IO thread and then PNG decoding passed off to a worker. Requires glpng rework, see Replace 3rd party libs #74.

    • Optimization, if glMapBuffer() is available: Map a GPU buffer, kick off decoding PNG data into the buffer in a separate thread, when done do glTexImage2D() using that buffer as GL_PIXEL_UNPACK_BUFFER in the main thread. So the GPU can still do the texture prep in the background.
  • Rendering:

    • Layer traversal can be MT'd: One job per RenderLayer that accumulates objects to render in a list. One list per layer. Kick off lists in order once all are done. Not sure how much this is worth. Would greatly simplify future OpenGL decoupling if the renderer doesn't need to know about layers and object hierarchies and whatnot.
    • Minimap? Rendering the minimap seems to be quite expensive. Could prepare a vertex buffer in background.
    • GridRender? Could also recalc a vertex buffer whenever the map changes or the camera has moved far enough.
  • Pathfinding:

    • Simple pathfinding: Make Entity::moveToPos() kick off a background job and start to move a few frames later once the path has been calculated. Avoids lag spikes. Need to handle entity or map deletion while a job is active.
    • Advanced (not used by vanilla): See PathFinding::beginFindPath(). Can calculate the entire path in background instead of incremental updates per frame.
  • Schoolfish update: FlockEntity::updateFlockData()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant