コード例 #1
0
/* rename - rename a file or directory
 * Errors - path resolution, ENOENT, EINVAL, EEXIST
 *
 * ENOENT - source does not exist
 * EEXIST - destination already exists
 * EINVAL - source and destination are not in the same directory
 *
 * Note that this is a simplified version of the UNIX rename
 * functionality - see 'man 2 rename' for full semantics. In
 * particular, the full version can move across directories, replace a
 * destination file, and replace an empty directory with a full one.
 */
static int hw4_rename(const char *src_path, const char *dst_path)
{
	char *sub_src_path = (char*)calloc(16*44,sizeof(char));
	char *sub_dst_path = (char*)calloc(16*44,sizeof(char));

	char path1[20][44];
	char path2[20][44];
	
	int k = 0;

	strcpy(sub_src_path, src_path);
	strcpy(sub_dst_path, dst_path);

	// save src path to path1
	// save dst path to path2
	while(1)
	{
		sub_src_path = strwrd(sub_src_path, path1[k], 44, " /");
		sub_dst_path = strwrd(sub_dst_path, path2[k], 44, " /");
		
		if (sub_src_path == NULL && sub_dst_path == NULL)
			break;
		
		if (sub_src_path == NULL || sub_dst_path == NULL)
			return -EINVAL;
			
		if (strcmp(path1[k], path2[k]) != 0)
			return -EINVAL;
			
		k++;
	}

	char *filename = (char*)malloc(sizeof(char)*44);
	strcpy(filename, path2[k]);
	
	int blk_num = super->root_dirent.start;
	int current_blk_num;

	// find the block and entry number of the src path
	int entry = parsePath((void*)src_path, blk_num);
	current_blk_num = new_current_blk_num;
	
	// find the entry number of the dst path
	int dst_entry = lookupEntry(filename, current_blk_num);

	// check if the dst file is existed
	if (dst_entry != -1)
		return -EEXIST;

	strcpy(directory[entry].name, filename);
	directory[entry].mtime = time(NULL);

	// write back
	disk->ops->write(disk, current_blk_num*2, 2, (void*)directory);

	free(filename);
	free(sub_src_path);
	free(sub_dst_path);
    return 0;
}
コード例 #2
0
static int hw4_getattr(const char *path, struct stat *sb)
{
	char *sub_path = (char*)calloc(16*44,sizeof(char));
	strcpy(sub_path, path);
	
	int start = super->root_dirent.start;
	int entry;
	
	// find the block and entry of the path

	while(sub_path != NULL)
 	{			
		memset(name,0,sizeof(name));
		sub_path = strwrd(sub_path, name, sizeof(name), "/");
		disk->ops->read(disk, start * 2, 2, (void*)directory);
		entry = lookupEntry(name, start);		
		if(entry == -1) 
			return -ENOENT;
		start = directory[entry].start;
	}

	convertAttr(entry, sb);
	free(sub_path);

    return 0;
}
コード例 #3
0
ファイル: value.c プロジェクト: alabid/scheme_interpreter
void destroyFrame(Environment *env){
  assert(env!=NULL);
  Value *subEnvCounter = lookup(env->bindings->tableValue, "#envID");
  assert(subEnvCounter!=NULL);
  assert(subEnvCounter->type==integerType);
  int i;
  ConsCell *entry;
  char *id;

  for (i = subEnvCounter->intValue;i>=0;i--){
    id = intToString(i);
  
    assert(env->bindings->tableValue!=NULL);
    entry = lookupEntry(env->bindings->tableValue, id);
    
    if (entry){

      destroyFrame(entry->cdr->envValue);

      free(entry->cdr);
      entry->cdr = NULL;
    }
    free(id);
  }
  destroyEnvironment(env);
}
コード例 #4
0
ファイル: model_obj.cpp プロジェクト: Almamu/crashutils
void model_obj::load(entry *svtx, int frame, texture_buffer *texbuf, prim_alloc *prims)
{
  positionMode = 1;
  location.X = 0;
  location.Y = 0;
  location.Z = 0;
  
  vertCount = 0;
  polyCount = 0;
  
  if (svtx->type != 1) { return; }
  
  if (svtx->itemData[frame] == 0 || svtx->itemSize[frame] == 0) { return; }
  
  unsigned char *buffer = svtx->itemData[frame];
  
  vertCount               =        getWord(buffer, 0, true);
  unsigned long tgeoEID   =        getWord(buffer, 4, true);
  unsigned long parentCID =         nsd->lookupCID(tgeoEID);
  chunk *parentChunk      =     nsf->lookupChunk(parentCID);
  entry *tgeoEntry        = lookupEntry(tgeoEID, parentChunk);

  loadVertices(svtx, frame, prims);
  loadPolygons(tgeoEntry, texbuf, prims);
  render = true;
}
コード例 #5
0
/* parsePath 
 * parse the path and return the entry number
 */
