revision of savedata
[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
10 /* types
11 */
12
13 enum world_geo_type{
14 k_world_geo_type_solid = 0,
15 k_world_geo_type_nonsolid = 1,
16 k_world_geo_type_water = 2
17 };
18
19 enum world_purpose{
20 k_world_purpose_hub,
21 k_world_purpose_client
22 }
23 purpose;
24
25 typedef struct world_instance world_instance;
26
27 static void skaterift_world_get_save_path( enum world_purpose which,
28 char buf[128] );
29
30 /* submodule headers */
31 #include "world_entity.h"
32 #include "world_gate.h"
33 #include "world_gen.h"
34 #include "world_info.h"
35 #include "world_load.h"
36 #include "world_physics.h"
37 #include "world_render.h"
38 #include "world_sfd.h"
39 #include "world_volumes.h"
40 #include "world_water.h"
41 #include "world_audio.h"
42 #include "world_routes.h"
43
44 /* console variables */
45
46 static f32 k_day_length = 30.0f; /* minutes */
47 static i32 k_debug_light_indices = 0,
48 k_debug_light_complexity= 0,
49 k_light_preview = 0;
50
51
52 struct world_instance {
53 /* Fixed items
54 * -------------------------------------------------------
55 */
56
57 void *heap;
58 enum world_status{
59 k_world_status_unloaded = 0,
60 k_world_status_loading = 1,
61 k_world_status_loaded = 2,
62 k_world_status_unloading = 3 /* dont spawn sounds and stuff */
63 }
64 status;
65
66 struct{
67 boxf depthbounds;
68 int depth_computed;
69
70 float height;
71 int enabled;
72 v4f plane;
73 }
74 water;
75
76 f64 time;
77
78 /* STD140 */
79 struct ub_world_lighting{
80 v4f g_cube_min,
81 g_cube_inv_range;
82
83 v4f g_water_plane,
84 g_depth_bounds;
85
86 v4f g_daysky_colour;
87 v4f g_nightsky_colour;
88 v4f g_sunset_colour;
89 v4f g_ambient_colour;
90 v4f g_sunset_ambient;
91 v4f g_sun_colour;
92 v4f g_sun_dir;
93 v4f g_board_0;
94 v4f g_board_1;
95
96 float g_water_fog;
97 float g_time;
98 float g_realtime;
99 float g_shadow_length;
100 float g_shadow_spread;
101
102 float g_time_of_day;
103 float g_day_phase;
104 float g_sunset_phase;
105
106 int g_light_preview;
107 int g_shadow_samples;
108
109 int g_debug_indices;
110 int g_debug_complexity;
111 }
112 ub_lighting;
113 GLuint ubo_lighting;
114 int ubo_bind_point;
115
116 GLuint tbo_light_entities,
117 tex_light_entities,
118 tex_light_cubes;
119
120 float probabilities[3];
121
122 v3i light_cubes;
123 struct framebuffer heightmap;
124
125 /*
126 * Dynamically allocated when world_load is called.
127 *
128 * the following arrays index somewhere into this linear
129 * allocator
130 * --------------------------------------------------------------------------
131 */
132
133 /*
134 * Main world .mdl
135 */
136 mdl_context meta;
137
138 GLuint *textures;
139 u32 texture_count;
140
141 struct world_surface{
142 mdl_material info;
143 mdl_submesh sm_geo,
144 sm_no_collide;
145 }
146 * surfaces;
147 u32 surface_count;
148
149 ent_worldinfo info;
150 mdl_array_ptr ent_spawn,
151 ent_gate,
152 ent_light,
153 ent_route_node,
154 ent_path_index,
155 ent_checkpoint,
156 ent_route,
157 ent_water,
158
159 ent_audio_clip,
160 ent_audio,
161 ent_volume,
162 ent_traffic,
163 ent_skateshop,
164 ent_marker,
165 ent_camera,
166 ent_swspreview,
167 ent_ccmd,
168 ent_challenge,
169 ent_unlock,
170 ent_relay;
171
172 ent_gate *rendering_gate;
173
174 /* logic
175 * ----------------------------------------------------
176 */
177
178 /* world geometry */
179 scene_context scene_geo,
180 scene_no_collide,
181 scene_lines;
182
183 /* spacial mappings */
184 bh_tree *geo_bh,
185 *entity_bh;
186 u32 *entity_list;
187
188 /* graphics */
189 glmesh mesh_route_lines;
190 glmesh mesh_geo,
191 mesh_no_collide,
192 mesh_water;
193
194 rb_object rb_geo;
195
196 ent_challenge *challenge_target;
197 f32 challenge_timer;
198 };
199
200 struct world_static {
201 /*
202 * Allocated as system memory
203 * --------------------------------------------------------------------------
204 */
205 void *heap;
206
207 u32 current_run_version;
208 double time, rewind_from, rewind_to, last_use;
209
210 u32 active_trigger_volumes[8];
211 u32 active_trigger_volume_count;
212
213 world_instance instances[4];
214 i32 active_instance;
215
216 addon_reg *addon_hub,
217 *addon_client;
218
219 enum world_loader_state{
220 k_world_loader_none,
221 k_world_loader_preload,
222 k_world_loader_load
223 }
224 load_state;
225 }
226 static world_static;
227
228 static void world_init(void);
229 static world_instance *world_current_instance(void);
230
231 #endif /* WORLD_H */