upgrade to vg_msgv2
[carveJwlIkooP6JGAAIwe30JlM.git] / world.h
1 /*
2 * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved
3 */
4
5 #ifndef WORLD_H
6 #define WORLD_H
7
8 #include "render.h"
9
10 /* types
11 */
12
13 enum world_geo_type{
14 k_world_geo_type_solid = 0,
15 k_world_geo_type_nonsolid = 1,
16 k_world_geo_type_water = 2
17 };
18
19 typedef struct world_instance world_instance;
20
21 /* submodule headers */
22 #include "world_entity.h"
23 #include "world_gate.h"
24 #include "world_gen.h"
25 #include "world_info.h"
26 #include "world_load.h"
27 #include "world_physics.h"
28 #include "world_render.h"
29 #include "world_sfd.h"
30 #include "world_volumes.h"
31 #include "world_water.h"
32 #include "world_audio.h"
33 #include "world_routes.h"
34
35 /* console variables */
36
37 static f32 k_day_length = 30.0f; /* minutes */
38 static i32 k_debug_light_indices = 0,
39 k_debug_light_complexity= 0,
40 k_light_preview = 0;
41
42
43 struct world_instance {
44 /* Fixed items
45 * -------------------------------------------------------
46 */
47
48 void *heap;
49 enum world_status{
50 k_world_status_unloaded = 0,
51 k_world_status_loading = 1,
52 k_world_status_loaded = 2,
53 k_world_status_unloading = 3 /* dont spawn sounds and stuff */
54 }
55 status;
56
57 struct{
58 boxf depthbounds;
59 int depth_computed;
60
61 float height;
62 int enabled;
63 v4f plane;
64 }
65 water;
66
67 f64 time;
68
69 /* STD140 */
70 struct ub_world_lighting{
71 v4f g_cube_min,
72 g_cube_inv_range;
73
74 v4f g_water_plane,
75 g_depth_bounds;
76
77 v4f g_daysky_colour;
78 v4f g_nightsky_colour;
79 v4f g_sunset_colour;
80 v4f g_ambient_colour;
81 v4f g_sunset_ambient;
82 v4f g_sun_colour;
83 v4f g_sun_dir;
84 v4f g_board_0;
85 v4f g_board_1;
86
87 float g_water_fog;
88 float g_time;
89 float g_realtime;
90 float g_shadow_length;
91 float g_shadow_spread;
92
93 float g_time_of_day;
94 float g_day_phase;
95 float g_sunset_phase;
96
97 int g_light_preview;
98 int g_shadow_samples;
99
100 int g_debug_indices;
101 int g_debug_complexity;
102 }
103 ub_lighting;
104 GLuint ubo_lighting;
105 int ubo_bind_point;
106
107 GLuint tbo_light_entities,
108 tex_light_entities,
109 tex_light_cubes;
110
111 float probabilities[3];
112
113 v3i light_cubes;
114 struct framebuffer heightmap;
115
116 /*
117 * Dynamically allocated when world_load is called.
118 *
119 * the following arrays index somewhere into this linear
120 * allocator
121 * --------------------------------------------------------------------------
122 */
123
124 /*
125 * Main world .mdl
126 */
127 mdl_context meta;
128
129 GLuint *textures;
130 u32 texture_count;
131
132 struct world_surface{
133 mdl_material info;
134 mdl_submesh sm_geo,
135 sm_no_collide;
136 }
137 * surfaces;
138 u32 surface_count;
139
140 ent_worldinfo info;
141 mdl_array_ptr ent_spawn,
142 ent_gate,
143 ent_light,
144 ent_route_node,
145 ent_path_index,
146 ent_checkpoint,
147 ent_route,
148 ent_water,
149
150 ent_audio_clip,
151 ent_audio,
152 ent_volume,
153 ent_traffic,
154 ent_skateshop,
155 ent_marker,
156 ent_camera,
157 ent_swspreview,
158 ent_ccmd;
159
160 ent_gate *rendering_gate;
161
162 /* logic
163 * ----------------------------------------------------
164 */
165
166 /* world geometry */
167 scene_context scene_geo,
168 scene_no_collide,
169 scene_lines;
170
171 /* spacial mappings */
172 bh_tree *audio_bh,
173 *volume_bh,
174 *geo_bh;
175
176 /* graphics */
177 glmesh mesh_route_lines;
178 glmesh mesh_geo,
179 mesh_no_collide,
180 mesh_water;
181
182 rb_object rb_geo;
183 };
184
185 struct world_static {
186 /*
187 * Allocated as system memory
188 * --------------------------------------------------------------------------
189 */
190 void *heap;
191
192 u32 current_run_version;
193 double time, rewind_from, rewind_to, last_use;
194
195 u32 active_trigger_volumes[8];
196 u32 active_trigger_volume_count;
197
198 world_instance worlds[4];
199 i32 active_world;
200 }
201 static world_static;
202
203 static void world_init(void);
204 static world_instance *world_current_instance(void);
205
206 #endif /* WORLD_H */