dont remember
[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 if( length == 0 )
38 {
39 strncpy( buf, "User", length );
40 return;
41 }
42
43 u8 *ustr = (u8 *)str;
44 u32 utf32_code = 0x00000000;
45 u32 i=0, j=0, utf32_byte_ct=0;
46
47 for(;i < length-1;)
48 {
49 if( ustr[i] == 0x00 )
50 break;
51
52 if( ustr[i] & 0x80 )
53 {
54 if( utf32_byte_ct )
55 {
56 utf32_byte_ct --;
57 utf32_code |= (ustr[i] & 0x3F) << (utf32_byte_ct*6);
58
59 if( !utf32_byte_ct )
60 {
61 const char *match;
62 size_t chars = anyascii( utf32_code, &match );
63
64 for( u32 k=0; k<VG_MIN(chars, length-1-j); k++ )
65 {
66 buf[ j++ ] = (u8)match[k];
67 }
68 }
69 }
70 else
71 {
72 utf32_byte_ct = utf8_byte0_byte_count( ustr[i] )-1;
73 utf32_code = ustr[i] & (0x3F >> utf32_byte_ct);
74 utf32_code <<= utf32_byte_ct*6;
75 }
76 }
77 else
78 {
79 utf32_byte_ct = 0x00;
80 buf[j ++] = str[i];
81 }
82
83 i++;
84 }
85
86 buf[j] = 0x00;
87 }
88
89 #endif /* COMMON_H */