From 081c113234f3dafb6ada39a160e5b48eb0921035 Mon Sep 17 00:00:00 2001
From: havoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Sat, 12 Mar 2011 10:56:44 +0000
Subject: [PATCH] significant speed gain on collision_cache 1 by tweaking some
 numbers

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10910 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=7df6ca291a248ce599e9a36b6eba1ad8af48d494
---
 collision.c | 14 ++++++++------
 todo        |  1 +
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/collision.c b/collision.c
index fbc8a1cb..34389136 100644
--- a/collision.c
+++ b/collision.c
@@ -1693,6 +1693,7 @@ static int collision_cachedtrace_firstfree;
 static int collision_cachedtrace_lastused;
 static int collision_cachedtrace_max;
 static int collision_cachedtrace_sequence;
+static int collision_cachedtrace_hashsize;
 static int *collision_cachedtrace_hash;
 
 void Collision_Cache_Reset(qboolean resetlimits)
@@ -1705,8 +1706,9 @@ void Collision_Cache_Reset(qboolean resetlimits)
 		collision_cachedtrace_max = 1024;
 	collision_cachedtrace_firstfree = 1;
 	collision_cachedtrace_lastused = 0;
+	collision_cachedtrace_hashsize = collision_cachedtrace_max * 2;
 	collision_cachedtrace_array = (collision_cachedtrace_t *)Mem_Alloc(collision_cachedtrace_mempool, collision_cachedtrace_max * sizeof(collision_cachedtrace_t));
-	collision_cachedtrace_hash = (int *)Mem_Alloc(collision_cachedtrace_mempool, collision_cachedtrace_max * sizeof(int));
+	collision_cachedtrace_hash = (int *)Mem_Alloc(collision_cachedtrace_mempool, collision_cachedtrace_hashsize * sizeof(int));
 	collision_cachedtrace_sequence = 1;
 }
 
@@ -1722,7 +1724,7 @@ void Collision_Cache_NewFrame(void)
 	int index;
 	int *p;
 	// unlink all stale traces
-	for (hashindex = 0;hashindex < collision_cachedtrace_max;hashindex++)
+	for (hashindex = 0;hashindex < collision_cachedtrace_hashsize;hashindex++)
 	{
 		if (!collision_cachedtrace_hash[hashindex])
 			continue;
@@ -1766,18 +1768,18 @@ static collision_cachedtrace_t *Collision_Cache_Lookup(dp_model_t *model, const
 	else
 	{
 		// cached trace lookup
-		hashindex = (int)(((size_t)model + (size_t) + (size_t)(VectorLength2(bodymins) + VectorLength2(bodymaxs) + start[0] + start[1] + start[2] + end[0] + end[1] + end[2]) + bodysupercontents + hitsupercontentsmask) % collision_cachedtrace_max);
+		hashindex = (int)(((size_t)model + (size_t) + (size_t)(start[0] * 53 + start[1] * 207 + start[2] * 97 + end[0] * 37 + end[1] * 743 + end[2] * 13) + bodysupercontents + hitsupercontentsmask) % collision_cachedtrace_hashsize);
 		for (index = collision_cachedtrace_hash[hashindex];index;index = cached->next)
 		{
 			cached = collision_cachedtrace_array + index;
-			if (cached->model == model
+			if (VectorCompare(cached->start, start)
+			 && VectorCompare(cached->end, end)
+			 && cached->model == model
 			 && VectorCompare(cached->bodymins, bodymins)
 			 && VectorCompare(cached->bodymaxs, bodymaxs)
 			 && cached->bodysupercontents == bodysupercontents
-			 && VectorCompare(cached->start, start)
 			 && VectorCompare(cached->mins, mins)
 			 && VectorCompare(cached->maxs, maxs)
-			 && VectorCompare(cached->end, end)
 			 && cached->hitsupercontentsmask == hitsupercontentsmask
 			 && !memcmp(&cached->matrix, matrix, sizeof(*matrix)))
 			{
diff --git a/todo b/todo
index c9790741..0306ca48 100644
--- a/todo
+++ b/todo
@@ -27,6 +27,7 @@
 0 bug darkplaces d3d9: alphatest not working (VorteX)
 0 bug darkplaces d3d9: gamma not working (VorteX)
 0 bug darkplaces d3d9: shadowmaps are clipped - does this mean r_shadows 2 or light shadowmaps? (VorteX)
+0 bug darkplaces d3d9: water/refraction/reflection/warp render scissor is wrong (SavageX)
 0 bug darkplaces effects: add a cvar to disable colored dlights (leileilol)
 0 bug darkplaces effects: dlights don't look anything like quake ones, bring back lightmap dlights as a cvar - with both classic and old dp falloff modes (leileilol)
 0 bug darkplaces effects: quake mode blood trails don't have the appropriate slight gravity - there may be other effects missing this also (leileilol)
-- 
2.39.5