Put the scene on the heap since it's huge now.
This commit is contained in:
parent
482ec07fb3
commit
6235bfb657
1 changed files with 25 additions and 25 deletions
|
|
@ -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) {
|
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
|
if(glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
|
||||||
scene.camera.forward();
|
scene->camera.forward();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
|
if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
|
||||||
scene.camera.back();
|
scene->camera.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
|
if(glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
|
||||||
scene.camera.left();
|
scene->camera.left();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
|
if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
|
||||||
scene.camera.right();
|
scene->camera.right();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) {
|
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) {
|
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) {
|
if(glfwGetKey(window, GLFW_KEY_H) == GLFW_PRESS) {
|
||||||
scene.spawn("human");
|
scene->spawn("human");
|
||||||
glm::vec3 pos = scene.camera.position;
|
glm::vec3 pos = scene->camera.position;
|
||||||
text_content = std::format("Spawn human at {},{},{}", pos.x, pos.y, pos.z);
|
text_content = std::format("Spawn human at {},{},{}", pos.x, pos.y, pos.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(glfwGetKey(window, GLFW_KEY_L) == GLFW_PRESS) {
|
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) {
|
if(glfwGetKey(window, GLFW_KEY_O) == GLFW_PRESS) {
|
||||||
for(auto& light : scene.light.directional) {
|
for(auto& light : scene->light.directional) {
|
||||||
light.adjust(-0.01f);
|
light.adjust(-0.01f);
|
||||||
}
|
}
|
||||||
|
|
||||||
scene.shader.apply_lighting(scene.light);
|
scene->shader.apply_lighting(scene->light);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) {
|
if(glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) {
|
||||||
for(auto& light : scene.light.directional) {
|
for(auto& light : scene->light.directional) {
|
||||||
light.adjust(0.01f);
|
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_DEPTH_TEST);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
|
|
@ -124,23 +124,23 @@ Scene setup() {
|
||||||
|
|
||||||
components::Scene config = utils::load_scene_config("config.json");
|
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();
|
glfwPollEvents();
|
||||||
process_input(window, scene);
|
process_input(window, scene);
|
||||||
scene.update();
|
scene->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(GLFWwindow* window, Scene& scene, Text &text) {
|
void render(GLFWwindow* window, std::shared_ptr<Scene> scene, Text &text) {
|
||||||
scene.render(window);
|
scene->render(window);
|
||||||
text.render(text_content, 25.0f, 25.0f, 1.0f, glm::vec3(1.0, 0.0f, 0.0f));
|
text.render(text_content, 25.0f, 25.0f, 1.0f, glm::vec3(1.0, 0.0f, 0.0f));
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void quit(GLFWwindow* window, Scene& scene) {
|
void quit(GLFWwindow* window, std::shared_ptr<Scene> scene) {
|
||||||
scene.cleanup();
|
scene->cleanup();
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,10 +148,10 @@ int main() {
|
||||||
init_glfw();
|
init_glfw();
|
||||||
|
|
||||||
auto window = create_window();
|
auto window = create_window();
|
||||||
auto scene = setup();
|
std::shared_ptr<Scene> scene = setup();
|
||||||
Text text;
|
Text text;
|
||||||
|
|
||||||
glfwSetWindowUserPointer(window, &scene);
|
glfwSetWindowUserPointer(window, scene.get());
|
||||||
|
|
||||||
while(!glfwWindowShouldClose(window)) {
|
while(!glfwWindowShouldClose(window)) {
|
||||||
update(window, scene);
|
update(window, scene);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue