Esempio n. 1
0
/**
 * @brief Allocates memory for FSR source arrays.
 * @details Deletes memory for old source arrays if they were allocated for a
 *          previous simulation.
 */
void VectorizedSolver::initializeSourceArrays() {

  /* Delete old sources arrays if they exist */
  if (_reduced_sources != NULL)
    MM_FREE(_reduced_sources);
  if (_fixed_sources != NULL)
    MM_FREE(_fixed_sources);

  int size = _num_FSRs * _num_groups * sizeof(FP_PRECISION);

  /* Allocate aligned memory for all source arrays */
  try{
    _reduced_sources = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);
    _fixed_sources = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);
  }
  catch(std::exception &e) {
    log_printf(ERROR, "Could not allocate memory for FSR sources");
  }

  /* Initialize fixed sources to zero */
  memset(_fixed_sources, 0.0, size);

  /* Populate fixed source array with any user-defined sources */
  initializeFixedSources();
}
Esempio n. 2
0
/**
 * @brief Computes the total source (fission, scattering, fixed) in each FSR.
 * @details This method computes the total source in each FSR based on
 *          this iteration's current approximation to the scalar flux.
 */
void VectorizedSolver::computeFSRSources() {

#pragma omp parallel default(none)
  {
    int tid;
    Material* material;
    FP_PRECISION* sigma_t;
    FP_PRECISION* sigma_s;
    FP_PRECISION* fiss_mat;
    FP_PRECISION scatter_source, fission_source;

    int size = _num_groups * sizeof(FP_PRECISION);
    FP_PRECISION* fission_sources =
      (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);
    FP_PRECISION* scatter_sources =
      (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);

    /* For all FSRs, find the source */
#pragma omp for schedule(guided)
    for (int r=0; r < _num_FSRs; r++) {

      tid = omp_get_thread_num();
      material = _FSR_materials[r];
      sigma_t = material->getSigmaT();
      sigma_s = material->getSigmaS();
      fiss_mat = material->getFissionMatrix();

      /* Compute scatter + fission source for group G */
      for (int G=0; G < _num_groups; G++) {
        for (int v=0; v < _num_vector_lengths; v++) {

#pragma simd vectorlength(VEC_LENGTH)
          for (int g=v*VEC_LENGTH; g < (v+1)*VEC_LENGTH; g++) {
            scatter_sources[g] = sigma_s[G*_num_groups+g] * _scalar_flux(r,g);
            fission_sources[g] = fiss_mat[G*_num_groups+g] * _scalar_flux(r,g);
          }
        }

#ifdef SINGLE
        scatter_source=cblas_sasum(_num_groups, scatter_sources, 1);
        fission_source=cblas_sasum(_num_groups, fission_sources, 1);
#else
        scatter_source=cblas_dasum(_num_groups, scatter_sources, 1);
        fission_source=cblas_dasum(_num_groups, fission_sources, 1);
#endif

        fission_source /= _k_eff;

        /* Compute total (scatter+fission+fixed) reduced source */
        _reduced_sources(r,G) = _fixed_sources(r,G);
        _reduced_sources(r,G) += scatter_source + fission_source;
        _reduced_sources(r,G) *= ONE_OVER_FOUR_PI / sigma_t[G];
      }
    }

    MM_FREE(fission_sources);
    MM_FREE(scatter_sources);
  }
}
Esempio n. 3
0
/**
 * @brief Compute \f$ k_{eff} \f$ from successive fission sources.
 */
void VectorizedSolver::computeKeff() {

  FP_PRECISION fission;

  int size = _num_FSRs * sizeof(FP_PRECISION);
  FP_PRECISION* FSR_rates = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);

  size = _num_threads * _num_groups * sizeof(FP_PRECISION);
  FP_PRECISION* group_rates = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);

#pragma omp parallel
  {

    int tid = omp_get_thread_num() * _num_groups;
    Material* material;
    FP_PRECISION* sigma;
    FP_PRECISION volume;

    /* Compute the new nu-fission rates in each FSR */
#pragma omp for schedule(guided)
    for (int r=0; r < _num_FSRs; r++) {

      volume = _FSR_volumes[r];
      material = _FSR_materials[r];
      sigma = material->getNuSigmaF();

      /* Loop over each energy group vector length */
      for (int v=0; v < _num_vector_lengths; v++) {

        /* Loop over energy groups within this vector */
#pragma simd vectorlength(VEC_LENGTH)
        for (int e=v*VEC_LENGTH; e < (v+1)*VEC_LENGTH; e++)
          group_rates[tid+e] = sigma[e] * _scalar_flux(r,e);
      }

#ifdef SINGLE
      FSR_rates[r] = cblas_sasum(_num_groups, &group_rates[tid], 1) * volume;
#else
      FSR_rates[r] = cblas_dasum(_num_groups, &group_rates[tid], 1) * volume;
#endif
    }
  }

  /* Reduce new fission rates across FSRs */
#ifdef SINGLE
  fission = cblas_sasum(_num_FSRs, FSR_rates, 1);
#else
  fission = cblas_dasum(_num_FSRs, FSR_rates, 1);
#endif

  _k_eff *= fission;

  MM_FREE(FSR_rates);
  MM_FREE(group_rates);
}
Esempio n. 4
0
/*
-----------------------------------------------------------------------------
 Function: Z_TagMalloc -Allocates zone memory blocks.
 
 Parameters: 
 			size -[in] Bytes to allocate. 	
 			tag -[in] Tag to associate with memory (see header for tag).
 
 Returns: 
 		A void pointer to the allocated space, or will shutdown application 
		if there is insufficient memory available.
 
 Notes: 
-----------------------------------------------------------------------------
*/
PUBLIC void *Z_TagMalloc( size_t size, int tag )
{
	zhead_t	*z;

	// Allocate memory
	size += sizeof( zhead_t );
	z = MM_MALLOC( size );
	
	
	if( ! z )
	{
		Com_Error( ERR_FATAL, "Z_Malloc: failed on allocation of %i bytes", size );
	}

	// Set memory block to zero and fill in header.
	memset( z, 0, size );
	z_count++;
	z_bytes += size;
	z->magic = Z_MAGIC;
	z->tag = tag;
	z->size = size;

	// Add new memory block to chain.
	z->next = z_chain.next;
	z->prev = &z_chain;
	z_chain.next->prev = z;
	z_chain.next = z;

	return (void *)(z+1);
}
Esempio n. 5
0
/**
 * \brief Get Page file raw data.
 * \param[in] pagenum Page to load.
 * \param[in] length Length of data.
 * \return On success pointer to data block, otherwise NULL.
 * \note Caller is responsible for freeing allocated data by calling MM_FREE.
 */
PUBLIC void *PageFile_getPage( W32 pagenum, W32 *length )
{
    W8 *addr;
    PageList_t *page;
	W32  pageOffset;
    W16  pageLength;


	*length = 0;

    page = &PMPages[ pagenum ];


	pageOffset = LittleLong( page->offset );
    pageLength = LittleShort( page->length );


	if( pageLength == 0 )
	{
		return NULL;
	}

    addr = (PW8)MM_MALLOC( pageLength );
	if( addr == NULL )
	{
		return NULL;
	}

    PageFile_ReadFromFile( addr, pageOffset, pageLength );

	*length = pageLength;

    return addr;
}
Esempio n. 6
0
/**
 * \brief Decodes raw sprite data into RGB32.
 * \param[in] data Raw sprite data.
 * \param[in] palette Palette array.
 * \return On success pointer to raw image data block, otherwise NULL.
 * \note Caller is responsible for freeing allocated data by calling MM_FREE.
 */
