Put the scene on the heap since it's huge now.

This commit is contained in:
Zed A. Shaw 2026-09-19 16:47:53 -04:00
parent 482ec07fb3
commit 6235bfb657

View file

@ -54,65 +54,65 @@ GLFWwindow* create_window() {
}
void process_input(GLFWwindow *window, Scene& scene) {
void process_input(GLFWwindow *window, std::shared_ptr<Scene> scene) {
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);
}
if(glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
scene.camera.forward();
scene->camera.forward();
}
if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
scene.camera.back();
scene->camera.back();
}
if(glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
scene.camera.left();
scene->camera.left();
}
if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
scene.camera.right();
scene->camera.right();
}
if(glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) {
scene.reflect_on = !scene.reflect_on;
scene->reflect_on = !scene->reflect_on;
}
if(glfwGetKey(window, GLFW_KEY_J) == GLFW_PRESS) {
scene.debug_on = !scene.debug_on;
scene->debug_on = !scene->debug_on;
}
if(glfwGetKey(window, GLFW_KEY_H) == GLFW_PRESS) {
scene.spawn("human");
glm::vec3 pos = scene.camera.position;
scene->spawn("human");
glm::vec3 pos = scene->camera.position;
text_content = std::format("Spawn human at {},{},{}", pos.x, pos.y, pos.z);
}
if(glfwGetKey(window, GLFW_KEY_L) == GLFW_PRESS) {
scene.light.camera.on = !scene.light.camera.on;
scene->light.camera.on = !scene->light.camera.on;
scene.shader.apply_lighting(scene.light);
scene->shader.apply_lighting(scene->light);
}
if(glfwGetKey(window, GLFW_KEY_O) == GLFW_PRESS) {
for(auto& light : scene.light.directional) {
for(auto& light : scene->light.directional) {
light.adjust(-0.01f);
}
scene.shader.apply_lighting(scene.light);
scene->shader.apply_lighting(scene->light);
}
if(glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) {
for(auto& light : scene.light.directional) {
for(auto& light : scene->light.directional) {
light.adjust(0.01f);
}
scene.shader.apply_lighting(scene.light);
scene->shader.apply_lighting(scene->light);
}
}
Scene setup() {
std::shared_ptr<Scene> setup() {
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glDisable(GL_CULL_FACE);
@ -124,23 +124,23 @@ Scene setup() {
components::Scene config = utils::load_scene_config("config.json");
return {config};
return std::make_shared<Scene>(config);
}
void update(GLFWwindow* window, Scene& scene) {
void update(GLFWwindow* window, std::shared_ptr<Scene> scene) {
glfwPollEvents();
process_input(window, scene);
scene.update();
scene->update();
}
void render(GLFWwindow* window, Scene& scene, Text &text) {
scene.render(window);
void render(GLFWwindow* window, std::shared_ptr<Scene> scene, Text &text) {
scene->render(window);
text.render(text_content, 25.0f, 25.0f, 1.0f, glm::vec3(1.0, 0.0f, 0.0f));
glfwSwapBuffers(window);
}
void quit(GLFWwindow* window, Scene& scene) {
scene.cleanup();
void quit(GLFWwindow* window, std::shared_ptr<Scene> scene) {
scene->cleanup();
glfwTerminate();
}
@ -148,10 +148,10 @@ int main() {
init_glfw();
auto window = create_window();
auto scene = setup();
std::shared_ptr<Scene> scene = setup();
Text text;
glfwSetWindowUserPointer(window, &scene);
glfwSetWindowUserPointer(window, scene.get());
while(!glfwWindowShouldClose(window)) {
update(window, scene);