Merge branch 'master' of https://github.com/cocos2d/cocos2d-x into input2

Conflicts:
	cocos2dx/platform/wophone/CCApplication_wophone.h
	tests/tests/tests.h
This commit is contained in:
yangws 2011-05-10 16:09:26 +08:00
commit 21c8628e68
41 changed files with 766 additions and 50 deletions

View File

@ -75,4 +75,8 @@ bool HelloWorld::init()
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}

View File

@ -1 +1 @@
3300607858936d3cd32e8d541a02eb4464613808
b24c63ccf57b54f4c803ee0476d220f01225a535

View File

@ -77,6 +77,7 @@ support/CCArray.cpp \
support/CCProfiling.cpp \
support/CCPointExtension.cpp \
support/TransformUtils.cpp \
support/CCUserDefault.cpp \
support/base64.cpp \
support/ccUtils.cpp \
support/image_support/TGAlib.cpp \

View File

@ -46,6 +46,7 @@ THE SOFTWARE.
#include "CCGL.h"
#include "CCAnimationCache.h"
#include "CCTouch.h"
#include "CCUserDefault.h"
#if CC_ENABLE_PROFILERS
#include "support/CCProfiling.h"
@ -569,6 +570,7 @@ void CCDirector::purgeDirector()
CCActionManager::sharedManager()->purgeSharedManager();
CCScheduler::purgeSharedScheduler();
CCTextureCache::purgeSharedTextureCache();
CCUserDefault::purgeSharedUserDefault();
// OpenGL view
m_pobOpenGLView->release();

View File

@ -0,0 +1,71 @@
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
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 __SUPPORT_CCUSERDEFAULT_H__
#define __SUPPORT_CCUSERDEFAULT_H__
#include "CCPlatformMacros.h"
#include <string>
NS_CC_BEGIN;
class CC_DLL CCUserDefault
{
public:
~CCUserDefault();
// get value methods
bool getBoolForKey(const char* pKey);
int getIntegerForKey(const char* pKey);
float getFloatForKey(const char* pKey);
double getDoubleForKey(const char* pKey);
std::string getStringForKey(const char* pKey);
// set value methods
void setBoolForKey(const char* pKey, bool value);
void setIntegerForKey(const char* pKey, int value);
void setFloatForKey(const char* pKey, float value);
void setDoubleForKey(const char* pKey, double value);
void setStringForKey(const char* pKey, std::string value);
static CCUserDefault* sharedUserDefault();
static void purgeSharedUserDefault();
const static std::string& getXMLFilePath();
private:
CCUserDefault() {}
static bool createXMLFile();
static bool isXMLFileExist();
static void initXMLFilePath();
static CCUserDefault* m_spUserDefault;
static std::string m_sFilePath;
static bool m_sbIsFilePathInitialized;
};
NS_CC_END;
#endif // __SUPPORT_CCUSERDEFAULT_H__

View File

@ -41,8 +41,7 @@ THE SOFTWARE.
#include "CCProtocols.h"
#include "CCNode.h"
#include "CCDirector.h"
// #include "CCTouchDispatcher.h"
// #include "CCTouchDelegateProtocol.h"
#include "CCUserDefault.h"
#include "CCActionInstant.h"
#include "CCActionInterval.h"
#include "CCActionEase.h"

View File

@ -86,6 +86,12 @@ public:
*/
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName);
/**
@brief Get the writeable path
@return The path that can write/read file
*/
static std::string getWriteablePath();
/**
@brief Set/Get whether pop-up a message box when the image load failed
*/

View File

@ -340,5 +340,11 @@ bool CCFileUtils::getIsPopupNotify()
return s_bPopupNotify;
}
std::string CCFileUtils::getWriteablePath()
{
// fixed me, what path can airplay can write
return string("");
}
NS_CC_END;

View File

@ -104,4 +104,12 @@ int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out)
return 0;
}
string CCFileUtils::getWriteablePath()
{
// the path is: /data/data/ + package name
string dir("/data/data");
size_t length = s_strResourcePath.rfind(".") - s_strResourcePath.rfind("/");
return dir + s_strResourcePath.substr(s_strResourcePath.rfind("/"), length) + "/" ;
}
NS_CC_END;

View File

@ -337,6 +337,14 @@ namespace cocos2d {
{
return s_bPopupNotify;
}
std::string CCFileUtils::getWriteablePath()
{
// save to document folder
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory UTF8String];
}
}//namespace cocos2d

View File

