Repository navigation
Expand file tree
/
Copy pathframework__async__NetworkSystem.v
More file actions
679 lines (612 loc) · 23.2 KB
/
Copy pathframework__async__NetworkSystem.v
File metadata and controls
679 lines (612 loc) · 23.2 KB
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
// Translated to V with c2v from dhewm3; see UPSTREAM-NOTICES.md.
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
Doom 3 Source Code 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 3 of the License, or
(at your option) any later version.
Doom 3 Source Code 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 Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
@[translated]
module main
// 8 bits
// 16 bits
// 32 bits
// empty enum
// skipping global dup "idRandom_MAX_RAND"
//
// ===============================================================================
//
// Random number generator
//
// ===============================================================================
//
// skipping global dup "idRandom2_MAX_RAND"
// skipping global dup "idRandom2_IEEE_ONE"
// skipping global dup "idRandom2_IEEE_MASK"
type IdList_idStr_new_t_NetworkSystem = fn () IdStr
type IdList_idPoolStrPtr_new_t_NetworkSystem = fn () &IdPoolStr
type IdList_idKeyValue_new_t_NetworkSystem = fn () IdKeyValue
type IdList_networkServer_t_new_t_NetworkSystem = fn () NetworkServer_t
type IdList_inServer_t_new_t_NetworkSystem = fn () InServer_t
type IdList_int_new_t_NetworkSystem = fn () i32
type IdList_idStrPtr_new_t_NetworkSystem = fn () &IdStr
type IdList_pakDlEntry_t_new_t_NetworkSystem = fn () PakDlEntry_t
// note that this isn't journaled...
// allow game to yield CPU time
// NOTE: due to SDL_TIMESLICE this is very bad portability karma, and should be completely removed
// like Sys_Milliseconds(), but with higher precision
// sleep until Sys_MillisecondsPrecise() returns >= targetTimeMS
// aims for about 0.01ms precision (but might busy wait for the last 1.5ms or so)
// returns a selection of the CPUID_* flags
// sets the FPU precision
// sets Flush-To-Zero mode
// sets Denormals-Are-Zero mode
// returns amount of system ram
// returns amount of drive space in path
// lock and unlock memory
// set amount of physical work memory
// DLL loading, the path should be a fully qualified OS path to the DLL file to be loaded
// event generation
// input is tied to windows, so it needs to be started up and shut down whenever
// the main window is recreated
// map a scancode key to a char
// does nothing on win32, as SE_KEY == SE_CHAR there
// on other OSes, consider the keyboard mapping
// for keynums between K_FIRST_SCANCODE and K_LAST_SCANCODE
// returns e.g. "SC_A" for K_SC_A
// returns localized name of the key (between K_FIRST_SCANCODE and K_LAST_SCANCODE),
// regarding the current keyboard layout - if that name is in ASCII or corresponds
// to a "High-ASCII" char supported by Doom3.
// Otherwise return same name as Sys_GetScancodeName()
// !! Returned string is only valid until next call to this function !!
// the same, but using UTF-8 instead of "High-ASCII"
// returns keyNum_t (K_SC_* constant) for given scancode name (like "SC_A")
// returns display name of the key (between K_FIRST_JOY and K_LAST_JOY)
// With SDL2 it'll return the name in the SDL_GameController standard layout
// (which is based on XBox/XInput => on Nintendo gamepads, A/B and X/Y will be flipped),
// with SDL3 it will return the "real" button name
// keyboard input polling
// mouse input polling
// joystick input polling
// when the console is down, or the game is about to perform a lengthy
// operation like map loading, the system can release the mouse cursor
// when in windowed mode
// DG: added this for an ungodly hack for gamepad support
// active = true means "currently a GUI with a cursor is active/focused"
// active = false means "that GUI is not active anymore"
// ui == NULL means "clear all currently remembered GUIs"
// NOTE: do we need to guarantee the same output on all platforms?
// use fs_debug to verbose Sys_ListFiles
// returns -1 if directory was not found (the list is cleared)
//
// ==============================================================
//
// Networking
//
// ==============================================================
//
// parses the port number
// can also do DNS resolve if you ask for it.
// NOTE: DNS resolve is a slow/blocking call, think before you use
// ( could be exploited for server DoS )
//
// ==============================================================
//
// Multi-threading
//
// ==============================================================
//
// sets threadHandle back to 0
// find the name of the calling thread
// if index != NULL, set the index in threads array (use -1 for "main" thread)
// skipping global dup "MAX_CRITICAL_SECTIONS"
// empty enum
// skipping global dup "MAX_TRIGGER_EVENTS"
// empty enum
//
// ==============================================================
//
// idSys
//
// ==============================================================
//
//
// ===========================================================================
//
// Doom 3 GPL Source Code
// Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
//
// This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
//
// Doom 3 Source Code 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 3 of the License, or
// (at your option) any later version.
//
// Doom 3 Source Code 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 Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
//
// In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
//
// If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
//
// ===========================================================================
//
//
// ===============================================================================
//
// Single Instruction Multiple Data (SIMD)
//
// For optimal use data should be aligned on a 16 byte boundary.
// All idSIMDProcessor routines are thread safe.
//
// ===============================================================================
//
//
// ===============================================================================
//
// virtual base class for different SIMD processors
//
// ===============================================================================
//
// skipping global dup "MIXBUFFER_SAMPLES"
// pointer to SIMD processor
//
// ===============================================================================
//
// Types and defines used throughout the engine.
//
// ===============================================================================
//
// basic colors
// packs color floats in the range [0,1] into an integer
// little/big endian conversion
// for base64
// DG: change assert to use ?: so I can use it in _alloca()/_alloca16() (MSVC didn't like if() in there)
// move from Math.h to keep gcc happy
//
// ===============================================================================
//
// Block based allocator for fixed size objects.
//
// All objects of the 'type' are properly constructed.
// However, the constructor is not called for re-used objects.
//
// ===============================================================================
//
// ===============================================================
//
// idVec2 - 2D vector
//
// ===============================================================
// ===============================================================
//
// idVec3 - 3D vector
//
// ===============================================================
// ===============================================================
//
// idVec4 - 4D vector
//
// ===============================================================
// ===============================================================
//
// idVec5 - 5D vector
//
// ===============================================================
// ===============================================================
//
// idVec6 - 6D vector
//
// ===============================================================
// ===============================================================
//
// idVecX - arbitrary sized vector
//
// The vector lives on 16 byte aligned and 16 byte padded memory.
//
// NOTE: due to the temporary memory pool idVecX cannot be used by multiple threads
//
// ===============================================================
// ===============================================================
//
// idPolar3
//
// ===============================================================
//
// ================
// idListNewElement<type>
// ================
//
//
// ================
// idSwap<type>
// ================
//
// color escape character
// skipping global dup "C_COLOR_ESCAPE"
// skipping global dup "C_COLOR_DEFAULT"
// skipping global dup "C_COLOR_RED"
// skipping global dup "C_COLOR_GREEN"
// skipping global dup "C_COLOR_YELLOW"
// skipping global dup "C_COLOR_BLUE"
// skipping global dup "C_COLOR_CYAN"
// skipping global dup "C_COLOR_MAGENTA"
// skipping global dup "C_COLOR_WHITE"
// skipping global dup "C_COLOR_GRAY"
// skipping global dup "C_COLOR_BLACK"
// color escape string
// make idStr a multiple of 16 bytes long
// don't make too large to keep memory requirements to a minimum
// skipping global dup "STR_ALLOC_BASE"
// skipping global dup "STR_ALLOC_GRAN"
// behaves like C99's vsnprintf() by returning the amount of bytes that
// *would* have been written into a big enough buffer, even if that's > size
// unlike idStr::vsnPrintf() which returns -1 in that case
// convert UTF-8 to ISU8859-1 (the "High ASCII" 8-bit encoding Doom3 uses)
// invalidChar is inserted into the output buffer for unicode characters that can't be
// represented by ISO8859-1; if it's 0, those will just be skipped
// convert ISO8859-1 (the "High ASCII" 8-bit encoding Doom3 uses) to UTF-8
// returns NULL on error (need more than utf8bufLen chars in utf8buf)
// returns number of Unicode codepoints (UTF32 char) in given UTF-8 string.
// if n >= 0, it only looks at the first n bytes of str (but still stops at the first \0)
// that's not necessarily the number of printed characters (as unicode allows graphemes that
// consist of multiple codepoints), but for our purposes (limiting to Latin1 subset) it is..
// cuts off str (by writing \0 char) after n Unicode codepoints
// returns number of bytes that remain in string => returns strlen(str) (after cutting off)
// if str contains <= n codepoints, it's not modified and the number of bytes in it
// is still returned (excluding terminating \0)
// ===============================================================
//
// idMat2 - 2x2 matrix
//
// ===============================================================
// ===============================================================
//
// idMat3 - 3x3 matrix
//
// NOTE: matrix is column-major
//
// ===============================================================
// ===============================================================
//
// idMat4 - 4x4 matrix
//
// ===============================================================
// ===============================================================
//
// idMat5 - 5x5 matrix
//
// ===============================================================
// ===============================================================
//
// idMat6 - 6x6 matrix
//
// ===============================================================
// ===============================================================
//
// idMatX - arbitrary sized dense real matrix
//
// The matrix lives on 16 byte aligned and 16 byte padded memory.
//
// NOTE: due to the temporary memory pool idMatX cannot be used by multiple threads.
//
// ===============================================================
// punctuation ids
// punctuation
// indents used for conditional compilation directives:
// #if, #else, #elif, #ifdef, #ifndef
// parameters for command buffer stuffing
// command function
// argument completion function
// skipping global dup "cmdSystem"
//
// ===============================================================================
//
// idCVar
//
// ===============================================================================
//
//
// ===============================================================================
//
// idCVarSystem
//
// ===============================================================================
//
// skipping global dup "cvarSystem"
// skipping global dup "com_version"
// skipping global dup "com_skipRenderer"
// skipping global dup "com_asyncSound"
// skipping global dup "com_machineSpec"
// skipping global dup "com_purgeAll"
// skipping global dup "com_developer"
// skipping global dup "com_allowConsole"
// skipping global dup "com_speeds"
// skipping global dup "com_showFPS"
// skipping global dup "com_showMemoryUsage"
// skipping global dup "com_showAsyncStats"
// skipping global dup "com_showSoundDecoders"
// skipping global dup "com_makingBuild"
// skipping global dup "com_updateLoadSize"
// skipping global dup "com_enableDebuggerServer"
// skipping global dup "com_dbgClientAdr"
// skipping global dup "com_dbgServerAdr"
// skipping global dup "time_gameFrame"
// game logic time
// skipping global dup "time_gameDraw"
// game present time
// skipping global dup "time_frontend"
// renderer frontend time
// skipping global dup "time_backend"
// renderer backend time
// skipping global dup "com_frameTime"
// time for the current frame in milliseconds
// skipping global dup "com_ticNumber"
// 60 hz tics, incremented by async function
// skipping global dup "com_editors"
// current active editor(s)
// skipping global dup "com_editorActive"
// true if an editor has focus
// skipping global dup "com_debuggerSupported"
// only set to true when the updateDebugger function is set. see GetAdditionalFunction()
// skipping global dup "common"
//
// ===============================================================================
//
// idBitMsgDelta
//
// ===============================================================================
//
//
// ===============================================================================
//
// Network channel.
//
// Handles message fragmentation and out of order / duplicate suppression.
// Unreliable messages are not garrenteed to arrive but when they do, they
// arrive in order and without duplicates. Reliable messages always arrive,
// and they also arrive in order without duplicates. Reliable messages piggy
// back on unreliable messages. As such an unreliable message stream is
// required for the reliable messages to be delivered.
//
// ===============================================================================
//
// max length of a message, which may
// be fragmented into multiple packets
// id for connectionless messages
// value to mask away connectionless message id
// must be a power of 2
//
// ===============================================================================
//
// feed data to a listDef
// each item has an id and a display string
//
// ===============================================================================
//
// the menu gui uses a hard-coded control type to display a list of network games
// skipping global dup "USERCMD_HZ"
// 60 frames per second
// skipping global dup "USERCMD_MSEC"
// skipping global dup "BUTTON_ATTACK"
// skipping global dup "BUTTON_RUN"
// skipping global dup "BUTTON_ZOOM"
// skipping global dup "BUTTON_SCORES"
// skipping global dup "BUTTON_MLOOK"
// skipping global dup "BUTTON_5"
// skipping global dup "BUTTON_6"
// skipping global dup "BUTTON_7"
// usercmd_t->impulse commands
// skipping global dup "IMPULSE_0"
// weap 0
// skipping global dup "IMPULSE_1"
// weap 1
// skipping global dup "IMPULSE_2"
// weap 2
// skipping global dup "IMPULSE_3"
// weap 3
// skipping global dup "IMPULSE_4"
// weap 4
// skipping global dup "IMPULSE_5"
// weap 5
// skipping global dup "IMPULSE_6"
// weap 6
// skipping global dup "IMPULSE_7"
// weap 7
// skipping global dup "IMPULSE_8"
// weap 8
// skipping global dup "IMPULSE_9"
// weap 9
// skipping global dup "IMPULSE_10"
// weap 10
// skipping global dup "IMPULSE_11"
// weap 11
// skipping global dup "IMPULSE_12"
// weap 12
// skipping global dup "IMPULSE_13"
// weap reload
// skipping global dup "IMPULSE_14"
// weap next
// skipping global dup "IMPULSE_15"
// weap prev
// skipping global dup "IMPULSE_16"
// <unused>
// skipping global dup "IMPULSE_17"
// ready to play ( toggles ui_ready )
// skipping global dup "IMPULSE_18"
// center view
// skipping global dup "IMPULSE_19"
// show PDA/INV/MAP
// skipping global dup "IMPULSE_20"
// toggle team ( toggles ui_team )
// skipping global dup "IMPULSE_21"
// <unused>
// skipping global dup "IMPULSE_22"
// spectate
// skipping global dup "IMPULSE_23"
// <unused>
// skipping global dup "IMPULSE_24"
// <unused>
// skipping global dup "IMPULSE_25"
// <unused>
// skipping global dup "IMPULSE_26"
// <unused>
// skipping global dup "IMPULSE_27"
// <unused>
// skipping global dup "IMPULSE_28"
// vote yes
// skipping global dup "IMPULSE_29"
// vote no
// skipping global dup "IMPULSE_40"
// use vehicle
// usercmd_t->flags
// skipping global dup "UCF_IMPULSE_SEQUENCE"
// toggled every time an impulse command is sent
// skipping global dup "MAX_BUFFERED_USERCMD"
// skipping global dup "usercmdGen"
// DG: https://www.gnu.org/software/libc/manual/html_node/Limits-for-Files.html says
// that FILENAME_MAX can be *really* big on some systems and thus is not suitable
// for buffer lengths. So limit it to prevent stack overflow/out of memory issues
// modes for OpenFileByMode. used as bit mask internally
// file list for directory listings
// mod list
// skipping global dup "fileSystem"
//
// ===============================================================================
//
// The session is the glue that holds games together between levels.
//
// ===============================================================================
//
// needed by the gui system for the load game menu
// log every half second
// skipping global dup "session"
// skipping global dup "MAX_CHALLENGES"
// if we don't hear from authorize server, assume it is down
// skipping global dup "AUTHORIZE_TIMEOUT"
// states for the server's authorization process
// states from the auth server, while the client is in CDK_WAIT
// message from auth to be forwarded back to the client
// some are locally hardcoded to save space, auth has the possibility to send a custom reply
// skipping global dup "idAsyncServer_stats_numsamples"
// empty enum
// reliable server -> client messages
// empty enum
// unreliable client -> server messages
// empty enum
// reliable client -> server messages
// empty enum
// server print messages
// empty enum
// empty enum
// empty enum
fn (mut this IdNetworkSystem) init() {
this.c2v_class = 2424475271
}
fn (this &IdNetworkSystem) server_send_reliable_message(client_num i32, msg &IdBitMsg) {
if id_async_network_server.is_active() {
id_async_network_server.send_reliable_game_message(client_num, msg)
}
}
fn (this &IdNetworkSystem) server_send_reliable_message_excluding(client_num i32, msg &IdBitMsg) {
if id_async_network_server.is_active() {
id_async_network_server.send_reliable_game_message_excluding(client_num, msg)
}
}
fn (this &IdNetworkSystem) server_get_client_ping(client_num i32) i32 {
if id_async_network_server.is_active() {
return id_async_network_server.get_client_ping(client_num)
}
return 0
}
fn (this &IdNetworkSystem) server_get_client_prediction(client_num i32) i32 {
if id_async_network_server.is_active() {
return id_async_network_server.get_client_prediction(client_num)
}
return 0
}
fn (this &IdNetworkSystem) server_get_client_time_since_last_packet(client_num i32) i32 {
if id_async_network_server.is_active() {
return id_async_network_server.get_client_time_since_last_packet(client_num)
}
return 0
}
fn (this &IdNetworkSystem) server_get_client_time_since_last_input(client_num i32) i32 {
if id_async_network_server.is_active() {
return id_async_network_server.get_client_time_since_last_input(client_num)
}
return 0
}
fn (this &IdNetworkSystem) server_get_client_outgoing_rate(client_num i32) i32 {
if id_async_network_server.is_active() {
return id_async_network_server.get_client_outgoing_rate(client_num)
}
return 0
}
fn (this &IdNetworkSystem) server_get_client_incoming_rate(client_num i32) i32 {
if id_async_network_server.is_active() {
return id_async_network_server.get_client_incoming_rate(client_num)
}
return 0
}
fn (this &IdNetworkSystem) server_get_client_incoming_packet_loss(client_num i32) f32 {
if id_async_network_server.is_active() {
return id_async_network_server.get_client_incoming_packet_loss(client_num)
}
return 0.0
}
fn (this &IdNetworkSystem) client_send_reliable_message(msg &IdBitMsg) {
if id_async_network_client.is_active() {
id_async_network_client.send_reliable_game_message(msg)
} else if id_async_network_server.is_active() {
id_async_network_server.local_client_send_reliable_message(msg)
}
}
fn (this &IdNetworkSystem) client_get_prediction() i32 {
if id_async_network_client.is_active() {
return id_async_network_client.get_prediction()
}
return 0
}
fn (this &IdNetworkSystem) client_get_time_since_last_packet() i32 {
if id_async_network_client.is_active() {
return id_async_network_client.get_time_since_last_packet()
}
return 0
}
fn (this &IdNetworkSystem) client_get_outgoing_rate() i32 {
if id_async_network_client.is_active() {
return id_async_network_client.get_outgoing_rate()
}
return 0
}
fn (this &IdNetworkSystem) client_get_incoming_rate() i32 {
if id_async_network_client.is_active() {
return id_async_network_client.get_incoming_rate()
}
return 0
}
fn (this &IdNetworkSystem) client_get_incoming_packet_loss() f32 {
if id_async_network_client.is_active() {
return id_async_network_client.get_incoming_packet_loss()
}
return 0.0
}