Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutoriallevel2/src/external/bullet/LinearMath/btPoolAllocator.h @ 8740

Last change on this file since 8740 was 8351, checked in by rgrieder, 14 years ago

Merged kicklib2 branch back to trunk (includes former branches ois_update, mac_osx and kicklib).

Notes for updating

Linux:
You don't need an extra package for CEGUILua and Tolua, it's already shipped with CEGUI.
However you do need to make sure that the OgreRenderer is installed too with CEGUI 0.7 (may be a separate package).
Also, Orxonox now recognises if you install the CgProgramManager (a separate package available on newer Ubuntu on Debian systems).

Windows:
Download the new dependency packages versioned 6.0 and use these. If you have problems with that or if you don't like the in game console problem mentioned below, you can download the new 4.3 version of the packages (only available for Visual Studio 2005/2008).

Key new features:

  • *Support for Mac OS X*
  • Visual Studio 2010 support
  • Bullet library update to 2.77
  • OIS library update to 1.3
  • Support for CEGUI 0.7 —> Support for Arch Linux and even SuSE
  • Improved install target
  • Compiles now with GCC 4.6
  • Ogre Cg Shader plugin activated for Linux if available
  • And of course lots of bug fixes

There are also some regressions:

  • No support for CEGUI 0.5, Ogre 1.4 and boost 1.35 - 1.39 any more
  • In game console is not working in main menu for CEGUI 0.7
  • Tolua (just the C lib, not the application) and CEGUILua libraries are no longer in our repository. —> You will need to get these as well when compiling Orxonox
  • And of course lots of new bugs we don't yet know about
  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1/*
2Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans  http://continuousphysics.com/Bullet/
3
4This software is provided 'as-is', without any express or implied warranty.
5In no event will the authors be held liable for any damages arising from the use of this software.
6Permission is granted to anyone to use this software for any purpose,
7including commercial applications, and to alter it and redistribute it freely,
8subject to the following restrictions:
9
101. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
112. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
123. This notice may not be removed or altered from any source distribution.
13*/
14
15
16#ifndef _BT_POOL_ALLOCATOR_H
17#define _BT_POOL_ALLOCATOR_H
18
19#include "btScalar.h"
20#include "btAlignedAllocator.h"
21
22///The btPoolAllocator class allows to efficiently allocate a large pool of objects, instead of dynamically allocating them separately.
23class btPoolAllocator
24{
25        int                             m_elemSize;
26        int                             m_maxElements;
27        int                             m_freeCount;
28        void*                   m_firstFree;
29        unsigned char*  m_pool;
30
31public:
32
33        btPoolAllocator(int elemSize, int maxElements)
34                :m_elemSize(elemSize),
35                m_maxElements(maxElements)
36        {
37                m_pool = (unsigned char*) btAlignedAlloc( static_cast<unsigned int>(m_elemSize*m_maxElements),16);
38
39                unsigned char* p = m_pool;
40        m_firstFree = p;
41        m_freeCount = m_maxElements;
42        int count = m_maxElements;
43        while (--count) {
44            *(void**)p = (p + m_elemSize);
45            p += m_elemSize;
46        }
47        *(void**)p = 0;
48    }
49
50        ~btPoolAllocator()
51        {
52                btAlignedFree( m_pool);
53        }
54
55        int     getFreeCount() const
56        {
57                return m_freeCount;
58        }
59
60        int getUsedCount() const
61        {
62                return m_maxElements - m_freeCount;
63        }
64
65        void*   allocate(int size)
66        {
67                // release mode fix
68                (void)size;
69                btAssert(!size || size<=m_elemSize);
70                btAssert(m_freeCount>0);
71        void* result = m_firstFree;
72        m_firstFree = *(void**)m_firstFree;
73        --m_freeCount;
74        return result;
75        }
76
77        bool validPtr(void* ptr)
78        {
79                if (ptr) {
80                        if (((unsigned char*)ptr >= m_pool && (unsigned char*)ptr < m_pool + m_maxElements * m_elemSize))
81                        {
82                                return true;
83                        }
84                }
85                return false;
86        }
87
88        void    freeMemory(void* ptr)
89        {
90                 if (ptr) {
91            btAssert((unsigned char*)ptr >= m_pool && (unsigned char*)ptr < m_pool + m_maxElements * m_elemSize);
92
93            *(void**)ptr = m_firstFree;
94            m_firstFree = ptr;
95            ++m_freeCount;
96        }
97        }
98
99        int     getElementSize() const
100        {
101                return m_elemSize;
102        }
103
104        unsigned char*  getPoolAddress()
105        {
106                return m_pool;
107        }
108
109        const unsigned char*    getPoolAddress() const
110        {
111                return m_pool;
112        }
113
114};
115
116#endif //_BT_POOL_ALLOCATOR_H
Note: See TracBrowser for help on using the repository browser.