Physics and collision system to make players interact with the generated terraine without falling through the world like lemmings. It uses a shared bilinear interpolation function for terrain height for smooth and consistant height queries on the client and server.
30 lines
600 B
C++
30 lines
600 B
C++
#pragma once
|
|
|
|
#include <map>
|
|
#include "bettola/noise/fast_noise_lite.h"
|
|
#include "bettola/game/chunk.h"
|
|
|
|
struct ChunkPos {
|
|
int x, z;
|
|
bool operator<(const ChunkPos& other) const {
|
|
if(x < other.x) return true;
|
|
if(x > other.x) return false;
|
|
return z < other.z;
|
|
}
|
|
};
|
|
|
|
class World {
|
|
public:
|
|
World(void);
|
|
|
|
BettolaLib::Game::Chunk& get_chunk(int x, int z);
|
|
float get_height(float world_x, float world_z);
|
|
|
|
private:
|
|
void _generate_chunk(BettolaLib::Game::Chunk& chunk, int chunk_x, int chunk_z);
|
|
|
|
FastNoiseLite m_noise;
|
|
std::map<ChunkPos, BettolaLib::Game::Chunk> m_chunks;
|
|
};
|
|
|