animation and transition adjustments
[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 #define WORLD_SURFACE_HAS_TRAFFIC 0x1
62 #define WORLD_SURFACE_HAS_PROPS 0x2
63
64 struct world_instance {
65 /* Fixed items
66 * -------------------------------------------------------
67 */
68
69 v4f player_co;
70
71 void *heap;
72 enum world_status{
73 k_world_status_unloaded = 0,
74 k_world_status_loading = 1,
75 k_world_status_loaded = 2,
76 k_world_status_unloading = 3 /* dont spawn sounds and stuff */
77 }
78 status;
79
80 struct{
81 boxf depthbounds;
82 int depth_computed;
83
84 float height;
85 int enabled;
86 v4f plane;
87 }
88 water;
89
90 f64 time;
91 f32 tar_min, tar_max;
92
93 /* STD140 */
94 struct ub_world_lighting{
95 v4f g_cube_min,
96 g_cube_inv_range;
97
98 v4f g_water_plane,
99 g_depth_bounds;
100
101 v4f g_daysky_colour;
102 v4f g_nightsky_colour;
103 v4f g_sunset_colour;
104 v4f g_ambient_colour;
105 v4f g_sunset_ambient;
106 v4f g_sun_colour;
107 v4f g_sun_dir;
108 v4f g_board_0;
109 v4f g_board_1;
110
111 float g_water_fog;
112 float g_time;
113 float g_realtime;
114 float g_shadow_length;
115 float g_shadow_spread;
116
117 float g_time_of_day;
118 float g_day_phase;
119 float g_sunset_phase;
120
121 int g_light_preview;
122 int g_shadow_samples;
123
124 int g_debug_indices;
125 int g_debug_complexity;
126 }
127 ub_lighting;
128 GLuint ubo_lighting;
129 int ubo_bind_point;
130
131 GLuint tbo_light_entities,
132 tex_light_entities,
133 tex_light_cubes;
134
135 float probabilities[3];
136
137 v3i light_cubes;
138 struct framebuffer heightmap;
139
140 /*
141 * Dynamically allocated when world_load is called.
142 *
143 * the following arrays index somewhere into this linear
144 * allocator
145 * --------------------------------------------------------------------------
146 */
147
148 /*
149 * Main world .mdl
150 */
151 mdl_context meta;
152
153 GLuint *textures;
154 u32 texture_count;
155
156 struct world_surface{
157 mdl_material info;
158 mdl_submesh sm_geo,
159 sm_no_collide;
160 u32 flags;
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
192 enum skybox {
193 k_skybox_default,
194 k_skybox_space
195 } skybox;
196
197 ent_gate *rendering_gate;
198
199 /* logic
200 * ----------------------------------------------------
201 */
202
203 /* world geometry */
204 scene_context scene_geo,
205 scene_no_collide,
206 scene_lines;
207
208 /* spacial mappings */
209 bh_tree *geo_bh,
210 *entity_bh;
211 u32 *entity_list;
212
213 /* graphics */
214 glmesh mesh_route_lines;
215 glmesh mesh_geo,
216 mesh_no_collide,
217 mesh_water;
218 u32 cubemap_cooldown, cubemap_side;
219
220 rb_object rb_geo;
221
222 /* leaderboards */
223 struct leaderboard_cache *leaderboard_cache;
224
225 /* ui */
226 struct route_ui *routes_ui;
227 };
228
229 struct world_static {
230 /*
231 * Allocated as system memory
232 * --------------------------------------------------------------------------
233 */
234 void *heap;
235
236 u32 current_run_version;
237 double time, rewind_from, rewind_to, last_use;
238
239 u32 active_trigger_volumes[8];
240 u32 active_trigger_volume_count;
241
242 addon_reg *instance_addons[ k_world_max ];
243 world_instance instances[ k_world_max ];
244
245 enum world_purpose active_instance;
246 u32 focused_entity; /* like skateshop, challenge.. */
247 f32 focus_strength;
248 camera focus_cam;
249
250 /* challenges */
251 ent_objective *challenge_target;
252 f32 challenge_timer;
253
254 enum world_loader_state{
255 k_world_loader_none,
256 k_world_loader_preload,
257 k_world_loader_load
258 }
259 load_state;
260 }
261 static world_static;
262
263 static void world_init(void);
264 static world_instance *world_current_instance(void);
265 static void world_switch_instance( u32 index );
266
267 #endif /* WORLD_H */