]> git.localhorst.tv Git - blank.git/blobdiff - src/app.cpp
minor optimizations in chunk
[blank.git] / src / app.cpp
index 4a890d56a61f0cdc10bf5b7a7d9b5cfc3661d256..57651e3b754370602eca2d92706dd000573df1fb 100644 (file)
@@ -6,23 +6,35 @@
 
 namespace blank {
 
-Application::Application()
+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()
-, 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);
 }
 
+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.AngularVelocity(glm::quat(glm::vec3{ 0.00001f, 0.000006f, 0.000013f }));
+       return e;
+}
+
 
 void Application::RunN(size_t n) {
        Uint32 last = SDL_GetTicks();
@@ -76,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);
@@ -116,18 +133,19 @@ void Application::HandleEvents() {
 
 void Application::Update(int dt) {
        interface.Update(dt);
+       test_controller.Update(dt);
        world.Update(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();
 }