mirror of https://github.com/axmolengine/axmol.git
Merge pull request #3461 from dumganhar/iss2650-remove-typeinfo
closed #2650: Remove ccTypeInfo since we could get the hash value from typeid(T).hash_code() if using c++11.
This commit is contained in:
commit
b746bda738
|
@ -42,26 +42,6 @@ THE SOFTWARE.
|
||||||
|
|
||||||
namespace CocosDenshion {
|
namespace CocosDenshion {
|
||||||
|
|
||||||
class TypeInfo
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual long getClassTypeInfo() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline unsigned int getHashCodeByString(const char *key)
|
|
||||||
{
|
|
||||||
unsigned int len = strlen(key);
|
|
||||||
const char *end=key+len;
|
|
||||||
unsigned int hash;
|
|
||||||
|
|
||||||
for (hash = 0; key < end; key++)
|
|
||||||
{
|
|
||||||
hash *= 16777619;
|
|
||||||
hash ^= (unsigned int) (unsigned char) toupper(*key);
|
|
||||||
}
|
|
||||||
return (hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@class SimpleAudioEngine
|
@class SimpleAudioEngine
|
||||||
@brief Offers a VERY simple interface to play background music & sound effects.
|
@brief Offers a VERY simple interface to play background music & sound effects.
|
||||||
|
@ -69,7 +49,7 @@ static inline unsigned int getHashCodeByString(const char *key)
|
||||||
to release allocated resources.
|
to release allocated resources.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class EXPORT_DLL SimpleAudioEngine : public TypeInfo
|
class EXPORT_DLL SimpleAudioEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -90,10 +70,6 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual long getClassTypeInfo() {
|
|
||||||
return getHashCodeByString(typeid(CocosDenshion::SimpleAudioEngine).name());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Preload background music
|
@brief Preload background music
|
||||||
@param pszFilePath The path of the background music file.
|
@param pszFilePath The path of the background music file.
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
b7815826ba065f201f8241cc2f4ce8c18973969d
|
530264983c51672ffb213e87cbf1a2743867630d
|
|
@ -36,7 +36,6 @@ THE SOFTWARE.
|
||||||
#include "CCGL.h"
|
#include "CCGL.h"
|
||||||
#include "kazmath/mat4.h"
|
#include "kazmath/mat4.h"
|
||||||
#include "label_nodes/CCLabelAtlas.h"
|
#include "label_nodes/CCLabelAtlas.h"
|
||||||
#include "ccTypeInfo.h"
|
|
||||||
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
@ -79,7 +78,7 @@ and when to execute the Scenes.
|
||||||
- GL_COLOR_ARRAY is enabled
|
- GL_COLOR_ARRAY is enabled
|
||||||
- GL_TEXTURE_COORD_ARRAY is enabled
|
- GL_TEXTURE_COORD_ARRAY is enabled
|
||||||
*/
|
*/
|
||||||
class CC_DLL Director : public Object, public TypeInfo
|
class CC_DLL Director : public Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** @typedef ccDirectorProjection
|
/** @typedef ccDirectorProjection
|
||||||
|
@ -109,10 +108,6 @@ public:
|
||||||
Director(void);
|
Director(void);
|
||||||
virtual ~Director(void);
|
virtual ~Director(void);
|
||||||
virtual bool init(void);
|
virtual bool init(void);
|
||||||
virtual long getClassTypeInfo() {
|
|
||||||
static const long id = cocos2d::getHashCodeByString(typeid(cocos2d::Director).name());
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// attribute
|
// attribute
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ THE SOFTWARE.
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "CCStdC.h"
|
#include "CCStdC.h"
|
||||||
#include "ccTypeInfo.h"
|
|
||||||
#include "CCAction.h"
|
#include "CCAction.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
@ -297,7 +296,7 @@ protected:
|
||||||
@brief Calls a 'callback' with the node as the first argument
|
@brief Calls a 'callback' with the node as the first argument
|
||||||
N means Node
|
N means Node
|
||||||
*/
|
*/
|
||||||
class CC_DLL CallFuncN : public CallFunc, public TypeInfo
|
class CC_DLL CallFuncN : public CallFunc
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** creates the action with the callback of type std::function<void()>.
|
/** creates the action with the callback of type std::function<void()>.
|
||||||
|
@ -325,11 +324,6 @@ public:
|
||||||
*/
|
*/
|
||||||
CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Object* pSelectorTarget, SEL_CallFuncN selector);
|
CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Object* pSelectorTarget, SEL_CallFuncN selector);
|
||||||
|
|
||||||
virtual long getClassTypeInfo() {
|
|
||||||
static const long id = cocos2d::getHashCodeByString(typeid(cocos2d::CallFunc).name());
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Overrides
|
// Overrides
|
||||||
//
|
//
|
||||||
|
@ -353,11 +347,6 @@ public:
|
||||||
/** creates the action with the callback and the data to pass as an argument */
|
/** creates the action with the callback and the data to pass as an argument */
|
||||||
CC_DEPRECATED_ATTRIBUTE static __CCCallFuncND * create(Object* selectorTarget, SEL_CallFuncND selector, void* d);
|
CC_DEPRECATED_ATTRIBUTE static __CCCallFuncND * create(Object* selectorTarget, SEL_CallFuncND selector, void* d);
|
||||||
|
|
||||||
virtual long getClassTypeInfo() {
|
|
||||||
static const long id = cocos2d::getHashCodeByString(typeid(cocos2d::CallFunc).name());
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** initializes the action with the callback and the data to pass as an argument */
|
/** initializes the action with the callback and the data to pass as an argument */
|
||||||
bool initWithTarget(Object* selectorTarget, SEL_CallFuncND selector, void* d);
|
bool initWithTarget(Object* selectorTarget, SEL_CallFuncND selector, void* d);
|
||||||
|
@ -382,7 +371,7 @@ protected:
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class CC_DLL __CCCallFuncO : public CallFunc, public TypeInfo
|
class CC_DLL __CCCallFuncO : public CallFunc
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** creates the action with the callback
|
/** creates the action with the callback
|
||||||
|
@ -394,11 +383,6 @@ public:
|
||||||
__CCCallFuncO();
|
__CCCallFuncO();
|
||||||
virtual ~__CCCallFuncO();
|
virtual ~__CCCallFuncO();
|
||||||
|
|
||||||
virtual long getClassTypeInfo() {
|
|
||||||
static const long id = cocos2d::getHashCodeByString(typeid(cocos2d::CallFunc).name());
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** initializes the action with the callback
|
/** initializes the action with the callback
|
||||||
|
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2012 cocos2d-x.org
|
|
||||||
|
|
||||||
http://www.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 cocos2dx_ccTypeInfo_h
|
|
||||||
#define cocos2dx_ccTypeInfo_h
|
|
||||||
|
|
||||||
#include "platform/CCPlatformMacros.h"
|
|
||||||
|
|
||||||
#include <typeinfo>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
|
||||||
|
|
||||||
class TypeInfo
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual long getClassTypeInfo() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline unsigned int getHashCodeByString(const char *key)
|
|
||||||
{
|
|
||||||
size_t len = strlen(key);
|
|
||||||
const char *end=key+len;
|
|
||||||
unsigned int hash;
|
|
||||||
|
|
||||||
for (hash = 0; key < end; key++)
|
|
||||||
{
|
|
||||||
hash *= 16777619;
|
|
||||||
hash ^= (unsigned int) (unsigned char) toupper(*key);
|
|
||||||
}
|
|
||||||
return (hash);
|
|
||||||
}
|
|
||||||
NS_CC_END
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -29,7 +29,6 @@ THE SOFTWARE.
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "CCPlatformMacros.h"
|
#include "CCPlatformMacros.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "ccTypeInfo.h"
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -41,20 +40,11 @@ class Array;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//! @brief Helper class to handle file operations
|
//! @brief Helper class to handle file operations
|
||||||
class CC_DLL FileUtils : public TypeInfo
|
class CC_DLL FileUtils
|
||||||
{
|
{
|
||||||
friend class Array;
|
friend class Array;
|
||||||
friend class Dictionary;
|
friend class Dictionary;
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* Returns an unique ID for this class.
|
|
||||||
* @note It's only used for JSBindings now.
|
|
||||||
* @return The unique ID for this class.
|
|
||||||
*/
|
|
||||||
virtual long getClassTypeInfo() {
|
|
||||||
static const long id = cocos2d::getHashCodeByString(typeid(cocos2d::FileUtils).name());
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the instance of FileUtils.
|
* Gets the instance of FileUtils.
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include "platform/CCFileUtils.h"
|
#include "platform/CCFileUtils.h"
|
||||||
#include "platform/CCPlatformMacros.h"
|
#include "platform/CCPlatformMacros.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "ccTypeInfo.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include "platform/CCFileUtils.h"
|
#include "platform/CCFileUtils.h"
|
||||||
#include "platform/CCPlatformMacros.h"
|
#include "platform/CCPlatformMacros.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "ccTypeInfo.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "CCPlatformMacros.h"
|
#include "CCPlatformMacros.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "ccTypeInfo.h"
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include "platform/CCFileUtils.h"
|
#include "platform/CCFileUtils.h"
|
||||||
#include "platform/CCPlatformMacros.h"
|
#include "platform/CCPlatformMacros.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "ccTypeInfo.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "CCPlatformMacros.h"
|
#include "CCPlatformMacros.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "ccTypeInfo.h"
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#include "platform/CCPlatformMacros.h"
|
#include "platform/CCPlatformMacros.h"
|
||||||
#include "platform/CCCommon.h"
|
#include "platform/CCCommon.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "ccTypeInfo.h"
|
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
|
@ -29,7 +29,6 @@ THE SOFTWARE.
|
||||||
#include "platform/CCFileUtils.h"
|
#include "platform/CCFileUtils.h"
|
||||||
#include "platform/CCPlatformMacros.h"
|
#include "platform/CCPlatformMacros.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "ccTypeInfo.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include "platform/CCFileUtils.h"
|
#include "platform/CCFileUtils.h"
|
||||||
#include "platform/CCPlatformMacros.h"
|
#include "platform/CCPlatformMacros.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "ccTypeInfo.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
|
@ -40,15 +40,10 @@ extern callfuncTarget_proxy_t *_callfuncTarget_native_ht;
|
||||||
template <class T>
|
template <class T>
|
||||||
inline js_type_class_t *js_get_type_from_native(T* native_obj) {
|
inline js_type_class_t *js_get_type_from_native(T* native_obj) {
|
||||||
js_type_class_t *typeProxy;
|
js_type_class_t *typeProxy;
|
||||||
long typeId = cocos2d::getHashCodeByString(typeid(*native_obj).name());
|
long typeId = typeid(*native_obj).hash_code();
|
||||||
HASH_FIND_INT(_js_global_type_ht, &typeId, typeProxy);
|
HASH_FIND_INT(_js_global_type_ht, &typeId, typeProxy);
|
||||||
if (!typeProxy) {
|
if (!typeProxy) {
|
||||||
cocos2d::TypeInfo *typeInfo = dynamic_cast<cocos2d::TypeInfo *>(native_obj);
|
typeId = typeid(T).hash_code();
|
||||||
if (typeInfo) {
|
|
||||||
typeId = typeInfo->getClassTypeInfo();
|
|
||||||
} else {
|
|
||||||
typeId = cocos2d::getHashCodeByString(typeid(T).name());
|
|
||||||
}
|
|
||||||
HASH_FIND_INT(_js_global_type_ht, &typeId, typeProxy);
|
HASH_FIND_INT(_js_global_type_ht, &typeId, typeProxy);
|
||||||
}
|
}
|
||||||
return typeProxy;
|
return typeProxy;
|
||||||
|
|
|
@ -37,7 +37,7 @@ class TypeTest
|
||||||
But the return string from typeid(*native_obj).name() is the same string, so we must convert the string to hash id to make sure we can get unique id.
|
But the return string from typeid(*native_obj).name() is the same string, so we must convert the string to hash id to make sure we can get unique id.
|
||||||
*/
|
*/
|
||||||
// static const long id = reinterpret_cast<long>(typeid( DERIVED ).name());
|
// static const long id = reinterpret_cast<long>(typeid( DERIVED ).name());
|
||||||
static const long id = cocos2d::getHashCodeByString(typeid( DERIVED ).name());
|
static const long id = typeid( DERIVED ).hash_code();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue