@@ -22,6 +22,37 @@ void GetSelf() = {
22
22
self = findfloat(world, entnum, player_localentnum);
23
23
}
24
24
25
+ void PushToSlotSelectionHistory(float value) {
26
+ if (slot_selection_history_top >= MAX_SLOT_SELECTION_HISTORY_SIZE) {
27
+ // Stack is full
28
+ return;
29
+ }
30
+
31
+ slot_selection_history_top += 1;
32
+ print(sprintf("slot_selection_history_top: %f\n", slot_selection_history_top));
33
+ slot_selection_history[slot_selection_history_top] = value;
34
+ }
35
+
36
+ float RemoveSlotFromSelectionHistory(float slot) {
37
+ if (slot_selection_history_top == -1) {
38
+ // Stack is empty
39
+ return -1;
40
+ }
41
+
42
+ for (float i = slot_selection_history_top; i >= 0; i--) {
43
+ if (slot_selection_history[i] == slot) {
44
+ for (float j = i+1; j < MAX_SLOT_SELECTION_HISTORY_SIZE; j++) {
45
+ slot_selection_history[j-1] = slot_selection_history[j];
46
+ }
47
+
48
+ slot_selection_history[MAX_SLOT_SELECTION_HISTORY_SIZE-1] = 0;
49
+ slot_selection_history_top--;
50
+ break;
51
+ }
52
+ }
53
+ }
54
+
55
+
25
56
DECLARE_PERF_SAMPLER(frame_timing, 60, 0.1);
26
57
DECLARE_PERF_SAMPLER(hud_timing, 60, 0.1);
27
58
DECLARE_PERF_SAMPLER(hud_partial_timing, 60, 0.1);
@@ -49,14 +80,8 @@ noref void(float apiver, string enginename, float enginever) CSQC_Init = {
49
80
50
81
slot_selection_history_top = -1;
51
82
52
- registercommand("+zel1");
53
- registercommand("-zel1");
54
- registercommand("+zel2");
55
- registercommand("-zel2");
56
- registercommand("+zel3");
57
- registercommand("-zel3");
58
- registercommand("+zel4");
59
- registercommand("-zel4");
83
+ registercommand("+slot");
84
+ registercommand("-slot");
60
85
61
86
registercommand("login");
62
87
registercommand("fo_hud_editor");
@@ -174,36 +199,36 @@ noref void(float width, float height, float menushown) CSQC_UpdateView = {
174
199
recent_pmove_vel_z = pmove_vel_z;
175
200
}
176
201
202
+ void Slot_Keydown(float slot) {
203
+ PushToSlotSelectionHistory(slot);
204
+ localcmd(sprintf("impulse %f\n", slot));
205
+ localcmd("+attack\n");
206
+ }
207
+
208
+ void Slot_Keyup(float slot) {
209
+ RemoveSlotFromSelectionHistory(slot);
210
+ if (slot_selection_history_top >= 0) {
211
+ localcmd(sprintf("impulse %f\n", slot_selection_history[slot_selection_history_top]));
212
+ } else {
213
+ if (CVARF(fo_default_weapon)) {
214
+ localcmd(sprintf("impulse %f\n", CVARF(fo_default_weapon)));
215
+ }
216
+ localcmd("-attack\n");
217
+ }
218
+ }
219
+
177
220
noref float(string cmd) CSQC_ConsoleCommand = {
178
221
tokenize_console(cmd);
179
222
float val;
180
223
string key1, key2;
181
224
local float grentype;
182
225
183
226
switch(argv(0)) {
184
- case "+zel1":
185
- input_slots |= SLOT1;
186
- break;
187
- case "-zel1":
188
- input_slots &= ~SLOT1;
189
- break;
190
- case "+zel2":
191
- input_slots |= SLOT2;
192
- break;
193
- case "-zel2":
194
- input_slots &= ~SLOT2;
195
- break;
196
- case "+zel3":
197
- input_slots |= SLOT3;
198
- break;
199
- case "-zel3":
200
- input_slots &= ~SLOT3;
201
- break;
202
- case "+zel4":
203
- input_slots |= SLOT4;
227
+ case "+slot":
228
+ Slot_Keydown(stof(argv(1)));
204
229
break;
205
- case "-zel4 ":
206
- input_slots &= ~SLOT4 ;
230
+ case "-slot ":
231
+ Slot_Keyup(stof(argv(1))) ;
207
232
break;
208
233
case "login":
209
234
FoLogin(argv(1));
@@ -467,73 +492,7 @@ void() CSQC_Ent_Remove = { //the entity in question left the player's pvs, and
467
492
remove(self);
468
493
};
469
494
470
- void PushSlotSelection(float value) {
471
- if (slot_selection_history_top == MAX_SLOT_SELECTION_HISTORY_SIZE) {
472
- // Stack is full
473
- return;
474
- }
475
-
476
- slot_selection_history_top += 1;
477
- slot_selection_history[slot_selection_history_top] = value;
478
- }
479
-
480
- float PopSlotSelectionHistoryIf(float slot) {
481
- if (slot_selection_history_top == -1) {
482
- // Stack is empty
483
- return -1;
484
- }
485
-
486
- for (float i = slot_selection_history_top; i >= 0; i--) {
487
- if (slot_selection_history[i] == slot) {
488
- for (float j = i+1; j < MAX_SLOT_SELECTION_HISTORY_SIZE; j++) {
489
- slot_selection_history[j-1] = slot_selection_history[j];
490
- }
491
-
492
- slot_selection_history[MAX_SLOT_SELECTION_HISTORY_SIZE-1] = 0;
493
- slot_selection_history_top--;
494
- break;
495
- }
496
- }
497
- }
498
-
499
- void Handle_Slot_Key(float slot, float impulse) {
500
- if (input_slots & slot) { // slot keydown
501
- PushSlotSelection(impulse);
502
- input_impulse = impulse;
503
- } else { // slot keyup
504
- PopSlotSelectionHistoryIf(impulse);
505
- if (slot_selection_history_top >= 0) {
506
- input_impulse = slot_selection_history[slot_selection_history_top];
507
- } else {
508
- if (CVARF(fo_default_weapon)) {
509
- input_impulse = CVARF(fo_default_weapon);
510
- }
511
- }
512
- }
513
- }
514
-
515
495
noref void CSQC_Input_Frame() {
516
- local float changed_slots = input_slots ^ oldslots;
517
- oldslots = input_slots;
518
-
519
- local float slotdowns = changed_slots & input_buttons;
520
- local float slotups = changed_slots & ~input_buttons;
521
-
522
- if (input_slots) { // if using slots, you definitely should be shooting
523
- input_buttons |= BUTTON0;
524
- }
525
-
526
- if (changed_slots & SLOT1) { Handle_Slot_Key(SLOT1, 1); }
527
- if (changed_slots & SLOT2) { Handle_Slot_Key(SLOT2, 2); }
528
- if (changed_slots & SLOT3) { Handle_Slot_Key(SLOT3, 3); }
529
- if (changed_slots & SLOT4) { Handle_Slot_Key(SLOT4, 4); }
530
-
531
- local float changed_buttons = input_buttons ^ oldbuttons;
532
- oldbuttons = input_buttons;
533
-
534
- local float keydowns = changed_buttons & input_buttons;
535
- local float keyups = changed_buttons & ~input_buttons;
536
-
537
496
Sync_GameState();
538
497
539
498
// Intercept rocket jump;
0 commit comments