Exemplo n.º 1
0
void CMC_start_up (int argc, char **argv, int *verbose)
{
    int ret, cnt, i;

    Argc = argc;
    Argv = argv;

    /* close all fd may inherited from parent. We have less than 64 fds */
    for (i = 3; i < 64; i++)
	close (i);

    /* read options */
    if (Read_options (argc, argv) != 0)
	exit (1);

    /* Initialize the LE and CS services */
    if (Test_mode)
	goto next;
    if (getenv ("LE_DIR_EVENT") != NULL) {
	char tsk_name[NAME_LEN];

	sprintf (tsk_name, "%s.%d", argv[0], Comm_manager_index);
	ret = LE_create_lb (tsk_name, Log_size, LB_SINGLE_WRITER, -1);
	if (ret < 0) {
	    LE_send_msg (GL_ERROR,  "LE_create_lb failed (ret %d)", ret);
	    exit (1);
	}
	LE_set_option ("LE name", tsk_name);
	LE_set_option ("label", tsk_name);

	cnt = 0;
	while (1) {
	    ret = LE_init (argc, argv);
    
	    if (Verbose)
		LE_local_vl (1);
    
	    cnt++;
	    if (cnt < 10 && ret == LE_DUPLI_INSTANCE) {
		LE_send_msg (LE_VL0 | 9,  "LE file locked - will retry");
		sleep (1);
		continue;
	    }
	    else
		break;
	}
	if (ret < 0) {
	    LE_send_msg (GL_ERROR | 10,  "LE_init failed (ret %d)", ret);
	    exit (1);
	}
    }
next:
    Termination_start_time = 0;
    sigset (SIGTERM, Term_handler); 
    sigset (SIGHUP, Term_handler);
/*    sigset (SIGINT, Term_handler); */

    *verbose = Verbose;
    return;
}
Exemplo n.º 2
0
void CAM_StartPlaying(char* filename)
{
	uint i;	
	filehandle_t* file ;
	uchar isCP1 = 0;
	
	file = FS_OpenFile(filename, "rt");
	
	if (!file)
		return;
	
	isCP1 = (*file->ptrStart == 'c' && *(file->ptrStart+1) == 'p' && *(file->ptrStart+2) == '1') ;
	
	if (!isCP1)
	{
		printf("Camera path is not a valid file:");
		return;
	}
	
	LE_init(file);
	
	LE_readToken(); //CP1
	LE_readToken(); //num_frames
	
	
	
	camera.path.num_frames = LE_readReal();
	
	camera.path.frames = CAM_ReadFrameFromFile();
	camera.path.frames->next = 0;
	camera.path.currentFrame = camera.path.frames;
	
	for(i=1 ; i < camera.path.num_frames ; i++)
	{
		camera.path.currentFrame->next = CAM_ReadFrameFromFile();
		camera.path.currentFrame = camera.path.currentFrame->next;
		camera.path.currentFrame->next = 0;
	}
							  
	camera.playing = 1;
	camera.path.currentFrame = camera.path.frames;
	strcpy(camera.recordFilename, filename);
	simulationTime = camera.path.frames[0].time;
	
	FS_CloseFile(file);
}
Exemplo n.º 3
0
void dEngine_ReadConfig(void)
{
	filehandle_t* config;
	int currentSceneId=0;
	
    
    
	config = FS_OpenFile(CONFIG_PATH, "rt");
	FS_UploadToRAM(config);
	
	if (!config)
	{
		Log_Printf("Configuration file: data/config.cfg not found");
		exit(0);
	}
	
	//renderer.resolution = 1;

	LE_pushLexer();
	LE_init(config);
	
	while (LE_hasMoreData()) 
	{
		LE_readToken();

		if (!strcmp("scenes", LE_getCurrentToken()))
		{
			LE_readToken(); // {
			LE_readToken(); // numScenes
			while (LE_hasMoreData() && strcmp("}", LE_getCurrentToken()))
			{
				if (!strcmp("numScenes", LE_getCurrentToken()))
				{
					engine.numScenes = LE_readReal();
				}
				else 
				if (!strcmp("scene", LE_getCurrentToken()))
				{
					currentSceneId = LE_readReal();
					
					LE_readToken(); //The name of the scene, here only to help developer to keep track of config.cfg
					strReplace(LE_getCurrentToken(), '_', ' ');
					strcpy(engine.scenes[currentSceneId].name, LE_getCurrentToken());
					
					LE_readToken();
					strcpy(engine.scenes[currentSceneId].path, LE_getCurrentToken());
					
					Log_Printf("Read scene %d, name %s, path %s\n",currentSceneId,engine.scenes[currentSceneId].name,engine.scenes[currentSceneId].path);
					
					
				}
				
				LE_readToken();
				
			}
		}
		else if (!strcmp("fx", LE_getCurrentToken()))
		{
			LE_readToken(); //{
			while (LE_hasMoreData() && strcmp("}", LE_getCurrentToken()))
			{
				LE_readToken();
				
				if (!strcmp("impactTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
	//			explosionTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(explosionTexture.path, LE_getCurrentToken());
				}
				else 
				if (!strcmp("smokeTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
	//				smokeTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(smokeTexture.path, LE_getCurrentToken());
				}
				else 
				if (!strcmp("ghostTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
	//				ghostTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(ghostTexture.path, LE_getCurrentToken());
				}
			}
		}
		/*
		else if (!strcmp("video", LE_getCurrentToken()))
		{
			
			LE_readToken(); // {
			LE_readToken();
			while (strcmp("}", LE_getCurrentToken()))
			{
				if (!strcmp("record", LE_getCurrentToken()))
				{
					engine.recordVideo = LE_readReal();
				}
				LE_readToken();
			}
		}
		*/
		else if (!strcmp("players", LE_getCurrentToken()))
		{
			LE_readToken();	//{
			LE_readToken();
			while (LE_hasMoreData() && strcmp("}", LE_getCurrentToken()))
			{
				if (!strcmp("model1", LE_getCurrentToken()))
				{
					LE_readToken();
					strcpy(players[1].modelPath, LE_getCurrentToken());
				}
				else 
				if (!strcmp("model0", LE_getCurrentToken()))
				{
					LE_readToken();
					strcpy(players[0].modelPath, LE_getCurrentToken());
				}
				else 
					if (!strcmp("bulletTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
//					bulletConfig.bulletTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(bulletConfig.bulletTexture.path, LE_getCurrentToken());
				}
				else 
				if (!strcmp("ttl", LE_getCurrentToken()))
				{
					bulletConfig.ttl = LE_readReal();
				}
				else 
				if (!strcmp("heightRatio", LE_getCurrentToken()))
				{
					bulletConfig.heightRatio = LE_readReal();
				}
				else 
				if (!strcmp("widthRatio", LE_getCurrentToken()))
				{
					bulletConfig.widthRatio = LE_readReal();
				}
				else 
				if (!strcmp("screenSpaceXDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.screenSpaceXDeltaRatio = LE_readReal();
				}
				else 
				if (!strcmp("screenSpaceYDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.screenSpaceYDeltaRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashHeightRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashHeightRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashWidthRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashWidthRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashScreenSpaceXDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashScreenSpaceXDeltaRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashScreenSpaceYDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashScreenSpaceYDeltaRatio = LE_readReal();
				}
				
				LE_readToken();
			}
			
		}
		
	}
	
	
	LE_popLexer();
	FS_CloseFile(config);
	
	
}
Exemplo n.º 4
0
char OBJ_Load(char* filename,entity_t* entity)
{
	static vec3_t tmpVertices[DE_USHRT_MAX];
	ushort num_vertices=0;
	
	static vec2_t tmpTextureCoor[DE_USHRT_MAX];
	ushort num_textuCoor=0;
	
	int idata[9];	
	int i;
	
	ushort indiceOfCurrentVertex;
	
	filehandle_t* objFile ;
	
	obj_t* obj;
	
	
	
	
	objFile = FS_OpenFile(filename, "rt");
	
	if (!objFile)
	{
		printf("Could not Load OBJ: '%s'.\n",filename);
		return 0;
	}
	
	
		
	OBJ_InitVerticeCache();
	
	obj = (obj_t*)entity->model;
	obj->vertices = (obj_vertex_t*)calloc(DE_USHRT_MAX, sizeof(obj_vertex_t));
	obj->num_vertices = 0;
	obj->indices = (ushort*)calloc(DE_USHRT_MAX, sizeof(ushort));
	obj->num_indices = 0;
	
	LE_pushLexer();
	
	LE_init(objFile);
	
	while (LE_hasMoreData()) 
	{
		LE_readToken();
		
		if (!strcmp("v",LE_getCurrentToken()))
		{
			tmpVertices[num_vertices][0] = LE_readReal();
			tmpVertices[num_vertices][1] = LE_readReal();
			tmpVertices[num_vertices][2] = LE_readReal();
			num_vertices++;
			
		}
		else
		if (!strcmp("vt",LE_getCurrentToken()))
		{
			tmpTextureCoor[num_textuCoor][0] = LE_readReal();
			tmpTextureCoor[num_textuCoor][1] = 1- LE_readReal();
			num_textuCoor++;
		}
		else
		if (!strcmp("vn",LE_getCurrentToken()))
		{
			for(i=0;i<3;i++)
				LE_readReal();
			
			//Drop it (like it's hot)
		}
		else
		if (!strcmp("f",LE_getCurrentToken()))
		{
			LE_SetWhiteCharValue('/', 1);
			
			for(i=0;i<9;i++)
			{
				idata[i] = LE_readReal();
				idata[i]--;
			}
			
			#ifdef OBJ_FACE_CCW
			for(i=0;i<3;i++)//OBJ Standard: Couter-clockwise
			#else
			for(i=2;i>=0;i--) //Bugged expoter.
			#endif			
			{
				indiceOfCurrentVertex = GetCacheVertex(idata[3*i],tmpTextureCoor[idata[3*i+1]]);
				//indiceOfCurrentVertex = obj->num_indices;
				
				if (indiceOfCurrentVertex+1 > obj->num_vertices)
					obj->num_vertices = indiceOfCurrentVertex+1;
				
				vectorCopy (tmpVertices[idata[3*i]]		, obj->vertices[indiceOfCurrentVertex].position);
				//for(i=0;i<3;i++)
				//{
				//		printf("Vertices: %d, %d, %d.\n",obj->vertices[indiceOfCurrentVertex].position[0],obj->vertices[indiceOfCurrentVertex].position[1],obj->vertices[indiceOfCurrentVertex].position[2]);
				//}
				vector2Copy(tmpTextureCoor[idata[3*i+1]], obj->vertices[indiceOfCurrentVertex].textCoo);
				
				//printf("num_indices = %d, indice pointer=%d\n",obj->num_indices,indiceOfCurrentVertex);
				obj->indices[obj->num_indices++] = indiceOfCurrentVertex ;
				
			}
			
			LE_SetWhiteCharValue('/', 0);
		}
		else
		if (!strcmp("usemtl",LE_getCurrentToken()))
		{
			LE_readToken();
			entity->material = MATLIB_Get(LE_getCurrentToken());
			if (entity->material == 0)
				printf("************[OBJ Loader] Could not find material: '%s'\n",LE_getCurrentToken());
			
		}
	}
	
	
	LE_popLexer();
	
	FS_CloseFile(objFile);
	
	//Adjust size of vertices and indices
	obj->vertices = realloc(obj->vertices,obj->num_vertices  * sizeof(obj_vertex_t));
	obj->indices  = realloc(obj->indices ,obj->num_indices   * sizeof(ushort));
	
	//printf("Obj %s has %d vertices.\n",filename,obj->num_vertices);
	//printf("Obj %s has %d indices.\n",filename,obj->num_indices);
	
	OBJ_DestroyVerticeCache();
	
	//Generate lighting infos.
	OBJ_GenerateLightingInfo(obj);
	
	return 1;
}
Exemplo n.º 5
0
char MD5_LoadMesh(md5_mesh_t* mesh, const char* filename)
{
	filehandle_t* fhandle = 0;
	vertex_t* currentVertex = 0;
	ushort verticesCounter=0;
	int versionNumber = 0;
	int i;
	
	 
	
	fhandle = FS_OpenFile(filename, "rt");
	
	if (!fhandle)
	{
		return 0;
	}
	
	LE_pushLexer();
	LE_init(fhandle);
	
	
	mesh->memLocation = MD5_MEMLOC_RAM;
	
	//printf("[MD5_LoadEntity] Loading MD5 '%s' .\n",filename); 

	
	
	while (LE_hasMoreData()) 
	{
		LE_readToken();
		
		if(!strcmp("MD5Version", LE_getCurrentToken()))
		{
			versionNumber = LE_readReal();
			if (versionNumber != 10)
			{
				printf ("[MD5_Loader ERROR] : %s has a bad model version (%d)\n",filename,versionNumber);
				return 0;
			}
		}
		else
		if (!strcmp("numJoints", LE_getCurrentToken()))
		{
			mesh->numBones = LE_readReal();
			mesh->bones = (md5_bone_t*)calloc(mesh->numBones,sizeof(md5_bone_t));
			//printf("[MD5_LoadEntity] Found numJoints: %d.\n",mesh->numBones);
		}
		else
		if (!strcmp("mesh", LE_getCurrentToken()))
		{
			//printf("[MD5_LoadEntity] Found mesh.\n");
			MD5_ReadMesh(mesh);  
		}
		else
		if (!strcmp("numMeshes", LE_getCurrentToken()))
		{
			//printf("[MD5_LoadEntity] Found numMeshes.\n");
			if(LE_readReal() > 1)
			{
				printf("[MD5_Loader ERROR] %s has more than one mesh: Not supported.\n",filename);
				return 0;
			}
		}		   
		else
		if (!strcmp("joints", LE_getCurrentToken()))
		{
			//printf("[MD5_LoadEntity] Found joints.\n");
			MD5_ReadJoints(mesh->bones,mesh->numBones);
		}		   
		   
	}
	

	
	mesh->vertexArray = (vertex_t*)calloc(mesh->numVertices, sizeof(vertex_t));
	mesh->indices = (ushort*)calloc(mesh->numTriangles * 3,sizeof(ushort));
	
	//Write indices
	mesh->numIndices=0 ;
	for (i = 0  ; i < mesh->numTriangles; i++)
	{
		mesh->indices[mesh->numIndices++] = mesh->triangles[i].index[0];
		mesh->indices[mesh->numIndices++] = mesh->triangles[i].index[1];
		mesh->indices[mesh->numIndices++] = mesh->triangles[i].index[2];
	}
	
	//Write textureCoo
	//Set all textures coordinate once for all, this will never change
	currentVertex = mesh->vertexArray;
	for(verticesCounter=0 ; verticesCounter < mesh->numVertices ; verticesCounter++,currentVertex++)
	{
		currentVertex->text[0] = mesh->vertices[verticesCounter].st[0];
		currentVertex->text[1] = mesh->vertices[verticesCounter].st[1];
	}
	
	//printf("[MD5 Loader] %d vertices.\n",mesh->numVertices);
	//printf("[MD5 Loader] %d triangles.\n",mesh->numTriangles);
	//printf("[MD5 Loader] %d indices.\n",mesh->numIndices);
	
	
	
	MD5_GenerateSkin(mesh,mesh->bones);
	MD5_GenerateLightingInfo(mesh);
	MD5_GenerateSkin(mesh,mesh->bones);
	
	//Bounding box
	MD5_GenerateModelSpaceBBox(mesh);
	
	if (TRACE_BLOCK)
	{
	if (!strcmp(filename,"data/models/misc/FRA200L.obj.md5mesh"))
	{
		currentVertex = mesh->vertexArray;
		printf("Listing Vertices.\n");
		for (i=0; i < mesh->numVertices ; i++,currentVertex++) 
		{
			printf("vertex: %d/%hu  (norm: %hd , %hd , %hd ) (text: %hd , %hd ) (pos: %f , %f , %f )\n",
				   i,
				   mesh->numVertices-1,   
				   currentVertex->normal[0],
				   currentVertex->normal[1],
				   currentVertex->normal[2],
				   currentVertex->text[0],
				   currentVertex->text[1],
				   currentVertex->pos[0],
				   currentVertex->pos[1],
				   currentVertex->pos[2]	   
				   );
		}


		printf("Listing indices.\n");
		for(i=0;  i < mesh->numIndices ; i++)
		{
			printf("indice: %d/%hu, vertex: %hu   (norm: %hd , %hd , %hd ) (text: %hd , %hd ) (pos: %f , %f , %f )\n",
				   i,
				   mesh->numIndices-1,   
					mesh->indices[i],
				   mesh->vertexArray[mesh->indices[i]].normal[0],
				   mesh->vertexArray[mesh->indices[i]].normal[1],
				   mesh->vertexArray[mesh->indices[i]].normal[2],
				   mesh->vertexArray[mesh->indices[i]].text[0],
				   mesh->vertexArray[mesh->indices[i]].text[1],
				   mesh->vertexArray[mesh->indices[i]].pos[0],
				   mesh->vertexArray[mesh->indices[i]].pos[1],
				   mesh->vertexArray[mesh->indices[i]].pos[2]	 
				   );
		}
	}
	}

	FS_CloseFile(fhandle);
	LE_popLexer();
	
	
	//Cache mesh to speed up future loading.
	
	return 1;
}
Exemplo n.º 6
0
int main (int argc, char **argv) {
    double cr_t, l_open, l_read;

    /* get command line options */
    if (Read_options (argc, argv) != 0)
	exit (1);

    if (Le_label != NULL)
	LE_set_option ("label", Le_label);
    if (!(Le_label != NULL && strcmp (Le_label, "stderr") == 0))
	LE_init (argc, argv);

    sigset (SIGPIPE, Sig_callback);

    if (Server_port > 0 &&
	RMT_port_number (Server_port) < 0) {
	MISC_log ("RMT_port_number (%d) failed\n", Server_port);
	exit (1);
    }

    Open_lbs ();

    RMT_time_out (0x7ffffff);	/* never timed out */

    if (Byteswap_func != NULL)
	Set_byte_swap ();

    /* static replication */
    if (Max_static_msgs > 0) {
	Static_rp ();
	MISC_log ("Static replication done\n");
	if (Static_rep_only) {
	    MISC_log ("Static replication only - exit\n");
	    exit (0);
	}
    }

    /* dynamic replication */
    l_open = Get_cr_time ();
    l_read = l_open;
    while (1) {
	int i;
	l_read += Poll_ms;
	for (i = 0; i < N_reps; i++) {
	    if (!(Rep_list[i].stype & LB_DB))
	        Copy_mq_msg (Rep_list + i);  /* may not return if Poll_set */
	}
	while ((cr_t = Get_cr_time ()) < l_read) {
	    msleep (100);
	    Replic_db_lbs ();
	}
	if (Poll_set)
	    l_read = cr_t;
	Replic_db_lbs ();
	if (cr_t >= l_open + 10000) {		/* open every 10 seconds */
	    Open_lbs ();
	    l_open = cr_t;
	}
    }

    exit (0);
}