Skip to content

Commit 2617271

Browse files
committed
Refactor
1 parent 2996dbe commit 2617271

File tree

3 files changed

+57
-104
lines changed

3 files changed

+57
-104
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ FortressOne Server
44
New commands
55
------------
66

7-
* `fo_default_weapon 0` default weapon when using +zelx binds
7+
* `+slot n` bind. fires nth weapon
8+
* `fo_default_weapon 0` default weapon when using `+slot` binds
89
* `fo_hud_cache 1` less resource intensive hud
910
* `fo_hud_fps 60` set hud refresh rate
1011
* `fo_grentimer_ping_frac 1` fraction of ping to correct for

csqc/csextradefs.qc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ const vector PLAYER_MAXS = [16, 16, 32];
6868

6969
#define MAP_MAX_CHARS 20
7070

71-
#define SLOT1 1
72-
#define SLOT2 2
73-
#define SLOT3 4
74-
#define SLOT4 8
7571
#define MAX_SLOT_SELECTION_HISTORY_SIZE 10
7672

7773
.void() removefunc;
@@ -112,10 +108,7 @@ float vote_selected_index;
112108
float vote_list_offset;
113109
entity current_vote;
114110
string vote_list_filter;
115-
float oldbuttons;
116111
float zoomed_in;
117-
float input_slots;
118-
float oldslots;
119112
float slot_selection_history[MAX_SLOT_SELECTION_HISTORY_SIZE];
120113
float slot_selection_history_top;
121114

csqc/main.qc

Lines changed: 55 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,37 @@ void GetSelf() = {
2222
self = findfloat(world, entnum, player_localentnum);
2323
}
2424

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+
2556
DECLARE_PERF_SAMPLER(frame_timing, 60, 0.1);
2657
DECLARE_PERF_SAMPLER(hud_timing, 60, 0.1);
2758
DECLARE_PERF_SAMPLER(hud_partial_timing, 60, 0.1);
@@ -49,14 +80,8 @@ noref void(float apiver, string enginename, float enginever) CSQC_Init = {
4980

5081
slot_selection_history_top = -1;
5182

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");
6085

6186
registercommand("login");
6287
registercommand("fo_hud_editor");
@@ -174,36 +199,36 @@ noref void(float width, float height, float menushown) CSQC_UpdateView = {
174199
recent_pmove_vel_z = pmove_vel_z;
175200
}
176201

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+
177220
noref float(string cmd) CSQC_ConsoleCommand = {
178221
tokenize_console(cmd);
179222
float val;
180223
string key1, key2;
181224
local float grentype;
182225

183226
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)));
204229
break;
205-
case "-zel4":
206-
input_slots &= ~SLOT4;
230+
case "-slot":
231+
Slot_Keyup(stof(argv(1)));
207232
break;
208233
case "login":
209234
FoLogin(argv(1));
@@ -467,73 +492,7 @@ void() CSQC_Ent_Remove = { //the entity in question left the player's pvs, and
467492
remove(self);
468493
};
469494

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-
515495
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-
537496
Sync_GameState();
538497

539498
// Intercept rocket jump;

0 commit comments

Comments
 (0)