qutils / light / light.c

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <time.h>
#include <stdarg.h>
#include <unistd.h>
#include "../common/cmdlib.h"
#include <math.h>
#include "../common/mathlib.h"
#include "../common/bspfile.h"
#include "entities.h"
#include "threads.h"
#include "light.h"

/*

NOTES
-----

*/

float scaledist = 1.0;
float scalecos = 0.5;
float rangescale = 0.5;

byte *filebase, *file_p, *file_end;

dmodel_t *bspmodel;
int bspfileface;				// next surface to dispatch

vec3_t bsp_origin;

qboolean extrasamples;

float minlights[MAX_MAP_FACES];


byte *
GetFileSpace(int size)
{
	byte *buf;

	LOCK;
	file_p = (byte *) (((long)file_p + 3) & ~3);
	buf = file_p;
	file_p += size;
	UNLOCK;
	if(file_p > file_end)
		Error("GetFileSpace: overrun");
	return buf;
}


void
LightThread(void *junk)
{
	int i;

	while(1) {
		LOCK;
		i = bspfileface++;
		UNLOCK;
		if(i >= numfaces)
			return;

		LightFace(i);
	}
}

/*
=============
LightWorld
=============
*/
void
LightWorld(void)
{
	filebase = file_p = dlightdata;
	file_end = filebase + MAX_MAP_LIGHTING;

	RunThreadsOn(LightThread);

	lightdatasize = file_p - filebase;

	printf("lightdatasize: %i\n", lightdatasize);
}


/*
========
main

light modelfile
========
*/
int
main(int argc, char **argv)
{
	int i;
	double start, end;
	char source[1024];

	printf("----- LightFaces ----\n");

	for(i = 1; i < argc; i++) {
		if(!strcmp(argv[i], "-threads")) {
			numthreads = atoi(argv[i + 1]);
			i++;
		} else if(!strcmp(argv[i], "-extra")) {
			extrasamples = true;
			printf("extra sampling enabled\n");
		} else if(!strcmp(argv[i], "-dist")) {
			scaledist = atof(argv[i + 1]);
			i++;
		} else if(!strcmp(argv[i], "-range")) {
			rangescale = atof(argv[i + 1]);
			i++;
		} else if(argv[i][0] == '-')
			Error("Unknown option \"%s\"", argv[i]);
		else
			break;
	}

	if(i != argc - 1)
		Error("usage: light [-threads num] [-extra] bspfile");

	InitThreads();

	start = I_FloatTime();

	strcpy(source, argv[i]);
	StripExtension(source);
	DefaultExtension(source, ".bsp");

	LoadBSPFile(source);
	LoadEntities();

	MakeTnodes(&dmodels[0]);

	LightWorld();

	WriteEntitiesToString();
	WriteBSPFile(source);

	end = I_FloatTime();
	printf("%5.1f seconds elapsed\n", end - start);

	return 0;
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.