Code Monkey home page Code Monkey logo

Comments (6)

selimanac avatar selimanac commented on May 23, 2024 2

actually, I guess did this for my old project. I was searching for nearest enemy(or hero) in attack range on turn based game. It was a draft quality project but I'm going to try to find the code that I did. It might be useful.

from daabbcc.

selimanac avatar selimanac commented on May 23, 2024 1

Hi @8bitskull

Distance based shorting is on dev branch now. Please use this url as dependency:
https://github.com/selimanac/DAABBCC/archive/refs/heads/dev.zip

I'm going to clean up the code if works for you. I just did a few small sized tests but it is hard for me to test it on large scales as your game require.

I prefer to use separate functions since I don't want to implement an extra if-else check on the exist functions. Params are same. It is enough to add "_short" at the end:

  • aabb.query_id_short(group_id, aabb_id)
  • aabb.query_short(group_id, x, y, w, h)
  • aabb.raycast_short(group_id, start_x, start_y, end_x, end_y)

I made a change on returning results. Now, they are returning IDs and Distances. This might cause you a lot of extra work.
If so, please let me know, I can remove the distance from results and just kept the ID as before. But it might be useful(double checking) to compering the distances between those results and your Lua results:

{ --[[0x10e32b530]]
  1 = { --[[0x10e32b590]]
    id = 3,
    distance = 0
  },
  2 = { --[[0x10e32b630]]
    id = 0,
    distance = 39
  }
}

Also I updated the example(it is the same but just in case)

I hope this cause a performance gain...
I don't have high hopes but I'm going to take a look at the other issue today.

from daabbcc.

paweljarosz avatar paweljarosz commented on May 23, 2024

I believe the only struggle here would be to extract the positions for given ids from the dynamic tree to calculate those distances, right? ;)

from daabbcc.

selimanac avatar selimanac commented on May 23, 2024

I believe the only struggle here would be to extract the positions for given ids from the dynamic tree to calculate those distances, right? ;)

Nope, this is the easiest part. It is possible to extract their center position and distance from given id. I already have those math functions. Most challenging part is the ordering the array by distance with ids. :) Unfortunately it is not simple as lua with C.

from daabbcc.

8bitskull avatar 8bitskull commented on May 23, 2024

Thanks very much @selimanac.

I can confirm that it works as expected. It reduces my targeting function from 24 lines to 9 lines and produces much more robust results - before, my function was guessing the closest enemy within an error margin to save on performance. Now I get the actual closest enemy.

from daabbcc.

selimanac avatar selimanac commented on May 23, 2024

@8bitskull I made a typo on function names. All "_short" -> "_sort now. Sorry about that.
You can check out the 2.1 branch(default branch now). Also updated the readme.
I'm going to close this issue now, feel free to open a new issue if there is a problem.

from daabbcc.

Related Issues (9)

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.