PUBLIC void *PageFile_decodeSprite_RGB32( W8 *data, W8 *palette )
{
	W32 i;
	W32 temp;
	W32 x, y;
	W8 *buffer;
	W8 *ptr;
	W16 *cmdptr;
	SW16 *linecmds;

	t_compshape *shape;

	W16 leftpix, rightpix;

	buffer = (PW8)MM_MALLOC( 64 * 64 * 4 );
	if( NULL == buffer )
	{
		return NULL;
	}


	for( x = 0 ; x < (64 * 64 * 4) ; x += 4 )
	{
		ptr = buffer + x;

		ptr[ 0 ] = 0xFF;	/* R */
		ptr[ 1 ] = 0x00;	/* G */
		ptr[ 2 ] = 0xFF;	/* B */
        ptr[ 3 ] = 0x00;	/* A */
	}

	shape = (t_compshape *)data;

	leftpix = LittleShort( shape->leftpix );
	rightpix = LittleShort( shape->rightpix );

	cmdptr = shape->dataofs;
	for( x = leftpix ; x <= rightpix ; ++x )
	{
        linecmds = (PSW16)(data + LittleShort( *cmdptr ));
		cmdptr++;
		for( ; LittleShort( *linecmds ) ; linecmds += 3 )
		{
			i = (LittleShort( linecmds[ 2 ] ) / 2) + LittleShort( linecmds[ 1 ] );
			for( y = (W32)(LittleShort( linecmds[ 2 ] ) / 2) ; y < (W32)(LittleShort( linecmds[ 0 ] ) / 2) ; ++y, ++i )
			{
				temp = data[ i ] * 3;

				ptr = buffer + (y * 64 + x) * 4;

				ptr[ 0 ] = palette[ temp + 0 ];		/* R */
				ptr[ 1 ] = palette[ temp + 1 ];		/* G */
				ptr[ 2 ] = palette[ temp + 2 ];		/* B */
                ptr[ 3 ] = 0xFF;		            /* A */
			}
		}
	}

	return (void *)buffer;
}
Esempio n. 7
0
/**
 * \brief Decodes raw wall data into RGB-32.
 * \param[in] data Raw wall data.
 * \param[in] palette Palette array.
 * \return On success pointer to raw image data block, otherwise NULL.
 * \note Caller is responsible for freeing allocated data by calling MM_FREE.
 */
PUBLIC void *PageFile_decodeWall_RGB32( W8 *data, W8 *palette )
{
	W32 temp;
	W8 *buffer;
	W8 *ptr;
	W32 x, y;

	buffer = (PW8)MM_MALLOC( 64 * 64 * 4 );
	if( NULL == buffer )
	{
		return NULL;
	}

	for( x = 0 ; x < 64 ; ++x )
	{
		for( y = 0 ; y < 64 ; ++y )
		{
			temp = ( data[ (x << 6) + y ] ) * 3;

			ptr = buffer + ( ( (y << 6) + x ) * 4 );

			ptr[ 0 ] = palette[ temp + 0 ];		/* R */
			ptr[ 1 ] = palette[ temp + 1 ];		/* G */
			ptr[ 2 ] = palette[ temp + 2 ];		/* B */

            ptr[ 3 ] = 0xFF;                    /* A */
		}
	}

	return (void *)buffer;
}
Esempio n. 8
0
/**
 * @brief Allocates memory for Track boundary angular and FSR scalar fluxes.
 * @details Deletes memory for old flux arrays if they were allocated for a
 *          previous simulation.
 */
void VectorizedSolver::initializeFluxArrays() {

  /* Delete old flux arrays if they exist */
  if (_boundary_flux != NULL)
    MM_FREE(_boundary_flux);

  if (_scalar_flux != NULL && !_user_fluxes)
    MM_FREE(_scalar_flux);

  if (_old_scalar_flux != NULL)
    MM_FREE(_old_scalar_flux);

  if (_delta_psi != NULL)
    MM_FREE(_delta_psi);

  if (_thread_taus != NULL)
    MM_FREE(_thread_taus);

  int size;

  /* Allocate aligned memory for all flux arrays */
  try{

    size = 2 * _tot_num_tracks * _num_groups * _num_polar;
    size *= sizeof(FP_PRECISION);
    _boundary_flux = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);

    size = _num_FSRs * _num_groups * sizeof(FP_PRECISION);
    _scalar_flux = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);
    _old_scalar_flux = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);

    size = _num_threads * _num_groups * sizeof(FP_PRECISION);
    _delta_psi = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);

    size = _num_threads * _polar_times_groups * sizeof(FP_PRECISION);
    _thread_taus = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);
  }
  catch(std::exception &e) {
    log_printf(ERROR, "Could not allocate memory for the fluxes");
  }
}
Esempio n. 9
0
/**
 * \brief Gets the current working directory
 * \return If the function succeeds, a pointer to a NUL-terminated string. Otherwise NULL.
 * \note Caller is responsible for freeing allocated memory.
 */
