-
Notifications
You must be signed in to change notification settings - Fork 96
/
3DWorld.cpp
executable file
·2441 lines (2153 loc) · 97 KB
/
3DWorld.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 3D World - Main function, glut callbacks, mouse and keyboard processing, window management, config file variable handling, etc.
// by Frank Gennari
// 3/10/02
#include "mesh.h"
#include "main.h"
#include "sinf.h"
#include "ship.h"
#include "ship_util.h"
#include "player_state.h"
#include "dynamic_particle.h"
#include "physics_objects.h"
#include "gl_ext_arb.h"
#include "model3d.h"
#include "openal_wrap.h"
#include "file_utils.h"
#include "draw_utils.h"
#include "tree_leaf.h"
#include <set>
#include <thread> // for std::thread::hardware_concurrency()
#ifdef _WIN32 // wglew.h seems to be Windows only
#include <GL/wglew.h> // for wglSwapIntervalEXT
#else // linux
#include <GL/glxew.h>
#endif
#ifdef _WIN32
extern "C" { // force use of dedicated GPUs rather than Intel integrated graphics
__declspec(dllexport) DWORD NvOptimusEnablement = 1;
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}
#endif
using namespace std;
typedef set<unsigned char>::iterator keyset_it;
int const INIT_DMODE = 0x010F;
bool const MOUSE_LOOK_DEF = 0;
int const STARTING_INIT_X = 0; // setting to 1 seems safer but less efficient
float const DEF_CRADIUS = 10.0;
float const DEF_CTHETA = -1.0;
float const DEF_CPHI = 1.5;
float const DEF_UPTHETA = 0.0;
float const DEF_CAMY = 1.0;
float const MAP_SHIFT = 20.0;
float const MAP_ZOOM = 1.5;
float const D_TIMESTEP = 1.5;
float const MOUSE_R_ADJ = 0.01; // mouse zoom radius adjustment
float const MOUSE_TRAN_ADJ = 0.01; // mouse translate adjustment
float const MOUSE_ANG_ADJ = PI/350; // mouse camera angle increment
float const MA_TOLERANCE = 0.0001; // tolerance adjustment
float const CAMERA_AIR_CONT= 0.5;
float const DEF_OCEAN_WAVE_HEIGHT = 0.01;
float const DEF_CAMERA_RADIUS = 0.06;
int const START_MODE = WMODE_GROUND; // 0 = standard mesh, 1 = planet/universe, 2 = infinite terrain
char const *const defaults_file = "defaults.txt";
char const *const dstate_file = "state.txt";
char const *const dmesh_file = "mesh.txt";
char const *const dcoll_obj_file = "coll_objs/coll_objs.txt";
char const *const dship_def_file = "universe/ship_defs.txt";
char *state_file(nullptr), *mesh_file(nullptr), *coll_obj_file(nullptr);
char *mh_filename(nullptr), *mh_filename_tt(nullptr), *mesh_diffuse_tex_fn(nullptr), *ship_def_file(nullptr), *snow_file(nullptr);
char *lighting_file[NUM_LIGHTING_TYPES] = {0};
// Global Variables - most of these are set by the config file reader and used in other files.
// I decided to use global variables here rather than a global config class to avoid frequent recompile of all code
// every time a config option is added/changed, because almost every file would need to include the class definition/header.
// Note that these are all the default values when no config variable is specified.
bool combined_gu(0), underwater(0), kbd_text_mode(0), univ_stencil_shadows(1), use_waypoint_app_spots(0), enable_tiled_mesh_ao(0), tiled_terrain_only(0);
bool show_lightning(0), disable_shader_effects(0), use_waypoints(0), group_back_face_cull(0), start_maximized(0), claim_planet(0), skip_light_vis_test(0);
bool no_smoke_over_mesh(0), enable_model3d_tex_comp(0), global_lighting_update(0), lighting_update_offline(0), mesh_difuse_tex_comp(1), smoke_dlights(0), keep_keycards_on_death(0);
bool texture_alpha_in_red_comp(0), use_model3d_tex_mipmaps(1), mt_cobj_tree_build(0), two_sided_lighting(0), inf_terrain_scenery(1), invert_model_nmap_bscale(0);
bool gen_tree_roots(1), fast_water_reflect(0), vsync_enabled(0), use_voxel_cobjs(0), disable_sound(0), enable_depth_clamp(0), volume_lighting(0), no_subdiv_model(0);
bool detail_normal_map(0), init_core_context(0), use_core_context(0), enable_multisample(1), dynamic_smap_bias(0), model3d_wn_normal(0), snow_shadows(0), user_action_key(0);
bool enable_dlight_shadows(1), tree_indir_lighting(0), ctrl_key_pressed(0), only_pine_palm_trees(0), enable_gamma_correct(0), use_z_prepass(0), reflect_dodgeballs(0);
bool store_cobj_accum_lighting_as_blocked(0), all_model3d_ref_update(0), begin_motion(0), enable_mouse_look(MOUSE_LOOK_DEF), enable_init_shields(1), tt_triplanar_tex(0);
bool enable_model3d_bump_maps(1), use_obj_file_bump_grayscale(1), invert_bump_maps(0), use_interior_cube_map_refl(0), enable_cube_map_bump_maps(1), no_store_model_textures_in_memory(0);
bool enable_model3d_custom_mipmaps(1), flatten_tt_mesh_under_models(0), smileys_chase_player(0), disable_fire_delay(0), disable_recoil(0), mesh_size_locked(0);
bool enable_dpart_shadows(0), enable_tt_model_reflect(1), enable_tt_model_indir(0), auto_calc_tt_model_zvals(0), use_model_lod_blocks(0), enable_translocator(0), enable_grass_fire(0);
bool disable_model_textures(0), start_in_inf_terrain(0), allow_shader_invariants(1), config_unlimited_weapons(0), disable_tt_water_reflect(0), allow_model3d_quads(1);
bool enable_timing_profiler(0), fast_transparent_spheres(0), force_ref_cmap_update(0), use_instanced_pine_trees(0), enable_postproc_recolor(0), draw_building_interiors(0);
bool toggle_room_light(0), teleport_to_screenshot(0), merge_model_objects(0), reverse_3ds_vert_winding_order(1), disable_dlights(0), voxel_add_remove(0), enable_ground_csm(0);
bool enable_hcopter_shadows(0), pre_load_full_tiled_terrain(0), disable_blood(0), enable_model_animations(1), rotate_trees(0), invert_model3d_faces(0), play_gameplay_alert(1);
bool player_custom_start_pos(0);
int xoff(0), yoff(0), xoff2(0), yoff2(0), rand_gen_index(0), mesh_rgen_index(0), camera_change(1), camera_in_air(0), auto_time_adv(0);
int animate(1), animate2(1), draw_model(0), init_x(STARTING_INIT_X), fire_key(0), do_run(0), init_num_balls(-1), change_wmode_frame(0);
int game_mode(0), map_mode(0), load_hmv(0), load_coll_objs(1), read_landscape(0), screen_reset(0), mesh_seed(0), rgen_seed(1);
int display_framerate(1), init_resize(1), temp_change(0), is_cloudy(0), recreated(1), cloud_model(0), force_tree_class(-1);
int invert_mh_image(0), voxel_editing(0), min_time(0), show_framerate(0), preproc_cube_cobjs(0), use_voxel_rocks(2);
int camera_view(0), camera_reset(1), camera_mode(0), camera_surf_collide(1), camera_coll_smooth(0), use_smoke_for_fog(0);
int window_width(512), window_height(512), map_color(1); // window dimensions, etc.
int border_height(20), border_width(4), world_mode(START_MODE), display_mode(INIT_DMODE), do_read_mesh(0);
int last_mouse_x(0), last_mouse_y(0), m_button(0), mouse_state(1), maximized(0), fullscreen(0), verbose_mode(0), leaf_color_changed(0);
int do_zoom(0), disable_universe(0), disable_inf_terrain(0), precip_mode(0), building_action_key(0);
int num_trees(0), num_smileys(1), srand_param(3), left_handed(0), mesh_scale_change(0);
int pause_frame(0), show_fog(0), spectate(0), b2down(0), free_for_all(0), teams(2), show_scores(0), universe_only(0);
int reset_timing(0), read_heightmap(0), default_ground_tex(-1), num_dodgeballs(1), INIT_DISABLE_WATER, ground_effects_level(2);
int enable_fsource(0), run_forward(0), advanced(0), dynamic_mesh_scroll(0), default_anim_id(-1), stats_display_mode(0);
int read_snow_file(0), write_snow_file(0), mesh_detail_tex(NOISE_TEX);
int read_light_files[NUM_LIGHTING_TYPES] = {0}, write_light_files[NUM_LIGHTING_TYPES] = {0};
unsigned num_snowflakes(0), create_voxel_landscape(0), hmap_filter_width(0), num_dynam_parts(100), snow_coverage_resolution(2), show_map_view_fractal(0);
unsigned num_birds_per_tile(2), num_fish_per_tile(15), num_bflies_per_tile(4);
unsigned erosion_iters(0), erosion_iters_tt(0), skybox_tid(0), tiled_terrain_gen_heightmap_sz(0), game_mode_disable_mask(0), num_frame_draw_calls(0);
float NEAR_CLIP(DEF_NEAR_CLIP), FAR_CLIP(DEF_FAR_CLIP), system_max_orbit(1.0), sky_occlude_scale(0.0), tree_slope_thresh(5.0), mouse_sensitivity(1.0), tt_grass_scale_factor(1.0);
float water_plane_z(0.0), base_gravity(1.0), crater_depth(1.0), crater_radius(1.0), disabled_mesh_z(FAR_CLIP), vegetation(1.0), atmosphere(1.0), biome_x_offset(0.0);
float mesh_file_scale(1.0), mesh_file_tz(0.0), speed_mult(1.0), mesh_z_cutoff(-FAR_CLIP), relh_adj_tex(0.0), dodgeball_metalness(1.0), ray_step_size_mult(1.0);
float water_h_off(0.0), water_h_off_rel(0.0), perspective_fovy(0.0), perspective_nclip(0.0), read_mesh_zmm(0.0), indir_light_exp(1.0), cloud_height_offset(0.0);
float snow_depth(0.0), snow_random(0.0), cobj_z_bias(DEF_Z_BIAS), init_temperature(DEF_TEMPERATURE), indir_vert_offset(0.25), sm_tree_density(1.0), fog_dist_scale(1.0);
float CAMERA_RADIUS(DEF_CAMERA_RADIUS), C_STEP_HEIGHT(0.6), waypoint_sz_thresh(1.0), model3d_alpha_thresh(0.9), model3d_texture_anisotropy(1.0), dist_to_fire_sq(0.0);
float ocean_wave_height(DEF_OCEAN_WAVE_HEIGHT), tree_density_thresh(0.55), model_auto_tc_scale(0.0), model_triplanar_tc_scale(0.0), precip_dist_scale(1.0);
float custom_glaciate_exp(0.0), tree_type_rand_zone(0.0), jump_height(1.0), force_czmin(0.0), force_czmax(0.0), smap_thresh_scale(1.0), dlight_intensity_scale(1.0);
float model_mat_lod_thresh(5.0), clouds_per_tile(0.5), def_atmosphere(1.0), def_vegetation(1.0), ocean_depth_opacity_mult(1.0), erode_amount(1.0), ambient_scale(1.0);
float model_hemi_lighting_scale(0.5), pine_tree_radius_scale(1.0), sunlight_brightness(1.0), moonlight_brightness(1.0), sm_tree_scale(1.0), tt_fog_density(1.0);
float mouse_smooth_factor(0.0), tree_depth_scale(1.0);
float light_int_scale[NUM_LIGHTING_TYPES] = {1.0, 1.0, 1.0, 1.0, 1.0}, first_ray_weight[NUM_LIGHTING_TYPES] = {1.0, 1.0, 1.0, 1.0, 1.0};
double camera_zh(0.0);
point mesh_origin(all_zeros), camera_pos(all_zeros), cube_map_center(all_zeros);
string user_text, cobjs_out_fn, sphere_materials_fn, hmap_out_fn, skybox_cube_map_name, coll_damage_name, assimp_alpha_exclude_str;
colorRGB ambient_lighting_scale(1,1,1), mesh_color_scale(1,1,1);
colorRGBA flower_color(ALPHA0);
set<unsigned char> keys, keyset;
unsigned init_item_counts[] = {2, 2, 2, 6, 6}; // HEALTH, SHIELD, POWERUP, WEAPON, AMMO
vector<cube_t> smoke_bounds;
// camera variables
double c_radius(DEF_CRADIUS), c_theta(DEF_CTHETA), c_phi(DEF_CPHI), up_theta(DEF_UPTHETA), camera_y(DEF_CAMY);
float sun_rot(0.2), moon_rot(-0.2), sun_theta(1.2), moon_theta(0.3), light_factor, ball_velocity(15.0), cview_radius(1.0), player_speed(1.0);
vector3d up_vector(plus_y), cview_dir(all_zeros);
point camera_origin(all_zeros), surface_pos(all_zeros), cpos2;
char player_name[MAX_CHARS] = "Player";
bool vert_opt_flags[3] = {0}; // {enable, full_opt, verbose}
extern bool clear_landscape_vbo, use_dense_voxels, tree_4th_branches, model_calc_tan_vect, water_is_lava, use_grass_tess, def_tex_compress, ship_cube_map_reflection;
extern bool flashlight_on, player_wait_respawn, camera_in_building, player_in_tunnel;
extern int camera_flight, DISABLE_WATER, DISABLE_SCENERY, camera_invincible, onscreen_display, mesh_freq_filter, show_waypoints, last_inventory_frame;
extern int tree_coll_level, GLACIATE, UNLIMITED_WEAPONS, destroy_thresh, MAX_RUN_DIST, mesh_gen_mode, mesh_gen_shape, map_drag_x, map_drag_y, player_in_water;
extern unsigned NPTS, NRAYS, LOCAL_RAYS, GLOBAL_RAYS, DYNAMIC_RAYS, NUM_THREADS, MAX_RAY_BOUNCES, grass_density, max_unique_trees, shadow_map_sz;
extern unsigned scene_smap_vbo_invalid, spheres_mode, max_cube_map_tex_sz, DL_GRID_BS;
extern float fticks, team_damage, self_damage, player_damage, smiley_damage, smiley_speed, tree_deadness, tree_dead_prob, lm_dz_adj, nleaves_scale, flower_density, universe_ambient_scale;
extern float mesh_scale, tree_scale, mesh_height_scale, smiley_acc, hmv_scale, last_temp, grass_length, grass_width, branch_radius_scale, tree_height_scale, planet_update_rate;
extern float MESH_START_MAG, MESH_START_FREQ, MESH_MAG_MULT, MESH_FREQ_MULT, def_tex_aniso;
extern double map_x, map_y, tfticks;
extern point hmv_pos, camera_last_pos;
extern colorRGBA sunlight_color;
extern int coll_id[];
extern float tree_lod_scales[4];
extern string read_hmap_modmap_fn, write_hmap_modmap_fn, read_voxel_brush_fn, write_voxel_brush_fn, font_texture_atlas_fn;
extern vector<bbox> team_starts;
extern player_state *sstates;
extern pt_line_drawer obj_pld;
extern tree_cont_t t_trees;
extern dpart_params_t dp_params;
extern hmap_params_t hmap_params;
extern reflect_plane_selector reflect_planes;
extern reflective_cobjs_t reflective_cobjs;
// init and cleanup functions exported from other systems that are called at the beginning and end of main()
void init_keyset();
int load_config(string const &config_file);
void init_lights();
bool export_modmap(string const &filename);
void reset_planet_defaults();
void invalidate_cached_stars();
void clear_default_vao();
void create_sin_table();
void clear_sm_tree_vbos();
void clear_scenery_vbos();
void clear_asteroid_contexts();
void clear_quad_ix_buffer_context();
void clear_vbo_ring_buffer();
void free_cloud_context();
void free_universe_context();
void free_animal_context();
void setup_linear_fog(colorRGBA const &color, float fog_end);
void write_map_mode_heightmap_image();
void apply_grass_scale();
void take_screenshot_texture();
void teleport_to_map_location();
void building_gameplay_action_key(int mode, bool mouse_wheel);
float get_player_building_speed_mult();
void toggle_city_spectate_mode();
float get_tt_building_sound_gain();
// all OpenGL error handling goes through these functions
bool get_gl_error(unsigned loc_id, const char* stmt, const char* fname) {
bool had_error(0);
while (1) {
int const error(glGetError());
if (!error) break;
const GLubyte *const error_str(gluErrorString(error));
cerr << "GL Error " << error;
if (fname) {cerr << " in statement " << stmt << " file " << fname << " line " << loc_id << ": ";} // from source file
else {cerr << " at location id " << loc_id << ": ";} // from check_gl_error()
if (error_str) {cerr << error_str << "." << endl;} else {cerr << "<NULL>." << endl;}
had_error = 1;
}
if (fname) {assert(!had_error);} // caller ignores return code in this case, add the assert here
return had_error;
}
bool check_gl_error(unsigned loc_id) {
bool had_error(0);
#ifdef _DEBUG
had_error = get_gl_error(loc_id);
assert(!had_error); // currently fatal
#endif
return had_error;
}
void display_window_resized() {invalidate_cached_stars();}
void post_window_redisplay () {glutPostRedisplay();} // Schedule a new display event
void clear_context() { // free all textures, shaders, VBOs, etc.; used on context switch and at shutdown
reset_textures();
free_universe_context();
free_model_context();
free_voxel_context();
free_sphere_vbos();
clear_shaders();
reset_snow_vbos();
update_grass_vbos();
update_tiled_terrain_grass_vbos();
clear_tree_context();
clear_sm_tree_vbos();
clear_scenery_vbos();
reset_tiled_terrain_state();
free_cobj_draw_group_vbos();
clear_univ_obj_contexts();
clear_asteroid_contexts();
clear_quad_ix_buffer_context();
clear_vbo_ring_buffer();
clear_default_vao();
free_cloud_context();
free_animal_context();
reflective_cobjs.free_textures();
clear_landscape_vbo_now();
clear_building_vbos();
free_city_context();
}
void quit_3dworld() { // called once at the end for proper cleanup
cout << "quitting" << endl;
kill_current_raytrace_threads();
end_building_rt_job();
clear_context();
exit_openal();
if (!universe_only) {
free_models();
free_scenery_cobjs();
delete_matrices();
}
glutExit();
exit(0); // quit
}
int get_swap_interval() {return (vsync_enabled ? 1 : 0);}
#ifdef _WIN32
void set_vsync() {wglSwapIntervalEXT(get_swap_interval());}
#else // linux
void set_vsync() {
//has_extension("GLX_EXT_swap_control")
if (glXSwapIntervalEXT) {glXSwapIntervalEXT(glXGetCurrentDisplay(), glXGetCurrentDrawable(), get_swap_interval());}
else if (glXSwapIntervalSGI) {glXSwapIntervalSGI(get_swap_interval());}
}
#endif
void init_window() { // register all glut callbacks
set_vsync();
glutSetCursor(GLUT_CURSOR_CROSSHAIR);
glutDisplayFunc(display);
glutReshapeFunc(resize);
//glutCloseFunc(quit_3dworld); // can't do this because we don't want to quit when destroying the context
// init keyboard and mouse callbacks
glutIgnoreKeyRepeat(1);
glutMouseFunc(mouseButton);
glutMotionFunc(mouseMotion);
glutPassiveMotionFunc(mousePassiveMotion);
glutKeyboardFunc(keyboard);
glutSpecialFunc(keyboard2);
glutKeyboardUpFunc(keyboard_up);
glutSpecialUpFunc(keyboard2_up);
init_keyset();
// Initialize GL
fgMatrixMode(FG_PROJECTION);
fgLoadIdentity();
glClearColor(0.0, 0.0, 0.0, 0.0);
}
void toggle_fullscreen() {
static int xsz(window_width), ysz(window_height);
if (!fullscreen) { // make fullscreen
if (window_width > 0) {xsz = window_width;}
if (window_height > 0) {ysz = window_height;}
glutFullScreen();
glutSetCursor(GLUT_CURSOR_NONE);
}
else { // make windowed
glutReshapeWindow(xsz, ysz);
resize(xsz, ysz);
glutSetCursor(GLUT_CURSOR_CROSSHAIR);
}
screen_reset = 1;
fullscreen ^= 1;
}
void enable_blend () {glEnable (GL_BLEND);}
void disable_blend() {glDisable(GL_BLEND);}
void set_std_blend_mode () {glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);}
void set_additive_blend_mode() {glBlendFunc(GL_SRC_ALPHA, GL_ONE);}
void reset_fog() {
setup_linear_fog(GRAY, ((world_mode == WMODE_INF_TERRAIN) ? get_inf_terrain_fog_dist() : 2.5*Z_SCENE_SIZE*fog_dist_scale));
}
void set_std_depth_func () {glDepthFunc(GL_LESS );}
void set_std_depth_func_with_eq() {glDepthFunc(GL_LEQUAL);}
void set_gl_params() {
reset_fog();
set_std_depth_func();
set_std_blend_mode();
glEnable(GL_DEPTH_TEST);
}
void reset_camera_pos() {
if (world_mode == WMODE_UNIVERSE) return;
camera_origin = mesh_origin;
up_theta = DEF_UPTHETA;
c_radius = DEF_CRADIUS;
c_theta = DEF_CTHETA;
c_phi = DEF_CPHI;
camera_y = DEF_CAMY;
if (world_mode == WMODE_UNIVERSE) camera_origin.z = zcenter;
if (enable_mouse_look) {m_button = GLUT_LEFT_BUTTON;}
}
void set_perspective_near_far(float near_clip, float far_clip, float aspect_ratio) {
if (window_width == 0) return; // window not setup yet, skip (maybe got here during mouse/keyboard even before display() was called or config was read)
assert(window_width > 0 && window_height > 0);
perspective_nclip = near_clip;
fgMatrixMode(FG_PROJECTION);
fgLoadIdentity();
fgPerspective(perspective_fovy, ((aspect_ratio == 0.0) ? ((double)window_width)/window_height : aspect_ratio), perspective_nclip, far_clip);
fgMatrixMode(FG_MODELVIEW);
fgLoadIdentity();
}
void set_perspective(float fovy, float nc_scale) {
perspective_fovy = fovy;
set_perspective_near_far(nc_scale*NEAR_CLIP, FAR_CLIP);
}
void check_zoom() {
float fovy(PERSP_ANGLE);
if (do_zoom == 1) {do_zoom = 2; fovy /= ZOOM_FACTOR;}
else if (do_zoom == 2) {do_zoom = 1;}
set_perspective(fovy, 1.0);
}
void check_xy_offsets() {
if (camera_view) return;
int const mrd(((world_mode == WMODE_INF_TERRAIN) ? 4 : 1)*MAX_RUN_DIST); // increase distance in TT mode to reduce shadow map updates
vector3d delta;
while (xoff >= mrd) {xoff -= mrd; delta.x -= mrd*DX_VAL;}
while (xoff <= -mrd) {xoff += mrd; delta.x += mrd*DX_VAL;}
while (yoff >= mrd) {yoff -= mrd; delta.y -= mrd*DY_VAL;}
while (yoff <= -mrd) {yoff += mrd; delta.y += mrd*DY_VAL;}
surface_pos += delta;
camera_last_pos += delta;
}
float get_player_speed_mult() {return pow(3.0f, min(((world_mode == WMODE_INF_TERRAIN) ? 3 : 2), do_run));}
float calc_speed() {
float speed(get_player_speed_mult());
if (camera_in_air) {speed *= CAMERA_AIR_CONT;} // what about smileys?
return speed;
}
vector3d calc_camera_direction() {return -rtp_to_xyz(1.0, c_theta, c_phi);}
void update_cpos() {
if (world_mode != WMODE_UNIVERSE) {
if (fabs(c_phi) < 0.001 || fabs(c_phi - PI) < 0.001 || fabs(c_phi - TWO_PI) < 0.001) c_phi += 0.01;
if (!spectate) {cview_dir = calc_camera_direction();} // spherical coordinates
cview_radius = c_radius;
}
camera_pos = camera_origin;
if (world_mode != WMODE_UNIVERSE) {camera_pos -= vector3d_d(cview_dir)*double(cview_radius);}
}
void calc_theta_phi_from_cview_dir() {
c_phi = acosf(-cview_dir.z);
c_theta = atan2(-cview_dir.y, -cview_dir.x);
}
void set_camera_pos_dir(point const &pos, vector3d const &dir) {
//camera_pos = pos // no, can't change this mid-frame
surface_pos = pos;
cview_dir = dir.get_norm();
calc_theta_phi_from_cview_dir();
}
void move_camera_pos_xy(vector3d const &v, float dist) {
// called when the player moves in both ground and TT modes; checks for XY collisions that block movement
// normal ground movement - should speed depend on orientation or not?
if (world_mode == WMODE_INF_TERRAIN) {dist *= get_player_building_speed_mult();}
static float prev_camera_zval(surface_pos.z); // required for walking on bridges to determine if camera is on or below the bridge
point const prev(surface_pos);
float const xy_scale(dist*(v.mag()/v.xy_mag()));
surface_pos.x += xy_scale*v.x;
surface_pos.y += xy_scale*v.y;
if (world_mode == WMODE_INF_TERRAIN) {check_legal_movement_using_model_coll(prev, surface_pos, CAMERA_RADIUS);} // collision with models
bool const include_cars = 1;
proc_city_sphere_coll(surface_pos, prev, CAMERA_RADIUS, prev_camera_zval, include_cars, nullptr, 1); // use prev pos for building collisions; check_interior=1
prev_camera_zval = surface_pos.z;
}
void move_camera_pos(vector3d const &v, float dist) { // remember that dist is negative
if (dist == 0.0) return;
if (!camera_surf_collide || camera_flight) {surface_pos += v*dist;}
else {move_camera_pos_xy(v, dist);}
}
float get_player_move_dist() {return fticks*speed_mult*player_speed*GROUND_SPEED*calc_speed();}
void advance_camera(int dir) { // player movement processing
advanced = 1;
if (world_mode == WMODE_UNIVERSE) { // universe
bool const hyperspeed(do_run == 2);
if (player_ship_inited()) {player_ship().thrust(dir, speed_mult, hyperspeed);}
return;
}
if (camera_mode != 1 || (map_mode && world_mode != WMODE_INF_TERRAIN)) return;
if (world_mode == WMODE_INF_TERRAIN && player_wait_respawn) return; // can't move during respawn
vector3d v;
float dist(get_player_move_dist());
if (game_mode && sstates != NULL) {
if (sstates[CAMERA_ID].freeze_time > 0) return; // can't move
dist *= sstates[CAMERA_ID].get_rspeed_scale();
}
// Note: the player can hold down both forward and sidestep keys at the same time and move diagonally a bit faster than they can move using forward alone;
// while I'm sure it's possible to fix this by tracking which keys are held down each frame, I've gotten used to it, and it doesn't affect gameplay much
switch (dir) {
case MOVE_BACK: // backward
dist = -dist;
dist *= BACKWARD_SPEED; // slower backwards
case MOVE_FRONT: // forward
move_camera_pos(cview_dir, dist);
break;
case MOVE_RIGHT:
dist = -dist;
case MOVE_LEFT:
dist *= SIDESTEP_SPEED;
cross_product(up_vector, cview_dir, v);
move_camera_pos(v, dist);
break;
default: assert(0);
}
}
void change_terrain_zoom(float val) {
if (!(display_mode & 0x01)) { // mesh not enabled - only scale trees
tree_scale /= val;
regen_trees(0);
build_cobj_tree();
clear_tiled_terrain();
}
else {
last_temp = -100.0; // force update
camera_change = 1;
mesh_scale_change = 1;
update_mesh(val, 1);
clear_tiled_terrain();
calc_watershed();
}
scene_smap_vbo_invalid = 2; // full rebuild of shadowers
}
void change_world_mode() { // switch terrain mode: 0 = normal/ground, 1 = universe, 2 = tiled terrain
if (map_mode || universe_only || tiled_terrain_only || (disable_universe && disable_inf_terrain)) return;
static int xoff_(0), yoff_(0), xoff2_(0), yoff2_(0);
static point camera_pos_(all_zeros);
last_temp = -100.0; // force update
if (world_mode == WMODE_UNIVERSE) { // restore saved parameters and recalculate sun and moon pos
xoff = xoff_; yoff = yoff_; xoff2 = xoff2_; yoff2 = yoff2_;
camera_pos = camera_pos_;
//up_vector = get_player_up(); // doesn't work - need to set up_theta
//cview_dir = get_player_dir(); // doesn't work - need to set c_theta, c_phi
update_sun_and_moon();
}
else if (world_mode == WMODE_INF_TERRAIN) {
c_radius = 2.5;
}
do {
world_mode = (world_mode+1)%NUM_WMODE;
} while ((disable_universe && world_mode == WMODE_UNIVERSE) || (disable_inf_terrain && world_mode == WMODE_INF_TERRAIN));
if (world_mode == WMODE_UNIVERSE) { // save camera position parameters
xoff_ = xoff; yoff_ = yoff; xoff2_ = xoff2; yoff2_ = yoff2;
camera_pos_ = camera_pos; // fix_player_upv()?
}
else if (combined_gu) {
setup_current_system();
}
if (!map_mode) {reset_offsets();} // ???
init_x = 1;
camera_change = 1;
if (world_mode == WMODE_GROUND || world_mode == WMODE_INF_TERRAIN) {apply_grass_scale();}
reset_fog();
clear_tiled_terrain();
update_grass_vbos();
clear_vbo_ring_buffer();
obj_pld.free_mem();
invalidate_cached_stars();
clear_dynamic_lights();
glDrawBuffer(GL_BACK);
post_window_redisplay();
if (world_mode == WMODE_GROUND && combined_gu) {regen_trees(0);}
change_wmode_frame = frame_counter;
}
void update_sound_loops() {
bool const universe(world_mode == WMODE_UNIVERSE);
float const fire_gain(0.1/dist_to_fire_sq), rain_wind_volume(get_tt_building_sound_gain());
if (player_in_tunnel) {set_sound_loop_state(SOUND_LOOP_RAIN, 1, 0.5);} // light rain sound in tunnel
else {set_sound_loop_state(SOUND_LOOP_RAIN, (!universe && rain_wind_volume > 0.0 && is_rain_enabled()), rain_wind_volume);}
set_sound_loop_state(SOUND_LOOP_WIND, (!universe && rain_wind_volume > 0.0 && wind.mag() >= 1.0), rain_wind_volume);
set_sound_loop_state(SOUND_LOOP_FIRE, (!universe && dist_to_fire_sq > 0.0 && dist_to_fire_sq < 2.0), fire_gain);
set_sound_loop_state(SOUND_LOOP_UNDERWATER, (!universe && (underwater || player_in_water == 2) && frame_counter > change_wmode_frame+1));
dist_to_fire_sq = 0.0;
proc_delayed_and_placed_sounds();
}
void switch_weapon(bool prev, bool mouse_wheel) {
if (world_mode == WMODE_UNIVERSE) {player_ship().switch_weapon(prev);} else {switch_player_weapon((prev ? -1 : 1), mouse_wheel);}
}
// *** Begin glut callback functions ***
// This function is called whenever the window is resized.
// Parameters are the new dimentions of the window
void resize(int x, int y) {
if (init_resize) {init_resize = 0;}
else {add_uevent_resize(x, y);}
y = y & (~1); // make sure y is even (required for video encoding)
x = x & (~1); // make sure x is even (required for video encoding)
glViewport(0, 0, x, y);
window_width = x;
window_height = y;
set_perspective(PERSP_ANGLE, 1.0);
set_gl_params();
post_window_redisplay();
display_window_resized();
}
bool is_shift_key_pressed() {return ((glutGetModifiers() & GLUT_ACTIVE_SHIFT) != 0);}
bool is_ctrl_key_pressed () {return ((glutGetModifiers() & GLUT_ACTIVE_CTRL ) != 0);} // used for universe mode query and building gample crouch
bool is_alt_key_pressed () {return ((glutGetModifiers() & GLUT_ACTIVE_ALT ) != 0);}
void update_ctrl_key_pressed() {ctrl_key_pressed = is_ctrl_key_pressed();}
void update_key_ignore_ctrl(unsigned char &key) {
if (is_ctrl_key_pressed()) {key ^= 96;} // control key modifier changes key code
}
struct player_height_mgr_t {
double cur_height = 0.0;
bool inited = 0;
void next_frame() {
if (!inited) {cur_height = camera_zh; inited = 1;} // start at full height
float adj_val(0.0);
if (player_wait_respawn) { // player is on the floor if waiting for respawn
if (cur_height == 0) return; // already fully down
adj_val = -0.5;
}
else if (ctrl_key_pressed) { // crouch
if (cur_height == 0) return; // already fully down
adj_val = -1.0;
}
else { // uncrouch
if (cur_height == camera_zh) return; // already fully up
adj_val = 1.0;
}
cur_height += adj_val*camera_zh*5.0*(fticks/TICKS_PER_SECOND); // 200ms for complete transition
cur_height = max(0.25*camera_zh, min(camera_zh, cur_height)); // clamp to valid range, 25% to 100% height
}
};
player_height_mgr_t player_height_mgr;
double get_player_height() {return player_height_mgr.cur_height;} // control key = crouch
float get_crouch_amt () {return (1.0 - get_player_height()/camera_zh)/0.75;}
void force_player_height(double height) {assert(height >= 0.0); player_height_mgr.cur_height = height;} // for building attic forced crouch
// This function is called whenever the mouse is pressed or released
// button is a number 0 to 2 designating the button
// state is 1 for release 0 for press event
// x and y are the location of the mouse (in window-relative coordinates)
void mouseButton(int button, int state, int x, int y) {
bool const fire_button(!map_mode && (button == GLUT_RIGHT_BUTTON || (enable_mouse_look && button == GLUT_LEFT_BUTTON)));
add_uevent_mbutton(button, state, x, y);
if (ui_intercept_mouse(button, state, x, y, 1)) return; // already handled
if ((camera_mode == 1 || world_mode == WMODE_UNIVERSE) && fire_button) {
b2down = !state;
return;
}
m_button = button;
last_mouse_x = x;
last_mouse_y = y;
mouse_state = state;
if (button == GLUT_MIDDLE_BUTTON && state == 0) {user_action_key = 1;}
if (state == 0) { // use mouse scroll wheel to switch weapons and zoom in/out in map mode
if (button == 3) { // mouse wheel up
if (map_mode) {map_zoom /= 1.2;}
else {switch_weapon(0, 1);}
}
else if (button == 4) { // mouse wheel down
if (map_mode) {map_zoom *= 1.2;}
else {switch_weapon(1, 1);}
}
}
}
void clamp_and_scale_mouse_delta(int &delta, int dmax) {
delta = min(dmax, max(-dmax, delta));
if (abs(delta) > 1) {delta = round_fp(mouse_sensitivity*delta);} // don't round +/-1 down to 0
}
void update_mouse_pos(int dx, int dy) {
if (animate && mouse_smooth_factor > 0.0) { // mouse smoothing
// Note: this doesn't work well because it's only run when the mouse moves rather than every frame
static float prev_tfticks(0.0);
static float prev_dx(0), prev_dy(0);
if (dx == 0 && dy == 0 && tfticks == prev_tfticks) return; // same frame, no change
float const elapsed_time(tfticks - prev_tfticks), blend(min(1.0f*elapsed_time/mouse_smooth_factor, 1.0f));
prev_dx = blend*dx + (1.0 - blend)*prev_dx;
prev_dy = blend*dy + (1.0 - blend)*prev_dy;
int const new_dx(round_fp(prev_dx)), new_dy(round_fp(prev_dy));
if (new_dx != 0) {dx = new_dx;} else if (dx != 0) {dx = ((dx < 0) ? -1 : 1);}
if (new_dy != 0) {dy = new_dy;} else if (dy != 0) {dy = ((dy < 0) ? -1 : 1);}
prev_tfticks = tfticks;
}
int button(m_button);
if (camera_mode == 1 && enable_mouse_look && !map_mode) {button = GLUT_LEFT_BUTTON;}
switch (button) {
case GLUT_LEFT_BUTTON: // h: longitude, v: latitude
if (dx == 0 && dy == 0) break;
if (world_mode == WMODE_UNIVERSE) {
vector3d delta(dx, dy, 0.0); // mouse delta
delta *= (1280.0/window_width); // ???
if (player_ship_inited()) {player_ship().turn(delta);}
update_cpos();
}
else if (map_mode) { // map mode click and drag
if (mouse_state == 0) {map_drag_x -= dx; map_drag_y += dy;} // mouse down
}
else { // ground mode
float c_phi2(c_phi - double(MOUSE_ANG_ADJ)*dy);
if (camera_mode) {c_phi2 = max(0.01f, min((float)PI-0.01f, c_phi2));} // walking on ground
if (dy > 0) { // change camera y direction when camera moved through poles and jump over poles (x=0,z=0) to eliminate "singularity"
if (c_phi2 < 0.0 || (c_phi > PI && c_phi2 < PI)) {camera_y *= -1.0;}
if (fabs(c_phi2) < MA_TOLERANCE || fabs(c_phi2 - PI) < MA_TOLERANCE) {++dy;}
}
else if (dy < 0) {
if (c_phi2 > TWO_PI || (c_phi < PI && c_phi2 > PI)) {camera_y *= -1.0;}
if (fabs(c_phi2 - TWO_PI) < MA_TOLERANCE || fabs(c_phi2 - PI) < MA_TOLERANCE) {--dy;}
}
c_theta -= double(MOUSE_ANG_ADJ)*dx*camera_y;
c_theta = fix_angle(c_theta);
c_phi = fix_angle(c_phi2);
update_cpos();
}
break;
case GLUT_MIDDLE_BUTTON: // translate camera
if (!camera_view) {
camera_origin.x += MOUSE_TRAN_ADJ*dy;
camera_origin.y += MOUSE_TRAN_ADJ*dx;
}
// Note: could use the middle button to move the sun/moon, etc.
break;
case GLUT_RIGHT_BUTTON: // v: radius, h: up_vector
if (map_mode) { // map scroll
if (dy < 0) {map_zoom /= (1.0 - 0.01*dy);}
else if (dy > 0) {map_zoom *= (1.0 + 0.01*dy);}
break;
}
if (camera_mode == 1) break; // not free look mode
if (!camera_view) {
up_theta += double(MOUSE_ANG_ADJ)*dx;
up_theta = fix_angle(up_theta);
c_radius = c_radius*(1.0 + double(MOUSE_R_ADJ)*dy);
if (c_radius <= 0.05*MOUSE_R_ADJ) {c_radius = 0.05*MOUSE_R_ADJ;}
update_cpos();
}
break;
default: // is there any other mouse button? error?
break;
}
}
// This function is called whenever the mouse is moved with a mouse button held down.
// x and y are the location of the mouse (in window-relative coordinates)
void mouseMotion(int x, int y) {
if (screen_reset || start_maximized) {
last_mouse_x = x;
last_mouse_y = y;
screen_reset = 0;
return;
}
add_uevent_mmotion(x, y);
if (ui_intercept_mouse(0, 0, x, y, 0)) return; // already handled
int dx(x - last_mouse_x), dy(y - last_mouse_y);
clamp_and_scale_mouse_delta(dx, window_width /20); // limit to a reasonable delta in case the frame rate is very low
clamp_and_scale_mouse_delta(dy, window_height/20);
update_mouse_pos(dx, dy);
last_mouse_x = x;
last_mouse_y = y;
if (enable_mouse_look) { // wrap the pointer when it goes off screen
if (x == 0) {
glutWarpPointer(window_width-2, y);
last_mouse_x = window_width-2;
}
if (x >= window_width-1) {
glutWarpPointer(1, y);
last_mouse_x = 1;
}
if (y == 0) {
glutWarpPointer(x, window_height-2);
last_mouse_y = window_height-2;
}
if (y >= window_height-1) {
glutWarpPointer(x, 1);
last_mouse_y = 1;
}
}
if (dx != 0 || dy != 0) {post_window_redisplay();}
}
void mousePassiveMotion(int x, int y) {
if (enable_mouse_look) {mouseMotion(x, y);}
}
void change_tree_mode() {
if (world_mode != WMODE_GROUND && world_mode != WMODE_INF_TERRAIN) return;
if (num_trees == 0 && t_trees.empty()) return;
tree_mode = (tree_mode+1)%4; // 0=none, 1=large, 2=small, 3=large+small
if (world_mode == WMODE_INF_TERRAIN) {
clear_tiled_terrain(1); // no_regen_buildings=1
}
else {
//if (num_trees == 0) return; // Note: will skip scene/cobj updates on scenes that have placed trees
#if 1
gen_scene(0, 1, 1, 0, 1); // Note: will destroy any fixed cobjs
#else
remove_small_tree_cobjs();
remove_tree_cobjs();
regen_trees(0); // Note: won't regen trees if num_trees == 0
#endif
}
}
void switch_weapon_mode() {
if (sstates == NULL || game_mode != GAME_MODE_FPS) return;
++sstates[CAMERA_ID].wmode;
sstates[CAMERA_ID].verify_wmode();
play_switch_wmode_sound();
//last_inventory_frame = frame_counter;
}
void toggle_camera_mode() {
camera_mode = (camera_mode == 0);
camera_reset = 1;
camera_change = 1;
if (camera_mode == 1) {camera_invincible = 1;} // in air (else on ground)
}
void update_precip_rate_verbose(float val) {
update_precip_rate(val);
cout << ((val > 1.0) ? "increase" : "decrease") << " precip to " << obj_groups[coll_id[PRECIP]].max_objs << endl;
}
void show_bool_option_change(string const &name, bool new_val) {
print_text_onscreen((name + (new_val ? " ON" : " OFF")), WHITE, 1.0, 1.0*TICKS_PER_SECOND);
}
void show_speed() {
ostringstream oss;
oss << "Player Speed " << get_player_speed_mult() << "x";
print_text_onscreen(oss.str(), WHITE, 1.0, 1.0*TICKS_PER_SECOND);
}
void show_text_prompt() {
print_text_onscreen("Text Prompt", WHITE, 1.0, 2.0*TICKS_PER_SECOND);
}
void print_texture_stats();
void print_shader_stats();
void show_tiled_terrain_debug_stats();
void show_frame_stats() {
print_texture_stats();
print_shader_stats();
cout << "Draw calls for frame " << frame_counter << ": " << num_frame_draw_calls << endl;
if (world_mode == WMODE_INF_TERRAIN) {show_tiled_terrain_debug_stats();}
}
void next_game_mode() {
if (world_mode == WMODE_UNIVERSE) return; // only one game mode
if ((game_mode_disable_mask & 7) == 7) return; // all game modes disabled, leave at init game mode (error?)
int const prev_game_mode(game_mode);
do {game_mode = (game_mode + 1) % 3;} while (game_mode_disable_mask & (1 << game_mode)); // select the next enabled game mode
if (game_mode != prev_game_mode) {change_game_mode();}
}
// This function is called whenever there is a keyboard input;
// key is the ASCII value of the key pressed (esc = 27, enter = 13, backspace = 8, tab = 9, del = 127);
// x and y are the location of the mouse, which generally aren't used but are part of the callback function;
// key repeat is only enabled for movement keys wasd
void keyboard_proc(unsigned char key, int x, int y) {
switch (key) { // available: sometimes O, sometimes Z
case 0x1B: // ESC key (27)
quit_3dworld();
break;
case 'Q':
reload_all_shaders();
break;
case 'A':
enable_multisample ^= 1;
show_bool_option_change("Multisample", enable_multisample);
if (!enable_multisample) {glDisable(GL_MULTISAMPLE);}
break;
case 'X': // change selected UI menu
next_selected_menu_ix();
break;
case 8: // backspace
if (world_mode == WMODE_INF_TERRAIN) {inf_terrain_undo_hmap_mod();}
else if (world_mode == WMODE_GROUND) {undo_voxel_brush();}
break;
case 'm': // toggle fullscreen mode
toggle_fullscreen();
break;
case 'r': // run mode (always move forward)
if (world_mode == WMODE_INF_TERRAIN && have_buildings()) {building_gameplay_action_key(3, 0);}
else {run_forward = !run_forward;}
break;
case 'V': // change mouse mode
enable_mouse_look = !enable_mouse_look;
break;
case 'C': // recreate mesh / add red ships
if (world_mode == WMODE_UNIVERSE) {
add_other_ships(ALIGN_RED); // red
break;
}
if (mesh_seed != 0 || read_heightmap) break;
rand_gen_index = mesh_rgen_index = rand();
gen_scene(1, (world_mode == WMODE_GROUND), 0, 0, 0);
regen_lightmap();
recreated = 1;
camera_change = 1;
break;
case 'x': // toggle auto framerate updates
animate = !animate;
if (animate) {reset_timing = 1;}
break;
case 't': // animation/physics timesteps - movement (freeze frame on objects), show star streams in universe mode
animate2 = !animate2;
show_bool_option_change("Timestep Update", animate2);
if (animate2) {reset_timing = 1;}
break;
case 'b': // begin motion animation
begin_motion = !begin_motion;
show_bool_option_change("Physics Update", begin_motion);
free_dodgeballs(1, 1);
break;
case 'y': // save eventlist
save_ueventlist();
break;
case 'k': // change drawing model for mesh (filled polygons vs. wireframe)
if (map_mode) {map_color = !map_color;} else {draw_model = !draw_model;}
break;
case 'i': // toggle autopilot / change pedestrian animation / force reflection cube map update
if (world_mode == WMODE_UNIVERSE) {toggle_autopilot();}
else if (world_mode == WMODE_INF_TERRAIN) {next_pedestrian_animation();}
else {force_ref_cmap_update ^= 1;}
break;
case 'n': // toggle fog / reset player target
if (world_mode == WMODE_UNIVERSE) {
reset_player_target();
break;
}
show_fog = !show_fog;
break;
case 'l': // enable lightning / dock fighters
if (world_mode == WMODE_UNIVERSE) {
toggle_dock_fighters();
break;
}
show_lightning = !show_lightning;
break;
case 'z': // zoom / onscreen display
if (map_mode) {map_zoom /= MAP_ZOOM;}
else if (world_mode == WMODE_UNIVERSE) {onscreen_display = !onscreen_display;}
else if (world_mode == WMODE_GROUND || world_mode == WMODE_INF_TERRAIN) {do_zoom = !do_zoom;} // Note: tiled mesh reflection is incompatible with zoom and is disabled
break;
case 'f': // print framerate and stats
show_framerate = 1;
timing_profiler_stats();
show_frame_stats();
break;
case 'g': // pause/resume playback of eventlist
show_bool_option_change("Frame Pause", !pause_frame);
pause_frame = !pause_frame;
break;