int parsePath(char *path, int blk_num)
{
	new_blk_num = blk_num;
	int entry = 0;
	// root directory
	if(strlen(path) == 1)
	{
		disk->ops->read(disk, new_blk_num * 2, 2, (void*)directory);
		return entry;
	}
	
	while(path != NULL)
	{
		memset(name,0,sizeof(name));
		path = strwrd((char*)path, name, sizeof(name),"/");
		disk->ops->read(disk, new_blk_num * 2, 2, (void*)directory);
		entry = lookupEntry(name, new_blk_num);
		if (entry == -1) 
			return -ENOENT;
		if (entry <0)
			return entry;
		new_current_blk_num = new_blk_num;
		new_blk_num = directory[entry].start;
	}
	
	return entry;
}
コード例 #6
0
ファイル: value.c プロジェクト: alabid/scheme_interpreter
// can free top frame and also destory itself.
void destroyTopFrame(Environment *env){
  assert(env!=NULL);
  Environment *top = env;
  while (top->parent){
    top = top->parent;
  }  // make sure it is the top level environment.
  Value *subEnvCounter = lookup(top->bindings->tableValue, "#envID");
  assert(subEnvCounter!=NULL);
  assert(subEnvCounter->type==integerType);
  int i;
  ConsCell *entry;
  char *id;

  for (i = subEnvCounter->intValue ;i>=0;i--){
    id = intToString(i);
  
    assert(top->bindings->tableValue!=NULL);
    entry = lookupEntry(top->bindings->tableValue, id);
    if (entry){
      destroyFrame(entry->cdr->envValue);
    
      free(entry->cdr);
      entry->cdr = NULL;
    }
    free(id);
  }
  destroyEnvironment(env);
}
コード例 #7
0
ファイル: value.c プロジェクト: alabid/scheme_interpreter
/*
  Return the payload with key = id
*/
Value* lookup(HashTable* table, char* id){
  ConsCell* entry = lookupEntry(table, id);
  if (entry){
    return entry->cdr;
  }else{
    return NULL;
  }
}
コード例 #8
0
mxArray* getEnqBufCount()
{
   double retVal = 0.0;
   biEntry* cmdStruct = lookupEntry("PageList", vars, ARRAYLEN(vars));
   if (cmdStruct->var != NULL)
      retVal = mxGetNumberOfElements(cmdStruct->var);

   return mxCreateDoubleScalar(retVal);
}
コード例 #9
0
void incPageNo()
{
   double* pageNo;
   biEntry* cmdStruct = lookupEntry("PageNo", vars, ARRAYLEN(vars));
   if (cmdStruct->var == NULL)
   {
      cmdStruct->var = mxCreateDoubleScalar(1.0);
      mexMakeArrayPersistent(cmdStruct->var);
   }
   else
   {
      pageNo = mxGetPr(cmdStruct->var);
      *pageNo = *pageNo + 1.0;
   }
}
コード例 #10
0
ファイル: value.c プロジェクト: alabid/scheme_interpreter
/*
  Delete an item with key = id.
  This function does not free the payload since we did not malloc memory 
  inside the insertItem function for payload.
*/
int deleteItem(HashTable* table, char* id){
  ConsCell* entry = lookupEntry(table, id);
  if (entry){
    if (entry->car && entry->car->type == symbolType){
      free(entry->car->symbolValue); 
      free(entry->car);
      freeValue(entry->cdr);
     }
     entry->car = NULL;
     //entry->cdr = NULL;
     (table->size)--;
     
    return 1;
  }
  return 0;
}
コード例 #11
0
void pushPage(const mxArray* in)
{
   biEntry* cmdStruct = lookupEntry("PageList", vars, ARRAYLEN(vars));
   if (cmdStruct->var == NULL)
   {
      cmdStruct->setter(cmdStruct, in);
   }
   else
   {
      size_t M = mxGetM(cmdStruct->var);
      size_t N = mxGetN(cmdStruct->var);
      size_t maxMN = M > N ? M : N;
      mxArray* tmp = mxCreateDoubleMatrix(1, maxMN + 1, mxREAL);
      memcpy(mxGetPr(tmp), mxGetPr(cmdStruct->var), maxMN * sizeof(double));
      memcpy(mxGetPr(tmp) + maxMN, mxGetPr(in), sizeof(double));
      cmdStruct->setter(cmdStruct, tmp);
   }
}
コード例 #12
0
mxArray* popPage()
{
   size_t M,N,maxMN;
   double retVal;
   mxArray* tmp;
   biEntry* cmdStruct = lookupEntry("PageList", vars, ARRAYLEN(vars));
   if (cmdStruct->var == NULL)
   {
      return cmdStruct->getter(cmdStruct);
   }
   else
   {
      retVal = mxGetScalar(cmdStruct->var);
      M = mxGetM(cmdStruct->var);
      N = mxGetN(cmdStruct->var);
      maxMN = M > N ? M : N;
      tmp = mxCreateDoubleMatrix(1, maxMN - 1, mxREAL);
      memcpy(mxGetPr(tmp), mxGetPr(cmdStruct->var) + 1, (maxMN - 1)*sizeof(double));
      cmdStruct->setter(cmdStruct, tmp);
      return mxCreateDoubleScalar(retVal);
   }
}
コード例 #13
0
/*
 * Cereate the entry depending on the isDir
 */
