mirror of https://github.com/axmolengine/axmol.git
issue #6:issue #6
This commit is contained in:
parent
6d9c6c926e
commit
afffd75d0e
|
@ -0,0 +1,65 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __NS_AUTO_RELEASE_POOL_H__
|
||||
#define __NS_AUTO_RELEASE_POOL_H__
|
||||
|
||||
#include "NSObject.h"
|
||||
#include <vector>
|
||||
|
||||
class NSAutoreleasePool : public NSObject
|
||||
{
|
||||
public:
|
||||
NSAutoreleasePool(void);
|
||||
|
||||
void addObject(NSObject *pObject);
|
||||
void removeObject(NSObject *pObject);
|
||||
|
||||
void clear(void);
|
||||
private:
|
||||
std::vector<NSObject *> m_managedObjectArray;
|
||||
};
|
||||
|
||||
class NSPoolManager
|
||||
{
|
||||
public:
|
||||
|
||||
~NSPoolManager();
|
||||
|
||||
void finalize(void);
|
||||
void push(void);
|
||||
void pop(void);
|
||||
|
||||
void removeObject(NSObject *pObject);
|
||||
void addObject(NSObject *pObject);
|
||||
|
||||
public:
|
||||
static NSPoolManager* getInstance();
|
||||
|
||||
private:
|
||||
NSPoolManager();
|
||||
|
||||
private:
|
||||
static NSPoolManager *m_pPoolManager;
|
||||
}
|
||||
|
||||
#endif //__NS_AUTO_RELEASE_POOL_H__
|
|
@ -0,0 +1,21 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
|
@ -0,0 +1,29 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __COCOA_NS_MUTATLE_ARRAY_H__
|
||||
#define __COCOA_NS_MUTATLE_ARRAY_H__
|
||||
|
||||
#include "NSObject.h"
|
||||
#include <vector>
|
||||
|
||||
#endif // __COCOA_NS_MUTATLE_ARRAY_H__
|
|
@ -33,8 +33,67 @@ NSObject* CCCopying::copyWithZone(NSZone *pZone)
|
|||
|
||||
NSObject::NSObject(void)
|
||||
{
|
||||
static UINT uObjectCount = 0;
|
||||
|
||||
m_uID = ++uObjectCount;
|
||||
|
||||
// when the object is created, the refrence count of it is 1
|
||||
m_uRefrence = 1;
|
||||
m_bManaged = FALSE;
|
||||
}
|
||||
|
||||
NSObject::~NSObject(void)
|
||||
{
|
||||
// if the object is managed, we should remove it
|
||||
// from pool manager
|
||||
if (m_bManaged)
|
||||
{
|
||||
// todo: remove from pool manager
|
||||
}
|
||||
}
|
||||
|
||||
NSObject* NSObject::copy()
|
||||
{
|
||||
return copyWithZone(NULL);
|
||||
}
|
||||
|
||||
void NSObject::release(void)
|
||||
{
|
||||
assert(m_uRefrence > 0);
|
||||
--m_uRefrence;
|
||||
|
||||
if (m_uRefrence == 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
void NSObject::retain(void)
|
||||
{
|
||||
assert(m_uRefrence > 0);
|
||||
|
||||
++m_uRefrence;
|
||||
}
|
||||
|
||||
NSObject* NSObject::autorelease(void)
|
||||
{
|
||||
// todo add to pool manager
|
||||
|
||||
m_bManaged = TRUE;
|
||||
return this;
|
||||
}
|
||||
|
||||
BOOL NSObject::isSingleRefrence(void)
|
||||
{
|
||||
return m_uRefrence == 1;
|
||||
}
|
||||
|
||||
UINT32 NSObject::retainCount(void)
|
||||
{
|
||||
return m_uRefrence;
|
||||
}
|
||||
|
||||
BOOL NSObject::isEqual(const NSObject *pObject)
|
||||
{
|
||||
return this == pObject;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue