| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- /*
- ** Command & Conquer Generals(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /*****************************************************************************
- ** **
- ** Westwood Studios Pacific. **
- ** **
- ** Confidential Information **
- ** Copyright (C) 2000 - All Rights Reserved **
- ** **
- ******************************************************************************
- ** **
- ** Project: Dune Emperor **
- ** **
- ** Module: <module> (<prefix>_) **
- ** **
- ** Version: $ID$ **
- ** **
- ** File name: audmpool.cpp **
- ** **
- ** Created by: 10/23/95 TR **
- ** **
- ** Description: <description> **
- ** **
- *****************************************************************************/
- /*****************************************************************************
- ** Includes **
- *****************************************************************************/
- #include <string.h>
- #include <wpaudio/altypes.h>
- #include <wpaudio/memory.h>
- // 'assignment within condition expression'.
- #pragma warning(disable : 4706)
- DBG_DECLARE_TYPE ( AudioMemoryPool )
- DBG_DECLARE_TYPE ( MemoryItem )
- /*****************************************************************************
- ** Externals **
- *****************************************************************************/
- /*****************************************************************************
- ** Defines **
- *****************************************************************************/
- /*****************************************************************************
- ** Private Types **
- *****************************************************************************/
- /*****************************************************************************
- ** Private Data **
- *****************************************************************************/
- /*****************************************************************************
- ** Public Data **
- *****************************************************************************/
- /*****************************************************************************
- ** Private Prototypes **
- *****************************************************************************/
- /*****************************************************************************
- ** Private Functions **
- *****************************************************************************/
- /*****************************************************************************
- ** Public Functions **
- *****************************************************************************/
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- AudioMemoryPool* MemoryPoolCreate( uint items, uint size )
- {
- uint poolsize;
- AudioMemoryPool *pool;
- MemoryItem *item;
- uint i;
-
- DBG_ASSERT ( items > 0 );
- DBG_ASSERT ( size > 0 );
- poolsize = items*(size + sizeof(MemoryItem)) + sizeof (AudioMemoryPool);
- if ((pool = (AudioMemoryPool *) AudioMemAlloc ( poolsize )))
- {
- item = (MemoryItem *)( (uint)pool + (uint) sizeof(AudioMemoryPool));
-
- pool->next = item;
- DBG_CODE ( pool->itemsOut = 0;)
- DBG_CODE ( pool->numItems = items;)
- DBG_SET_TYPE ( pool, AudioMemoryPool );
- for ( i=0; i < items-1; i++)
- {
- DBG_SET_TYPE ( item, MemoryItem );
- item->next = (MemoryItem *) ( (uint) item + (uint) (sizeof(MemoryItem) + size) );
- item = item->next;
- }
- item->next = NULL;
- DBG_SET_TYPE ( item, MemoryItem );
- }
- return pool;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void MemoryPoolDestroy ( AudioMemoryPool *pool )
- {
- DBG_ASSERT_TYPE ( pool, AudioMemoryPool );
-
- DBG_CODE
- (
- if ( pool->itemsOut > 0 )
- {
- DBGPRINTF ( ( "Destroying memory pool with %d items still out\n", pool->itemsOut) );
- }
- )
-
- AudioMemFree ( pool );
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void *MemoryPoolGetItem ( AudioMemoryPool *pool )
- {
- MemoryItem *item = NULL;
- DBG_ASSERT_TYPE ( pool, AudioMemoryPool );
- if (! (item = pool->next) )
- {
- return NULL;
- }
-
- DBG_CODE ( pool->itemsOut++;)
-
- DBG_MSGASSERT ( pool->itemsOut <= pool->numItems,( "pool overflow" ));
- DBG_ASSERT_TYPE ( item, MemoryItem ); // !!! Memory corruption !!!
-
- pool->next = item->next;
-
- return (void *) ( (uint) item + (uint) sizeof(MemoryItem));
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void MemoryPoolReturnItem ( AudioMemoryPool *pool, void *data )
- {
- MemoryItem *item;
- DBG_ASSERT_TYPE ( pool, AudioMemoryPool );
- DBG_ASSERT_PTR ( data );
- item = (MemoryItem *) ( (uint) data - (uint) sizeof(MemoryItem));
-
- DBG_ASSERT_TYPE ( item, MemoryItem ); // returning invalid item to pool
-
- item->next = pool->next;
- pool->next = item;
-
- DBG_MSGASSERT ( pool->itemsOut > 0,( "Pool underflow" )); // returning more items than were taken
-
- DBG_CODE ( pool->itemsOut--; )
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- int MemoryPoolCount ( AudioMemoryPool *pool )
- {
- MemoryItem *item = NULL;
- int count = 0;
- DBG_ASSERT_TYPE ( pool, AudioMemoryPool );
- if ( (item = pool->next) )
- {
- while ( item )
- {
- count++;
- item = item->next;
- }
- }
-
- return count;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioAddSlash ( char *string )
- {
- int len = strlen ( string );
- if ( len )
- {
- if ( string[len-1] != '\\' )
- {
- string[len] = '\\';
- string[len+1] = 0;
- }
- }
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- int AudioHasPath ( const char *string )
- {
- return ( strchr ( string, ':' ) || strchr ( string, '\\' ) || strchr ( string, '/' ) || strchr ( string, '.'));
- }
|