summaryrefslogtreecommitdiff
path: root/src/world.hpp
blob: e8882b2a25a3f0fe83ec70b6730aed659f1b9f27 (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
#pragma once

#include "xe_game_object.hpp"
#include "skinned_renderer.hpp"
#include "chunk.hpp"

#define GLM_FORCE_RADIANS
#include <glm/common.hpp>
#include <glm/fwd.hpp>
#include <glm/geometric.hpp>

#include <vector>

namespace app {

class World {

  public:

    struct Ray {
      glm::ivec3 pos;
      int hit;
    };

    World(xe::GameObject& viewer, int renderDistance, int worldSeed);
    ~World();

    void reloadChunks();
    void reloadChunks(int newRenderDistance);
    
    void render(xe::Camera& camera);

    Ray raycast(float distance, int steps);

  private:

    void resetChunks();

    void unloadOldChunks();
    void loadNewChunks();
    void updateChunkMeshs();

    int viewX, viewZ;

    int worldSeed;
    int renderDistance;
    
    const xe::GameObject& viewer;
    std::vector<xe::GameObject> loadedChunks;

    SkinnedRenderer skinnedRenderer;

};

}