shithub: qk1

Download patch

ref: 4c1435a0346ab111b5d9fec0abf5910952b7950e
parent: d055c88eb3b78fde7e532fd28025893b5d28fc25
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Fri Dec 15 11:35:23 EST 2023

DP_EF_ADDITIVE

--- a/d_local.h
+++ b/d_local.h
@@ -73,22 +73,22 @@
 extern int d_minmip;
 extern float d_scalemip[3];
 
-#define blendalpha(ca, cb, alpha) \
-	((((alpha)*(((ca)>> 0)&0xff) + (255-(alpha))*(((cb)>> 0)&0xff))>> 8) << 0 | \
-	 (((alpha)*(((ca)>> 8)&0xff) + (255-(alpha))*(((cb)>> 8)&0xff))>> 8) << 8 | \
-	 (((alpha)*(((ca)>>16)&0xff) + (255-(alpha))*(((cb)>>16)&0xff))>> 8) << 16)
-
-/*
 static inline pixel_t
 blendalpha(pixel_t ca, pixel_t cb, int alpha)
 {
-	//pixel_t x;
-	//x.r = alpha*ca.r + (255-alpha)*cb.r;
-	//x.g = alpha*ca.g + (255-alpha)*cb.g;
-	//x.b = alpha*ca.b + (255-alpha)*cb.b;
-	USED(cb);
-	USED(alpha);
-	return ca;
+	int a, b, c;
+
+	if(currententity != nil && currententity->effects & EF_ADDITIVE){
+		a = (alpha*((ca>> 0)&0xff) + 255*((cb>> 0)&0xff))>> 8;
+		b = (alpha*((ca>> 8)&0xff) + 255*((cb>> 8)&0xff))>> 8;
+		c = (alpha*((ca>>16)&0xff) + 255*((cb>>16)&0xff))>> 8;
+		return min(a, 255) | min(b, 255)<<8 | min(c, 255)<<16;
+	}
+
+	return
+		((alpha*((ca>> 0)&0xff) + (255-alpha)*((cb>> 0)&0xff))>> 8) << 0 |
+		((alpha*((ca>> 8)&0xff) + (255-alpha)*((cb>> 8)&0xff))>> 8) << 8 |
+		((alpha*((ca>>16)&0xff) + (255-alpha)*((cb>>16)&0xff))>> 8) << 16;
 }
-*/
+
 float alphafor(int flags);
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -1629,6 +1629,7 @@
 }
 
 static const char *exts[] = {
+	"DP_EF_ADDITIVE",
 	"DP_EF_NODRAW",
 	"DP_QC_ASINACOSATANATAN2TAN",
 	"DP_QC_MINMAXBOUND",
--- a/r_draw.c
+++ b/r_draw.c
@@ -53,12 +53,12 @@
 int
 entdrawflags(entity_t *e)
 {
-	if(e != nil){
+	if(e == nil || e->model == nil)
+		return DRAW_NO;
+	if(e->model != cl.worldmodel){
 		if(e->effects & EF_NODRAW)
 			return DRAW_NO;
-		if(!defalpha(e->alpha))
-			return DRAW_BLEND;
-		if(e->model != nil && e->model != cl.worldmodel && e->model->blend)
+		if(e->model->blend || (e->effects & EF_ADDITIVE) || !defalpha(e->alpha))
 			return DRAW_BLEND;
 	}
 	return 0;
--- a/r_surf.c
+++ b/r_surf.c
@@ -283,6 +283,9 @@
 	if((x & 0xff000000U) == 0)
 		return x;
 
+	if(currententity != nil && (currententity->effects & EF_ADDITIVE) != 0)
+		return x;
+
 	r = (x>>16) & 0xff;
 	g = (x>>8)  & 0xff;
 	b = (x>>0)  & 0xff;
--- a/server.h
+++ b/server.h
@@ -147,6 +147,7 @@
 	EF_BRIGHTLIGHT = 1<<2,
 	EF_DIMLIGHT = 1<<3,
 	EF_NODRAW = 1<<4,
+	EF_ADDITIVE = 1<<5,
 
 	SPAWNFLAG_NOT_EASY = 1<<8,
 	SPAWNFLAG_NOT_MEDIUM = 1<<9,