about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNguyễn Gia Phong <cnx@loang.net>2023-08-25 03:07:59 +0900
committerNguyễn Gia Phong <cnx@loang.net>2023-08-25 03:07:59 +0900
commitd08aaf50515cf3fcf03e6523976258b02f6b2e95 (patch)
tree08a1eaf05b05b41c3c612769e1b249eef41b9c46 /src
parent95cdcaf3214a29cbe6ea5d39ac4616eefd963b03 (diff)
downloadblackshades-d08aaf50515cf3fcf03e6523976258b02f6b2e95.tar.gz
Narrow visions flag to a bool
Diffstat (limited to 'src')
-rw-r--r--src/GameDraw.cpp23
-rw-r--r--src/GameInitDispose.cpp8
-rw-r--r--src/GameLoop.cpp4
-rw-r--r--src/GameTick.cpp14
-rw-r--r--src/Globals.cpp2
-rw-r--r--src/Person.cpp22
-rw-r--r--src/Skeleton.cpp1
-rw-r--r--src/decal.zig1
-rw-r--r--src/geom.zig1
9 files changed, 48 insertions, 28 deletions
diff --git a/src/GameDraw.cpp b/src/GameDraw.cpp
index b97f814..6db98b9 100644
--- a/src/GameDraw.cpp
+++ b/src/GameDraw.cpp
@@ -29,7 +29,7 @@
 extern int thirdperson;
 extern float multiplier;
 extern int nocolors;
-extern int visions;
+extern bool visions;
 extern unsigned int gSourceID[37];
 extern Camera camera;
 extern Sprites sprites;
@@ -459,13 +459,17 @@ void Game::DrawGLScene(void)
 			glEnable(GL_LIGHTING);
 			glTranslatef(camera.position.x,0,camera.position.z);
 			glScalef(viewdistance*5/100,1,viewdistance*5/100);
-			if(visions==0)street.draw(.22,.22,.22);
-			if(visions==1)street.draw(0,0,0);
+			if (visions)
+				street.draw(0.0f, 0.0f, 0.0f);
+			else
+				street.draw(0.22f, 0.22f, 0.22f);
 			glEnable(GL_DEPTH_TEST);
 			glDepthMask(1);
 		glPopMatrix();
-		if(visions==0)glEnable(GL_LIGHTING);
-		if(visions==1)glDisable(GL_LIGHTING);
+		if (visions)
+			glDisable(GL_LIGHTING);
+		else
+			glEnable(GL_LIGHTING);
 
 		//Draw blocks
 		glEnable(GL_BLEND);
@@ -625,8 +629,10 @@ void Game::DrawGLScene(void)
 						if(person[i].skeleton.free==0){
 							glTranslatef(person[i].playercoords.x,person[i].playercoords.y,person[i].playercoords.z);
 							glRotatef(person[i].playerrotation,0,1,0);
-							if(i!=0||visions==0)person[i].DoAnimations(i);
-							if(i==0&&visions==1)person[i].DoAnimationslite(i);
+							if (i != 0 || !visions)
+								person[i].DoAnimations(i);
+							else
+								person[i].DoAnimationslite(i);
 						}
 						if(visions==1)nocolors=1;
 						if(visions==1&&person[i].type==eviltype)nocolors=2;
@@ -669,7 +675,8 @@ void Game::DrawGLScene(void)
 					glDepthMask(1);
 					glDisable(GL_TEXTURE_2D);
 					glEnable(GL_CULL_FACE);
-					if(visions!=1)glEnable(GL_LIGHTING);
+					if (!visions)
+						glEnable(GL_LIGHTING);
 				}
 			}
 			if(person[i].skeleton.free<1&&!draw)person[i].DoAnimationslite(i);
diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp
index fe5dc05..51c8b13 100644
--- a/src/GameInitDispose.cpp
+++ b/src/GameInitDispose.cpp
@@ -39,7 +39,7 @@ extern Model skeletonmodels[10];
 extern Model gunmodels[10];
 extern Costume costume[10];
 extern Animation animation[30];
-extern int visions;
+extern bool visions;
 extern float rad2deg;
 extern Fog fog;
 extern bool blood;
@@ -229,9 +229,9 @@ void initGame(Game* game)
 	game->timeremaining = level.time;
 	game->difficulty = level.difficulty;
 
-	//Setup fast radian to degree conversion
-	rad2deg= 56.54866776;
-	visions=0;
+	// Setup fast radian to degree conversion
+	rad2deg = 56.54866776;
+	visions = false;
 
 	//Setup bounding cylinder model
 	float boundingscale=3;
diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp
index bc23f22..66b7395 100644
--- a/src/GameLoop.cpp
+++ b/src/GameLoop.cpp
@@ -26,7 +26,7 @@
 
 extern float multiplier;
 extern int thirdperson;
-extern int visions;
+extern bool visions;
 extern float soundscalefactor;
 extern unsigned int gSourceID[37];
 extern Camera camera;
@@ -222,7 +222,7 @@ void eventLoop(Game* game)
 
 	do multiplier = glfwGetTime() - start;
 	while (multiplier < 1.0f / 69);
-	if (visions == 1 && !game->menu)
+	if (visions && !game->menu)
 		multiplier /= 3;
 	if (slomo)
 		multiplier /= 5;
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index 7fa90fa..e71d8dd 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -29,7 +29,7 @@
 
 extern float multiplier;
 extern int thirdperson;
-extern int visions;
+extern bool visions;
 extern Sprites sprites;
 extern unsigned int gSourceID[37];
 extern Camera camera;
@@ -1309,7 +1309,8 @@ void Game::Tick()
 						    && sqrlen(person[i].playercoords - person[person[i].killtarget].playercoords) > 30000)
 							person[i].killtargetvisible = 0;
 
