Commit Graph

29 Commits

Author SHA1 Message Date
Nicolas Lebacq
c9cc4324d3 NextAction refactoring to eliminate sentinel arrays and pointers (#1923)
<!--
> [!WARNING]
> **This is a DRAFT PR.**
> The structure is not definitive. The code might not be optimised yet.
It might not even start nor compile yet.
> **Don't panic.  It's going to be ok. 👌 We can make modifications, we
can fix things.** 😁
-->
# Description

This PR aims to refactor the NextAction declaration to achieve two
goals:

## Eliminate C-style sentinel arrays

Currently, a double pointer (`NextAction**`) approach is being used.
This an old pre-C++11 (< 2011) trick before `std::vector<>` became a
thing.
This approach is painful for developers because they constantly need to
declare their `NextAction` arrays as:
```cpp
NextAction::array(0, new NextAction("foo", 1.0f), nullptr)
```
Instead of:
```cpp
{ new NextAction("foo", 1.0f) }
```
The first argument of `NextAction::array` is actually a hack. It is used
to have a named argument so `va_args` can find the remaining arguments.
It is set to 0 everywhere but in fact does nothing. This is very
confusing to people unfamiliar with this antiquated syntax.
The last argument `nullptr` is what we call a sentinel. It's a `nullptr`
because `va_args` is looking for a `nullptr` to stop iterating. It's
also a hack and also leads to confusion.

## Eliminate unnecessary pointers for `NextAction`

Pointers can be used for several reasons, to cite a few:
- Indicate strong, absolute identity.
- Provide strong but transferable ownership (unlike references).
- When a null value is acceptable (`nullptr`).
- When copy is expensive.

`NextAction` meets none of these criteria:
- It has no identity because it is purely behavioural.
- It is never owned by anything as it is passed around and never fetched
from a registry.
- The only situations where it can be `nullptr` are errors that should
in fact throw an `std::invalid_argument` instead.
- They are extremely small objects that embark a single `std::string`
and a single `float`.

Pointers should be avoided when not strictly necessary because they can
quickly lead to undefined behaviour due to unhandled `nullptr`
situations. They also make the syntax heavier due to the necessity to
constantly check for `nullptr`. Finally, they aren't even good for
performance in that situation because shifting a pointer so many times
is likely more expensive than copying such a trivial object.

# End goal

The end goal is to declare `NextAction` arrays this way:
```cpp
{ NextAction("foo", 1.0f) }
```

> [!NOTE]
> Additional note: `NextAction` is nothing but a hacky proxy to an
`Action` constructor. This should eventually be reworked to use handles
instead of strings. This would make copying `NextAction` even cheaper
and remove the need for the extremely heavy stringly typed current
approach. Stringly typed entities are a known anti-pattern so we need to
move on from those.
2026-01-06 12:37:39 +01:00
kadeshar
85c7009fe1 Codestyle fix (#1797)
Warning:
Dont change this PR as draft to make it testable


DONT REVIEW UNTIL Codestyle C++ workflow dont pass
2025-11-05 21:10:17 +01:00
bash
0cc15411c1 license update (#1674) 2025-09-30 15:19:44 +02:00
Revision
fcb956ec1b Removed unnecessary spaces 2025-09-19 22:43:50 +02:00
Yunfan Li
feda619066 Engine optimization for better performance and mem usage (#1462)
* Optimize loot

* World channel talk

* General improvement

* Engine rebuild for performance and memory usage

* Fix crash with AutoDoQuest = 0
2025-07-25 12:11:03 +02:00
SaW
419e96e5aa Revert expireActionTime (#991)
* Revert expireActionTime

* Revert expireActionTime

* Revert RemoveExpired

* Revert RemoveExpired

* Revert RemoveExpired

* Revert Action expiration
2025-02-21 11:32:00 +08:00
Yunfan Li
bb729e35b9 Fix stuck on knockback, enhance movement & flee and trap weave strats (#980)
* Hunter trap weave strats

* Do not allow actions to stack

* Remove trap weave by default

* Refactor on Engine

Co-authored-by: SaW <swerkhoven@outlook.com>

* Remove unused funcs in Queue

* Remove ExpireActionTime config

---------

Co-authored-by: SaW <swerkhoven@outlook.com>
2025-02-18 22:55:44 +08:00
SaW
72db64ba84 Refactored Engine::DoNextAction (#854)
Update Engine.cpp
2025-01-10 18:52:20 +01:00
Yunfan Li
21e17e163b [Spell] Healer spell enhancement 2024-10-04 20:48:29 +08:00
Yunfan Li
2ddaae9ef0 Dynamic delay 2024-08-14 18:37:21 +08:00
Yunfan Li
085b2e7f19 Improve containsstrategy performance 2024-08-05 22:07:07 +08:00
Yunfan Li
53611c9040 Run clang-format 2024-08-04 10:23:36 +08:00
Yunfan Li
e1e51f52d1 Fix triggers bug 2024-07-31 23:20:54 +08:00
Atidot3
eec4776672 removed action error log 2024-07-28 10:47:33 +02:00
Atidot3
d21d1e9b68 Suggest dungeon implementation + log action unknown to help debug 2024-07-27 10:13:33 +02:00
Yunfan Li
7cacca5293 [Optimization] Better performance 2024-06-24 21:56:14 +08:00
Yunfan Li
45d0ae00ab default actions 2023-10-22 12:50:17 +08:00
Yunfan Li
c8d223e898 rollback strategy deletion 2023-10-14 19:29:53 +08:00
Yunfan Li
5d3ab08d30 cast time strategy & relieve memory leak 2023-10-13 23:29:48 +08:00
Yunfan Li
0437d73eb9 engine depth 2023-08-24 22:04:00 +08:00
Yunfan Li
8a4b43f02e performance improve 2023-08-10 01:00:55 +08:00
Yunfan Li
09566cb664 miscs: engine 2023-08-03 21:27:59 +08:00
Yunfan Li
1c47108c23 coredump fix & rpg actions 2023-08-03 15:15:31 +08:00
Yunfan Li
6ba6bc3615 performance optimize 2023-07-27 11:39:03 +08:00
Yunfan Li
429dc03100 feat: fix warning 2023-05-24 19:44:53 +08:00
Yunfan Li
c16e587854 fix: bot stuck after drink or food && initialization customized 2023-05-23 23:39:20 +08:00
qcloud
32da0c07c9 feat: log action 2023-05-22 23:14:17 +08:00
郑佩茹
256b8c79f9 Add more logging to debug strategy for useless/not possible actions 2023-03-23 12:41:07 -06:00
UltraNix
b952636f0d Big update. 2022-03-12 22:27:09 +01:00