hopefully make everything happy with the new bsp struct

This commit is contained in:
Bill Currie 2002-09-20 22:31:44 +00:00
parent c1c68830c5
commit 00294f7ae0
6 changed files with 64 additions and 66 deletions

View file

@ -55,10 +55,11 @@ void LightFace (int surfnum);
void LightLeaf (dleaf_t *leaf); void LightLeaf (dleaf_t *leaf);
void MakeTnodes (dmodel_t *bm); void MakeTnodes (dmodel_t *bm);
byte *GetFileSpace (int size); int GetFileSpace (int size);
void TransformSample (vec3_t in, vec3_t out); void TransformSample (vec3_t in, vec3_t out);
void RotateSample (vec3_t in, vec3_t out); void RotateSample (vec3_t in, vec3_t out);
extern struct bsp_s *bsp; extern struct bsp_s *bsp;
extern struct dstring_s *lightdata;
#endif// __light_h #endif// __light_h

View file

@ -36,8 +36,8 @@
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_H
#include <pthread.h> #include <pthread.h>
extern pthread_mutex_t *my_mutex; extern pthread_mutex_t *my_mutex;
#define LOCK pthread_mutex_lock (my_mutex) #define LOCK do { if (options.threads > 1) pthread_mutex_lock (my_mutex); } while (0);
#define UNLOCK pthread_mutex_unlock (my_mutex) #define UNLOCK do { if (options.threads > 1) pthread_mutex_unlock (my_mutex); } while (0);
#else #else
#define LOCK #define LOCK
#define UNLOCK #define UNLOCK

View file

@ -274,14 +274,12 @@ GetVectorForKey (entity_t *ent, char *key, vec3_t vec)
void void
WriteEntitiesToString (void) WriteEntitiesToString (void)
{ {
char *buf, *end; dstring_t *buf;
char line[128]; char line[128];
epair_t *ep; epair_t *ep;
int i; int i;
buf = bsp->entdata; buf = dstring_newstr ();
end = buf;
*end = 0;
if (options.verbosity >= 0) if (options.verbosity >= 0)
printf ("%i switchable light styles\n", numlighttargets); printf ("%i switchable light styles\n", numlighttargets);
@ -291,19 +289,13 @@ WriteEntitiesToString (void)
if (!ep) if (!ep)
continue; // ent got removed continue; // ent got removed
strcat (end, "{\n"); dstring_appendstr (buf, "{\n");
end += 2;
for (ep = entities[i].epairs; ep; ep = ep->next) { for (ep = entities[i].epairs; ep; ep = ep->next) {
sprintf (line, "\"%s\" \"%s\"\n", ep->key, ep->value); sprintf (line, "\"%s\" \"%s\"\n", ep->key, ep->value);
strcat (end, line); dstring_appendstr (buf, line);
end += strlen (line);
} }
strcat (end, "}\n"); dstring_appendstr (buf, "}\n");
end += 2;
if (end > buf + MAX_MAP_ENTSTRING)
fprintf (stderr, "Entity text too long");
} }
bsp->entdatasize = end - buf + 1; BSP_AddEntities (bsp, buf->str, buf->size);
} }

View file

@ -54,6 +54,7 @@ static const char rcsid[] =
#include "light.h" #include "light.h"
#include "entities.h" #include "entities.h"
#include "options.h" #include "options.h"
#include "threads.h"
#define SINGLEMAP (18*18*4) #define SINGLEMAP (18*18*4)
@ -451,7 +452,8 @@ FixMinlight (lightinfo_t *l)
void void
LightFace (int surfnum) LightFace (int surfnum)
{ {
byte *out; int ofs;
byte *out;
dface_t *f; dface_t *f;
int lightmapwidth, lightmapsize, size, c, i, j, s, t, w, h; int lightmapwidth, lightmapsize, size, c, i, j, s, t, w, h;
lightinfo_t l; lightinfo_t l;
@ -513,8 +515,11 @@ LightFace (int surfnum)
lightmapsize = size * l.numlightstyles; lightmapsize = size * l.numlightstyles;
out = GetFileSpace (lightmapsize); LOCK;
f->lightofs = out - filebase; out = malloc (lightmapsize);
UNLOCK;
ofs = GetFileSpace (lightmapsize);
f->lightofs = ofs;
// extra filtering // extra filtering
h = (l.texsize[1] + 1) * 2; h = (l.texsize[1] + 1) * 2;
@ -544,4 +549,8 @@ LightFace (int surfnum)
*out++ = total; *out++ = total;
} }
} }
LOCK;
memcpy (lightdata->str + ofs, out, lightmapsize);
free (out);
UNLOCK;
} }

View file

