trail rendering basics
[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 k_light_editor = 0;
61
62 #define WORLD_SURFACE_HAS_TRAFFIC 0x1
63 #define WORLD_SURFACE_HAS_PROPS 0x2
64
65 struct world_instance {
66 /* Fixed items
67 * -------------------------------------------------------
68 */
69
70 v4f player_co;
71
72 void *heap;
73 enum world_status{
74 k_world_status_unloaded = 0,
75 k_world_status_loading = 1,
76 k_world_status_loaded = 2,
77 k_world_status_unloading = 3 /* dont spawn sounds and stuff */
78 }
79 status;
80
81 struct{
82 boxf depthbounds;
83 int depth_computed;
84
85 float height;
86 int enabled;
87 v4f plane;
88 }
89 water;
90
91 f64 time;
92 f32 tar_min, tar_max;
93
94 /* STD140 */
95 struct ub_world_lighting{
96 v4f g_cube_min,
97 g_cube_inv_range;
98
99 v4f g_water_plane,
100 g_depth_bounds;
101
102 v4f g_daysky_colour;
103 v4f g_nightsky_colour;
104 v4f g_sunset_colour;
105 v4f g_ambient_colour;
106 v4f g_sunset_ambient;
107 v4f g_sun_colour;
108 v4f g_sun_dir;
109 v4f g_board_0;
110 v4f g_board_1;
111
112 float g_water_fog;
113 float g_time;
114 float g_realtime;
115 float g_shadow_length;
116 float g_shadow_spread;
117
118 float g_time_of_day;
119 float g_day_phase;
120 float g_sunset_phase;
121
122 int g_light_preview;
123 int g_shadow_samples;
124
125 int g_debug_indices;
126 int g_debug_complexity;
127 }
128 ub_lighting;
129 GLuint ubo_lighting;
130 int ubo_bind_point;
131
132 GLuint tbo_light_entities,
133 tex_light_entities,
134 tex_light_cubes;
135
136 float probabilities[3];
137
138 v3i light_cubes;
139 struct framebuffer heightmap;
140
141 /*
142 * Dynamically allocated when world_load is called.
143 *
144 * the following arrays index somewhere into this linear
145 * allocator
146 * --------------------------------------------------------------------------
147 */
148
149 /*
150 * Main world .mdl
151 */
152 mdl_context meta;
153
154 GLuint *textures;
155 u32 texture_count;
156
157 struct world_surface{
158 mdl_material info;
159 mdl_submesh sm_geo,
160 sm_no_collide;
161 u32 flags;
162 }
163 * surfaces;
164 u32 surface_count;
165
166 ent_worldinfo info;
167 mdl_array_ptr ent_spawn,
168 ent_gate,
169 ent_light,
170 ent_route_node,
171 ent_path_index,
172 ent_checkpoint,
173 ent_route,
174 ent_water,
175
176 ent_audio_clip,
177 ent_audio,
178 ent_volume,
179 ent_traffic,
180 ent_skateshop,
181 ent_marker,
182 ent_camera,
183 ent_swspreview,
184 ent_ccmd,
185 ent_objective,
186 ent_challenge,
187 ent_relay,
188 ent_cubemap,
189 ent_miniworld,
190 ent_prop,
191 ent_region;
192
193 enum skybox {
194 k_skybox_default,
195 k_skybox_space
196 } skybox;
197
198 ent_gate *rendering_gate;
199
200 /* logic
201 * ----------------------------------------------------
202 */
203
204 /* world geometry */
205 scene_context scene_geo,
206 scene_no_collide,
207 scene_lines;
208
209 /* spacial mappings */
210 bh_tree *geo_bh,
211 *entity_bh;
212 u32 *entity_list;
213
214 /* graphics */
215 glmesh mesh_route_lines;
216 glmesh mesh_geo,
217 mesh_no_collide,
218 mesh_water;
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 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 static world_static;
261
262 static void world_init(void);
263 static world_instance *world_current_instance(void);
264 static void world_switch_instance( u32 index );
265
266 #endif /* WORLD_H */