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