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

Add THST and doctest #3534

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

Linvail
Copy link
Contributor

@Linvail Linvail commented Oct 8, 2024

Add THST and doctest

  • THST: Templated hierarchical spatial trees designed for
    high-performance and hierarchical spatial partitioning use cases.
    It improves the performance of the handling of ranged buffs.

Here are some test reports.
https://github.com/Linvail/keeperfx/wiki/Test-THST-on-keeperfx-for-querying-nearby-creatures
https://github.com/Linvail/keeperfx/wiki/Test-THST-on-keeperfx-for-querying-nearby-creatures-2

  • doctest is a new C++ testing framework but is by far the fastest
    both in compile times (by orders of magnitude) and runtime compared
    to other feature-rich alternatives.
    We use it to create test programs.

With the help of THST, the following improvements are introduced.

  • Ranged Buffs can be cast on the creatures of allied player.
  • Prevent multiple creatures from casting the same spell on the same target.
    For example, assuming Time Mage can cast the Ranged Speed, if
    we put 4 Time Mages and 4 Dragons in the same room, 4 Dragons
    will get the Speed effect. Those Time Mages will not cast the
    Ranged Speed on the same target.

Type: New Feature
Change-Id: Ie0857b57cc00badf1ba46c2f589ed0a4f6a6b546

The current performance of using ranged buffs is not good.
It requires one search for each ranged buff instance. The search
results cannot be retained, and they cannot benefit future usages.

This change adds scan_nearby_creature(), which runs every turn.
For each creatures, it scan nearby area and collect creatures
within CREATURE_SCAN_RANGE_MAX, and record found creatures in the
CreatureControl.creatures_nearby.

This CreatureControl.creatures_nearby is an sorted array by
the distance in ascending order.

It can be used in many places, especially useful for ranged buffs.
It will benefit the combat(searching targets) in the future.

Since the allied creatures are also included, so we can extend our
ranged buffs to allies. The new property - APPLY_TO_ALLIES is added.

Type: New Feature
Add new function: get_nth_creature_with_filter()
This is a creature-specialization of get_nth_thing_of_class_with_filter.
Instead of the entire map, this one only searches the
CreatureControl.creatures_nearby array of the input creature, so the
search base is much smaller.

Type: Optimization
@Linvail Linvail marked this pull request as draft October 8, 2024 11:23
@Linvail Linvail changed the title Feature/battlefield awareness Store nearby creatures in GameControl Oct 8, 2024
@Linvail
Copy link
Contributor Author

Linvail commented Oct 8, 2024

This is my preliminary work for the mass/group ranged buffs.

@Linvail
Copy link
Contributor Author

Linvail commented Oct 8, 2024

Still a draft, not tested, but the design is almost fixed.

src/thing_creature.c Outdated Show resolved Hide resolved
Change-Id: Ibd169e49d01fadab7bb3fe4aca9d0bd104734eff
* THST: Templated hierarchical spatial trees designed for
high-performance and hierarchical spatial partitioning use cases.
It improves the performance of the handling of ranged buffs.

Here are some test reports.
https://github.com/Linvail/keeperfx/wiki/Test-THST-on-keeperfx-for-querying-nearby-creatures
https://github.com/Linvail/keeperfx/wiki/Test-THST-on-keeperfx-for-querying-nearby-creatures-2


* doctest is a new C++ testing framework but is by far the fastest
both in compile times (by orders of magnitude) and runtime compared
to other feature-rich alternatives.
We use it to create test programs.

Type: New Feature
Change-Id: Ie0857b57cc00badf1ba46c2f589ed0a4f6a6b546
@Linvail Linvail changed the title Store nearby creatures in GameControl Add THST and doctest Nov 3, 2024
@Linvail Linvail self-assigned this Nov 3, 2024
@Linvail Linvail marked this pull request as ready for review November 3, 2024 13:24
src/thing_list.c Outdated Show resolved Hide resolved
Change-Id: I838cd7adb4f8e7a34d2ed8c99e8224a2c5bde2cb
Prevent multiple creatures from casting the same spell on the
same target.

For example, assuming Time Mage can cast the Ranged Speed, if
we put 4 Time Mages and 4 Dragons in the same room, 4 Dragons
will get the Speed effect. Those Time Mages will not cast the
Ranged Speed on the same target.

Type: New Feature
Change-Id: Ibc408f0ae2cf154db84e51bdf6067fbfefcff0f6
doctest allows us to write test cases in the main program's code
without making a new source code file.
To facilitate that, I move doctest to the submodule folder.
All submodules should be put here in the future.

Also add README and LICENSE for THST.

Type: Code Improvement
Change-Id: I9d2da6a6d5cd7608e7c7872df8313d48bd5cd0fd
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

Successfully merging this pull request may close these issues.

2 participants