Example #1
0
int main(void) {
	char str_1[256] = "123456789";
	char str_2[256] = "abcdefg";
	char str_3[256] = "ABCDEFGHIJKLMN";
	char *p_memory_1 = NULL;
	char *p_memory_2 = NULL;
	bool ok_new;

	p_memory_1 = (char *)malloc(64);
	if (NULL == p_memory_1) {
		printf("malloc() failure! [%p]\n", p_memory_1);
	}
	else {
		printf("malloc() success! [%p]\n", p_memory_1);
		memcpy(p_memory_1, str_1, strlen(str_1));
		free(p_memory_1);
	}

	ok_new = NewMemory(&p_memory_2, 64);
	if (false == ok_new) {
		printf("NewMemory() failure! [%d,%p]\n", ok_new, p_memory_2);
	}
	else {
		printf("NewMemory() success! [%d,%p]\n", ok_new, p_memory_2);
		memcpy(p_memory_2, str_1, strlen(str_1));
		ResizeMemory(&p_memory_2, 128);
		memcpy(p_memory_2 + strlen(str_1), str_2, strlen(str_2));
		ResizeMemory(&p_memory_2, 32);
		FreeMemory(p_memory_2);
	}

	return 0;
}
Example #2
0
static inline int CreateSSector(struct Seg *tmps)
{
	struct Seg *next;
	int n;

	if(num_ssectors == 0)
		{
		ssectors = GetMemory(sizeof(struct SSector));
		}
	else
		{
		ssectors = ResizeMemory(ssectors,sizeof(struct SSector)*(num_ssectors+1));
		}
	
	ssectors[num_ssectors].first = num_psegs;

	n = num_psegs;
	
/*	printf("\n");*/

	for(;tmps;tmps=next)
		{
		if(num_psegs == 0)
			{
			psegs = GetMemory(sizeof(struct Pseg));
			}
		else
			{
			psegs = ResizeMemory(psegs,sizeof(struct Pseg)*(num_psegs+1));
			}

		psegs[num_psegs].start = tmps->start;
		psegs[num_psegs].end = tmps->end;
		psegs[num_psegs].angle = tmps->angle;
		psegs[num_psegs].linedef = tmps->linedef;
		psegs[num_psegs].flip = tmps->flip;
		psegs[num_psegs].dist = tmps->dist;
/*
		printf("%d,%d,%u,%d,%d,%u\n",
			psegs[num_psegs].start,
			psegs[num_psegs].end,
			psegs[num_psegs].angle,
			psegs[num_psegs].linedef,
			psegs[num_psegs].flip,
			psegs[num_psegs].dist);
*/
		num_psegs++;
		next = tmps->next;
		free(tmps); /* This seg is done */
		}

	ssectors[num_ssectors].num = num_psegs-n;

	num_ssectors++;

	return num_ssectors-1;
}
Example #3
0
void ResetObject()
{
   int i,old_objects;
   class_node *c;

   for (i=0;i<num_objects;i++)
   {
      if (!objects[i].deleted)
      {
	 c = GetClassByID(objects[i].class_id);
	 if (c == NULL)
	 {
	    eprintf("ResetObject can't find class id %i\n",objects[i].class_id);
	    return;
	 }

	 FreeMemory(MALLOC_ID_OBJECT_PROPERTIES,objects[i].p,
		    sizeof(prop_type)*(1+c->num_properties));
      }
   }
   old_objects = max_objects;
   num_objects = 0;  
   max_objects = INIT_OBJECTS;
   objects = (object_node *)
      ResizeMemory(MALLOC_ID_OBJECT,objects,old_objects*sizeof(object_node),
		   max_objects*sizeof(object_node));
}
Example #4
0
void copy_args(int *argc, char **aargv, char ***argv_sv){
#ifdef WIN32
  char *filename=NULL;
  char **argv=NULL;
  int filelength=1024,openfile;
  int i;

  if(NewMemory((void **)&argv,(*argc+1)*sizeof(char **))!=0){
    *argv_sv=argv;
    for(i=0;i<*argc;i++){
      argv[i]=aargv[i];
    }
    if(*argc==1){
      if(NewMemory((void **)&filename,(unsigned int)(filelength+1))!=0){
        openfile=0;
        OpenSMVFile(filename,filelength,&openfile);
        if(openfile==1&&ResizeMemory((void **)&filename,strlen(filename)+1)!=0){
          *argc=2;
          argv[1]=filename;
        }
        else{
          FREEMEMORY(filename);
        }
      }
    }
  }
  else{
    *argc=0;
  }
#else
  *argv_sv=aargv;
#endif
}
Example #5
0
// Reallocates the timer heap memory if there is not enough space to create
// the next timer. Allocates timer_node memory at each new timer_heap element.
void ReallocTimerNodes(void)
{
   int old_timer_nodes = num_timer_nodes;

   num_timer_nodes = num_timer_nodes * 2;
   timer_heap = (timer_node **)ResizeMemory(MALLOC_ID_TIMER, timer_heap,
      old_timer_nodes * sizeof(timer_node *), num_timer_nodes * sizeof(timer_node *));
   lprintf("ReallocTimerNodes resized to %i timer nodes\n", num_timer_nodes);
   for (int i = old_timer_nodes; i < num_timer_nodes; ++i)
      timer_heap[i] = (timer_node *)AllocateMemory(MALLOC_ID_TIMER, sizeof(timer_node));
}
Example #6
0
/* ClearObject
 *
 * This is to clear away objects loaded in when there is an error loading
 * the game.
 */