PUBLIC char *FS_GetCurrentDirectory( void )
{
	char *path;

	path = MM_MALLOC( MAXPATHLEN );
	if( path == NULL )
	{
		return NULL;
	}

	return getcwd( path, MAXPATHLEN );
}
Esempio n. 10
0
/*
-----------------------------------------------------------------------------
 Function: CAL_ExpandGrChunk() -Expand compressed graphic chunk.
 
 Parameters: chunk -[in] Chunk number to expand.
             source -[in] Pointer to compressed data.
             version -[in] extension version. 
                        1 -WL6
                        2 -SOD 
 
 Returns: Nothing.
 
 Notes: 
-----------------------------------------------------------------------------
*/
PRIVATE void CAL_ExpandGrChunk( W32 chunk, const W8 *source, W16 version )
{
	W32 expanded;
	W16	 offset = 0;

	if( version & SOD_PAK )
        offset = SOD_STARTDIFF;

	if( chunk >= ( STARTTILE8 + offset ) && 
        chunk < ( STARTEXTERNS + offset ) )
	{
	//
	// expanded sizes of tile8/16/32 are implicit
	//

#define BLOCK		64
#define MASKBLOCK	128

		if( chunk < (STARTTILE8M + offset) ) // tile 8s are all in one chunk!
			expanded = BLOCK * NUMTILE8;
		else if( chunk < (STARTTILE16 + offset) )
			expanded = MASKBLOCK * NUMTILE8M;
		else if( chunk < (STARTTILE16M + offset) )	// all other tiles are one/chunk
			expanded = BLOCK << 2;
		else if( chunk < (STARTTILE32 + offset) )
			expanded = MASKBLOCK << 2;
		else if( chunk < (STARTTILE32M + offset) )
			expanded = BLOCK << 4;
		else
			expanded = MASKBLOCK << 4;
	}
	else
	{
	//
	// everything else has an explicit size longword
	//
		expanded = *(PW32)source;
		source += 4;			// skip over length
	}

//
// allocate final space and decompress it.
// Sprites need to have shifts made and various other junk.
//
	grsegs[ chunk ] = MM_MALLOC( expanded );
	if( grsegs[ chunk ] == NULL )
	{
		return;
	}
	
	CAL_HuffExpand( source, grsegs[ chunk ], expanded, grhuffman );
}
Esempio n. 11
0
/*
-----------------------------------------------------------------------------
 Function: 

 Parameters:

 Returns:

 Notes: 
-----------------------------------------------------------------------------
*/
PRIVATE void R_ScreenShot_f( void ) 
{
	W8		*buffer;
	char	picname[ 80 ]; 
	char	checkname[ MAX_OSPATH ];
	int		i;
	FILE	*f;

	// create the scrnshots directory if it doesn't exist
	my_snprintf( checkname, sizeof( checkname ), "%s/scrnshot", FS_Gamedir() );
	FS_CreateDirectory( checkname );

// 
// find a file name to save it to 
// 
	my_strlcpy( picname, "scrn00.tga", sizeof( picname ) );

	for( i = 0 ; i <= 99 ; ++i ) 
	{ 
		picname[ 4 ] = i / 10 + '0'; 
		picname[ 5 ] = i % 10 + '0'; 
		my_snprintf( checkname, sizeof( checkname ), "%s/scrnshot/%s", FS_Gamedir(), picname );
		f = fopen( checkname, "rb" );
		if( ! f )
		{
			break;	// file doesn't exist
		}

		fclose( f );
	} 

	if( i == 100 ) 
	{
		Com_Printf( "R_ScreenShot_f: Couldn't create a file\n" ); 
		return;
 	}


	buffer = MM_MALLOC( viddef.width * viddef.height * 3 );
	

	pfglReadPixels( 0, 0, viddef.width, viddef.height, GL_RGB, GL_UNSIGNED_BYTE, buffer ); 

	
	WriteTGA( checkname, 24, viddef.width, viddef.height, buffer, 1, 1 );
	

	MM_FREE( buffer );
	Com_Printf( "Wrote %s\n", picname );
}
Esempio n. 12
0
/**
 * \brief Create a new link list.
 * \return Pointer to new link list structure. 
 */
PUBLIC linkList_t *linkList_new( void )
{
    linkList_t *list;

	list = (linkList_t *) MM_MALLOC( sizeof( linkList_t ) );
    if( list == NULL )
	{
        MM_OUTOFMEM( "linkList_new" );
	}

    list->element = NULL;
    list->next = NULL;

    return list;
}
Esempio n. 13
0
/**
 * @brief Allocates memory for the exponential linear interpolation table.
 */
void VectorizedSolver::initializeExpEvaluator() {

  CPUSolver::initializeExpEvaluator();

  /* Deallocates memory for the exponentials if it was allocated for a
   * previous simulation */
  if (_thread_exponentials != NULL)
    MM_FREE(_thread_exponentials);

  /* Allocates memory for an array of exponential values for each thread
   * - this is not used by default, but can be to allow for vectorized
   * evaluation of the exponentials. Unfortunately this does not appear
   * to give any performance boost. */
  int size = _num_threads * _polar_times_groups * sizeof(FP_PRECISION);
  _thread_exponentials = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);
}
Esempio n. 14
0
/*
-----------------------------------------------------------------------------
 Function: CA_CacheGrChunk() -Cache graphic chunk.
 
 Parameters: chunk -[in] Chunk number to cache.
             version -[in] extension version. 
                        1 -WL6
                        2 -SOD 
                        
 Returns: Nothing.
 
 Notes: Makes sure a given chunk is in memory, loading it if needed.
-----------------------------------------------------------------------------
*/
PRIVATE void CA_CacheGrChunk( W32 chunk, W16 version )
{
	SW32	pos;
	W32		compressed;
	void	*buffer;
	W32		next;
	
	if( grsegs[ chunk ] )
	{
		return;	// already in memory
	}

	
//
// load the chunk into a buffer
//
	pos = GRFILEPOS( chunk );
	if( pos < 0 )  // $FFFFFFFF start is a sparse tile
	{
		return;
	}

	next = chunk + 1;
	while( GRFILEPOS( next ) == -1 )   // skip past any sparse tiles
	{
		next++;
	}

	compressed = GRFILEPOS( next ) - pos;

	fseek( grhandle, pos, SEEK_SET );

	
	buffer = MM_MALLOC( compressed );
	if( buffer == NULL )
	{
		return;
	}


	fread( buffer, 1, compressed, grhandle );
	
	CAL_ExpandGrChunk( chunk, buffer, version );


	MM_FREE( buffer );
}
Esempio n. 15
0
/*
-----------------------------------------------------------------------------
 Function: 
 
 Parameters:
 
 Returns:
 
 Notes: 

-----------------------------------------------------------------------------
*/
PRIVATE powerup_t *Pow_AddNew( void )
{
	powerup_t *newp;
	
	newp = MM_MALLOC( sizeof( powerup_t ) );
	newp->prev = NULL;
	newp->next = powerups;

	if( powerups )
	{
		powerups->prev = newp;
	}

	powerups = newp;

	return newp;
}
/**
 * \brief Cache audio data.
 * \param[in] chunkId Id of chunk to cache. 
 * \return On success pointer to raw data, otherwise NULL.
 */
PUBLIC void *AudioFile_CacheAudioChunk( const W32 chunkId )
{
	W32	pos;
	W32 chunk_size;
	W32 count;			/* Number of bytes read from file */	
	SW8 *buffer;

//
// Load the chunk into a buffer
//
	pos = LittleLong( audiostarts[ chunkId ] );
	chunk_size = (LittleLong( audiostarts[ chunkId+1 ] )) - pos;
	if( chunk_size < 1 )
	{
		fprintf( stderr, "[AudioFile_CacheAudioChunk]: Chunk size not valid\n" );
		
		return NULL;
	}
	

	if( fseek( audiohandle, pos, SEEK_SET ) != 0 )
	{
		fprintf( stderr, "[AudioFile_CacheAudioChunk]: Could not seek in file!\n" );
		
		return NULL;
	}

	buffer = (PSW8) MM_MALLOC( chunk_size );
	if( buffer == NULL )
	{
		return NULL;
	}

	count = fread( buffer, 1, chunk_size, audiohandle );
	if( count != chunk_size )
	{
		fprintf( stderr, "[AudioFile_CacheAudioChunk]: Read error!\n" );

		MM_FREE( buffer );
		
		return NULL;	
	}

	return (void *)buffer;
}
Esempio n. 17
0
/**
 * \brief Initialize Texture Manager.
 * \note Generates default texture.
 */
