diff --git a/.gitignore b/.gitignore index 57024a17c..d323cb901 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,11 @@ .cache +.cmake compile_commands.json build-for-vscode build-win +build cocos +publish bullet/build bullet/build-win bullet/examples/pybullet diff --git a/.vscode/settings.json b/.vscode/settings.json index b22be53c3..c162c0732 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,14 @@ { "files.associations": { - "*.idl": "idl" + "*.ts": "typescriptreact", + "*.idl": "idl", + "memory": "cpp", + "optional": "cpp", + "functional": "cpp", + "charconv": "cpp", + "xhash": "cpp", + "xlocbuf": "cpp", + "xmemory": "cpp" }, "C_Cpp.default.includePath": ["bullet/src"] } \ No newline at end of file diff --git a/ammo.idl b/ammo.idl index 8ebcbb064..b0c5deb72 100644 --- a/ammo.idl +++ b/ammo.idl @@ -185,6 +185,7 @@ interface ClosestRayResultCallback { }; ClosestRayResultCallback implements RayResultCallback; +[Prefix="cc::"] interface ccClosestRayResultCallback { void ccClosestRayResultCallback([Const, Ref] btVector3 from, [Const, Ref] btVector3 to); attribute long m_shapeUserPointer; @@ -222,6 +223,7 @@ interface AllHitsRayResultCallback { }; AllHitsRayResultCallback implements RayResultCallback; +[Prefix="cc::"] interface ccAllHitsRayResultCallback { void ccAllHitsRayResultCallback([Const, Ref] btVector3 from, [Const, Ref] btVector3 to); [Value] attribute btIntArray m_shapeUserPointers; @@ -498,7 +500,7 @@ interface btCompoundShape { float getMargin(); ///XXX - void setMaterial(long childShapeindex, float f, float r, optional float rf, optional float sf); + //void setMaterial(long childShapeindex, float f, float r, optional float rf, optional float sf); }; btCompoundShape implements btCollisionShape; @@ -618,6 +620,7 @@ interface btOverlappingPairCallback { interface btOverlapFilterCallback { }; +[Prefix="cc::"] interface ccOverlapFilterCallback { void ccOverlapFilterCallback(); }; @@ -916,14 +919,15 @@ interface btDiscreteDynamicsWorld { }; btDiscreteDynamicsWorld implements btDynamicsWorld; +[Prefix="cc::"] interface ccDiscreteDynamicsWorld { void ccDiscreteDynamicsWorld(btDispatcher dispatcher, btBroadphaseInterface pairCache, btConstraintSolver constraintSolver, btCollisionConfiguration collisionConfiguration); void setAllowSleep(boolean v); void setDeactivationTime(float v); void setNarrowPhaseMethod(long v); void setAllowCcdPenetration(float v); - void setCcdCastCheckResponse(boolean v); - [Ref] btIntArray getCcdTriggerRecorder(); + //void setCcdCastCheckResponse(boolean v); + //[Ref] btIntArray getCcdTriggerRecorder(); }; ccDiscreteDynamicsWorld implements btDiscreteDynamicsWorld; @@ -1043,6 +1047,7 @@ interface btKinematicCharacterController { }; btKinematicCharacterController implements btActionInterface; +[Prefix="cc::"] interface ccKinematicCharacterController { void ccKinematicCharacterController(btPairCachingGhostObject ghostObject, btConvexShape convexShape, float stepHeight, optional long upAxis); diff --git a/ammo.release.idl b/ammo.release.idl index c15446761..f90179236 100644 --- a/ammo.release.idl +++ b/ammo.release.idl @@ -185,6 +185,7 @@ interface ClosestRayResultCallback { }; ClosestRayResultCallback implements RayResultCallback; +[Prefix="cc::"] interface ccClosestRayResultCallback { void ccClosestRayResultCallback([Const, Ref] btVector3 from, [Const, Ref] btVector3 to); // attribute long m_shapeUserPointer; @@ -222,6 +223,7 @@ interface AllHitsRayResultCallback { }; AllHitsRayResultCallback implements RayResultCallback; +[Prefix="cc::"] interface ccAllHitsRayResultCallback { void ccAllHitsRayResultCallback([Const, Ref] btVector3 from, [Const, Ref] btVector3 to); // [Value] attribute btIntArray m_shapeParts; @@ -353,7 +355,7 @@ interface btBoxShape { // XXX void setUnscaledHalfExtents([Ref] btVector3 boxHalfExtents); }; -btBoxShape implements btConvexInternalShape; +btBoxShape implements btCollisionShape; interface btCapsuleShape { void btCapsuleShape(float radius, float height); @@ -366,7 +368,7 @@ interface btCapsuleShape { // XXX void updateProp(float r, float h, long upAxis); }; -btCapsuleShape implements btConvexInternalShape; +btBoxShape implements btCollisionShape; // interface btCapsuleShapeX { // void btCapsuleShapeX(float radius, float height); @@ -502,7 +504,7 @@ interface btCompoundShape { float getMargin(); ///XXX - void setMaterial(long childShapeindex, float f, float r, optional float rf, optional float sf); + //void setMaterial(long childShapeindex, float f, float r, optional float rf, optional float sf); }; btCompoundShape implements btCollisionShape; @@ -913,14 +915,15 @@ interface btDiscreteDynamicsWorld { }; btDiscreteDynamicsWorld implements btDynamicsWorld; +[Prefix="cc::"] interface ccDiscreteDynamicsWorld { void ccDiscreteDynamicsWorld(btDispatcher dispatcher, btBroadphaseInterface pairCache, btConstraintSolver constraintSolver, btCollisionConfiguration collisionConfiguration); void setAllowSleep(boolean v); void setDeactivationTime(float v); void setNarrowPhaseMethod(long v); void setAllowCcdPenetration(float v); - void setCcdCastCheckResponse(boolean v); - [Ref] btIntArray getCcdTriggerRecorder(); + //void setCcdCastCheckResponse(boolean v); + //[Ref] btIntArray getCcdTriggerRecorder(); }; ccDiscreteDynamicsWorld implements btDiscreteDynamicsWorld; diff --git a/build-asm-debug.sh b/build-asm-debug.sh new file mode 100644 index 000000000..a283d63b4 --- /dev/null +++ b/build-asm-debug.sh @@ -0,0 +1,6 @@ +#!/bin/sh +cd bullet +sh autogen.sh +cd .. +python make.py add_func closure debug +npm run port2node \ No newline at end of file diff --git a/build-asm-release.sh b/build-asm-release.sh new file mode 100644 index 000000000..772772d43 --- /dev/null +++ b/build-asm-release.sh @@ -0,0 +1,6 @@ +#!/bin/sh +cd bullet +sh autogen.sh +cd .. +python make.py add_func closure release +npm run port2node \ No newline at end of file diff --git a/build-wasm-debug.sh b/build-wasm-debug.sh new file mode 100644 index 000000000..957b28d63 --- /dev/null +++ b/build-wasm-debug.sh @@ -0,0 +1,5 @@ +#!/bin/sh +cd bullet +sh autogen.sh +cd .. +python make.py add_func wasm closure debug diff --git a/build-wasm-release.sh b/build-wasm-release.sh new file mode 100644 index 000000000..72c6d5c9e --- /dev/null +++ b/build-wasm-release.sh @@ -0,0 +1,5 @@ +#!/bin/sh +cd bullet +sh autogen.sh +cd .. +python make.py add_func wasm closure release diff --git a/builds/node/ammo.cocos.js b/builds/node/ammo.cocos.js index 7b625e8e4..c4bc8328f 100644 --- a/builds/node/ammo.cocos.js +++ b/builds/node/ammo.cocos.js @@ -1,4 +1,4 @@ -//Sun Aug 22 2021 10:50:34 GMT+0800 (China Standard Time) +//Mon Oct 21 2024 18:18:56 GMT+0800 (中国标准时间) (function (root, factory) { if (typeof define === 'function' && define.amd) define(factory); diff --git a/bullet/CMakeLists.txt b/bullet/CMakeLists.txt index 1f6330154..ba6bf33af 100644 --- a/bullet/CMakeLists.txt +++ b/bullet/CMakeLists.txt @@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 3.8) PROJECT(BULLET_PHYSICS) SET(BULLET_VERSION 2.82) +message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.") + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../../bullet-release-embind/${CMAKE_BUILD_TYPE}") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../../bullet-release-embind/${CMAKE_BUILD_TYPE}") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../../bullet-release-embind/${CMAKE_BUILD_TYPE}") diff --git a/bullet/webBinding/BulletWebBindings.cpp b/bullet/webBinding/BulletWebBindings.cpp index 45d6f0cf3..5a18746b7 100644 --- a/bullet/webBinding/BulletWebBindings.cpp +++ b/bullet/webBinding/BulletWebBindings.cpp @@ -269,6 +269,8 @@ EMSCRIPTEN_BINDINGS(bullet) { function("DbvtBroadphase_new", &DbvtBroadphase_new, allow_raw_pointers()); function("SequentialImpulseConstraintSolver_new", &SequentialImpulseConstraintSolver_new, allow_raw_pointers()); + function("ccDiscreteDynamicsWorld_reset", &ccDiscreteDynamicsWorld_reset, allow_raw_pointers()); + function("CollisionWorld_addCollisionObject", &CollisionWorld_addCollisionObject, allow_raw_pointers()); function("CollisionWorld_removeCollisionObject", &CollisionWorld_removeCollisionObject, allow_raw_pointers()); function("CollisionWorld_rayTest", &CollisionWorld_rayTest, allow_raw_pointers()); diff --git a/bullet/webBinding/bullet.d.ts b/bullet/webBinding/bullet.d.ts index a2d0c96e2..4bea04a12 100644 --- a/bullet/webBinding/bullet.d.ts +++ b/bullet/webBinding/bullet.d.ts @@ -229,6 +229,7 @@ declare namespace Bullet { DbvtBroadphase_new(): ptr; SequentialImpulseConstraintSolver_new(): ptr; + ccDiscreteDynamicsWorld_reset(dispatcher: ptr,broadphase: ptr,solver: ptr): void; CollisionWorld_addCollisionObject(p: ptr, body: ptr, g: number, m: number): void; CollisionWorld_removeCollisionObject(p: ptr, body: ptr): void; diff --git a/bullet/webBinding/collision-world.cpp b/bullet/webBinding/collision-world.cpp index b89d37e9b..8f10c20b9 100644 --- a/bullet/webBinding/collision-world.cpp +++ b/bullet/webBinding/collision-world.cpp @@ -45,6 +45,16 @@ return (int)new btSequentialImpulseConstraintSolver(); } + void DLL_EXPORT ccDiscreteDynamicsWorld_reset(int dispatcher,int broadphase,int solver) + { + btCollisionDispatcher *m_dispatcher = (btCollisionDispatcher *)dispatcher; + btDbvtBroadphase *m_broadphase = (btDbvtBroadphase *)broadphase; + btConstraintSolver *m_solver = (btConstraintSolver *)solver; + + m_broadphase->resetPool(m_dispatcher); + m_solver->reset(); + } + // btDispatcherInfo bool DLL_EXPORT CollisionWorld_get_m_useContinuous(int ptr) { diff --git a/make.py b/make.py index 24ac6e7a7..45b09cb48 100755 --- a/make.py +++ b/make.py @@ -1,29 +1,48 @@ #!/usr/bin/python -import os, sys, re, json, shutil, multiprocessing -from subprocess import Popen, PIPE, STDOUT +import os, sys, multiprocessing +from subprocess import Popen,PIPE # Definitions -INCLUDES = ['btBulletDynamicsCommon.h', -os.path.join('BulletCollision', 'CollisionShapes', 'btHeightfieldTerrainShape.h'), -os.path.join('BulletCollision', 'CollisionShapes', 'btConvexPolyhedron.h'), -os.path.join('BulletCollision', 'CollisionShapes', 'btShapeHull.h'), -os.path.join('BulletCollision', 'CollisionDispatch', 'btGhostObject.h'), - -os.path.join('BulletDynamics', 'Character', 'btKinematicCharacterController.h'), -os.path.join('..', '..', 'extensions', 'ccKinematicCharacterController.cpp'), -os.path.join('..', '..', 'extensions', 'ccOverlapFilterCallback.h'), -os.path.join('..', '..', 'extensions', 'ccRayResultCallback.h'), -os.path.join('..', '..', 'extensions', 'ccDiscreteDynamicsWorld.cpp'), -os.path.join('..', '..', 'extensions', 'ccConvexCastCallBack.h'), - +INCLUDES = [ os.path.join('BulletSoftBody', 'btSoftBody.h'), -os.path.join('BulletSoftBody', 'btSoftRigidDynamicsWorld.h'), os.path.join('BulletSoftBody', 'btDefaultSoftBodySolver.h'), +os.path.join('BulletSoftBody', 'btSoftRigidDynamicsWorld.h'), +os.path.join('BulletSoftBody', 'btDefaultSoftBodySolver.h'), os.path.join('BulletSoftBody', 'btSoftBodyRigidBodyCollisionConfiguration.h'), os.path.join('BulletSoftBody', 'btSoftBodyHelpers.h'), -os.path.join('..', '..', 'idl_templates.h')] +'btBulletDynamicsCommon.h', +os.path.join('BulletDynamics', 'Character', 'btKinematicCharacterController.h'), + +os.path.join('BulletCollision', 'CollisionShapes', 'btHeightfieldTerrainShape.h'), +os.path.join('BulletCollision', 'CollisionShapes', 'btConvexPolyhedron.h'), +os.path.join('BulletCollision', 'CollisionShapes', 'btShapeHull.h'), +# os.path.join('BulletCollision', 'CollisionShapes', 'btConvexInternalShape.h'), +# os.path.join('BulletCollision', 'CollisionShapes', 'btPolyhedralConvexShape.h'), +# os.path.join('BulletCollision', 'CollisionShapes', 'btTriangleCallback.h'), +# os.path.join('BulletCollision', 'CollisionShapes', 'btConvexShape.h'), + +os.path.join('BulletCollision', 'CollisionDispatch', 'btGhostObject.h'), +# os.path.join('BulletCollision', 'CollisionDispatch', 'btCollisionWorld.cpp'), +# os.path.join('BulletCollision', 'CollisionDispatch', 'btCollisionDispatcher.h'), +# os.path.join('BulletCollision', 'CollisionDispatch', 'btCollisionObject.h'), + +# os.path.join('BulletCollision', 'NarrowPhaseCollision', 'btRaycastCallback.h'), +# os.path.join('BulletCollision', 'NarrowPhaseCollision', 'btConvexCast.h'), + +# os.path.join('extensions', 'btCharacterController.cpp'), +# os.path.join('extensions', 'btCharacterControllerDefs.h'), +# os.path.join('extensions', 'ccCompoundShape.cpp'), +# os.path.join('extensions', 'ccMaterial.h'), + +os.path.join('extensions', 'ccKinematicCharacterController.cpp'), +os.path.join('extensions', 'ccOverlapFilterCallback.h'), +os.path.join('extensions', 'ccRayResultCallback.h'), +os.path.join('extensions', 'ccDiscreteDynamicsWorld.cpp'), +os.path.join('extensions', 'ccConvexCastCallBack.h'), +os.path.join('..', '..', 'idl_templates.h') +] # Startup @@ -39,16 +58,19 @@ def which(program): def build(): EMSCRIPTEN_ROOT = os.environ.get('EMSCRIPTEN') if not EMSCRIPTEN_ROOT: - emcc = which('emcc') - EMSCRIPTEN_ROOT = os.path.dirname(emcc) + envEMSDK = os.environ.get('EMSDK') + if not envEMSDK: + print("ERROR: envEMSDK environment variable not found") + sys.exit(1) + EMSCRIPTEN_ROOT = os.path.join(envEMSDK, 'upstream', 'emscripten') if not EMSCRIPTEN_ROOT: - print "ERROR: EMSCRIPTEN_ROOT environment variable (which should be equal to emscripten's root dir) not found" + print("ERROR: EMSCRIPTEN_ROOT environment variable (which should be equal to emscripten's root dir) not found") sys.exit(1) sys.path.append(EMSCRIPTEN_ROOT) - import tools.shared as emscripten - + # import tools.config as config + # import tools.shared as shared # Settings ''' @@ -69,39 +91,53 @@ def build(): O3 = 'O3' in sys.argv Os = 'Os' in sys.argv Oz = 'Oz' in sys.argv + g0 = 'g0' in sys.argv g1 = 'g1' in sys.argv g2 = 'g2' in sys.argv g3 = 'g3' in sys.argv - g4 = 'g4' in sys.argv - - args = '-O3' - if O1 : args = '-O1' - elif O2 : args = '-O2' - elif O3 : args = '-O3' - elif Os : args = '-Os' - elif Oz : args = '-Oz' - - if g1 : args += ' -g1' - elif g2 : args += ' -g2' - elif g3 : args += ' -g3' - elif g4 : args += ' -g4' - - # args += ' -g4' + debug = 'debug' in sys.argv + release = 'release' in sys.argv + + args = [] + if O1 : args.append('-O1') + elif O2 : args.append('-O2') + elif O3 : args.append('-O3') + elif Os : args.append('-Os') + elif Oz : args.append('-Oz') + else: + not_debug = True - args += ' --llvm-lto 1 -s NO_EXIT_RUNTIME=1 -s NO_FILESYSTEM=1 -s ASSERTIONS=0 -s ENVIRONMENT=web,worker' + if g0 : args.append('-g0') + elif g1 : args.append('-g1') + elif g2 : args.append('-g2') + elif g3 : args.append('-g3') + else: + not_release = True + + if not_debug and not_release: + if debug: + args.append('-g3') + closure = False + elif release: + args.append('-O3') + else: + args.append('-O3') + # --llvm-lto + args += '-flto -s EXIT_RUNTIME=0 -s FILESYSTEM=0 -s ASSERTIONS=0 -s -s ENVIRONMENT=web,worker'.split(" ") # args = '-O3 --llvm-lto 1 -s NO_EXIT_RUNTIME=1 -s NO_FILESYSTEM=1 -s EXPORTED_RUNTIME_METHODS=["UTF8ToString"] -s ASSERTIONS=1' if add_function_support: - args += ' -s RESERVED_FUNCTION_POINTERS=20 -s EXTRA_EXPORTED_RUNTIME_METHODS=["addFunction"]' + args += '-s ALLOW_TABLE_GROWTH=1 -s EXPORTED_RUNTIME_METHODS=["addFunction"]'.split(" ") if not wasm: - args += ' -s WASM=0 -s AGGRESSIVE_VARIABLE_ELIMINATION=1 -s ELIMINATE_DUPLICATE_FUNCTIONS=1 -s SINGLE_FILE=1' # -s LEGACY_VM_SUPPORT=1' + args += '-s WASM=0 -s AGGRESSIVE_VARIABLE_ELIMINATION=1 -s ELIMINATE_DUPLICATE_FUNCTIONS=1 -s SINGLE_FILE=1'.split(" ") # -s LEGACY_VM_SUPPORT=1' else: - args += ' -s WASM=1 -s BINARYEN_IGNORE_IMPLICIT_TRAPS=1' # -s BINARYEN_TRAP_MODE="clamp" + args += '-s WASM=1 -s BINARYEN_IGNORE_IMPLICIT_TRAPS=1'.split(" ") # -s BINARYEN_TRAP_MODE="clamp" if closure: - args += ' --closure 1 -s IGNORE_CLOSURE_COMPILER_ERRORS=1' # closure complains about the bullet Node class (Node is a DOM thing too) + args += '--closure 1 -s IGNORE_CLOSURE_COMPILER_ERRORS=1'.split(" ") # closure complains about the bullet Node class (Node is a DOM thing too) else: - args += ' -s NO_DYNAMIC_EXECUTION=1' + args += '-s DYNAMIC_EXECUTION=0'.split(" ") + - emcc_args = args.split(' ') + emcc_args = args emcc_args += ['-s', 'TOTAL_MEMORY=%d' % (64*1024*1024)] # default 64MB. Compile with ALLOW_MEMORY_GROWTH if you want a growable heap (slower though). #emcc_args += ['-s', 'ALLOW_MEMORY_GROWTH=1'] # resizable heap, with some amount of slowness @@ -115,12 +151,17 @@ def build(): if full: this_idl = 'ammo.idl' target = 'ammo.full.js' if not wasm else 'ammo.full.wasm.js' + + if debug: + this_idl = 'ammo.idl' + target = 'bullet.debug.asm.js' if not wasm else 'bullet.debug.wasm.js' + elif release: + this_idl = 'ammo.release.idl' + target = 'bullet.release.asm.js' if not wasm else 'bullet.release.wasm.js' - print - print '--------------------------------------------------' - print 'Building ammo.js, build type:', emcc_args - print '--------------------------------------------------' - print + print('--------------------------------------------------') + print('Building ammo.js, build type:', emcc_args) + print('--------------------------------------------------') ''' import os, sys, re @@ -131,7 +172,7 @@ def build(): t1 = infile while True: t2 = re.sub(r'\(\n?!\n?1\n?\+\n?\(\n?!\n?1\n?\+\n?(\w)\n?\)\n?\)', lambda m: '(!1+' + m.group(1) + ')', t1) - print len(infile), len(t2) + print(len(infile), len(t2)) if t1 == t2: break t1 = t2 @@ -144,11 +185,9 @@ def stage(text): global stage_counter stage_counter += 1 text = 'Stage %d: %s' % (stage_counter, text) - print - print '=' * len(text) - print text - print '=' * len(text) - print + print('=' * len(text)) + print(text) + print('=' * len(text)) # Main @@ -159,41 +198,49 @@ def stage(text): os.makedirs('build') os.chdir('build') - stage('Generate bindings') - - Popen([emscripten.PYTHON, os.path.join(EMSCRIPTEN_ROOT, 'tools', 'webidl_binder.py'), os.path.join(this_dir, this_idl), 'glue']).communicate() + glue_args = ["python",os.path.join(EMSCRIPTEN_ROOT, 'tools', 'webidl_binder.py'), os.path.join(this_dir, this_idl), 'glue'] + stage('Generate bindings:'+' '.join(glue_args)) + Popen(glue_args).communicate() # Popen([emscripten.PYTHON, os.path.join(EMSCRIPTEN_ROOT, 'tools', 'webidl_binder.py'), os.path.join(this_dir, 'ammo.idl'), 'glue']).communicate() assert os.path.exists('glue.js') assert os.path.exists('glue.cpp') - stage('Build bindings') - args = ['-I../src', '-c'] for include in INCLUDES: args += ['-include', include] - emscripten.Building.emcc('glue.cpp', args, 'glue.o') + args = ['emcc','glue.cpp'] + args + args = args + ['-o','glue.o'] + + stage('Build bindings:'+' '.join(args)) + + Popen(args).communicate() assert(os.path.exists('glue.o')) # Configure with CMake on Windows, and with configure on Unix. - cmake_build = emscripten.WINDOWS + cmake_build = sys.platform.startswith("win") if cmake_build: if not os.path.exists('CMakeCache.txt'): stage('Configure via CMake') - emscripten.Building.configure([emscripten.PYTHON, os.path.join(EMSCRIPTEN_ROOT, 'emcmake'), 'cmake', '..', '-DBUILD_DEMOS=OFF', '-DBUILD_EXTRAS=OFF', '-DBUILD_CPU_DEMOS=OFF', '-DUSE_GLUT=OFF', '-DCMAKE_BUILD_TYPE=Release']) + Popen(['python', os.path.join(EMSCRIPTEN_ROOT, 'emcmake'), 'cmake', '..', '-DBUILD_DEMOS=OFF', '-DBUILD_EXTRAS=OFF', '-DBUILD_CPU_DEMOS=OFF', '-DUSE_GLUT=OFF', '-DCMAKE_BUILD_TYPE=Release']).communicate() else: if not os.path.exists('config.h'): stage('Configure (if this fails, run autogen.sh in bullet/ first)') - emscripten.Building.configure(['../configure', '--disable-demos','--disable-dependency-tracking']) + Popen(['emconfigure','../configure', '--disable-demos','--disable-dependency-tracking']).communicate() stage('Make') CORES = multiprocessing.cpu_count() - if emscripten.WINDOWS: - emscripten.Building.make(['mingw32-make', '-j', str(CORES)]) + if cmake_build: + Popen(['mingw32-make', '-j', str(CORES)]).communicate() else: - emscripten.Building.make(['make', '-j', str(CORES)]) + p = Popen(['emmake','make', '-j', str(CORES)], stdout=PIPE, stderr=PIPE) + stdout, stderr = p.communicate() + if stderr: + print(f'Error: {stderr.decode()}') + + # Popen(['emcc', '-o',"mylib.bc *.o"]).communicate() stage('Link') @@ -208,11 +255,22 @@ def stage(text): os.path.join('src', '.libs', 'libBulletCollision.a'), os.path.join('src', '.libs', 'libLinearMath.a')] - stage('emcc: ' + ' '.join(emcc_args)) - - temp = os.path.join('..', '..', 'builds', target) - emscripten.Building.emcc('-DNOTHING_WAKA_WAKA', emcc_args + ['glue.o'] + bullet_libs + ['--js-transform', 'python %s' % os.path.join('..', '..', 'bundle.py')], - temp) + temp = os.path.join('..','..', 'builds') + if not os.path.exists(temp): + os.makedirs(temp) + temp = os.path.join(temp,target) + print('temp: ' + temp) + if os.path.exists(temp): + os.remove(temp) + args = ['emcc','-DNOTHING_WAKA_WAKA'] + args = args + ['glue.o']+ bullet_libs + emcc_args# + ['--js-transform', 'python %s' % os.path.join('..','..', 'bundle.py')] + args = args + ['-o',temp] + Popen(["pwd"]).communicate() + print('emcc: ' + ' '.join(args)) + p = Popen(args, stdout=PIPE, stderr=PIPE) + stdout, stderr = p.communicate() + if stderr: + print(f'Error: {stderr.decode()}') assert os.path.exists(temp), 'Failed to create script code' @@ -224,8 +282,19 @@ def stage(text): open(temp, 'w').write(wrapped) + bulletdts = os.path.join('..', 'webBinding','bullet.d.ts') + + bulletdts_dst = os.path.join('..','..', 'builds','bullet.d.ts') + + if not os.path.exists(bulletdts_dst): + wrapped = open(bulletdts).read() + open(bulletdts_dst, 'w').write(wrapped) + + except Exception as e: + print(f"发生错误:{e}") finally: os.chdir(this_dir); + sys.exit() if __name__ == '__main__': build() diff --git a/publish.sh b/publish.sh index d805d8c7a..be21f77b4 100644 --- a/publish.sh +++ b/publish.sh @@ -1,4 +1,8 @@ #!/bin/bash +sh ./build-asm-release.sh +sh ./build-asm-debug.sh +sh ./build-wasm-release.sh +sh ./build-wasm-debug.sh dst=$1 @@ -12,10 +16,18 @@ echo "publish to ${dst}" mkdir -p ${dst} -cp ./bullet-release/bullet.cocos.js ${dst}/bullet.asm.js +cp ./builds/bullet.debug.asm.js ${dst}/bullet.debug.asm.js -cp ./bullet-release/bullet.wasm.wasm ${dst}/bullet.wasm +cp ./builds/bullet.release.asm.js ${dst}/bullet.release.asm.js -cp ./bullet-release/bullet.d.ts ${dst}/bullet.d.ts +cp ./builds/bullet.debug.wasm.js ${dst}/bullet.debug.wasm.js + +cp ./builds/bullet.debug.wasm.wasm ${dst}/bullet.debug.wasm.wasm + +cp ./builds/bullet.release.wasm.js ${dst}/bullet.release.wasm.js + +cp ./builds/bullet.release.wasm.wasm ${dst}/bullet.release.wasm.wasm + +cp ./builds/bullet.d.ts ${dst}/bullet.d.ts echo "Done!"