Skip to content

Commit

Permalink
use ENTITY_MASK when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Auto committed Jan 9, 2025
1 parent 6d43579 commit 1df3ee2
Show file tree
Hide file tree
Showing 24 changed files with 203 additions and 193 deletions.
26 changes: 13 additions & 13 deletions docs/game_data/spel2.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions docs/src/includes/_globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ Use this only when no other approach works, this call can be expensive if overus

> Search script examples for [set_post_entity_spawn](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_post_entity_spawn)
#### [CallbackId](#Aliases) set_post_entity_spawn(function cb, [SPAWN_TYPE](#SPAWN_TYPE) flags, int mask, variadic_args entity_types)
#### [CallbackId](#Aliases) set_post_entity_spawn(function cb, [SPAWN_TYPE](#SPAWN_TYPE) flags, [MASK](#MASK) mask, variadic_args entity_types)

Add a callback for a spawn of specific entity types or mask. Set `mask` to `MASK.ANY` to ignore that.
This is run right after the entity is spawned but before and particular properties are changed, e.g. owner or velocity.
Expand All @@ -327,7 +327,7 @@ Sets a callback that is called right after the screen is drawn.

> Search script examples for [set_pre_entity_spawn](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_pre_entity_spawn)
#### [CallbackId](#Aliases) set_pre_entity_spawn(function cb, [SPAWN_TYPE](#SPAWN_TYPE) flags, int mask, variadic_args entity_types)
#### [CallbackId](#Aliases) set_pre_entity_spawn(function cb, [SPAWN_TYPE](#SPAWN_TYPE) flags, [MASK](#MASK) mask, variadic_args entity_types)

Add a callback for a spawn of specific entity types or mask. Set `mask` to `MASK.ANY` to ignore that.
This is run before the entity is spawned, spawn your own entity and return its uid to replace the intended spawn.
Expand Down Expand Up @@ -541,9 +541,9 @@ Calls the enter door function, position doesn't matter, can also enter closed do

> Search script examples for [entity_get_items_by](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=entity_get_items_by)
#### vector&lt;int&gt; entity_get_items_by(int uid, array<[ENT_TYPE](#ENT_TYPE)> entity_types, int mask)
#### vector&lt;int&gt; entity_get_items_by(int uid, array<[ENT_TYPE](#ENT_TYPE)> entity_types, [MASK](#MASK) mask)

#### vector&lt;int&gt; entity_get_items_by(int uid, [ENT_TYPE](#ENT_TYPE) entity_type, int mask)
#### vector&lt;int&gt; entity_get_items_by(int uid, [ENT_TYPE](#ENT_TYPE) entity_type, [MASK](#MASK) mask)