PUBLIC void TM_Init( void )
{
    W8 *ptr;
    W8 *data;
    int x, y;


    memset( _texWalls, 0, sizeof( _texWalls ) );
    memset( _texSprites, 0, sizeof( _texSprites ) );

    texture_registration_sequence = 1;

// create a checkerboard texture
    data = (PW8)MM_MALLOC( 16 * 16 * 4 );
    for( y = 0; y < 16; ++y )
    {
        for( x = 0; x < 16; ++x )
        {
            ptr = &data[ (y * 16 + x) * 4 ];
            if( (y < 8) ^ (x < 8) )
            {
                ptr[ 0 ] = ptr[ 1 ] = ptr[ 2 ] = 0x00;
                ptr[ 3 ] = 0xFF;
            }
            else
            {
                ptr[ 0 ] = ptr[ 1 ] = ptr[ 2 ] = 0xFF;
                ptr[ 3 ] = 0xFF;
            }
        }
    }

    r_notexture = TM_LoadTexture( "***r_notexture***", data, 16, 16, TT_Pic, 4 );

    MM_FREE( data );


    Cmd_AddCommand( "listTextures", TM_TextureList_f );


}
Esempio n. 18
0
/**
 * \brief Add element to link list.
 * \param[in] list Pointer to linkList_t structure.
 * \param[in] newElement Element to add to link list.
 * \return On success pointer to newly added node, otherwise NULL.
 */
PUBLIC linkList_t *linkList_addList( linkList_t *list, void *newElement )
{
    if( list )
	{
		linkList_t *newNode;

		newNode = (linkList_t *) MM_MALLOC( sizeof( linkList_t ) );
		if( newNode == NULL )
		{
			MM_OUTOFMEM( "linkList_addList" );
		}

		newNode->element = newElement;
		newNode->next = list->next;
		list->next = newNode;

		return newNode;
    } 

    return (linkList_t *) NULL;
}
Esempio n. 19
0
/**
 * \brief Add element to link list.
 * \param[in] list Pointer to linkList_t structure.
 * \param[in] newElement Element to add to link list.
 * \return On success true, otherwise false.
 */
PUBLIC wtBoolean linkList_add( linkList_t *list, void *newElement )
{
    if( list )
	{
		linkList_t *newNode;
		
		newNode = (linkList_t *) MM_MALLOC( sizeof( linkList_t ) );
		if( newNode == NULL )
		{
			MM_OUTOFMEM( "linkList_add" );
		}

		newNode->element = newElement;
		newNode->next = list->next;
		list->next = newNode;
		
		return true;
    } 
	
    return false;
}
/**
 * \brief Get map data chunk.
 * \param[in] chunkOffset Source buffer to convert from
 * \param[in] chunkLength Size of chunk data.
 * \return NULL on error, otherwise pointer to map data.
 * \note Caller must free allocated data.
 */
PUBLIC void *MapFile_getMapData( W32 chunkOffset, W32 chunkLength )
{
	void *mapdata;

	if( map_file_handle == NULL )
	{
		return NULL;
	}

	mapdata = MM_MALLOC( chunkLength );
	if( NULL == mapdata )
	{
		MM_OUTOFMEM( "MapFile_getMapData"  );

		return NULL;
	}

	fseek( map_file_handle, chunkOffset, SEEK_SET );

	fread( mapdata, 1, chunkLength, map_file_handle );


	return mapdata;
}
Esempio n. 21
0
/**
 * @brief Allocates memory for FSR source arrays.
 * @details Deletes memory for old source arrays if they were allocated for a
 *          previous simulation.
 */
