Esempio n. 1
0
///////////////////////////////////////////////////////////////////////
// Function            :   osTempdir
// Description         :   Create a path to a directory suitable
//                     :   for storing temporary files.
// Return Value        :   -
// Comments            :   The directory will end with / or \
//                     :   Does not create the directory.
//                     :   Path is only unique within this process.
void   osTempdir(char *result, size_t resultsize) {    
   
#ifdef _WINDOWS
	sprintf(result,"PixieTemp_%d\\",GetCurrentProcessId());
//#elif defined(__APPLE__) || defined(__APPLE_CC__)  // guard against __APPLE__ being undef from ftlk
//	FSRef tempRef;
//	char tempDirPath[OS_MAX_PATH_LENGTH];
//	OSErr err = FSFindFolder(kLocalDomain,kTemporaryFolderType,true,&tempRef);
//	if (!err)
//		err = FSRefMakePath(&tempRef,(UInt8*)tempDirPath,sizeof(tempDirPath));
//	if (!err)
//		snprintf(result,resultsize,"%s/PixieTemp_%d/",tempDirPath,getpid());
//	else
//		snprintf(result,resultsize,"/tmp/PixieTemp_%d/",getpid());
	
#else
	// Unix-y
	const char *tempDirEnv = osEnvironment("TMPDIR");
	if (!tempDirEnv)
		tempDirEnv = osEnvironment("TMP");
	if (tempDirEnv != NULL)
		snprintf(result,resultsize,"%s/PixieTemp_%d/",tempDirEnv,getpid());
	else
		snprintf(result,resultsize,"PixieTemp_%d/",getpid());
#endif
	
	osFixSlashes(result);   
}
Esempio n. 2
0
///////////////////////////////////////////////////////////////////////
// Class				:	CRenderer
// Method				:	shutdownFiles
// Description			:	Shutdown the files
// Return Value			:
// Comments				:
void		CRenderer::shutdownFiles() {

    // Ditch the temporary files created
    if (osFileExists(temporaryPath)) {
        char	tmp[OS_MAX_PATH_LENGTH];

        sprintf(tmp,"%s*",temporaryPath);
        osFixSlashes(tmp);
        osEnumerate(tmp,rcClearTemp,NULL);
        osDeleteDir(temporaryPath);
    }

    // Ditch the DSO shaders that have been loaded
    CDSO	*cDso;
    for (cDso=dsos; cDso!=NULL;) {
        CDSO	*nDso	=	cDso->next;
        // Call DSO's cleanup
        if(cDso->cleanup != NULL) cDso->cleanup(cDso->handle);
        free(cDso->name);
        free(cDso->prototype);
        delete cDso;
        cDso	=	nDso;
    }

    // Ditch the loaded files
    assert(globalFiles != NULL);
    globalFiles->destroy();
}
Esempio n. 3
0
///////////////////////////////////////////////////////////////////////
// Function				:	enumerate
// Description			:	Enumerate the files matching a criteria
// Return Value			:
// Comments				:
void	osEnumerate(const char *name,int (*callback)(const char *,void *),void *userData) {
#ifdef _WINDOWS
	_finddata_t	c_file;
	intptr_t	hFile;
	char		tmp[OS_MAX_PATH_LENGTH];
	char		*tmpp;

	strcpy(tmp,name);
	osFixSlashes(tmp);

	tmpp	=	strrchr(tmp,OS_DIR_SEPERATOR);
	if (tmpp == NULL) {
		tmpp	=	tmp;
	} else {
		tmpp++;
	}

	if( (hFile = _findfirst(name, &c_file )) == -1L ) {
	} else {
		strcpy(tmpp,c_file.name);
		if (callback(tmp,userData) == TRUE) {
			while( _findnext( hFile, &c_file ) == 0 ) {
				strcpy(tmpp,c_file.name);
				if (callback(tmp,userData) == FALSE)	break;
			}
		}

		_findclose( hFile );
	}
#else
	glob_t	globbuf;
	int		i;

	globbuf.gl_offs =       0;
	glob(name,GLOB_DOOFFS,NULL,&globbuf);


	for (i=0;i<globbuf.gl_pathc;i++) {
		if (callback(globbuf.gl_pathv[i],userData) == FALSE)	break;
	}

	globfree(&globbuf);
#endif
}
Esempio n. 4
0
///////////////////////////////////////////////////////////////////////
// Function				:	main
// Description			:	The god
// Return Value			:	-
// Comments				:
int main(int argc, char* argv[]) {
	char	tmp[1024];

	if (argc > 1) {
		TSdrShader		*cShader;
		TSdrParameter	*cParameter;
		const char		*pixieHome	=	osEnvironment("PIXIEHOME");
		const char		*shaders	=	osEnvironment("SHADERS");

		sprintf(tmp,".");

		if (pixieHome != NULL) {
			strcat(tmp,":");
			strcat(tmp,pixieHome);
			strcat(tmp,"/shaders");
		}

		if (shaders != NULL) {
			strcat(tmp,":");
			strcat(tmp,shaders);
		}


		osFixSlashes(tmp);
		cShader	=	sdrGet(argv[1],tmp);

		if (cShader == NULL) {
			fprintf(stderr,"Failed to find shader \"%s\"\n",argv[1]);
			exit(1);
		}

		switch(cShader->type) {
		case SHADER_SURFACE:
			fprintf(stdout,"surface ");
			break;
		case SHADER_DISPLACEMENT:
			fprintf(stdout,"displacement ");
			break;
		case SHADER_VOLUME:
			fprintf(stdout,"volume ");
			break;
		case SHADER_LIGHT:
			fprintf(stdout,"light ");
			break;
		case SHADER_IMAGER:
			fprintf(stdout,"imager ");
			break;
		}

		fprintf(stdout,"\"%s\"\n",cShader->name);

		for (cParameter=cShader->parameters;cParameter!=NULL;cParameter=cParameter->next) {
			fprintf(stdout,"\t\"%s\" ",cParameter->name);

			if (cParameter->writable) {
				fprintf(stdout,"\"output ");
			} else {
				fprintf(stdout,"\"");
			}
			
			switch(cParameter->container) {
			case CONTAINER_CONSTANT:
				fprintf(stdout,"constant ");
				break;
			case CONTAINER_UNIFORM:
				fprintf(stdout,"uniform ");
				break;
			case CONTAINER_VARYING:
				fprintf(stdout,"varying ");
				break;
			case CONTAINER_VERTEX:
				fprintf(stdout,"vertex ");
				break;
			}

			switch(cParameter->type) {
			case TYPE_FLOAT:
				fprintf(stdout,"float");
				break;
			case TYPE_VECTOR:
				fprintf(stdout,"vector");
				break;
			case TYPE_NORMAL:
				fprintf(stdout,"normal");
				break;
			case TYPE_POINT:
				fprintf(stdout,"point");
				break;
			case TYPE_COLOR:
				fprintf(stdout,"color");
				break;
			case TYPE_MATRIX:
				fprintf(stdout,"matrix");
				break;
			case TYPE_STRING:
				fprintf(stdout,"string");
				break;
			}

			if (cParameter->numItems > 1) {
				fprintf(stdout,"[%d]",cParameter->numItems);
			}

			fprintf(stdout,"\"\n");

			fprintf(stdout,"\t\tDefault value: ");

			UDefaultVal *currentDefault = &cParameter->defaultValue;
			if (cParameter->numItems > 1)
				currentDefault = currentDefault->array;
			
			for(int i=0;i<cParameter->numItems;i++){
				switch(cParameter->type) {
				case TYPE_FLOAT:
					fprintf(stdout,"%g ",currentDefault->scalar);
					break;
				case TYPE_VECTOR:
				case TYPE_NORMAL:
				case TYPE_POINT:
				case TYPE_COLOR:
					if (cParameter->space != NULL) {
						fprintf(stdout,"\"%s\" ",cParameter->space);
					}

					if (currentDefault->vector != NULL) {
						fprintf(stdout,"[%g %g %g] ",currentDefault->vector[0],currentDefault->vector[1],currentDefault->vector[2]);
					} else {
						fprintf(stdout,"[0 0 0] ");
					}
					break;
				case TYPE_MATRIX:
					if (currentDefault->matrix != NULL) {
						fprintf(stdout,"[%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g] "
							,currentDefault->matrix[0]
							,currentDefault->matrix[1]
							,currentDefault->matrix[2]
							,currentDefault->matrix[3]
							,currentDefault->matrix[4]
							,currentDefault->matrix[5]
							,currentDefault->matrix[6]
							,currentDefault->matrix[7]
							,currentDefault->matrix[8]
							,currentDefault->matrix[9]
							,currentDefault->matrix[10]
							,currentDefault->matrix[11]
							,currentDefault->matrix[12]
							,currentDefault->matrix[13]
							,currentDefault->matrix[14]
							,currentDefault->matrix[15]);
					} else {
						fprintf(stdout,"[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] ");
					}
					break;
				case TYPE_STRING:
					if (currentDefault->string != NULL) {
						fprintf(stdout,"\"%s\" ",currentDefault->string);
					} else {
						fprintf(stdout,"NULL ");
					}
					break;
				}
				currentDefault++;
			}
			fprintf(stdout,"\n");
		}

		sdrDelete(cShader);
	}

	return 0;
}
Esempio n. 5
0
///////////////////////////////////////////////////////////////////////
// Function				:	optionsGetSearchPath
// Description			:
/// \brief					Get the searchpath
// Return Value			:	-
// Comments				:
TSearchpath					*optionsGetSearchPath(const char *path,TSearchpath *oldPath) {
	TSearchpath		*newPath	=	NULL;
	TSearchpath		*lastPath	=	NULL;
	TSearchpath		*cPath;
	const	char	*currentPath;
	char			tmp[OS_MAX_PATH_LENGTH];
	char			*dest;

	for (dest=tmp,currentPath=path;;) {
		if ((*currentPath == '\0') || (*currentPath == ':')) {		// End of the current path

#ifdef _WIN32
			if ((dest - tmp) == 1) {
				if ((currentPath[1] == '\\') || (currentPath[1] == '/')) {
					*dest++	=	*currentPath++;
					continue;
				}
			}
#endif

			if ((dest - tmp) > 0) {		// Do we have anything to record ?
				dest--;

				if ((*dest == '/') || (*dest == '\\')) {	// The last character has to be a slash
					dest++;
				} else {
					dest++;
					*dest++	=	'/';
				}

				*dest++		=	'\0';
				osFixSlashes(tmp);

				cPath				=	new TSearchpath;
				if (strncmp(tmp,"\\\\",2) == 0) {
					tmp[1]	=	tmp[2];
					tmp[2]	=	':';
					tmp[3]	=	'\\';
					cPath->directory	=	strdup(tmp+1);
				} else {
					cPath->directory	=	strdup(tmp);
				}
				cPath->next			=	NULL;

				if (lastPath == NULL) {
					lastPath		=	cPath;
					newPath			=	cPath;
				} else {
					lastPath->next	=	cPath;
					lastPath		=	cPath;
				}
			}

			dest			=	tmp;

			if (*currentPath == '\0')	break;

			currentPath++;
		} else if (*currentPath == '%') {
			const	char	*endOfCurrentPath	=	strchr(currentPath+1,'%');
			char			environmentVariable[OS_MAX_PATH_LENGTH];

			if (endOfCurrentPath!=NULL) {
				const	int		environmentLength	=	(int) (endOfCurrentPath - currentPath) - 1;
				const	char	*value;

				strncpy(environmentVariable,currentPath+1,environmentLength);
				environmentVariable[environmentLength]	=	'\0';

				value		=	osEnvironment(environmentVariable);
				if (value != NULL) {
					strcpy(dest,value);
					dest	+=	strlen(value);
					currentPath =   endOfCurrentPath+1;
				} else {
					// If this environment variable was not defined, scrap the entire
					// path in progress b/c it will not be correct without this env variable
					dest = tmp;
					*dest = '\0';   // Truncate dest path
					currentPath = strchr(endOfCurrentPath,':');         // Skip to next path
					if (!currentPath)
						currentPath = strchr(endOfCurrentPath,'\0');    // ...or end if last path
				}

			} else {
				currentPath++;
			}
		} else if ((*currentPath == '@') || (*currentPath == '&')) {
			for (cPath=oldPath;cPath!=NULL;cPath=cPath->next) {
				TSearchpath	*nPath	=	new TSearchpath;

				nPath->directory	=	strdup(cPath->directory);
				nPath->next			=	NULL;

				if (lastPath == NULL) {
					lastPath		=	nPath;
					newPath			=	nPath;
				} else {
					lastPath->next	=	nPath;
					lastPath		=	nPath;
				}
			}
			currentPath++;
		} else {
			*dest++	=	*currentPath++;
		}
	}

	optionsDeleteSearchPath(oldPath);

	return newPath;
}
Esempio n. 6
0
///////////////////////////////////////////////////////////////////////
// Class				:	CRenderer
// Method				:	locateFile
// Description			:	Locate a file on disk
// Return Value			:	TRUE if found
// Comments				:
int	CRenderer::locateFile(char *result,const char *name,TSearchpath *searchpath) {

    if (netClient != INVALID_SOCKET) {
        // check netfile mappings
        CNetFileMapping* mapping;
        if (netFileMappings->find(name,mapping)) {
            name = mapping->to;
        }
    }

    if (strchr(name,OS_DIR_SEPERATOR)) {
        // Supplied path
        // Check if the file exists
        if (osFileExists(name)) {
            strcpy(result,name);
            info(CODE_RESOLUTION,"\"%s\" -> \"%s\"\n",name,name);
            return TRUE;
        }
    } else {
        // Only filename
        // Look at the search path
        for (; searchpath!=NULL; searchpath=searchpath->next) {
            sprintf(result,"%s%s",searchpath->directory,name);
            osFixSlashes(result);
            if (osFileExists(result)) {
                info(CODE_RESOLUTION,"\"%s\" -> \"%s\"\n",name,result);
                return TRUE;
            }
        }

        // Last resort, look into the temporary directory
        sprintf(result,"%s%s",temporaryPath,name);
        osFixSlashes(result);
        if (osFileExists(result)) {
            info(CODE_RESOLUTION,"\"%s\" -> \"%s\"\n",name,result);
            return TRUE;
        }
    }

    // Unable to find the file, check the network
    // Check the net if we can find the file
    if (netClient != INVALID_SOCKET) {

        // Lock the network
        osLock(networkMutex);

        if (getFile(result,name) == TRUE) {
            if (osFileExists(result)) {
                info(CODE_RESOLUTION,"\"%s\" -> \"%s\"\n",name,result);
                osUnlock(networkMutex);
                return TRUE;
            }
        }

        // Unlock the network
        osUnlock(networkMutex);
    }

    info(CODE_RESOLUTION,"\"%s\" -> ???\n",name);

    return FALSE;
}