Skip to content

Commit d45befc

Browse files
committed
Do skin updates on next prethink
1 parent eaecdce commit d45befc

File tree

5 files changed

+74
-57
lines changed

5 files changed

+74
-57
lines changed

ssqc/client.qc

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ void StopAssCan();
7373
void Predict_InitPlayer(entity player);
7474
void Predict_Destroy(entity player);
7575

76+
void SetSkinInfoFor(entity pov, entity target);
77+
7678
void () info_intermission =
7779
{
7880
if (CheckExistence() == 0) {
@@ -2768,9 +2770,31 @@ static void ConcUpdate() {
27682770
}
27692771
}
27702772

2773+
// If a forceinfokey and a SVC_SETINFO are both set in the same frame, they
2774+
// will clobber each other. Thus we do skin setinfos like normal, and then
2775+
// per-player custom skin infos are immediately applied for those who need to
2776+
// update on the next frame.
2777+
void () UpdateAllSkins = {
2778+
local entity target = find(world, classname, "player");
2779+
local entity pov;
2780+
2781+
while (target != world) {
2782+
if (target.needs_skin_update) {
2783+
pov = find(world, classname, "player");
2784+
while (pov != world) {
2785+
SetSkinInfoFor(pov, target);
2786+
pov = find(pov, classname, "player");
2787+
}
2788+
target.needs_skin_update = 0;
2789+
}
2790+
target = find(target, classname, "player");
2791+
}
2792+
}
2793+
27712794
void () PlayerPreThink = {
27722795
FO_UpdateClientTime();
27732796
ConcUpdate();
2797+
UpdateAllSkins();
27742798

27752799
if (self.impulse) {
27762800
if (self.impulse == TF_VOTENEXT) {
@@ -3147,21 +3171,37 @@ void () UpdateAllClientsTeamScores = {
31473171
}
31483172
}
31493173

3150-
void (entity pov, entity target) SetSkinInfoFor = {
3174+
void (entity pov, entity target) SetBottomColorInfoFor = {
31513175
local float target_idx = target.colormap - 1;
31523176
local string color = TeamFortress_TeamGetColorFor(pov, target.team_no);
31533177

3178+
bprint(PRINT_HIGH, sprintf("Setting bottomcolor %s on %s for %s\n", color, target.netname, pov.netname));
3179+
31543180
msg_entity = pov;
31553181
WriteByte(MSG_ONE, SVC_SETINFO);
31563182
WriteByte(MSG_ONE, target_idx);
3157-
WriteString(MSG_ONE, "topcolor");
3183+
WriteString(MSG_ONE, "bottomcolor");
31583184
WriteString(MSG_ONE, color);
3185+
}
3186+
3187+
void (entity pov, entity target) SetTopColorInfoFor = {
3188+
local float target_idx = target.colormap - 1;
3189+
local string color = TeamFortress_TeamGetColorFor(pov, target.team_no);
3190+
3191+
bprint(PRINT_HIGH, sprintf("Setting topcolor %s on %s for %s\n", color, target.netname, pov.netname));
3192+
3193+
msg_entity = pov;
31593194
WriteByte(MSG_ONE, SVC_SETINFO);
31603195
WriteByte(MSG_ONE, target_idx);
3161-
WriteString(MSG_ONE, "bottomcolor");
3196+
WriteString(MSG_ONE, "topcolor");
31623197
WriteString(MSG_ONE, color);
31633198
}
31643199

3200+
void (entity pov, entity target) SetSkinInfoFor = {
3201+
SetTopColorInfoFor(pov, target);
3202+
SetBottomColorInfoFor(pov, target);
3203+
}
3204+
31653205
void () ClientConnect = {
31663206
if (!infokeyf(self,INFOKEY_P_CSQCACTIVE)) {
31673207
sprint(self, PRINT_HIGH, "FTE/CSQC is required for this server, please download the latest client package at www.fortressone.org\n");
@@ -3221,13 +3261,7 @@ void () ClientConnect = {
32213261
UpdateClientTeamScores(self);
32223262
UpdateClientPrematch(self, !cb_prematch);
32233263
UpdateClient_VoteMap_AddAll(self);
3224-
3225-
// Set skin colours
3226-
local entity te = find(world, classname, "player");
3227-
while (te != world) {
3228-
SetSkinInfoFor(self, te);
3229-
te = find(te, classname, "player");
3230-
}
3264+
TeamFortress_SetSkin(self);
32313265

32323266
if (cb_prematch)
32333267
sprint(self, PRINT_HIGH, "Currently in \sprematch\s time\n");

ssqc/commands.qc

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,10 @@ void (entity pl) PrintWho = {
316316
void (entity pov, string command, string color) UpdateTeamColor = {
317317
forceinfokey(pov, command, color);
318318

319-
local entity te = find(world, classname, "player");
320-
while (te != world) {
321-
TeamFortress_SetSkin(te);
322-
323-
te = find(te, classname, "player");
319+
local entity target = find(world, classname, "player");
320+
while (target != world) {
321+
SetSkinInfoFor(pov, target);
322+
target = find(target, classname, "player");
324323
}
325324
}
326325

@@ -363,12 +362,6 @@ float (string arg1, string arg2, string arg3) ParseCmds = {
363362
case "setinfo":
364363
if (arg2) {
365364
switch(arg2) {
366-
/* case "topcolor": */
367-
/* case "bottomcolor": */
368-
/* case "color": */
369-
/* TeamFortress_SetSkin(self); */
370-
/* processedCmd = TRUE; */
371-
/* break; */
372365
case "team1color":
373366
case "team2color":
374367
case "team3color":

ssqc/qw.qc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ float remote_client_time();
100100
.float building_percentage; // The building percentage shown in status bar
101101
.float fragstreak; // Frag streak
102102
.float caps; // Caps during this game
103+
.float needs_skin_update; // Set true when per-player skins need updating
103104

104105
.entity nopickup; // Don't pick up this backpack/ammobox because it doesn't contain any of your ammo types
105106

ssqc/tfort.qc

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,48 +1171,34 @@ string(float pc) TeamFortress_GetSkin = {
11711171
return skin;
11721172
};
11731173

1174-
void (entity player) TeamFortress_SetSkinInfos = {
1175-
local string sk = TeamFortress_GetSkin(player.playerclass);
1176-
forceinfokey(player, "skin", sk);
1177-
stuffcmd(player, sprintf("skin %s\n", sk));
1178-
1179-
local string col = TeamFortress_TeamGetColor(player.team_no);
1180-
forceinfokey(player, "bottomcolor", col);
1181-
/* stuffcmd(player, sprintf("setinfo bottomcolor %s\n", col)); */
1182-
forceinfokey(player, "topcolor", col);
1183-
/* stuffcmd(player, sprintf("setinfo topcolor %s\n", col)); */
1184-
1185-
local entity te = find(world, classname, "player");
1186-
while (te != world) {
1187-
SetSkinInfoFor(te, player);
1188-
te = find(te, classname, "player");
1189-
}
1190-
}
1191-
1192-
void (entity p) TeamFortress_SetSkin = {
1193-
p.immune_to_check = time + 10;
1194-
1195-
if (p.playerclass == PC_SPY || p.last_playerclass == PC_SPY) {
1196-
if (!p.is_undercover) {
1197-
TeamFortress_SetSkinInfos(p);
1198-
} else {
1199-
Spy_SetClientSkins(p);
1200-
}
1174+
void (entity player) TeamFortress_SetSkin = {
1175+
player.immune_to_check = time + 10;
12011176

1177+
if (player.playerclass == PC_SPY && player.is_undercover) {
1178+
Spy_SetClientSkins(player);
12021179
return;
12031180
}
12041181

1205-
p.skin = p.playerclass;
1182+
player.skin = player.playerclass;
1183+
1184+
if (player.skin != 0) {
1185+
player.needs_skin_update = 1;
1186+
local string sk = TeamFortress_GetSkin(player.playerclass);
1187+
forceinfokey(player, "skin", sk);
1188+
stuffcmd(player, sprintf("skin %s\n", sk));
12061189

1207-
if (p.skin != 0) {
1208-
TeamFortress_SetSkinInfos(p);
1190+
local string col = TeamFortress_TeamGetColor(player.team_no);
1191+
forceinfokey(player, "bottomcolor", col);
1192+
stuffcmd(player, sprintf("setinfo bottomcolor %s\n", col));
1193+
forceinfokey(player, "topcolor", col);
1194+
stuffcmd(player, sprintf("setinfo topcolor %s\n", col));
12091195
} else {
1210-
forceinfokey(p, "skin", "base");
1211-
stuffcmd(p, sprintf("skin %s\n", "base"));
1212-
forceinfokey(p, "bottomcolor", NOTEAMCOLOR);
1213-
stuffcmd(p, sprintf("bottomcolor %s\n", NOTEAMCOLOR));
1214-
forceinfokey(p, "topcolor", NOTEAMCOLOR);
1215-
stuffcmd(p, sprintf("topcolor %s\n", NOTEAMCOLOR));
1196+
forceinfokey(player, "skin", "base");
1197+
stuffcmd(player, sprintf("skin %s\n", "base"));
1198+
forceinfokey(player, "bottomcolor", NOTEAMCOLOR);
1199+
stuffcmd(player, sprintf("bottomcolor %s\n", NOTEAMCOLOR));
1200+
forceinfokey(player, "topcolor", NOTEAMCOLOR);
1201+
stuffcmd(player, sprintf("topcolor %s\n", NOTEAMCOLOR));
12161202
}
12171203
};
12181204

ssqc/tforttm.qc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ void (entity player) TeamFortress_CheckTeamCheats = {
339339
if ((player.team_no > 0) && (teamplay > 0)) {
340340
st = infokey(player, "bottomcolor");
341341
if (st != TeamFortress_TeamGetColor(player.team_no)) {
342+
bprint(PRINT_HIGH, sprintf("%s's bottomcolor is wrong\n", player.netname));
343+
bprint(PRINT_HIGH, sprintf("setinfo: %s\n", st));
344+
bprint(PRINT_HIGH, sprintf("TF_TGC: %s\n", TeamFortress_TeamGetColor(player.team_no)));
342345
TeamFortress_SetSkin(player);
343346
}
344347
if (player.playerclass != 0) {

0 commit comments

Comments
 (0)