void VectorizedSolver::initializeSourceArrays() {

  /* Delete old sources arrays if they exist */
  if (_fission_sources != NULL)
    MM_FREE(_fission_sources);

  if (_scatter_sources != NULL)
    MM_FREE(_scatter_sources);

  if (_source != NULL)
    MM_FREE(_source);

  if (_old_source != NULL)
    MM_FREE(_old_source);

  if (_reduced_source != NULL)
    MM_FREE(_reduced_source);

  if (_source_residuals != NULL)
    MM_FREE(_source_residuals);

  int size;

  /* Allocate aligned memory for all source arrays */
  try{
    size = _num_FSRs * _num_groups * sizeof(FP_PRECISION);
    _fission_sources = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);
    _source = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);
    _old_source = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);
    _reduced_source = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);

    size = _num_threads * _num_groups * sizeof(FP_PRECISION);
    _scatter_sources = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);

    size = _num_FSRs * sizeof(FP_PRECISION);
    _source_residuals = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);
  }
  catch(std::exception &e) {
    log_printf(ERROR, "Could not allocate memory for the VectorizedSolver's "
               "FSR sources array. Backtrace:%s", e.what());
  }
}
Esempio n. 22
0
/*
-----------------------------------------------------------------------------
 Function: LumpExtractor() -Extract Lump gfx from Wolf3D and SOD data files.
 
 Parameters: fextension -[in] String holding file extension 
                            (must be in '.XXX' format).
             limit -[in] max
             version -[in] extension version. 
                        1 -WL6
                        2 -SOD 
 
 Returns:   Nothing.
 
 Notes: 

-----------------------------------------------------------------------------
*/
PUBLIC _boolean LumpExtractor( const char *fextension, W32 limit, W16 version )
{
    W32 i;
    W8 *buffer, *buffer2;
	
    
    if( ! fextension || ! *fextension )
    {
        printf( "Invalid file extension passed into LumpExtractor!\n" );
        
		return false;
    }

//
// Setup
//

	if( 0 == FS_Mkdir( LGFXDIR ) )
	{
		printf( "[%s] Could not create directory (%s)!\n", "wolf_gfx.c", LGFXDIR );
		
		return false;
	}

    
    if( ! CAL_SetupGrFile( fextension ) )
	{
		CAL_Shutdown();
		
		return false;
	}
	
//
// Allocate buffers
//

	buffer = MM_MALLOC( 320 * 416 * 2 );
	if( buffer == NULL )
	{
		CAL_Shutdown();
		
		return false;
	}

    buffer2 = MM_MALLOC( 640 * 400 * 4 );
	if( buffer2 == NULL )
	{
		MM_FREE( buffer );
		CAL_Shutdown();
		
		return false;
	}

//
// Decode GFX data
//

	printf( "Decoding GFX Data...\n" );
	
//	(void)DecodeText( version );
	
	
	for( i = STARTFONT; i < STARTPICS; ++i )
    {
        CA_CacheGrChunk( i, version );
        Fontline( i, version );
    }
	
    
    for( i = STARTPICS; i < limit+1; ++i )
    {
        CA_CacheGrChunk( i, version );
        SavePic( i, version, buffer, buffer2 );		
    }
	


//
// Shutdown
//
    
    MM_FREE( buffer2 );
	MM_FREE( buffer );	
    
    CAL_Shutdown();

	return true;
}
Esempio n. 23
0
/*
-----------------------------------------------------------------------------
 Function: CAL_SetupGrFile() -Initialize graphic files and arrays.
 
 Parameters: extension -[in] Pointer to a null-terminated string that 
                            specifies the file extension.
                            (must be in '.XXX' format).
 
 Returns: 1 on success, 0 otherwise.
 
 Notes: 
        Uses global variables grhandle and pictable.
        1. Open vgadict.XXX, read huffman dictionary data.
        2. Open vgahead.XXX, read data offsets.
        3. Open vgagraph.XXX, read pic and sprite header, expand data.
-----------------------------------------------------------------------------
*/
PRIVATE W8 CAL_SetupGrFile( const char *extension )
{
	void *compseg;
	FILE *handle;
	char filename[ 16 ];
	SW32 chunkcomplen; // chunk compressed length
	
//
// load vgadict.ext (huffman dictionary for graphics files)
//
	cs_strlcpy( filename, GFXDICTFNAME, sizeof( filename ) );
	cs_strlcat( filename, extension, sizeof( filename ) );
	
	if( ( handle = fopen( cs_strupr( filename ), "rb" ) ) ==  NULL )
	{
		if( ( handle = fopen( cs_strlwr( filename ), "rb" ) ) ==  NULL )
		{
			printf( "Could not open file (%s) for read!\n", filename );
			return 0;
		}
	}
  
	fread( grhuffman, sizeof( grhuffman ), 1, handle );
	fclose( handle );
	
//
// Open then load the data offsets from vgahead.ext
//	
	
	cs_strlcpy( filename, GFXHEADFNAME, sizeof( filename ) );
	cs_strlcat( filename, extension, sizeof( filename ) );
	
	if( (handle = fopen( cs_strupr( filename ), "rb" )) ==  NULL )
	{
		if( (handle = fopen( cs_strlwr( filename ), "rb" )) ==  NULL )
		{
			printf( "Could not open file (%s) for read!\n", filename );
			return 0;
		}
	}
	
	grstarts = MM_MALLOC( (NUMCHUNKS+1) * FILEPOSSIZE );
	if( grstarts == NULL )
	{
		return 0;
	}
  
	fread( grstarts, sizeof( long ), (NUMCHUNKS+1) * FILEPOSSIZE, handle );
	
	fclose( handle );
	
//
// Open the graphics file 'vgagraph.XXX'.
//
	
	cs_strlcpy( filename, GFXFNAME, sizeof( filename ) );
	cs_strlcat( filename, extension, sizeof( filename ) );
	
	if( ( grhandle = fopen( cs_strupr( filename ), "rb" ) ) ==  NULL )
	{
		if( ( grhandle = fopen( cs_strlwr( filename ), "rb" ) ) ==  NULL )
		{
			printf( "Could not open file (%s) for read!\n", filename );
			return 0;
		}
	}
  
//
// load the pic and sprite headers into the arrays.
//
	pictable = MM_MALLOC( NUMPICS * sizeof( pictabletype ) );
	if( pictable == NULL )
	{
		return 0;
	}
  
  
	chunkcomplen = CAL_GetGrChunkLength( STRUCTPIC );  // position file pointer
	
	compseg = MM_MALLOC( chunkcomplen );
	if( compseg == NULL )
	{
		return 0;
	}
	
	fread( compseg, chunkcomplen, 1, grhandle );
	
	CAL_HuffExpand( compseg, (PW8)pictable, 
	                NUMPICS * sizeof( pictabletype ), 
                    grhuffman );

	MM_FREE( compseg ); 
 
    return 1;                 
}
Esempio n. 24
0
void Epoll_Engine::Engine_Loop()
{
	const static int maxevents = 1024;
	struct epoll_event events[1024];
	
	if( socketpair(AF_UNIX,SOCK_STREAM,0,pipefd) == -1)
	{
		LOGDEBUG("libshared","create pipe error!");
		return;
	}
	__shared_setnonblocking( pipefd[1] );
	AddFd(pipefd[0]);
	
	while(true)
	{
		time_t time_start = CURRENTTIME();
		time_t time_end = 0;
		
		int nfds = epoll_wait(m_EpollFd,events,maxevents,timeout);
		if(nfds <= 0)
		{
			// epoll_wait超时...执行时间心跳
			m_timeHeap->Tick();
			timeout = TIME_OUT;
		}
		else
		{
			time_end = CURRENTTIME();
			timeout = time_end - time_start;
			for(int i = 0; i < nfds; i++)
			{
				int fd = events[i].data.fd;
				/////////////////////////////////////////////////////
				//				信号处理
				////////////////////////////////////////////////////
				if(fd == pipefd[0] && events[i].events & EPOLLIN)
				{
					// 信号处理: 主循环来完成吧~~
					//LOGDEBUG("debug","收到信号~~");
					OnRecvSignal();
					continue;
				}
				////////////////////////////////////////////////////
				
				basesocket_sptr socket = fds[fd];

				if(!socket)
				{
					continue;
				}
				// 有一个潜在问题 :当socket的异常时通过epoll_wait发现抛出,
				// EPOLLERR/EPOLLHUP事件,而不是read/write流程中发现,这时
				// 同样会误以为异常断开连接,所以只是再read/write流程中忽略
				// 相关错误码不够完善,当epoll_wait检测到socket错误时,仍然
				// 会当成fatal error处理。
				//
				// 正确的解决方法:
				// 1.read/write流程中对非知名错误(EINTR/EAGAIN/EWOULDBLOCK...)合理处理。
				// 2.遇到EPOLLERR/EPOLLHUP事件时,有两种做法:
				//		(1)不调用error异常流程,而是跟EPOLLIN一样调用读取流程,让读取流程
				//			 去确认/处理实际的错误.
				//		(2)通过getsocketopt SO_REEOR获取具体的错误码,并过滤掉非fatal错误.
				if(events[i].events & EPOLLHUP || events[i].events & EPOLLERR)
				{
					int eno = -1;
					int len = sizeof(int);
					if( getsockopt(fd,SOL_SOCKET,SO_ERROR,(void *)&eno,(socklen_t *)&len) == 0)
					{
						if(eno == 0 || eno == 32)
						{
							// 在OnWrite中已经做过处理,这里不必再处理!
							continue;
						}
						MM_Task * task = new (MM_MALLOC(sizeof(MM_Task))) MM_Task(SWITCH_MM_TASK_ONERROR,(Socket_Engine *)this,fd,socket->GetCtime());
						//MM_Task * task = new MM_Task(SWITCH_MM_TASK_ONERROR,(Socket_Engine *)this,fd,socket->GetCtime());
						if(task != NULL)
							sMMThreads.AddOneTask(task);
					}
				}
				else if(events[i].events & EPOLLIN) // recv data
				{
					MM_Task * task = new (MM_MALLOC(sizeof(MM_Task))) MM_Task(SWITCH_MM_TASK_ONREAD,(Socket_Engine *)this,fd,socket->GetCtime());
					//MM_Task * task = new  MM_Task(SWITCH_MM_TASK_ONREAD,(Socket_Engine *)this,fd,socket->GetCtime());
					if(task != NULL)
						sMMThreads.AddOneTask(task);
				}
				else if(events[i].events & EPOLLOUT) // send data
				{
					MM_Task * task = new (MM_MALLOC(sizeof(MM_Task))) MM_Task(SWITCH_MM_TASK_ONWRITE,(Socket_Engine *)this,fd,socket->GetCtime());
					//MM_Task * task = new  MM_Task(SWITCH_MM_TASK_ONWRITE,(Socket_Engine *)this,fd,socket->GetCtime());
					if(task != NULL)
						sMMThreads.AddOneTask(task);
				}
			}
		}
		sMMThreads.Run();
	}
}
Esempio n. 25
0
/*
-----------------------------------------------------------------------------
 Function: Fontline() -Extract and save font.
 
 Parameters: fontnumber -[in] font to save.
             version -[in] extension version. 
                        1 -WL6
                        2 -SOD 
 
 Returns: Nothing.
 
 Notes: Font must be cached in grsegs[] before calling.
-----------------------------------------------------------------------------
*/
PRIVATE void Fontline( W32 fontnumber, W16 version )
{
	fontstruct	*font;
	W16 i;
	W16 x, y;
	W16 px, py;
	W8 *buffer;	
	W8 *source;
	W8 *ptr;	
	char filename[ 256 ];
	

	font = (fontstruct *)grsegs[ fontnumber ];	
	

	buffer = MM_MALLOC( FONTWIDTH * FONTHEIGHT * 4 );
	if( buffer == NULL )
		return;

	ptr = buffer;
	for( x = 0; x < FONTWIDTH; ++x )
	{
		for( y = 0; y < FONTHEIGHT; ++y, ptr += 4 )
		{
			ptr[ 0 ] = ptr[ 1 ] = ptr[ 2 ] = 0xFF;
			ptr[ 3 ] = 0x00;
		}
	}

	px = py = 0;
	for( i = 0; i < 256; ++i )
	{		
		if( ! font->width[ i ] )
			continue;
		 
		if( px + font->width[ i ] > FONTWIDTH-1 )
		{
			py += font->height;
			px = 0;
		}
			
		source = ((PW8) font) + font->location[ i ];

		ptr = buffer + (py * FONTWIDTH + px) * 4;
		for( y = 0; y < font->height; ++y, ptr += FONTWIDTH * 4 )
		{
			for( x = 0; x < font->width[ i ]; ++x )
			{
				if( *source++ )	
				{
					ptr[ x * 4 + 3 ] = 0xFF;
				}
			}
		}
		
		px += 16;

	} // end for i = 0; i < 256; ++i


	cs_snprintf( filename, sizeof( filename ), "%s/font%d.tga", LGFXDIR, fontnumber );
	
	WriteTGA( filename, 32, FONTWIDTH, FONTHEIGHT, buffer, 0, 1 );	
	
	MM_FREE( buffer );

}
Esempio n. 26
0
/**
 * \brief Load font details from file
 * \param[in] filename File name to load details
 * \return Valid pointer to font_t
 */
