aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.h
blob: 338f9355110f811028967d2f156a409afdddbea0 (plain) (blame)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "utils.h"
#include "assets.h"
#include "entity.h"

#ifndef WORLD_H
#define WORLD_H

#define WORLD_ENTITY_MAX 5001
#define WORLD_PLANT_COUNT 2500
#define WORLD_UTILITY_POLE_COUNT 25
#define WORLD_PLACE_COUNT 1

#define WORLD_SIZE (Vector3){4096.0, 256.0, 4096.0}
#define WORLD_IMAGE_WIDTH 512
#define WORLD_IMAGE_HEIGHT 512
#define WORLD_IMAGE_SCALE 5.0

#define WORLD_GROUND_COLOR GREEN
#define WORLD_GROUND_BLUR 2
#define WORLD_GROUND_CONTRAST -30
#define WORLD_GROUND_IMAGE_NOISE 0.3

#define BVH_MAX 4 // Max entities per node.
#define BVH_MAX_BRANCH_COUNT 8
#define BVH_BOX_MAX 100.0

// Places.
#define PLACE_POND_MIN_DISTANCE 400 // Pond distance from center.
#define PLACE_POND_MAX_DISTANCE 600
#define PLACE_POND_DEPTH 10
#define PLACE_POND_OUTER_AREA 25
#define PLACE_POND_WALKING_AREA 7

// Characters.
#define WORLD_CHARACTER_COUNT 1

#define PLACE_SAMANTHAS_SPOT_SIZE 10
#define SAMANTHA_OFFSET (Vector3){0.0, 0.0, 2.0}

// UID for anything in the world.
typedef int16_t WorldUID;
typedef int Seed;

// Places.
enum {
  PLACE_POND
};

typedef struct BVHNode {
  BoundingBox box;
  Vector3 position;
  WorldUID entities[BVH_MAX]; // Only for leafs.
  struct BVHNode* branches[BVH_MAX_BRANCH_COUNT];
  int8_t branchCount;
} BVHNode;

#define UTILITY_LINE_COUNT 4

typedef struct {
  Vector3 start;
  Vector3 end;
} UtilityPoleLines[UTILITY_LINE_COUNT];

struct World {
  Vector3 size;
  Texture heightmapTexture;
  Model heightmap;
  
  Entity entities[WORLD_ENTITY_MAX];
  WorldUID places[WORLD_PLACE_COUNT];
  BVHNode bvh;

  // Transforms for mesh instancing.
  Matrix utilityPoleTransforms[WORLD_UTILITY_POLE_COUNT];
  UtilityPoleLines utilityPoleLines[WORLD_UTILITY_POLE_COUNT - 1];

  int bvhDebugSelect;
};

World createWorld(Seed seed, const Assets* assets);
void updateWorld(World* world, Game* game);
void freeWorld(World world);
// Dam, I wanta live in a free world ):

// When dealing with the world in 2d use y in place of z.
float getWorldHeightAtLocation(const World* world, float x, float y);
Vector2 worldPositionToPixel(const World* world, float x, float y);
WorldUID castRayAtWorld(const World* world, Ray ray, int* tests);

#endif