@ -65,7 +65,7 @@ char *bspfile;
float scalecos = 0.5; float scalecos = 0.5;
byte *filebase, *file_p, *file_end; dstring_t *lightdata;
dmodel_t *bspmodel; dmodel_t *bspmodel;
int bspfileface; // next surface to dispatch int bspfileface; // next surface to dispatch
@ -77,19 +77,18 @@ qboolean extrasamples;
float minlights[MAX_MAP_FACES]; float minlights[MAX_MAP_FACES];
byte * int
GetFileSpace (int size) GetFileSpace (int size)
{ {
byte *buf; int ofs;
LOCK; LOCK;
file_p = (byte *) (((long) file_p + 3) & ~3); lightdata->size = (lightdata->size + 3) & 3;
buf = file_p; ofs = lightdata->size;
file_p += size; lightdata->size += size;
dstring_adjust (lightdata);
UNLOCK; UNLOCK;
if (file_p > file_end) return ofs;
fprintf (stderr, "GetFileSpace: overrun");
return buf;
} }
void * void *
@ -111,12 +110,11 @@ LightThread (void *junk)
void void
LightWorld (void) LightWorld (void)
{ {
filebase = file_p = bsp->lightdata; lightdata = dstring_new ();
file_end = filebase + MAX_MAP_LIGHTING;
RunThreadsOn (LightThread); RunThreadsOn (LightThread);
bsp->lightdatasize = file_p - filebase; BSP_AddLighting (bsp, lightdata->str, lightdata->size);
if (options.verbosity >= 0) if (options.verbosity >= 0)
printf ("lightdatasize: %i\n", bsp->lightdatasize); printf ("lightdatasize: %i\n", bsp->lightdatasize);

View file

@ -46,28 +46,29 @@ static const char rcsid[] =
#include "QF/qtypes.h" #include "QF/qtypes.h"
#include "QF/qendian.h" #include "QF/qendian.h"
#include "options.h"
#include "threads.h" #include "threads.h"
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_H
int numthreads = 4;
pthread_mutex_t *my_mutex; pthread_mutex_t *my_mutex;
#else
int numthreads = 1;
#endif #endif
void void
InitThreads (void) InitThreads (void)
{ {
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_H
pthread_mutexattr_t mattrib; if (options.threads > 1) {
pthread_mutexattr_t mattrib;
my_mutex = malloc (sizeof (*my_mutex)); my_mutex = malloc (sizeof (*my_mutex));
if (pthread_mutexattr_init (&mattrib) == -1) if (pthread_mutexattr_init (&mattrib) == -1)
fprintf (stderr, "pthread_mutex_attr_init failed"); fprintf (stderr, "pthread_mutex_attr_init failed");
// if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1) // if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
// fprintf (stderr, "pthread_mutexattr_setkind_np failed"); // fprintf (stderr, "pthread_mutexattr_setkind_np failed");
if (pthread_mutex_init (my_mutex, &mattrib) == -1) if (pthread_mutex_init (my_mutex, &mattrib) == -1)
fprintf (stderr, "pthread_mutex_init failed"); fprintf (stderr, "pthread_mutex_init failed");
}
#endif #endif
} }
@ -75,31 +76,28 @@ void
RunThreadsOn (threadfunc_t *func) RunThreadsOn (threadfunc_t *func)
{ {
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_H
pthread_t work_threads[256]; if (options.threads > 1) {
void *status; pthread_t work_threads[256];
pthread_attr_t attrib; void *status;
int i; pthread_attr_t attrib;
int i;
if (numthreads == 1) { if (pthread_attr_init (&attrib) == -1)
func (NULL); fprintf (stderr, "pthread_attr_init failed");
if (pthread_attr_setstacksize (&attrib, 0x100000) == -1)
fprintf (stderr, "pthread_attr_setstacksize failed");
for (i = 0; i < options.threads; i++) {
if (pthread_create (&work_threads[i], &attrib, func, (void *) i) == -1)
fprintf (stderr, "pthread_create failed");
}
for (i = 0; i < options.threads; i++) {
if (pthread_join (work_threads[i], &status) == -1)
fprintf (stderr, "pthread_join failed");
}
return; return;
} }
if (pthread_attr_init (&attrib) == -1)
fprintf (stderr, "pthread_attr_init failed");
if (pthread_attr_setstacksize (&attrib, 0x100000) == -1)
fprintf (stderr, "pthread_attr_setstacksize failed");
for (i = 0; i < numthreads; i++) {
if (pthread_create (&work_threads[i], &attrib, func, (void *) i) == -1)
fprintf (stderr, "pthread_create failed");
}
for (i = 0; i < numthreads; i++) {
if (pthread_join (work_threads[i], &status) == -1)
fprintf (stderr, "pthread_join failed");
}
#else
func (NULL);
#endif #endif
func (NULL);
} }