Skip to content

Commit

Permalink
Backport race lobby
Browse files Browse the repository at this point in the history
  • Loading branch information
timoschwarzer committed Nov 24, 2023
1 parent 89608d9 commit 55380e4
Show file tree
Hide file tree
Showing 10 changed files with 514 additions and 312 deletions.
14 changes: 6 additions & 8 deletions projects/Core/api/scenes/create_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ namespace core::api::scenes {
std::unordered_map<std::string, ObjectSpawn> object_spawns;
std::unordered_map<std::string, std::unordered_set<ObjectSpawn*>> pending_object_spawns_by_scene;

void on_loading_callback(std::string_view scene_name, app::SceneState__Enum state, app::GameObject* scene_root) {
if (state == app::SceneState__Enum::Loaded && scene_root != nullptr) {
auto scene_name_string = std::string(scene_name);

for (auto spawn : pending_object_spawns_by_scene[scene_name_string]) {
auto prefab = il2cpp::unity::find_child(scene_root, spawn->path);
void on_loading_callback(SceneLoadEventMetadata* metadata) {
if (metadata->state == app::SceneState__Enum::Loaded && metadata->scene->fields.SceneRoot != nullptr) {
for (auto spawn : pending_object_spawns_by_scene[metadata->scene_name]) {
auto prefab = il2cpp::unity::find_child(metadata->scene->fields.SceneRoot, spawn->path);
if (!il2cpp::unity::is_valid(prefab))
return;

Expand All @@ -69,10 +67,10 @@ namespace core::api::scenes {

core::api::graphics::shaders::duplicate_materials(spawn->game_object);
if (spawn->on_loaded != nullptr)
spawn->on_loaded(scene_name, spawn->name, scene_root, spawn->game_object);
spawn->on_loaded(metadata->scene_name, spawn->name, il2cpp::unity::get_game_object(metadata->scene->fields.SceneRoot), spawn->game_object);
}

pending_object_spawns_by_scene.erase(scene_name_string);
pending_object_spawns_by_scene.erase(metadata->scene_name);
}
}

Expand Down
14 changes: 8 additions & 6 deletions projects/Core/api/scenes/scene_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace core::api::scenes {
}

for (auto on_load_callback : pending_scene.scene_loading_callbacks) {
on_load_callback(pending_scene.scene_name, state, scene_root_go);
on_load_callback(&event);
}
}
}
Expand Down Expand Up @@ -195,7 +195,10 @@ namespace core::api::scenes {
scene_manager_scene->fields.PreventUnloading = keep_preloaded;

if (callback != nullptr) {
callback(scene, scene_manager_scene->fields.m_currentState, scene_root_go);
SceneLoadEventMetadata metadata {
std::string(scene), scene_manager_scene->fields.m_currentState, scene_manager_scene,
};
callback(&metadata);
}
} else if (!ScenesManager::SceneIsLoading(scenes_manager, scene_meta->fields.SceneMoonGuid)) {
ScenesManager::RequestAdditivelyLoadScene(scenes_manager, scene_meta, async, true, true, true, false);
Expand Down Expand Up @@ -312,10 +315,9 @@ namespace core::api::scenes {
}
}

void on_load_spawn(std::string_view scene_name, app::SceneState__Enum state, app::GameObject* scene_root) {
if (state == app::SceneState__Enum::Loaded && scene_root != nullptr) {
auto root = il2cpp::unity::get_component<app::SceneRoot>(scene_root, types::SceneRoot::get_class());
initial_values_handle = il2cpp::gchandle_new(root->fields.MetaData->fields.InitialValuesWisp, false);
void on_load_spawn(SceneLoadEventMetadata* metadata) {
if (metadata->state == app::SceneState__Enum::Loaded && metadata->scene->fields.SceneRoot != nullptr) {
initial_values_handle = il2cpp::gchandle_new(metadata->scene->fields.SceneRoot->fields.MetaData->fields.InitialValuesWisp, false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion projects/Core/api/scenes/scene_load.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace core::api::scenes {
app::SceneManagerScene* scene;
};

using scene_loading_callback = void (*)(std::string_view scene_name, app::SceneState__Enum state, app::GameObject* scene_root);
using scene_loading_callback = void (*)(SceneLoadEventMetadata* metadata);

CORE_DLLEXPORT app::ScenesManager* get_scenes_manager();

Expand Down
6 changes: 3 additions & 3 deletions projects/Core/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <functional>

namespace core::task {
CORE_DLLEXPORT void schedule(float seconds, std::function<void()> task);
namespace core::events {
CORE_DLLEXPORT void schedule_task(float seconds, std::function<void()> task);
CORE_DLLEXPORT void schedule_for_next_update(std::function<void()> task);
} // namespace core::tasks
} // namespace core::tasks
2 changes: 1 addition & 1 deletion projects/Randomizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ set(
"game/shops/spirit_light_spent.cpp"
"game/shops/tuley.cpp"
"game/shops/twillen.cpp"
"game/spawning_preloading_teleporting.cpp"
"game/spawning_preloading_teleporting_and_race_lobby_yes_this_file_needs_to_be_split.cpp"
"ghosts/plugins/update_active_animations_plugin.cpp"
"ghosts/plugins.cpp"
"ghosts.cpp"
Expand Down
12 changes: 6 additions & 6 deletions projects/Randomizer/features/credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ namespace randomizer::features::credits {
constexpr char CREDITS_PATH_FMT[] = "{}\\credits";
randomizer::messages::CreditsController credits;

void credits_scene_loaded_callback(std::string_view scene_name, app::SceneState__Enum state, app::GameObject* scene_root) {
if (state == app::SceneState__Enum::Loaded && scene_root != nullptr) {
void credits_scene_loaded_callback(core::api::scenes::SceneLoadEventMetadata* metadata) {
if (metadata->state == app::SceneState__Enum::Loaded && metadata->scene->fields.SceneRoot != nullptr) {
credits.reset();
credits.load(fmt::format(CREDITS_PATH_FMT, modloader::base_path().string()));
auto credits_go = il2cpp::unity::find_child(scene_root, "credits");
auto credits_go = il2cpp::unity::find_child(metadata->scene->fields.SceneRoot, "credits");
auto cred_cont = il2cpp::unity::get_component<app::CreditsController>(credits_go, types::CreditsController::get_class());
auto timeline = cred_cont->fields.CreditsTimeline;
il2cpp::invoke_virtual(timeline, reinterpret_cast<Il2CppClass*>(types::TimelineEntity::get_class()), "StartPlayback");
Expand All @@ -55,9 +55,9 @@ namespace randomizer::features::credits {
}
}

void ending_scene_loaded_callback(std::string_view scene_name, app::SceneState__Enum state, app::GameObject* scene_root) {
if (state == app::SceneState__Enum::Loaded && scene_root != nullptr) {
auto master_timeline_go = il2cpp::unity::find_child(scene_root, "master2.0");
void ending_scene_loaded_callback(core::api::scenes::SceneLoadEventMetadata* metadata) {
if (metadata->state == app::SceneState__Enum::Loaded && metadata->scene->fields.SceneRoot != nullptr) {
auto master_timeline_go = il2cpp::unity::find_child(metadata->scene->fields.SceneRoot, "master2.0");
il2cpp::unity::destroy_object(master_timeline_go);

core::api::game::player::set_position(0.f, 0.f);
Expand Down
Loading

0 comments on commit 55380e4

Please sign in to comment.