-						if(person[i].killtarget==0&&visions==1)person[i].killtargetvisible=0;
+						if (person[i].killtarget == 0 && visions)
+							person[i].killtargetvisible = 0;
 
 						if(person[i].killtargetvisible){
 							beginx=person[i].whichblockx-2;
@@ -1472,8 +1473,11 @@ void Game::Tick()
 
 			person[i].whichblockx=((person[i].playercoords.x+block_spacing/2)/block_spacing);
 			person[i].whichblocky=((person[i].playercoords.z+block_spacing/2)/block_spacing);
-			if(!person[i].onground)person[i].velocity.y+=multiplier*gravity;
-			if(!person[i].onground&&(i!=0||visions!=1))person[i].playercoords+=person[i].velocity*multiplier;
+			if (!person[i].onground) {
+				person[i].velocity.y += multiplier * gravity;
+				if (i != 0 || !visions)
+					person[i].playercoords += person[i].velocity * multiplier;
+			}
 
 			//Death by bleeding/shock
 			if(person[i].health<=0){
@@ -1558,7 +1562,7 @@ void Game::Tick()
 	}
 
 	attackCloseRange(this, flatfacing);
-	if (person[0].currentanimation == diveanim && visions == 0)
+	if (person[0].currentanimation == diveanim && !visions)
 		tackle(this, flatfacing);
 
 	// Empty magazine
diff --git a/src/Globals.cpp b/src/Globals.cpp
index 2adfd22..1c5d2c1 100644
--- a/src/Globals.cpp
+++ b/src/Globals.cpp
@@ -30,7 +30,7 @@ Sprites sprites;
 Decals decals;
 int thirdperson;
 int nocolors;
-int visions;
+bool visions;
 Camera camera;
 float rad2deg;
 Skeleton testskeleton;
diff --git a/src/Person.cpp b/src/Person.cpp
index 0115a89..1c5ce32 100644
--- a/src/Person.cpp
+++ b/src/Person.cpp
@@ -29,7 +29,7 @@ extern float multiplier;
 extern unsigned int gSourceID[37];
 extern Animation animation[30];
 extern int thirdperson;
-extern int visions;
+extern bool visions;
 extern Camera camera;
 extern float rad2deg;
 extern Model gunmodels[10];
@@ -671,10 +671,9 @@ void Person::DoStuff(int who)
 		playerrotation = playerlowrotation - 70;
 	}
 
-	if (who == 0)
+	if (who == 0) {
 		camera.rotation = 180 - playerrotation;
-
-	if(who!=0&&visions==0){
+	} else if (!visions) {
 		if(targetanimation!=walkanim&&targetanimation!=zombiewalkanim)speed=1.0*speedmult;
 		if(targetanimation==walkanim||targetanimation==zombiewalkanim)speed=1.8*speedmult;
 		playerlowrotation=playerrotation;
@@ -694,12 +693,23 @@ void Person::DoStuff(int who)
 
 	if(onground)
 		velocity = {};
-	if(((currentanimation==joganim||currentanimation==zombiejoganim||currentanimation==diveanim)&&onground)||(who==0&&visions==1&&((currentanimation==joganim||currentanimation==walkanim||currentanimation==diveanim)||(currentanimation==zombiejoganim||currentanimation==zombiewalkanim)))){
+	if (((currentanimation == joganim
+	      || currentanimation == zombiejoganim
+	      || currentanimation == diveanim)
+	     && onground)
+	    || ((currentanimation == joganim
+	         || currentanimation == zombiejoganim
+	         || currentanimation == diveanim
+	         || currentanimation == walkanim
+	         || currentanimation == zombiewalkanim)
+	        && who == 0 && visions)) {
 		playercoords+=facing*multiplier*15*speed;
 		velocity.x=facing.x*15*speed;
 		velocity.z=facing.z*15*speed;
 	}
-	if((currentanimation==walkanim||currentanimation==zombiewalkanim)&&onground&&(who!=0||visions==0)){
+	if ((currentanimation == walkanim
+	     || currentanimation == zombiewalkanim)
+	    && onground && (who != 0 || !visions)) {
 		playercoords+=facing*multiplier*4*speed;
 		velocity.x=facing.x*4*speed;
 		velocity.z=facing.z*4*speed;
diff --git a/src/Skeleton.cpp b/src/Skeleton.cpp
index 8d5ae3b..b01e27d 100644
--- a/src/Skeleton.cpp
+++ b/src/Skeleton.cpp
@@ -6,7 +6,6 @@
 
 extern float multiplier;
 extern unsigned int gSourceID[37];
-extern int visions;
 extern float rad2deg;
 extern Camera camera;
 extern float soundscalefactor;
diff --git a/src/decal.zig b/src/decal.zig
index de4d9e8..a89fc22 100644
--- a/src/decal.zig
+++ b/src/decal.zig
@@ -18,7 +18,6 @@
 // You should have received a copy of the GNU General Public License
 // along with Black Shades.  If not, see <https://www.gnu.org/licenses/>.
 
-//const f32Eps = std.math.floatEps(f32);
 const XYZ = @import("geom.zig").XYZ;
 const c = @import("cimport.zig");
 
diff --git a/src/geom.zig b/src/geom.zig
index d6dc036..5727a39 100644
--- a/src/geom.zig
+++ b/src/geom.zig
@@ -115,6 +115,7 @@ export fn segCrossTrigon(start: XYZ, end: XYZ,
     if (mu < 0 or mu > 1)
         return false; // intersection not within segment
 
+    // Check if intersection is in the triangle
     const n_abs = @fabs(n);
     const n_max = @reduce(.Max, n_abs);
     const k: struct { usize, usize } = if (n_max == n_abs[0])