PUBLIC font_t *createFont( const char *filename )
{
	font_t *temp_font;
	char *datname;
	filehandle_t *fp;
	W32 size;
	W32 i;

	if( num_fonts == (MAX_FONTS - 1) )
	{
		Com_Printf( "[createFont]: No more font slots open\n" );

		return NULL;
	}


	temp_font = (font_t *)Z_Malloc( sizeof( font_t ) );

	temp_font->texfont = TM_FindTexture( filename, TT_Pic );
	if( NULL == temp_font->texfont )
	{
		Com_Printf( "[createFont]: unable to open file (%s)\n", filename );

		Z_Free( temp_font );

		return NULL;
	}

	memset( temp_font->nCharWidth, 0, sizeof( temp_font->nCharWidth ) );

	datname = (char *)MM_MALLOC( strlen( filename ) + 1 );

	FS_RemoveExtension( filename, datname );

	com_strlcat( datname, ".dat", strlen( filename ) + 1 );

	fp = FS_OpenFile( datname, 0 );
	if( NULL == fp )
	{
		Com_Printf( "[createFont]: unable to open file (%s)\n", datname );

		MM_FREE( datname );
		Z_Free( temp_font );

		return NULL;
	}

	size = FS_GetFileSize( fp );

	// check header size
	if( size < 10 )
	{
		Com_Printf( "[createFont]: File (%s) has incorrect file length\n", datname );

		MM_FREE( datname );
		Z_Free( temp_font );

		FS_CloseFile( fp );

		return NULL;
	}


	// Check sig of font dat file

	FS_ReadFile( &size, 1, 4, fp );


	FS_ReadFile( &temp_font->nMaxWidth, 1, 1, fp );
	FS_ReadFile( &temp_font->nMaxHeight, 1, 1, fp );


	FS_ReadFile( &size, 1, 4, fp );
	size = LittleLong( size );

	if( size > 127 )
	{
		Com_Printf( "[createFont]: File (%s) has incorrect Character Width array\n", datname );

		MM_FREE( datname );
		Z_Free( temp_font );

		FS_CloseFile( fp );

		return NULL;
	}

	FS_ReadFile( &temp_font->nCharWidth, 1, size, fp );

	FS_CloseFile( fp );




	temp_font->nSize = 2;
	temp_font->colour[ 3 ] = 255;

	temp_font->hFrac = (float)(temp_font->nMaxHeight / (float)temp_font->texfont->height);
	temp_font->wFrac = (float)(temp_font->nMaxWidth / (float)temp_font->texfont->width);



	for( i = 0 ; i < MAX_FONTS ; ++i )
	{
		if( ! myfonts[ i ] )
		{
			break;
		}
	}

	if( i == (MAX_FONTS - 1) )
	{
		Com_Printf( "[createFont]: No more font slots open\n" );

		MM_FREE( datname );
		Z_Free( temp_font );

		return NULL;
	}

	myfonts[ i ] = temp_font;

	MM_FREE( datname );


	return temp_font;
}
Esempio n. 27
0
/**
 * \brief Setup page file for decoding.
 * \param[in] pagefname Source buffer to convert from
 * \param[out] nBlocks Destination buffer to convert to.
 * \param[out] SpriteStart Offset index for sprite data.
 * \param[out] SoundStart Offset index for sound data.
 * \return On success true, otherwise false.
 */
PUBLIC wtBoolean PageFile_Setup( const char *pagefname, W32 *nBlocks, W32 *SpriteStart, W32 *SoundStart )
{
	W32    i;
	W32  size;
	void *buf = NULL;
	W32  *offsetptr;
	char *temp_fileName = NULL;
	PageList_t *page;
	W16 *lengthptr;
	W16 tval;
	W32 PMNumBlocks;
	W32 PMSpriteStart;
	W32 PMSoundStart;


	if( ! pagefname || ! *pagefname )
	{
		fprintf( stderr, "[PageFile_Setup]: Invalid file name\n" );

		goto PMSetupFailure;
	}

	temp_fileName = (char *) MM_MALLOC( strlen( pagefname ) + 1 );
	if( temp_fileName == NULL )
	{
		goto PMSetupFailure;
	}

	wt_strlcpy( temp_fileName, pagefname, strlen( pagefname ) + 1 );


	/* Open page file */
	file_handle_page = fopen( wt_strupr( temp_fileName ), "rb" );
	if( file_handle_page == NULL )
	{
		file_handle_page = fopen( wt_strlwr( temp_fileName ), "rb" );
		if( file_handle_page == NULL )
		{
			fprintf( stderr, "Could not open file (%s) for read!\n", temp_fileName );

			goto PMSetupFailure;
		}
	}


	/* Read in header variables */
	fread( &tval, sizeof( W16 ), 1, file_handle_page );
	PMNumBlocks = LittleShort( tval );

	fread( &tval, sizeof( W16 ), 1, file_handle_page );
	PMSpriteStart = LittleShort( tval );

	fread( &tval, sizeof( W16 ), 1, file_handle_page );
	PMSoundStart = LittleShort( tval );


	/* Allocate and clear the page list */
	PMPages = (PageList_t *) MM_MALLOC( sizeof( PageList_t ) * PMNumBlocks );
	if( PMPages == NULL )
	{
		goto PMSetupFailure;
	}


	memset( PMPages, 0, sizeof( PageList_t ) * PMNumBlocks );


	/* Read in the chunk offsets */
	size = sizeof( W32 ) * PMNumBlocks;

	buf = MM_MALLOC( size );
	if( buf == NULL )
	{
		goto PMSetupFailure;
	}


	if( fread( buf, 1, size, file_handle_page ) == 0 )
	{
		fprintf( stderr, "Could not read chunk offsets from file (%s)\n", temp_fileName );
	}

	offsetptr = (PW32) buf;
	for( i = 0, page = PMPages; i < PMNumBlocks; i++, page++ )
	{
		page->offset = LittleLong( *offsetptr++ );
	}
	MM_FREE( buf );


	/* Read in the chunk lengths */
	size = sizeof( W16 ) * PMNumBlocks;

	buf = MM_MALLOC( size );
	if( buf == NULL )
	{
		goto PMSetupFailure;
	}

	if( fread( buf, 1, size, file_handle_page ) == 0 )
	{
		fprintf( stderr, "Could not read chunk lengths from file (%s)\n", temp_fileName );
	}

	lengthptr = (PW16)buf;
	for( i = 0, page = PMPages ; i < PMNumBlocks ; ++i, page++ )
	{
		page->length = LittleShort( *lengthptr++ );
	}

	MM_FREE( buf );
	MM_FREE( temp_fileName );

	*nBlocks = PMNumBlocks;
	*SpriteStart = PMSpriteStart;
	*SoundStart = PMSoundStart;

	return true;

PMSetupFailure:

	MM_FREE( temp_fileName );
	MM_FREE( PMPages );
	MM_FREE( buf );

	return false;
}
Esempio n. 28
0
/**
 * \brief Redux the Page file data.
 * \param[in] vsfname data file name.
 * \param[in] wallPath Path to save wall data.
 * \param[in] spritePath Path to save sprite data.
 * \param[in] soundPath Path to save sound data.
 * \param[in] palette Palette array.
 * \return On success true, otherwise false.
 * \note Caller is responsible for freeing allocated data by calling MM_FREE.
 */