Gets uids of entities attached to given entity uid. Use `entity_type` and `mask` ([MASK](#MASK)) to filter, set them to 0 to return all attached entities.

Expand Down Expand Up @@ -617,9 +617,9 @@ Get door target `world`, `level`, `theme`

> Search script examples for [get_entities_at](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_entities_at)
#### vector&lt;int&gt; get_entities_at(array<[ENT_TYPE](#ENT_TYPE)> entity_types, int mask, float x, float y, [LAYER](#LAYER) layer, float radius)
#### vector&lt;int&gt; get_entities_at(array<[ENT_TYPE](#ENT_TYPE)> entity_types, [MASK](#MASK) mask, float x, float y, [LAYER](#LAYER) layer, float radius)

#### vector&lt;int&gt; get_entities_at([ENT_TYPE](#ENT_TYPE) entity_type, int mask, float x, float y, [LAYER](#LAYER) layer, float radius)
#### vector&lt;int&gt; get_entities_at([ENT_TYPE](#ENT_TYPE) entity_type, [MASK](#MASK) mask, float x, float y, [LAYER](#LAYER) layer, float radius)

Get uids of matching entities inside some radius ([ENT_TYPE](#ENT_TYPE), [MASK](#MASK)). Set `entity_type` or `mask` to `0` to ignore that, can also use table of entity_types
Recommended to always set the mask, even if you look for one entity type
Expand All @@ -640,9 +640,9 @@ end

> Search script examples for [get_entities_by](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_entities_by)
#### vector&lt;int&gt; get_entities_by(array<[ENT_TYPE](#ENT_TYPE)> entity_types, int mask, [LAYER](#LAYER) layer)
#### vector&lt;int&gt; get_entities_by(array<[ENT_TYPE](#ENT_TYPE)> entity_types, [MASK](#MASK) mask, [LAYER](#LAYER) layer)

#### vector&lt;int&gt; get_entities_by([ENT_TYPE](#ENT_TYPE) entity_type, int mask, [LAYER](#LAYER) layer)
#### vector&lt;int&gt; get_entities_by([ENT_TYPE](#ENT_TYPE) entity_type, [MASK](#MASK) mask, [LAYER](#LAYER) layer)

Get uids of entities by some conditions ([ENT_TYPE](#ENT_TYPE), [MASK](#MASK)). Set `entity_type` or `mask` to `0` to ignore that, can also use table of entity_types.
Recommended to always set the mask, even if you look for one entity type
Expand Down Expand Up @@ -696,9 +696,9 @@ Get uids of static entities overlapping this grid position (decorations, backgro

> Search script examples for [get_entities_overlapping_hitbox](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_entities_overlapping_hitbox)
#### vector&lt;int&gt; get_entities_overlapping_hitbox(array<[ENT_TYPE](#ENT_TYPE)> entity_types, int mask, [AABB](#AABB) hitbox, [LAYER](#LAYER) layer)
#### vector&lt;int&gt; get_entities_overlapping_hitbox(array<[ENT_TYPE](#ENT_TYPE)> entity_types, [MASK](#MASK) mask, [AABB](#AABB) hitbox, [LAYER](#LAYER) layer)

#### vector&lt;int&gt; get_entities_overlapping_hitbox([ENT_TYPE](#ENT_TYPE) entity_type, int mask, [AABB](#AABB) hitbox, [LAYER](#LAYER) layer)
#### vector&lt;int&gt; get_entities_overlapping_hitbox([ENT_TYPE](#ENT_TYPE) entity_type, [MASK](#MASK) mask, [AABB](#AABB) hitbox, [LAYER](#LAYER) layer)

Get uids of matching entities overlapping with the given hitbox. Set `entity_type` or `mask` to `0` to ignore that, can also use table of entity_types

Expand Down Expand Up @@ -4120,7 +4120,7 @@ Use `get_entities_by(0, MASK.ANY, LAYER.BOTH)` instead

> Search script examples for [get_entities_by_mask](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_entities_by_mask)
#### vector&lt;int&gt; get_entities_by_mask(int mask)
#### vector&lt;int&gt; get_entities_by_mask([MASK](#MASK) mask)

Use `get_entities_by(0, mask, LAYER.BOTH)` instead

Expand All @@ -4138,9 +4138,9 @@ Use `get_entities_by(0, MASK.ANY, layer)` instead

> Search script examples for [get_entities_overlapping](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_entities_overlapping)
#### vector&lt;int&gt; get_entities_overlapping(array<[ENT_TYPE](#ENT_TYPE)> entity_types, int mask, float sx, float sy, float sx2, float sy2, [LAYER](#LAYER) layer)
#### vector&lt;int&gt; get_entities_overlapping(array<[ENT_TYPE](#ENT_TYPE)> entity_types, [MASK](#MASK) mask, float sx, float sy, float sx2, float sy2, [LAYER](#LAYER) layer)

#### vector&lt;int&gt; get_entities_overlapping([ENT_TYPE](#ENT_TYPE) entity_type, int mask, float sx, float sy, float sx2, float sy2, [LAYER](#LAYER) layer)
#### vector&lt;int&gt; get_entities_overlapping([ENT_TYPE](#ENT_TYPE) entity_type, [MASK](#MASK) mask, float sx, float sy, float sx2, float sy2, [LAYER](#LAYER) layer)

Use `get_entities_overlapping_hitbox` instead

Expand Down
6 changes: 3 additions & 3 deletions docs/src/includes/_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ Type | Name | Description
[EntityDB](#EntityDB) | [new(EntityDB other)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=EntityDB) |
[EntityDB](#EntityDB) | [new(ENT_TYPE other)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=EntityDB) |
[ENT_TYPE](#ENT_TYPE) | [id](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=id) |
int | [search_flags](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=search_flags) | [MASK](#MASK)
[MASK](#MASK) | [search_flags](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=search_flags) | [MASK](#MASK)
float | [width](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=width) |
float | [height](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=height) |
int | [draw_depth](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=draw_depth) |
Expand Down Expand Up @@ -4358,9 +4358,9 @@ bool | [is_in_liquid()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q
bool | [is_cursed()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=is_cursed) |
bool | [is_movable()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=is_movable) |
bool | [can_be_pushed()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=can_be_pushed) |
nil | [kill_recursive(bool destroy_corpse, Entity responsible, optional<int> mask, array<ENT_TYPE> ent_types, RECURSIVE_MODE rec_mode)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=kill_recursive) | Kill entity along with all entities attached to it. Be aware that for example killing push block with this function will also kill anything on top of it, any items, players, monsters etc.<br/>To avoid that, you can inclusively or exclusively limit certain [MASK](#MASK) and [ENT_TYPE](#ENT_TYPE). Note: the function will first check mask, if the entity doesn't match, it will look in the provided [ENT_TYPE](#ENT_TYPE)'s<br/>destroy_corpse and responsible are the standard parameters for the kill function
nil | [kill_recursive(bool destroy_corpse, Entity responsible, optional<MASK> mask, array<ENT_TYPE> ent_types, RECURSIVE_MODE rec_mode)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=kill_recursive) | Kill entity along with all entities attached to it. Be aware that for example killing push block with this function will also kill anything on top of it, any items, players, monsters etc.<br/>To avoid that, you can inclusively or exclusively limit certain [MASK](#MASK) and [ENT_TYPE](#ENT_TYPE). Note: the function will first check mask, if the entity doesn't match, it will look in the provided [ENT_TYPE](#ENT_TYPE)'s<br/>destroy_corpse and responsible are the standard parameters for the kill function
nil | [kill_recursive(bool destroy_corpse, Entity responsible)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=kill_recursive) | Short for using [RECURSIVE_MODE](#RECURSIVE_MODE).NONE
nil | [destroy_recursive(optional<int> mask, array<ENT_TYPE> ent_types, RECURSIVE_MODE rec_mode)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=destroy_recursive) | Destroy entity along with all entities attached to it. Be aware that for example destroying push block with this function will also destroy anything on top of it, any items, players, monsters etc.<br/>To avoid that, you can inclusively or exclusively limit certain [MASK](#MASK) and [ENT_TYPE](#ENT_TYPE). Note: the function will first check the mask, if the entity doesn't match, it will look in the provided [ENT_TYPE](#ENT_TYPE)'s
nil | [destroy_recursive(optional<MASK> mask, array<ENT_TYPE> ent_types, RECURSIVE_MODE rec_mode)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=destroy_recursive) | Destroy entity along with all entities attached to it. Be aware that for example destroying push block with this function will also destroy anything on top of it, any items, players, monsters etc.<br/>To avoid that, you can inclusively or exclusively limit certain [MASK](#MASK) and [ENT_TYPE](#ENT_TYPE). Note: the function will first check the mask, if the entity doesn't match, it will look in the provided [ENT_TYPE](#ENT_TYPE)'s
nil | [destroy_recursive()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=destroy_recursive) | Short for using [RECURSIVE_MODE](#RECURSIVE_MODE).NONE
nil | [update()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=update) |
nil | [flip(bool left)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=flip) |
Expand Down
5 changes: 5 additions & 0 deletions src/game_api/aliases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ enum class ENTITY_MASK : uint32_t
};
ENUM_CLASS_FLAGS(ENTITY_MASK)

inline bool operator!(ENTITY_MASK v)
{
return v == static_cast<ENTITY_MASK>(0);
}

// Returns true if any of the set bits in `mask` are in `flags`
template <class T>
requires std::is_enum_v<T>
Expand Down
Loading

0 comments on commit 1df3ee2

Please sign in to comment.