achievements and stuff
[carveJwlIkooP6JGAAIwe30JlM.git] / common.h
1 /*
2 * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
3 */
4
5 #ifndef COMMON_H
6 #define COMMON_H
7
8 #define VG_TIMESTEP_FIXED (1.0/60.0)
9 #define VG_3D
10 #define VG_FRAMEBUFFER_RESIZE 1
11 #include "vg/vg.h"
12 #include "anyascii/anyascii.h"
13
14 typedef struct ray_hit ray_hit;
15 struct ray_hit
16 {
17 float dist;
18 u32 *tri;
19 v3f pos, normal;
20 };
21
22 static int network_scores_updated = 0;
23
24 static u32 utf8_byte0_byte_count( u8 char0 )
25 {
26 for( u32 k=2; k<4; k++ )
27 {
28 if( !(char0 & (0x80 >> k)) )
29 return k;
30 }
31
32 return 0;
33 }
34
35 static void str_utf8_collapse( const char *str, char *buf, u32 length )
36 {
37 u8 *ustr = (u8 *)str;
38 u32 utf32_code = 0x00000000;
39 u32 i=0, j=0, utf32_byte_ct=0;
40
41 for(;i < length-1;)
42 {
43 if( ustr[i] == 0x00 )
44 break;
45
46 if( ustr[i] & 0x80 )
47 {
48 if( utf32_byte_ct )
49 {
50 utf32_byte_ct --;
51 utf32_code |= (ustr[i] & 0x3F) << (utf32_byte_ct*6);
52
53 if( !utf32_byte_ct )
54 {
55 const char *match;
56 size_t chars = anyascii( utf32_code, &match );
57
58 for( u32 k=0; k<VG_MIN(chars, length-1-j); k++ )
59 {
60 buf[ j++ ] = (u8)match[k];
61 }
62 }
63 }
64 else
65 {
66 utf32_byte_ct = utf8_byte0_byte_count( ustr[i] )-1;
67 utf32_code = ustr[i] & (0x3F >> utf32_byte_ct);
68 utf32_code <<= utf32_byte_ct*6;
69 }
70 }
71 else
72 {
73 utf32_byte_ct = 0x00;
74 buf[j ++] = str[i];
75 }
76
77 i++;
78 }
79
80 buf[j] = 0x00;
81 }
82
83 #endif /* COMMON_H */