summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/GameTick.cpp282
1 files changed, 102 insertions, 180 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index 16f00bc..2800632 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -73,10 +73,11 @@ void Game::Splat(int k)
 		joint.velocity = {0, person[k].velocity.y, 0};
 	}
 
+	auto soundpos = head_joint.position - camera.position;
 	ALfloat gLoc[] {
-		(head_joint.position.x - camera.position.x) / soundscalefactor,
-		(head_joint.position.y - camera.position.x) / soundscalefactor,
-		(head_joint.position.z - camera.position.x) / soundscalefactor,
+		soundpos.x / soundscalefactor,
+		soundpos.y / soundscalefactor,
+		soundpos.z / soundscalefactor,
 	};
 	alSourcefv(gSourceID[headwhacksound], AL_POSITION, gLoc);
 	alSourcePlay(gSourceID[headwhacksound]);
@@ -2057,6 +2058,8 @@ void Game::Tick()
 		if (person[j].whichgun != grenade)
 			person[j].ammo--;
 
+		auto& joints = person[0].skeleton.joints;
+		auto& jointlabels = person[0].skeleton.jointlabels;
 		for (int p = 0; p < numshots; p++) {
 			XYZ aim;
 			if (j)
@@ -2067,159 +2070,84 @@ void Game::Tick()
 				aim = facing;
 			Normalise(&aim);
 
-			if(person[j].whichgun==sniperrifle){
-
-				start=person[j].playercoords+DoRotation(person[j].skeleton.joints[(person[j].skeleton.jointlabels[lefthand])].position,0,person[j].playerrotation,0);
-
-				float gLoc[3];
-
-				start-=DoRotation(DoRotation(DoRotation(aim,0,-person[j].playerrotation,0),90,0,0),0,person[j].playerrotation,0)*.35;
-
-				gLoc[0]=(camera.position.x+(start.x-camera.position.x)/4)/soundscalefactor;
-
-				gLoc[1]=(camera.position.y+(start.y-camera.position.y)/4)/soundscalefactor;
-
-				gLoc[2]=(camera.position.z+(start.z-camera.position.z)/4)/soundscalefactor;
-
-				alSourcefv(gSourceID[riflesound], AL_POSITION, gLoc);
-
-				alSourcePlay(gSourceID[riflesound]);
-
-				if(j==0){
-
-					if(person[j].currentanimation!=crouchanim)camera.rotation2-=7;
-
-					if(person[j].currentanimation==crouchanim)camera.rotation2-=3;
-
-				}
-
+			int aimjoint;
+			switch (person[j].whichgun) {
+			case handgun1:
+			case handgun2:
+				aimjoint = person[j].skeleton.jointlabels[rightwrist];
+				break;
+			default:
+				aimjoint = person[j].skeleton.jointlabels[lefthand];
 			}
-
-			if(person[j].whichgun==shotgun){
-
-				start=person[j].playercoords+DoRotation(person[j].skeleton.joints[(person[j].skeleton.jointlabels[lefthand])].position,0,person[j].playerrotation,0);
-
-				float gLoc[3];
-
-				start-=DoRotation(DoRotation(DoRotation(aim,0,-person[j].playerrotation,0),90,0,0),0,person[j].playerrotation,0)*.35;
-
-				if(p==numshots-1){
-
-				gLoc[0]=(camera.position.x+(start.x-camera.position.x)/4)/soundscalefactor;
-
-				gLoc[1]=(camera.position.y+(start.y-camera.position.y)/4)/soundscalefactor;
-
-				gLoc[2]=(camera.position.z+(start.z-camera.position.z)/4)/soundscalefactor;
-
-				alSourcefv(gSourceID[shotgunsound], AL_POSITION, gLoc);
-
-				alSourcePlay(gSourceID[shotgunsound]);
-
-				if(j==0){
-
-					if(person[j].currentanimation!=crouchanim)camera.rotation2-=7;
-
-					if(person[j].currentanimation==crouchanim)camera.rotation2-=3;
-
-				}
-
-				}
-
+			start = person[j].playercoords
+				+ DoRotation(person[j].skeleton.joints[aimjoint].position,
+					0, person[j].playerrotation, 0);
+
+			auto startsub = DoRotation(aim,
+				0, -person[j].playerrotation, 0);
+			startsub = DoRotation(startsub, 90, 0, 0);
+			startsub *= DoRotation(startsub,
+				0, person[j].playerrotation,0);
+			switch (person[j].whichgun) {
+			case sniperrifle:
+			case shotgun:
+				start -= startsub * 0.35f;
+				break;
+			case handgun1:
+			case handgun2:
+				start -= startsub * 0.55f;
+				break;
+			default: // assaultrifle
+				start -= startsub * 0.25f;
 			}
 
-			if(person[j].whichgun==handgun1){
-
-				start=person[j].playercoords+DoRotation(person[j].skeleton.joints[(person[j].skeleton.jointlabels[rightwrist])].position,0,person[j].playerrotation,0);
-
-				start-=DoRotation(DoRotation(DoRotation(aim,0,-person[j].playerrotation,0),90,0,0),0,person[j].playerrotation,0)*.55;
-
-				float gLoc[3];
-
-				gLoc[0]=(camera.position.x+(start.x-camera.position.x)/4)/soundscalefactor;
-
-				gLoc[1]=(camera.position.y+(start.y-camera.position.y)/4)/soundscalefactor;
-
-				gLoc[2]=(camera.position.z+(start.z-camera.position.z)/4)/soundscalefactor;
-
-				alSourcefv(gSourceID[pistol1sound], AL_POSITION, gLoc);
-
-				alSourcePlay(gSourceID[pistol1sound]);
-
-				if(j==0){
-
-					if(person[j].currentanimation!=crouchanim)camera.rotation2-=6;
-
-					if(person[j].currentanimation==crouchanim)camera.rotation2-=4;
-
+			if (p == numshots - 1) {
+				auto crouch = person[j].currentanimation == crouchanim;
+				float rot = 0.0f, rot2 = 0.0f;
+				switch (person[j].whichgun) {
+				case sniperrifle:
+				case shotgun:
+					rot2 = crouch ? 3.0f : 7.0f;
+					break;
+				case handgun1:
+					rot2 = crouch ? 4.0f : 6.0f;
+					break;
+				case handgun2:
+					rot2 = crouch ? 3.0f : 5.0f;
+					break;
+				case assaultrifle:
+					rot = Random() % 100 / (crouch ? 60.0f : 50.0f);
+					rot2 = crouch ? 1.5f : 2.3f;
+					break;
 				}
-
-			}
-
-			if(person[j].whichgun==handgun2){
-
-				start=person[j].playercoords+DoRotation(person[j].skeleton.joints[(person[j].skeleton.jointlabels[rightwrist])].position,0,person[j].playerrotation,0);
-
-				start-=DoRotation(DoRotation(DoRotation(aim,0,-person[j].playerrotation,0),90,0,0),0,person[j].playerrotation,0)*.55;
-
-				float gLoc[3];
-
-				gLoc[0]=(camera.position.x+(start.x-camera.position.x)/4)/soundscalefactor;
-
-				gLoc[1]=(camera.position.y+(start.y-camera.position.y)/4)/soundscalefactor;
-
-				gLoc[2]=(camera.position.z+(start.z-camera.position.z)/4)/soundscalefactor;
-
-				alSourcefv(gSourceID[pistol2sound], AL_POSITION, gLoc);
-
-				alSourcePlay(gSourceID[pistol2sound]);
-
-				if(j==0){
-
-					if(person[j].currentanimation!=crouchanim)camera.rotation2-=5;
-
-					if(person[j].currentanimation==crouchanim)camera.rotation2-=3;
-
-				}
-
-			}
-
-			if(person[j].whichgun==assaultrifle){
-				start=person[j].playercoords+DoRotation(person[j].skeleton.joints[(person[j].skeleton.jointlabels[lefthand])].position,0,person[j].playerrotation,0);
-
-				start-=DoRotation(DoRotation(DoRotation(aim,0,-person[j].playerrotation,0),90,0,0),0,person[j].playerrotation,0)*.25;
-
-				float gLoc[3];
-
-				gLoc[0]=(camera.position.x+(start.x-camera.position.x)/4)/soundscalefactor;
-
-				gLoc[1]=(camera.position.y+(start.y-camera.position.y)/4)/soundscalefactor;
-
-				gLoc[2]=(camera.position.z+(start.z-camera.position.z)/4)/soundscalefactor;
-
-				alSourcefv(gSourceID[machinegunsound], AL_POSITION, gLoc);
-
-				alSourcePlay(gSourceID[machinegunsound]);
-
-				if(j==0){
-
-					if(person[j].currentanimation!=crouchanim){
-
-						camera.rotation2-=2.3;
-
-						camera.rotation+=(float)(Random()%100)/50;
-
-					}
-
-					if(person[j].currentanimation==crouchanim){
-
-						camera.rotation2-=1.5;
-
-						camera.rotation+=(float)(Random()%100)/60;
-
-					}
-
+				camera.rotation -= rot;
+				camera.rotation2 -= rot2;
+
+				auto soundpos = start - camera.position;
+				ALfloat gLoc[] {
+					soundpos.x / 4 / soundscalefactor,
+					soundpos.y / 4 / soundscalefactor,
+					soundpos.z / 4 / soundscalefactor,
+				};
+				ALuint gunsound;
+				switch (person[j].whichgun) {
+				case sniperrifle:
+					gunsound = gSourceID[riflesound];
+					break;
+				case shotgun:
+					gunsound = gSourceID[shotgunsound];
+					break;
+				case handgun1:
+					gunsound = gSourceID[pistol1sound];
+					break;
+				case handgun2:
+					gunsound = gSourceID[pistol2sound];
+					break;
+				default: // assaultrifle
+					gunsound = gSourceID[machinegunsound];
 				}
-
+				alSourcefv(gunsound, AL_POSITION, gLoc);
+				alSourcePlay(gunsound);
 			}
 
 			XYZ end {start + aim * 1000};
@@ -3125,22 +3053,18 @@ void Game::Tick()
 
 					sprites.velocity[i]*=.3;
 
-					if(sprites.type[i]==grenadesprite){
-
-						float gLoc[3];
-
-						gLoc[0]=(((sprites.location[i].x)-camera.position.x)/findLengthfast(sprites.velocity[i])*5+camera.position.x)/soundscalefactor;
-
-						gLoc[1]=(((sprites.location[i].y)-camera.position.y)/findLengthfast(sprites.velocity[i])*5+camera.position.y)/soundscalefactor;
-
-						gLoc[2]=(((sprites.location[i].z)-camera.position.z)/findLengthfast(sprites.velocity[i])*5+camera.position.z)/soundscalefactor;
-
-						whichsound=abs(Random()%2);
-
-						alSourcefv(gSourceID[bouncesound+whichsound], AL_POSITION, gLoc);
-
-						if(sprites.size[i]<=1)alSourcePlay(gSourceID[bouncesound+whichsound]);
-
+					if (sprites.type[i] == grenadesprite
+					    && sprites.size[i] <= 1) {
+						auto soundpos = sprites.location[i] - camera.position;
+						auto v = findLengthfast(sprites.velocity[i]) * 0.2;
+						ALfloat gLoc[] {
+							soundpos.x / v / soundscalefactor,
+							soundpos.y / v / soundscalefactor,
+							soundpos.z / v / soundscalefactor,
+						};
+						whichsound = bouncesound + abs(Random()%2);
+						alSourcefv(gSourceID[whichsound], AL_POSITION, gLoc);
+						alSourcePlay(gSourceID[whichsound]);
 					}
 
 					if(findLengthfast(sprites.velocity[i])<=10)sprites.velocity[i]=0;
@@ -3175,19 +3099,17 @@ void Game::Tick()
 
 						}
 
-						float gLoc[3];
-
-						gLoc[0]=(((sprites.location[i].x)-camera.position.x)/findLengthfast(sprites.velocity[i])*5+camera.position.x)/soundscalefactor;
-
-						gLoc[1]=(((sprites.location[i].y)-camera.position.y)/findLengthfast(sprites.velocity[i])*5+camera.position.y)/soundscalefactor;
-
-						gLoc[2]=(((sprites.location[i].z)-camera.position.z)/findLengthfast(sprites.velocity[i])*5+camera.position.z)/soundscalefactor;
-
-						whichsound=abs(Random()%2);
-
-						alSourcefv(gSourceID[bouncesound+whichsound], AL_POSITION, gLoc);
-
-						if(sprites.size[i]<=1)alSourcePlay(gSourceID[bouncesound+whichsound]);
+						auto soundpos = sprites.location[i] - camera.position;
+						auto v = findLengthfast(sprites.velocity[i]) * 0.2;
+						ALfloat gLoc[] {
+							soundpos.x / v / soundscalefactor,
+							soundpos.y / v / soundscalefactor,
+							soundpos.z / v / soundscalefactor,
+						};
+						whichsound = bouncesound + abs(Random()%2);
+						alSourcefv(gSourceID[whichsound], AL_POSITION, gLoc);
+						if (sprites.size[i] <= 1)
+							alSourcePlay(gSourceID[whichsound]);
 
 					}