@ -22,6 +22,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "windows.h"
using namespace std;
NS_CC_BEGIN;
// record the resource path
@ -159,4 +163,19 @@ void CCFileUtils::setRelativePath(const char* pszRelativePath)
CCAssert(0, "Have not implement!");
}
string CCFileUtils::getWriteablePath()
{
// return the path that the exe file saved in
char full_path[_MAX_PATH + 1];
::GetModuleFileNameA(NULL, full_path, _MAX_PATH + 1);
string ret((char*)full_path);
// remove xxx.exe
ret = ret.substr(0, ret.rfind("\\") + 1);
return ret;
}
NS_CC_END;

View File

@ -47,20 +47,26 @@ CCApplication::CCApplication()
Int32 nRet = SS_AppRequest_GetAppName(AppID, &nCmdType);
CC_BREAK_IF(nRet < 0);
TUChar AppPath[EOS_FILE_MAX_PATH] = {0};
char DataPath[EOS_FILE_MAX_PATH] = {0};
SS_GetApplicationPath(AppID, SS_APP_PATH_TYPE_CONST, AppPath);
TUString::StrUnicodeToStrUtf8((Char*) DataPath, AppPath);
#ifndef _TRANZDA_VM_
char *pszDriver = "";
#else
char *pszDriver = "D:/Work7";
#endif
// record the data path
TUChar AppPath[EOS_FILE_MAX_PATH] = {0};
char DataPath[EOS_FILE_MAX_PATH] = {0};
// get the const data path of the application and record it
SS_GetApplicationPath(AppID, SS_APP_PATH_TYPE_CONST, AppPath);
TUString::StrUnicodeToStrUtf8((Char*) DataPath, AppPath);
strcpy(m_AppDataPath, pszDriver);
strcat(m_AppDataPath, DataPath);
// get the writable data path of the application and record it
SS_GetApplicationPath(AppID, SS_APP_PATH_TYPE_DATA, AppPath);
TUString::StrUnicodeToStrUtf8((Char*) DataPath, AppPath);
strcpy(m_AppWritablePath, pszDriver);
strcat(m_AppWritablePath, DataPath);
} while (0);
CC_ASSERT(! sm_pSharedApplication);
@ -184,6 +190,11 @@ const char* CCApplication::getAppDataPath()
return m_AppDataPath;
}
const char* CCApplication::getAppWritablePath()
{
return m_AppWritablePath;
}
void CCApplication::switchNotify(int nTurnOn)
{
bool bInBack = isInBackground();
@ -278,7 +289,7 @@ Int32 CCApplication::_OnAppIdle(MESSAGE_t * pMsg, UInt32 uData)
#endif
else
{
Sys_Sleep(0);
Sys_SchedYield();
}
Sys_PostMessage2(MESSAGE_PRIOR_LOWEST, &rThis.m_tMsg);
}

View File