void ClearObject()
{
   int old_objects;

   old_objects = max_objects;
   num_objects = 0;
   max_objects = INIT_OBJECTS;
   objects = (object_node *)
      ResizeMemory(MALLOC_ID_OBJECT,objects,old_objects*sizeof(object_node),
		   max_objects*sizeof(object_node));
}
Example #7
0
void ResetString()
{
   int i,old_strings;

   for (i=0;i<num_strings;i++)
      FreeMemory(MALLOC_ID_STRING,strings[i].data,strings[i].len_data);

   old_strings = max_strings;
   num_strings = 0;  
   max_strings = INIT_STRING_NODES;
   strings = (string_node *)
      ResizeMemory(MALLOC_ID_STRING,strings,old_strings*sizeof(string_node),
		   max_strings*sizeof(string_node));
}
Example #8
0
int AllocateObject(int class_id)
{
   int old_objects;
   class_node *c;

   c = GetClassByID(class_id);
   if (c == NULL)
   {
      eprintf("AllocateObject can't find class id %i\n",class_id);
      return INVALID_OBJECT;
   }

   if (num_objects == max_objects)
   {
      old_objects = max_objects;
      max_objects = max_objects * 2;
      objects = (object_node *)
	 ResizeMemory(MALLOC_ID_OBJECT,objects,old_objects*sizeof(object_node),
		      max_objects*sizeof(object_node));
      lprintf("AllocateObject resized to %i objects\n",max_objects);
   }

   objects[num_objects].object_id = num_objects;
   objects[num_objects].class_id = class_id;
   objects[num_objects].deleted = False;
   objects[num_objects].num_props = 1 + c->num_properties;
   objects[num_objects].p = (prop_type *)AllocateMemory(MALLOC_ID_OBJECT_PROPERTIES,
							sizeof(prop_type)*(1+c->num_properties));

   if (ConfigBool(DEBUG_INITPROPERTIES))
   {
      int i;
      prop_type p;

      p.id = 0;
      p.val.v.tag = TAG_INVALID;
      p.val.v.data = 0;

      for (i = 0; i < (1+c->num_properties); i++)
      {
	 objects[num_objects].p[i] = p;
      }
   }

   return num_objects++;
}
Example #9
0
int AllocateString()
{
   int old_strings;

   if (num_strings == max_strings)
   {
      old_strings = max_strings;
      max_strings = max_strings * 2;
      strings = (string_node *)
	 ResizeMemory(MALLOC_ID_STRING,strings,old_strings*sizeof(string_node),
		      max_strings*sizeof(string_node));      
      lprintf("AllocateStringNode resized to %i string nodes\n",max_strings);
   }

   strings[num_strings].data = NULL;
   strings[num_strings].len_data = 0;
   
   return num_strings++;
}
Example #10
0
/*
   append a string to a null-terminated string list
*/
void AppendItemToList( char ***list, char *item)
{
   BCINT i = 0;

   if (*list)
   {
      /* count the number of elements in the list (last = null) */
      while ((*list)[ i])
	 i++;
      /* expand the list */
      *list = (char **) ResizeMemory( *list, (i + 2) * sizeof( char **));
   }
   else
      /* create a new list */
      *list = (char **) GetMemory( 2 * sizeof( char **));

   /* append the new element */
   (*list)[ i] = item;
   (*list)[ i + 1] = NULL;
}
Example #11
0
/*
   the main program menu loop
*/
void MainLoop()
{
   WadPtr wad;
   FILE *file;
   char input[ 120];
   char *com, *out;
   BCINT episode, mission;

   for (;;)
   {
      /* get the input */
      printf( "\n[? for help]> ");
      gets( input);
		if(feof(stdin)) strcpy(input, "QUIT");
      printf( "\n");

      /* eat the white space and get the first command word */
      com = strtok( input, " ");
      strupr( com);

      /* user just hit return */
      if (com == NULL)
	 printf( "[Please enter a command or ? for help.]\n");

      /* user inputting for help */
      else if (!strcmp( com, "?") || !strcmp( com, "HELP") || !strcmp( com, "H"))
      {
	 printf( "? or H[elp]                       -- to display this text\n");
	 printf( "A[nalyze] episode mission         -- to analyze a game level's statistics\n");
	 printf( "D[ump] <DirEntry> [outfile]       -- to dump a directory entry in hex\n");
	 printf( "F[lags] { <+-><24ABDEFGLMNPSTUZ>} -- to display/set the print flags\n");
	 printf( "L[ist] <WadFile> [outfile]        -- to list the directory of a WAD file\n");
	 printf( "M[aster] [outfile]                -- to list the master directory\n");
	 printf( "N[ame] [name or '']               -- to display/set the user level name\n");
	 printf( "P[rint] episode mission <PSfile>  -- to print a game level to a PostScript file\n");
	 printf( "Q[uit]                            -- to quit\n");
	 printf( "R[ead] <WadFile>                  -- to read a new WAD patch file\n");
	 printf( "W[ads]                            -- to display the open WAD files\n");
	 printf( "X[tract] <DirEntry> <RawFile>     -- to save (extract) one object to a raw file\n");
      }

      /* user asked for list of open WAD files */
      else if (!strcmp( com, "WADS") || !strcmp( com, "W"))
      {
	 printf( "%-20s  IWAD  (Main ", WadFileList->filename);
	 switch (GameVersion % 16)
	 {
	    case 0: printf( "Shareware"); break;
	    case 1: printf( "Registered"); break;
	    case 2: printf( "Commercial"); break;
	    case 4: printf( "Ultimate"); break;
	 }
	 printf( " WAD file)\n");

	 for (wad = WadFileList->next; wad; wad = wad->next)
	 {
	    if (GameVersion == 2 && wad->directory[ 0].name[ 0] == 'M' &&
		 		    wad->directory[ 0].name[ 1] == 'A' &&
				    wad->directory[ 0].name[ 2] == 'P')
	       printf( "%-20s  PWAD  (Patch WAD file for level %c%c)\n",
			wad->filename, wad->directory[ 0].name[ 3], wad->directory[ 0].name[ 4]);
	    else if (GameVersion != 2 && wad->directory[ 0].name[ 0] == 'E' &&
					 wad->directory[ 0].name[ 2] == 'M')
	       printf( "%-20s  PWAD  (Patch WAD file for episode %c mission %c)\n",
			wad->filename, wad->directory[ 0].name[ 1], wad->directory[ 0].name[ 3]);
	    else
	    {
	       /* kludge */
	       strncpy( input, wad->directory[ 0].name, 8);
	       input[ 8] = '\0';
	       printf( "%-20s  PWAD  (Patch WAD file for %s)\n", wad->filename, input);
	    }
	 }
      }

      /* user asked to quit */
      else if (!strcmp( com, "QUIT") || !strcmp( com, "Q"))
      {
	 if (GameVersion == 0)
	    printf("Remember to register your copy of DOOM!\n");
	 else if (GameVersion == 16)
	    printf("Remember to register your copy of Heretic!\n");
	 printf( "Goodbye...\n");
	 break;
      }

      /* user asked to display/set the print flags */
      else if (!strcmp( com, "FLAGS") || !strcmp( com, "F"))
      {
	 com = strtok( NULL, " ");
	 if (com == NULL)
	    DisplayFlags();
	 else
	    while (com != NULL)
	    {
	       strupr( com);
	       if (com[ 0] != '+' && com[ 0] != '-')
		  printf( "[Flag must start with '+' or '-'.]\n");
	       else if (!strchr( "24ABDEFGLMNPSTUZ", com[ 1]))
		  printf( "[Flag must be one of '24ABDEFGLMNPSTUZ'.]\n");
	       else if (com[ 2] != ' ' && com[ 2] != '\0')
		  printf( "[Flag must be one character.]\n");
	       else
		  SetFlag( com[ 1], com[ 0]);
	       com = strtok( NULL, " ");
	    }
      }

      /* user asked to display/set the user level name */
      else if (!strcmp( com, "NAME") || !strcmp( com, "N"))
      {
	 com = strtok( NULL, " ");
	 if (com == NULL)
	    if (UserLvlNm != NULL)
	       printf( "User level name : %s\n", UserLvlNm);
	    else
	       printf( "[User level name is not set.]\n");
	 else
	    if (! strcmp( com, "''"))
	    {
	       /* reset user level name */
	       FreeMemory( UserLvlNm);
	       UserLvlNm = NULL;
	       printf( "User level name reset\n");
	    }
	    else
	    {
	       /* set user level name */
	       UserLvlNm = (char *) GetMemory( (strlen( com) + 1) * sizeof( char));
	       strcpy( UserLvlNm, com);
	       while ((com = strtok( NULL, " ")) != NULL)
	       {
		  UserLvlNm = (char *) ResizeMemory( UserLvlNm, (strlen( UserLvlNm) + 1 +
								 strlen( com)) * sizeof( char));
		  strcat( UserLvlNm, " ");
		  strcat( UserLvlNm, com);
	       }
	       printf( "User level name set : %s\n", UserLvlNm);
	    }
      }

      /* user asked to print a level */
      else if (!strcmp( com, "PRINT") || !strcmp( com, "P"))
      {
	 com = strtok( NULL, " ");
	 if (com == NULL)
	 {
	    printf( "[Episode number argument missing.]\n");
	    continue;
	 }
	 episode = atoi( com);
	 com = strtok( NULL, " ");
	 if (com == NULL)
	 {
	    printf( "[Mission number argument missing.]\n");
	    continue;
	 }
	 mission = atoi( com);

	 if (GameVersion == 2)
	 {
	    if (episode != 0)
	    {
	       printf( "[Invalid game episode number (%d).]\n", episode);
	       continue;
	    }
	    if (mission < 1 || mission > 32)
	    {
	       printf( "[Invalid game mission number (%d).]\n", mission);
	       continue;
	    }
	 }
	 else /* GameVersion != 2 */
	    if (!(GameVersion == 17 && episode == 4 && mission == 1)) /* Heretic E4M1 */
	    {
	       if (episode < 1 || episode > (GameVersion == 4 ? 4 : (GameVersion & 1 ? 3 : 1)))
	       {
		  printf( "[Invalid game episode number (%d).]\n", episode);
		  continue;
	       }
	       if (mission < 1 || mission > 9)
	       {
		  printf( "[Invalid game mission number (%d).]\n", mission);
		  continue;
	       }
	    }

	 out = strtok( NULL, " ");
	 if (! out)
	 {
	    printf( "[PostScript file name argument missing.]\n");
	    continue;
	 }
	 if (GameVersion == 2)
	    printf( "Outputting PostScript map of level MAP%02d to \"%s\".\n",
		     mission, out);
	 else
	    printf( "Outputting PostScript map of level E%dM%d to \"%s\".\n",
		     episode, mission, out);
	 if ((PSFile = fopen( out, "wt")) == NULL)
	    ProgError( "error opening output file \"%s\"", out);
	 fprintf( PSFile, "%%! DMPSMU: DooM PostScript Maps Utility, ver %s\n",
			   DMPS_VERSION);
	 PrintLevel( episode, mission);
	 fprintf( PSFile, "\n%%%% End of file.\n");
	 fclose( PSFile);
      }

      /* user asked to analyze a level */
      else if (!strcmp( com, "ANALYZE") || !strcmp( com, "A"))
      {
	 com = strtok( NULL, " ");
	 if (com == NULL)
	 {
	    printf( "[Episode number argument missing.]\n");
	    continue;
	 }
	 episode = atoi( com);
	 com = strtok( NULL, " ");
	 if (com == NULL)
	 {
	    printf( "[Mission number argument missing.]\n");
	    continue;
	 }
	 mission = atoi( com);

	 if (GameVersion == 2)
	 {
	    if (episode != 0)
	    {
	       printf( "[Invalid game episode number (%d).]\n", episode);
	       continue;
	    }
	    if (mission < 1 || mission > 32)
	    {
	       printf( "[Invalid game mission number (%d).]\n", mission);
	       continue;
	    }
	 }
	 else /* GameVersion != 2 */
	    if (!(GameVersion == 17 && episode == 4 && mission == 1)) /* Heretic E4M1 */
	    {
	       if (episode < 1 || episode > (GameVersion == 4 ? 4 : (GameVersion & 1 ? 3 : 1)))
	       {
		  printf( "[Invalid game episode number (%d).]\n", episode);
		  continue;
	       }
	       if (mission < 1 || mission > 9)
	       {
		  printf( "[Invalid game mission number (%d).]\n", mission);
		  continue;
	       }
	    }

	 AnalyzeLevel( episode, mission);
      }

      /* user ask for a listing of a WAD file */
      else if (!strcmp( com, "LIST") || !strcmp( com, "L"))
      {
	 com = strtok( NULL, " ");
	 if (com == NULL)
	 {
	    printf( "[Wad file name argument missing.]\n");
	    continue;
	 }
	 for (wad = WadFileList; wad; wad = wad->next)
	    if (!strcmp( com, wad->filename))
	       break;
	 if (! wad)
	 {
	    printf( "[Wad file \"%s\" is not open.]\n", com);
	    continue;
	 }
	 out = strtok( NULL, " ");
	 if (out)
	 {
	    printf( "Outputting directory of \"%s\" to \"%s\".\n", wad->filename, out);
	    if ((file = fopen( out, "wt")) == NULL)
	       ProgError( "error opening output file \"%s\"", out);
	    Credits( file);
	    ListFileDirectory( file, wad);
	    fprintf( file, "\nEnd of file.\n");
	    fclose( file);
	 }
	 else
	    ListFileDirectory( stdout, wad);
      }

      /* user asked for the list of the master directory */
      else if (!strcmp( com, "MASTER") || !strcmp( com, "M"))
      {
	 out = strtok( NULL, " ");
	 if (out)
	 {
	    printf( "Outputting master directory to \"%s\".\n", out);
	    if ((file = fopen( out, "wt")) == NULL)
	       ProgError( "error opening output file \"%s\"", out);
	    Credits( file);
	    ListMasterDirectory( file);
	    fprintf( file, "\nEnd of file.\n");
	    fclose( file);
	 }
	 else
	    ListMasterDirectory( stdout);
      }

      /* user asked to read a new patch WAD file */
      else if (!strcmp( com, "READ") || !strcmp( com, "R"))
      {
	 com = strtok( NULL, " ");
	 if (com == NULL)
	 {
	    printf( "[Wad file name argument missing.]\n");
	    continue;
	 }
	 out = strtok( NULL, " ");
	 if (out)
	    *out = '\0';
	 out = (char *) GetMemory( (strlen( com) + 1) * sizeof( char));
	 strcpy( out, com);
	 OpenPatchWad( out);
	 CloseUnusedWadFiles();
      }

      /* user asked to dump the contents of a WAD file entry */
      else if (!strcmp( com, "DUMP") || !strcmp( com, "D"))
      {
	 com = strtok( NULL, " ");
	 if (com == NULL)
	 {
	    printf( "[Object name argument missing.]\n");
	    continue;
	 }
	 strupr( com);
	 out = strtok( NULL, " ");
	 if (out)
	 {
	    printf( "Outputting directory entry data to \"%s\".\n", out);
	    if ((file = fopen( out, "wt")) == NULL)
	       ProgError( "error opening output file \"%s\"", out);
	    Credits( file);
	    DumpDirectoryEntry( file, com);
	    fprintf( file, "\nEnd of file.\n");
	    fclose( file);
	 }
	 else
	    DumpDirectoryEntry( stdout, com);
      }

      /* user asked to extract an object to a raw binary file */
      else if (!strcmp( com, "XTRACT") || !strcmp( com, "X") || !strcmp( com, "EXTRACT"))
      {
	 com = strtok( NULL, " ");
	 if (com == NULL)
	 {
	    printf( "[Object name argument missing.]\n");
	    continue;
	 }
	 if (strlen( com) > 8 || strchr( com, '.'))
	 {
	    printf( "[Invalid object name.]\n");
	    continue;
	 }
	 strupr( com);
	 out = strtok( NULL, " ");
	 if (! out)
	 {
	    printf( "[Raw file name argument missing.]\n");
	    continue;
	 }
	 for (wad = WadFileList; wad; wad = wad->next)
	    if (!strcmp( out, wad->filename))
	       break;
	 if (wad)
	 {
	    printf( "[You may not overwrite an opened Wad file with raw data.]\n");
	    continue;
	 }
	 printf( "Saving directory entry data to \"%s\".\n", out);
	 if ((file = fopen( out, "wb")) == NULL)
	    ProgError( "error opening output file \"%s\"", out);
	 SaveEntryToRawFile( file, com);
	 fclose( file);
      }

      /* unknown command */
      else
	 printf( "[Unknown command \"%s\"!]\n", com);
   }
}
Example #12
0
void getlinecontours(const  float *xgrid, const float *ygrid, int nx, int ny,  
                 const float *vals, const char *iblank, const float line_min, const float line_max,
                 const contour *ci){
  int n,i,j;
  double x[4],y[4],v[4];
  double linelevel;
  float *xline=NULL, *yline=NULL;
  float *xlinecopy, *ylinecopy;
  int mxpolys,mxlines;
  int nnode2,doit;
  int ij0,ij2,i2j,i2j2;
  int nlinepts;
  int nlevels;
  int blankit=0;
  float dval;

  

  nlevels=ci->nlevels;
  dval=0.0;
  if(nlevels>1&&line_min!=line_max){
    dval=(line_max-line_min)/(float)(nlevels-1);
  }
  for(n=0;n<nlevels;n++){
    linelevel=(double)line_min+n*dval;
    ci->levels[n]=linelevel;

    mxpolys=(nx+1)*(ny+1)+1;
    mxlines=4*mxpolys;
    NewMemory((void **)&xline,mxlines*sizeof(float));
    xlinecopy=xline;
    NewMemory((void **)&yline,mxlines*sizeof(float));
    ylinecopy=yline;

    nlinepts=0;
    for(j=0;j<ny-1;j++){
      y[0]=(double)ygrid[j];
      y[1]=(double)ygrid[j+1];
      y[2]=(double)ygrid[j+1];
      y[3]=(double)ygrid[j];
      for(i=0;i<nx-1;i++){
        x[0]=(double)xgrid[i];
        x[1]=(double)xgrid[i];
        x[2]=(double)xgrid[i+1];
        x[3]=(double)xgrid[i+1];
        doit=1;
        ij0=ijnodeF(i,j);
        ij2=ijnodeF(i,j+1);
        i2j2=ijnodeF(i+1,j+1);
        i2j=ijnodeF(i+1,j);
        if(iblank!=NULL&&iblank[ijcellF(i,j)]!=GASGAS)doit=0;
        if(doit==1){
          v[0]=(double)vals[ij0];
          v[1]=(double)vals[ij2];
          v[2]=(double)vals[i2j2];
          v[3]=(double)vals[i2j];
          getlinecontournodes(linelevel,x,y,v,
            &nnode2,xlinecopy,ylinecopy,
            blankit);
          if(nnode2!=0){
            xlinecopy += nnode2;
            ylinecopy += nnode2;
            nlinepts += nnode2;
          }
        }
      }
    }
    if(nlinepts>0){
      ResizeMemory((void **)&xline,nlinepts*sizeof(float));
      ResizeMemory((void **)&yline,nlinepts*sizeof(float));
    }
    ci->xlines[n]=xline;
    ci->ylines[n]=yline;
    ci->nlines[n]=nlinepts;
  }
}
Example #13
0
void getcontours(const  float *xgrid, const float *ygrid, int nx, int ny,  
                 const float *vals, const char *iblank, const float *levels,int cellflag,int dataflag,
                 const contour *ci){
  int n,i,j;
  double x[4],y[4],v[4];
  double contlow, conthigh;
  float *xnode=NULL, *ynode=NULL;
  float *xnodecopy, *ynodecopy;
  float *xline=NULL, *yline=NULL;
  float *xlinecopy, *ylinecopy;
  int *polysize;
  int nnodes, npolys;
  int mxnodes, mxpolys,mxlines;
  int nnode,nnode2,casen;
  int ij0,ij2,i2j,i2j2;
  int lastcasenum;
  int nlinepts;
  int nlevels;
  int blankit=0;
  int minfill, maxfill;

// Fortran arrays

#define ijnodeF(i,j) ((i)*ny+(j))
#define ijcellF(i,j) ((i)*(ny-1)+(j))

// C arrays

#define ijnodeC(i,j) ((j)*nx+(i))
#define ijcellC(i,j) ((j)*(nx-1)+(i))

  nlevels=ci->nlevels;
  for(n=0;n<nlevels-2;n++){
    ci->levels[n]=levels[n];
  }

  for(n=0;n<nlevels;n++){
    minfill=0;
    maxfill=0;
    if(n==nlevels-2){
      contlow=(double)levels[0]-(levels[1]-levels[0]);
      conthigh=(double)levels[0];
      minfill=1;
    }
    else if(n==nlevels-1){
      contlow=levels[nlevels-2];
      conthigh=levels[nlevels-2]+(levels[nlevels-3]-levels[nlevels-4]);
      maxfill=1;
    }
    else{
      contlow=(double)levels[n];
      conthigh=(double)levels[n+1];
    }

    mxpolys=(nx+1)*(ny+1)+1;
    mxnodes=8*mxpolys;
    mxlines=4*mxpolys;
    NewMemory((void **)&xnode,mxnodes*sizeof(float));
    xnodecopy=xnode;
    NewMemory((void **)&xline,mxlines*sizeof(float));
    xlinecopy=xline;
    NewMemory((void **)&ynode,mxnodes*sizeof(float));
    ynodecopy=ynode;
    NewMemory((void **)&yline,mxlines*sizeof(float));
    ylinecopy=yline;

    NewMemory((void **)&polysize,mxpolys*sizeof(int));

    npolys = 0;
    nnodes=0;
    nlinepts=0;
    for(j=0;j<ny-1;j++){
      y[0]=(double)ygrid[j];
      y[1]=(double)ygrid[j+1];
      y[2]=(double)ygrid[j+1];
      y[3]=(double)ygrid[j];
      lastcasenum=-1;
      for(i=0;i<nx-1;i++){
        x[0]=(double)xgrid[i];
        x[1]=(double)xgrid[i];
        x[2]=(double)xgrid[i+1];
        x[3]=(double)xgrid[i+1];
        if(dataflag==DATA_FORTRAN){
          ij0=ijnodeF(i,j);
          ij2=ijnodeF(i,j+1);
          i2j2=ijnodeF(i+1,j+1);
          i2j=ijnodeF(i+1,j);
        }
        else{
          ij0=ijnodeC(i,j);
          ij2=ijnodeC(i,j+1);
          i2j2=ijnodeC(i+1,j+1);
          i2j=ijnodeC(i+1,j);
        }
        if(iblank!=NULL){
          int cellij;

          if(dataflag==DATA_FORTRAN){
            cellij = ijcellF(i,j);
          }
          else{
            cellij = ijcellC(i,j);
          }
          if(iblank[cellij]!=GASGAS){
            lastcasenum=-1;
            continue;
          }
          if(dataflag==DATA_FORTRAN){
            if(iblank[ijcellF(i,j+1)]!=GASGAS)ij2=ij0;
            if(iblank[ijcellF(i+1,j+1)]!=GASGAS)i2j2=ij0;
            if(iblank[ijcellF(i+1,j)]!=GASGAS)i2j=ij0;
          }
          else{
            if(iblank[ijcellC(i,j+1)]!=GASGAS)ij2=ij0;
            if(iblank[ijcellC(i+1,j+1)]!=GASGAS)i2j2=ij0;
            if(iblank[ijcellC(i+1,j)]!=GASGAS)i2j=ij0;
          }
        }
        v[0]=(double)vals[ij0];
        v[1]=(double)vals[ij2];
        v[2]=(double)vals[i2j2];
        v[3]=(double)vals[i2j];
        getcontournodes(n,nlevels,x,y,v,contlow,minfill,conthigh,maxfill,
          &nnode, xnodecopy, ynodecopy,
          &nnode2,xlinecopy,ylinecopy,
          &casen,blankit);
        if(nnode!=0){
          if(casen!=40||lastcasenum!=40){
            nnodes += nnode;
            xnodecopy += nnode;
            ynodecopy += nnode;
            polysize[npolys]=nnode;
            npolys++;
          }
          else{
            xnodecopy[-2]=xnodecopy[2];
            xnodecopy[-1]=xnodecopy[3];
            ynodecopy[-2]=ynodecopy[2];
            ynodecopy[-1]=ynodecopy[3];
          }
          lastcasenum=casen;
        }
        if(nnode2!=0){
          xlinecopy += nnode2;
          ylinecopy += nnode2;
          nlinepts += nnode2;
        }
      }
    }
    if(nnodes>0){
      ResizeMemory((void **)&xnode,nnodes*sizeof(float));
      ResizeMemory((void **)&ynode,nnodes*sizeof(float));
    }
    else{
      FREEMEMORY(xnode);
      FREEMEMORY(ynode);
    }
    if(nlinepts>0){
      ResizeMemory((void **)&xline,nlinepts*sizeof(float));
      ResizeMemory((void **)&yline,nlinepts*sizeof(float));
    }
    else{
      FREEMEMORY(xline);
      FREEMEMORY(yline);
    }
    if(npolys>0){
      ResizeMemory((void **)&polysize,npolys*sizeof(int));
    }
    else{
      FREEMEMORY(polysize);
    }
    ci->nnodes[n]=nnodes;
    ci->npolys[n]=npolys;
    ci->xnode[n]=xnode;
    ci->ynode[n]=ynode;
    ci->xlines[n]=xline;
    ci->ylines[n]=yline;
    ci->nlines[n]=nlinepts;
    ci->polysize[n]=polysize;
  }
  /* PRINTF("polygon count=%i\n",npolystotal); */
  if(cellflag==GET_NODE_AREAS)GetContourAreas(ci);

}
Example #14
0
static inline void 
DivideSegs(struct Seg *ts, struct Seg **rs, struct Seg **ls, const bbox_t bbox)
{
	struct Seg *rights,*lefts;
	struct Seg *tmps,*best,*news,*prev;
	struct Seg *add_to_rs,*add_to_ls;
  	struct Seg *new_best=NULL,*new_rs,*new_ls;

	struct Seg *strights,*stlefts;
        int num_new=0;
	short int x,y,val;

	best = PickNode(ts,bbox);			/* Pick best node to use.*/

	if(best == NULL) ProgError("Couldn't pick nodeline!");

	node_x = vertices[best->start].x;
	node_y = vertices[best->start].y;
	node_dx = vertices[best->end].x-vertices[best->start].x;
	node_dy = vertices[best->end].y-vertices[best->start].y;

/* When we get to here, best is a pointer to the partition seg.
	Using this partition line, we must split any lines that are intersected
	into a left and right half, flagging them to be put their respective sides
	Ok, now we have the best line to use as a partitioning line, we must
   split all of the segs into two lists (rightside & leftside).				 */

	rights = NULL;									/* Start off with empty*/
	lefts = NULL;									/* lists.*/
	strights = NULL;								/* Start off with empty*/
	stlefts = NULL;								/* lists.*/

	psx = vertices[best->start].x;			/* Partition line coords*/
	psy = vertices[best->start].y;
	pex = vertices[best->end].x;
	pey = vertices[best->end].y;
	pdx = psx - pex;								/* Partition line DX,DY*/
	pdy = psy - pey;

	for(tmps=ts;tmps;tmps=tmps->next)
		{
		progress();									/* Something for the user to look at.*/
		add_to_rs = NULL;
		add_to_ls = NULL;
		if(tmps != best)
			{
			lsx = vertices[tmps->start].x;	/* Calculate this here, cos it doesn't*/
			lsy = vertices[tmps->start].y;	/* change for all the interations of*/
			lex = vertices[tmps->end].x;		/* the inner loop!*/
			ley = vertices[tmps->end].y;
			val = DoLinesIntersect();
			if((val&2 && val&64) || (val&4 && val&32))	/* If intersecting !!*/
				{
				ComputeIntersection(&x,&y);
/*				printf("Splitting Linedef %d at %d,%d\n",tmps->linedef,x,y);*/
 			        vertices = ResizeMemory(vertices, sizeof(struct Vertex) * (num_verts+1));
				vertices[num_verts].x = x;
				vertices[num_verts].y = y;

				news = GetMemory(sizeof( struct Seg));
				*news = *tmps;
				tmps->next = news;
				news->start = num_verts;
				tmps->end = num_verts;
				news->dist = SplitDist(news);
/*				printf("splitting dist = %d\n",news->dist);*/
/*				printf("splitting vertices = %d,%d,%d,%d\n",tmps->start,tmps->end,news->start,news->end);*/
				if(val&32) add_to_ls = tmps;
				if(val&64) add_to_rs = tmps;
				if(val&2) add_to_ls = news;
				if(val&4) add_to_rs = news;
				tmps = news;
				num_verts++;
				num_new++;
				}
			else
				{											/* Not split, which side ?*/
				if(val&34) add_to_ls = tmps;
				if(val&68) add_to_rs = tmps;
				if(val&1 && val&16)					/* On same line*/
					{
/* 06/01/97 Lee Killough: this fixes a bug ever since 1.2x,
   probably 1.0, of BSP: when partitioning a parallel seg,
   you must take its vertices' orientation into account, NOT the
   flip bits, to determine which side of the partitioning line a
   parallel seg should go on. If you simply flip the linedef in
   question, you will be flipping both its vertices and sidedefs,
   and the flip bits as well, even though the basic geometry has
   not changed. Thus you need to use the vertices' orientation
   (whether the seg is in the same direction or not, regardless
   of its original linedef's being flipped or not), into account.

   Originally, some segs were partitioned backwards, and if
   it happened that there were different sectors on either
   side of the seg being partitioned, it could leave holes
   in space, causing either invisible barriers or disappearing
   Things, because the ssector would be associated with the
   wrong sector.

   The old logic of tmps->flip != best->flip seems to rest on
   the assumption that if two segs are parallel, they came
   from the same linedef. This is clearly not always true.   */

              /*  if (tmps->flip != best->flip)   old logic -- wrong!!! */

              /* We know the segs are parallel or nearly so, so take their
                 dot product to determine their relative orientation. */

		if ( (lsx-lex)*pdx + (lsy-ley)*pdy < 0)
  	         add_to_ls = tmps;
	 	else
		 add_to_rs = tmps;
					}
				}
			}
		else add_to_rs = tmps;						/* This is the partition line*/

/*		printf("Val = %X\n",val);*/

		if(add_to_rs)							/* CHECK IF SHOULD ADD RIGHT ONE */
			{
			new_rs = GetMemory(sizeof(struct Seg));
			*new_rs = *add_to_rs;
			if(add_to_rs == best) new_best = new_rs;
			new_rs->next = NULL;
			if(!rights) strights = rights = new_rs;
			else
				{
				rights->next = new_rs;
				rights = new_rs;
				}
			}
				
		if(add_to_ls)							/* CHECK IF SHOULD ADD LEFT ONE */
			{
			new_ls = GetMemory(sizeof(struct Seg));
			*new_ls = *add_to_ls;
			if(add_to_ls == best) new_best = new_ls;
			new_ls->next = NULL;
			if(!lefts) stlefts = lefts = new_ls;
			else
				{
				lefts->next = new_ls;
				lefts = new_ls;
				}
			}
		}

	if(strights == NULL)
		{
/*		printf("No right side, moving partition into right side\n");*/
		strights = rights = new_best;
		prev = NULL;
		for(tmps=stlefts;tmps;tmps=tmps->next)
			{
			if(tmps == new_best)
				{
				if(prev != NULL) prev->next=tmps->next;
				else stlefts=tmps->next;
				}
			prev=tmps;
			}
		prev->next = NULL;
		}
	
	if(stlefts == NULL)
		{
/*		printf("No left side, moving partition into left side\n");*/
		stlefts = lefts = new_best;
		prev = NULL;
		for(tmps=strights;tmps;tmps=tmps->next)
			{
			if(tmps == new_best)
				{
				if(prev != NULL) prev->next=tmps->next;
				else strights=tmps->next;
				}
			prev=tmps;
			}
		stlefts->next = NULL;
		prev->next = NULL;								/* Make sure end of list = NULL*/
		}

	if(rights->next != NULL) rights->next = NULL;
	if(lefts->next != NULL) lefts->next = NULL;

	for(tmps=ts;tmps;tmps=best)
		{
		best=tmps->next;
		free(tmps);
		}

/*	printf("Made %d new Vertices and Segs\n",num_new);*/

	*rs = strights ; *ls = stlefts;
}
Example #15
0
void Update_Times(void){
  int ntimes2;
  float *timescopy;
  int i;
  float dt_MIN=100000.0;

  FREEMEMORY(geominfoptrs);
  ngeominfoptrs=0;
  GetGeomInfoPtrs(&geominfoptrs,&ngeominfoptrs);

  // pass 1 - determine ntimes

  Update_Show();  
  CheckMemory;
  nglobal_times = 0;

  for(i=0;i<ngeominfoptrs;i++){
    geomdata *geomi;

    geomi = geominfoptrs[i];
    if(geomi->loaded==0||geomi->display==0)continue;
    nglobal_times+=geomi->ntimes;
  }
  if(visTerrainType!=TERRAIN_HIDDEN){
    for(i=0;i<nterraininfo;i++){
      terraindata *terri;

      terri = terraininfo + i;
      if(terri->loaded==1)nglobal_times+=terri->ntimes;
    }
  }
  if(visShooter!=0&&shooter_active==1){
    nglobal_times+=nshooter_frames;
  }
  for(i=0;i<ntours;i++){
    tourdata *touri;

    touri = tourinfo + i;
    if(touri->display==0)continue;
    nglobal_times+= touri->ntimes;
  }
  for(i=0;i<npartinfo;i++){
    partdata *parti;

    parti = partinfo + i;
    if(parti->loaded==0)continue;
    nglobal_times+= parti->ntimes;
  }
  for(i=0;i<nsliceinfo;i++){
    slicedata *sd;

    sd=sliceinfo+i;
    if(sd->loaded==1||sd->vloaded==1){
      nglobal_times+=sd->ntimes;
    }
  }
  if(ReadTargFile==1&&visTarg==1){
    nglobal_times+=ntargtimes;
  }
  for(i=0;i<npatchinfo;i++){
    patchdata *patchi;

    patchi = patchinfo + i;
    if(patchi->loaded==1&&patchi->filetype==2){
      nglobal_times+=patchi->ngeom_times;
    }
  }
  for(i=0;i<nmeshes;i++){
    patchdata *patchi;
    mesh *meshi;
    int filenum;

    meshi=meshinfo+i;
    filenum =meshi->patchfilenum;
    if(filenum!=-1){
      patchi=patchinfo+filenum;
      if(patchi->loaded==1&&patchi->filetype!=2){
        nglobal_times+=meshi->npatch_times;
      }
    }
  }
  if(ReadZoneFile==1&&visZone==1){
    nglobal_times+=nzone_times;
  }
  if(ReadIsoFile==1&&visAIso!=0){
    for(i=0;i<nmeshes;i++){
      mesh *meshi;
      isodata *ib;

      meshi=meshinfo+i;
      if(meshi->isofilenum<0)continue;
      ib = isoinfo + meshi->isofilenum;
      if(ib->geomflag==1||ib->loaded==0)continue;
      nglobal_times+=meshi->niso_times;
    }
  }
  if(nvolrenderinfo>0){
    for(i=0;i<nmeshes;i++){
      volrenderdata *vr;
      mesh *meshi;

      meshi=meshinfo+i;
      vr = &meshi->volrenderinfo;
      if(vr->fireslice==NULL||vr->smokeslice==NULL)continue;
      if(vr->loaded==0||vr->display==0)continue;
      nglobal_times+=vr->ntimes;
    }
  }
  {
    smoke3ddata *smoke3di;

    if(Read3DSmoke3DFile==1&&vis3DSmoke3D==1){
      for(i=0;i<nsmoke3dinfo;i++){
        smoke3di = smoke3dinfo + i;
        if(smoke3di->loaded==0)continue;
        nglobal_times+= smoke3di->ntimes;
      }
    }
  }

  // end pass 1

  CheckMemory;
  FREEMEMORY(global_times);
  if(nglobal_times>0)NewMemory((void **)&global_times,nglobal_times*sizeof(float));
  timescopy=global_times;

  // pass 2 - merge times arrays

  for(i=0;i<ngeominfoptrs;i++){
    geomdata *geomi;
    int n;

    geomi = geominfoptrs[i];
    if(geomi->loaded==0||geomi->display==0)continue;
    for(n=0;n<geomi->ntimes;n++){
      float t_diff;

      *timescopy++=geomi->times[n];
      t_diff = timescopy[-1]-timescopy[-2];
      if(n>0&&t_diff<dt_MIN&&t_diff>0.0){
        dt_MIN=t_diff;
      }
    }
  }
  if(visTerrainType!=TERRAIN_HIDDEN){
    for(i=0;i<nterraininfo;i++){
      terraindata *terri;
      int n;

      terri = terraininfo + i;
      if(terri->loaded==0)continue;
      for(n=0;n<terri->ntimes;n++){
        float t_diff;

        *timescopy++=terri->times[n];
        t_diff = timescopy[-1]-timescopy[-2];
        if(n>0&&t_diff<dt_MIN&&t_diff>0.0){
          dt_MIN=t_diff;
        }
      }
    }
  }
  if(visShooter!=0&&shooter_active==1){
    for(i=0;i<nshooter_frames;i++){
      float t_diff;

      *timescopy++=shoottimeinfo[i].time;

      t_diff = timescopy[-1]-timescopy[-2];
      if(i>0&&t_diff<dt_MIN&&t_diff>0.0){
        dt_MIN=t_diff;
      }
    }
    CheckMemory;
  }

  for(i=0;i<ntours;i++){
    tourdata *touri;
    int n;

    touri = tourinfo + i;
    if(touri->display==0)continue;
    for(n=0;n<touri->ntimes;n++){
      float t_diff;

      *timescopy++=touri->path_times[n];
      t_diff = timescopy[-1]-timescopy[-2];
      if(n>0&&t_diff<dt_MIN&&t_diff>0.0){
        dt_MIN=t_diff;
      }
    }
  }

  tmax_part=0.0;
  for(i=0;i<npartinfo;i++){
    partdata *parti;
    int n;

    parti = partinfo + i;
    if(parti->loaded==0)continue;
    for(n=0;n<parti->ntimes;n++){
      float t_diff;

      *timescopy++=parti->times[n];
      t_diff = timescopy[-1]-timescopy[-2];
      if(n>0&&t_diff<dt_MIN&&t_diff>0.0){
        dt_MIN=t_diff;
      }
    }
    tmax_part=MAX(parti->times[parti->ntimes-1],tmax_part);
  }

  for(i=0;i<nsliceinfo;i++){
    slicedata *sd;
    int n;

    sd = sliceinfo + i;
    if(sd->loaded==1||sd->vloaded==1){
      for(n=0;n<sd->ntimes;n++){
        float t_diff;

        *timescopy++=sd->times[n];
        t_diff = timescopy[-1]-timescopy[-2];
        if(n>0&&t_diff<dt_MIN&&t_diff>0.0){
          dt_MIN=t_diff;
        }
      }
    }
  }

  if(ReadTargFile==1&&visTarg==1){
    int n;

    for(n=0;n<ntargtimes;n++){
      float t_diff;

      *timescopy++=targtimes[n];
      t_diff = timescopy[-1]-timescopy[-2];
      if(n>0&&t_diff<dt_MIN&&t_diff>0.0){
        dt_MIN=t_diff;
      }
    }
  }
  for(i=0;i<npatchinfo;i++){
    patchdata *patchi;
    int n;

    patchi = patchinfo + i;
    if(patchi->loaded==1&&patchi->filetype==2){
      for(n=0;n<patchi->ngeom_times;n++){
        float t_diff;

        *timescopy++=patchi->geom_times[n];
        t_diff = timescopy[-1]-timescopy[-2];
        if(n>0&&t_diff<dt_MIN&&t_diff>0.0){
          dt_MIN=t_diff;
        }
      }
    }
  }
  for(i=0;i<nmeshes;i++){
    patchdata *patchi;
    mesh *meshi;
    int filenum;

    meshi=meshinfo + i;
    filenum=meshi->patchfilenum;
    if(filenum!=-1){
      patchi = patchinfo + filenum;
      if(patchi->loaded==1&&patchi->filetype!=2){
        int n;

        for(n=0;n<meshi->npatch_times;n++){
          float t_diff;

          *timescopy++=meshi->patch_times[n];
          t_diff = timescopy[-1]-timescopy[-2];
          if(n>0&&t_diff<dt_MIN&&t_diff>0.0){
            dt_MIN=t_diff;
          }
        }
      }
    }
  }
  if(nvolrenderinfo>0){
    for(i=0;i<nmeshes;i++){
      volrenderdata *vr;
      mesh *meshi;
      int n;

      meshi=meshinfo + i;
      vr = &meshi->volrenderinfo;
      if(vr->smokeslice==NULL)continue;
      if(vr->loaded==0||vr->display==0)continue;
      for(n=0;n<vr->ntimes;n++){
        float t_diff;

        *timescopy++=vr->times[n];
        if(n>0){
          t_diff = timescopy[-1]-timescopy[-2];
          if(t_diff<dt_MIN&&t_diff>0.0){
            dt_MIN=t_diff;
          }
        }
      }
    }
  }
  if(ReadZoneFile==1&&visZone==1){
    int n;

    for(n=0;n<nzone_times;n++){
      float t_diff;

      *timescopy++=zone_times[n];
      t_diff = timescopy[-1]-timescopy[-2];
      if(n>0&&t_diff<dt_MIN&&t_diff>0.0){
        dt_MIN=t_diff;
      }
    }
  }
  if(ReadIsoFile==1&&visAIso!=0){
    for(i=0;i<nisoinfo;i++){
      mesh *meshi;
      isodata *ib;
      int n;

      ib = isoinfo+i;
      if(ib->geomflag==1||ib->loaded==0)continue;
      meshi=meshinfo + ib->blocknumber;
      for(n=0;n<meshi->niso_times;n++){
        float t_diff;

        *timescopy++=meshi->iso_times[n];
        t_diff = timescopy[-1]-timescopy[-2];
        if(n>0&&t_diff<dt_MIN&&t_diff>0.0){
          dt_MIN=t_diff;
        }
      }
    }
  }
  {
    smoke3ddata *smoke3di;

    if(Read3DSmoke3DFile==1&&vis3DSmoke3D==1){
      for(i=0;i<nsmoke3dinfo;i++){
        int n;

        smoke3di = smoke3dinfo + i;
        if(smoke3di->loaded==0)continue;
        for(n=0;n<smoke3di->ntimes;n++){
          float t_diff;

          *timescopy++=smoke3di->times[n];
          t_diff = timescopy[-1]-timescopy[-2];
          if(n>0&&t_diff<dt_MIN&&t_diff>0.0){
            dt_MIN=t_diff;
          }
        }
      }
    }
  }

  // end pass 2

  // sort times array and remove duplicates

  if(nglobal_times>0)qsort( (float *)global_times, (size_t)nglobal_times, sizeof( float ), compare_float );

  {
    int n,n2;

    for(n2=1,ntimes2=nglobal_times,n=1;n<nglobal_times;n++){
      if(ABS(global_times[n]-global_times[n-1])>dt_MIN/10.0){
        global_times[n2]=global_times[n];
        n2++;
      }
      else{
        ntimes2--;
      }
    }
  }
  nglobal_times=ntimes2;

  // pass 3 - allocate memory for individual times array

  if(nglobal_times>ntimes_old){
    ntimes_old=nglobal_times;
    FREEMEMORY(render_frame);
    if(nglobal_times>0)NewMemory((void **)&render_frame,nglobal_times*sizeof(int));
  }

  for(i=0;i<ngeominfoptrs;i++){
    geomdata *geomi;

    geomi = geominfoptrs[i];
    if(geomi->loaded==0||geomi->display==0)continue;
    FREEMEMORY(geomi->timeslist);
    if(nglobal_times>0)NewMemory((void **)&geomi->timeslist,nglobal_times*sizeof(int));
  }
  for(i=0;i<npartinfo;i++){
    partdata *parti;

    parti=partinfo+i;
    FREEMEMORY(parti->timeslist);
    if(nglobal_times>0)NewMemory((void **)&parti->timeslist,nglobal_times*sizeof(int));
  }
  for(i=0;i<ntours;i++){
    tourdata *touri;

    touri=tourinfo + i;
    if(touri->display==0)continue;
    FREEMEMORY(touri->timeslist);
    if(nglobal_times>0)NewMemory((void **)&touri->timeslist,nglobal_times*sizeof(int));
  }
  if(visTerrainType!=TERRAIN_HIDDEN){
    for(i=0;i<nterraininfo;i++){
      terraindata *terri;

      terri = terraininfo + i;
      if(terri->loaded==0)continue;
      FREEMEMORY(terri->timeslist);
      if(nglobal_times>0)NewMemory((void **)&terri->timeslist,nglobal_times*sizeof(int));
    }
  }
  if(hrrinfo!=NULL){
    FREEMEMORY(hrrinfo->timeslist);
    FREEMEMORY(hrrinfo->times);
    FREEMEMORY(hrrinfo->hrrval);
    if(hrrinfo->loaded==1&&hrrinfo->display==1&&nglobal_times>0){
      int jstart=0;

      NewMemory((void **)&hrrinfo->timeslist,nglobal_times*sizeof(int));
      NewMemory((void **)&hrrinfo->times,nglobal_times*sizeof(float));
      NewMemory((void **)&hrrinfo->hrrval,nglobal_times*sizeof(float));
      hrrinfo->ntimes=nglobal_times;
      for(i=0;i<nglobal_times;i++){
        int j, foundit;

        foundit=0;
        hrrinfo->times[i]=global_times[i];
        for(j=jstart;j<hrrinfo->ntimes_csv-1;j++){
          if(hrrinfo->times_csv[j]<=global_times[i]&&global_times[i]<hrrinfo->times_csv[j+1]){
            float f1, tbot;

            foundit=1;
            tbot = hrrinfo->times_csv[j+1]-hrrinfo->times_csv[j];
            if(tbot>0.0){
              f1 = (global_times[i]-hrrinfo->times_csv[j])/tbot;
            }
            else{
              f1=0.0;
            }
            hrrinfo->hrrval[i]=(1.0-f1)*hrrinfo->hrrval_csv[j]+f1*hrrinfo->hrrval_csv[j+1];
            jstart=j;
            break;
          }
        }
        if(foundit==0){
          hrrinfo->hrrval[i]=hrrinfo->hrrval_csv[hrrinfo->ntimes_csv-1];
        }
      }
    }
  }
  FREEMEMORY(shooter_timeslist);
  if(visShooter!=0&&shooter_active==1){
    NewMemory((void **)&shooter_timeslist,nshooter_frames*sizeof(int));
  }

  for(i=0;i<nsliceinfo;i++){
    slicedata *sd;

    sd = sliceinfo + i;
    FREEMEMORY(sd->timeslist);
    if(nglobal_times>0)NewMemory((void **)&sd->timeslist,nglobal_times*sizeof(int));
  }
  if(nvolrenderinfo>0){
    for(i=0;i<nmeshes;i++){
      mesh *meshi;
      volrenderdata *vr;

      meshi = meshinfo + i;
      vr = &(meshi->volrenderinfo);
      if(vr->fireslice==NULL||vr->smokeslice==NULL)continue;
      if(vr->loaded==0||vr->display==0)continue;
      FREEMEMORY(vr->timeslist);
      if(nglobal_times>0)NewMemory((void **)&vr->timeslist,nglobal_times*sizeof(int));
    }
  }
  {
    smoke3ddata *smoke3di;

    for(i=0;i<nsmoke3dinfo;i++){
      smoke3di = smoke3dinfo + i;
      FREEMEMORY(smoke3di->timeslist);
      if(nglobal_times>0)NewMemory((void **)&smoke3di->timeslist,nglobal_times*sizeof(int));
    }
  }
  for(i=0;i<nmeshes;i++){
    mesh *meshi;

    meshi=meshinfo+i;
    if(meshi->iso_times==NULL)continue;
    FREEMEMORY(meshi->iso_timeslist);
    if(nglobal_times>0)NewMemory((void **)&meshi->iso_timeslist,  nglobal_times*sizeof(int));  
  }

  for(i=0;i<npatchinfo;i++){
    patchdata *patchi;

    patchi = patchinfo + i;
    FREEMEMORY(patchi->geom_timeslist);
    if(patchi->filetype!=2)continue;
    if(patchi->geom_times==NULL)continue;
    if(nglobal_times>0)NewMemory((void **)&patchi->geom_timeslist,nglobal_times*sizeof(int));
  }
  for(i=0;i<nmeshes;i++){
    FREEMEMORY(meshinfo[i].patch_timeslist); 
  }
  for(i=0;i<nmeshes;i++){
    if(meshinfo[i].patch_times==NULL)continue;
    if(nglobal_times>0)NewMemory((void **)&meshinfo[i].patch_timeslist,nglobal_times*sizeof(int));
  }

  FREEMEMORY(zone_timeslist); 
  if(nglobal_times>0)NewMemory((void **)&zone_timeslist,     nglobal_times*sizeof(int));

  FREEMEMORY(targtimeslist);
  if(nglobal_times>0)NewMemory((void **)&targtimeslist,  nglobal_times*sizeof(int));

  if(ntotal_smooth_blockages>0){
    for(i=0;i<nmeshes;i++){
      mesh *meshi;

      meshi=meshinfo+i;
      FREEMEMORY(meshi->showsmoothtimelist);
      if(nglobal_times>0)NewMemory((void **)&meshi->showsmoothtimelist,nglobal_times*sizeof(smoothblockage *));
    }
  }

  // end pass 3

  // reset render_frame array

  if(current_script_command!=NULL&&current_script_command->command==SCRIPT_VOLSMOKERENDERALL){
    if(current_script_command->first==1){
      int n;

      for(n=0;n<nglobal_times;n++){
        render_frame[n]=0;
      }
      current_script_command->first=0;
    }
  }
  else{
    int n;

    for(n=0;n<nglobal_times;n++){
      render_frame[n]=0;
    }
  }

  // reallocate times array

  if(nglobal_times==0){
    FREEMEMORY(global_times);
  }
  if(nglobal_times>0)ResizeMemory((void **)&global_times,nglobal_times*sizeof(float));
  
  // pass 4 - initialize individual time pointers

  izone=0; 
  reset_itimes0();
  for(i=0;i<ngeominfoptrs;i++){
    geomdata *geomi;

    geomi = geominfoptrs[i];
    if(geomi->loaded==0||geomi->display==0)continue;
    geomi->itime=0;
  }
  for(i=0;i<nmeshes;i++){
    mesh *meshi;

    meshi=meshinfo+i;
    meshi->patch_itime=0;
  }
  for(i=0;i<nsliceinfo;i++){
    slicedata *sd;

    sd = sliceinfo + i;
    sd->itime=0; 
  }
  frame_index=first_frame_index; 
  for(i=0;i<nmeshes;i++){
    mesh *meshi;

    meshi=meshinfo+i;
    if(meshi->iso_times==NULL)continue;
    meshi->iso_itime=0;
  }
  for(i=0;i<npartinfo;i++){
    partdata *parti;

    parti = partinfo + i;
    parti->itime=0;
  }

  /* determine visibility of each blockage at each time step */

  for(i=0;i<nmeshes;i++){
    int j;
    mesh *meshi;

    meshi=meshinfo+i;
    for(j=0;j<meshi->nbptrs;j++){
      blockagedata *bc;

      bc = meshi->blockageinfoptrs[j];
      if(bc->showtime==NULL)continue;
      FREEMEMORY(bc->showtimelist);
      if(nglobal_times>0){
        int k;

        NewMemory((void **)&bc->showtimelist,nglobal_times*sizeof(int));
        for(k=0;k<nglobal_times;k++){
          int listindex;

          bc->showtimelist[k]=1;
          listindex=getindex(global_times[k],bc->showtime,bc->nshowtime);
          bc->showtimelist[k]=bc->showhide[listindex];
        }
      }
    }
  }

  /* determine state of each device at each time step */

  for(i=0;i<ndeviceinfo;i++){
    devicedata *devicei;

    devicei = deviceinfo + i;
    if(devicei->object->visible==0)continue;
    if(devicei->nstate_changes==0)continue;
    FREEMEMORY(devicei->showstatelist);
    if(nglobal_times>0){
      int k;

      NewMemory((void **)&devicei->showstatelist,nglobal_times*sizeof(int));
      for(k=0;k<nglobal_times;k++){
        int listindex;

        listindex=getindex(global_times[k],devicei->act_times,devicei->nstate_changes);
        devicei->showstatelist[k]=devicei->state_values[listindex];
      }
    }
  }

  /* determine visibility of each vent at each time step */

  for(i=0;i<nmeshes;i++){
    int j;
    mesh *meshi;

    meshi=meshinfo+i;
    if(meshi->ventinfo==NULL)continue;
    for(j=0;j<meshi->nvents;j++){
      ventdata *vi;

      vi = meshi->ventinfo+j;
      if(vi->showtime==NULL)continue;
      FREEMEMORY(vi->showtimelist);
      if(nglobal_times>0){
        int k;

        NewMemory((void **)&vi->showtimelist,nglobal_times*sizeof(int));
        for(k=0;k<nglobal_times;k++){
          int listindex;

          vi->showtimelist[k]=1;
          listindex=getindex(global_times[k],vi->showtime,vi->nshowtime);
          vi->showtimelist[k]=vi->showhide[listindex];
        }
      }
    }
  }

  if(nglobal_times>0)Synch_Times();
  updatefaces=1;
  if(nglobal_times>0){
    UpdateTimeLabels();
    updateGluiTimeBounds(global_times[0],global_times[nglobal_times-1]);
  }
  show_slice_terrain=0;
  if(visTerrainType==TERRAIN_3D_MAP){
    for(i=0;i<nsliceinfo;i++){
      slicedata *sd;

      sd = sliceinfo + i;
      if(sd->loaded==0||sd->display==0||sd->slicetype!=SLICE_TERRAIN)continue;
      show_slice_terrain=1;
      break;
    }
  }
}