fix warning

This commit is contained in:
halx99 2020-08-25 14:47:51 +08:00
parent 0545a471cb
commit feb4e1783a
5 changed files with 18 additions and 42 deletions

View File

@ -20,7 +20,7 @@ int store_dds_uncompressed_image(const astc_codec_image* img, const char* filena
int store_tga_image(const astc_codec_image* img, const char* tga_filename, int bitness) { return 0; }
extern int ASTC_INIT = 0;
static int ASTC_INIT = 0;
uint8_t float2byte(float f) {

View File

@ -23,8 +23,8 @@ 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 __CC_UTILS_H__
#define __CC_UTILS_H__
#ifndef __SUPPORT_CC_UTILS_H__
#define __SUPPORT_CC_UTILS_H__
#include <vector>
#include <string>
@ -153,8 +153,8 @@ namespace utils
* @return Returns found node or nullptr with specified type 'T'
*/
template<typename T>
inline T findChild(Node* levelRoot, const std::string& name)
template<typename T> inline
T findChild(Node* levelRoot, const std::string& name)
{
return dynamic_cast<T>(findChild(levelRoot, name));
}
@ -164,46 +164,12 @@ namespace utils
* @return Returns found node or nullptr with specified type 'T'
*/
template<typename T>
inline T findChild(Node* levelRoot, int tag)
template<typename T> inline
T findChild(Node* levelRoot, int tag)
{
return dynamic_cast<T>(findChild(levelRoot, tag));
}
/**
* Create a Game Object instance, like CREATE_FUNC, but more powerful
* @return Returns a autorelease game object
* @limition: the init function finit must be public
*/
template<typename T, typename F, typename...Ts>
inline T* createInstance(F&& finit, Ts&&... args)
{
T* pRet = new(std::nothrow) T();
if (pRet && std::mem_fn(finit)(pRet, std::forward<Ts>(args)...)) {
pRet->autorelease();
return pRet;
}
else
{
delete pRet;
pRet = nullptr;
return nullptr;
}
}
/**
* Create a Game Object instance with 'bool T::init()' function, like CREATE_FUNC, but more powerful
* @return Returns a autorelease game object
* @limition: the init function finit must be public
*/
template<typename T>
inline T* createInstance()
{
return ::cocos2d::utils::createInstance<T>(&T::init);
}
/**
* Gets the md5 hash for the given file.
* @param filename The file to calculate md5 hash.

View File

@ -108,7 +108,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
register_all_packages();
// create a scene. it's an autorelease object
auto scene = utils::createInstance<HelloWorld>();
auto scene = HelloWorld::createScene();
// run
director->runWithScene(scene);

View File

@ -26,6 +26,11 @@
USING_NS_CC;
Scene* HelloWorld::createScene()
{
return HelloWorld::create();
}
// Print useful error message instead of segfaulting when files are not there.
static void problemLoading(const char* filename)
{

View File

@ -30,10 +30,15 @@
class HelloWorld : public cocos2d::Scene
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
// a selector callback
void menuCloseCallback(cocos2d::Ref* pSender);
// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);
};
#endif // __HELLOWORLD_SCENE_H__