forked from Francesco149/oppai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
951 lines (781 loc) · 23.7 KB
/
main.cc
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
#include "types.hh"
#include "common.hh"
// at the moment I'm not using static anywhere since it's a monolithic build
// anyways. it might be nice to have it though, for extra scope safety
// common includes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <float.h> // DBL_MAX
#include <ctype.h> // tolower/toupper
char toupper_wrapper(char c) { return (char)toupper(c); }
char tolower_wrapper(char c) { return (char)tolower(c); }
#ifndef OPPAI_LIB
#define OPPAIAPI internalfn
#define VERSION_SUFFIX
#else
// these are not thread safe so we must disable them in lib mode
#undef OPPAI_PROFILER
#undef SHOW_BEATMAP
#undef _DEBUG
#define OPPAIAPI
#define VERSION_SUFFIX "-lib"
#endif
const char* version_string = "0.9.13" VERSION_SUFFIX;
// -----------------------------------------------------------------------------
struct oppai_ctx
{
const char* last_err;
oppai_ctx() : last_err(0) {}
};
// returns the last error, or 0 if no error has occurred
OPPAIAPI
const char* oppai_err(oppai_ctx* ctx) {
return ctx->last_err;
}
// -----------------------------------------------------------------------------
// sets the last error to msg if it's not already set
#define die(ctx, msg) dbgputs(msg); die_impl(ctx, msg)
internalfn
void die_impl(oppai_ctx* ctx, const char* msg)
{
if (ctx->last_err) {
return;
}
ctx->last_err = msg;
}
#ifdef OPPAI_LIB
#define chk(ctx) \
if (oppai_err(ctx)) { \
return 1; \
}
#else
internalfn
void chk(oppai_ctx* ctx)
{
if (!oppai_err(ctx)) {
return;
}
fputs(oppai_err(ctx), stderr);
fputs("\n", stderr);
exit(1);
}
#endif
// -----------------------------------------------------------------------------
// these don't necessarily need to match the pp processor's bitmask 1:1 but
// I'll keep them consistent just because
namespace mods
{
const u32
nomod = 0,
nf = 1 << 0,
ez = 1 << 1,
hd = 1 << 3,
hr = 1 << 4,
dt = 1 << 6,
ht = 1 << 8,
nc = 1 << 9,
fl = 1 << 10,
so = 1 << 12,
speed_changing = dt | ht | nc,
map_changing = hr | ez | speed_changing;
}
const char* const mod_strs[] = {
"nomod", "nf", "ez", "hd", "hr", "dt", "ht", "nc", "fl", "so"
};
const u32 mod_masks[] = {
mods::nomod, mods::nf, mods::ez, mods::hd, mods::hr, mods::dt, mods::ht,
mods::nc, mods::fl, mods::so
};
const size_t num_mods = sizeof(mod_masks) / sizeof(mod_masks[0]);
// -----------------------------------------------------------------------------
// TODO: move this?
internalfn bool encode_str(FILE* fd, const char* str);
// this a monolithic build. stuff is separated into files purely for readability
#include "profiler.cc"
#include "math.cc"
#include "beatmap.cc"
#include "diff_calc.cc"
#include "pp_calc.cc"
// -----------------------------------------------------------------------------
#ifdef SHOW_BEATMAP
internalfn void print_beatmap(beatmap& b, oppai_ctx* ctx);
#endif
// -----------------------------------------------------------------------------
// !!!!!!!!! OVERRIDE PRINTF AND PUTS FOR OUTPUT MODULES !!!!!!!!!!
#define printf(fmt, ...) fprintf(fd, fmt, __VA_ARGS__)
#define puts(s) fputs(s "\n", fd)
#define putchar(c) fputc(c, fd)
// output modules
#define print_sig(name) \
void name( \
FILE* fd, \
char* mods_str, \
u16 combo, \
u16 misses, \
u32 scoring, \
f64 stars, \
f64 aim, \
f64 speed, \
bool has_awkwardness, \
f64 rhythm_awkwardness, \
u16 nsingles, \
u16 nsingles_timing, \
u16 nsingles_threshold, \
pp_calc_result& res, \
beatmap& b)
#define twodecimals(x) (macro_round((x) * 100.0) / 100.0)
// text output
internalfn
print_sig(text_print)
{
// round to 2 decimal places
aim = twodecimals(aim);
speed = twodecimals(speed);
stars = twodecimals(stars);
f64 pp = twodecimals(res.pp);
f64 aim_pp = twodecimals(res.aim_pp);
f64 speed_pp = twodecimals(res.speed_pp);
f64 acc_pp = twodecimals(res.acc_pp);
f64 acc_percent = twodecimals(res.acc_percent);
printf("o p p a i | v%s\n", version_string);
puts("s d n | ");
puts("u v s | (looking for");
puts("! a p | cool ascii");
puts(" n e | to put here)");
puts(" c c | ");
puts(" e t | ");
puts(" d o | ");
puts(" r |\n");
printf("\n%s - %s [%s] (%s) %s\n",
b.artist, b.title, b.version, b.creator, mods_str ? mods_str : "");
printf(
"od%g ar%g cs%g hp%g\n",
(i32)(b.od * 100.0) / 100.0,
(i32)(b.ar * 100.0) / 100.0,
(i32)(b.cs * 100.0) / 100.0,
(i32)(b.hp * 100.0) / 100.0
);
printf("%" fu16 "/%" fu16 " combo\n", combo, b.max_combo);
printf("%" fu16 " circles, %" fu16 " sliders %" fu16 " spinners\n",
b.num_circles, b.num_sliders, b.num_spinners);
printf("%" fu16 "xmiss\n", misses);
printf("%g%%\n", acc_percent);
printf("scorev%" fu32"\n\n", scoring);
printf("%g stars\naim stars: %g, speed stars: %g\n\n", stars, aim, speed);
printf("aim: %g\n", aim_pp);
printf("speed: %g\n", speed_pp);
printf("accuracy: %g\n", acc_pp);
if (has_awkwardness)
{
printf("\nrhythm awkwardness (beta): %g\n", rhythm_awkwardness);
f64 awkwardness_bonus =
std::max(1.0, std::min(1.15, std::pow(rhythm_awkwardness, 0.3)));
printf("awkwardness acc pp bonus (beta): %g\n", awkwardness_bonus);
}
// first object is ignored since it has no previous to compare with
u16 nmaxsingles = b.num_circles + b.num_sliders - 1;
printf("%" fu16 " spacing singletaps (%g%%)\n",
nsingles, (f32)nsingles / nmaxsingles * 100.0f);
printf("%" fu16 " timing singletaps (%g%%)\n",
nsingles_timing, (f32)nsingles_timing / nmaxsingles * 100.0f);
printf("%" fu16 " notes within singletap threshold (%g%%)\n",
nsingles_threshold,
(f32)nsingles_threshold / nmaxsingles * 100.0f);
printf("\n%gpp\n", pp);
}
// json output
internalfn
void print_escaped_json_string(FILE* fd, const char* str)
{
putchar('"');
const char* chars_to_escape = "\\\"";
for (; *str; ++str)
{
// escape all characters in chars_to_escape
for (const char* p = chars_to_escape; *p; ++p) {
if (*p == *str) {
putchar('\\');
}
}
putchar(*str);
}
putchar('"');
}
// https://www.doc.ic.ac.uk/%7Eeedwards/compsys/float/nan.html
bool is_inf(double b)
{
u64* p = (u64*)&b;
return *p == 0x7FF0000000000000LL ||
*p == 0xFFF0000000000000LL;
}
bool is_nan(double b)
{
u64* p = (u64*)&b;
return
(*p > 0x7FF0000000000000LL && *p < 0x8000000000000000LL) ||
(*p > 0xFFF7FFFFFFFFFFFFLL && *p <= 0xFFFFFFFFFFFFFFFFLL);
}
// json is mentally challenged and can't handle inf and nan so we/re gonna be
// mathematically incorrect
void fix_json_f64(double* v)
{
if (is_inf(*v)) {
*v = DBL_MAX;
}
if (is_nan(*v)) {
*v = 0;
}
}
internalfn
print_sig(json_print)
{
double dod = b.od;
double dar = b.ar;
double dcs = b.cs;
double dhp = b.hp;
fix_json_f64(&res.acc_percent);
fix_json_f64(&res.pp);
fix_json_f64(&res.speed_pp);
fix_json_f64(&res.acc_pp);
fix_json_f64(&stars);
fix_json_f64(&aim);
fix_json_f64(&speed);
fix_json_f64(&rhythm_awkwardness);
fix_json_f64(&dod);
fix_json_f64(&dar);
fix_json_f64(&dcs);
fix_json_f64(&dhp);
printf("%s", "{\"oppai_version\":");
print_escaped_json_string(fd, version_string);
// first print the artist, title, version and creator like this
// since json-string so " and \ needs to be escaped
printf("%s", ",\"artist\":");
print_escaped_json_string(fd, b.artist);
printf("%s", ",\"title\":");
print_escaped_json_string(fd, b.title);
printf("%s", ",\"version\":");
print_escaped_json_string(fd, b.version);
printf("%s", ",\"creator\":");
print_escaped_json_string(fd, b.creator);
// now print the rest
printf(
","
"\"mods_str\": \"%s\","
"\"od\":%g,\"ar\":%g,\"cs\":%g,\"hp\":%g,"
"\"combo\": %" fu16 ",\"max_combo\": %" fu16 ","
"\"num_circles\": %" fu16 ","
"\"num_sliders\": %" fu16 ","
"\"num_spinners\": %" fu16 ","
"\"misses\": %" fu16 ","
"\"score_version\": %" fu32 ","
"\"stars\": %.17g,\"speed_stars\": %.17g,\"aim_stars\": %.17g,",
mods_str ? mods_str : "",
(i32)(dod * 100.0) / 100.0,
(i32)(dar * 100.0) / 100.0,
(i32)(dcs * 100.0) / 100.0,
(i32)(dhp * 100.0) / 100.0,
combo, b.max_combo,
b.num_circles, b.num_sliders, b.num_spinners,
misses, scoring,
stars, speed, aim
);
if (has_awkwardness) {
printf("\"rhythm_awkwardness\": %.17g,", rhythm_awkwardness);
}
printf(
"\"nsingles\": %" fu16 ","
"\"nsingles_timing\": %" fu16 ","
"\"nsingles_threshold\": %" fu16 ","
"\"pp\":%.17g"
"}\n",
nsingles, nsingles_timing, nsingles_threshold,
res.pp
);
}
// binary output
internalfn
bool encode_str(FILE* fd, const char* str)
{
u16 len = 0xFFFF;
size_t slen = strlen(str);
if (slen < 0xFFFF) {
len = (u16)slen;
}
if (fwrite(&len, 2, 1, fd) != 1) {
perror("fwrite");
return false;
}
if (fwrite(str, 1, len, fd) != len) {
perror("fwrite");
return false;
}
return true;
}
// binary format history:
// version 2: added hp
print_sig(binary_print)
{
if (!freopen(0, "wb", fd)) {
perror("freopen");
exit(1);
}
u32 binary_output_version = 2;
// TODO: shorten this with macros
fputc('\0', fd);
fputc('\0', fd); // is_struct
fwrite(&binary_output_version, 4, 1, fd);
if (!encode_str(fd, version_string) ||
!encode_str(fd, b.artist) ||
!encode_str(fd, b.title) ||
!encode_str(fd, b.version) ||
!encode_str(fd, b.creator) ||
!encode_str(fd, mods_str ? mods_str : ""))
{
exit(1);
}
fwrite(&b.od, sizeof(f32), 1, fd);
fwrite(&b.ar, sizeof(f32), 1, fd);
fwrite(&b.cs, sizeof(f32), 1, fd);
fwrite(&b.hp, sizeof(f32), 1, fd);
fwrite(&combo, 2, 1, fd);
fwrite(&b.max_combo, 2, 1, fd);
fwrite(&b.num_circles, 2, 1, fd);
fwrite(&b.num_sliders, 2, 1, fd);
fwrite(&b.num_spinners, 2, 1, fd);
fwrite(&misses, 2, 1, fd);
fwrite(&scoring, 4, 1, fd);
f32 tmp = (f32)stars;
fwrite(&tmp, sizeof(f32), 1, fd);
tmp = (f32)speed;
fwrite(&tmp, sizeof(f32), 1, fd);
tmp = (f32)aim;
fwrite(&tmp, sizeof(f32), 1, fd);
tmp = (f32)res.pp;
fwrite(&tmp, sizeof(f32), 1, fd);
}
#ifndef __GNUC__
#pragma pack(push, 1)
#endif
// binary struct output
struct binary_output_data
{
u8 must_be_zero;
u8 is_struct;
u32 output_version;
char oppai_version[256];
char artist[256];
char title[256];
char version[256];
char creator[256];
char mods_str[256];
f32 od, ar, cs, hp;
u16 combo, max_combo;
u16 num_circles, num_sliders, num_spinners;
u16 misses;
u32 scoring;
f32 stars, speed, aim;
f32 pp;
}
#ifdef __GNUC__
__attribute__ ((aligned (1), packed));
#else
;
#pragma pack(pop)
#endif
print_sig(binary_struct_print)
{
if (!freopen(0, "wb", fd)) {
perror(0);
exit(1);
}
binary_output_data d;
memset(&d, 0, sizeof(binary_output_data));
d.is_struct = 1;
d.output_version = 1;
strcpy(d.oppai_version, version_string);
strcpy(d.artist, b.artist);
strcpy(d.title, b.title);
strcpy(d.version, b.version);
strcpy(d.creator, b.creator);
strcpy(d.mods_str, mods_str ? mods_str : "");
d.od = b.od;
d.ar = b.ar;
d.cs = b.cs;
d.hp = b.hp;
d.combo = combo;
d.max_combo = b.max_combo;
d.num_circles = b.num_circles;
d.num_sliders = b.num_sliders;
d.num_spinners = b.num_spinners;
d.misses = misses;
d.scoring = scoring;
d.stars = (f32)stars;
d.speed = (f32)speed;
d.aim = (f32)aim;
d.pp = (f32)res.pp;
fwrite(&d, sizeof(binary_output_data), 1, fd);
}
// ---
typedef print_sig(print_callback);
#undef print_sig
#undef printf
#undef puts
#undef putchar
struct output_module
{
const char* name;
print_callback* print;
};
globvar
output_module modules[] =
{
{ "text", text_print },
{ "json", json_print },
{ "binary", binary_print },
{ "binary_struct", binary_struct_print },
{ 0, 0 }
};
OPPAIAPI
output_module* get_output_modules() {
return modules;
}
OPPAIAPI
output_module* get_output_module(const char* name)
{
for (output_module* m = modules; m->name; ++m)
{
if (!strcmp(m->name, name)) {
return m;
}
}
return 0;
}
// -----------------------------------------------------------------------------
#ifndef OPPAI_LIB
const size_t bufsize = 8000000;
globvar char buf[bufsize];
int main(int argc, char* argv[])
{
// TODO: abstract error outputting into the output modules
if (argc < 2)
{
printf("Usage: %s /path/to/difficulty.osu "
"{[acc]%% or [num_100s]x100 [num_50s]x50} +[mods] "
"[combo]x [misses]m scorev[scoring_version] "
"AR[ar_override] OD[od_override] CS[cs_override] "
"[other options]\n\n", *argv);
puts("use \"-\" instead of a path to an .osu file to read from stdin\n");
puts("acc: the accuracy in percent (example: 99.99%)\n");
puts("num_100s, num_50s: specify accuracy in 100 and 50 count\n");
puts("mods: any combination of nomod, nf, ez, hd, hr, dt, ht"
", nc, fl, so (example: +hddthr)\n");
puts("combo: the highest combo (example: 1337x)\n");
puts("misses: amount of misses (example: 1m)\n");
puts("scoring_version: can only be 1 or 2 (example: scorev2)\n");
puts("ar_override, od_override, cs_override: overrides base ar/od/cs "
"for the map. useful to quickly calculate how it would affect pp "
"without editing the actual map. (example: AR10 OD10 CS6.5)\n");
puts("singletap_max_bpm: singletap bpm threshold, defaults to 240. "
"this is used to count how many notes are within 1/2 singletaps "
"of this bpm.\n");
printf("output_module: the module that will be used to output the "
"results (defaults to text). currently available modules: ");
for (output_module* m = get_output_modules(); m->name; ++m) {
printf("%s ", m->name);
}
puts("\n");
puts("-no-awkwardness: disables rhythm awkwardness calculation. since "
"this is disabled by default as of 0.9.8, this flag is only kept "
"for backwards compatibility\n");
puts("-awkwardness: enables experimental rhythm awkwardness "
"calculations, ~10% slower\n");
puts("-no-cache: disables caching. since caching is disabled by "
"default as of 0.9.7, this flag does nothing and is just kept "
"for backwards compatibility\n");
puts("-cache: enables caching of pre-parsed beatmap data to the "
"oppai_cache folder where the oppai binary is located. this "
"usually boosts performance by ~25% on reasonably fast drives.\n"
"WARNING: the cache files might not be portable to different "
"machines and might cause incorrect calculations if corrupt\n");
puts("-version: prints version number");
puts("arguments in [square brackets] are optional");
puts("(the order of the optional arguments does not matter)");
return 1;
}
// ---
#if OPPAI_PROFILING
const int prid = 0;
#endif
bool no_cache = true;
if (!strcmp(argv[1], "-version")) {
puts(version_string);
exit(0);
}
// TODO: find a way to do this without using 2 loops
for (int i = 2; i < argc; i++)
{
// no cache (purely for backwards compatibility)
if (!strcmp(argv[i], "-no-cache")) {
no_cache = true;
argv[i] = 0;
break;
}
if (!strcmp(argv[i], "-cache")) {
no_cache = false;
argv[i] = 0;
break;
}
}
profile_init();
// ---
profile(prid, "beatmap parse");
oppai_ctx ctx;
beatmap b(&ctx);
beatmap::parse(argv[1], b, buf, bufsize, no_cache);
chk(&ctx);
// ---
profile(prid, "arguments parse");
char* output_module_name = (char*)"text";
char* mods_str = 0;
f64 acc = 0;
f32 ar, od, cs;
u32 mods = mods::nomod;
u16 combo = b.max_combo;
u16 misses = 0;
u32 scoring = 1;
u16 c100 = 0, c50 = 0;
i32 single_max_bpm = 240;
// TODO: bitmask
bool no_percent = true;
bool no_awkwardness = true;
dbgputs("\nparsing arguments");
for (int i = 2; i < argc; i++)
{
char suff[64] = {0};
char* a = argv[i];
if (!a) {
continue;
}
std::transform(a, a + strlen(a), a, tolower_wrapper);
if (a[0] == '-')
{
// output module
if (a[1] == 'o') {
output_module_name = a + 2;
continue;
}
// singletap threshold
i32 tmp;
if (sscanf(a + 1, "st%" fi32, &tmp) == 1) {
single_max_bpm = tmp;
continue;
}
// no rhythm awkwardness (purely for backwards compatibility)
if (!strcmp(a + 1, "no-awkwardness")) {
no_awkwardness = true;
continue;
}
// enable rhythm awkwardness
if (!strcmp(a + 1, "awkwardness")) {
no_awkwardness = false;
continue;
}
}
// acc
f64 tmp_acc;
if (sscanf(a, "%lf%s", &tmp_acc, suff) == 2 && !strcmp(suff, "%"))
{
acc = tmp_acc;
no_percent = false;
continue;
}
// 100s, 50s
u16 tmp_c100 = 0, tmp_c50 = 0;
if (sscanf(a, "%" fu16 "%s", &tmp_c100, suff) == 2 &&
!strcmp(suff, "x100"))
{
c100 = tmp_c100;
continue;
}
if (sscanf(a, "%" fu16 "%s", &tmp_c50, suff) == 2 &&
!strcmp(suff, "x50"))
{
c50 = tmp_c50;
continue;
}
// mods
char* tmp_mods_str = 0;
for (size_t j = 0; j < num_mods; j++)
{
if (strstr(a, mod_strs[j]))
{
tmp_mods_str = a;
mods |= mod_masks[j];
}
}
if (tmp_mods_str == a && *tmp_mods_str == '+')
{
// at least one mod found in the parameter and the prefix matches
mods_str = tmp_mods_str;
std::transform(mods_str, mods_str + strlen(mods_str), mods_str,
toupper_wrapper);
continue;
}
// combo
u16 tmp_combo;
if (sscanf(a, "%" fu16 "%s", &tmp_combo, suff) == 2 &&
!strcmp(suff, "x"))
{
combo = tmp_combo;
continue;
}
// misses
u16 tmp_misses;
if (sscanf(a, "%" fu16 "%s", &tmp_misses, suff) == 2 &&
(!strcmp(suff, "xm") || !strcmp(suff, "xmiss") ||
!strcmp(suff, "m")))
{
misses = tmp_misses;
continue;
}
// scorev1 / scorev2
u32 tmp_scoring;
if (sscanf(a, "scorev%" fu32, &tmp_scoring) == 1)
{
scoring = tmp_scoring;
continue;
}
// AR/OD/CS override
if (sscanf(a, "ar%f", &ar) == 1) {
b.ar = ar;
continue;
}
if (sscanf(a, "od%f", &od) == 1) {
b.od = od;
continue;
}
if (sscanf(a, "cs%f", &cs) == 1) {
b.cs = cs;
continue;
}
printf(">%s\n", a);
die(&ctx, "Invalid parameter");
break;
}
chk(&ctx);
// ---
#ifdef SHOW_BEATMAP
print_beatmap(b, &ctx);
chk(&ctx);
#endif
profile(prid, "diff calc");
b.apply_mods(mods);
chk(&ctx);
d_calc_ctx dctx(&ctx);
u16 nsingles = 0, nsingles_timing = 0, nsingles_threshold = 0;
f64 aim = 0, speed = 0, rhythm_complexity = 0;
f64 stars =
d_calc(
&dctx,
b,
&aim,
&speed,
no_awkwardness ? 0 : &rhythm_complexity,
&nsingles,
&nsingles_timing,
&nsingles_threshold,
(i32)((60000.0f / single_max_bpm) / 2)
);
chk(&ctx);
pp_calc_result res = no_percent ?
pp_calc(
&ctx,
aim, speed, b, mods,
combo, misses,
0xFFFF, c100, c50,
scoring
)
: pp_calc_acc(&ctx, aim, speed, b, acc, mods, combo, misses, scoring);
chk(&ctx);
// ---
profile(prid, "output");
output_module* m = get_output_module(output_module_name);
if (!m) {
die(&ctx, "The specified output module does not exist");
}
chk(&ctx);
m->print(stdout, mods_str, combo, misses, scoring,
stars, aim, speed, !no_awkwardness, rhythm_complexity,
nsingles, nsingles_timing, nsingles_threshold, res, b);
// ---
profile(prid, "");
profile_end();
return 0;
}
#endif
#ifdef SHOW_BEATMAP
internalfn
void print_beatmap(beatmap& b, oppai_ctx* ctx)
{
printf(
"Format version: %" fi32 "\n"
"Stack Leniency: %g\n"
"Mode: %" fi32 "\n"
"Title: %s\n"
"Artist: %s\n"
"Version: %s\n"
"HP%g CS%g OD%g AR%g SV%g\n\n"
,
b.format_version,
b.stack_leniency,
b.mode,
b.title,
b.artist,
b.version,
b.hp, b.cs, b.od, b.ar, b.sv
);
printf("> %" fu32 " timing points\n", (u32)b.num_timing_points);
for (size_t i = 0; i < b.num_timing_points; i++)
{
timing_point& tp = b.timing_points[i];
printf("%" fi32 ": ", tp.time);
if (!tp.inherit) {
printf("%g bpm\n", 60000.0 / tp.ms_per_beat);
} else {
printf("%gx\n", -100.0 / tp.ms_per_beat);
}
}
printf("\n> %" fu32 " hit objects\n", (u32)b.num_objects);
for (size_t i = 0; i < b.num_objects; i++)
{
hit_object& ho = b.objects[i];
switch (ho.type) {
case obj::circle:
printf("%" fi32 ": Circle (%g, %g)\n",
ho.time, ho.pos.x, ho.pos.y);
break;
case obj::spinner:
printf("%" fi32 "-%" fi32 ": Spinner\n",
ho.time, ho.end_time);
break;
case obj::slider:
{
slider_data& sl = ho.slider;
printf(
"%" fi32 "-%" fi32 ": Slider "
"[Type %c, Length %g, %" fu16 " Repetitions] ",
ho.time, ho.end_time, sl.type,
sl.length, sl.repetitions);
puts("");
break;
}
default:
die(ctx, "Invalid object type");
return;
}
}
}
#endif