PUBLIC wtBoolean PageFile_ReduxDecodePageData( const char *vsfname, const char *wallPath, const char *spritePath, const char *soundPath, W8 *palette )
{
	void *data;
	void *decdata;
	W32 length;
	char tempFileName[ 1024 ];
	W32 i;
	W32 SpriteStart, NumBlocks, SoundStart;
	W32 soundBufferSize;
	W8 *soundBuffer;
	W32 totallength;


	printf( "Decoding Page Data..." );

	if( ! PageFile_Setup( vsfname, &NumBlocks, &SpriteStart, &SoundStart ) )
	{
		PageFile_Shutdown();

		return false;
	}

    // ////////////////////////////////////////////////////////////////////////
    // Decode Walls

	for( i = 0 ; i < SpriteStart ; ++i )
	{
		data = PageFile_getPage( i, &length );
		if( data == NULL )
		{
			continue;
		}

		decdata = PageFile_decodeWall_RGB32( (PW8)data, palette );
		if( decdata == NULL )
		{
			fprintf( stderr, "[PageFile_ReduxDecodePageData]: Unable to decode wall (%d).\n", i );

			MM_FREE( data );

			continue;
		}


		if( _filterScale > 0 )
		{
			void *scaledImgBuf;

			scaledImgBuf = (void *) MM_MALLOC( 128 * 128 * 4 );
			if( NULL == scaledImgBuf )
			{
				MM_FREE( data );
				MM_FREE( decdata );
				continue;
			}


			// Scale2x
		        if( _filterScale == 1 )
			{
		                scale( 2, (void *)scaledImgBuf, 128 * 4, decdata, 64 * 4, 4, 64, 64 );
				RGB32toRGB24( (const PW8)scaledImgBuf, (PW8)scaledImgBuf, 128 * 128 * 4 );
			} else {
		                // hq2x
		                RGB32toRGB24( (const PW8)decdata, (PW8)decdata, 64 * 64 * 4 );
		                RGB24toBGR565( decdata, decdata, 64 * 64 * 3 );
				hq2x_32( (PW8)decdata, (PW8)scaledImgBuf, 64, 64, 64 * 2 * 4  );
        		        RGB32toRGB24( (const PW8)scaledImgBuf, (PW8)scaledImgBuf, 128 * 128 * 4 );

        		}

    		        wt_snprintf( tempFileName, sizeof( tempFileName ), "%s%c%.3d.tga", wallPath, PATH_SEP, GetWallMappedIndex( i ) );
			TGA_write( tempFileName, 24, 128, 128, scaledImgBuf, 0, 1 );

			MM_FREE( scaledImgBuf );

		} else {
		        wt_snprintf( tempFileName, sizeof( tempFileName ), "%s%c%.3d.tga", wallPath, PATH_SEP, GetWallMappedIndex( i ) );

		        RGB32toRGB24( (const PW8)decdata, (PW8)decdata, 64 * 64 * 4 );
			TGA_write( tempFileName, 24, 64, 64, decdata, 0, 1 );
		}


		MM_FREE( data );
		MM_FREE( decdata );
	}


    // ////////////////////////////////////////////////////////////////////////
    // Decode Sprites

	for( i = SpriteStart ; i < SoundStart ; ++i )
	{
		data = PageFile_getPage( i, &length );
		if( data == NULL )
		{
			continue;
		}

		decdata = PageFile_decodeSprite_RGB32( (PW8)data, palette );
		if( decdata == NULL )
		{
			MM_FREE( data );

			continue;
		}

		if( _filterScale_Sprites > 0 )
		{
			W8 *scaledImgBuf;

			scaledImgBuf = (PW8) MM_MALLOC( 128 * 128 * 4 );
			if( NULL == scaledImgBuf ) {
				MM_FREE( data );
				MM_FREE( decdata );
				continue;
			}
			if( _filterScale_Sprites == 1 ) {
				scale( 2, (void *)scaledImgBuf, 128 * 4, decdata, 64 * 4, 4, 64, 64 );
			} else {
			// hq2x
				RGB32toRGB24( (const PW8)decdata, (PW8)decdata, 64 * 64 * 4 );
				RGB24toBGR565( decdata, decdata, 64 * 64 * 3 );
				hq2x_32( (PW8)decdata, (PW8)scaledImgBuf, 64, 64, 64 * 2 * 4  );
				ReduxAlphaChannel_hq2x( scaledImgBuf, 128, 128 );
			}

			wt_snprintf( tempFileName, sizeof( tempFileName ), "%s%c%.3d.tga", spritePath, PATH_SEP, GetSpriteMappedIndex( i - SpriteStart ) );
			TGA_write( tempFileName, 32, 128, 128, scaledImgBuf, 0, 1 );
			MM_FREE( scaledImgBuf );
		} else {
			wt_snprintf( tempFileName, sizeof( tempFileName ), "%s%c%.3d.tga", spritePath, PATH_SEP, GetSpriteMappedIndex( i - SpriteStart )  );
			TGA_write( tempFileName, 32, 64, 64, decdata, 0, 1 );
		}
		MM_FREE( data );
		MM_FREE( decdata );
	}


    // ////////////////////////////////////////////////////////////////////////
    // Decode SFX

	soundBufferSize = 20 * 4096;
	soundBuffer = (PW8) MM_MALLOC( soundBufferSize );
	if( soundBuffer == NULL )
	{
		PageFile_Shutdown();

		return false;
	}

	totallength = 0;
	for( i = SoundStart ; i < NumBlocks ; ++i )
	{
		data = PageFile_getPage( i, &length );
		if( data == NULL )
		{
			continue;
		}


		if( (totallength + length) > soundBufferSize )
		{
			fprintf( stderr, "[PageFile_ReduxDecodePageData]: Buffer not large enough to hold sound data!\n" );


			MM_FREE( data );
			MM_FREE( soundBuffer );

			return false;
		}

	  	MM_MEMCPY( soundBuffer + totallength, data, length );

		totallength += length;


		if( length < 4096 )
		{

			wt_snprintf( tempFileName, sizeof( tempFileName ), "%s%c%.3d.wav", soundPath, PATH_SEP, i - SoundStart );
			wav_write( tempFileName, soundBuffer, totallength, 1, SAMPLERATE, 1 );


			totallength = 0;

		}


		MM_FREE( data );


	}
	MM_FREE( soundBuffer );

	PageFile_Shutdown();
	MM_FREE( data );

	printf( "Done\n" );

	return true;
}
Esempio n. 29
0
/*
-----------------------------------------------------------------------------
 Function: CAL_SetupAudioFile() -Setup for decoding audio data.
 
 Parameters: fextension -[in] Pointer to string with file extension.
 
 Returns: Non-zero on success, otherwise zero.
 
 Notes: 
-----------------------------------------------------------------------------
*/
PRIVATE W8 CAL_SetupAudioFile( const char *fextension )
{
	FILE *handle;
	SW32 length;
	W32 count;
	char fname[ 13 ];

	if( ! fextension || ! *fextension )
	{
		printf( "NULL extension passed into CAL_SetupAudioFile!\n" );
		
		return 0;	
	}

//
// load audiohed.XXX (offsets and lengths for audio file)
//
	cs_strlcpy( fname, AHEADFNAME, sizeof( fname ) );
	cs_strlcat( fname, fextension, sizeof( fname ) );
	
    handle = fopen( cs_strupr( fname ), "rb" );
	if( handle == NULL )
	{
		handle = fopen( cs_strlwr( fname ), "rb" );
		
		if( handle == NULL )
		{
			printf( "Can not open file (%s) for read!\n", fname );
			return 0;
		}
    }

	length = FS_FileLength( handle );
	if( length < 4 )
	{
		fclose( handle );
		printf( "Incorrect audio header size on file: %s\n", fname );
		return 0;
	}

	audiostarts = (PW32) MM_MALLOC( length );
	if( audiostarts == NULL )
	{
		return 0;
	}
	
	count = fread( audiostarts, sizeof( W32 ), length >> 2, handle );
	if( count != (W32)(length >> 2) )
    {
        fclose( handle );
        printf( "[Error]: Read error on file: (%s)", fname  );
		return 0;
	}
	
	
	fclose( handle );

//
// open the Audio data file
//
	cs_strlcpy( fname, AUDIOFNAME, sizeof( fname ) );
	cs_strlcat( fname, fextension, sizeof( fname ) );
	
	audiohandle = fopen( cs_strupr( fname ), "rb" );
	if( audiohandle == NULL )
	{
		audiohandle = fopen( cs_strlwr( fname ), "rb" );
		if( audiohandle == NULL )
		{
			printf( "Could not open file (%s) for read!\n", fname ); 
			return 0;
		}
    }
    
    return 1;
}
Esempio n. 30
0
/**
 * @brief Reallocates the Material's cross-section data structures along
 *        word-aligned boundaries
 * @details This method is used to assist with SIMD auto-vectorization of the
 *          MOC routines in the Solver classes. Rather than using the assigned
 *          number of energy groups, this method adds "dummy" energy groups
 *          such that the total number of groups is some multiple of VEC_LENGTH
 *          (typically 4, 8, or 16). As a result, the SIMD-vectorized Solver
 *          subclasses can break up loops over energy groups in such a way
 *          to "expose" the SIMD nature of the algorithm.
 */
