mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 14:20:59 +00:00
hopefully make everything happy with the new bsp struct
This commit is contained in:
parent
c1c68830c5
commit
00294f7ae0
6 changed files with 64 additions and 66 deletions
|
@ -55,10 +55,11 @@ void LightFace (int surfnum);
|
|||
void LightLeaf (dleaf_t *leaf);
|
||||
|
||||
void MakeTnodes (dmodel_t *bm);
|
||||
byte *GetFileSpace (int size);
|
||||
int GetFileSpace (int size);
|
||||
void TransformSample (vec3_t in, vec3_t out);
|
||||
void RotateSample (vec3_t in, vec3_t out);
|
||||
|
||||
extern struct bsp_s *bsp;
|
||||
extern struct dstring_s *lightdata;
|
||||
|
||||
#endif// __light_h
|
||||
|
|
|
@ -36,8 +36,8 @@
|
|||
#ifdef HAVE_PTHREAD_H
|
||||
#include <pthread.h>
|
||||
extern pthread_mutex_t *my_mutex;
|
||||
#define LOCK pthread_mutex_lock (my_mutex)
|
||||
#define UNLOCK pthread_mutex_unlock (my_mutex)
|
||||
#define LOCK do { if (options.threads > 1) pthread_mutex_lock (my_mutex); } while (0);
|
||||
#define UNLOCK do { if (options.threads > 1) pthread_mutex_unlock (my_mutex); } while (0);
|
||||
#else
|
||||
#define LOCK
|
||||
#define UNLOCK
|
||||
|
|
|
@ -274,14 +274,12 @@ GetVectorForKey (entity_t *ent, char *key, vec3_t vec)
|
|||
void
|
||||
WriteEntitiesToString (void)
|
||||
{
|
||||
char *buf, *end;
|
||||
dstring_t *buf;
|
||||
char line[128];
|
||||
epair_t *ep;
|
||||
int i;
|
||||
|
||||
buf = bsp->entdata;
|
||||
end = buf;
|
||||
*end = 0;
|
||||
buf = dstring_newstr ();
|
||||
|
||||
if (options.verbosity >= 0)
|
||||
printf ("%i switchable light styles\n", numlighttargets);
|
||||
|
@ -291,19 +289,13 @@ WriteEntitiesToString (void)
|
|||
if (!ep)
|
||||
continue; // ent got removed
|
||||
|
||||
strcat (end, "{\n");
|
||||
end += 2;
|
||||
dstring_appendstr (buf, "{\n");
|
||||
|
||||
for (ep = entities[i].epairs; ep; ep = ep->next) {
|
||||
sprintf (line, "\"%s\" \"%s\"\n", ep->key, ep->value);
|
||||
strcat (end, line);
|
||||
end += strlen (line);
|
||||
dstring_appendstr (buf, line);
|
||||
}
|
||||
strcat (end, "}\n");
|
||||
end += 2;
|
||||
|
||||
if (end > buf + MAX_MAP_ENTSTRING)
|
||||
fprintf (stderr, "Entity text too long");
|
||||
dstring_appendstr (buf, "}\n");
|
||||
}
|
||||
bsp->entdatasize = end - buf + 1;
|
||||
BSP_AddEntities (bsp, buf->str, buf->size);
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ static const char rcsid[] =
|
|||
#include "light.h"
|
||||
#include "entities.h"
|
||||
#include "options.h"
|
||||
#include "threads.h"
|
||||
|
||||
#define SINGLEMAP (18*18*4)
|
||||
|
||||
|
@ -451,7 +452,8 @@ FixMinlight (lightinfo_t *l)
|
|||
void
|
||||
LightFace (int surfnum)
|
||||
{
|
||||
byte *out;
|
||||
int ofs;
|
||||
byte *out;
|
||||
dface_t *f;
|
||||
int lightmapwidth, lightmapsize, size, c, i, j, s, t, w, h;
|
||||
lightinfo_t l;
|
||||
|
@ -513,8 +515,11 @@ LightFace (int surfnum)
|
|||
|
||||
lightmapsize = size * l.numlightstyles;
|
||||
|
||||
out = GetFileSpace (lightmapsize);
|
||||
f->lightofs = out - filebase;
|
||||
LOCK;
|
||||
out = malloc (lightmapsize);
|
||||
UNLOCK;
|
||||
ofs = GetFileSpace (lightmapsize);
|
||||
f->lightofs = ofs;
|
||||
|
||||
// extra filtering
|
||||
h = (l.texsize[1] + 1) * 2;
|
||||
|
@ -544,4 +549,8 @@ LightFace (int surfnum)
|
|||
*out++ = total;
|
||||
}
|
||||
}
|
||||
LOCK;
|
||||
memcpy (lightdata->str + ofs, out, lightmapsize);
|
||||
free (out);
|
||||
UNLOCK;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ char *bspfile;
|
|||
|
||||
float scalecos = 0.5;
|
||||
|
||||
byte *filebase, *file_p, *file_end;
|
||||
dstring_t *lightdata;
|
||||
|
||||
dmodel_t *bspmodel;
|
||||
int bspfileface; // next surface to dispatch
|
||||
|
@ -77,19 +77,18 @@ qboolean extrasamples;
|
|||
float minlights[MAX_MAP_FACES];
|
||||
|
||||
|
||||
byte *
|
||||
int
|
||||
GetFileSpace (int size)
|
||||
{
|
||||
byte *buf;
|
||||
int ofs;
|
||||
|
||||
LOCK;
|
||||
file_p = (byte *) (((long) file_p + 3) & ~3);
|
||||
buf = file_p;
|
||||
file_p += size;
|
||||
lightdata->size = (lightdata->size + 3) & 3;
|
||||
ofs = lightdata->size;
|
||||
lightdata->size += size;
|
||||
dstring_adjust (lightdata);
|
||||
UNLOCK;
|
||||
if (file_p > file_end)
|
||||
fprintf (stderr, "GetFileSpace: overrun");
|
||||
return buf;
|
||||
return ofs;
|
||||
}
|
||||
|
||||
void *
|
||||
|
@ -111,12 +110,11 @@ LightThread (void *junk)
|
|||
void
|
||||
LightWorld (void)
|
||||
{
|
||||
filebase = file_p = bsp->lightdata;
|
||||
file_end = filebase + MAX_MAP_LIGHTING;
|
||||
lightdata = dstring_new ();
|
||||
|
||||
RunThreadsOn (LightThread);
|
||||
|
||||
bsp->lightdatasize = file_p - filebase;
|
||||
BSP_AddLighting (bsp, lightdata->str, lightdata->size);
|
||||
|
||||
if (options.verbosity >= 0)
|
||||
printf ("lightdatasize: %i\n", bsp->lightdatasize);
|
||||
|
|
|
@ -46,28 +46,29 @@ static const char rcsid[] =
|
|||
|
||||
#include "QF/qtypes.h"
|
||||
#include "QF/qendian.h"
|
||||
|
||||
#include "options.h"
|
||||
#include "threads.h"
|
||||
|
||||
#ifdef HAVE_PTHREAD_H
|
||||
int numthreads = 4;
|
||||
pthread_mutex_t *my_mutex;
|
||||
#else
|
||||
int numthreads = 1;
|
||||
#endif
|
||||
|
||||
void
|
||||
InitThreads (void)
|
||||
{
|
||||
#ifdef HAVE_PTHREAD_H
|
||||
pthread_mutexattr_t mattrib;
|
||||
if (options.threads > 1) {
|
||||
pthread_mutexattr_t mattrib;
|
||||
|
||||
my_mutex = malloc (sizeof (*my_mutex));
|
||||
if (pthread_mutexattr_init (&mattrib) == -1)
|
||||
fprintf (stderr, "pthread_mutex_attr_init failed");
|
||||
// if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
|
||||
// fprintf (stderr, "pthread_mutexattr_setkind_np failed");
|
||||
if (pthread_mutex_init (my_mutex, &mattrib) == -1)
|
||||
fprintf (stderr, "pthread_mutex_init failed");
|
||||
my_mutex = malloc (sizeof (*my_mutex));
|
||||
if (pthread_mutexattr_init (&mattrib) == -1)
|
||||
fprintf (stderr, "pthread_mutex_attr_init failed");
|
||||
// if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
|
||||
// fprintf (stderr, "pthread_mutexattr_setkind_np failed");
|
||||
if (pthread_mutex_init (my_mutex, &mattrib) == -1)
|
||||
fprintf (stderr, "pthread_mutex_init failed");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -75,31 +76,28 @@ void
|
|||
RunThreadsOn (threadfunc_t *func)
|
||||
{
|
||||
#ifdef HAVE_PTHREAD_H
|
||||
pthread_t work_threads[256];
|
||||
void *status;
|
||||
pthread_attr_t attrib;
|
||||
int i;
|
||||
if (options.threads > 1) {
|
||||
pthread_t work_threads[256];
|
||||
void *status;
|
||||
pthread_attr_t attrib;
|
||||
int i;
|
||||
|
||||
if (numthreads == 1) {
|
||||
func (NULL);
|
||||
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 < 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;
|
||||
}
|
||||
|
||||
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
|
||||
func (NULL);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue