Skip to content
This repository was archived by the owner on Jul 7, 2024. It is now read-only.

Commit accee12

Browse files
author
ewasylishen
committed
AllocBlock: cache index of last used lightmap, start search there
Can speed up map loading by multiple seconds on levels with a lot of lightmaps, at a cost of using slightly more lightmaps (about 5% more). https://sourceforge.net/p/quakespasm/patches/20/ git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@956 af15c1b1-3010-417e-b628-4374ebc0bcbd
1 parent 7a02718 commit accee12

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

quakespasm/Quake/r_brush.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ qboolean lightmap_modified[MAX_LIGHTMAPS];
4545
glRect_t lightmap_rectchange[MAX_LIGHTMAPS];
4646

4747
int allocated[MAX_LIGHTMAPS][BLOCK_WIDTH];
48+
int last_lightmap_allocated; //ericw -- optimization: remember the index of the last lightmap AllocBlock stored a surf in
4849

4950
// the lightmap texture data needs to be kept in
5051
// main memory so texsubimage can update properly
@@ -716,7 +717,12 @@ int AllocBlock (int w, int h, int *x, int *y)
716717
int best, best2;
717718
int texnum;
718719

719-
for (texnum=0 ; texnum<MAX_LIGHTMAPS ; texnum++)
720+
// ericw -- rather than searching starting at lightmap 0 every time,
721+
// start at the last lightmap we allocated a surface in.
722+
// This makes AllocBlock much faster on large levels (can shave off 3+ seconds
723+
// of load time on a level with 180 lightmaps), at a cost of not quite packing
724+
// lightmaps as tightly vs. not doing this (uses ~5% more lightmaps)
725+
for (texnum=last_lightmap_allocated ; texnum<MAX_LIGHTMAPS ; texnum++, last_lightmap_allocated++)
720726
{
721727
best = BLOCK_HEIGHT;
722728

@@ -865,6 +871,7 @@ void GL_BuildLightmaps (void)
865871
qmodel_t *m;
866872

867873
memset (allocated, 0, sizeof(allocated));
874+
last_lightmap_allocated = 0;
868875

869876
r_framecount = 1; // no dlightcache
870877

0 commit comments

Comments
 (0)