Skip to content

Commit

Permalink
Particles (#249)
Browse files Browse the repository at this point in the history
* Add jay's particle info stuff

* Make work

* Revert name change of not-really-alpha

* Add an x, y discriminated extrude

* Actually remove alpha

* Fix docs

* Automated clang-format changes

* Fix i/ofstream issue

* Formatting

* Fix typo

* Add size() to EmittedParticlesInfo

* Simplify extinguish_particles

* Add get_entity_name

* Tiny fixes

* Maybe fix CI  🤞

* Another one  🙊

Co-authored-by: Clang-Format Bot <[email protected]>
  • Loading branch information
Malacath-92 and Clang-Format Bot authored Aug 12, 2022
1 parent f97ba32 commit 5365d5d
Show file tree
Hide file tree
Showing 27 changed files with 359 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: |
mkdir build
cd build
cmake .. -A x64 -T ${{ matrix.toolset }} ${{ matrix.additional_opts }}
cmake .. -Wno-dev -A x64 -T ${{ matrix.toolset }} ${{ matrix.additional_opts }}
- name: Build
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
[submodule "docs/slate"]
path = docs/slate
url = https://github.com/spelunky-fyi/slate
[submodule "src/neo"]
path = src/neo
url = https://github.com/vector-of-bool/neo-fun.git
23 changes: 22 additions & 1 deletion docs/game_data/spel2.lua

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

7 changes: 4 additions & 3 deletions docs/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"constexpr": "",
"static": "",
"variadic_args va": "int, int...",
"EmittedParticlesInfo": "array<Particle>",
}


Expand Down Expand Up @@ -133,7 +134,7 @@ def print_af(lf, af):

def print_lf(lf):
comments = lf["comment"]
if comments and comments[0] == "NoDoc":
if comments and "NoDoc" in comments[0]:
return
name = lf["name"]
if name in printed_funcs:
Expand Down Expand Up @@ -441,7 +442,7 @@ def print_lf(lf):
if len(ps.rpcfunc(lf["cpp"])):
print_lf(lf)
elif not (lf["name"].startswith("on_") or lf["name"] in ps.not_functions):
if lf["comment"] and lf["comment"][0] == "NoDoc":
if lf["comment"] and "NoDoc" in lf["comment"][0]:
continue
m = re.search(r"\(([^\{]*)\)\s*->\s*([^\{]*)", lf["cpp"])
m2 = re.search(r"\(([^\{]*)\)", lf["cpp"])
Expand Down Expand Up @@ -486,7 +487,7 @@ def print_lf(lf):
if len(ps.rpcfunc(lf["cpp"])):
print_lf(lf)
elif not (lf["name"].startswith("on_") or lf["name"] in ps.not_functions):
if lf["comment"] and lf["comment"][0] == "NoDoc":
if lf["comment"] and "NoDoc" in lf["comment"][0]:
continue
m = re.search(r"\(([^\{]*)\)\s*->\s*([^\{]*)", lf["cpp"])
m2 = re.search(r"\(([^\{]*)\)", lf["cpp"])
Expand Down
5 changes: 3 additions & 2 deletions docs/generate_emmylua.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"&": "",
"const ": "",
"ShopType": "SHOP_TYPE",
"EmittedParticlesInfo": "Array<Particle>",
}

reFloat = re.compile(r"\bfloat\b")
Expand Down Expand Up @@ -150,7 +151,7 @@ def print_comment(lf):


