the route strips are back
[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 #include "network_msg.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 static void skaterift_world_get_save_path( enum world_purpose which,
37 char buf[128] );
38
39 /* submodule headers */
40 #include "world_entity.h"
41 #include "world_gate.h"
42 #include "world_gen.h"
43 #include "world_info.h"
44 #include "world_load.h"
45 #include "world_physics.h"
46 #include "world_render.h"
47 #include "world_sfd.h"
48 #include "world_volumes.h"
49 #include "world_water.h"
50 #include "world_audio.h"
51 #include "world_routes.h"
52 #include "world_routes_ui.h"
53
54 /* console variables */
55
56 static f32 k_day_length = 30.0f; /* minutes */
57 static i32 k_debug_light_indices = 0,
58 k_debug_light_complexity= 0,
59 k_light_preview = 0;
60
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 }
159 * surfaces;
160 u32 surface_count;
161
162 ent_worldinfo info;
163 mdl_array_ptr ent_spawn,
164 ent_gate,
165 ent_light,
166 ent_route_node,
167 ent_path_index,
168 ent_checkpoint,
169 ent_route,
170 ent_water,
171
172 ent_audio_clip,
173 ent_audio,
174 ent_volume,
175 ent_traffic,
176 ent_skateshop,
177 ent_marker,
178 ent_camera,
179 ent_swspreview,
180 ent_ccmd,
181 ent_objective,
182 ent_challenge,
183 ent_relay,
184 ent_cubemap,
185 ent_miniworld,
186 ent_prop;
187
188 enum skybox {
189 k_skybox_default,
190 k_skybox_space
191 } skybox;
192
193 ent_gate *rendering_gate;
194
195 /* logic
196 * ----------------------------------------------------
197 */
198
199 /* world geometry */
200 scene_context scene_geo,
201 scene_no_collide,
202 scene_lines;
203
204 /* spacial mappings */
205 bh_tree *geo_bh,
206 *entity_bh;
207 u32 *entity_list;
208
209 /* graphics */
210 glmesh mesh_route_lines;
211 glmesh mesh_geo,
212 mesh_no_collide,
213 mesh_water;
214 u32 cubemap_cooldown, cubemap_side;
215
216 rb_object rb_geo;
217
218 /* leaderboards */
219 struct leaderboard_cache *leaderboard_cache;
220
221 /* ui */
222 struct route_ui *routes_ui;
223 };
224
225 struct world_static {
226 /*
227 * Allocated as system memory
228 * --------------------------------------------------------------------------
229 */
230 void *heap;
231
232 u32 current_run_version;
233 double time, rewind_from, rewind_to, last_use;
234
235 u32 active_trigger_volumes[8];
236 u32 active_trigger_volume_count;
237
238 addon_reg *instance_addons[ k_world_max ];
239 world_instance instances[ k_world_max ];
240
241 enum world_purpose active_instance;
242 u32 focused_entity; /* like skateshop, challenge.. */
243 f32 focus_strength;
244 camera focus_cam;
245
246 /* challenges */
247 ent_objective *challenge_target;
248 f32 challenge_timer;
249
250 enum world_loader_state{
251 k_world_loader_none,
252 k_world_loader_preload,
253 k_world_loader_load
254 }
255 load_state;
256 }
257 static world_static;
258
259 static void world_init(void);
260 static world_instance *world_current_instance(void);
261 static void world_switch_instance( u32 index );
262
263 #endif /* WORLD_H */