From 9b107d1af78b53f2b8aa876c00adc6c78ec1683b Mon Sep 17 00:00:00 2001 From: sauerbraten Date: Thu, 3 Dec 2020 18:38:43 +0100 Subject: [PATCH] add frag message limit and X position --- Makefile | 2 +- README.md | 2 ++ patches/hudfragmessages.patch | 29 +++++++++++++++++++---------- src/fpsgame/fps.cpp | 4 ++-- src/fpsgame/fragmessages.cpp | 10 +++++++++- src/fpsgame/fragmessages.h | 1 + src/fpsgame/game.h | 2 +- 7 files changed, 35 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 1b2561b..df5b42a 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ undo-patches: $(PATCH) --reverse < patches/macos_builds.patch $(PATCH) --reverse < patches/scoreboard.patch $(PATCH) --reverse < patches/moviehud.patch - $(PATCH) < patches/hudfragmessages.patch + $(PATCH) --reverse < patches/hudfragmessages.patch unix2dos src/vcpp/sauerbraten.vcxproj clean-sauer: check-env diff --git a/README.md b/README.md index 06311d5..23460c5 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ a.k.a. Features - adds the following variables: - `hudfragmessages`: when 0, no frag messages are shown - `hudfragmessageduration`: how long each message will be shown, in milliseconds, between 100 (= 0.1s) and 10,000 (= 10s) + - `maxhudfragmessages`: how many messages to show at most (between 1 and 10) + - `hudfragmessagex`: horizontal position (between 0 and 1) where messages will appear - `hudfragmessagey`: vertical position (between 0 and 1) where the newest message will appear when hudfragmessagey<=0.5 (new messages appearing in the upper half of the screen), older messages will be stacked above newer ones, otherwise (new messages appear in the lower half), older messages are shown below newer ones - `hudfragmessagescale`: size of the messages, between 0.0 and 1.0 diff --git a/patches/hudfragmessages.patch b/patches/hudfragmessages.patch index 554ef5a..ceb942b 100644 --- a/patches/hudfragmessages.patch +++ b/patches/hudfragmessages.patch @@ -1,6 +1,6 @@ Index: src/Makefile =================================================================== ---- src/Makefile (revision 6469) +--- src/Makefile (revision 6471) +++ src/Makefile (working copy) @@ -125,6 +125,7 @@ fpsgame/client.o \ @@ -22,14 +22,14 @@ Index: src/Makefile shared/crypto-standalone.o: shared/ents.h shared/command.h shared/iengine.h Index: src/fpsgame/fps.cpp =================================================================== ---- src/fpsgame/fps.cpp (revision 6469) +--- src/fpsgame/fps.cpp (revision 6471) +++ src/fpsgame/fps.cpp (working copy) @@ -495,6 +495,8 @@ { if(d==player1) conoutf(contype, "\f2%s got fragged by %s", dname, aname); else conoutf(contype, "\f2%s fragged %s", aname, dname); -+ actor->fragmessages->add(fragmessage(aname, dname, d->lasthitpushgun)); -+ d->fragmessages->add(fragmessage(aname, dname, d->lasthitpushgun)); ++ addfragmessage(actor, aname, dname, d->lasthitpushgun); ++ addfragmessage(d, aname, dname, d->lasthitpushgun); } deathstate(d); ai::killed(d, actor); @@ -70,23 +70,31 @@ Index: src/fpsgame/fragmessages.cpp =================================================================== --- src/fpsgame/fragmessages.cpp (nonexistent) +++ src/fpsgame/fragmessages.cpp (working copy) -@@ -0,0 +1,54 @@ +@@ -0,0 +1,62 @@ +#include "game.h" +#include "fragmessage_type.h" + +namespace game { + VARP(hudfragmessages, 0, 1, 1); + VARP(hudfragmessageduration, 0, 1000, 10000); ++ VARP(maxhudfragmessages, 1, 3, 10); ++ FVARP(hudfragmessagex, 0, 0.5f, 1.0f); + FVARP(hudfragmessagey, 0, 0.25f, 1.0f); + FVARP(hudfragmessagescale, 0.1f, 0.5f, 1.0f); + ++ void addfragmessage(fpsent *c, const char *aname, const char *vname, int gun) ++ { ++ if(c->fragmessages->length()>=maxhudfragmessages) c->fragmessages->remove(0); ++ c->fragmessages->add(fragmessage(aname, vname, gun)); ++ } ++ + void drawfragmessages(fpsent *d, int w, int h) + { + if(d->fragmessages->empty()) return; + + float stepsize = (3*HICON_SIZE)/2; + float stepdir = hudfragmessagey>0.5 ? 1 : -1; -+ vec2 origin = vec2(.5f, hudfragmessagey).mul(vec2(w, h).div(hudfragmessagescale)); ++ vec2 origin = vec2(hudfragmessagex, hudfragmessagey).mul(vec2(w, h).div(hudfragmessagescale)); + + pushhudmatrix(); + hudmatrix.scale(hudfragmessagescale, hudfragmessagescale, 1); @@ -130,7 +138,7 @@ Index: src/fpsgame/fragmessages.h =================================================================== --- src/fpsgame/fragmessages.h (nonexistent) +++ src/fpsgame/fragmessages.h (working copy) -@@ -0,0 +1,12 @@ +@@ -0,0 +1,13 @@ +#ifndef __FRAGMESSAGES_H__ +#define __FRAGMESSAGES_H__ + @@ -139,6 +147,7 @@ Index: src/fpsgame/fragmessages.h +namespace game { + extern vector fragmessages; + extern int hudfragmessages; ++ extern void addfragmessage(fpsent *c, const char *aname, const char *vname, int gun); + extern void drawfragmessages(fpsent *d, int w, int h); +} + @@ -146,7 +155,7 @@ Index: src/fpsgame/fragmessages.h \ No newline at end of file Index: src/fpsgame/game.h =================================================================== ---- src/fpsgame/game.h (revision 6469) +--- src/fpsgame/game.h (revision 6471) +++ src/fpsgame/game.h (working copy) @@ -535,6 +535,8 @@ } @@ -162,7 +171,7 @@ Index: src/fpsgame/game.h int lastpain; int lastaction, lastattackgun; + int lasthitpushgun; -+ vector *fragmessages; ++ vector *fragmessages; // oldest first, newest at the end bool attacking; int attacksound, attackchan, idlesound, idlechan; int lasttaunt; @@ -201,7 +210,7 @@ Index: src/fpsgame/game.h extern const char *modename(int n, const char *unknown = "unknown"); Index: src/vcpp/sauerbraten.vcxproj =================================================================== ---- src/vcpp/sauerbraten.vcxproj (revision 6470) +--- src/vcpp/sauerbraten.vcxproj (revision 6471) +++ src/vcpp/sauerbraten.vcxproj (working copy) @@ -1078,6 +1078,20 @@ $(IntDir)game.pch diff --git a/src/fpsgame/fps.cpp b/src/fpsgame/fps.cpp index f8f8656..5bcea4a 100644 --- a/src/fpsgame/fps.cpp +++ b/src/fpsgame/fps.cpp @@ -498,8 +498,8 @@ namespace game { if(d==player1) conoutf(contype, "\f2%s got fragged by %s", dname, aname); else conoutf(contype, "\f2%s fragged %s", aname, dname); - actor->fragmessages->add(fragmessage(aname, dname, d->lasthitpushgun)); - d->fragmessages->add(fragmessage(aname, dname, d->lasthitpushgun)); + addfragmessage(actor, aname, dname, d->lasthitpushgun); + addfragmessage(d, aname, dname, d->lasthitpushgun); } deathstate(d); ai::killed(d, actor); diff --git a/src/fpsgame/fragmessages.cpp b/src/fpsgame/fragmessages.cpp index 7287a09..8aaea90 100644 --- a/src/fpsgame/fragmessages.cpp +++ b/src/fpsgame/fragmessages.cpp @@ -4,16 +4,24 @@ namespace game { VARP(hudfragmessages, 0, 1, 1); VARP(hudfragmessageduration, 0, 1000, 10000); + VARP(maxhudfragmessages, 1, 3, 10); + FVARP(hudfragmessagex, 0, 0.5f, 1.0f); FVARP(hudfragmessagey, 0, 0.25f, 1.0f); FVARP(hudfragmessagescale, 0.1f, 0.5f, 1.0f); + void addfragmessage(fpsent *c, const char *aname, const char *vname, int gun) + { + if(c->fragmessages->length()>=maxhudfragmessages) c->fragmessages->remove(0); + c->fragmessages->add(fragmessage(aname, vname, gun)); + } + void drawfragmessages(fpsent *d, int w, int h) { if(d->fragmessages->empty()) return; float stepsize = (3*HICON_SIZE)/2; float stepdir = hudfragmessagey>0.5 ? 1 : -1; - vec2 origin = vec2(.5f, hudfragmessagey).mul(vec2(w, h).div(hudfragmessagescale)); + vec2 origin = vec2(hudfragmessagex, hudfragmessagey).mul(vec2(w, h).div(hudfragmessagescale)); pushhudmatrix(); hudmatrix.scale(hudfragmessagescale, hudfragmessagescale, 1); diff --git a/src/fpsgame/fragmessages.h b/src/fpsgame/fragmessages.h index d9ab6f5..04efd52 100644 --- a/src/fpsgame/fragmessages.h +++ b/src/fpsgame/fragmessages.h @@ -6,6 +6,7 @@ namespace game { extern vector fragmessages; extern int hudfragmessages; + extern void addfragmessage(fpsent *c, const char *aname, const char *vname, int gun); extern void drawfragmessages(fpsent *d, int w, int h); } diff --git a/src/fpsgame/game.h b/src/fpsgame/game.h index d5f1c67..94d18f6 100644 --- a/src/fpsgame/game.h +++ b/src/fpsgame/game.h @@ -548,7 +548,7 @@ struct fpsent : dynent, fpsstate int lastpain; int lastaction, lastattackgun; int lasthitpushgun; - vector *fragmessages; + vector *fragmessages; // oldest first, newest at the end bool attacking; int attacksound, attackchan, idlesound, idlechan; int lasttaunt;