@ -77,11 +77,18 @@ public:
/**
@brief Get the data path of the Application.
@return If the app is installed,the return value is the path of .so file.
else the return value is "/NEWPLUS/TG3/APP/"
@return If the app is installed,the return value is the "Const" path of the application,
else the return value is "/NEWPLUS/TG3/ConstData/"
*/
const char* getAppDataPath();
/**
@brief Get the writable path for the Application.
@return If the app is installed,the return value is the "Data" path of the application.
else the return value is "/NEWPLUS/TG3/TDA_DATA/Data/Data/"
*/
const char* getAppWritablePath();
void switchNotify(int nTurnOn);
/**
@ -103,6 +110,7 @@ protected:
bool m_bNeedStop;
bool m_bInBackground;
char m_AppDataPath[EOS_FILE_MAX_PATH];
char m_AppWritablePath[EOS_FILE_MAX_PATH];
static CCApplication * sm_pSharedApplication;
static UInt32 sm_uDesignOrientation;

View File

@ -26,6 +26,10 @@ THE SOFTWARE.
#include <TG3.h>
#include "CCApplication.h"
#include <string>
using namespace std;
NS_CC_BEGIN;
// record the resource path
@ -250,4 +254,9 @@ void CCFileUtils::setRelativePath(const char* pszRelativePath)
CCAssert(0, "Have not implement!");
}
string CCFileUtils::getWriteablePath()
{
return string(CCApplication::sharedApplication().getAppWritablePath());
}
NS_CC_END;

View File

@ -627,6 +627,10 @@
RelativePath="..\include\ccTypes.h"
>
</File>
<File
RelativePath="..\include\CCUserDefault.h"
>
</File>
<File
RelativePath="..\include\CCZone.h"
>
@ -911,6 +915,10 @@
RelativePath="..\support\CCProfiling.h"
>
</File>
<File
RelativePath="..\support\CCUserDefault.cpp"
>
</File>
<File
RelativePath="..\support\ccUtils.cpp"
>

View File

@ -104,6 +104,7 @@ OBJECTS = \
$(OBJECTS_DIR)/CCArray.o \
$(OBJECTS_DIR)/CCPointExtension.o \
$(OBJECTS_DIR)/CCProfiling.o \
$(OBJECTS_DIR)/CCUserDefault.o \
$(OBJECTS_DIR)/ccUtils.o \
$(OBJECTS_DIR)/TransformUtils.o \
$(OBJECTS_DIR)/TGAlib.o \
@ -357,6 +358,9 @@ $(OBJECTS_DIR)/CCPointExtension.o : ../support/CCPointExtension.cpp
$(OBJECTS_DIR)/CCProfiling.o : ../support/CCProfiling.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCProfiling.o ../support/CCProfiling.cpp
$(OBJECTS_DIR)/CCUserDefault.o : ../support/CCUserDefault.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCUserDefault.o ../support/CCUserDefault.cpp
$(OBJECTS_DIR)/ccUtils.o : ../support/ccUtils.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/ccUtils.o ../support/ccUtils.cpp

View File

@ -588,6 +588,10 @@
RelativePath="..\include\ccTypes.h"
>
</File>
<File
RelativePath="..\include\CCUserDefault.h"
>
</File>
<File
RelativePath="..\include\CCZone.h"
>
@ -752,6 +756,10 @@
RelativePath="..\support\CCProfiling.h"
>
</File>
<File
RelativePath="..\support\CCUserDefault.cpp"
>
</File>
<File
RelativePath="..\support\ccUtils.cpp"
>

View File

@ -0,0 +1,367 @@
#include "CCUserDefault.h"
#include "platform/CCFileUtils.h"
#include <libxml/parser.h>
#include <libxml/tree.h>
// root name of xml
#define USERDEFAULT_ROOT_NAME "userDefaultRoot"
#define XML_FILE_NAME "UserDefault.xml"
using namespace std;
NS_CC_BEGIN;
/**
* define the functions here because we don't want to
* export xmlNodePtr and other types in "CCUserDefault.h"
*/
static xmlNodePtr getXMLNodeForKey(const char* pKey, xmlNodePtr *rootNode, xmlDocPtr *doc)
{
xmlNodePtr curNode = NULL;
// check the key value
if (! pKey)
{
return NULL;
}
do
{
// read doc
*doc = xmlReadFile(CCUserDefault::sharedUserDefault()->getXMLFilePath().c_str(), "utf-8", XML_PARSE_RECOVER);
if (NULL == *doc)
{
CCLOG("can not read xml file");
break;
}
// get root node
*rootNode = xmlDocGetRootElement(*doc);
if (NULL == *rootNode)
{
CCLOG("read root node error");
break;
}
// find the node
curNode = (*rootNode)->xmlChildrenNode;
while (NULL != curNode)
{
if (! xmlStrcmp(curNode->name, BAD_CAST pKey))
{
break;
}
curNode = curNode->next;
}
} while (0);
return curNode;
}
const char* getValueForKey(const char* pKey)
{
const char* ret = NULL;
xmlNodePtr rootNode;
xmlDocPtr doc;
xmlNodePtr node = getXMLNodeForKey(pKey, &rootNode, &doc);
// find the node
if (node)
{
ret = (const char*)xmlNodeGetContent(node);
}
// free doc
if (doc)
{
xmlFreeDoc(doc);
}
return ret;
}
void setValueForKey(const char* pKey, const char* pValue)
{
xmlNodePtr rootNode;
xmlDocPtr doc;
xmlNodePtr node;
// check the params
if (! pKey || ! pValue)
{
return;
}
// find the node
node = getXMLNodeForKey(pKey, &rootNode, &doc);
// if node exist, change the content
if (node)
{
xmlNodeSetContent(node, BAD_CAST pValue);
}
else
{
if (rootNode)
{
// the node doesn't exist, add a new one
// libxml in android donesn't support xmlNewTextChild, so use this approach
xmlNodePtr tmpNode = xmlNewNode(NULL, BAD_CAST pKey);
xmlNodePtr content = xmlNewText(BAD_CAST pValue);
xmlAddChild(rootNode, tmpNode);
xmlAddChild(tmpNode, content);
}
}
// save file and free doc
if (doc)
{
xmlSaveFile(CCUserDefault::sharedUserDefault()->getXMLFilePath().c_str(),doc);
xmlFreeDoc(doc);
}
}
/**
* implements of CCUserDefault
*/
CCUserDefault* CCUserDefault::m_spUserDefault = 0;
string CCUserDefault::m_sFilePath = string("");
bool CCUserDefault::m_sbIsFilePathInitialized = false;
/**
* If the user invoke delete CCUserDefault::sharedUserDefault(), should set m_spUserDefault
* to null to avoid error when he invoke CCUserDefault::sharedUserDefault() later.
*/
CCUserDefault::~CCUserDefault()
{
m_spUserDefault = NULL;
}
void CCUserDefault::purgeSharedUserDefault()
{
CC_SAFE_DELETE(m_spUserDefault);
m_spUserDefault = NULL;
}
bool CCUserDefault::getBoolForKey(const char* pKey)
{
const char* value = getValueForKey(pKey);
bool ret = false;
if (value)
{
if (! strcmp(value, "true"))
{
ret = true;
}
}
return ret;
}
int CCUserDefault::getIntegerForKey(const char* pKey)
{
const char* value = getValueForKey(pKey);
int ret = 0;
if (value)
{
ret = atoi(value);
xmlFree((void*)value);
}
return ret;
}
float CCUserDefault::getFloatForKey(const char* pKey)
{
float ret = (float)getDoubleForKey(pKey);
return ret;
}
double CCUserDefault::getDoubleForKey(const char* pKey)
{
const char* value = getValueForKey(pKey);
double ret = 0.0;
if (value)
{
ret = atof(value);
xmlFree((void*)value);
}
return ret;
}
string CCUserDefault::getStringForKey(const char* pKey)
{
const char* value = getValueForKey(pKey);
string ret("");
if (value)
{
ret = string(value);
xmlFree((void*)value);
}
return ret;
}
void CCUserDefault::setBoolForKey(const char* pKey, bool value)
{
// save bool value as sring
if (true == value)
{
setStringForKey(pKey, "true");
}
else
{
setStringForKey(pKey, "false");
}
}
void CCUserDefault::setIntegerForKey(const char* pKey, int value)
{
// check key
if (! pKey)
{
return;
}
// format the value
char tmp[50];
memset(tmp, 0, 50);
sprintf(tmp, "%d", value);
setValueForKey(pKey, tmp);
}
void CCUserDefault::setFloatForKey(const char* pKey, float value)
{
setDoubleForKey(pKey, value);
}
void CCUserDefault::setDoubleForKey(const char* pKey, double value)
{
// check key
if (! pKey)
{
return;
}
// format the value
char tmp[50];
memset(tmp, 0, 50);
sprintf(tmp, "%f", value);
setValueForKey(pKey, tmp);
}
void CCUserDefault::setStringForKey(const char* pKey, std::string value)
{
// check key
if (! pKey)
{
return;
}
setValueForKey(pKey, value.c_str());
}
CCUserDefault* CCUserDefault::sharedUserDefault()
{
initXMLFilePath();
// only create xml file one time
// the file exists after the programe exit
if ((! isXMLFileExist()) && (! createXMLFile()))
{
return NULL;
}
if (! m_spUserDefault)
{
m_spUserDefault = new CCUserDefault();
}
return m_spUserDefault;
}
bool CCUserDefault::isXMLFileExist()
{
FILE *fp = fopen(m_sFilePath.c_str(), "r");
bool bRet = false;
if (fp)
{
bRet = true;
fclose(fp);
}
return bRet;
}
void CCUserDefault::initXMLFilePath()
{
if (! m_sbIsFilePathInitialized)
{
m_sFilePath += CCFileUtils::getWriteablePath() + XML_FILE_NAME;
m_sbIsFilePathInitialized = true;
}
}
// create new xml file
bool CCUserDefault::createXMLFile()
{
bool bRet = false;
xmlDocPtr doc = NULL;
do
{
// new doc
doc = xmlNewDoc(BAD_CAST"1.0");
if (doc == NULL)
{
CCLOG("can not create xml doc");
break;
}
// new root node
xmlNodePtr rootNode = xmlNewNode(NULL, BAD_CAST USERDEFAULT_ROOT_NAME);
if (rootNode == NULL)
{
CCLOG("can not create root node");
break;
}
// set root node
xmlDocSetRootElement(doc, rootNode);
// save xml file
xmlSaveFile(m_sFilePath.c_str(), doc);
bRet = true;
} while (0);
// if doc is not null, free it
if (doc)
{
xmlFreeDoc(doc);
}
return bRet;
}
const string& CCUserDefault::getXMLFilePath()
{
return m_sFilePath;
}
NS_CC_END;

