Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove CppReflection, add CCBCustomClass and CCBCustomClassFactory to…
… implement reflection, leave some jobs to class HelloCocosBuilder: public CCBCustomClass. The approach is not so tricky, much easier to understand now.
- Loading branch information
Showing
12 changed files
with
251 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/**************************************************************************** | ||
Copyright (c) 2012 cocos2d-x.org | ||
Copyright (c) 2012 XiaoLong Zhang, Chukong Inc. | ||
http://www.cocos2d-x.org | ||
|
@@ -23,30 +22,50 @@ | |
THE SOFTWARE. | ||
****************************************************************************/ | ||
|
||
#ifndef cocos2dXReflection_CClassFactory_h | ||
#define cocos2dXReflection_CClassFactory_h | ||
#ifndef _CC_CUSTOM_CLASS_H_ | ||
#define _CC_CUSTOM_CLASS_H_ | ||
|
||
#include <string> | ||
#include <map> | ||
#include <iostream> | ||
#include "cocos2d.h" | ||
#include <map> | ||
|
||
typedef void* (*createClass)(void); | ||
NS_CC_EXT_BEGIN | ||
|
||
class CCBCustomClass; | ||
typedef CCBCustomClass* (*FUNC_CUSTON_CLASS_CREATOR)(void); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
walzer
Author
Contributor
|
||
typedef std::map<std::string, FUNC_CUSTON_CLASS_CREATOR> CUSTOM_CLASS_MAP; | ||
|
||
class CClassFactory | ||
// This is a simple reflection implement for custom classes in CocosBuilder | ||
class CCBCustomClass : public cocos2d::CCNode | ||
{ | ||
public: | ||
CClassFactory() ; | ||
public: | ||
static CCBCustomClass* createInstance() { return NULL; }; // cannot create virual class here | ||
|
||
CCBCustomClass() {}; | ||
virtual ~CCBCustomClass() {}; | ||
|
||
void* getClassByName(std::string className); | ||
// implement 3 pure virtual methods inherited from CCBCustomClass | ||
virtual bool callbackSetChildren(const char* name, cocos2d::CCObject* node) = 0; | ||
virtual void callbackInvokeMethods(cocos2d::CCNode *sender) = 0; | ||
virtual void callbackAfterCCBLoaded() = 0; | ||
}; | ||
|
||
void registClass(std::string name, createClass method) ; | ||
|
||
|
||
class CCBCustomClassFactory | ||
{ | ||
public: | ||
CCBCustomClassFactory(); | ||
virtual ~CCBCustomClassFactory(); | ||
|
||
static CClassFactory& sharedClassFactory() ; | ||
static CCBCustomClassFactory* sharedFactory(); | ||
|
||
bool registCustomClass(const char* name, FUNC_CUSTON_CLASS_CREATOR pfnCreator); | ||
CCBCustomClass* createCustomClassWithName(const char* name); | ||
|
||
private: | ||
std::map<std::string, createClass> m_classMap ; | ||
} ; | ||
protected: | ||
CUSTOM_CLASS_MAP* m_pCustomCreatorsMap; | ||
}; | ||
|
||
NS_CC_EXT_END; | ||
|
||
#endif | ||
#endif // _CC_CUSTOM_CLASS_H_ |
Oops, something went wrong.
Typo:
...FUNC_CUSTON_CLASS_CREATOR...
Should be:
...FUNC_CUSTOM_CLASS_CREATOR...