diff options
author | rubidium <rubidium@openttd.org> | 2007-01-02 19:19:48 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-01-02 19:19:48 +0000 |
commit | 66bbf336c6af7353ef0aeed58002c46543b30635 (patch) | |
tree | ad4a63860df2626b22f77e7dac712e958bea54cb /src/oldpool.h | |
parent | ccc0a3f4dbf58c005b22341ac8874252924690cd (diff) | |
download | openttd-66bbf336c6af7353ef0aeed58002c46543b30635.tar.xz |
(svn r7759) -Merge: makefile rewrite. This merge features:
- A proper ./configure, so everything needs to be configured only once, not for every make.
- Usage of makedepend when available. This greatly reduces the time needed for generating the dependencies.
- A generator for all project files. There is a single file with sources, which is used to generate Makefiles and the project files for MSVC.
- Proper support for OSX universal binaries.
- Object files for non-MSVC compiles are also placed in separate directories, making is faster to switch between debug and release compiles and it does not touch the directory with the source files.
- Functionality to make a bundle of all needed files for for example a nightly or distribution of a binary with all needed GRFs and language files.
Note: as this merge moves almost all files, it is recommended to make a backup of your working copy before updating your working copy.
Diffstat (limited to 'src/oldpool.h')
-rw-r--r-- | src/oldpool.h | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/oldpool.h b/src/oldpool.h new file mode 100644 index 000000000..ba22e4ef4 --- /dev/null +++ b/src/oldpool.h @@ -0,0 +1,96 @@ +/* $Id$ */ + +#ifndef OLDPOOL_H +#define OLDPOOL_H + +typedef struct OldMemoryPool OldMemoryPool; + +/* The function that is called after a new block is added + start_item is the first item of the new made block */ +typedef void OldMemoryPoolNewBlock(uint start_item); +/* The function that is called before a block is cleaned up */ +typedef void OldMemoryPoolCleanBlock(uint start_item, uint end_item); + +/** + * Stuff for dynamic vehicles. Use the wrappers to access the OldMemoryPool + * please try to avoid manual calls! + */ +struct OldMemoryPool { + const char* const name; ///< Name of the pool (just for debugging) + + const uint max_blocks; ///< The max amount of blocks this pool can have + const uint block_size_bits; ///< The size of each block in bits + const uint item_size; ///< How many bytes one block is + + /// Pointer to a function that is called after a new block is added + OldMemoryPoolNewBlock *new_block_proc; + /// Pointer to a function that is called to clean a block + OldMemoryPoolCleanBlock *clean_block_proc; + + uint current_blocks; ///< How many blocks we have in our pool + uint total_items; ///< How many items we now have in this pool + + byte **blocks; ///< An array of blocks (one block hold all the items) +}; + +/** + * Those are the wrappers: + * CleanPool cleans the pool up, but you can use AddBlockToPool directly again + * (no need to call CreatePool!) + * AddBlockToPool adds 1 more block to the pool. Returns false if there is no + * more room + */ +void CleanPool(OldMemoryPool *array); +bool AddBlockToPool(OldMemoryPool *array); + +/** + * Adds blocks to the pool if needed (and possible) till index fits inside the pool + * + * @return Returns false if adding failed + */ +bool AddBlockIfNeeded(OldMemoryPool *array, uint index); + + +#define OLD_POOL_ENUM(name, type, block_size_bits, max_blocks) \ + enum { \ + name##_POOL_BLOCK_SIZE_BITS = block_size_bits, \ + name##_POOL_MAX_BLOCKS = max_blocks \ + }; + + +#define OLD_POOL_ACCESSORS(name, type) \ + static inline type* Get##name(uint index) \ + { \ + assert(index < _##name##_pool.total_items); \ + return (type*)( \ + _##name##_pool.blocks[index >> name##_POOL_BLOCK_SIZE_BITS] + \ + (index & ((1 << name##_POOL_BLOCK_SIZE_BITS) - 1)) * sizeof(type) \ + ); \ + } \ +\ + static inline uint Get##name##PoolSize(void) \ + { \ + return _##name##_pool.total_items; \ + } + + +#define DECLARE_OLD_POOL(name, type, block_size_bits, max_blocks) \ + OLD_POOL_ENUM(name, type, block_size_bits, max_blocks) \ + extern OldMemoryPool _##name##_pool; \ + OLD_POOL_ACCESSORS(name, type) + + +#define DEFINE_OLD_POOL(name, type, new_block_proc, clean_block_proc) \ + OldMemoryPool _##name##_pool = { \ + #name, name##_POOL_MAX_BLOCKS, name##_POOL_BLOCK_SIZE_BITS, sizeof(type), \ + new_block_proc, clean_block_proc, \ + 0, 0, NULL \ + }; + + +#define STATIC_OLD_POOL(name, type, block_size_bits, max_blocks, new_block_proc, clean_block_proc) \ + OLD_POOL_ENUM(name, type, block_size_bits, max_blocks) \ + static DEFINE_OLD_POOL(name, type, new_block_proc, clean_block_proc) \ + OLD_POOL_ACCESSORS(name, type) + +#endif /* OLDPOOL_H */ |