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

Test only, don't merge! #324

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 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: 6 additions & 1 deletion docs/src/includes/_globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,12 @@ end, 60)
#### [CallbackId](#Aliases) set_interval(function cb, int frames)

Returns unique id for the callback to be used in [clear_callback](#clear_callback). You can also return `false` from your function to clear the callback.
Add per level callback function to be called every `frames` engine frames. Timer is paused on pause and cleared on level transition.
Add per level callback function to be called every `frames` engine frames
Ex. frames = 100 - will call the function on 100th frame from this point. This might differ in the exact timing of first frame depending as in what part of the frame you call this function
or even be one frame off if called right before the time_level variable is updated
If you require precise timing, choose the start of your interval in one of those safe callbacks:
The [SCREEN](#SCREEN) callbacks: from [ON](#ON).LOGO to [ON](#ON).ONLINE_LOBBY or custom callbacks [ON](#ON).FRAME, [ON](#ON).[SCREEN](#SCREEN), [ON](#ON).START, [ON](#ON).LOADING, [ON](#ON).RESET, [ON](#ON).POST_UPDATE
Timer is paused on pause and cleared on level transition.

### set_on_player_instagib

Expand Down
5 changes: 2 additions & 3 deletions src/game_api/file_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ std::string hash_path(std::string_view path)
int i = 0;
do
{
uint64_t merge = std::toupper(abs_path_str[i]) * 65536 + std::toupper(abs_path_str[i + 1]);
uint64_t merge = (uint64_t)std::toupper(abs_path_str[i]) * 65536 + (uint64_t)std::toupper(abs_path_str[i + 1]);
res = res * 8191 + merge;
i++;
} while (i < abs_path_str.length());
Expand Down Expand Up @@ -260,13 +260,12 @@ FileInfo* load_file_as_dds_if_image(const char* file_path, AllocFun alloc_fun)
{
fwrite(file_info->Data, sizeof(char), file_info->DataSize, cache_file);
DEBUG("Cached '{}' to '{}'", path, cache_path.string());
fclose(cache_file);
}
else
{
DEBUG("Couldn't cache '{}' to '{}'", path, cache_path.string());
}
fclose(cache_file);

return file_info;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/game_api/level_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ std::uint32_t LevelGenData::define_tile_code(std::string tile_code)

std::optional<uint8_t> LevelGenData::get_short_tile_code(ShortTileCodeDef short_tile_code_def)
{
for (auto [i, def] : short_tile_codes)
for (auto& [i, def] : short_tile_codes)
{
if (def == short_tile_code_def)
{
Expand Down
32 changes: 16 additions & 16 deletions src/game_api/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,18 @@ struct Vec2
std::tuple<float, float> split()
{} // just for the autodoc
*/
operator std::pair<float, float>() const
{
return {x, y};
}
operator std::tuple<float, float>() const
{
return {x, y};
}
operator std::tuple<float&, float&>()
{
return {x, y};
}
//operator std::pair<float, float>() const
//{
// return {x, y};
//}
//operator std::tuple<float, float>() const
//{
// return {x, y};
//}
//operator std::tuple<float&, float&>()
//{
// return {x, y};
//}

float x{0};
float y{0};
Expand Down Expand Up @@ -463,10 +463,10 @@ struct Quad
return in;
};

std::tie(bottom_left_x, bottom_left_y) = rotate_around_pivot({bottom_left_x, bottom_left_y});
std::tie(bottom_right_x, bottom_right_y) = rotate_around_pivot({bottom_right_x, bottom_right_y});
std::tie(top_left_x, top_left_y) = rotate_around_pivot({top_left_x, top_left_y});
std::tie(top_right_x, top_right_y) = rotate_around_pivot({top_right_x, top_right_y});
//std::tie(bottom_left_x, bottom_left_y) = rotate_around_pivot({bottom_left_x, bottom_left_y});
//std::tie(bottom_right_x, bottom_right_y) = rotate_around_pivot({bottom_right_x, bottom_right_y});
//std::tie(top_left_x, top_left_y) = rotate_around_pivot({top_left_x, top_left_y});
//std::tie(top_right_x, top_right_y) = rotate_around_pivot({top_right_x, top_right_y});

return *this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/game_api/render_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ void on_open_journal_chapter(JournalUI* journal_ui, uint8_t chapter, bool instan
}
side ^= 0x1;
}
for (auto p : pages_copy) // free unused screens
for (auto& p : pages_copy) // free unused screens
{
if (p.second)
{
Expand Down
6 changes: 3 additions & 3 deletions src/game_api/script/lua_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ bool LuaBackend::pre_load_screen()
saved.mount = get_user_data(ent->overlay->uid);
should_save = true;
}
for (auto [type, powerup] : ent->powerups)
for (auto& [type, powerup] : ent->powerups)
{
if (user_datas.contains(powerup->uid))
{
Expand Down Expand Up @@ -919,7 +919,7 @@ void LuaBackend::load_user_data()
set_user_data(ent->holding_uid, saved_user_datas[slot].held.value());
if (ent->overlay && (ent->overlay->type->search_flags & 2) > 0 && saved_user_datas[slot].mount.has_value())
set_user_data(ent->overlay->uid, saved_user_datas[slot].mount.value());
for (auto [type, powerup] : ent->powerups)
for (auto& [type, powerup] : ent->powerups)
{
if (saved_user_datas[slot].powerups.contains(type))
set_user_data(powerup->uid, saved_user_datas[slot].powerups[type]);
Expand Down Expand Up @@ -1399,7 +1399,7 @@ std::vector<uint32_t> LuaBackend::post_load_journal_chapter(uint8_t chapter, con
{
new_pages.clear();
const auto table = returned_pages.as<sol::table>();
for (auto something : table)
for (auto& something : table)
{
if (something.second.get_type() == sol::type::number)
{
Expand Down
12 changes: 9 additions & 3 deletions src/game_api/script/lua_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,17 @@ end
};

/// Returns unique id for the callback to be used in [clear_callback](#clear_callback). You can also return `false` from your function to clear the callback.
/// Add per level callback function to be called every `frames` engine frames. Timer is paused on pause and cleared on level transition.
/// Add per level callback function to be called every `frames` engine frames
/// Ex. frames = 100 - will call the function on 100th frame from this point. This might differ in the exact timing of first frame depending as in what part of the frame you call this function
/// or even be one frame off if called right before the time_level variable is updated
/// If you require precise timing, choose the start of your interval in one of those safe callbacks:
/// The SCREEN callbacks: from ON.LOGO to ON.ONLINE_LOBBY or custom callbacks ON.FRAME, ON.SCREEN, ON.START, ON.LOADING, ON.RESET, ON.POST_UPDATE
/// Timer is paused on pause and cleared on level transition.
lua["set_interval"] = [](sol::function cb, int frames) -> CallbackId
{
auto backend = LuaBackend::get_calling_backend();
auto luaCb = IntervalCallback{cb, frames, -1};
auto state = State::get().ptr_main();
auto luaCb = IntervalCallback{cb, frames, (int)state->time_level};
backend->level_timers[backend->cbcount] = luaCb;
return backend->cbcount++;
};
Expand Down Expand Up @@ -2472,7 +2478,7 @@ end
//, "", ...check__[game_settings.txt]\[game_data/game_settings.txt\]...
//, "CROSSPROGRESS_AUTOSYNC", 47
);
for (auto [setting_name_view, setting_index] : get_settings_names_and_indices())
for (auto& [setting_name_view, setting_index] : get_settings_names_and_indices())
{
std::string setting_name{setting_name_view};
std::transform(setting_name.begin(), setting_name.end(), setting_name.begin(), [](unsigned char c)
Expand Down
2 changes: 1 addition & 1 deletion src/game_api/script/usertypes/entity_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void register_usertypes(sol::state& lua)
auto name = item.name.substr(9, item.name.size());
lua["ENT_TYPE"][name] = item.id;
}
for (auto elm : get_custom_types_map())
for (auto& elm : get_custom_types_map())
{
lua["ENT_TYPE"][elm.second] = elm.first;
}
Expand Down
4 changes: 2 additions & 2 deletions src/game_api/script/usertypes/gui_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void GuiDrawContext::draw_poly(std::vector<Vec2> points, float thickness, uColor
auto draw = [&](ImDrawList* dl)
{
dl->PathClear();
for (auto point : points)
for (auto& point : points)
{
ImVec2 a = screenify_fix({point.x, point.y});
dl->PathLineToMergeDuplicate(a);
Expand All @@ -170,7 +170,7 @@ void GuiDrawContext::draw_poly_filled(std::vector<Vec2> points, uColor color)
auto draw = [&](ImDrawList* dl)
{
dl->PathClear();
for (auto point : points)
for (auto& point : points)
{
ImVec2 a = screenify_fix({point.x, point.y});
dl->PathLineToMergeDuplicate(a);
Expand Down
4 changes: 2 additions & 2 deletions src/game_api/script/usertypes/hitbox_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ void register_usertypes(sol::state& lua)
"y",
&Vec2::y,
"rotate",
&Vec2::rotate,
&Vec2::rotate/*,
"split",
// &Vec2::split); // for the autodoc
&Vec2::operator std::pair<float, float>);
&Vec2::operator std::pair<float, float>*/);

const auto extrude = sol::overload(
static_cast<AABB& (AABB::*)(float)>(&AABB::extrude),
Expand Down
4 changes: 2 additions & 2 deletions src/game_api/script/usertypes/vanilla_render_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void VanillaRenderContext::draw_screen_poly(std::vector<Vec2> points, float thic
if (!corner.is_null())
draw_screen_poly_filled(convert_ratio(corner, true), std::move(color));
}
for (auto line : draw_list)
for (auto& line : draw_list)
{
draw_screen_poly_filled(convert_ratio(line, true), std::move(color));
}
Expand Down Expand Up @@ -533,7 +533,7 @@ void VanillaRenderContext::draw_world_poly(std::vector<Vec2> points, float thick
if (!corner.is_null())
draw_world_poly_filled(corner, std::move(color));
}
for (auto line : draw_list)
for (auto& line : draw_list)
{
draw_world_poly_filled(line, std::move(color));
}
Expand Down
2 changes: 1 addition & 1 deletion src/game_api/string_hashes.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// THIS FILE IS AUTO-GENERATED
// If you need to make changes it please change strings_get_hashes.py
// If you need to make changes to it, please change "strings_get_hashes.py"

#include <cstdint> // for uint32_t
#include <functional> // for less
Expand Down
2 changes: 1 addition & 1 deletion src/game_api/strings_get_hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
print(
"""
// THIS FILE IS AUTO-GENERATED
// If you need to make changes it please change strings_get_hashes.py
// If you need to make changes to it, please change "strings_get_hashes.py"

#include <cstdint> // for uint32_t
#include <functional> // for less
Expand Down
Loading