]> git.localhorst.tv Git - blank.git/blobdiff - src/app.cpp
minor optimizations in chunk
[blank.git] / src / app.cpp
index b7e71ec681387512db2dc897a4f6063bce6f0d9a..57651e3b754370602eca2d92706dd000573df1fb 100644 (file)
@@ -6,20 +6,23 @@
 
 namespace blank {
 
-Application::Application(unsigned int seed)
+Application::Application(const Config &config)
 : init_sdl()
 , init_img()
-, init_gl()
+, init_gl(config.doublebuf, config.multisampling)
 , window()
 , ctx(window.CreateContext())
 , init_glew()
-, program()
+, chunk_prog()
+, entity_prog()
 , cam()
-, world(seed)
-, interface(world)
+, world(config.world)
+, interface(config.interface, world)
 , test_controller(MakeTestEntity(world))
 , running(false) {
-       GLContext::EnableVSync();
+       if (config.vsync) {
+               GLContext::EnableVSync();
+       }
 
        glClearColor(0.0, 0.0, 0.0, 1.0);
 }
@@ -27,7 +30,7 @@ Application::Application(unsigned int seed)
 Entity &Application::MakeTestEntity(World &world) {
        Entity &e = world.AddEntity();
        e.Position({ 0.0f, 0.0f, 0.0f });
-       e.SetShape(world.BlockTypes()[1]->shape, { 1.0f, 1.0f, 0.0f });
+       e.SetShape(world.BlockTypes()[1].shape, { 1.0f, 1.0f, 0.0f });
        e.AngularVelocity(glm::quat(glm::vec3{ 0.00001f, 0.000006f, 0.000013f }));
        return e;
 }
@@ -85,11 +88,16 @@ void Application::HandleEvents() {
        while (SDL_PollEvent(&event)) {
                switch (event.type) {
                        case SDL_KEYDOWN:
+                               interface.HandlePress(event.key);
+                               break;
                        case SDL_KEYUP:
-                               interface.Handle(event.key);
+                               interface.HandleRelease(event.key);
                                break;
                        case SDL_MOUSEBUTTONDOWN:
-                               interface.Handle(event.button);
+                               interface.HandlePress(event.button);
+                               break;
+                       case SDL_MOUSEBUTTONUP:
+                               interface.HandleRelease(event.button);
                                break;
                        case SDL_MOUSEMOTION:
                                interface.Handle(event.motion);
@@ -132,12 +140,12 @@ void Application::Update(int dt) {
 void Application::Render() {
        GLContext::Clear();
 
-       program.Activate();
+       chunk_prog.SetProjection(cam.Projection());
+       entity_prog.SetProjection(cam.Projection());
 
-       program.SetProjection(cam.Projection());
-       world.Render(program);
+       world.Render(chunk_prog, entity_prog);
 
-       interface.Render(program);
+       interface.Render(entity_prog);
 
        window.Flip();
 }