def print_af(lf, af):
if lf["comment"] and lf["comment"][0] == "NoDoc":
if lf["comment"] and "NoDoc" in lf["comment"][0]:
return
ret = replace_all(af["return"]) or "nil"
name = lf["name"]
Expand Down Expand Up @@ -197,7 +198,7 @@ def print_af(lf, af):
for af in ps.rpcfunc(lf["cpp"]):
print_af(lf, af)
elif not (lf["name"].startswith("on_") or lf["name"] in ps.not_functions):
if lf["comment"] and lf["comment"][0] == "NoDoc":
if lf["comment"] and "NoDoc" in lf["comment"][0]:
continue
m = re.search(r"\(([^\{]*)\)\s*->\s*([^\{]*)", lf["cpp"])
m2 = re.search(r"\(([^\{]*)\)", lf["cpp"])
Expand Down
13 changes: 8 additions & 5 deletions docs/parse_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def run_parse():
line = line.replace("*", "")
if not class_name and ("struct" in line or "class" in line):
m = re.match(r"(struct|class)\s+(\S+)", line)
if m:
if m and not line.endswith(";"):
class_name = m[2]
elif class_name:
prev_brackets_depth = brackets_depth
Expand Down Expand Up @@ -423,10 +423,11 @@ def run_parse():
"cpp": m.group(2),
"comment": comment,
}
if comment and comment[0] == "Deprecated":
deprecated_funcs.append(func)
else:
funcs.append(func)
if not comment or "NoDoc" not in comment[0]:
if comment and comment[0] == "Deprecated":
deprecated_funcs.append(func)
else:
funcs.append(func)
comment = []

c = re.search(r"/// ?(.*)$", line)
Expand All @@ -438,6 +439,8 @@ def run_parse():
data = open(file, "r").read()
data = data.replace("\n", "")
data = re.sub(r" ", "", data)
reParticleHelper = re.compile(r"MakeParticleMemberAccess<(.+?)>\(\)")
data = reParticleHelper.sub(r"\1", data)
m = re.findall(r'new_usertype\<([^\>]*?)\>\s*\(\s*"([^"]*)",(.*?)\);', data)
for type in m:
cpp_type = type[0]
Expand Down
1 change: 1 addition & 0 deletions docs/src/includes/_enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ Name | Data | Description
[RENDER_POST_JOURNAL_PAGE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ON.RENDER_POST_JOURNAL_PAGE) | ON::RENDER_POST_JOURNAL_PAGE | Params: `VanillaRenderContext render_ctx, JOURNAL_PAGE_TYPE page_type, JournalPage page`<br/>Runs after the journal page is drawn on screen. In this event, you can draw textures with the `draw_screen_texture` function of the render_ctx<br/>The page_type parameter values can be found in the JOURNAL_PAGE_TYPE ENUM<br/>The JournalPage parameter gives you access to the specific fields of the page. Be sure to cast it to the correct type, the following functions are available to do that:<br/>`page:as_journal_page_progress()`<br/>`page:as_journal_page_journalmenu()`<br/>`page:as_journal_page_places()`<br/>`page:as_journal_page_people()`<br/>`page:as_journal_page_bestiary()`<br/>`page:as_journal_page_items()`<br/>`page:as_journal_page_traps()`<br/>`page:as_journal_page_story()`<br/>`page:as_journal_page_feats()`<br/>`page:as_journal_page_deathcause()`<br/>`page:as_journal_page_deathmenu()`<br/>`page:as_journal_page_recap()`<br/>`page:as_journal_page_playerprofile()`<br/>`page:as_journal_page_lastgameplayed()`<br/>
[SPEECH_BUBBLE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ON.SPEECH_BUBBLE) | ON::SPEECH_BUBBLE | Params: `Entity speaking_entity, string text`<br/>Runs before any speech bubble is created, even the one using `say` function<br/>Return behavior: if you don't return anything it will execute the speech bubble function normally with default message<br/>if you return empty string, it will not create the speech bubble at all, if you return string, it will use that instead of the original<br/>The first script to return string (empty or not) will take priority, the rest will receive callback call but the return behavior won't matter<br/>
[TOAST](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ON.TOAST) | ON::TOAST | Params: `string text`<br/>Runs before any toast is created, even the one using `toast` function<br/>Return behavior: if you don't return anything it will execute the toast function normally with default message<br/>if you return empty string, it will not create the toast at all, if you return string, it will use that instead of the original message<br/>The first script to return string (empty or not) will take priority, the rest will receive callback call but the return behavior won't matter<br/>
[DEATH_MESSAGE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ON.DEATH_MESSAGE) | ON::DEATH_MESSAGE | Params: `STRINGID id`<br/>Runs once after death when the death message journal page is shown. The parameter is the STRINGID of the title, like 1221 for BLOWN UP.<br/>

## PARTICLEEMITTER

Expand Down
3 changes: 3 additions & 0 deletions docs/src/includes/_globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -2744,6 +2744,7 @@ Note that `define_texture` will also reload the texture if it already exists
#### nil reset_lut([LAYER](#LAYER) layer)

Same as `set_lut(nil, layer)`

### set_lut

Expand All @@ -2752,6 +2753,8 @@ Note that `define_texture` will also reload the texture if it already exists
#### nil set_lut(optional<[TEXTURE](#TEXTURE)> texture_id, [LAYER](#LAYER) layer)

Force the LUT texture for the given layer (or both) until it is reset
Pass `nil` in the first parameter to reset

## Theme functions

Expand Down
17 changes: 17 additions & 0 deletions docs/src/includes/_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ float | [top](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=top) |
bool | [overlaps_with(const AABB& other)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=overlaps_with) |
[AABB](#AABB)& | [abs()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=abs) | Fixes the [AABB](#AABB) if any of the sides have negative length
[AABB](#AABB)& | [extrude(float amount)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=extrude) | Grows or shrinks the [AABB](#AABB) by the given amount in all directions.<br/>If `amount < 0` and `abs(amount) > right/top - left/bottom` the respective dimension of the AABB will become `0`.
[AABB](#AABB)& | [extrude(float amount_x, float amount_y)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=extrude) | Grows or shrinks the [AABB](#AABB) by the given amount in each direction.<br/>If `amount_x/y < 0` and `abs(amount_x/y) > right/top - left/bottom` the respective dimension of the AABB will become `0`.
[AABB](#AABB)& | [offset(float off_x, float off_y)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=offset) | Offsets the [AABB](#AABB) by the given offset.
float | [area()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=area) | Compute area of the [AABB](#AABB), can be zero if one dimension is zero or negative if one dimension is inverted.
tuple&lt;float, float&gt; | [center()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=center) | Short for `(aabb.left + aabb.right) / 2.0f, (aabb.top + aabb.bottom) / 2.0f`.
Expand Down Expand Up @@ -1012,6 +1013,21 @@ string | [player_name](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=
## Particle types


### Particle


Type | Name | Description
---- | ---- | -----------
float | [x](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=x) |
float | [y](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=y) |
float | [velocityx](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=velocityx) |
float | [velocityy](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=velocityy) |
[uColor](#Aliases) | [color](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=color) |
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 | [lifetime](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=lifetime) |
int | [max_lifetime](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=max_lifetime) |

### ParticleDB


Expand Down Expand Up @@ -1060,6 +1076,7 @@ float | [x](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=x) |
float | [y](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=y) |
float | [offset_x](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=offset_x) |
float | [offset_y](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=offset_y) |
array&lt;[Particle](#Particle)&gt; | [emitted_particles](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=emitted_particles) |

## Savegame types

Expand Down
1 change: 1 addition & 0 deletions src/game_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ if(MSVC)
target_compile_options(spel2_api PRIVATE
/Zm80
/bigobj)
target_compile_definitions(spel2_api PRIVATE _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
endif()
4 changes: 2 additions & 2 deletions src/game_api/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void SpelunkyConsole::set_max_history_size(size_t max_history)
}
void SpelunkyConsole::save_history(std::string_view path)
{
if (std::ofstream history_file = std::ofstream(path))
if (std::ofstream history_file = std::ofstream(std::string{path}))
{
std::string line;
for (const auto& history_item : m_Impl->history)
Expand All @@ -82,7 +82,7 @@ void SpelunkyConsole::save_history(std::string_view path)
}
void SpelunkyConsole::load_history(std::string_view path)
{
if (std::ifstream history_file = std::ifstream(path))
if (std::ifstream history_file = std::ifstream(std::string{path}))
{
std::string line;
std::string history_item;
Expand Down
14 changes: 10 additions & 4 deletions src/game_api/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,22 @@ struct AABB
/// If `amount < 0` and `abs(amount) > right/top - left/bottom` the respective dimension of the AABB will become `0`.
AABB& extrude(float amount)
{
left -= amount;
right += amount;
return extrude(amount, amount);
}
/// Grows or shrinks the AABB by the given amount in each direction.
/// If `amount_x/y < 0` and `abs(amount_x/y) > right/top - left/bottom` the respective dimension of the AABB will become `0`.
AABB& extrude(float amount_x, float amount_y)
{
left -= amount_x;
right += amount_x;
if (left > right)
{
left = (left + right) / 2.0f;
right = left;
}

bottom -= amount;
top += amount;
bottom -= amount_y;
top += amount_y;
if (bottom > top)
{
bottom = (bottom + top) / 2.0f;
Expand Down
6 changes: 4 additions & 2 deletions src/game_api/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ void write_mem(size_t addr, std::string payload)
write_mem_prot(addr, payload, false);
}

size_t function_start(size_t off)
// Looks for padding between functions, which sometimes does not exist, in that case
// you might be able to specify a different distinct byte
size_t function_start(size_t off, uint8_t outside_byte)
{
off &= ~0xf;
while (read_u8(off - 1) != 0xcc)
while (read_u8(off - 1) != outside_byte)
{
off -= 0x10;
}
Expand Down
2 changes: 1 addition & 1 deletion src/game_api/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ LPVOID alloc_mem_rel32(size_t addr, size_t size);
void write_mem_prot(size_t addr, std::string_view payload, bool prot);
void write_mem_prot(size_t addr, std::string payload, bool prot);
void write_mem(size_t addr, std::string payload);
size_t function_start(size_t off);
size_t function_start(size_t off, uint8_t outside_byte = '\xcc');
void write_mem_recoverable(std::string name, size_t addr, std::string_view payload, bool prot);
void recover_mem(std::string name, size_t addr = NULL);

Expand Down
72 changes: 72 additions & 0 deletions src/game_api/particles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,78 @@ bool ParticleDB::set_texture(std::uint32_t texture_id)
return false;
}

EmittedParticlesInfo::Iterator EmittedParticlesInfo::begin()
{
return Iterator{this, 0};
}
EmittedParticlesInfo::Iterator EmittedParticlesInfo::end()
{
return Iterator{this, particle_emitter->particle_count};
}
EmittedParticlesInfo::ConstIterator EmittedParticlesInfo::begin() const
{
return cbegin();
}
EmittedParticlesInfo::ConstIterator EmittedParticlesInfo::end() const
{
return cend();
}
EmittedParticlesInfo::ConstIterator EmittedParticlesInfo::cbegin() const
{
return ConstIterator{this, 0};
}
EmittedParticlesInfo::ConstIterator EmittedParticlesInfo::cend() const
{
return ConstIterator{this, particle_emitter->particle_count};
}

Particle EmittedParticlesInfo::front()
{
return (*this)[0];
}
Particle EmittedParticlesInfo::back()
{
return (*this)[particle_emitter->particle_count - 1];
}
const Particle EmittedParticlesInfo::front() const
{
return (*this)[0];
}
const Particle EmittedParticlesInfo::back() const
{
return (*this)[particle_emitter->particle_count - 1];
}

bool EmittedParticlesInfo::empty()
{
return particle_emitter->particle_count == 0;
}
EmittedParticlesInfo::size_type EmittedParticlesInfo::size()
{
return particle_emitter->particle_count;
}

Particle EmittedParticlesInfo::operator[](const size_type idx)
{
return static_cast<const EmittedParticlesInfo&>(*this)[idx];
}
const Particle EmittedParticlesInfo::operator[](const size_type idx) const
{
return {
max_lifetimes + idx,
lifetimes + idx,
x_positions + idx,
y_positions + idx,
unknown_x_positions + idx,
unknown_y_positions + idx,
colors + idx,
widths + idx,
heights + idx,
x_velocities + idx,
y_velocities + idx,
};
}

ParticleDB* get_particle_type(uint32_t id)
{
static std::unordered_map<uint32_t, ParticleDB*> mapping = {};
Expand Down
Loading

0 comments on commit 5365d5d

Please sign in to comment.