-
Notifications
You must be signed in to change notification settings - Fork 0
scene_loader::load_scene()
Paweł Waligóra edited this page May 22, 2024
·
3 revisions
void scene_loader::load_scene(const std::string& file_name) {
//un load previous scene
un_load_scene();
// load new scene from file
std::ifstream file(file_name); // open file
nlohmann::json json;
file >> json;
for (auto& entry : json["scripts"])
{
// create script instance
nlohmann::json args = entry["args"];
if (entry["type"] == "gameplay_manager") { scripts_system::scripts.push_back(new game::gameplay_manager()); }
else if (entry["type"] == "player") { scripts_system::scripts.push_back(new game::player(glm::vec3(args["x"], args["y"], args["z"]), args["rot_y"])); }
else if (entry["type"] == "fly_cam") { scripts_system::scripts.push_back(new game::fly_cam()); }
else if (entry["type"] == "wall") { scripts_system::scripts.push_back(new game::wall(
glm::vec3(args["position"]["x"], args["position"]["y"], args["position"]["z"]),
glm::vec3(args["rotation"]["x"], args["rotation"]["y"], args["rotation"]["z"]),
glm::vec3(args["size"]["x"], args["size"]["y"], args["size"]["z"]))); }
else if (entry["type"] == "collision_test_script") { scripts_system::scripts.push_back(new physics::collision_test_script()); }
// name the script
scripts_system::scripts.back()->name = entry["name"];
}
file.close(); // close file
printf("===scene_loaded===\n");
scripts_system::call_events(SCRIPTS_START);
}
Function un_load currently loaded scene and loads a new one from file.
Can be used in a script. Simply call: scene_loader::load_scene("scene-name.json");
and that's it.
file_name
is a path to a file. The rules of how file should look are presented on scene_file page.
- engine
- scripts_system
- scene_loader
- time_system
-
input_system
- input_system::key_held
- input_system::key_events
- input_system::subscribe() (deprecated)
- input_system::axis_state()
- input_system::key_bind
- input_system::axis
- input_system::double_axis
- input_system::triple_axis
- input_system::axis2
- input_system::double_axis2
- input_system::triple_axis2
- input_system::axis-choice
- renderer
- physics
- ui_system
- game