View File

@ -152,6 +152,10 @@ bool CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned int capacity
//CCLOG("cocos2d: CCTextureAtlas: not enough memory");
CC_SAFE_FREE(m_pQuads)
CC_SAFE_FREE(m_pIndices)
// release texture, should set it to null, because the destruction will
// release it too. see cocos2d-x issue #484
CC_SAFE_RELEASE_NULL(m_pTexture);
return false;
}

View File

@ -19,7 +19,7 @@ set _ANDROIDTOOLS=d:\android-sdk\tools
if not exist "%_ANDROIDTOOLS%" echo Couldn't find android sdk tools at "%_ANDROIDTOOLS%" & pause & exit 5
:: modify it to work under your environment
set _NDKROOT=e:\android-ndk-r4-crystax
set _NDKROOT=e:\android-ndk-r5
if not exist "%_NDKROOT%" echo Couldn't find ndk at "%_NDKROOT%" & pause & exit 6
:: create android project
@ -45,3 +45,5 @@ for /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "%_NDKROOT%"') do set _NDKROOT=%
:: Throw away temporary env vars and invoke script, passing any args that were passed to us
endlocal & %_CYGBIN%\bash --login "%_CYGSCRIPT%" %_CURRENTDIR% %_PROJECTNAME% %_NDKROOT% "windows"
pause

View File

@ -1,6 +1,6 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := helloworld
LOCAL_MODULE := game
LOCAL_SRC_FILES := main.cpp \
../../../Classes/AppDelegate.cpp \
@ -9,14 +9,20 @@ LOCAL_SRC_FILES := main.cpp \
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../cocos2dx \
$(LOCAL_PATH)/../../../../cocos2dx/platform \
$(LOCAL_PATH)/../../../../cocos2dx/include \
$(LOCAL_PATH)/../../../../CocosDenshion/include \
$(LOCAL_PATH)/../../../Classes
LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../libs/armeabi -lcocos2d -llog -lcocosdenshion
# it is used for ndk-r5
# it is used for ndk-r4
# if you build with nkd-r4, uncomment it
# LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../libs/armeabi -lcocos2d -llog -lcocosdenshion \
# -L$(LOCAL_PATH)/../../../../cocos2dx/platform/third_party/android/libraries -lcurl
# it is used for ndk-r5
# if you build with ndk-r4, comment it
# because the new Windows toolchain doesn't support Cygwin's drive
# mapping (i.e /cygdrive/c/ instead of C:/)
# LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/../../libs/armeabi) \
# -lcocos2d -llog -lcocosdenshion
LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/../../libs/armeabi) \
-lcocos2d -llog -lcocosdenshion \
-L$(call host-path, $(LOCAL_PATH)/../../../../cocos2dx/platform/third_party/android/libraries) -lcurl
include $(BUILD_SHARED_LIBRARY)

View File

@ -1,3 +1,3 @@
# it is needed for ndk-r5
APP_STL := stlport_static
APP_MODULES := cocos2d cocosdenshion helloworld
APP_MODULES := cocos2d cocosdenshion game

View File

