823b38c70e7992ae838f91b6dd0f55a330feec1e
[carveJwlIkooP6JGAAIwe30JlM.git] / world.h
1 /*
2 * Copyright (C) 2021-2024 Mt.ZERO Software, Harry Godden - All Rights Reserved
3 */
4
5 #pragma once
6 #include "render.h"
7 #include "network_msg.h"
8 #include "addon.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 enum world_purpose{
20 k_world_purpose_invalid = -1,
21 k_world_purpose_hub = 0,
22 k_world_purpose_client = 1,
23 k_world_max
24 };
25
26 struct leaderboard_cache {
27 enum request_status status;
28 f64 cache_time;
29 u8 *data;
30 u32 data_len;
31 };
32
33 typedef struct world_instance world_instance;
34
35 void skaterift_world_get_save_path( enum world_purpose which, char buf[128] );
36
37 /* submodule headers */
38 #include "world_entity.h"
39 #include "world_gate.h"
40 #include "world_gen.h"
41 #include "world_info.h"
42 #include "world_physics.h"
43 #include "world_render.h"
44 #include "world_sfd.h"
45 #include "world_volumes.h"
46 #include "world_water.h"
47 #include "world_audio.h"
48 #include "world_routes.h"
49 #include "world_routes_ui.h"
50
51 /* console variables */
52
53 static f32 k_day_length = 30.0f; /* minutes */
54 static i32 k_debug_light_indices = 0,
55 k_debug_light_complexity= 0,
56 k_light_preview = 0,
57 k_light_editor = 0;
58
59 #define WORLD_SURFACE_HAS_TRAFFIC 0x1
60 #define WORLD_SURFACE_HAS_PROPS 0x2
61
62 struct world_instance {
63 /* Fixed items
64 * -------------------------------------------------------
65 */
66
67 v4f player_co;
68
69 void *heap;
70 enum world_status{
71 k_world_status_unloaded = 0,
72 k_world_status_loading = 1,
73 k_world_status_loaded = 2,
74 k_world_status_unloading = 3 /* dont spawn sounds and stuff */
75 }
76 status;
77
78 struct{
79 boxf depthbounds;
80 int depth_computed;
81
82 float height;
83 int enabled;
84 v4f plane;
85 }
86 water;
87
88 f64 time;
89 f32 tar_min, tar_max;
90
91 /* STD140 */
92 struct ub_world_lighting{
93 v4f g_cube_min,
94 g_cube_inv_range;
95
96 v4f g_water_plane,
97 g_depth_bounds;
98
99 v4f g_daysky_colour;
100 v4f g_nightsky_colour;
101 v4f g_sunset_colour;
102 v4f g_ambient_colour;
103 v4f g_sunset_ambient;
104 v4f g_sun_colour;
105 v4f g_sun_dir;
106 v4f g_board_0;
107 v4f g_board_1;
108
109 float g_water_fog;
110 float g_time;
111 float g_realtime;
112 float g_shadow_length;
113 float g_shadow_spread;
114
115 float g_time_of_day;
116 float g_day_phase;
117 float g_sunset_phase;
118
119 int g_light_preview;
120 int g_shadow_samples;
121
122 int g_debug_indices;
123 int g_debug_complexity;
124 }
125 ub_lighting;
126 GLuint ubo_lighting;
127 int ubo_bind_point;
128
129 GLuint tbo_light_entities,
130 tex_light_entities,
131 tex_light_cubes;
132
133 float probabilities[3];
134
135 v3i light_cubes;
136 struct framebuffer heightmap;
137
138 /*
139 * Dynamically allocated when world_load is called.
140 *
141 * the following arrays index somewhere into this linear
142 * allocator
143 * --------------------------------------------------------------------------
144 */
145
146 /*
147 * Main world .mdl
148 */
149 mdl_context meta;
150
151 GLuint *textures;
152 u32 texture_count;
153
154 struct world_surface{
155 mdl_material info;
156 mdl_submesh sm_geo,
157 sm_no_collide;
158 u32 flags;
159 }
160 * surfaces;
161 u32 surface_count;
162
163 ent_worldinfo info;
164 mdl_array_ptr ent_spawn,
165 ent_gate,
166 ent_light,
167 ent_route_node,
168 ent_path_index,
169 ent_checkpoint,
170 ent_route,
171 ent_water,
172
173 ent_audio_clip,
174 ent_audio,
175 ent_volume,
176 ent_traffic,
177 ent_skateshop,
178 ent_marker,
179 ent_camera,
180 ent_swspreview,
181 ent_ccmd,
182 ent_objective,
183 ent_challenge,
184 ent_relay,
185 ent_cubemap,
186 ent_miniworld,
187 ent_prop,
188 ent_region,
189 ent_glider;
190
191 enum skybox {
192 k_skybox_default,
193 k_skybox_space
194 } skybox;
195
196 ent_gate *rendering_gate;
197
198 /* logic
199 * ----------------------------------------------------
200 */
201
202 /* world geometry */
203 scene_context scene_geo,
204 scene_no_collide,
205 scene_lines;
206
207 /* spacial mappings */
208 bh_tree *geo_bh,
209 *entity_bh;
210 u32 *entity_list;
211
212 /* graphics */
213 glmesh mesh_route_lines;
214 glmesh mesh_geo,
215 mesh_no_collide,
216 mesh_water;
217 u32 cubemap_cooldown, cubemap_side;
218
219 /* leaderboards */
220 struct leaderboard_cache *leaderboard_cache;
221
222 /* ui */
223 struct route_ui *routes_ui;
224 };
225
226 struct world_static {
227 /*
228 * Allocated as system memory
229 * --------------------------------------------------------------------------
230 */
231 void *heap;
232
233 u32 current_run_version;
234 double time, rewind_from, rewind_to, last_use;
235
236 u32 active_trigger_volumes[8];
237 u32 active_trigger_volume_count;
238
239 addon_reg *instance_addons[ k_world_max ];
240 world_instance instances[ k_world_max ];
241
242 enum world_purpose active_instance;
243 u32 focused_entity; /* like skateshop, challenge.. */
244 f32 focus_strength;
245 vg_camera focus_cam;
246
247 /* challenges */
248 ent_objective *challenge_target;
249 f32 challenge_timer;
250
251 enum world_loader_state{
252 k_world_loader_none,
253 k_world_loader_preload,
254 k_world_loader_load
255 }
256 load_state;
257 }
258 extern world_static;
259
260 struct world_load_args
261 {
262 enum world_purpose purpose;
263 addon_reg *reg;
264 };
265
266 void world_init(void);
267 world_instance *world_current_instance(void);
268 void world_switch_instance( u32 index );
269 void skaterift_world_load_thread( void *_args );
270 void world_update( world_instance *world, v3f pos );