summaryrefslogtreecommitdiff
path: root/src/first_app.cpp
blob: 231967000df472d9eefb1a1ff44ed8885f31f732 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "first_app.hpp"
#include "chunk.hpp"

namespace app {

FirstApp::FirstApp() : xeEngine{WIDTH, HEIGHT, "Xenon Vulkan Engine"} {};

FirstApp::~FirstApp() {}

void FirstApp::run() {

  Chunk::load();

  loadGameObjects();

  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 = {-7.f, 3.f, -7.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();

}

void FirstApp::loadGameObjects() {

  for(int32_t x = 0; x < 10; x++) {
    for(int32_t z = 0; z < 10; z++) {
      Chunk* chunk = Chunk::newChunk(x, z, 53463);
    }
  }

  for(int32_t x = 0; x < 10; x++) {
    for(int32_t z = 0; z < 10; z++) {
      Chunk* chunk = Chunk::getChunk(x,z);
      chunk->createMesh();
      
      auto chunkObject = xe::GameObject::createGameObject();
      chunkObject.model = chunk->getMesh();
      chunkObject.transform.translation = {16.f*x, 0.f, 16.f*z};
      gameObjects.push_back(std::move(chunkObject));
    }
  }

}

}