@ -1,29 +1,29 @@
# set params
ANDROID_NDK_ROOT=__ndkroot__
COCOS2DX_ROOT=__cocos2dxroot__
HELLOWORLD_ROOT=$COCOS2DX_ROOT/__projectname__
HELLOWORLD_ANDROID_ROOT=$HELLOWORLD_ROOT/android
RESOURCE_ROOT=$HELLOWORLD_ROOT/Resource
GAME_ROOT=$COCOS2DX_ROOT/__projectname__
GAME_ANDROID_ROOT=$GAME_ROOT/android
RESOURCE_ROOT=$GAME_ROOT/Resource
# make sure assets is exist
if [ -d $HELLOWORLD_ANDROID_ROOT/assets ]; then
rm -rf $HELLOWORLD_ANDROID_ROOT/assets
if [ -d $GAME_ANDROID_ROOT/assets ]; then
rm -rf $GAME_ANDROID_ROOT/assets
fi
mkdir $HELLOWORLD_ANDROID_ROOT/assets
mkdir $GAME_ANDROID_ROOT/assets
# copy resources
for file in $RESOURCE_ROOT/*
do
if [ -d $file ]; then
cp -rf $file $HELLOWORLD_ANDROID_ROOT/assets
cp -rf $file $GAME_ANDROID_ROOT/assets
fi
if [ -f $file ]; then
cp $file $HELLOWORLD_ANDROID_ROOT/assets
cp $file $GAME_ANDROID_ROOT/assets
fi
done
# build
$ANDROID_NDK_ROOT/ndk-build -C $HELLOWORLD_ANDROID_ROOT $*
$ANDROID_NDK_ROOT/ndk-build -C $GAME_ANDROID_ROOT $*

View File

@ -67,12 +67,22 @@ modify_androidmanifest(){
sed "s/ApplicationDemo/$APP_NAME/" $HELLOWORLD_ROOT/android/AndroidManifest.xml > $APP_DIR/android/AndroidManifest.xml
}
# rename APP_DIR/android/src/org/cocos2dx/application/ApplicationDemo.java
# and change some content
# modify ApplicationDemo.java
modify_applicationdemo(){
sed "s/ApplicationDemo/$APP_NAME/" $APP_DIR/android/src/org/cocos2dx/application/ApplicationDemo.java > $APP_DIR/android/src/org/cocos2dx/application/tempfile.java
# rename APP_DIR/android/src/org/cocos2dx/application/ApplicationDemo.java to
# APP_DIR/android/src/org/cocos2dx/application/$APP_NAME.java, change helloworld to game
sed "s/ApplicationDemo/$APP_NAME/;s/helloworld/game/" $APP_DIR/android/src/org/cocos2dx/application/ApplicationDemo.java > $APP_DIR/android/src/org/cocos2dx/application/tempfile.java
rm -f $APP_DIR/android/src/org/cocos2dx/application/ApplicationDemo.java
mv $APP_DIR/android/src/org/cocos2dx/application/tempfile.java $APP_DIR/android/src/org/cocos2dx/application/$APP_NAME.java
}
modify_layout(){
cp $HELLOWORLD_ROOT/android/res/layout/helloworld_demo.xml $APP_DIR/android/res/layout
sed "s/helloworld_gl_surfaceview/game_gl_surfaceview/" $APP_DIR/android/res/layout/helloworld_demo.xml > $APP_DIR/android/res/layout/game_demo.xml
rm -f $APP_DIR/android/res/layout/main.xml
rm -f $APP_DIR/android/res/layout/helloworld_demo.xml
}
move_files_into_android
@ -82,3 +92,4 @@ copy_src_and_jni
copy_build_native
modify_androidmanifest
modify_applicationdemo
modify_layout

View File

@ -192,7 +192,7 @@ function AddConfigurations(proj, strProjectName) {
strAddIncludeDir += ';..\\cocos2dx\\platform\\third_party\\win32\\OGLES';
if (wizard.FindSymbol('CC_USE_BOX2D')) {
strAddIncludeDir += ';..\\;..\\Box2D';
strAddIncludeDir += ';..\\';
}
if (wizard.FindSymbol('CC_USE_CHIPMUNK')) {
strAddIncludeDir += ';..\\chipmunk\\include\\chipmunk';

View File

@ -4,7 +4,7 @@
#include "cocos2d.h"
[! if CC_USE_BOX2D]
#include "Box2D.h"
#include "Box2D/Box2D.h"
[! endif]
[! if CC_USE_CHIPMUNK]

View File

@ -182,7 +182,7 @@ function AddConfigurations(proj, strProjectName) {
var strOutputFile = '$(OutDir)/' + wizard.FindSymbol("PROJECT_NAME") + '.dll';
if (wizard.FindSymbol('CC_USE_BOX2D')) {
strCurIncludeDir += ';..\\;..\\Box2D';
strCurIncludeDir += ';..\\';
strDependLibs += ' libBox2d.lib';
}
if (wizard.FindSymbol('CC_USE_CHIPMUNK')) {

View File

@ -4,7 +4,7 @@
#include "cocos2d.h"
[! if CC_USE_BOX2D]
#include "Box2D.h"
#include "Box2D/Box2D.h"
[! endif]
[! if CC_USE_CHIPMUNK]

View File

@ -40,7 +40,7 @@ DEFINES=-D__TCOM_SUPPORT__ ;生成的是TCOM组件注意TOPS应用也
INCLUDE_PATH=-I ../../PRJ_TG3/Include/OpenGL -I../cocos2dx -I../cocos2dx/include -I../cocos2dx/platform
INCLUDE_PATH=-I. -I./Classes -I./wophone -I./wophone/Res ;默认本项目的路径
[! if CC_USE_BOX2D]
INCLUDE_PATH=-I../ -I../Box2D
INCLUDE_PATH=-I../
[! endif]
[! if CC_USE_CHIPMUNK]
INCLUDE_PATH=-I../chipmunk/include/chipmunk

View File

@ -1 +1 @@
8c9f77a384b0e17df11cc843e89538b603e91f12
d1962bc646d8650f27302fd6c32dff2d9d4ab6a5

View File

@ -1 +1 @@
2fc55bb5f8692cca82e907045481456851797347
6c636339fa5aff82bfca50d9da220b50af5c0053

View File

@ -1 +1 @@
bf9495b1eb39b27435866491b2da9918233c5c90
aeb5b381069888074bcb7bd1b6e3e658e1262d7d

View File

@ -66,6 +66,7 @@ LOCAL_SRC_FILES := main.cpp \
../../../tests/TouchesTest/Paddle.cpp \
../../../tests/TouchesTest/TouchesTest.cpp \
../../../tests/TransitionsTest/TransitionsTest.cpp \
../../../tests/UserDefaultTest/UserDefaultTest.cpp \
../../../tests/ZwoptexTest/ZwoptexTest.cpp \
../../../tests/controller.cpp \
../../../tests/testBasic.cpp \

View File

@ -1 +1 @@
9d64949d940f3601af63ef349967d1853680ef81
9f36b35f636dbc0d59f5e319e14cadb04630172a

View File

@ -947,6 +947,18 @@
>
</File>
</Filter>
<Filter
Name="UserDefaultTest"
>
<File
RelativePath="..\tests\UserDefaultTest\UserDefaultTest.cpp"
>
</File>
<File
RelativePath="..\tests\UserDefaultTest\UserDefaultTest.h"
>
</File>
</Filter>
</Filter>
</Filter>
</Files>

View File

@ -105,7 +105,8 @@ OBJECTS = \
$(OBJECTS_DIR)/Paddle.o \
$(OBJECTS_DIR)/TouchesTest.o \
$(OBJECTS_DIR)/TransitionsTest.o \
$(OBJECTS_DIR)/ZwoptexTest.o
$(OBJECTS_DIR)/ZwoptexTest.o \
$(OBJECTS_DIR)/UserDefaultTest.o
ADD_OBJECTS +=
@ -333,4 +334,7 @@ $(OBJECTS_DIR)/ZwoptexTest.o : ../tests/ZwoptexTest/ZwoptexTest.cpp
$(OBJECTS_DIR)/CurlTest.o : ../tests/CurlTest/CurlTest.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CurlTest.o ../tests/CurlTest/CurlTest.cpp
$(OBJECTS_DIR)/UserDefaultTest.o : ../tests/UserDefaultTest/UserDefaultTest.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/UserDefaultTest.o ../tests/UserDefaultTest/UserDefaultTest.cpp

View File

@ -987,6 +987,18 @@
>
</File>
</Filter>
<Filter
Name="UserDefaultTest"
>
<File
RelativePath="..\tests\UserDefaultTest\UserDefaultTest.cpp"
>
</File>
<File
RelativePath="..\tests\UserDefaultTest\UserDefaultTest.h"
>
</File>
</Filter>
</Filter>
</Files>
<Globals>

View File

@ -0,0 +1,101 @@
// enable log
#define COCOS2D_DEBUG 1
#include "UserDefaultTest.h"
#include "stdio.h"
#include "stdlib.h"
UserDefaultTest::UserDefaultTest()
{
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* label = CCLabelTTF::labelWithString("CCUserDefault test see log", "Arial", 28);
addChild(label, 0);
label->setPosition( ccp(s.width/2, s.height-50) );
doTest();
}
void UserDefaultTest::doTest()
{
CCLOG("********************** init value ***********************");
// set default value
CCUserDefault::sharedUserDefault()->setStringForKey("string", "value1");
CCUserDefault::sharedUserDefault()->setIntegerForKey("integer", 10);
CCUserDefault::sharedUserDefault()->setFloatForKey("float", 2.3f);
CCUserDefault::sharedUserDefault()->setDoubleForKey("double", 2.4);
CCUserDefault::sharedUserDefault()->setBoolForKey("bool", true);
// print value
string ret = CCUserDefault::sharedUserDefault()->getStringForKey("string");
CCLOG("string is %s", ret.c_str());
double d = CCUserDefault::sharedUserDefault()->getDoubleForKey("double");
CCLOG("double is %f", d);
int i = CCUserDefault::sharedUserDefault()->getIntegerForKey("integer");
CCLOG("integer is %d", i);
float f = CCUserDefault::sharedUserDefault()->getFloatForKey("float");
CCLOG("float is %f", f);
bool b = CCUserDefault::sharedUserDefault()->getBoolForKey("bool");
if (b)
{
CCLOG("bool is true");
}
else
{
CCLOG("bool is false");
}
CCLOG("********************** after change value ***********************");
// change the value
CCUserDefault::sharedUserDefault()->setStringForKey("string", "value2");
CCUserDefault::sharedUserDefault()->setIntegerForKey("integer", 11);
CCUserDefault::sharedUserDefault()->setFloatForKey("float", 2.5f);
CCUserDefault::sharedUserDefault()->setDoubleForKey("double", 2.6);
CCUserDefault::sharedUserDefault()->setBoolForKey("bool", false);
// print value
ret = CCUserDefault::sharedUserDefault()->getStringForKey("string");
CCLOG("string is %s", ret.c_str());
d = CCUserDefault::sharedUserDefault()->getDoubleForKey("double");
CCLOG("double is %f", d);
i = CCUserDefault::sharedUserDefault()->getIntegerForKey("integer");
CCLOG("integer is %d", i);
f = CCUserDefault::sharedUserDefault()->getFloatForKey("float");
CCLOG("float is %f", f);
b = CCUserDefault::sharedUserDefault()->getBoolForKey("bool");
if (b)
{
CCLOG("bool is true");
}
else
{
CCLOG("bool is false");
}
}
UserDefaultTest::~UserDefaultTest()
{
}
void UserDefaultTestScene::runThisTest()
{
CCLayer* pLayer = new UserDefaultTest();
addChild(pLayer);
CCDirector::sharedDirector()->replaceScene(this);
pLayer->release();
}

View File

@ -0,0 +1,23 @@
#ifndef _USERDEFAULT_TEST_H_
#define _USERDEFAULT_TEST_H_
#include "cocos2d.h"
#include "../testBasic.h"
class UserDefaultTest : public CCLayer
{
public:
UserDefaultTest();
~UserDefaultTest();
private:
void doTest();
};
class UserDefaultTestScene : public TestScene
{
public:
virtual void runThisTest();
};
#endif // _USERDEFAULT_TEST_H_

View File

@ -109,6 +109,10 @@ static TestScene* CreateTestScene(int nIdx)
pScene = new ZwoptexTestScene(); break;
case TEST_CURL:
pScene = new CurlTestScene(); break;
#if (CC_TARGET_PLATFORM != CC_PLATFORM_AIRPLAY)
case TEST_USERDEFAULT:
pScene = new UserDefaultTestScene(); break;
#endif
default:
break;
}

View File

@ -38,6 +38,7 @@
#include "ZwoptexTest/ZwoptexTest.h"
#include "CocosDenshionTest/CocosDenshionTest.h"
#include "CurlTest/CurlTest.h"
#include "UserDefaultTest/UserDefaultTest.h"
#if (CC_TARGET_PLATFORM != CC_PLATFORM_AIRPLAY)
#include "ChipmunkTest/cocos2dChipmunkDemo.h"
@ -47,7 +48,7 @@
#include "ChipmunkTest/cocos2dChipmunkDemo.h"
#endif
#endif
#endif
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_AIRPLAY)
enum
{
@ -72,10 +73,7 @@ enum
TEST_INTERVAL,
TEST_CHIPMUNK,
TEST_LABEL,
// havn't implement on airplay
#if (CC_TARGET_PLATFORM != CC_PLATFORM_AIRPLAY)
TEST_TEXT_INPUT,
#endif
TEST_SPRITE,
TEST_SCHEDULER,
TEST_RENDERTEXTURE,
@ -89,6 +87,7 @@ enum
TEST_PERFORMANCE,
TEST_ZWOPTEX,
TEST_CURL,
TEST_USERDEFAULT,
TESTS_COUNT,
};
@ -115,10 +114,7 @@ const std::string g_aTestNames[TESTS_COUNT] = {
"IntervalTest",
"ChipmunkTest",
"LabelTest",
// havn't implement on airplay
#if (CC_TARGET_PLATFORM != CC_PLATFORM_AIRPLAY)
"TextInputTest",
#endif
"SpriteTest",
"SchdulerTest",
"RenderTextureTest",
@ -131,7 +127,8 @@ const std::string g_aTestNames[TESTS_COUNT] = {
"CocosDenshionTest",
"PerformanceTest",
"ZwoptexTest",
"CurlTest"
"CurlTest",
"UserDefaultTest"
};
#endif