void Material::alignData() {

  /* If the data has already been aligned, do nothing */
  if (_data_aligned)
    return;

  if (_num_groups <= 0)
    log_printf(ERROR, "Unable to align Material %d data since the "
               "cross-sections have not yet been set\n", _id);

  _num_vector_groups = (_num_groups / VEC_LENGTH) + 1;

  /* Allocate memory for the new aligned xs data */
  int size = _num_vector_groups * VEC_LENGTH * sizeof(FP_PRECISION);

  /* Allocate word-aligned memory for cross-section data arrays */
  FP_PRECISION* new_sigma_t = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);
  FP_PRECISION* new_sigma_a = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);
  FP_PRECISION* new_sigma_f = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);
  FP_PRECISION* new_nu_sigma_f=(FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);
  FP_PRECISION* new_chi = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);

  /* The scattering matrix will be the number of vector groups
   * wide (SIMD) and the actual number of groups long since
   * instructions are not SIMD in this dimension */

  size = _num_vector_groups * VEC_LENGTH * _num_vector_groups;
  size *= VEC_LENGTH * sizeof(FP_PRECISION);
  FP_PRECISION* new_sigma_s = (FP_PRECISION*)MM_MALLOC(size, VEC_ALIGNMENT);

  /* Initialize data structures to ones for sigma_t since it is used to
   * divide the source in the solver, and zeroes for everything else */
  size = _num_vector_groups * VEC_LENGTH * sizeof(FP_PRECISION);
  for (int i=0; i < _num_vector_groups * VEC_LENGTH; i++) {
    new_sigma_t[i] = 1.0;
    new_sigma_a[i] = 0.0;
    new_sigma_f[i] = 0.0;
    new_nu_sigma_f[i] = 0.0;
    new_chi[i] = 0.0;
  }

  size *= _num_vector_groups * VEC_LENGTH;
  memset(new_sigma_s, 0.0, size);

  /* Copy materials data from unaligned arrays into new aligned arrays */
  size = _num_groups * sizeof(FP_PRECISION);
  memcpy(new_sigma_t, _sigma_t, size);
  memcpy(new_sigma_a, _sigma_a, size);
  memcpy(new_sigma_f, _sigma_f, size);
  memcpy(new_nu_sigma_f, _nu_sigma_f, size);
  memcpy(new_chi, _chi, size);

  for (int e=0; e < _num_groups; e++) {
    memcpy(new_sigma_s, _sigma_s, size);
    new_sigma_s += _num_vector_groups * VEC_LENGTH;
    _sigma_s += _num_groups;
  }

  _sigma_s -= _num_groups * _num_groups;

  /* Reset the new scattering cross section array pointer */
  new_sigma_s -= _num_vector_groups * VEC_LENGTH * _num_groups;

  /* Delete the old unaligned arrays */
  delete [] _sigma_t;
  delete [] _sigma_a;
  delete [] _sigma_f;
  delete [] _nu_sigma_f;
  delete [] _chi;
  delete [] _sigma_s;

  /* Set the material's array pointers to the new aligned arrays */
  _sigma_t = new_sigma_t;
  _sigma_a = new_sigma_a;
  _sigma_f = new_sigma_f;
  _nu_sigma_f = new_nu_sigma_f;
  _chi = new_chi;
  _sigma_s = new_sigma_s;

  _data_aligned = true;

  return;
}