-
Notifications
You must be signed in to change notification settings - Fork 0
/
llem_code.cpp
9791 lines (6386 loc) · 199 KB
/
llem_code.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
/*
Copyright (C) 2019 BrerDawg
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//llem_code.cpp
//v1.01 2021-aug-25 //
//antialiasing is performed by drawing the scene (src image) at 4x the required size, then downsampling by 4x using a filter to create a smaller scene which is what is shown in the gui window (dest image). This produces high quality lines with negligible jaggies, however it is rather cpu intensive, so to keep the frame rate usable some techniques are used to only filter the scene where details exist and have changed. Most of the empty background is not filtered.
//The downsampling filter utilises a large number of src image pixels to create each dest image pixel, typically a 15x15 square of src pixels are convolved with the filter kernel to produce one dest pixel. The resultant dest image has a somewhat blurrier look but this is the trade off to avoid jaggies. Various filter kernels are selectable, and their widths are adjustable which allows sharper dest images, but then aliasing artifacts start to become prominent.
//The code is purely c++, no sse/simd cpu instructions are used (apart from those implemented by the compiler when it optimises), gpu hardware has not been coded for use. Therefore, there is quite a lot of room to accelerate rendering further.
#include "llem_code.h"
#define cn_deg2rad ( M_PI / 180 )
#define pi ( M_PI )
#define twopi ( M_PI * 2.0 )
#define pi2 ( M_PI / 2.0 )
#define cn_bytes_per_pixel 3
extern llem_wnd *wnd_llem;
extern int mains_font;
extern int mains_fontsize;
//fast_mgraph fgph4;
extern vector<float> fgph_vx;
extern vector<float> fgph_vy0;
extern vector<float> fgph_vy1;
extern vector<float> fgph_vy2;
extern int srate;
extern float timer_period;
//extern float audio_gain;
extern float audio_thrust_gain;
extern float audio_thrust_gain_slewed;
//extern float audio_thrust_gain_slewed_zeroed;
extern float filt_freq0;
extern float filt_q0;
extern void create_filter0();
float bounce_amp;
extern st_envlp_tag st_envlp2[];
extern void env_build_explosion_env0( int smpl_srate, bool init_as_finished );
extern void env_build_explosion_env1( int smpl_srate, bool init_as_finished );
extern void env_build_explosion_env2( int smpl_srate, bool init_as_finished );
extern int pref_allow_bounce_collision_det;
extern int pref_invert_mousewheel;
extern int pref_expertise0; //refer: 'landing_rating_speed_limit[]'
extern int pref_expertise1;
extern int pref_expertise2;
extern int pref_expertise3;
extern int pref_expertise4;
extern int pref_development_mode;
extern void cb_pref2(Fl_Widget*w, void* v);
extern void DoQuit();
extern bool mute;
float init_posy = 0; //only used for testing newtonian acceleration and displacement calcs (due to gravity)
mystr mtick_time;
mystr mdrw_time;
mystr mhandy_timer;
uint64_t draw_cnt = 0;
uint64_t draw_crosshair_cnt = 0;
int filter_calc_cnt = 0;
int filter_nonwhite_cnt = 0;
int obj_create_active = 0;
int obj_create_idx = 0; //0 is ship, 1 is ground (moonscape)
int obj_create_line_idx = 0;
bool obj_create_line_endpoint = 0;
float obj_create_line_dx, obj_create_line_dy;
extern string slast_ship_fname;
extern string slast_moonscape_fname;
extern string sship_state_fname;
string obj_create_fname = slast_ship_fname;
int dbg_0 = 0;
line_clip lineclp;
//function prototypes
void cb_menu_file( Fl_Widget *v, void *w );
void cb_menu_edit( Fl_Widget *v, void *w );
void cb_menu_highscore( Fl_Widget *v, void *w );
void cb_develope( Fl_Widget *v, void *w );
void cb_help( Fl_Widget *w, void *v);
extern void cb_bt_help( Fl_Widget *w, void *v );
extern void cb_btAbout(Fl_Widget *, void *);
extern st_envlp_tag st_envlp0[];
extern st_envlp_tag st_envlp1[];
extern st_envlp_tag st_envlp2[];
extern string slast_highscore_name;
//these MUST match 'en_line_type'
st_line_type_names_tag st_line_type_names[] =
{
"en_lt_ship :0",
"en_lt_ship_collision_det_pads_left :1",
"en_lt_ship_collision_det_pads_right :2",
"en_lt_ship_collision_det_sides :3",
"en_lt_spare4 :4",
"en_lt_spare5 :5",
"en_lt_spare6 :6",
"en_lt_spare7 :7",
"en_lt_spare8 :8",
"en_lt_spare9 :9",
"en_lt_spare10 :10",
"en_lt_spare11 :11",
"en_lt_spare12 :12",
"en_lt_ground_non_landing_pad :13",
"en_lt_ground_landing_zone_with_fuel :14",
"en_lt_ground_landing_zone_no_fuel :15",
"en_lt_ground_landing_zone_fuel_digit :16",
"en_lt_end_marker",
};
//used to detect end of enum defs
//expertise
#define cn_difficulty_options_max 5
float landing_rating_speed_limit[ cn_difficulty_options_max ] = //anything more negative (speed downwards) is a crash
{
-5.0f, //Novice Level
-4.0f, //Advanced Beginner
-2.5f, //Competent
-1.5f, //Proficient
-1.0f, //Expert
};
// !!! adj 'cn_landing_rating_mesg_max' to number of entries in 's_landing_rating[]'
#define cn_landing_rating_mesg_max 4
string s_landing_rating[ cn_landing_rating_mesg_max ]=
{
"Heavy Landing", //see 'cn_landing_rating_mesg_max'
"Average Landing",
"Good Landing",
"Great Landing",
};
//--------------------- Main Menu --------------------------
Fl_Menu_Item llem_menuitems_development[] =
{
{ "&File", 0, 0, 0, FL_SUBMENU },
{ "&New Game..", 0 , (Fl_Callback *)cb_menu_file, 0 },
// { "&Open Settings..", FL_CTRL + 'o' , (Fl_Callback *)cb_menu_file, 0 },
// { "&Save Settings..", FL_CTRL + 's' , (Fl_Callback *)cb_menu_file, 1, FL_MENU_DIVIDER },
{ "&Load Moonscape..", 0, (Fl_Callback *)cb_menu_file, 2 },
{ "E&xit", 0 , (Fl_Callback *)cb_menu_file, 3 },
{ 0 },
{ "&Edit", 0, 0, 0, FL_SUBMENU },
{ "&Preferences", 0, (Fl_Callback *)cb_menu_edit, 0 },
{ 0 },
{ "&HighScore", 0, 0, 0, FL_SUBMENU },
{ "&Show", 0, (Fl_Callback *)cb_menu_highscore, 0 },
{ 0 },
{ "&Develope", 0, 0, 0, FL_SUBMENU },
{ "&Toggle Obj Editor ('e')", 0, (Fl_Callback *)cb_develope, 0, FL_MENU_DIVIDER },
{ "&Load Ship State...('l' to repeat)", 0, (Fl_Callback *)cb_develope, 1 },
{ "&Save Ship State...", 0, (Fl_Callback *)cb_develope, 2 },
// { "&Restore Window Size...", 0, (Fl_Callback *)cb_debug, 4 },
{ 0 },
{ "&Help", 0, 0, 0, FL_SUBMENU },
{ "'help.txt'", 0 , (Fl_Callback *)cb_help, 0, FL_MENU_DIVIDER },
{ "&About", 0 , (Fl_Callback *)cb_help, 1 },
{ 0 },
{ 0 }
};
Fl_Menu_Item llem_menuitems[] =
{
{ "&File", 0, 0, 0, FL_SUBMENU },
{ "&New Game", 0 , (Fl_Callback *)cb_menu_file, 0 },
// { "&Open Settings..", FL_CTRL + 'o' , (Fl_Callback *)cb_menu_file, 0 },
// { "&Save Settings..", FL_CTRL + 's' , (Fl_Callback *)cb_menu_file, 1, FL_MENU_DIVIDER },
{ "&Load Moonscape..", 0, (Fl_Callback *)cb_menu_file, 2 },
{ "E&xit", 0 , (Fl_Callback *)cb_menu_file, 0 },
{ 0 },
{ "&Edit", 0, 0, 0, FL_SUBMENU },
{ "&Preferences", 0, (Fl_Callback *)cb_menu_edit, 0 },
{ 0 },
{ "&HighScore", 0, 0, 0, FL_SUBMENU },
{ "&Show", 0, (Fl_Callback *)cb_menu_highscore, 0 },
{ 0 },
{ "&Help", 0, 0, 0, FL_SUBMENU },
{ "'help.txt'", 0 , (Fl_Callback *)cb_help, 0, FL_MENU_DIVIDER },
{ "&About", 0 , (Fl_Callback *)cb_help, 1 },
{ 0 },
{ 0 }
};
//----------------------------------------------------------
void cb_help( Fl_Widget *w, void *v)
{
int which = (intptr_t)v;
if( which == 0 ) //help
{
cb_bt_help( w, v );
}
if( which == 1 ) //about
{
cb_btAbout(w, v );
}
}
void cb_menu_file( Fl_Widget *w, void *v )
{
string s1;
mystr m1;
int which = (intptr_t)v;
llem_wnd* ow = (llem_wnd*) w->parent();
if( which == 0 ) //new game
{
ow->init( 0 );
}
if( which == 2 ) //load moonscape
{
char *pPathName = fl_file_chooser( s1.c_str(), "*", (const char*)slast_moonscape_fname.c_str(), 0 );
if (!pPathName) return;
s1 = pPathName;
string sdesc;
if( ow->file_open_obj( ow->idx_ground, 0, 0, s1, 1, sdesc ) )
{
slast_moonscape_fname = s1;
m1 = sdesc;
m1.EscToStr();
ow->sdesc_ground = m1.szptr();
ow->ground_landing_zone_colour_and_fuel_digits();
ow->zoom_set_detent( 0 );
}
}
if( which == 3 ) //load moonscape
{
DoQuit();
}
//strpf( s1, "Open Settings is under development: '%s'", last_filename.c_str() );
//fl_alert( s1.c_str(), 0 );
}
void cb_menu_edit( Fl_Widget *w, void *v )
{
string s1;
int which = (intptr_t)v;
if( which == 0 ) //preferences
{
cb_pref2( w, v );
}
//strpf( s1, "Open Settings is under development: '%s'", last_filename.c_str() );
//fl_alert( s1.c_str(), 0 );
}
//highest(first) to lowest(last)
static int sort_highscore(const st_highscore_tag &s1, const st_highscore_tag &s2 )
{
if( s2.score > s1.score ) return 0;
return 1;
}
bool llem_wnd::file_load_highscore( string fname )
{
bool vb = 1;
mystr m1;
string s1, s2;
st_highscore_tag oh;
if(vb)printf("file_load_highscore() - reading '%s'\n", fname.c_str() );
vhighscore.clear();
oh.expertise = 0;
oh.score = 0;
oh.best_dy = -100;
oh.crashes = 0;
oh.sdate = "";
oh.sname_player = "";
oh.sname_llem = "";
oh.sdesc_llem = "";
oh.sfname_llem = "";
oh.sname_moonscape = "";
oh.sdesc_moonscape = "";
oh.sfname_moonscape = "";
vhighscore.resize( cn_highscore_entries_max, oh );
if( m1.readfile( fname, 2000 ) )
{
vector<string> vstr0, vstr1;
m1.LoadVectorStrings( vstr0, '\n' );
if( vstr0.size() == 0 ) return 0;
for( int i = 0; i < vstr0.size(); i++ )
{
m1 = vstr0[i];
if(vb)printf("file_load_highscore() -vstr0[%d] '%s'\n", i, vstr0[i].c_str() );
if( m1.LoadVectorStrings( vstr1, ',' ) )
{
if( vstr1.size() < 14 ) continue;
if(vb)printf("file_load_highscore() - vstr1.size() %d\n", vstr1.size() );
sscanf( vstr1[0].c_str(), "%d", &oh.expertise );
sscanf( vstr1[1].c_str(), "%d", &oh.score );
oh.slandings_tot = vstr1[2];
sscanf( vstr1[3].c_str(), "%f", &oh.best_dy );
sscanf( vstr1[4].c_str(), "%d", &oh.crashes );
m1 = vstr1[5];
m1.EscToStr();
oh.sdate = m1.szptr();
m1 = vstr1[6];
m1.EscToStr();
oh.stime = m1.szptr();
m1 = vstr1[7];
m1.EscToStr();
oh.sname_player = m1.szptr();
m1 = vstr1[8];
m1.EscToStr();
oh.sname_llem = m1.szptr();
m1 = vstr1[9];
m1.EscToStr();
oh.sdesc_llem = m1.szptr();
m1 = vstr1[10];
m1.EscToStr();
oh.sfname_llem = m1.szptr();
m1 = vstr1[11];
m1.EscToStr();
oh.sname_moonscape = m1.szptr();
m1 = vstr1[12];
m1.EscToStr();
oh.sdesc_moonscape = m1.szptr();
m1 = vstr1[13];
m1.EscToStr();
oh.sfname_moonscape = m1.szptr();
vhighscore[i] = oh;
}
}
}
else{
printf("file_load_highscore() - error reading '%s'\n", fname.c_str() );
return 0;
}
if( vhighscore.size() > cn_highscore_entries_max ) vhighscore.resize( cn_highscore_entries_max );
//std::stable_sort( vhighscore.begin(), vhighscore.end(), sort_highscore ); //sort vector by highscore
for( int i = 0; i < vhighscore.size(); i++ )
{
oh = vhighscore[i];
if(vb)printf("----- highscore [%03d] -----\n", i );
if(vb)printf("expertise: %02d\n", oh.expertise );
if(vb)printf("score: %05d\n", oh.score );
if(vb)printf("best_dy: %.2f\n", oh.best_dy );
if(vb)printf("crashes: %02d\n", oh.crashes );
if(vb)printf("sdate: '%s'\n", oh.sdate.c_str() );
if(vb)printf("stime: '%s'\n", oh.stime.c_str() );
if(vb)printf("sname_player: '%s'\n", oh.sname_player.c_str() );
if(vb)printf("sname_llem: '%s'\n", oh.sname_llem.c_str() );
if(vb)printf("sdesc_llem: '%s'\n", oh.sdesc_llem.c_str() );
if(vb)printf("sfname_llem: '%s'\n", oh.sfname_llem.c_str() );
if(vb)printf("sname_moonscape: '%s'\n", oh.sname_moonscape.c_str() );
if(vb)printf("sdesc_moonscape: '%s'\n", oh.sdesc_moonscape.c_str() );
if(vb)printf("sfname_moonscape: '%s'\n", oh.sfname_moonscape.c_str() );
if(vb)printf("--------------------------\n" );
}
return 1;
}
//returns index to 'vhighscore[]', if 'score' can be stored in list at or above the lowest score entry
//else returns -1
int llem_wnd::highscore_has_been_achieved( int score )
{
if( vhighscore.size() == 0 ) return 0;
for( int i = 0; i < vhighscore.size(); i++ )
{
st_highscore_tag oh = vhighscore[i];
if( score >= oh.score ) return i;
}
//if( vhighscore.size() < (cn_highscore_entries_max - 1) ) return ( vhighscore.size() ); //still unused entries in list?
return -1;
}
bool llem_wnd::file_save_highscore( string fname )
{
bool vb = 1;
mystr m1;
string s1, st;
st_highscore_tag oh;
if(vb)printf("file_save_highscore() - writing '%s'\n", fname.c_str() );
for( int i = 0; i < vhighscore.size(); i++ )
{
oh = vhighscore[i];
if( oh.score == 0 ) continue;
strpf( s1, "%d,", oh.expertise );
st += s1;
strpf( s1, "%d,", oh.score );
st += s1;
strpf( s1, "%s,", oh.slandings_tot.c_str() );
st += s1;
strpf( s1, "%.2f,", oh.best_dy );
st += s1;
strpf( s1, "%d,", oh.crashes );
st += s1;
strpf( s1, "%s,", oh.sdate.c_str() );
st += s1;
strpf( s1, "%s,", oh.stime.c_str() );
st += s1;
m1 = oh.sname_player;
m1.StrToEscMostCommon3();
strpf( s1, "%s,", m1.szptr() );
st += s1;
m1 = oh.sname_llem;
m1.StrToEscMostCommon3();
strpf( s1, "%s,", m1.szptr() );
st += s1;
m1 = oh.sdesc_llem;
m1.StrToEscMostCommon3();
strpf( s1, "%s,", m1.szptr() );
st += s1;
m1 = oh.sfname_llem;
m1.StrToEscMostCommon3();
strpf( s1, "%s,", m1.szptr() );
st += s1;
m1 = oh.sname_moonscape;
m1.StrToEscMostCommon3();
strpf( s1, "%s,", m1.szptr() );
st += s1;
m1 = oh.sdesc_moonscape;
m1.StrToEscMostCommon3();
strpf( s1, "%s,", m1.szptr() );
st += s1;
m1 = oh.sfname_moonscape;
m1.StrToEscMostCommon3();
strpf( s1, "%s", m1.szptr() ); //no ending comma
st += s1;
st += "\n";
}
m1 = st;
if( !m1.writefile( fname ) )
{
if(vb)printf("file_save_highscore() - failed writing '%s'\n", fname.c_str() );
return 0;
}
return 1;
}
void llem_wnd::file_load_ship_state( string fname )
{
mystr m1;
if( m1.readfile( fname, 2000 ) )
{
vector<string> vstr0;
m1.LoadVectorStrings( vstr0, '\n' );
if( vstr0.size() > 0 )
{
int idx = idx_ship;
vobj[idx] = st_obj_ship_copy;
sscanf( vstr0[0].c_str(), "%f %f %f %f %f %f", &vobj[idx].x, &vobj[idx].y, &vobj[idx].dx, &vobj[idx].dy, &vobj[idx].theta_detentzone, &thrust_wheel );
printf( "cb_debug() - '%s' %f %f %f %f %f %f\n", vstr0[0].c_str(), vobj[idx].x, vobj[idx].y, vobj[idx].dx, vobj[idx].dy, vobj[idx].theta_detentzone, thrust_wheel );
animate_bounce = 0;
game_state = en_gs_landing;
// set_thrust( 0.0 );
// vobj[idx].x = 267.7;
// vobj[idx].y = -457.0;
// vobj[idx].dx = 1.4;
// vobj[idx].dy = 0;
zoom_extents_goes_off = 1;
panx = vobj[idx].x;
pany = vobj[idx].y;
zoomx = zoomy = 12;
zoom_last = 0;
zoom_detent_last = 3; //set some value to cause a zoom change
zoom_holdoff_time_cnt = 0.25; //set some value to cause a zoom change
ground_landing_restore_fuel_levels();
ground_landing_zone_fuel_remove_digits();
ground_landing_zone_colour_and_fuel_digits();
// pause = 0;
scrn_regen = 1;
}
}
}
void llem_wnd::highscore_enter()
{
string s1, sname;
mystr m1;
int score0 = score;
if( !b_highscore_ask ) return;
if( score0 > 0 )
{
int idx = highscore_has_been_achieved( score0 );
printf("highscore_enter() - idx: %d\n", idx );
//getchar();
if( idx >= 0 )
{
strpf( s1, "Your score places you at position %d in Highscore list.\nEnter your name: ", idx+1 );
char *sz = fl_input( s1.c_str(), slast_highscore_name.c_str() );
if( sz != 0 )
{
slast_highscore_name = sz;
sname = sz;
// b_highscore_ask = 0;
}
else{
sname = "Anonymous";
}
st_highscore_tag oh;
struct tm tt;
m1.get_time_now( tt );
string dow, dom, mon_num, mon_name, year, year_short;
string sdate;
m1.make_date_str( tt, dow, dom, mon_num, mon_name, year, year_short );
strpf( sdate, "%s-%s-%s", year.c_str(), mon_num.c_str(), dom.c_str() );
string hrs, mins, secs, time;
m1.make_time_str( tt, hrs, mins, secs, time );
oh.expertise = expertise_level;
oh.score = score0;
strpf( s1, "%02d/%02d", landings_tot, landing_zones_avail );
oh.slandings_tot = s1;
oh.best_dy = best_dy;
oh.crashes = crashings_tot;
oh.sdate = sdate;
oh.stime = time;
oh.sname_player = sname;
oh.sname_llem = "name_llem";
oh.sdesc_llem = "desc_llem";
oh.sfname_llem = slast_ship_fname;
oh.sname_moonscape = "name_moonscape";
oh.sdesc_moonscape = "sdesc_moonscape";
oh.sfname_moonscape = slast_moonscape_fname;
vhighscore.insert( vhighscore.begin() + idx, oh );
vhighscore.resize( cn_highscore_entries_max );
}
}
//std::stable_sort( vhighscore.begin(), vhighscore.end(), sort_highscore ); //sort vector by highscore
file_save_highscore( cns_highscore_fname );
}
void cb_menu_highscore( Fl_Widget *w, void *v )
{
string s1, s2;
string sexpt;
mystr m1;
llem_wnd* ow = (llem_wnd*) w->parent();
int which = (intptr_t)v;
if( which == 0 ) //toggle obj editor
{
ow->set_pause( 1 );
string s1, st;
Fl_Window *wnd = new Fl_Window( ow->x()+20, ow->y()+20, 800, 500 );
wnd->label("High Score List");
Fl_Input *teText = new Fl_Input( 10, 10, wnd->w()-20, wnd->h()-20, "");
teText->type(FL_MULTILINE_OUTPUT);
teText->textfont(4);
teText->textsize(9);
//01 .... AdnceBeginr 001400 -1.30 1 2022-09-04 12:46:53 Will!
st = "Place Expertise Score Landings BestDy Crashes Date Time Name";
st += '\n';
st += "--------------------------------------------------------------------------------------------------";
st += '\n';
for( int i = 0; i < ow->vhighscore.size(); i++ )
{
st_highscore_tag oh = ow->vhighscore[i];
if( oh.score <= 0 ) continue;
string sline;
strpf( s1, "%02d .... ", i+1 );
sline += s1;
if( oh.expertise == 0 ) sexpt = "Novice ";
if( oh.expertise == 1 ) sexpt = "AdnceBeginr ";
if( oh.expertise == 2 ) sexpt = "Competent ";
if( oh.expertise == 3 ) sexpt = "Proficient ";
if( oh.expertise == 4 ) sexpt = "Expert ";
sline += sexpt;
strpf( s1, "%06d ", oh.score );
sline += s1;
strpf( s1, "%s ", oh.slandings_tot.c_str() );
sline += s1;
strpf( s1, "%.2f", oh.best_dy );
m1 = s1;
m1.padstr( s1, 11, 11 );
sline += s1;
strpf( s1, "%d ", oh.crashes );
sline += s1;
strpf( s1, "%s ", oh.sdate.c_str() );
sline += s1;
strpf( s1, "%s ", oh.stime.c_str() );
sline += s1;
strpf( s1, "%s", oh.sname_player.c_str() );
sline += s1;
st += sline;
st += '\n';
/*
oh.expertise = expertise_level;
oh.score = score0;
oh.sdate = s1;
strpf( s1, "%s, %s, Built: %s\n", cnsAppWndName, "v1.01", cns_build_date );
oh.stime = time;
oh.sname_player = slast_highscore_name;
oh.sname_llem = "name_llem";
oh.sdesc_llem = "desc_llem";
oh.sfname_llem = "fname_llem";
oh.sname_moonscape = "name_moonscape";
oh.sdesc_moonscape = "sdesc_moonscape";
oh.sfname_moonscape = "fname_moonscape";
vhighscore.insert( vhighscore.begin() + idx, oh );
vhighscore.resize( cn_highscore_entries_max );
*/
}
//strpf(s,"%s, v1.05, Mar 2011\n\nBasic app skeleton foundation to build onto...",cnsAppWndName);
teText->value(st.c_str());
wnd->end();
#ifndef compile_for_windows
wnd->set_modal();
#endif
wnd->show();
}
}
void cb_develope( Fl_Widget *w, void *v )
{
string s1;
llem_wnd* ow = (llem_wnd*) w->parent();
int which = (intptr_t)v;
if( which == 0 ) //toggle obj editor
{
ow->do_key( 'e', 1 );
}
if( which == 1 ) //load ship state
{
char *pPathName = fl_file_chooser( "Load Ship State ?", "*", (const char*)sship_state_fname.c_str(), 0 );
if (!pPathName) return;
sship_state_fname = pPathName;
ow->file_load_ship_state( sship_state_fname );
}
if( which == 2 ) //save ship state
{
char *pPathName = fl_file_chooser( "Save Ship State ?", "*", (const char*)sship_state_fname.c_str(), 0 );
if (!pPathName) return;
mystr m1;
bool do_write = 0;
unsigned long long int filesz;
if ( m1.filesize( pPathName, filesz ) )
{
strpf( s1, "File already exists, Overwrite it? : '%s'", pPathName );
int ret = fl_choice( s1.c_str(),"Cancel","Overwrite", 0 );
if( ret == 1 )
{
do_write = 1;
}
}
else{
do_write = 1;
}
if( do_write )
{
sship_state_fname = pPathName;
int idx = ow->idx_ship;
strpf( s1, "%f %f %f %f %f %f\n", ow->vobj[idx].x, ow->vobj[idx].y, ow->vobj[idx].dx, ow->vobj[idx].dy, ow->vobj[idx].theta_detentzone, ow->thrust_wheel );
m1 = s1;
m1.writefile( sship_state_fname );
}
}
/*
if( which == 4 ) //restore window size
{
wnd_llem->iconize();
wnd_llem->hide();
wnd_llem->show();
}
*/
//strpf( s1, "Open Settings is under development: '%s'", last_filename.c_str() );
//fl_alert( s1.c_str(), 0 );
}
/*
void plot_mgraph0_llem( float *kern0, int kern_size )
{
fgph_vx.clear();
fgph_vy0.clear();
fgph_vy1.clear();
string s1 = fgph4.label();
s1 += " - plot_mgraph0_llem() - filter kernel";
fgph4.copy_label( s1.c_str() );
fgph4.position( 10, 130 );
fgph4.scale_y( 1.0, 1.0, 1.0, 0.1 );
fgph4.shift_y( 0.0, -0.1, -0.10, -0.2 );
fgph4.font_size( 9 );
fgph4.set_sig_dig( 2 );
fgph4.sample_rect_hints_distancex = 0;
fgph4.sample_rect_hints_distancey = 0;
int cnt = kern_size;
for( int i = 0; i < cnt; i++ )
{
float f0 = sinf( (float)i/cnt * twopi * 5 );
float f1 = 0.8*sinf( (float)i/cnt * twopi * 10 );
f0 = kern0[i];
fgph_vx.push_back( i );
fgph_vy0.push_back( f0 );