int createEntry(const char *path, mode_t mode, int isDir)
{
	
	int entry=0;

	char *new_name = (char*)calloc(44,sizeof(char));

	int i, j;

	// save the path in paths
	// save the name in new_name
	char paths[20][44];
	int k = 0;

	while(1)
	{
		path = strwrd((char*)path, paths[k], sizeof(paths[k]), "/");
		strcpy(new_name, paths[k]);
		if (path == NULL)
			break;
		k++;
	}

	
	int blk_num = super->root_dirent.start;
	// find the location of the path
	for(i = 0; i < k; i++)
	{
		disk->ops->read(disk, blk_num * 2, 2, (void*)directory);
		entry = lookupEntry(paths[i], blk_num);
		if(entry == -1) 
			return -ENOENT;
		blk_num = directory[entry].start;
	}

	disk->ops->read(disk, blk_num * 2, 2, (void*)directory);
	
	// check if the entry is exsisted
	for(i = 0; i < 16; i++)
		if(strcmp(directory[i].name, paths[k]) == 0)
			return -EEXIST;

	// find an entry that is free
	for(i = 0; i < 16; i++)
		if(directory[i].valid == 0)
			break;
	
	// find a free block
	for(j = 0; j < 1024; j++)
	{
		if(fat[j].inUse == 0)
		{
			fat[j].inUse = 1;
			fat[j].eof = 1;		
			break;
		}
	}
	
	if(j==1024) 
		return -ENOSPC;

	// initialize the file
	directory[i].valid = 1;
	directory[i].isDir = isDir;
	directory[i].length = 0;
	directory[i].start = j;
	directory[i].mode = mode;
	directory[i].mtime = time(NULL);
	directory[i].gid = getgid();
	directory[i].uid = getuid();	
	directory[i].pad = 0;
	strcpy(directory[i].name, new_name);
	
	// write back
	disk->ops->write(disk,blk_num*2,2,(void*)directory);
	disk->ops->write(disk,2,8,(void*)fat);	

	free(new_name);
    return 0;
}
コード例 #14
0
ファイル: crashutils.cpp プロジェクト: Almamu/crashutils
void crashutils::onLookup(unsigned long EID, entry **result)
{
  unsigned long parentCID = nsd->lookupCID(EID);
  chunk *parentChunk      = nsf->lookupChunk(parentCID);
  *(result)               = lookupEntry(EID, parentChunk);
}
コード例 #15
0
ファイル: zonelist.cpp プロジェクト: Almamu/crashutils
void zoneList::occupy(entry *zone)
{
  unsigned char *zoneHeader = zone->itemData[0];
  modelCount = getWord(zoneHeader, 0, true);  
  headerColCount = getWord(zoneHeader, 0x204, true);
  sectionCount = getWord(zoneHeader, 0x208, true);
  entityCount = getWord(zoneHeader, 0x20C, true);
  neighborCount = getWord(zoneHeader, 0x210, true);
  
  char zoneModelString[8][30];
  for (unsigned long lp=0; lp<modelCount; lp++)
  {
    unsigned long modelEID = getWord(zoneHeader, 4+(lp*0x40), true);
    getEIDstring(zoneModelString[lp], modelEID);
    
    unsigned long parentCID = nsd->lookupCID(modelEID);
    if (parentCID != -1)
    {
      chunk *parentChunk      = nsf->lookupChunk(parentCID);
      zoneModel[lp]           = lookupEntry(modelEID, parentChunk);
    }
    else
    {
      char temp[6];
      getEIDstring(temp, modelEID);
      sprintf(zoneModelString[lp], "BAD REF: %s", temp);
      
      zoneModel[lp] = 0;
    }
  }
  
  char zoneEntityString[20][10];
  for (unsigned long lp=0; lp<entityCount; lp++)
  {
    unsigned char *entity = zone->itemData[headerColCount+sectionCount+lp];
    
    unsigned short entityID = getHword(entity, 0x8, true);
    
    unsigned char codeIndex = entity[0x12];
    unsigned long entityCodeEID = nsd->levelEIDs[codeIndex];
    char entityCodeEIDString[6];
    getEIDstring(entityCodeEIDString, entityCodeEID);
    
    sprintf(zoneEntityString[lp], "%i: %s", entityID, entityCodeEIDString);
  }
  
  char zoneNeighborString[20][10];
  for (unsigned long lp=0; lp<neighborCount; lp++)
  {
    unsigned long neighborEID = getWord(zoneHeader, 0x214+(lp*4), true);
    getEIDstring(zoneNeighborString[lp], neighborEID);
    
    unsigned long parentCID = nsd->lookupCID(neighborEID);
    if (parentCID != -1)
    {
      chunk *parentChunk      = nsf->lookupChunk(parentCID);
      zoneNeighbor[lp]        = lookupEntry(neighborEID, parentChunk);
    }
    else
    {
      char temp[6];
      getEIDstring(temp, neighborEID);
      sprintf(zoneNeighborString[lp], "BAD REF: %s", temp);
      
      zoneNeighbor[lp] = 0;
    }
  }
  
  char zoneEIDString[6];
  getEIDstring(zoneEIDString, zone->EID);
  
  char zoneString[20];
  sprintf(zoneString, "Zone: %s", zoneEIDString);
  
  AddItemToTree(hwnd, zoneString, 1, 1);
  
  AddItemToTree(hwnd, "Models", 2, 0);
  for (unsigned long lp=0; lp<modelCount; lp++)    
    AddItemToTree(hwnd, zoneModelString[lp], 3, (lp << 8) | 3);
  
  AddItemToTree(hwnd, "Entities", 2, 0);
  for (unsigned long lp=0; lp<entityCount; lp++)
    AddItemToTree(hwnd, zoneEntityString[lp], 3, (lp << 8) | 5);
  
  AddItemToTree(hwnd, "Sections", 2, 0);
  for (unsigned long lp=0; lp<sectionCount; lp++)
  {
    char sectionString[20];
    sprintf(sectionString, "Section %i", lp);
    AddItemToTree(hwnd, sectionString, 3, 0);
    
    AddItemToTree(hwnd,            "Camera", 4, (lp << 8) | (0 << 3) | 4);
    AddItemToTree(hwnd, "Neighbor Sections", 4, (lp << 8) | (1 << 3) | 4);
  }
  
  AddItemToTree(hwnd, "Neighbor Zones", 2, 0);
  for (unsigned long lp=0; lp<neighborCount; lp++)
  {
    AddItemToTree(hwnd, zoneNeighborString[lp], 3, (lp << 8) | 2);
  }
  
  AddItemToTree(hwnd,          "Lighting properties", 2, (1 << 3) | 1);
  AddItemToTree(hwnd, "Shading/rendering properties", 2, (2 << 3) | 1); 
  AddItemToTree(hwnd,             "Collision octree", 2, (3 << 3) | 1);
}
コード例 #16
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
   (void) nlhs; // To avoid the unused parameter warning
   static int atExitRegistered = 0;
   if (!atExitRegistered)
   {
      atExitRegistered = 1;
      mexAtExit(clearAllWrapper);
   }
   if (nrhs < 1)
   {
      mexErrMsgTxt("BLOCK_INTERFACE: Not enough input arguments.");
   }

   const mxArray* mxCmd = prhs[0];
   char command[COMMAND_LENGTH];
   size_t comStrLen = mxGetNumberOfElements(mxCmd);
   mxGetString(mxCmd, command, comStrLen + 1);

   if (!strncmp(command, "set", 3))
   {
      if (nrhs < 2)
      {
         mexErrMsgTxt("BLOCK_INTERFACE: Not enough arguments for the set method.");
      }
      biEntry* cmdStruct = lookupEntry(command + 3, vars, ARRAYLEN(vars));

      if (cmdStruct == NULL)
      {
         mexErrMsgTxt("BLOCK_INTERFACE: Unrecognized set command.");
      }
      cmdStruct->setter(cmdStruct, prhs[1]);
      return;
   }
   else if (!strncmp(command, "get", 3))
   {
      if (nrhs > 1)
      {
         mexErrMsgTxt("BLOCK_INTERFACE: Too many input arguments for get method.");
      }
      biEntry* cmdStruct = lookupEntry(command + 3, vars, ARRAYLEN(vars));
      if (cmdStruct == NULL)
      {
         mexErrMsgTxt("BLOCK_INTERFACE: Unrecognized get command.");
      }
      plhs[0] = cmdStruct->getter(cmdStruct);
      return;
   }
   else if (!strcmp(command, "reset"))
   {
      resetAll(vars, ARRAYLEN(vars));
      return;

   }
   else if (!strcmp(command, "incPageNo"))
   {
      incPageNo();
      return;
   }
   else if (!strcmp(command, "popPage"))
   {
      plhs[0] = popPage();
      return;
   }
   else if (!strcmp(command, "pushPage"))
   {
      pushPage(prhs[1]);
      return;
   }
   else if (!strcmp(command, "clearAll"))
   {
      clearAllWrapper();
      return;
   }
   else if (!strcmp(command, "flushBuffers"))
   {
      biEntry* be1 = lookupEntry("AnaOverlap", vars, ARRAYLEN(vars));

      if (be1->var != NULL)
      {
         mxDestroyArray(be1->var);
         be1->var = NULL;
      }
      biEntry* be2 = lookupEntry("SynOverlap", vars, ARRAYLEN(vars));

      if (be2->var != NULL)
      {
         mxDestroyArray(be2->var);
         be2->var = NULL;
      }
      return;
   }

   mexErrMsgTxt("BLOCK_INTERFACE: Unrecognized command.");

}
コード例 #17
0
ファイル: model_obj_md3.cpp プロジェクト: Almamu/crashutils
void model_obj_md3::exportMD3(entry *svtx, texture_buffer_md3 *texbuf, prim_alloc *prims, char *filename)
{
  int frameCount          =                   svtx->itemCount;
  unsigned char *buffer   =                 svtx->itemData[0];
  vertCount               =          getWord(buffer, 0, true);
  unsigned long tgeoEID   =          getWord(buffer, 4, true);
  unsigned long parentCID =           nsd->lookupCID(tgeoEID);
  chunk *parentChunk      =       nsf->lookupChunk(parentCID);
  entry *tgeo             = lookupEntry(tgeoEID, parentChunk);
  
  loadPolygons(tgeo, texbuf, prims);
  
  md3_header header;
  md3_frame* frames = (md3_frame*) calloc(frameCount, sizeof(md3_frame));
  md3_surface surface;  
  md3_triangle* md3_triangles = (md3_triangle*)calloc(polyCount, sizeof(md3_triangle));
  md3_texcoord* md3_texcoords = (md3_texcoord*)calloc(vertCount, sizeof(md3_texcoord));
  md3_vertex** md3_vertices = (md3_vertex**)calloc(frameCount * vertCount, sizeof(md3_vertex));

  memset(frames, 0, frameCount * sizeof(md3_frame));
  memset(frames, 0, polyCount * sizeof(md3_triangle));
  memset(frames, 0, vertCount * sizeof(md3_texcoord));
  memset(frames, 0, frameCount * vertCount * sizeof(md3_vertex));

  sprintf(header.ident, "IDP3");
  header.version = 15;
  sprintf(header.name, "%s", filename);
  header.flags = 0;
  header.num_frames = frameCount;
  header.num_tags = 0;
  header.num_surfaces = 1;
  header.num_skins = 0;
  
  sprintf(surface.ident, "IDP3");
  getEIDstring(surface.name, svtx->EID);
  surface.flags = 0;
  surface.num_frames = frameCount;
  surface.num_shaders = 1;
  surface.num_verts = vertCount;
  surface.num_triangles = polyCount;
  
  for (int frm = 0; frm < frameCount; frm++)
  {
    loadVertices(svtx, frm, prims);
    
    for (int vrt = 0; vrt < vertCount; vrt++)
    {
      svector *coord = &md3_vertices[frm][vrt].coord;
      coord->X = (signed short) (vertices[vrt].X * 64);
      coord->Y = (signed short) (vertices[vrt].Y * 64);
      coord->Z = (signed short) (vertices[vrt].Z * 64);
      
      md3_normal *normal = &md3_vertices[frm][vrt].normal;
      normal->z = (unsigned char) (atan2(normals[vrt].Y, normals[vrt].X) * 255 / (2 * PI));
      normal->a = (unsigned char) (acos(normals[vrt].Z) * 255 / (2 * PI));
    }
    
    frames[frm].min_bounds = bound.P1;
    frames[frm].max_bounds = bound.P2;
    frames[frm].local_origin = { 0, 0, 0 }; //or is this the other point value in the svtx data
    
    float A = bound.P2.X - bound.P1.X;
    float B = bound.P2.Y - bound.P1.Y;
    float C = bound.P2.Z - bound.P2.Z;
    float radius = (float) (sqrt((A * A) + (B * B) + (C * C)) /2);
    frames[frm].radius = radius;
    
    sprintf(frames[frm].name, "Frame %i", frm);
  }
  
  
  int it = 0;
  while (filename[it++] != 0);
  while (filename[--it] != '.');
  filename[it+1] = 't';
  filename[it+2] = 'g';
  filename[it+3] = 'a';
  filename[it+4] = 0;
  texbuf->exportTGA((const char*)filename);
  
  bakePolygonTextures(texbuf);

  for (int ply = 0; ply < polyCount; ply++)
  {
    unsigned long indexA = (unsigned long)(polygons[ply].vertexA - vertices);
    unsigned long indexB = (unsigned long)(polygons[ply].vertexB - vertices);
    unsigned long indexC = (unsigned long)(polygons[ply].vertexC - vertices);

    md3_triangles[ply].indexes[0] = indexA;
    md3_triangles[ply].indexes[1] = indexB;
    md3_triangles[ply].indexes[2] = indexC;
    
    md3_texcoords[ply].s = polygons[ply].tex->coords.A.X;
    md3_texcoords[ply].t = polygons[ply].tex->coords.A.Y;
  }

  md3_shader shader;
  sprintf(shader.name, "shader");
  shader.index = 0;
  
  unsigned long md3_start = 0;
  header.ofs_frames = md3_start + sizeof(header);
  header.ofs_tags = header.ofs_frames + sizeof(frames);
  header.ofs_surfaces = header.ofs_tags + 0; //0 = no tags
  
  unsigned long surface_start = header.ofs_surfaces;
  surface.ofs_shaders = surface_start + sizeof(surface);
  surface.ofs_triangles = surface.ofs_shaders + sizeof(shader);  
  surface.ofs_st = surface.ofs_triangles + sizeof(md3_triangles);
  surface.ofs_xyznormal = surface.ofs_st + sizeof(md3_texcoords);
  surface.ofs_end  = surface.ofs_xyznormal + sizeof(md3_vertices);
  
  header.ofs_eof = surface.ofs_end;

  
  it = 0;
  while (filename[it++] != 0);
  while (filename[--it] != '.');
  filename[it+1] = 'm';
  filename[it+2] = 'd';
  filename[it+3] = '3';
  filename[it+4] = 0;
  
  
  FILE *md3 = fopen((const char*)filename, "w+b");
  
  fwrite(&header, sizeof(md3_header), 1, md3);
  fwrite(&frames, sizeof(md3_frame), frameCount, md3);
  //fwrite(tags, sizeof(md3_tag), tagCount, md3);
  fwrite(&surface, sizeof(md3_surface), 1, md3);
  
  fwrite(&shader, sizeof(md3_shader), 1, md3);
  fwrite(&md3_triangles, sizeof(md3_triangle), polyCount, md3);
  fwrite(&md3_texcoords, sizeof(md3_texcoordquad), polyCount, md3);
  fwrite(&md3_vertices, sizeof(md3_vertex), vertCount * frameCount, md3);
  
  fclose(md3);
      
  it = 0;
  while (filename[it++] != 0);
  while (filename[--it] != '.');
  filename[it+1] = 't';
  filename[it+2] = 'g';
  filename[it+3] = 'a';
  filename[it+4] = 0;
  texbuf->exportTGA((const char*)filename);

  free(frames);
  free(md3_triangles);
  free(md3_texcoords);
  free(md3_vertices);

}
コード例 #18
0
ファイル: scene.cpp プロジェクト: wurlyfox/crashutils
void scene::addModel(entry *svtx, int frame, vector *trans, angle *rot, vector *scale, slightmatrix *light, scolormatrix *color, scolor *back, scolor *backIntensity)
{
  //model *mod = allocateModel();
  model *mod = modelBuffer[*modelCount];
  
  unsigned char *svtxFrame = svtx->itemData[frame];
  
  unsigned long tgeoEID    = getWord(svtxFrame, 4, true);
  unsigned long parentCID  = nsd->lookupCID(tgeoEID);
  chunk *parentChunk       = nsf->lookupChunk(parentCID);
  entry *tgeo              = lookupEntry(tgeoEID, parentChunk);
  
  unsigned char *modelHeader = tgeo->itemData[0];
  signed long modelXscale = getWord(modelHeader,   4, true);
  signed long modelYscale = getWord(modelHeader,   8, true);
  signed long modelZscale = getWord(modelHeader, 0xC, true);
    
  mod->type           = 1;
  mod->object_model   = geom->getObject(svtx, frame);
  mod->object_model->positionMode = 1;
  mod->trans.X        = ((float)(trans->X >> 8) / 0x1000) * 8;  
  mod->trans.Y        = ((float)(trans->Y >> 8) / 0x1000) * 8;
  mod->trans.Z        = ((float)(trans->Z >> 8) / 0x1000) * 8;
  mod->rot.X          = ((((float)rot->X) / 0x1000) * 360);
  mod->rot.Y          = ((((float)rot->Y) / 0x1000) * 360);
  mod->rot.Z          = ((((float)rot->Z) / 0x1000) * 360);
  mod->scale.X        = ((float)scale->X / 0x1000) * ((float)modelXscale / 0x1000);
  mod->scale.Y        = ((float)scale->Y / 0x1000) * ((float)modelYscale / 0x1000);
  mod->scale.Z        = ((float)scale->Z / 0x1000) * ((float)modelZscale / 0x1000);
  
  mod->lightMatrix.V1.X = (float)light->V1.X / 0x1000;
  mod->lightMatrix.V2.X = (float)light->V2.X / 0x1000;
  mod->lightMatrix.V3.X = (float)light->V3.X / 0x1000;
  mod->lightMatrix.V1.Y = (float)light->V1.Y / 0x1000;
  mod->lightMatrix.V2.Y = (float)light->V2.Y / 0x1000;
  mod->lightMatrix.V3.Y = (float)light->V3.Y / 0x1000;
  mod->lightMatrix.V1.Z = (float)light->V1.Z / 0x1000;
  mod->lightMatrix.V2.Z = (float)light->V2.Z / 0x1000;
  mod->lightMatrix.V3.Z = (float)light->V3.Z / 0x1000;
  
  mod->colorMatrix.C1.R = (float)color->C1.R / 0x1000;
  mod->colorMatrix.C2.R = (float)color->C2.R / 0x1000;
  mod->colorMatrix.C3.R = (float)color->C3.R / 0x1000;
  mod->colorMatrix.C1.G = (float)color->C1.G / 0x1000;
  mod->colorMatrix.C2.G = (float)color->C2.G / 0x1000;
  mod->colorMatrix.C3.G = (float)color->C3.G / 0x1000;
  mod->colorMatrix.C1.B = (float)color->C1.B / 0x1000;
  mod->colorMatrix.C2.B = (float)color->C2.B / 0x1000;
  mod->colorMatrix.C3.B = (float)color->C3.B / 0x1000;
  
  mod->backColor.R = (((float)back->R) * ((float)backIntensity->R / 256)) / 0x1000;
  mod->backColor.G = (((float)back->G) * ((float)backIntensity->G / 256)) / 0x1000;
  mod->backColor.B = (((float)back->B) * ((float)backIntensity->B / 256)) / 0x1000;

  mod->colors = &colorBuffer[colorCount];
  //mod->colors = 0;
  colorCount += ((mod->object_model->polyTexCount + mod->object_model->polyNonCount) * 3);
  
  mod->calcColors();  
  (*modelCount)++;
}