summaryrefslogtreecommitdiff
path: root/src/first_app.cpp
blob: 08f6f0ccbefa75ec6726385078ddb0d9b36e06bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "first_app.hpp"
#include "chunk.hpp"

namespace app {

FirstApp::FirstApp() : xeEngine{WIDTH, HEIGHT, "Minecraft Vulkan", "res/image/icon.png"} {};

FirstApp::~FirstApp() {}

void FirstApp::run() {

  Chunk::load();

  for(int32_t x = 0; x < 10; x++) {
    for(int32_t z = 0; z < 10; z++) {
      Chunk* chunk = Chunk::newChunk(x, z, 53463);
      Chunk::createMeshAsync(chunk);
      auto chunkObject = xe::GameObject::createGameObject();
      chunkObject.transform.translation = {16.f*x, 0.f, 16.f*z};
      gameObjects.push_back(std::move(chunkObject));
    }
  }

  SimpleRenderer renderer{xeEngine, Chunk::getTextures()};

  xe::Sound sound{"res/sound/when_the_world_ends.wav"};
  sound.setLooping(true);
  sound.play();
    
  auto viewerObject = xe::GameObject::createGameObject();
  viewerObject.transform.translation = {0.f, 10.f, 0.f};
  viewerObject.transform.rotation.y = glm::radians(45.f);
  KeyboardMovementController cameraController{xeEngine.getInput(), viewerObject};

  while (xeEngine.poll()) {

    float frameTime = xeEngine.getFrameTime();

    cameraController.update(frameTime);
    xeEngine.getCamera().setViewYXZ(viewerObject.transform.translation, viewerObject.transform.rotation);

    if(xeEngine.beginFrame()) {
      renderer.render(gameObjects, xeEngine.getCamera());
      xeEngine.endFrame();
    }

  }

  xeEngine.close();

  Chunk::unload();

}

}