Merge pull request #2182 from dumganhar/master

fixed #1642: Cxx-generator now works ok on windows, it uses the same config file as unix. For details, please refer to README file.
This commit is contained in:
James Chen 2013-03-16 23:50:10 -07:00
commit 62d7dd5002
10 changed files with 78 additions and 215 deletions

1
.gitignore vendored
View File

@ -64,6 +64,7 @@ build_*_vc10/
xcschememanagement.plist
build/
.DS_Store
._.*
xcuserdata/
DerivedData/

View File

@ -4,13 +4,12 @@ How to Use cxx-generator
On Windows:
------------
* Make sure that you have installed vs2010 or higher version.
* Make sure that you have installed `android-ndk-r8d` or higher version.
* Download python2.7.3 from (http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi).
* Add the installed path of python (e.g. C:\Python27) to windows environment variable named 'PATH'.
* Download pyyaml from http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.7.exe and install it.
* Download pyCheetah from https://raw.github.com/dumganhar/cocos2d-x/download/downloads/Cheetah.zip, unzip it to "C:\Python27\Lib\site-packages"
* There is a bug of redefine some base type(e.g. uint_16 in stdint.h file on windows.
So before you run the generating script, you should comment first line which contains "#include <stdint.h>" in "cocos2d-x\external\chipmunk\include\chipmunk\chipmunk_types.h"
* Modify environment variables (`PYTHON_ROOT` and `NDK_ROOT`) in `genbindings-win32.bat`.
* Go to "cocos2d-x/tools/tojs" folder, and run "genbindings-win32.bat". The generated codes will be under "cocos2d-x\scripting\javascript\bindings\generated".
On MAC:

View File

@ -1,147 +0,0 @@
[cocos2d-x]
# the prefix to be added to the generated functions. You might or might not use this in your own
# templates
prefix = cocos2dx
# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
# all classes will be embedded in that namespace
target_namespace = cc
clang_headers =
clang_flags = -x c++
cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/win32 -I%(cocosdir)s/cocos2dx/platform/third_party/win32/OGLES -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include -I%(cocosdir)s/extensions -I%(cocosdir)s/extensions/CCBReader -I%(cocosdir)s/external/chipmunk/include/chipmunk
cocos_flags = -DWIN32 -D_WINDOWS -DCOCOS2D_JAVASCRIPT -DCC_ENABLE_CHIPMUNK_INTEGRATION=1
cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common
# extra arguments for clang
extra_arguments = %(vs_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(vs_flags)s %(clang_flags)s %(cocos_flags)s
# what headers to parse
headers = %(cocosdir)s/cocos2dx/include/cocos2d.h %(cocosdir)s/CocosDenshion/include/SimpleAudioEngine.h %(cocosdir)s/extensions/cocos-ext.h
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^CCMenu*$".
classes = CCSprite.* CCScene CCNode.* CCDirector CCLayer.* CCMenu.* CCTouch CC.*Action.* CCMove.* CCRotate.* CCBlink.* CCTint.* CCSequence CCRepeat.* CCFade.* CCEase.* CCScale.* CCTransition.* CCSpawn CCSequence CCAnimat.* CCFlip.* CCDelay.* CCSkew.* CCJump.* CCPlace.* CCShow.* CCProgress.* CCPointArray CCToggleVisibility.* CCHide CCParticle.* CCLabel.* CCAtlas.* CCTextureCache.* CCTexture2D CCCardinal.* CCCatmullRom.* CCParallaxNode CCTileMap.* CCTMX.* CCCallFunc CCRenderTexture CCGridAction CCGrid3DAction CCGridBase$ CCShaky3D CCWaves3D CCFlipX3D CCFlipY3D CCSpeed CCActionManager CCBReader.* CCBAnimationManager.* CCSet SimpleAudioEngine CCScheduler CCTimer CCOrbit.* CCFollow.* CCBezier.* CCCardinalSpline.* CCControl$ CCControlButton.* CCCamera.* CCDrawNode CC.*3D$ CCLiquid$ CCWaves$ CCShuffleTiles$ CCTurnOffTiles$ CCSplit.* CCTwirl$ CCFileUtils$ CCScrollView$ CCTableView$ CCTableViewCell$
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just
# add a single "*" as functions. See bellow for several examples. A special class name is "*", which
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
# functions from all classes.
skip = CCNode::[.*Transform convertToWindowSpace getChildren ^setPosition$ getGrid setGLServerState description getShaderProgram getUserObject .*UserData getGLServerState unscheduleAllSelectors],
CCSprite::[getQuad displayFrame getBlendFunc ^setPosition$ setBlendFunc setSpriteBatchNode getSpriteBatchNode],
CCSpriteBatchNode::[getBlendFunc setBlendFunc],
CCMotionStreak::[getBlendFunc setBlendFunc],
CCAtlasNode::[getBlendFunc setBlendFunc],
CCParticleBatchNode::[getBlendFunc setBlendFunc],
CCLayerColor::[getBlendFunc setBlendFunc],
CCParticleSystem::[getBlendFunc setBlendFunc],
CCDrawNode::[getBlendFunc setBlendFunc drawPolygon],
CCDirector::[getAccelerometer getKeypadDispatcher getTouchDispatcher setWatcherCallbackFun getOpenGLView getProjection getClassTypeInfo],
CCLayer.*::[didAccelerate (g|s)etBlendFunc],
CCMenu.*::[.*Target getSubItems create initWithItems alignItemsInRows alignItemsInColumns],
CCMenuItem.*::[create],
CCRGBAProtocol::[*],
CCCopying::[*],
CC.*Protocol::[*],
CC.*Delegate::[*],
CCPoolManager::[*],
CCTexture2D::[initWithPVRTCData addPVRTCImage releaseData setTexParameters initWithData keepData],
CCSet::[begin end],
CCIMEDispatcher::[*],
CCSAXParser::[*],
CCThread::[*],
CCProfiler::[*],
CCProfilingTimer::[*],
CCCallFunc::[create],
CCSAXDelegator::[*],
CCColor3bObject::[*],
CCTouchDispatcher::[*],
EGLTouchDelegate::[*],
CCScriptEngineManager::[*],
CCKeypadHandler::[*],
CCInvocation::[*],
CCEGLView::[*],
CCSchedulerScriptHandlerEntry::[*],
CCSize::[*],
CCPoint::[*],
CCPointArray::[*],
CCRect::[*],
CCString::[*],
CCDictionary::[*],
CCArray::[*],
CCRange::[*],
CCNotificationObserver::[*],
CCListView.*::[*],
CCImage::[initWithString initWithImageData],
CCSequence::[create],
CCSpawn::[create],
CCAnimation::[create],
CCGrid3DAction::[create actionWith.*],
CCTiledGrid3DAction::[create actionWith.*],
CCTMXMapInfo::[startElement endElement textHandler],
CCParticleSystemQuad::[postStep setBatchNode draw setTexture$ setTotalParticles updateQuadWithParticle setupIndices listenBackToForeground initWithTotalParticles particleWithFile node],
CCLayerMultiplex::[create layerWith.* initWithLayers],
CCCatmullRom.*::[create actionWithDuration],
CCBezier.*::[create actionWithDuration],
CCBReader::[^CCBReader$ addOwnerCallbackName isJSControlled readByte getCCBMemberVariableAssigner readFloat getCCBSelectorResolver toLowerCase lastPathComponent deletePathExtension endsWith concat getResolutionScale getAnimatedProperties readBool readInt addOwnerCallbackNode addDocumentCallbackName readCachedString readNodeGraphFromData addDocumentCallbackNode getLoadedSpriteSheet initWithData readFileWithCleanUp getOwner$ readNodeGraphFromFile createSceneWithNodeGraphFromFile getAnimationManagers$ setAnimationManagers],
CCBAnimationManager::[setAnimationCompletedCallback],
CCCardinalSpline.*::[create actionWithDuration setPoints],
CCScheduler::[pause resume unscheduleAllSelectorsForTarget],
CCTextureCache::[addPVRTCImage],
CCTimer::[getSelector],
CC.*Loader.*::[*],
*::[copyWith.* onEnter.* onExit.* description getObjectType .*RGB.* .*HSV.*],
CCFileUtils::[(g|s)etSearchResolutionsOrder$ (g|s)etSearchPaths$ getClassTypeInfo],
SimpleAudioEngine::[getClassTypeInfo],
CCScrollView::[(g|s)etDelegate$],
CCTableView::[create (g|s)etDataSource$ (g|s)etDelegate]
rename_functions = CCDirector::[sharedDirector=getInstance],
CCSpriteFrameCache::[sharedSpriteFrameCache=getInstance addSpriteFramesWithFile=addSpriteFrames spriteFrameByName=getSpriteFrame isFlipX=isFlippedX isFlipY=isFlippedY],
CCMenuItemFont::[setFontNameObj=setFontName setFontSizeObj=setFontSize fontSizeObj=fontSize fontNameObj=fontName],
CCProgressTimer::[setReverseProgress=setReverseDirection],
CCTextureCache::[sharedTextureCache=getInstance],
CCAnimation::[addSpriteFrameWithFileName=addSpriteFrameWithFile],
CCAnimationCache::[sharedAnimationCache=getInstance addAnimationsWithFile=addAnimations animationByName=getAnimation removeAnimationByName=removeAnimation],
CCLayerGradient::[initWithColor=init],
CCLayerColor::[initWithColor=init],
CCNode::[boundingBox=getBoundingBox removeFromParentAndCleanup=removeFromParent removeAllChildrenWithCleanup=removeAllChildren],
CCLabelAtlas::[create=_create],
CCTMXLayer::[tileAt=getTileAt tileGIDAt=getTileGIDAt propertyNamed=getProperty],
CCTileMapAtlas::[tileAt=getTileAt],
CCSprite::[isFlipX=isFlippedX isFlipY=isFlippedY],
CCTouch::[getID=getId],
CCScheduler::[unscheduleAllSelectorsForTarget=unscheduleAllCallbacksForTarget unscheduleAll=unscheduleAllCallbacks],
SimpleAudioEngine::[sharedEngine=getInstance preloadBackgroundMusic=preloadMusic setBackgroundMusicVolume=setMusicVolume getBackgroundMusicVolume=getMusicVolume playBackgroundMusic=playMusic stopBackgroundMusic=stopMusic pauseBackgroundMusic=pauseMusic resumeBackgroundMusic=resumeMusic rewindBackgroundMusic=rewindMusic isBackgroundMusicPlaying=isMusicPlaying willPlayBackgroundMusic=willPlayMusic],
CCCamera.*::[setUpXYZ=setUp getUpXYZ=getUp setEyeXYZ=setEye getEyeXYZ=getEye setCenterXYZ=setCenter getCenterXYZ=getCenter],
CCBReader::[getAnimationManager=getActionManager setAnimationManager=setActionManager],
CCTMXTiledMap::[layerNamed=getLayer objectGroupNamed=getObjectGroup propertyNamed=getProperty],
CCTexture2D::[defaultAlphaPixelFormat=getDefaultAlphaPixelFormat],
CCFileUtils::[sharedFileUtils=getInstance loadFilenameLookupDictionaryFromFile=loadFilenameLookup]
rename_classes = CCParticleSystemQuad::CCParticleSystem,
SimpleAudioEngine::AudioEngine,
CCBReader::CC_Reader,
CCBAnimationManager::CCAnimationManager
# for all class names, should we remove something when registering in the target VM?
remove_prefix = CC
# classes for which there will be no "parent" lookup
classes_have_no_parents = CCNode CCDirector SimpleAudioEngine CCFileUtils CCTMXMapInfo
# base classes which will be skipped when their sub-classes found them.
base_classes_to_skip = CCObject
# classes that create no constructor
# CCSet is special and we will use a hand-written constructor
abstract_classes = CCDirector CCSpriteFrameCache CCTransitionEaseScene CCSet SimpleAudioEngine CCFileUtils
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
script_control_cpp = no

View File

@ -19,7 +19,7 @@ cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT
cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common
# extra arguments for clang
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s
# what headers to parse
headers = %(cocosdir)s/cocos2dx/include/cocos2d.h %(cocosdir)s/CocosDenshion/include/SimpleAudioEngine.h

View File

@ -19,7 +19,7 @@ cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT
cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common
# extra arguments for clang
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s
# what headers to parse
headers = %(cocosdir)s/extensions/cocos-ext.h

View File

@ -1,63 +1,69 @@
@echo off
echo./*
echo.* Check VC++ environment...
echo.*/
echo.
set PATH=%PATH%;%cd%
if defined VS110COMNTOOLS (
set VSTOOLS="%VS110COMNTOOLS%"
) else if defined VS100COMNTOOLS (
set VSTOOLS="%VS100COMNTOOLS%"
)
set VSTOOLS=%VSTOOLS:"=%
set "VSTOOLS=%VSTOOLS:\=/%"
set VSVARS="%VSTOOLS%vsvars32.bat"
if not defined VSVARS (
echo Can't find VC2010 or VC2012 installed!
goto ERROR
)
set VS_ROOT=%VSTOOLS%/../..
:: set vs compilation environment
call %VSVARS%
set COCOS2DX_ROOT=%cd%/../..
set "COCOS2DX_ROOT=%COCOS2DX_ROOT:\=/%"
set CXX_GENERATOR_ROOT=%COCOS2DX_ROOT%/tools/cxx-generator
set "CXX_GENERATOR_ROOT=%CXX_GENERATOR_ROOT:\=/%"
:: write userconf.ini
set _CONF_INI_FILE=%cd%\userconf.ini
if exist %_CONF_INI_FILE% del /Q %_CONF_INI_FILE%
echo
echo generating userconf.ini...
echo ---
echo [DEFAULT] > %_CONF_INI_FILE%
echo cocosdir=%COCOS2DX_ROOT% >> %_CONF_INI_FILE%
echo cxxgeneratordir=%CXX_GENERATOR_ROOT% >> %_CONF_INI_FILE%
echo vs_headers="%VS_ROOT%/VC/include" >> %_CONF_INI_FILE%
echo vs_flags= >> %_CONF_INI_FILE%
echo ---
:: Generate bindings for cocos2dx
echo Generating bindings for cocos2dx...
python %CXX_GENERATOR_ROOT%/generator.py cocos2dx-win32.ini -s cocos2d-x -o %COCOS2DX_ROOT%/scripting/javascript/bindings/generated
echo Generating bindings successfully.
:ERROR
pause
@echo off
:: This script is used to generate jsbinding glue codes.
:: You should modify PYTHON_ROOT and NDK_ROOT to work under your environment.
:: Android ndk version must be at least ndk-r8d.
set PYTHON_ROOT=C:/Python27
set NDK_ROOT=C:/android-ndk-r8d
set PATH=%PATH%;%cd%/win32;%PYTHON_ROOT%
set COCOS2DX_ROOT=%cd%/../..
set "COCOS2DX_ROOT=%COCOS2DX_ROOT:\=/%"
set CXX_GENERATOR_ROOT=%COCOS2DX_ROOT%/tools/cxx-generator
set TO_JS_ROOT=%COCOS2DX_ROOT%/tools/tojs
set "CXX_GENERATOR_ROOT=%CXX_GENERATOR_ROOT:\=/%"
set OUTPUT_DIR=%COCOS2DX_ROOT%/scripting/javascript/bindings/generated
set "OUTPUT_DIR=%OUTPUT_DIR:/=\%"
set CLANG_ROOT=%NDK_ROOT%/toolchains/llvm-3.1/prebuilt/windows
:: write userconf.ini
set _CONF_INI_FILE=%cd%\userconf.ini
if exist %_CONF_INI_FILE% del /Q %_CONF_INI_FILE%
echo
echo generating userconf.ini...
echo ---
echo [DEFAULT] > %_CONF_INI_FILE%
echo androidndkdir=%NDK_ROOT% >> %_CONF_INI_FILE%
echo clangllvmdir=%CLANG_ROOT% >> %_CONF_INI_FILE%
echo cocosdir=%COCOS2DX_ROOT% >> %_CONF_INI_FILE%
echo cxxgeneratordir=%CXX_GENERATOR_ROOT% >> %_CONF_INI_FILE%
echo extra_flags=-D__ARM_EABI__ -D__GNUC__=2 >> %_CONF_INI_FILE%
echo ---
:: Generate bindings for cocos2dx
echo Generating bindings for cocos2dx...
python %CXX_GENERATOR_ROOT%/generator.py %TO_JS_ROOT%/cocos2dx.ini -s cocos2d-x -o %OUTPUT_DIR% -n jsb_cocos2dx_auto
if %errorlevel% neq 0 goto ERROR
echo "Generating bindings for cocos2dx_extension..."
python %CXX_GENERATOR_ROOT%/generator.py %TO_JS_ROOT%/cocos2dx_extension.ini -s cocos2dx_extension -o %OUTPUT_DIR% -n jsb_cocos2dx_extension_auto
if %errorlevel% neq 0 goto ERROR
:: Change the generated file format from DOS to UNIX.
pushd "%OUTPUT_DIR%"
dos2unix *
popd
echo ---------------------------------
echo Generating bindings succeeds.
echo ---------------------------------
goto QUIT
:ERROR
echo ---------------------------------
echo Generating bindings fails.
echo ---------------------------------
:QUIT
pause

View File

@ -68,6 +68,8 @@ _CONTENTS+="androidndkdir=$NDK_ROOT"'\n'
_CONTENTS+="clangllvmdir=$CLANG_ROOT"'\n'
_CONTENTS+="cocosdir=$COCOS2DX_ROOT"'\n'
_CONTENTS+="cxxgeneratordir=$CXX_GENERATOR_ROOT"'\n'
_CONTENTS+="extra_flags="'\n'
echo
echo "generating userconf.ini..."
echo ---

View File

@ -0,0 +1 @@
f8bcb5d3cb13f170075570db09276e65d4f435ed

View File

@ -0,0 +1 @@
71cde86196932ad943470198ad5fcbafd47ea949