Files
@ r11338:445c71ff8f7f
Branch filter:
Location: cpp/openttd-patchpack/source/src/oldpool_func.h - annotation
r11338:445c71ff8f7f
1.8 KiB
text/x-c
(svn r15693) -Fix (r15691): The msvc project files weren't updated to include luxembourgish.
r8847:d0a2cc468a55 r8847:d0a2cc468a55 r9111:983de9c5a848 r9111:983de9c5a848 r8847:d0a2cc468a55 r9111:983de9c5a848 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r10636:3fa2314ac8e6 r10636:3fa2314ac8e6 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r9661:fdc34176f0ca r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r10636:3fa2314ac8e6 r10636:3fa2314ac8e6 r8847:d0a2cc468a55 r8847:d0a2cc468a55 r9038:786366c52a39 r9038:786366c52a39 r9038:786366c52a39 r9038:786366c52a39 r10304:5c0367102ee6 r10304:5c0367102ee6 r9038:786366c52a39 r10304:5c0367102ee6 r9038:786366c52a39 r9038:786366c52a39 r10635:87b713d8a41d r9038:786366c52a39 r10304:5c0367102ee6 r10304:5c0367102ee6 r9038:786366c52a39 r9038:786366c52a39 r10304:5c0367102ee6 r10304:5c0367102ee6 r9038:786366c52a39 r10635:87b713d8a41d r9038:786366c52a39 r9038:786366c52a39 r9038:786366c52a39 r9038:786366c52a39 r8847:d0a2cc468a55 | /* $Id$ */
/** @file oldpool_func.h Functions related to the old pool. */
#ifndef OLDPOOL_FUNC_H
#define OLDPOOL_FUNC_H
#include "oldpool.h"
/**
* Allocate a pool item; possibly allocate a new block in the pool.
* @param first the first pool item to start searching
* @pre first <= Tpool->GetSize()
* @pre CanAllocateItem()
* @return the allocated pool item
*/
template<typename T, typename Tid, OldMemoryPool<T> *Tpool> T *PoolItem<T, Tid, Tpool>::AllocateSafeRaw(uint &first)
{
uint last_minus_one = Tpool->GetSize() - 1;
for (T *t = Tpool->Get(first); t != NULL; t = ((uint)t->index < last_minus_one) ? Tpool->Get(t->index + 1U) : NULL) {
if (!t->IsValid()) {
first = t->index;
Tid index = t->index;
memset(t, 0, Tpool->item_size);
t->index = index;
return t;
}
}
/* Check if we can add a block to the pool */
if (Tpool->AddBlockToPool()) return AllocateRaw(first);
/* One should *ALWAYS* be sure to have enough space before making vehicles! */
NOT_REACHED();
}
/**
* Check whether we can allocate an item in this pool. This to prevent the
* need to actually construct the object and then destructing it again,
* which could be *very* costly.
* @param count the number of items to create
* @return true if and only if at least count items can be allocated.
*/
template<typename T, typename Tid, OldMemoryPool<T> *Tpool> bool PoolItem<T, Tid, Tpool>::CanAllocateItem(uint count)
{
uint last_minus_one = Tpool->GetSize() - 1;
uint orig_count = count;
for (T *t = Tpool->Get(Tpool->first_free_index); count > 0 && t != NULL; t = ((uint)t->index < last_minus_one) ? Tpool->Get(t->index + 1U) : NULL) {
if (!t->IsValid()) count--;
}
if (count == 0) return true;
/* Check if we can add a block to the pool */
if (Tpool->AddBlockToPool()) return CanAllocateItem(orig_count);
return false;
}
#endif /* OLDPOOL_FUNC_H */
|