shader overrides
[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
53 /* console variables */
54
55 static f32 k_day_length = 30.0f; /* minutes */
56 static i32 k_debug_light_indices = 0,
57 k_debug_light_complexity= 0,
58 k_light_preview = 0;
59
60
61 struct world_instance {
62 /* Fixed items
63 * -------------------------------------------------------
64 */
65
66 v4f player_co;
67
68 void *heap;
69 enum world_status{
70 k_world_status_unloaded = 0,
71 k_world_status_loading = 1,
72 k_world_status_loaded = 2,
73 k_world_status_unloading = 3 /* dont spawn sounds and stuff */
74 }
75 status;
76
77 struct{
78 boxf depthbounds;
79 int depth_computed;
80
81 float height;
82 int enabled;
83 v4f plane;
84 }
85 water;
86
87 f64 time;
88 f32 tar_min, tar_max;
89
90 /* STD140 */
91 struct ub_world_lighting{
92 v4f g_cube_min,
93 g_cube_inv_range;
94
95 v4f g_water_plane,
96 g_depth_bounds;
97
98 v4f g_daysky_colour;
99 v4f g_nightsky_colour;
100 v4f g_sunset_colour;
101 v4f g_ambient_colour;
102 v4f g_sunset_ambient;
103 v4f g_sun_colour;
104 v4f g_sun_dir;
105 v4f g_board_0;
106 v4f g_board_1;
107
108 float g_water_fog;
109 float g_time;
110 float g_realtime;
111 float g_shadow_length;
112 float g_shadow_spread;
113
114 float g_time_of_day;
115 float g_day_phase;
116 float g_sunset_phase;
117
118 int g_light_preview;
119 int g_shadow_samples;
120
121 int g_debug_indices;
122 int g_debug_complexity;
123 }
124 ub_lighting;
125 GLuint ubo_lighting;
126 int ubo_bind_point;
127
128 GLuint tbo_light_entities,
129 tex_light_entities,
130 tex_light_cubes;
131
132 float probabilities[3];
133
134 v3i light_cubes;
135 struct framebuffer heightmap;
136
137 /*
138 * Dynamically allocated when world_load is called.
139 *
140 * the following arrays index somewhere into this linear
141 * allocator
142 * --------------------------------------------------------------------------
143 */
144
145 /*
146 * Main world .mdl
147 */
148 mdl_context meta;
149
150 GLuint *textures;
151 u32 texture_count;
152
153 struct world_surface{
154 mdl_material info;
155 mdl_submesh sm_geo,
156 sm_no_collide;
157 }
158 * surfaces;
159 u32 surface_count;
160
161 ent_worldinfo info;
162 mdl_array_ptr ent_spawn,
163 ent_gate,
164 ent_light,
165 ent_route_node,
166 ent_path_index,
167 ent_checkpoint,
168 ent_route,
169 ent_water,
170
171 ent_audio_clip,
172 ent_audio,
173 ent_volume,
174 ent_traffic,
175 ent_skateshop,
176 ent_marker,
177 ent_camera,
178 ent_swspreview,
179 ent_ccmd,
180 ent_objective,
181 ent_challenge,
182 ent_relay,
183 ent_cubemap,
184 ent_miniworld,
185 ent_prop;
186
187 enum skybox {
188 k_skybox_default,
189 k_skybox_space
190 } skybox;
191
192 ent_gate *rendering_gate;
193
194 /* logic
195 * ----------------------------------------------------
196 */
197
198 /* world geometry */
199 scene_context scene_geo,
200 scene_no_collide,
201 scene_lines;
202
203 /* spacial mappings */
204 bh_tree *geo_bh,
205 *entity_bh;
206 u32 *entity_list;
207
208 /* graphics */
209 glmesh mesh_route_lines;
210 glmesh mesh_geo,
211 mesh_no_collide,
212 mesh_water;
213 u32 cubemap_cooldown, cubemap_side;
214
215 rb_object rb_geo;
216
217 /* leaderboards */
218 struct leaderboard_cache *leaderboard_cache;
219 };
220
221 struct world_static {
222 /*
223 * Allocated as system memory
224 * --------------------------------------------------------------------------
225 */
226 void *heap;
227
228 u32 current_run_version;
229 double time, rewind_from, rewind_to, last_use;
230
231 u32 active_trigger_volumes[8];
232 u32 active_trigger_volume_count;
233
234 addon_reg *instance_addons[ k_world_max ];
235 world_instance instances[ k_world_max ];
236
237 enum world_purpose active_instance;
238 u32 focused_entity; /* like skateshop, challenge.. */
239 f32 focus_strength;
240 camera focus_cam;
241
242 /* challenges */
243 ent_objective *challenge_target;
244 f32 challenge_timer;
245
246 enum world_loader_state{
247 k_world_loader_none,
248 k_world_loader_preload,
249 k_world_loader_load
250 }
251 load_state;
252 }
253 static world_static;
254
255 static void world_init(void);
256 static world_instance *world_current_instance(void);
257 static void world_switch_instance( u32 index );
258
259 #endif /* WORLD_H */