]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
WRITESPECTATABLE_MSG_ONE: cleanup
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 24 Dec 2015 06:46:58 +0000 (17:46 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 24 Dec 2015 06:47:27 +0000 (17:47 +1100)
qcsrc/lib/net.qh
qcsrc/server/race.qc

index d870ef1f9639ee91b252f64b5da1f3414b5aacb4..2473d672c24d87b746dc15a0aaa0faeade8b1ec9 100644 (file)
@@ -346,20 +346,17 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); }
                }
 
                // allow writing to also pass through to spectators (like so spectators see the same centerprints as players for example)
-               #define WRITESPECTATABLE_MSG_ONE_VARNAME(varname, statement) \
-                       entity varname; varname = msg_entity; \
-                       FOR_EACH_REALCLIENT(msg_entity) \
-                       if (msg_entity == varname || (msg_entity.classname == STR_SPECTATOR && msg_entity.enemy == varname)) \
-                               statement msg_entity = varname
-               #define WRITESPECTATABLE_MSG_ONE(statement) \
-                       MACRO_BEGIN \
-                       { \
-                               WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement); \
-                       } MACRO_END
-               #define WRITESPECTATABLE(msg, statement) \
-                       if (msg == MSG_ONE) WRITESPECTATABLE_MSG_ONE(statement); \
-                       else \
-                               statement float WRITESPECTATABLE_workaround = 0
+               #define WRITESPECTATABLE_MSG_ONE(statement) MACRO_BEGIN { \
+                       entity dst = msg_entity; \
+                       FOREACH_CLIENT(IS_REAL_CLIENT(it), { \
+                               if (it == dst || (it.classname == STR_SPECTATOR && it.enemy == dst)) \
+                               { \
+                                       msg_entity = it; \
+                                       LAMBDA(statement); \
+                               } \
+                       }); \
+                       msg_entity = dst; \
+               } MACRO_END
        #endif
 #endif
 
index dbc59457b87c427318db661d7862f9c57f64e51a..42d7e5dd644adefce60ec845dd24e618f583ae6c 100644 (file)
@@ -236,7 +236,7 @@ void race_SendStatus(float id, entity e)
        else
                msg = MSG_ALL;
        msg_entity = e;
-       WRITESPECTATABLE_MSG_ONE_VARNAME(dummy3, {
+       WRITESPECTATABLE_MSG_ONE({
                WriteHeader(msg, TE_CSQC_RACE);
                WriteByte(msg, RACE_NET_SERVER_STATUS);
                WriteShort(msg, id);
@@ -444,7 +444,7 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                        msg_entity = e;
                        if(g_race_qualifying)
                        {
-                               WRITESPECTATABLE_MSG_ONE_VARNAME(dummy1, {
+                               WRITESPECTATABLE_MSG_ONE({
                                        WriteHeader(MSG_ONE, TE_CSQC_RACE);
                                        WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_QUALIFYING);
                                        WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
@@ -472,7 +472,7 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                if(IS_REAL_CLIENT(e))
                {
                        msg_entity = e;
-                       WRITESPECTATABLE_MSG_ONE_VARNAME(dummy2, {
+                       WRITESPECTATABLE_MSG_ONE({
                                WriteHeader(MSG_ONE, TE_CSQC_RACE);
                                WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_RACE);
                                WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
@@ -498,7 +498,7 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                if(IS_REAL_CLIENT(oth))
                {
                        msg_entity = oth;
-                       WRITESPECTATABLE_MSG_ONE_VARNAME(dummy3, {
+                       WRITESPECTATABLE_MSG_ONE({
                                WriteHeader(MSG_ONE, TE_CSQC_RACE);
                                WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT);
                                WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
@@ -1102,7 +1102,7 @@ void race_ImposePenaltyTime(entity pl, float penalty, string reason)
                if(IS_REAL_CLIENT(pl))
                {
                        msg_entity = pl;
-                       WRITESPECTATABLE_MSG_ONE_VARNAME(dummy, {
+                       WRITESPECTATABLE_MSG_ONE({
                                WriteHeader(MSG_ONE, TE_CSQC_RACE);
                                WriteByte(MSG_ONE, RACE_NET_PENALTY_RACE);
                                WriteShort(MSG_ONE, TIME_ENCODE(penalty));