mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-01 03:21:41 +00:00
9ae077c033
* use c++11 std::align from <memory> * for Ubuntu, use gcc5 instead of 4.8 * use travis to set gcc to 5 eval and sudo * use eval in .travis.yml * use gcc-8 * replace precise with trusty llvm toolchain, because we have been using trusty for awhile now * push things to matrix, so we can support multiple releases if we want * we should not be allowing for failures, we are ready to start trusting clang and its analyzer * scan-build was pushed to another package * use gcc-8 still but wrap in scan-build * travis.yml cleanup, have output of scripts go to stdout, make search for substring a regex use double [] fix missing , use bash to use regex black spaces matter * set human readable names for our various builds, split out our static analysis between openmw and openmw-cs * test if not set, then set otherwise ignore * use quotes * do not eval it, set it in travis env * no more && * what does clang7 have to say? * use sourceline for now * use clang-7 instead of clang-7.0 * yes, llvm-toolchain-trusty-7 not llvm-toolchain-trusty-7.0 * for static analysis, openmw is compiled and checked on its own while openmw-cs is build with all the rest. this might change in the future. and actually do it the other way around
66 lines
1.8 KiB
C++
66 lines
1.8 KiB
C++
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTTEMPALLOCATOR_H
|
|
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTTEMPALLOCATOR_H
|
|
|
|
#include "recastallocutils.hpp"
|
|
|
|
#include <cassert>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
namespace DetourNavigator
|
|
{
|
|
class RecastTempAllocator
|
|
{
|
|
public:
|
|
RecastTempAllocator(std::size_t capacity)
|
|
: mStack(capacity), mTop(mStack.data()), mPrev(nullptr)
|
|
{}
|
|
|
|
void* alloc(std::size_t size)
|
|
{
|
|
std::size_t space = mStack.size() - getUsedSize();
|
|
void* top = mTop;
|
|
const auto itemSize = 2 * sizeof(std::size_t) + size;
|
|
if (rcUnlikely(!std::align(sizeof(std::size_t), itemSize, top, space)))
|
|
return nullptr;
|
|
setTempPtrBufferType(top, BufferType_temp);
|
|
setTempPtrPrev(top, mPrev);
|
|
mTop = static_cast<char*>(top) + itemSize;
|
|
mPrev = static_cast<char*>(top);
|
|
return getTempPtrDataPtr(top);
|
|
}
|
|
|
|
void free(void* ptr)
|
|
{
|
|
if (rcUnlikely(!ptr))
|
|
return;
|
|
assert(BufferType_temp == getDataPtrBufferType(ptr));
|
|
if (!mPrev || getTempDataPtrStackPtr(ptr) != mPrev)
|
|
{
|
|
setDataPtrBufferType(ptr, BufferType_unused);
|
|
return;
|
|
}
|
|
mTop = getTempDataPtrStackPtr(ptr);
|
|
mPrev = getTempPtrPrev(mTop);
|
|
while (mPrev && BufferType_unused == getTempPtrBufferType(mPrev))
|
|
{
|
|
mTop = mPrev;
|
|
mPrev = getTempPtrPrev(mTop);
|
|
}
|
|
return;
|
|
}
|
|
|
|
private:
|
|
std::vector<char> mStack;
|
|
void* mTop;
|
|
void* mPrev;
|
|
|
|
std::size_t getUsedSize() const
|
|
{
|
|
return static_cast<std::size_t>(static_cast<char*>(mTop) - mStack.data());
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif
|