chaos pt 1
[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, player_angles;
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
89 /* STD140 */
90 struct ub_world_lighting{
91 v4f g_cube_min,
92 g_cube_inv_range;
93
94 v4f g_water_plane,
95 g_depth_bounds;
96
97 v4f g_daysky_colour;
98 v4f g_nightsky_colour;
99 v4f g_sunset_colour;
100 v4f g_ambient_colour;
101 v4f g_sunset_ambient;
102 v4f g_sun_colour;
103 v4f g_sun_dir;
104 v4f g_board_0;
105 v4f g_board_1;
106
107 float g_water_fog;
108 float g_time;
109 float g_realtime;
110 float g_shadow_length;
111 float g_shadow_spread;
112
113 float g_time_of_day;
114 float g_day_phase;
115 float g_sunset_phase;
116
117 int g_light_preview;
118 int g_shadow_samples;
119
120 int g_debug_indices;
121 int g_debug_complexity;
122 }
123 ub_lighting;
124 GLuint ubo_lighting;
125 int ubo_bind_point;
126
127 GLuint tbo_light_entities,
128 tex_light_entities,
129 tex_light_cubes;
130
131 float probabilities[3];
132
133 v3i light_cubes;
134 struct framebuffer heightmap;
135
136 /*
137 * Dynamically allocated when world_load is called.
138 *
139 * the following arrays index somewhere into this linear
140 * allocator
141 * --------------------------------------------------------------------------
142 */
143
144 /*
145 * Main world .mdl
146 */
147 mdl_context meta;
148
149 GLuint *textures;
150 u32 texture_count;
151
152 struct world_surface{
153 mdl_material info;
154 mdl_submesh sm_geo,
155 sm_no_collide;
156 }
157 * surfaces;
158 u32 surface_count;
159
160 ent_worldinfo info;
161 mdl_array_ptr ent_spawn,
162 ent_gate,
163 ent_light,
164 ent_route_node,
165 ent_path_index,
166 ent_checkpoint,
167 ent_route,
168 ent_water,
169
170 ent_audio_clip,
171 ent_audio,
172 ent_volume,
173 ent_traffic,
174 ent_skateshop,
175 ent_marker,
176 ent_camera,
177 ent_swspreview,
178 ent_ccmd,
179 ent_objective,
180 ent_challenge,
181 ent_relay,
182 ent_cubemap,
183 ent_miniworld;
184
185 ent_gate *rendering_gate;
186
187 /* logic
188 * ----------------------------------------------------
189 */
190
191 /* world geometry */
192 scene_context scene_geo,
193 scene_no_collide,
194 scene_lines;
195
196 /* spacial mappings */
197 bh_tree *geo_bh,
198 *entity_bh;
199 u32 *entity_list;
200
201 /* graphics */
202 glmesh mesh_route_lines;
203 glmesh mesh_geo,
204 mesh_no_collide,
205 mesh_water;
206 u32 cubemap_cooldown, cubemap_side;
207
208 rb_object rb_geo;
209
210 /* leaderboards */
211 struct leaderboard_cache *leaderboard_cache;
212 };
213
214 struct world_static {
215 /*
216 * Allocated as system memory
217 * --------------------------------------------------------------------------
218 */
219 void *heap;
220
221 u32 current_run_version;
222 double time, rewind_from, rewind_to, last_use;
223
224 u32 active_trigger_volumes[8];
225 u32 active_trigger_volume_count;
226
227 addon_reg *instance_addons[ k_world_max ];
228 world_instance instances[ k_world_max ];
229
230 enum world_purpose active_instance;
231 u32 focused_entity; /* like skateshop, challenge.. */
232 f32 focus_strength;
233 camera focus_cam;
234
235 /* challenges */
236 ent_objective *challenge_target;
237 f32 challenge_timer;
238
239 enum world_loader_state{
240 k_world_loader_none,
241 k_world_loader_preload,
242 k_world_loader_load
243 }
244 load_state;
245 }
246 static world_static;
247
248 static void world_init(void);
249 static world_instance *world_current_instance(void);
250 static void world_switch_instance( u32 index );
251
252 #endif /* WORLD_H */