├── LICENSE ├── README.md ├── core ├── Android.mk ├── RDConfig.cpp ├── RDConfig.h ├── RDDirector.cpp ├── RDDirector.h ├── RDResolution.cpp ├── RDResolution.h ├── Rapid2D.cpp ├── Rapid2D.h ├── audio │ ├── Android.mk │ ├── RDAudio.cpp │ ├── RDAudio.h │ ├── RDAudioOgg.cpp │ ├── RDAudioOgg.h │ ├── libogg │ │ ├── ogg │ │ │ ├── ogg.h │ │ │ └── os_types.h │ │ └── src │ │ │ ├── bitwise.c │ │ │ └── framing.c │ └── libvorbis │ │ ├── lib │ │ ├── analysis.c │ │ ├── backends.h │ │ ├── barkmel.c │ │ ├── bitrate.c │ │ ├── bitrate.h │ │ ├── block.c │ │ ├── books │ │ │ ├── coupled │ │ │ │ ├── res_books_51.h │ │ │ │ └── res_books_stereo.h │ │ │ ├── floor │ │ │ │ └── floor_books.h │ │ │ └── uncoupled │ │ │ │ └── res_books_uncoupled.h │ │ ├── codebook.c │ │ ├── codebook.h │ │ ├── codec_internal.h │ │ ├── envelope.c │ │ ├── envelope.h │ │ ├── floor0.c │ │ ├── floor1.c │ │ ├── highlevel.h │ │ ├── info.c │ │ ├── lookup.c │ │ ├── lookup.h │ │ ├── lookup_data.h │ │ ├── lookups.pl │ │ ├── lpc.c │ │ ├── lpc.h │ │ ├── lsp.c │ │ ├── lsp.h │ │ ├── mapping0.c │ │ ├── masking.h │ │ ├── mdct.c │ │ ├── mdct.h │ │ ├── misc.h │ │ ├── modes │ │ │ ├── floor_all.h │ │ │ ├── psych_11.h │ │ │ ├── psych_16.h │ │ │ ├── psych_44.h │ │ │ ├── psych_8.h │ │ │ ├── residue_16.h │ │ │ ├── residue_44.h │ │ │ ├── residue_44p51.h │ │ │ ├── residue_44u.h │ │ │ ├── residue_8.h │ │ │ ├── setup_11.h │ │ │ ├── setup_16.h │ │ │ ├── setup_22.h │ │ │ ├── setup_32.h │ │ │ ├── setup_44.h │ │ │ ├── setup_44p51.h │ │ │ ├── setup_44u.h │ │ │ ├── setup_8.h │ │ │ └── setup_X.h │ │ ├── os.h │ │ ├── psy.c │ │ ├── psy.h │ │ ├── registry.c │ │ ├── registry.h │ │ ├── res0.c │ │ ├── scales.h │ │ ├── sharedbook.c │ │ ├── smallft.c │ │ ├── smallft.h │ │ ├── synthesis.c │ │ ├── tone.c │ │ ├── vorbisenc.c │ │ ├── vorbisfile.c │ │ ├── window.c │ │ └── window.h │ │ └── vorbis │ │ ├── codec.h │ │ ├── vorbisenc.h │ │ └── vorbisfile.h ├── crypto │ ├── base64.c │ ├── base64.h │ ├── md5.c │ ├── md5.h │ ├── xxtea.c │ └── xxtea.h ├── math │ ├── RDMath.c │ ├── RDMath.h │ ├── RDTypes.h │ ├── RDkmMath.c │ └── RDkmMath.h ├── porting │ ├── android │ │ ├── RDPortingPrint.cpp │ │ ├── RDPortingSystem.cpp │ │ ├── RDPortingTTF.cpp │ │ ├── RDRDPortingFile.cpp │ │ ├── RDRDPortingMainLoop.cpp │ │ ├── c2java.cpp │ │ └── c2java.h │ ├── inc │ │ ├── RDPortingFile.h │ │ ├── RDPortingGL.h │ │ ├── RDPortingMainLoop.h │ │ ├── RDPortingPrint.h │ │ ├── RDPortingSystem.h │ │ ├── RDPortingTTF.h │ │ ├── RDPortingTime.h │ │ └── RDPortingTypes.h │ ├── ios │ │ ├── RDPortingFile.mm │ │ ├── RDPortingMainLoop.mm │ │ ├── RDPortingPrint.mm │ │ ├── RDPortingSystem.mm │ │ └── RDPortingTTF.mm │ ├── mac │ │ ├── RDPortingFile.mm │ │ ├── RDPortingMainLoop.mm │ │ ├── RDPortingPrint.mm │ │ ├── RDPortingSystem.mm │ │ └── RDPortingTTF.mm │ └── win32 │ │ ├── RDPortingFile.cpp │ │ ├── RDPortingMainLoop.cpp │ │ ├── RDPortingPrint.cpp │ │ ├── RDPortingSystem.cpp │ │ ├── RDPortingTTF.cpp │ │ ├── RDPortingTime.cpp │ │ ├── RDWin32Char.cpp │ │ └── RDWin32Char.h ├── projects │ ├── ios │ │ └── Rapid2D.xcodeproj │ │ │ └── project.pbxproj │ ├── mac │ │ └── Rapid2D.xcodeproj │ │ │ └── project.pbxproj │ └── win32 │ │ ├── ReadMe.txt │ │ ├── core.sln │ │ ├── core.vcxproj │ │ ├── core.vcxproj.filters │ │ └── core.vcxproj.user ├── scripting │ ├── RDLuaconf.h │ ├── binding │ │ ├── RDLua.cpp │ │ ├── RDLua.h │ │ ├── RDlMat4.cpp │ │ ├── RDlOpenGL.cpp │ │ ├── RDlaudio.cpp │ │ ├── RDlcrypto.cpp │ │ ├── RDldrawvertex.cpp │ │ ├── RDlfilesystem.cpp │ │ ├── RDllualoader.cpp │ │ ├── RDlsprite.cpp │ │ ├── RDlspriteframe.cpp │ │ └── RDltexture.cpp │ ├── cjson │ │ ├── fpconv.c │ │ ├── fpconv.h │ │ ├── lua_cjson.c │ │ ├── strbuf.c │ │ └── strbuf.h │ └── lua │ │ ├── lapi.c │ │ ├── lapi.h │ │ ├── lauxlib.c │ │ ├── lauxlib.h │ │ ├── lbaselib.c │ │ ├── lbitlib.c │ │ ├── lcode.c │ │ ├── lcode.h │ │ ├── lcorolib.c │ │ ├── lctype.c │ │ ├── lctype.h │ │ ├── ldblib.c │ │ ├── ldebug.c │ │ ├── ldebug.h │ │ ├── ldo.c │ │ ├── ldo.h │ │ ├── ldump.c │ │ ├── lfunc.c │ │ ├── lfunc.h │ │ ├── lgc.c │ │ ├── lgc.h │ │ ├── linit.c │ │ ├── liolib.c │ │ ├── llex.c │ │ ├── llex.h │ │ ├── llimits.h │ │ ├── lmathlib.c │ │ ├── lmem.c │ │ ├── lmem.h │ │ ├── loadlib.c │ │ ├── lobject.c │ │ ├── lobject.h │ │ ├── lopcodes.c │ │ ├── lopcodes.h │ │ ├── loslib.c │ │ ├── lparser.c │ │ ├── lparser.h │ │ ├── lprefix.h │ │ ├── lstate.c │ │ ├── lstate.h │ │ ├── lstring.c │ │ ├── lstring.h │ │ ├── lstrlib.c │ │ ├── ltable.c │ │ ├── ltable.h │ │ ├── ltablib.c │ │ ├── ltm.c │ │ ├── ltm.h │ │ ├── lua.h │ │ ├── lua.hpp │ │ ├── luaconf.h │ │ ├── lualib.h │ │ ├── lundump.c │ │ ├── lundump.h │ │ ├── lutf8lib.c │ │ ├── lvm.c │ │ ├── lvm.h │ │ ├── lzio.c │ │ └── lzio.h ├── shader │ ├── RDIndexBuffer.cpp │ ├── RDIndexBuffer.h │ ├── RDProgram.cpp │ ├── RDProgram.h │ ├── RDProgramCache.cpp │ ├── RDProgramCache.h │ ├── RDShaderSprite.h │ └── RDShaderVertex.h ├── sprite │ ├── RDDrawVertex.cpp │ ├── RDDrawVertex.h │ ├── RDSprite.cpp │ ├── RDSprite.h │ └── RDSpriteFrame.h ├── texture │ ├── RDTexture.cpp │ ├── RDTexture.h │ └── RDTexturePng.cpp └── utils │ ├── RDData.cpp │ ├── RDData.h │ ├── RDFileSystem.cpp │ ├── RDFileSystem.h │ ├── RDLog.cpp │ ├── RDLog.h │ └── RDMacros.h ├── samples └── test │ ├── android │ ├── Rapid2D │ │ ├── build.gradle │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── jni │ │ │ ├── Android.mk │ │ │ ├── Application.mk │ │ │ └── main.c │ │ ├── proguard-rules.pro │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── org │ │ │ │ └── rapid2d │ │ │ │ └── library │ │ │ │ ├── OpenGLRender.java │ │ │ │ ├── OpenGLSurfaceView.java │ │ │ │ ├── RDBitmap.java │ │ │ │ └── Rapid2DActivity.java │ │ │ └── res │ │ │ └── values │ │ │ └── strings.xml │ ├── app │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── org │ │ │ │ └── rapid2d │ │ │ │ └── test │ │ │ │ └── MainActivity.java │ │ │ └── res │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle │ ├── common │ ├── cpp │ │ ├── startup.cpp │ │ └── startup.h │ ├── lua │ │ ├── game │ │ │ ├── button.lua │ │ │ ├── case │ │ │ │ ├── testActions.lua │ │ │ │ ├── testAudio.lua │ │ │ │ ├── testCrypto.lua │ │ │ │ ├── testDrawvertex.lua │ │ │ │ └── testFileSystem.lua │ │ │ ├── mainscene.lua │ │ │ └── testBase.lua │ │ ├── main.lua │ │ └── rapid2d │ │ │ ├── action │ │ │ ├── complex.lua │ │ │ ├── ease.lua │ │ │ ├── init.lua │ │ │ ├── manager.lua │ │ │ └── simple.lua │ │ │ ├── audio.lua │ │ │ ├── crypto.lua │ │ │ ├── filesystem.lua │ │ │ ├── init.lua │ │ │ ├── math.lua │ │ │ ├── renderer │ │ │ ├── director.lua │ │ │ ├── drawvertex.lua │ │ │ ├── init.lua │ │ │ ├── label.lua │ │ │ ├── node.lua │ │ │ ├── scene.lua │ │ │ ├── sprite.lua │ │ │ ├── spriteframecache.lua │ │ │ └── texturecache.lua │ │ │ ├── screen.lua │ │ │ ├── string.lua │ │ │ ├── table.lua │ │ │ └── utils.lua │ └── res │ │ ├── audio │ │ ├── bgm.ogg │ │ └── effect.ogg │ │ ├── btnNext.png │ │ ├── btnPrevious.png │ │ ├── pig.json │ │ └── pig.png │ ├── ios │ ├── test.xcodeproj │ │ └── project.pbxproj │ └── test │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── RDGLView.h │ │ ├── RDGLView.m │ │ ├── ViewController.h │ │ ├── ViewController.mm │ │ └── main.m │ ├── mac │ ├── test.xcodeproj │ │ └── project.pbxproj │ └── test │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ └── MainMenu.xib │ │ ├── Info.plist │ │ ├── RDGLView.h │ │ ├── RDGLView.m │ │ ├── main.m │ │ └── test.entitlements │ └── win32 │ ├── ReadMe.txt │ ├── stdafx.cpp │ ├── stdafx.h │ ├── targetver.h │ ├── test.cpp │ ├── test.sln │ ├── test.vcxproj │ ├── test.vcxproj.filters │ └── test.vcxproj.user ├── thirdParty ├── OpenAL │ ├── android │ │ ├── Android.mk │ │ ├── armeabi-v7a │ │ │ ├── libcommon.a │ │ │ └── libopenal.a │ │ ├── armeabi │ │ │ ├── libcommon.a │ │ │ └── libopenal.a │ │ └── x86 │ │ │ ├── libcommon.a │ │ │ └── libopenal.a │ ├── inc │ │ ├── al.h │ │ ├── alc.h │ │ ├── alext.h │ │ ├── efx-creative.h │ │ ├── efx-presets.h │ │ └── efx.h │ └── win32 │ │ ├── OpenAL32.dll │ │ ├── OpenAL32.lib │ │ └── common.lib ├── glew │ ├── inc │ │ └── GL │ │ │ ├── glew.h │ │ │ ├── glxew.h │ │ │ └── wglew.h │ └── win32 │ │ ├── glew32.dll │ │ └── glew32.lib ├── glfw │ ├── inc │ │ └── GLFW │ │ │ ├── glfw3.h │ │ │ └── glfw3native.h │ └── win32 │ │ ├── glfw3.dll │ │ └── glfw3dll.lib ├── png │ ├── android │ │ ├── Android.mk │ │ ├── armeabi-v7a │ │ │ └── libpng.a │ │ ├── armeabi │ │ │ └── libpng.a │ │ └── x86 │ │ │ └── libpng.a │ ├── inc │ │ ├── png.h │ │ ├── pngconf.h │ │ └── pnglibconf.h │ ├── ios │ │ └── libpng.a │ ├── mac │ │ └── libpng.a │ └── win32 │ │ └── libpng.lib └── z │ ├── android │ ├── Android.mk │ ├── armeabi-v7a │ │ └── libz.a │ ├── armeabi │ │ └── libz.a │ └── x86 │ │ └── libz.a │ ├── ios │ └── libz.a │ ├── mac │ └── libz.a │ └── win32 │ ├── zlib.dll │ └── zlib.lib └── tool ├── LuaCompiler.py ├── NDKBuilder.py ├── ProjectCreator.py ├── mac ├── __init__.py ├── luac └── xxtea.so └── win32 ├── __init__.py ├── luac.exe └── xxtea.pyd /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2016 KeNan Liu 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rapid2D - An Open-Source 2D Game Engine 2 | 3 | ## About 4 | 5 | Rapid2D is a pure Lua Game Engine. Graphics rendering is based on OpenGL ES 2.0, Audio output is based on OpenAL. 6 | 7 | Supported platforms: 8 | 9 | * Mac 10 | * iOS 11 | * Windows 12 | * Android 13 | 14 | ## Features 15 | 16 | * Using Lua 5.3 script engine. 17 | * Tree rendering like Cocos2d, but memory managed by Lua. 18 | * All platforms use a unified audio file format: ogg. 19 | * Complete Action system. 20 | * Touch event distribution mechanism based on the display hierarchy. 21 | 22 | ## License 23 | 24 | Rapid2D is released under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html). -------------------------------------------------------------------------------- /core/RDConfig.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDConfig_H__ 16 | #define __RDConfig_H__ 17 | 18 | #include "RDPortingGL.h" 19 | 20 | // engine config, GPU info, etc... 21 | 22 | class RDConfig 23 | { 24 | public: 25 | RDConfig(); 26 | ~RDConfig(); 27 | 28 | static RDConfig *getInstance(void); 29 | void dumpInfo(); 30 | private: 31 | static RDConfig *_instance; 32 | // GL properties 33 | GLint _maxTextureSize; 34 | GLint _maxTextureUnits; 35 | bool _supportsPVRTC; 36 | bool _supportsNPOT; 37 | bool _supportsBGRA8888; 38 | bool _supportsDiscardFramebuffer; 39 | bool _supportsVAO; 40 | 41 | void getGPUInfo(); 42 | bool checkGLExt(const char *searchName); 43 | }; 44 | 45 | #endif // __RDConfig_H__ 46 | -------------------------------------------------------------------------------- /core/RDDirector.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDDirector_H__ 16 | #define __RDDirector_H__ 17 | 18 | #include "RDPortingTime.h" 19 | #include "RDTypes.h" 20 | 21 | typedef enum { 22 | RD_Projection_2D, 23 | }RD_ProjectionType; 24 | 25 | class RDDirector 26 | { 27 | public: 28 | RDDirector(); 29 | ~RDDirector(); 30 | 31 | static RDDirector *getInstance(void); 32 | void start(void); 33 | void stop(void); 34 | // drawScene is call by mainLoop 35 | void drawScene(void); 36 | RDMat4 *getProjection(RD_ProjectionType type); 37 | 38 | private: 39 | static RDDirector *_instance; 40 | static RDMat4 _projection2D; 41 | float _deltaTime; 42 | struct timeval _lastUpdate; 43 | 44 | void initGL(void); 45 | /** calculates delta time since last time it was called */ 46 | void calculateDeltaTime(void); 47 | }; 48 | 49 | #endif // __RDDirector_H__ 50 | -------------------------------------------------------------------------------- /core/RDResolution.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "RDResolution.h" 18 | #include "RDMacros.h" 19 | 20 | RDResolution *RDResolution::_instance = nullptr; 21 | 22 | RDResolution::RDResolution() 23 | :_scale(1) 24 | { 25 | } 26 | 27 | RDResolution::~RDResolution() 28 | { 29 | } 30 | 31 | RDResolution *RDResolution::getInstance(void) 32 | { 33 | if (!_instance) { 34 | _instance = new RDResolution(); 35 | } 36 | return _instance; 37 | } 38 | 39 | void RDResolution::setResolutionModeSize(RD_ResolutionMode mode, float width, float height) 40 | { 41 | if (width == 0.0f || height == 0.0f) { 42 | return; 43 | } 44 | 45 | _resolutionSize.width = width; 46 | _resolutionSize.height = height; 47 | 48 | float scaleX = (float)_frameSize.width / _resolutionSize.width; 49 | float scaleY = (float)_frameSize.height / _resolutionSize.height; 50 | 51 | if ( mode == RD_Resolution_FixedHeight) { 52 | _scale = scaleY; 53 | _resolutionSize.width = ceilf(_frameSize.width / _scale); 54 | } 55 | 56 | if ( mode == RD_Resolution_FixedWidth) { 57 | _scale = scaleX; 58 | _resolutionSize.height = ceilf(_frameSize.height / _scale); 59 | } 60 | 61 | _mode = mode; 62 | } 63 | 64 | const RDSize &RDResolution::getResolutionSize(void) 65 | { 66 | return _resolutionSize; 67 | } 68 | 69 | const RDSize &RDResolution::getFrameSize(void) 70 | { 71 | return _frameSize; 72 | } 73 | 74 | void RDResolution::setFrameSize(float width, float height) 75 | { 76 | glViewport(0, 0, width, height); 77 | _frameSize.width = width; 78 | _frameSize.height = height; 79 | } 80 | -------------------------------------------------------------------------------- /core/RDResolution.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDResolution_H__ 16 | #define __RDResolution_H__ 17 | 18 | #include "RDTypes.h" 19 | 20 | typedef enum { 21 | RD_Resolution_FixedHeight, 22 | RD_Resolution_FixedWidth, 23 | RD_Resolution_UnKnown, 24 | }RD_ResolutionMode; 25 | 26 | class RDResolution 27 | { 28 | public: 29 | RDResolution(); 30 | ~RDResolution(); 31 | 32 | static RDResolution *getInstance(void); 33 | 34 | /* 35 | * Get the frame size of EGL view. 36 | * In general, it returns the screen size since the EGL view is a fullscreen view. 37 | */ 38 | const RDSize &getFrameSize(void); 39 | 40 | void setFrameSize(float width, float height); 41 | 42 | void setResolutionModeSize(RD_ResolutionMode mode, float width, float height); 43 | 44 | /* Get design resolution size. 45 | * Default resolution size is the same as 'getFrameSize'. 46 | */ 47 | const RDSize &getResolutionSize(void); 48 | 49 | float getScale() {return _scale;}; 50 | private: 51 | static RDResolution *_instance; 52 | 53 | // in full screen, _frameSize == screenSize 54 | RDSize _frameSize; 55 | // resolution size, it is the size appropriate for the app resources. 56 | RDSize _resolutionSize; 57 | RD_ResolutionMode _mode; 58 | float _scale; 59 | }; 60 | 61 | #endif /* __RDResolution_H__ */ 62 | -------------------------------------------------------------------------------- /core/Rapid2D.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "Rapid2D.h" 16 | #include "RDResolution.h" 17 | #include "RDDirector.h" 18 | #include "RDLog.h" 19 | #include "RDFileSystem.h" 20 | #include "RDLua.h" 21 | #include "RDConfig.h" 22 | #include "RDAudio.h" 23 | 24 | const char * Rapid2D_Version() 25 | { 26 | return "Rapid2D 0.1"; 27 | } 28 | 29 | void Rapid2D_setFrameSize(float width, float height) 30 | { 31 | RDResolution::getInstance()->setFrameSize(width, height); 32 | } 33 | 34 | void Rapid2D_setResolutionModeSize(unsigned int mode, float width, float height) 35 | { 36 | if (mode >= RD_Resolution_UnKnown) { 37 | RDLog("[Error]:Resolution mode must be 0 or 1\n"); 38 | return; 39 | } 40 | RDResolution::getInstance()->setResolutionModeSize((RD_ResolutionMode)mode, width, height); 41 | } 42 | 43 | void Rapid2D_start(const char *name, const char *key) 44 | { 45 | // init OpenAL 46 | RDAudio_init(); 47 | // dump GPU info 48 | RDConfig::getInstance()->dumpInfo(); 49 | // init lua binding 50 | RDLuaInit(name, key); 51 | // start main loop 52 | RDDirector::getInstance()->start(); 53 | } 54 | 55 | void Rapid2D_stop(void) 56 | { 57 | RDDirector::getInstance()->stop(); 58 | } 59 | 60 | // IMPORTANT: make sure this is call fram MAIN THREAD 61 | void Rapid2D_touchEvent(char *type, int count, intptr_t ids[], float xs[], float ys[]) 62 | { 63 | RDLuaTouchEvent(type, count, ids, xs, ys); 64 | } 65 | 66 | // IMPORTANT: make sure this is call fram MAIN THREAD 67 | void Rapid2D_keyBoardEvent(char *type, int keyCode) 68 | { 69 | RDLuaKeyBoardEvent(type, keyCode); 70 | } 71 | -------------------------------------------------------------------------------- /core/Rapid2D.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __Rapid2D_H__ 16 | #define __Rapid2D_H__ 17 | 18 | // API for startup in project directory 19 | // hide engine detail 20 | 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | const char * Rapid2D_Version(); 28 | void Rapid2D_setFrameSize(float width, float height); 29 | // mode: 30 | // 0 , FixedHeight 31 | // 1 , FixedWidth 32 | void Rapid2D_setResolutionModeSize(unsigned int mode, float width, float height); 33 | /* name: game chunks, locate in RD_FILEDIR_RES top level 34 | * if NULL, load from discrete files 35 | * key: is for xxtea decrypt 36 | */ 37 | void Rapid2D_start(const char *name, const char *key); 38 | void Rapid2D_stop(void); 39 | 40 | /**************** for porting ******************/ 41 | 42 | /* type 43 | * "began" 44 | * "moved" 45 | * "ended" 46 | * IMPORTANT: make sure this is call fram MAIN THREAD 47 | */ 48 | void Rapid2D_touchEvent(char *type, int count, intptr_t ids[], float xs[], float ys[]); 49 | 50 | /* type 51 | * "down" 52 | * "up" 53 | * IMPORTANT: make sure this is call fram MAIN THREAD 54 | * keyCode see "glfw3.h" 55 | */ 56 | void Rapid2D_keyBoardEvent(char *type, int keyCode); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif // __Rapid2D_H__ 63 | -------------------------------------------------------------------------------- /core/audio/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := static_Rapid2DAudio 6 | 7 | LOCAL_MODULE_FILENAME := libRapid2DAudio 8 | 9 | LOCAL_CFLAGS := -DRD_PLATFORM_ANDROID 10 | 11 | LOCAL_C_INCLUDES := $(LOCAL_PATH) \ 12 | $(LOCAL_PATH)/libogg \ 13 | $(LOCAL_PATH)/libvorbis/lib \ 14 | $(LOCAL_PATH)/libvorbis \ 15 | $(LOCAL_PATH)/../math \ 16 | $(LOCAL_PATH)/../porting/inc \ 17 | $(LOCAL_PATH)/../utils \ 18 | $(LOCAL_PATH)/../../thirdParty/OpenAL/inc 19 | 20 | # audio 21 | LOCAL_SRC_FILES := \ 22 | RDAudio.cpp \ 23 | RDAudioOgg.cpp 24 | # libogg 25 | LOCAL_SRC_FILES += \ 26 | libogg/src/bitwise.c \ 27 | libogg/src/framing.c 28 | # libvorbis 29 | LOCAL_SRC_FILES += \ 30 | libvorbis/lib/analysis.c \ 31 | libvorbis/lib/barkmel.c \ 32 | libvorbis/lib/bitrate.c \ 33 | libvorbis/lib/block.c \ 34 | libvorbis/lib/codebook.c \ 35 | libvorbis/lib/envelope.c \ 36 | libvorbis/lib/floor0.c \ 37 | libvorbis/lib/floor1.c \ 38 | libvorbis/lib/info.c \ 39 | libvorbis/lib/lookup.c \ 40 | libvorbis/lib/lpc.c \ 41 | libvorbis/lib/lsp.c \ 42 | libvorbis/lib/mapping0.c \ 43 | libvorbis/lib/mdct.c \ 44 | libvorbis/lib/psy.c \ 45 | libvorbis/lib/registry.c \ 46 | libvorbis/lib/res0.c \ 47 | libvorbis/lib/sharedbook.c \ 48 | libvorbis/lib/smallft.c \ 49 | libvorbis/lib/synthesis.c \ 50 | libvorbis/lib/tone.c \ 51 | libvorbis/lib/vorbisenc.c \ 52 | libvorbis/lib/vorbisfile.c \ 53 | libvorbis/lib/window.c 54 | 55 | include $(BUILD_STATIC_LIBRARY) 56 | -------------------------------------------------------------------------------- /core/audio/RDAudio.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDAudio_H__ 16 | #define __RDAudio_H__ 17 | 18 | #include "RDTypes.h" 19 | 20 | /****** For iOS ********/ 21 | #ifdef RD_PLATFORM_IOS 22 | #include 23 | #endif // end of RD_PLATFORM_IOS 24 | 25 | /****** For Mac ********/ 26 | #ifdef RD_PLATFORM_MAC 27 | #include 28 | #endif // end of RD_PLATFORM_MAC 29 | 30 | /****** For Win32 ********/ 31 | #ifdef RD_PLATFORM_WIN32 32 | #include "alext.h" 33 | #endif // end of RD_PLATFORM_WIN32 34 | 35 | /****** For Android ********/ 36 | #ifdef RD_PLATFORM_ANDROID 37 | #include "alext.h" 38 | #endif // end of RD_PLATFORM_ANDROID 39 | 40 | typedef struct RDPcmData { 41 | RD_uchar *data; 42 | RD_int32 channels; 43 | RD_int32 rate; 44 | size_t size; 45 | } RDPcmData; 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | void RDAudio_init(void); 52 | /* return bufferID, if 0 fail */ 53 | ALuint RDAudio_LoadFile(const char *path); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif // __RDAudio_H__ 60 | -------------------------------------------------------------------------------- /core/audio/RDAudioOgg.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDAudioOgg_H__ 16 | #define __RDAudioOgg_H__ 17 | 18 | #include "RDAudio.h" 19 | #include "RDData.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | int decodeOgg(RDData *data, RDPcmData *pcm); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif // __RDAudioOgg_H__ 32 | -------------------------------------------------------------------------------- /core/audio/libogg/ogg/os_types.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: #ifdef jail to whip a few platforms into the UNIX ideal. 14 | last mod: $Id: os_types.h 19098 2014-02-26 19:06:45Z giles $ 15 | 16 | ********************************************************************/ 17 | #ifndef _OS_TYPES_H 18 | #define _OS_TYPES_H 19 | 20 | #include "RDPortingTypes.h" 21 | 22 | /* make it easy on the folks that want to compile the libs with a 23 | different malloc than stdlib */ 24 | #define _ogg_malloc malloc 25 | #define _ogg_calloc calloc 26 | #define _ogg_realloc realloc 27 | #define _ogg_free free 28 | 29 | typedef RD_int16 ogg_int16_t; 30 | typedef RD_uint16 ogg_uint16_t; 31 | typedef RD_int32 ogg_int32_t; 32 | typedef RD_uint32 ogg_uint32_t; 33 | typedef RD_int64 ogg_int64_t; 34 | typedef RD_uint64 ogg_uint64_t; 35 | 36 | #endif /* _OS_TYPES_H */ 37 | -------------------------------------------------------------------------------- /core/audio/libvorbis/lib/bitrate.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: bitrate tracking and management 14 | last mod: $Id: bitrate.h 13293 2007-07-24 00:09:47Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_BITRATE_H_ 19 | #define _V_BITRATE_H_ 20 | 21 | #include "vorbis/codec.h" 22 | #include "codec_internal.h" 23 | #include "os.h" 24 | 25 | /* encode side bitrate tracking */ 26 | typedef struct bitrate_manager_state { 27 | int managed; 28 | 29 | long avg_reservoir; 30 | long minmax_reservoir; 31 | long avg_bitsper; 32 | long min_bitsper; 33 | long max_bitsper; 34 | 35 | long short_per_long; 36 | double avgfloat; 37 | 38 | vorbis_block *vb; 39 | int choice; 40 | } bitrate_manager_state; 41 | 42 | typedef struct bitrate_manager_info{ 43 | long avg_rate; 44 | long min_rate; 45 | long max_rate; 46 | long reservoir_bits; 47 | double reservoir_bias; 48 | 49 | double slew_damp; 50 | 51 | } bitrate_manager_info; 52 | 53 | extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs); 54 | extern void vorbis_bitrate_clear(bitrate_manager_state *bs); 55 | extern int vorbis_bitrate_managed(vorbis_block *vb); 56 | extern int vorbis_bitrate_addblock(vorbis_block *vb); 57 | extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /core/audio/libvorbis/lib/highlevel.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: highlevel encoder setup struct separated out for vorbisenc clarity 14 | last mod: $Id: highlevel.h 17195 2010-05-05 21:49:51Z giles $ 15 | 16 | ********************************************************************/ 17 | 18 | typedef struct highlevel_byblocktype { 19 | double tone_mask_setting; 20 | double tone_peaklimit_setting; 21 | double noise_bias_setting; 22 | double noise_compand_setting; 23 | } highlevel_byblocktype; 24 | 25 | typedef struct highlevel_encode_setup { 26 | int set_in_stone; 27 | const void *setup; 28 | double base_setting; 29 | 30 | double impulse_noisetune; 31 | 32 | /* bitrate management below all settable */ 33 | float req; 34 | int managed; 35 | long bitrate_min; 36 | long bitrate_av; 37 | double bitrate_av_damp; 38 | long bitrate_max; 39 | long bitrate_reservoir; 40 | double bitrate_reservoir_bias; 41 | 42 | int impulse_block_p; 43 | int noise_normalize_p; 44 | int coupling_p; 45 | 46 | double stereo_point_setting; 47 | double lowpass_kHz; 48 | int lowpass_altered; 49 | 50 | double ath_floating_dB; 51 | double ath_absolute_dB; 52 | 53 | double amplitude_track_dBpersec; 54 | double trigger_setting; 55 | 56 | highlevel_byblocktype block[4]; /* padding, impulse, transition, long */ 57 | 58 | } highlevel_encode_setup; 59 | -------------------------------------------------------------------------------- /core/audio/libvorbis/lib/lookup.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: lookup based functions 14 | last mod: $Id: lookup.h 16227 2009-07-08 06:58:46Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_LOOKUP_H_ 19 | 20 | #ifdef FLOAT_LOOKUP 21 | extern float vorbis_coslook(float a); 22 | extern float vorbis_invsqlook(float a); 23 | extern float vorbis_invsq2explook(int a); 24 | extern float vorbis_fromdBlook(float a); 25 | #endif 26 | #ifdef INT_LOOKUP 27 | extern long vorbis_invsqlook_i(long a,long e); 28 | extern long vorbis_coslook_i(long a); 29 | extern float vorbis_fromdBlook_i(long a); 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /core/audio/libvorbis/lib/lpc.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: LPC low level routines 14 | last mod: $Id: lpc.h 16037 2009-05-26 21:10:58Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_LPC_H_ 19 | #define _V_LPC_H_ 20 | 21 | #include "vorbis/codec.h" 22 | 23 | /* simple linear scale LPC code */ 24 | extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m); 25 | 26 | extern void vorbis_lpc_predict(float *coeff,float *prime,int m, 27 | float *data,long n); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /core/audio/libvorbis/lib/lsp.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: LSP (also called LSF) conversion routines 14 | last mod: $Id: lsp.h 16227 2009-07-08 06:58:46Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | 19 | #ifndef _V_LSP_H_ 20 | #define _V_LSP_H_ 21 | 22 | extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m); 23 | 24 | extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln, 25 | float *lsp,int m, 26 | float amp,float ampoffset); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /core/audio/libvorbis/lib/mdct.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: modified discrete cosine transform prototypes 14 | last mod: $Id: mdct.h 16227 2009-07-08 06:58:46Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _OGG_mdct_H_ 19 | #define _OGG_mdct_H_ 20 | 21 | #include "vorbis/codec.h" 22 | 23 | 24 | 25 | 26 | 27 | /*#define MDCT_INTEGERIZED <- be warned there could be some hurt left here*/ 28 | #ifdef MDCT_INTEGERIZED 29 | 30 | #define DATA_TYPE int 31 | #define REG_TYPE register int 32 | #define TRIGBITS 14 33 | #define cPI3_8 6270 34 | #define cPI2_8 11585 35 | #define cPI1_8 15137 36 | 37 | #define FLOAT_CONV(x) ((int)((x)*(1<>TRIGBITS) 39 | #define HALVE(x) ((x)>>1) 40 | 41 | #else 42 | 43 | #define DATA_TYPE float 44 | #define REG_TYPE float 45 | #define cPI3_8 .38268343236508977175F 46 | #define cPI2_8 .70710678118654752441F 47 | #define cPI1_8 .92387953251128675613F 48 | 49 | #define FLOAT_CONV(x) (x) 50 | #define MULT_NORM(x) (x) 51 | #define HALVE(x) ((x)*.5f) 52 | 53 | #endif 54 | 55 | 56 | typedef struct { 57 | int n; 58 | int log2n; 59 | 60 | DATA_TYPE *trig; 61 | int *bitrev; 62 | 63 | DATA_TYPE scale; 64 | } mdct_lookup; 65 | 66 | extern void mdct_init(mdct_lookup *lookup,int n); 67 | extern void mdct_clear(mdct_lookup *l); 68 | extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out); 69 | extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out); 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /core/audio/libvorbis/lib/misc.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: miscellaneous prototypes 14 | last mod: $Id: misc.h 19457 2015-03-03 00:15:29Z giles $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_RANDOM_H_ 19 | #define _V_RANDOM_H_ 20 | #include "vorbis/codec.h" 21 | 22 | extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes); 23 | extern void _vorbis_block_ripcord(vorbis_block *vb); 24 | extern int ov_ilog(ogg_uint32_t v); 25 | 26 | #ifdef ANALYSIS 27 | extern int analysis_noisy; 28 | extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB, 29 | ogg_int64_t off); 30 | extern void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB, 31 | ogg_int64_t off); 32 | #endif 33 | 34 | #ifdef DEBUG_MALLOC 35 | 36 | #define _VDBG_GRAPHFILE "malloc.m" 37 | #undef _VDBG_GRAPHFILE 38 | extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line); 39 | extern void _VDBG_free(void *ptr,char *file,long line); 40 | 41 | #ifndef MISC_C 42 | #undef _ogg_malloc 43 | #undef _ogg_calloc 44 | #undef _ogg_realloc 45 | #undef _ogg_free 46 | 47 | #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__) 48 | #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__) 49 | #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__) 50 | #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__) 51 | #endif 52 | #endif 53 | 54 | #endif 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /core/audio/libvorbis/lib/modes/setup_44p51.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2010 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: toplevel settings for 44.1/48kHz 5.1 surround modes 14 | last mod: $Id: setup_44p51.h 19013 2013-11-12 04:04:50Z giles $ 15 | 16 | ********************************************************************/ 17 | 18 | #include "modes/residue_44p51.h" 19 | 20 | static const double rate_mapping_44p51[12]={ 21 | 14000.,20000.,28000.,38000.,46000.,54000., 22 | 75000.,96000.,120000.,140000.,180000.,240001. 23 | }; 24 | 25 | static const ve_setup_data_template ve_setup_44_51={ 26 | 11, 27 | rate_mapping_44p51, 28 | quality_mapping_44, 29 | 6, 30 | 40000, 31 | 70000, 32 | 33 | blocksize_short_44, 34 | blocksize_long_44, 35 | 36 | _psy_tone_masteratt_44, 37 | _psy_tone_0dB, 38 | _psy_tone_suppress, 39 | 40 | _vp_tonemask_adj_otherblock, 41 | _vp_tonemask_adj_longblock, 42 | _vp_tonemask_adj_otherblock, 43 | 44 | _psy_noiseguards_44, 45 | _psy_noisebias_impulse, 46 | _psy_noisebias_padding, 47 | _psy_noisebias_trans, 48 | _psy_noisebias_long, 49 | _psy_noise_suppress, 50 | 51 | _psy_compand_44, 52 | _psy_compand_short_mapping, 53 | _psy_compand_long_mapping, 54 | 55 | {_noise_start_short_44,_noise_start_long_44}, 56 | {_noise_part_short_44,_noise_part_long_44}, 57 | _noise_thresh_44, 58 | 59 | _psy_ath_floater, 60 | _psy_ath_abs, 61 | 62 | _psy_lowpass_44, 63 | 64 | _psy_global_44, 65 | _global_mapping_44, 66 | _psy_stereo_modes_44, 67 | 68 | _floor_books, 69 | _floor, 70 | 3, 71 | _floor_mapping_44, 72 | 73 | _mapres_template_44_51 74 | }; 75 | -------------------------------------------------------------------------------- /core/audio/libvorbis/lib/modes/setup_44u.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: toplevel settings for 44.1/48kHz uncoupled modes 14 | last mod: $Id: setup_44u.h 16962 2010-03-11 07:30:34Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #include "modes/residue_44u.h" 19 | 20 | static const double rate_mapping_44_un[12]={ 21 | 32000.,48000.,60000.,70000.,80000.,86000., 22 | 96000.,110000.,120000.,140000.,160000.,240001. 23 | }; 24 | 25 | static const ve_setup_data_template ve_setup_44_uncoupled={ 26 | 11, 27 | rate_mapping_44_un, 28 | quality_mapping_44, 29 | -1, 30 | 40000, 31 | 50000, 32 | 33 | blocksize_short_44, 34 | blocksize_long_44, 35 | 36 | _psy_tone_masteratt_44, 37 | _psy_tone_0dB, 38 | _psy_tone_suppress, 39 | 40 | _vp_tonemask_adj_otherblock, 41 | _vp_tonemask_adj_longblock, 42 | _vp_tonemask_adj_otherblock, 43 | 44 | _psy_noiseguards_44, 45 | _psy_noisebias_impulse, 46 | _psy_noisebias_padding, 47 | _psy_noisebias_trans, 48 | _psy_noisebias_long, 49 | _psy_noise_suppress, 50 | 51 | _psy_compand_44, 52 | _psy_compand_short_mapping, 53 | _psy_compand_long_mapping, 54 | 55 | {_noise_start_short_44,_noise_start_long_44}, 56 | {_noise_part_short_44,_noise_part_long_44}, 57 | _noise_thresh_44, 58 | 59 | _psy_ath_floater, 60 | _psy_ath_abs, 61 | 62 | _psy_lowpass_44, 63 | 64 | _psy_global_44, 65 | _global_mapping_44, 66 | _psy_stereo_modes_44, 67 | 68 | _floor_books, 69 | _floor, 70 | 2, 71 | _floor_mapping_44, 72 | 73 | _mapres_template_44_uncoupled 74 | }; 75 | -------------------------------------------------------------------------------- /core/audio/libvorbis/lib/registry.c: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: registry for time, floor, res backends and channel mappings 14 | last mod: $Id: registry.c 16227 2009-07-08 06:58:46Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #include "vorbis/codec.h" 19 | #include "codec_internal.h" 20 | #include "registry.h" 21 | #include "misc.h" 22 | /* seems like major overkill now; the backend numbers will grow into 23 | the infrastructure soon enough */ 24 | 25 | extern const vorbis_func_floor floor0_exportbundle; 26 | extern const vorbis_func_floor floor1_exportbundle; 27 | extern const vorbis_func_residue residue0_exportbundle; 28 | extern const vorbis_func_residue residue1_exportbundle; 29 | extern const vorbis_func_residue residue2_exportbundle; 30 | extern const vorbis_func_mapping mapping0_exportbundle; 31 | 32 | const vorbis_func_floor *const _floor_P[]={ 33 | &floor0_exportbundle, 34 | &floor1_exportbundle, 35 | }; 36 | 37 | const vorbis_func_residue *const _residue_P[]={ 38 | &residue0_exportbundle, 39 | &residue1_exportbundle, 40 | &residue2_exportbundle, 41 | }; 42 | 43 | const vorbis_func_mapping *const _mapping_P[]={ 44 | &mapping0_exportbundle, 45 | }; 46 | -------------------------------------------------------------------------------- /core/audio/libvorbis/lib/registry.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: registry for time, floor, res backends and channel mappings 14 | last mod: $Id: registry.h 15531 2008-11-24 23:50:06Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_REG_H_ 19 | #define _V_REG_H_ 20 | 21 | #define VI_TRANSFORMB 1 22 | #define VI_WINDOWB 1 23 | #define VI_TIMEB 1 24 | #define VI_FLOORB 2 25 | #define VI_RESB 3 26 | #define VI_MAPB 1 27 | 28 | extern const vorbis_func_floor *const _floor_P[]; 29 | extern const vorbis_func_residue *const _residue_P[]; 30 | extern const vorbis_func_mapping *const _mapping_P[]; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /core/audio/libvorbis/lib/smallft.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: fft transform 14 | last mod: $Id: smallft.h 13293 2007-07-24 00:09:47Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_SMFT_H_ 19 | #define _V_SMFT_H_ 20 | 21 | #include "vorbis/codec.h" 22 | 23 | typedef struct { 24 | int n; 25 | float *trigcache; 26 | int *splitcache; 27 | } drft_lookup; 28 | 29 | extern void drft_forward(drft_lookup *l,float *data); 30 | extern void drft_backward(drft_lookup *l,float *data); 31 | extern void drft_init(drft_lookup *l,int n); 32 | extern void drft_clear(drft_lookup *l); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /core/audio/libvorbis/lib/tone.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #if defined(RD_PLATFORM_WIN32) 7 | #define M_PI (3.14159265358) 8 | #endif 9 | 10 | void usage(){ 11 | fprintf(stderr,"tone ,[] [,[]...]\n"); 12 | exit(1); 13 | } 14 | 15 | int main (int argc,char *argv[]){ 16 | int i,j; 17 | double *f; 18 | double *amp; 19 | 20 | if(argc<2)usage(); 21 | 22 | f=alloca(sizeof(*f)*(argc-1)); 23 | amp=alloca(sizeof(*amp)*(argc-1)); 24 | 25 | i=0; 26 | while(argv[i+1]){ 27 | char *pos=strchr(argv[i+1],','); 28 | 29 | f[i]=atof(argv[i+1]); 30 | if(pos) 31 | amp[i]=atof(pos+1)*32767.f; 32 | else 33 | amp[i]=32767.f; 34 | 35 | fprintf(stderr,"%g Hz, %g amp\n",f[i],amp[i]); 36 | 37 | i++; 38 | } 39 | 40 | for(i=0;i<44100*10;i++){ 41 | float val=0; 42 | int ival; 43 | for(j=0;j32767.f)ival=32767.f; 48 | if(ival<-32768.f)ival=-32768.f; 49 | 50 | fprintf(stdout,"%c%c%c%c", 51 | (char)(ival&0xff), 52 | (char)((ival>>8)&0xff), 53 | (char)(ival&0xff), 54 | (char)((ival>>8)&0xff)); 55 | } 56 | return(0); 57 | } 58 | 59 | -------------------------------------------------------------------------------- /core/audio/libvorbis/lib/window.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: window functions 14 | last mod: $Id: window.h 19028 2013-12-02 23:23:39Z tterribe $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_WINDOW_ 19 | #define _V_WINDOW_ 20 | 21 | extern const float *_vorbis_window_get(int n); 22 | extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes, 23 | int lW,int W,int nW); 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /core/crypto/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. 3 | * MD5 Message-Digest Algorithm (RFC 1321). 4 | * 5 | * Homepage: 6 | * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 7 | * 8 | * Author: 9 | * Alexander Peslyak, better known as Solar Designer 10 | * 11 | * This software was written by Alexander Peslyak in 2001. No copyright is 12 | * claimed, and the software is hereby placed in the public domain. 13 | * In case this attempt to disclaim copyright and place the software in the 14 | * public domain is deemed null and void, then the software is 15 | * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the 16 | * general public under the following terms: 17 | * 18 | * Redistribution and use in source and binary forms, with or without 19 | * modification, are permitted. 20 | * 21 | * There's ABSOLUTELY NO WARRANTY, express or implied. 22 | * 23 | * See md5.c for more information. 24 | */ 25 | 26 | #ifdef HAVE_OPENSSL 27 | #include 28 | #elif !defined(_MD5_H) 29 | #define _MD5_H 30 | 31 | /* Any 32-bit or wider unsigned integer data type will do */ 32 | typedef unsigned int MD5_u32plus; 33 | 34 | typedef struct { 35 | MD5_u32plus lo, hi; 36 | MD5_u32plus a, b, c, d; 37 | unsigned char buffer[64]; 38 | MD5_u32plus block[16]; 39 | } MD5_CTX; 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | void MD5_Init(MD5_CTX *ctx); 46 | void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size); 47 | void MD5_Final(unsigned char *result, MD5_CTX *ctx); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /core/crypto/xxtea.h: -------------------------------------------------------------------------------- 1 | /**********************************************************\ 2 | | | 3 | | xxtea.h | 4 | | | 5 | | XXTEA encryption algorithm library for C. | 6 | | | 7 | | Encryption Algorithm Authors: | 8 | | David J. Wheeler | 9 | | Roger M. Needham | 10 | | | 11 | | Code Authors: Chen fei | 12 | | Ma Bingyao | 13 | | LastModified: Mar 3, 2015 | 14 | | | 15 | \**********************************************************/ 16 | 17 | #ifndef XXTEA_INCLUDED 18 | #define XXTEA_INCLUDED 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /** 27 | * Function: xxtea_encrypt 28 | * @data: Data to be encrypted 29 | * @len: Length of the data to be encrypted 30 | * @key: Symmetric key 31 | * @out_len: Pointer to output length variable 32 | * Returns: Encrypted data or %NULL on failure 33 | * 34 | * Caller is responsible for freeing the returned buffer. 35 | */ 36 | void * xxtea_encrypt(const void * data, size_t len, const void * key, size_t * out_len); 37 | 38 | /** 39 | * Function: xxtea_decrypt 40 | * @data: Data to be decrypted 41 | * @len: Length of the data to be decrypted 42 | * @key: Symmetric key 43 | * @out_len: Pointer to output length variable 44 | * Returns: Decrypted data or %NULL on failure 45 | * 46 | * Caller is responsible for freeing the returned buffer. 47 | */ 48 | void * xxtea_decrypt(const void * data, size_t len, const void * key, size_t * out_len); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /core/math/RDMath.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDMath_H__ 16 | #define __RDMath_H__ 17 | 18 | // wrap from cocos3d 19 | 20 | #include "RDkmMath.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /* =================== below for projection ===================== */ 27 | // fill mat4 with a parallel projection matrix. 28 | void RDMath_OrthographicProjection(RDMat4 *mat4, 29 | GLfloat left, 30 | GLfloat right, 31 | GLfloat bottom, 32 | GLfloat top, 33 | GLfloat near, 34 | GLfloat far); 35 | // fill mat4 with a perspective projection matrix. 36 | void RDMath_PerspectiveProjection(RDMat4 *mat4, 37 | GLfloat left, 38 | GLfloat right, 39 | GLfloat bottom, 40 | GLfloat top, 41 | GLfloat near, 42 | GLfloat far); 43 | 44 | /* =================== below for ModelView ===================== */ 45 | void RDMath_modelView(RDMat4 *pOut, RDVec3 *translation, RDVec3 *rotation, RDVec3 *scale); 46 | 47 | /* ===== color ====== */ 48 | // init color by RGBA 49 | void RDColorInit(RDColor *color, RD_uchar r, RD_uchar g, RD_uchar b, RD_uchar a); 50 | // rdcolor Range in [0, 255], glcolor Range in [0, 1] 51 | void RDColorToGL(RDColor *rdcolor, RDGLColor *glColor); 52 | 53 | /* ===== RDVec3 ====== */ 54 | RDVec3 RDVec3Make(GLfloat x, GLfloat y, GLfloat z); 55 | 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif // __RDMath_H__ 62 | -------------------------------------------------------------------------------- /core/math/RDTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDTypes_H__ 16 | #define __RDTypes_H__ 17 | 18 | #include "RDPortingTypes.h" 19 | #include "RDPortingGL.h" 20 | 21 | typedef struct { 22 | GLfloat x; 23 | GLfloat y; 24 | } RDPoint; 25 | 26 | typedef struct { 27 | GLfloat width; 28 | GLfloat height; 29 | } RDSize; 30 | 31 | typedef struct { 32 | RDPoint origin; 33 | RDSize size; 34 | } RDRect; 35 | 36 | /* A three-dimensional vector. OpenGL coordinate */ 37 | typedef struct { 38 | GLfloat x; 39 | GLfloat y; 40 | GLfloat z; 41 | } RDVec3; 42 | 43 | /* Rapid2D color, [0, 255] */ 44 | typedef struct { 45 | RD_uchar r; 46 | RD_uchar g; 47 | RD_uchar b; 48 | RD_uchar a; 49 | } RDColor; 50 | 51 | /* OpenGL color, [0, 1] */ 52 | typedef struct { 53 | GLfloat r; 54 | GLfloat g; 55 | GLfloat b; 56 | GLfloat a; 57 | } RDGLColor; 58 | 59 | /* OpenGL Texture coordinate */ 60 | typedef struct { 61 | GLfloat s; 62 | GLfloat t; 63 | } RDTexCoord; 64 | 65 | /* A rotational quaternion */ 66 | typedef struct { 67 | GLfloat x; 68 | GLfloat y; 69 | GLfloat z; 70 | GLfloat w; 71 | } RDQuaternion; 72 | 73 | /* A standard 4x4 matrix */ 74 | typedef struct { 75 | GLfloat mat[16]; 76 | } RDMat4; 77 | 78 | typedef struct { 79 | RDVec3 position; 80 | RDGLColor color; 81 | } RDBasicVertex; 82 | 83 | typedef struct { 84 | RDVec3 position; 85 | RDGLColor color; 86 | RDTexCoord texcoord; 87 | } RDVertex; 88 | 89 | 90 | #endif // __RDTypes_H__ 91 | -------------------------------------------------------------------------------- /core/porting/android/RDPortingPrint.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include "RDPortingPrint.h" 17 | #include 18 | #include 19 | 20 | #define RD_MAX_LOG_LENGTH (1024) 21 | #define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, "Rapid2D_LOG", __VA_ARGS__) 22 | 23 | 24 | void RDPortingPrint_log(const char *format, va_list args) 25 | { 26 | char buf[RD_MAX_LOG_LENGTH]; 27 | memset(buf, 0, sizeof(char)* RD_MAX_LOG_LENGTH); 28 | vsnprintf(buf, RD_MAX_LOG_LENGTH, format, args); 29 | 30 | LOGV("%s", buf); 31 | } 32 | -------------------------------------------------------------------------------- /core/porting/android/RDPortingSystem.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "RDPortingSystem.h" 16 | 17 | void RDPortingSystem_OpenUrl(const char *url) 18 | { 19 | // 20 | } 21 | -------------------------------------------------------------------------------- /core/porting/android/RDRDPortingMainLoop.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "RDPortingMainLoop.h" 16 | 17 | extern void *g_mainFrameCB; 18 | void RDPortingMainLoop_start(RDPortingMainLoopCB cb) 19 | { 20 | g_mainFrameCB = (void *)cb; 21 | } 22 | 23 | void RDPortingMainLoop_stop(void) 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /core/porting/android/c2java.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include "c2java.h" 19 | 20 | static JavaVM *s_vm=NULL; 21 | static JNIEnv *s_env = NULL; 22 | 23 | JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) 24 | { 25 | // cache vm, DO NOT cache env here, otherwise ndk crash. 26 | s_vm = vm; 27 | return JNI_VERSION_1_4; 28 | } 29 | 30 | int c2java_getStaticInfo(const char *classname, 31 | const char *func, 32 | const char *param, 33 | c2java_info *info) 34 | { 35 | jclass cclass; 36 | jmethodID methodID;//If staticMethodID, do not release local ref. 37 | 38 | // cache env in GLThread 39 | if (NULL == s_env) { 40 | if(s_vm->GetEnv((void**)&s_env, JNI_VERSION_1_4) != JNI_OK) { 41 | __android_log_print(ANDROID_LOG_VERBOSE, "Rapid2D_LOG", 42 | "Error: c2java fail for GetEnv!"); 43 | return -1; 44 | } 45 | } 46 | 47 | // java class -> c class 48 | cclass = s_env->FindClass(classname); 49 | if (cclass == NULL) { 50 | __android_log_print(ANDROID_LOG_INFO, "Rapid2D_LOG", "c2java FindClass error"); 51 | return -2; 52 | } 53 | 54 | // get method 55 | methodID = s_env->GetStaticMethodID(cclass, func, param); 56 | if (methodID == NULL) { 57 | s_env->DeleteLocalRef(cclass); 58 | __android_log_print(ANDROID_LOG_INFO, "Rapid2D_LOG", "c2java GetMethodID error"); 59 | return -3; 60 | } 61 | 62 | info->env = s_env; 63 | info->method = methodID; 64 | info->cls = cclass; 65 | /* info->obj = NULL; */ 66 | 67 | return 0; 68 | } 69 | 70 | 71 | void c2java_release(c2java_info *info) 72 | { 73 | /* if (info->obj) { */ 74 | /* (info->env)->DeleteLocalRef(info->obj); */ 75 | /* } */ 76 | 77 | if (info->cls) { 78 | (info->env)->DeleteLocalRef(info->cls); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /core/porting/android/c2java.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __C2JAVA_H__ 16 | #define __C2JAVA_H__ 17 | 18 | #include 19 | 20 | typedef struct { 21 | JNIEnv *env; 22 | jclass cls; 23 | //jobject obj;// for non static method 24 | jmethodID method; 25 | } c2java_info; 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | int c2java_getStaticInfo(const char *classname, 32 | const char *func, 33 | const char *param, 34 | c2java_info *info); 35 | 36 | void c2java_release(c2java_info *info); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif // end of __C2JAVA_H__ 43 | -------------------------------------------------------------------------------- /core/porting/inc/RDPortingFile.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDPortingFile_h__ 16 | #define __RDPortingFile_h__ 17 | 18 | #include "RDPortingTypes.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /* return file buffer, need release by core. 25 | * if isTextMode, return a buffer terminal by \0 26 | */ 27 | RD_uchar *RDPortingFile_getData(const char *fullPath, bool isTextMode, size_t *outSize); 28 | 29 | /* write buffer to file, binary mode 30 | * return wrote size 31 | */ 32 | size_t RDPortingFile_putData(const char *fullPath, RD_uchar *buffer, size_t size); 33 | 34 | /* a Writable directory in sandbox for mobile app. 35 | * return file path in UTF8 encoding, need release by core. 36 | */ 37 | char *RDPortingFile_getDocumentsPath(); 38 | 39 | /* a ReadOnly directory in sandbox for mobile app. 40 | * return file path in UTF8 encoding, need release by core. 41 | */ 42 | char *RDPortingFile_getBundlePath(); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | 49 | #endif /* __RDPortingFile_h__ */ 50 | -------------------------------------------------------------------------------- /core/porting/inc/RDPortingGL.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDPortingGL_h__ 16 | #define __RDPortingGL_h__ 17 | 18 | /****** For iOS ********/ 19 | #ifdef RD_PLATFORM_IOS 20 | #define glClearDepth glClearDepthf 21 | #define glDeleteVertexArrays glDeleteVertexArraysOES 22 | #define glGenVertexArrays glGenVertexArraysOES 23 | #define glBindVertexArray glBindVertexArrayOES 24 | #define glMapBuffer glMapBufferOES 25 | #define glUnmapBuffer glUnmapBufferOES 26 | 27 | #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES 28 | #define GL_WRITE_ONLY GL_WRITE_ONLY_OES 29 | 30 | #include 31 | #include 32 | #endif // end of RD_PLATFORM_IOS 33 | 34 | /****** For Mac ********/ 35 | #ifdef RD_PLATFORM_MAC 36 | #include 37 | #include 38 | 39 | #define glDeleteVertexArrays glDeleteVertexArraysAPPLE 40 | #define glGenVertexArrays glGenVertexArraysAPPLE 41 | #define glBindVertexArray glBindVertexArrayAPPLE 42 | #endif // end of RD_PLATFORM_MAC 43 | 44 | /****** For Win32 ********/ 45 | #ifdef RD_PLATFORM_WIN32 46 | #include 47 | #endif // end of RD_PLATFORM_WIN32 48 | 49 | /****** For Android ********/ 50 | #ifdef RD_PLATFORM_ANDROID 51 | #include 52 | #include 53 | #endif // end of RD_PLATFORM_ANDROID 54 | 55 | 56 | #endif /* __RDPortingGL_h__ */ 57 | -------------------------------------------------------------------------------- /core/porting/inc/RDPortingMainLoop.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDPortingMainLoop_h__ 16 | #define __RDPortingMainLoop_h__ 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /* 23 | * mainloop callback 24 | */ 25 | typedef void (*RDPortingMainLoopCB)(void); 26 | 27 | void RDPortingMainLoop_start(RDPortingMainLoopCB cb); 28 | void RDPortingMainLoop_stop(void); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | 35 | #endif /* __RDPortingMainLoop_h__ */ 36 | -------------------------------------------------------------------------------- /core/porting/inc/RDPortingPrint.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDPortingPrint_h__ 16 | #define __RDPortingPrint_h__ 17 | 18 | #include 19 | #include "RDPortingTypes.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | void RDPortingPrint_log(const char *format, va_list args); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* __RDPortingPrint_h__ */ 32 | -------------------------------------------------------------------------------- /core/porting/inc/RDPortingSystem.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDPortingSystem_H__ 16 | #define __RDPortingSystem_H__ 17 | 18 | #include "RDPortingTypes.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | void RDPortingSystem_OpenUrl(const char *url); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif // __RDPortingSystem_H__ 31 | -------------------------------------------------------------------------------- /core/porting/inc/RDPortingTTF.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDPortingTTF_h__ 16 | #define __RDPortingTTF_h__ 17 | 18 | #include "RDTypes.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | typedef struct { 25 | RD_uchar *buffer;// r,g,b,a 26 | int width; 27 | int height; 28 | bool isPremultipliedAlpha; 29 | } RD_Bitmap32; 30 | 31 | bool RDPortingTTF_getBitmap32(const char *utf8_text, 32 | const char *fontName, 33 | float fontSize, 34 | RDColor *fontColor,// 0~255 35 | int align,// 0 left, 1 center, 2 right 36 | RD_Bitmap32 *outMap); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | 43 | #endif /* __RDPortingTTF_h__ */ 44 | -------------------------------------------------------------------------------- /core/porting/inc/RDPortingTime.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDPortingTime_h__ 16 | #define __RDPortingTime_h__ 17 | 18 | #include 19 | #ifdef WIN32 20 | # include 21 | #else 22 | # include 23 | #endif 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #ifdef WIN32 30 | int gettimeofday(struct timeval *tp, void *tzp); 31 | #endif 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | 38 | #endif /* __RDPortingTime_h__ */ 39 | -------------------------------------------------------------------------------- /core/porting/inc/RDPortingTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDPortingTypes_h__ 16 | #define __RDPortingTypes_h__ 17 | 18 | /****** For iOS, Mac ********/ 19 | #if defined(RD_PLATFORM_IOS) || defined(RD_PLATFORM_MAC) || defined(RD_PLATFORM_ANDROID) 20 | #include 21 | #include 22 | 23 | typedef unsigned char RD_uchar; 24 | typedef int16_t RD_int16; 25 | typedef uint16_t RD_uint16; 26 | typedef int32_t RD_int32; 27 | typedef uint32_t RD_uint32; 28 | typedef int64_t RD_int64; 29 | typedef uint64_t RD_uint64; 30 | 31 | #endif 32 | 33 | /****** end of For iOS, Mac ********/ 34 | 35 | #if defined(RD_PLATFORM_WIN32) 36 | typedef unsigned char RD_uchar; 37 | typedef short RD_int16; 38 | typedef unsigned short RD_uint16; 39 | typedef int RD_int32; 40 | typedef unsigned int RD_uint32; 41 | typedef long long RD_int64; 42 | typedef unsigned long long RD_uint64; 43 | 44 | #include // define size_t 45 | 46 | #if _MSC_VER < 1900 47 | // make VS happy 48 | #define strdup _strdup 49 | #define strcasecmp _stricmp 50 | #define snprintf _snprintf 51 | #endif 52 | 53 | #define strcasecmp _stricmp 54 | 55 | #define M_PI (3.14159265358) 56 | #define M_PI_2 (1.57079632679) 57 | 58 | #endif 59 | 60 | #endif /* __RDPortingTypes_h__ */ 61 | -------------------------------------------------------------------------------- /core/porting/ios/RDPortingPrint.mm: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include "RDPortingPrint.h" 17 | 18 | #define RD_MAX_LOG_LENGTH (1024) 19 | 20 | void RDPortingPrint_log(const char *format, va_list args) 21 | { 22 | char buf[RD_MAX_LOG_LENGTH]; 23 | memset(buf, 0, sizeof(char) * RD_MAX_LOG_LENGTH); 24 | vsnprintf(buf, RD_MAX_LOG_LENGTH - 3, format, args); 25 | 26 | fprintf(stdout, "%s", buf); 27 | fflush(stdout); 28 | } 29 | -------------------------------------------------------------------------------- /core/porting/ios/RDPortingSystem.mm: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "RDPortingSystem.h" 16 | 17 | void RDPortingSystem_OpenUrl(const char *url) 18 | { 19 | // 20 | } 21 | -------------------------------------------------------------------------------- /core/porting/mac/RDPortingPrint.mm: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include "RDPortingPrint.h" 17 | 18 | #define RD_MAX_LOG_LENGTH (1024) 19 | 20 | void RDPortingPrint_log(const char *format, va_list args) 21 | { 22 | char buf[RD_MAX_LOG_LENGTH]; 23 | memset(buf, 0, sizeof(char) * RD_MAX_LOG_LENGTH); 24 | vsnprintf(buf, RD_MAX_LOG_LENGTH - 3, format, args); 25 | 26 | fprintf(stdout, "%s", buf); 27 | fflush(stdout); 28 | } 29 | -------------------------------------------------------------------------------- /core/porting/mac/RDPortingSystem.mm: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "RDPortingSystem.h" 16 | 17 | void RDPortingSystem_OpenUrl(const char *url) 18 | { 19 | // 20 | } 21 | -------------------------------------------------------------------------------- /core/porting/win32/RDPortingMainLoop.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "RDPortingMainLoop.h" 16 | 17 | extern void main_setFrameCallBack(void *cb); 18 | 19 | void RDPortingMainLoop_start(RDPortingMainLoopCB cb) 20 | { 21 | main_setFrameCallBack(cb); 22 | } 23 | 24 | void RDPortingMainLoop_stop(void) 25 | { 26 | } 27 | -------------------------------------------------------------------------------- /core/porting/win32/RDPortingPrint.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include "RDPortingPrint.h" 17 | #include "RDWin32Char.h" 18 | 19 | #define RD_MAX_LOG_LENGTH (1024) 20 | 21 | void RDPortingPrint_log(const char *format, va_list args) 22 | { 23 | char szBuf[RD_MAX_LOG_LENGTH]; 24 | 25 | vsnprintf_s(szBuf, RD_MAX_LOG_LENGTH, RD_MAX_LOG_LENGTH, format, args); 26 | printf(szBuf); 27 | 28 | #ifdef RD_DEBUG 29 | // UTF8 -> Wchar 30 | WCHAR *wBuff = UTF8_To_Wchar(szBuf); 31 | if (wBuff) { 32 | OutputDebugStringW(wBuff); 33 | free(wBuff); 34 | } 35 | #endif 36 | } 37 | -------------------------------------------------------------------------------- /core/porting/win32/RDPortingSystem.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "RDPortingSystem.h" 16 | 17 | void RDPortingSystem_OpenUrl(const char *url) 18 | { 19 | // 20 | } 21 | -------------------------------------------------------------------------------- /core/porting/win32/RDPortingTime.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "RDPortingTime.h" 16 | 17 | int gettimeofday(struct timeval *tp, void *tzp) 18 | { 19 | time_t clock; 20 | struct tm tm; 21 | SYSTEMTIME wtm; 22 | 23 | GetLocalTime(&wtm); 24 | tm.tm_year = wtm.wYear - 1900; 25 | tm.tm_mon = wtm.wMonth - 1; 26 | tm.tm_mday = wtm.wDay; 27 | tm.tm_hour = wtm.wHour; 28 | tm.tm_min = wtm.wMinute; 29 | tm.tm_sec = wtm.wSecond; 30 | tm.tm_isdst = -1; 31 | clock = mktime(&tm); 32 | tp->tv_sec = (long)clock; 33 | tp->tv_usec = wtm.wMilliseconds * 1000; 34 | 35 | return (0); 36 | } 37 | -------------------------------------------------------------------------------- /core/porting/win32/RDWin32Char.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "RDWin32Char.h" 16 | 17 | WCHAR *UTF8_To_Wchar(const char *in) 18 | { 19 | int strLength = MultiByteToWideChar(CP_UTF8, 0, in, -1, nullptr, 0); 20 | if (strLength == 0) { 21 | return NULL; 22 | } 23 | 24 | WCHAR *pOut = (WCHAR *)malloc((strLength + 1) * sizeof(WCHAR)); 25 | memset(pOut, 0, (strLength + 1) * sizeof(WCHAR)); 26 | 27 | MultiByteToWideChar(CP_UTF8, 0, in, -1, pOut, strLength); 28 | return pOut; 29 | } 30 | 31 | char *Wchar_To_Utf8(WCHAR *in) 32 | { 33 | int strLength = WideCharToMultiByte(CP_UTF8, 0, in, -1, nullptr, 0, nullptr, FALSE); 34 | if (strLength == 0) { 35 | return NULL; 36 | } 37 | 38 | char *pOut = (char*)malloc(strLength + 1); 39 | memset(pOut, 0, strLength + 1); 40 | 41 | WideCharToMultiByte(CP_UTF8, 0, in, -1, pOut, strLength, nullptr, FALSE); 42 | return pOut; 43 | } 44 | -------------------------------------------------------------------------------- /core/porting/win32/RDWin32Char.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDWin32Char_h__ 16 | #define __RDWin32Char_h__ 17 | 18 | //Only use in win32 porting layer 19 | #include 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | WCHAR *UTF8_To_Wchar(const char *in); 26 | char *Wchar_To_Utf8(WCHAR *in); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif // __RDWin32Char_h__ 33 | -------------------------------------------------------------------------------- /core/projects/win32/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 静态库:core 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 core 库项目。 6 | 7 | 没有为此项目创建源文件。 8 | 9 | 10 | core.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | core.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | 其他注释: 18 | 19 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | -------------------------------------------------------------------------------- /core/projects/win32/core.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core", "core.vcxproj", "{8088D57F-7396-4437-9925-3F5F74E6D0DD}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {8088D57F-7396-4437-9925-3F5F74E6D0DD}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {8088D57F-7396-4437-9925-3F5F74E6D0DD}.Debug|Win32.Build.0 = Debug|Win32 16 | {8088D57F-7396-4437-9925-3F5F74E6D0DD}.Release|Win32.ActiveCfg = Release|Win32 17 | {8088D57F-7396-4437-9925-3F5F74E6D0DD}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /core/projects/win32/core.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /core/scripting/RDLuaconf.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDLuaconf_h__ 16 | #define __RDLuaconf_h__ 17 | 18 | #include "RDLog.h" 19 | 20 | // for different platform 21 | #ifdef RD_PLATFORM_IOS 22 | #define LUA_USE_MACOSX 23 | #endif 24 | 25 | #ifdef RD_PLATFORM_MAC 26 | #define LUA_USE_MACOSX 27 | #endif 28 | 29 | #ifdef RD_PLATFORM_WIN32 30 | #define LUA_USE_WINDOWS 31 | #endif 32 | 33 | #ifdef RD_PLATFORM_ANDROID 34 | #define LUA_USE_LINUX 35 | #define LUA_USE_C89 36 | #define lua_getlocaledecpoint() '.' 37 | #endif 38 | 39 | // configure for Rapid2D 40 | #define lua_writestring(s,l) RDLog(s) 41 | #define lua_writeline() RDLog("\n") 42 | #define lua_writestringerror(s,p) RDLog(s,p) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /core/scripting/binding/RDLua.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDLua_h__ 16 | #define __RDLua_h__ 17 | 18 | // lua5 header files 19 | #include "lua.hpp" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | // Rapid2D bindings 26 | LUAMOD_API int luaopen_cjson(lua_State *l); 27 | #define RD_LIB_LUALOADER "Rapid2D_CLuaLoader" 28 | LUAMOD_API int (luaopen_LuaLoader) (lua_State *L); 29 | #define RD_LIB_SPRITE "Rapid2D_CSprite" 30 | LUAMOD_API int (luaopen_Sprite) (lua_State *L); 31 | #define RD_LIB_TEXTURE "Rapid2D_CTexture" 32 | LUAMOD_API int luaopen_Texture(lua_State *L); 33 | #define RD_LIB_SPRITEFRAME "Rapid2D_CSriteFrame" 34 | LUAMOD_API int luaopen_SpriteFrame(lua_State *L); 35 | #define RD_LIB_FILESYSTEM "Rapid2D_CFileSystem" 36 | LUAMOD_API int luaopen_FileSystem(lua_State *L); 37 | #define RD_LIB_MAT4 "Rapid2D_CMat4" 38 | LUAMOD_API int luaopen_Mat4(lua_State *L); 39 | #define RD_LIB_DRAWVERTEX "Rapid2D_CDrawVertex" 40 | LUAMOD_API int (luaopen_DrawVertex) (lua_State *L); 41 | #define RD_LIB_OPENGL "Rapid2D_COpenGL" 42 | LUAMOD_API int (luaopen_OpenGL) (lua_State *L); 43 | #define RD_LIB_AUDIO "Rapid2D_CAudio" 44 | LUAMOD_API int luaopen_audio(lua_State *L); 45 | #define RD_LIB_CRYPTO "Rapid2D_CCrypto" 46 | LUAMOD_API int luaopen_crypto(lua_State *L); 47 | 48 | // name is 'require' search path 49 | int RDLuaLoadFromFile(lua_State *L, const char *name); 50 | int RDLuaLoadFromChunks(lua_State *L, const char *fullPath, const char *key); 51 | void RDLuaInit(const char *name, const char *key); 52 | void RDLuaDraw(float dt); 53 | void RDLuaTouchEvent(char *type, int count, intptr_t ids[], float xs[], float ys[]); 54 | void RDLuaKeyBoardEvent(char *type, int keyCode); 55 | void RDLuaClose(void); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* __RDLua_h__ */ 62 | -------------------------------------------------------------------------------- /core/scripting/binding/RDlOpenGL.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "RDLua.h" 16 | #include "RDTypes.h" 17 | #include "RDLog.h" 18 | 19 | static int lclearColor(lua_State *L) 20 | { 21 | lua_pushstring(L, "r"); 22 | lua_rawget(L, 1); 23 | GLfloat r = lua_tointeger(L, -1) / 255.0; 24 | lua_pop(L, 1); 25 | 26 | lua_pushstring(L, "g"); 27 | lua_rawget(L, 1); 28 | GLfloat g = lua_tointeger(L, -1) / 255.0; 29 | lua_pop(L, 1); 30 | 31 | lua_pushstring(L, "b"); 32 | lua_rawget(L, 1); 33 | GLfloat b = lua_tointeger(L, -1) / 255.0; 34 | lua_pop(L, 1); 35 | 36 | lua_pushstring(L, "a"); 37 | lua_rawget(L, 1); 38 | GLfloat a = lua_tointeger(L, -1) / 255.0; 39 | lua_pop(L, 1); 40 | 41 | glClearColor(r, g, b, a); 42 | return 0; 43 | } 44 | 45 | static const struct luaL_Reg luaOpenGL_funcs [] = { 46 | {"clearColor", lclearColor}, 47 | {NULL, NULL} 48 | }; 49 | 50 | // extern func for register library 51 | LUAMOD_API int luaopen_OpenGL(lua_State *L) 52 | { 53 | luaL_newlib(L, luaOpenGL_funcs); 54 | return 1; 55 | } 56 | -------------------------------------------------------------------------------- /core/scripting/cjson/fpconv.h: -------------------------------------------------------------------------------- 1 | /* Lua CJSON floating point conversion routines */ 2 | 3 | /* Buffer required to store the largest string representation of a double. 4 | * 5 | * Longest double printed with %.14g is 21 characters long: 6 | * -1.7976931348623e+308 */ 7 | # define FPCONV_G_FMT_BUFSIZE 32 8 | 9 | #ifdef WIN32 10 | #define inline __inline 11 | #define snprintf _snprintf 12 | #endif 13 | 14 | #ifdef USE_INTERNAL_FPCONV 15 | static inline void fpconv_init() 16 | { 17 | /* Do nothing - not required */ 18 | } 19 | #else 20 | extern void fpconv_init(); 21 | #endif 22 | 23 | extern int fpconv_g_fmt(char*, double, int); 24 | extern double fpconv_strtod(const char*, char**); 25 | 26 | /* vi:ai et sw=4 ts=4: 27 | */ 28 | -------------------------------------------------------------------------------- /core/scripting/lua/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /core/scripting/lua/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | /* 65 | ** this 'ltolower' only works for alphabetic characters 66 | */ 67 | #define ltolower(c) ((c) | ('A' ^ 'a')) 68 | 69 | 70 | /* two more entries for 0 and -1 (EOZ) */ 71 | LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2]; 72 | 73 | 74 | #else /* }{ */ 75 | 76 | /* 77 | ** use standard C ctypes 78 | */ 79 | 80 | #include 81 | 82 | 83 | #define lislalpha(c) (isalpha(c) || (c) == '_') 84 | #define lislalnum(c) (isalnum(c) || (c) == '_') 85 | #define lisdigit(c) (isdigit(c)) 86 | #define lisspace(c) (isspace(c)) 87 | #define lisprint(c) (isprint(c)) 88 | #define lisxdigit(c) (isxdigit(c)) 89 | 90 | #define ltolower(c) (tolower(c)) 91 | 92 | #endif /* } */ 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /core/scripting/lua/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.14 2015/05/22 17:45:56 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : -1) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 24 | const TValue *p2); 25 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 26 | const TValue *p2, 27 | const char *msg); 28 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 29 | const TValue *p2); 30 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 31 | const TValue *p2); 32 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 33 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 34 | TString *src, int line); 35 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 36 | LUAI_FUNC void luaG_traceexec (lua_State *L); 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /core/scripting/lua/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.29 2015/12/21 13:02:14 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Macro to check stack size and grow stack if needed. Parameters 18 | ** 'pre'/'pos' allow the macro to preserve a pointer into the 19 | ** stack across reallocations, doing the work only when needed. 20 | ** 'condmovestack' is used in heavy tests to force a stack reallocation 21 | ** at every check. 22 | */ 23 | #define luaD_checkstackaux(L,n,pre,pos) \ 24 | if (L->stack_last - L->top <= (n)) \ 25 | { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); } 26 | 27 | /* In general, 'pre'/'pos' are empty (nothing to save) */ 28 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) 29 | 30 | 31 | 32 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 33 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 34 | 35 | 36 | /* type of protected functions, to be ran by 'runprotected' */ 37 | typedef void (*Pfunc) (lua_State *L, void *ud); 38 | 39 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 40 | const char *mode); 41 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 45 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 46 | ptrdiff_t oldtop, ptrdiff_t ef); 47 | LUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, 48 | int nres); 49 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 50 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 51 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 52 | LUAI_FUNC void luaD_inctop (lua_State *L); 53 | 54 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 55 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /core/scripting/lua/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | /* 33 | ** Upvalues for Lua closures 34 | */ 35 | struct UpVal { 36 | TValue *v; /* points to stack or to its own value */ 37 | lu_mem refcount; /* reference counter */ 38 | union { 39 | struct { /* (when open) */ 40 | UpVal *next; /* linked list */ 41 | int touched; /* mark to avoid cycles with dead threads */ 42 | } open; 43 | TValue value; /* the value (when closed) */ 44 | } u; 45 | }; 46 | 47 | #define upisopen(up) ((up)->v != &(up)->u.value) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 57 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 58 | int pc); 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /core/scripting/lua/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.38 2015/01/05 13:48:33 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove _PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {"_G", luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | #if defined(LUA_COMPAT_BITLIB) 54 | {LUA_BITLIBNAME, luaopen_bit32}, 55 | #endif 56 | {NULL, NULL} 57 | }; 58 | 59 | 60 | LUALIB_API void luaL_openlibs (lua_State *L) { 61 | const luaL_Reg *lib; 62 | /* "require" functions from 'loadedlibs' and set results to global table */ 63 | for (lib = loadedlibs; lib->func; lib++) { 64 | luaL_requiref(L, lib->name, lib->func, 1); 65 | lua_pop(L, 1); /* remove lib */ 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /core/scripting/lua/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /core/scripting/lua/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.61 2015/11/03 15:36:01 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizelstring(l) (sizeof(union UTString) + ((l) + 1) * sizeof(char)) 16 | 17 | #define sizeludata(l) (sizeof(union UUdata) + (l)) 18 | #define sizeudata(u) sizeludata((u)->len) 19 | 20 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 21 | (sizeof(s)/sizeof(char))-1)) 22 | 23 | 24 | /* 25 | ** test whether a string is a reserved word 26 | */ 27 | #define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0) 28 | 29 | 30 | /* 31 | ** equality for short strings, which are always internalized 32 | */ 33 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b)) 34 | 35 | 36 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 37 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 40 | LUAI_FUNC void luaS_clearcache (global_State *g); 41 | LUAI_FUNC void luaS_init (lua_State *L); 42 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 43 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s); 44 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 45 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 46 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /core/scripting/lua/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.21 2015/11/03 15:47:30 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->i_key.nk.next) 16 | 17 | 18 | /* 'const' to avoid wrong writings that can mess up field 'next' */ 19 | #define gkey(n) cast(const TValue*, (&(n)->i_key.tvk)) 20 | 21 | /* 22 | ** writable version of 'gkey'; allows updates to individual fields, 23 | ** but not to the whole (which has incompatible type) 24 | */ 25 | #define wgkey(n) (&(n)->i_key.nk) 26 | 27 | #define invalidateTMcache(t) ((t)->flags = 0) 28 | 29 | 30 | /* returns the key, given the value of a table entry */ 31 | #define keyfromval(v) \ 32 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 33 | 34 | 35 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 36 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 37 | TValue *value); 38 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 39 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 40 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 41 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 42 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 43 | LUAI_FUNC Table *luaH_new (lua_State *L); 44 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 45 | unsigned int nhsize); 46 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 47 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 48 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 49 | LUAI_FUNC int luaH_getn (Table *t); 50 | 51 | 52 | #if defined(LUA_DEBUG) 53 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 54 | LUAI_FUNC int luaH_isdummy (Node *n); 55 | #endif 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /core/scripting/lua/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.22 2016/02/26 19:20:15 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" and "ORDER OP" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with fast access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_MOD, 29 | TM_POW, 30 | TM_DIV, 31 | TM_IDIV, 32 | TM_BAND, 33 | TM_BOR, 34 | TM_BXOR, 35 | TM_SHL, 36 | TM_SHR, 37 | TM_UNM, 38 | TM_BNOT, 39 | TM_LT, 40 | TM_LE, 41 | TM_CONCAT, 42 | TM_CALL, 43 | TM_N /* number of elements in the enum */ 44 | } TMS; 45 | 46 | 47 | 48 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 49 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 50 | 51 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 52 | 53 | #define ttypename(x) luaT_typenames_[(x) + 1] 54 | 55 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 56 | 57 | 58 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); 59 | 60 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 61 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 62 | TMS event); 63 | LUAI_FUNC void luaT_init (lua_State *L); 64 | 65 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 66 | const TValue *p2, TValue *p3, int hasres); 67 | LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 68 | StkId res, TMS event); 69 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 70 | StkId res, TMS event); 71 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 72 | const TValue *p2, TMS event); 73 | 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /core/scripting/lua/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /core/scripting/lua/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.44 2014/02/06 17:32:33 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | 15 | LUAMOD_API int (luaopen_base) (lua_State *L); 16 | 17 | #define LUA_COLIBNAME "coroutine" 18 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 19 | 20 | #define LUA_TABLIBNAME "table" 21 | LUAMOD_API int (luaopen_table) (lua_State *L); 22 | 23 | #define LUA_IOLIBNAME "io" 24 | LUAMOD_API int (luaopen_io) (lua_State *L); 25 | 26 | #define LUA_OSLIBNAME "os" 27 | LUAMOD_API int (luaopen_os) (lua_State *L); 28 | 29 | #define LUA_STRLIBNAME "string" 30 | LUAMOD_API int (luaopen_string) (lua_State *L); 31 | 32 | #define LUA_UTF8LIBNAME "utf8" 33 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 34 | 35 | #define LUA_BITLIBNAME "bit32" 36 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 37 | 38 | #define LUA_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | 53 | #if !defined(lua_assert) 54 | #define lua_assert(x) ((void)0) 55 | #endif 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /core/scripting/lua/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | #define MYINT(s) (s[0]-'0') 22 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 23 | #define LUAC_FORMAT 0 /* this is the official format */ 24 | 25 | /* load one chunk; from lundump.c */ 26 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 27 | 28 | /* dump one chunk; from ldump.c */ 29 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 30 | void* data, int strip); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /core/scripting/lua/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.37 2015/09/08 15:41:05 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /core/scripting/lua/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /core/shader/RDIndexBuffer.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "RDIndexBuffer.h" 16 | #include "RDLog.h" 17 | 18 | RDIndexBuffer *RDIndexBuffer::_instance = nullptr; 19 | 20 | RDIndexBuffer::RDIndexBuffer() 21 | { 22 | } 23 | 24 | RDIndexBuffer::~RDIndexBuffer() 25 | { 26 | } 27 | 28 | RDIndexBuffer *RDIndexBuffer::getInstance(void) 29 | { 30 | if (!_instance) { 31 | _instance = new RDIndexBuffer(); 32 | _instance->init(); 33 | } 34 | return _instance; 35 | } 36 | 37 | void RDIndexBuffer::init(void) 38 | { 39 | // vertex index buffer for sprite 40 | const GLubyte indices[] = { 41 | 0, 1, 2, 42 | 2, 3, 0 43 | }; 44 | 45 | GLuint buffer; 46 | glGenBuffers(1, &buffer); 47 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer); 48 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); 49 | 50 | _dict.insert(std::make_pair("sprite", buffer)); 51 | } 52 | 53 | GLuint RDIndexBuffer::getVIB(const char *name) 54 | { 55 | for (auto &pair : _dict) { 56 | if (0 == strcmp(pair.first, name)) { 57 | return pair.second; 58 | } 59 | } 60 | 61 | RDLog("[Error]: fail to getVIB:%s\n", name); 62 | return -1; 63 | } 64 | -------------------------------------------------------------------------------- /core/shader/RDIndexBuffer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDIndexBuffer_H__ 16 | #define __RDIndexBuffer_H__ 17 | 18 | #include 19 | #include "RDPortingGL.h" 20 | 21 | class RDIndexBuffer 22 | { 23 | public: 24 | RDIndexBuffer(); 25 | ~RDIndexBuffer(); 26 | static RDIndexBuffer *getInstance(void); 27 | 28 | // return a ref, must not be free by caller 29 | GLuint getVIB(const char *name); 30 | private: 31 | static RDIndexBuffer *_instance; 32 | std::map _dict; 33 | 34 | void init(void); 35 | }; 36 | 37 | #endif // __RDIndexBuffer_H__ 38 | -------------------------------------------------------------------------------- /core/shader/RDProgram.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDProgram_H__ 16 | #define __RDProgram_H__ 17 | 18 | #include "RDPortingGL.h" 19 | #include "RDData.h" 20 | 21 | // GLSL Loader 22 | 23 | class RDProgram 24 | { 25 | public: 26 | RDProgram(); 27 | ~RDProgram(); 28 | static RDProgram *create(const char *vshPath, const char *fshPath); 29 | static RDProgram *create(RDData *vshData, RDData *fshData); 30 | 31 | GLuint getProgram(void) {return _program;}; 32 | GLint getPositionSlot(void) {return _positionSlot;}; 33 | GLint getColorSlot(void) {return _colorSlot;}; 34 | GLint getProjectionUniform(void) {return _projectionUniform;}; 35 | GLint getModelviewUniform(void) {return _modelViewUniform;}; 36 | GLint getTexCoordSlot(void) {return _texCoordSlot;}; 37 | GLint getTextureUniform(void) {return _textureUniform;}; 38 | GLint getAlphaUniform(void) {return _aplhaUniform;}; 39 | GLint getPointSizeUniform(void) {return _pointSizeUniform;}; 40 | private: 41 | GLuint _program; 42 | GLint _positionSlot;// -1 for not set 43 | GLint _colorSlot;// -1 for not set 44 | GLint _projectionUniform;// -1 for not set 45 | GLint _modelViewUniform;// -1 for not set 46 | GLint _texCoordSlot;// -1 for not set 47 | GLint _textureUniform;// -1 for not set 48 | GLint _aplhaUniform;// -1 for not set 49 | GLint _pointSizeUniform;// -1 for not set 50 | 51 | bool init(RDData *vshData, RDData *fshData); 52 | bool compileShader(GLuint *shader, GLenum type, RDData *data); 53 | bool linkProgram(GLuint prog); 54 | }; 55 | 56 | #endif // __RDProgram_H__ 57 | -------------------------------------------------------------------------------- /core/shader/RDProgramCache.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDProgramCache_H__ 16 | #define __RDProgramCache_H__ 17 | 18 | #include 19 | 20 | class RDProgram; 21 | 22 | class RDProgramCache 23 | { 24 | public: 25 | RDProgramCache(); 26 | ~RDProgramCache(); 27 | static RDProgramCache *getInstance(void); 28 | 29 | // return a ref, must not be free by caller 30 | RDProgram *getProgram(const char * name); 31 | private: 32 | static RDProgramCache *_instance; 33 | std::map _dict; 34 | 35 | void init(void); 36 | }; 37 | 38 | #endif // __RDProgramCache_H__ 39 | -------------------------------------------------------------------------------- /core/shader/RDShaderSprite.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDShaderSprite_H__ 16 | #define __RDShaderSprite_H__ 17 | 18 | #include "RDMacros.h" 19 | 20 | static const char *_spriteShaderVSH = RDToString( 21 | attribute vec4 Position; 22 | attribute vec4 SourceColor; 23 | uniform mat4 Projection; 24 | uniform mat4 Modelview; 25 | 26 | varying vec4 DestinationColor;// out param to fsh 27 | 28 | attribute vec2 TexCoordIn; 29 | varying vec2 TexCoordOut; // out param to fsh 30 | 31 | void main(void) { 32 | DestinationColor = SourceColor; 33 | gl_Position = Projection * Modelview * Position; 34 | TexCoordOut = TexCoordIn; 35 | } 36 | ); 37 | 38 | static const char *_spriteShaderFSH = RDToString( 39 | \n#ifdef GL_ES\n 40 | // define float for OpenGL ES 41 | precision lowp float; 42 | \n#else\n 43 | // lowp is not implementation in OpenGL, but works in OpenGL ES 44 | \n#define lowp\n 45 | \n#endif\n 46 | 47 | varying lowp vec4 DestinationColor; 48 | varying lowp vec2 TexCoordOut; 49 | uniform sampler2D Texture; 50 | uniform float AlphaValue; 51 | 52 | void main(void) { 53 | vec4 texColor = texture2D(Texture, TexCoordOut); 54 | if (texColor.a <= AlphaValue) { 55 | discard; 56 | }; 57 | gl_FragColor = DestinationColor * texColor; 58 | } 59 | ); 60 | 61 | #endif // __RDShaderSprite_H__ 62 | -------------------------------------------------------------------------------- /core/shader/RDShaderVertex.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDShaderVertex_H__ 16 | #define __RDShaderVertex_H__ 17 | 18 | #include "RDMacros.h" 19 | 20 | static const char *_vertexShaderVSH = RDToString( 21 | attribute vec4 Position; 22 | attribute vec4 SourceColor; 23 | uniform mat4 Projection; 24 | uniform mat4 Modelview; 25 | uniform float PointSize; 26 | 27 | varying vec4 DestinationColor;// out param to fsh 28 | 29 | void main(void) { 30 | DestinationColor = SourceColor; 31 | gl_Position = Projection * Modelview * Position; 32 | gl_PointSize = PointSize; 33 | } 34 | ); 35 | 36 | static const char *_vertexShaderFSH = RDToString( 37 | \n#ifdef GL_ES\n 38 | // define float for OpenGL ES 39 | precision lowp float; 40 | \n#else\n 41 | // lowp is not implementation in OpenGL, but works in OpenGL ES 42 | \n#define lowp\n 43 | \n#endif\n 44 | 45 | varying lowp vec4 DestinationColor; 46 | 47 | void main(void) { 48 | gl_FragColor = DestinationColor; 49 | } 50 | ); 51 | 52 | #endif // __RDShaderVertex_H__ 53 | -------------------------------------------------------------------------------- /core/sprite/RDDrawVertex.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDDrawVertex_H__ 16 | #define __RDDrawVertex_H__ 17 | 18 | #include "RDTypes.h" 19 | #include "RDPortingGL.h" 20 | 21 | class RDProgram; 22 | 23 | class RDDrawVertex 24 | { 25 | public: 26 | RDDrawVertex(); 27 | ~RDDrawVertex(); 28 | static RDDrawVertex *create(RDBasicVertex *vertex, 29 | size_t count, 30 | int drawType, 31 | float pointSize); 32 | 33 | virtual void draw(RDMat4 *modelView); 34 | private: 35 | // ref only, manage by cache. 36 | RDProgram *_program; 37 | 38 | // OpenGL GL_ELEMENT_ARRAY_BUFFER 39 | GLuint _indexBuffer; 40 | // OpenGL VBO 41 | GLuint _vertexBuffer; 42 | // how many vertexs 43 | size_t _count; 44 | // GL_POINTS need this 45 | float _pointSize; 46 | // glDrawElements mode 47 | GLenum _drawMode; 48 | 49 | bool init(RDBasicVertex *vertex, 50 | size_t count, 51 | int drawType, 52 | float pointSize); 53 | }; 54 | 55 | #endif // __RDDrawVertex_H__ 56 | -------------------------------------------------------------------------------- /core/sprite/RDSprite.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDSprite_H__ 16 | #define __RDSprite_H__ 17 | 18 | #include "RDTypes.h" 19 | #include "RDSpriteFrame.h" 20 | 21 | #define RD_SPRITE_VERTEX_COUNT (4) 22 | 23 | class RDProgram; 24 | 25 | class RDSprite 26 | { 27 | public: 28 | RDSprite(); 29 | ~RDSprite(); 30 | static RDSprite *create(RDSpriteFrame *frame); 31 | 32 | virtual void draw(RDMat4 *modelView); 33 | 34 | void setAnchorPoint(RDPoint *point); 35 | RDPoint *getAnchorPoint(void) { return &_anchorPoint; }; 36 | 37 | // set all 4 vertexs color to the same value 38 | void setColor(RDColor *color); 39 | RDColor *getColor(void) { return &_color[0]; }; 40 | 41 | void setFlip(bool flipx, bool flipy); 42 | bool getFlipX(void) { return _flipX; }; 43 | bool getFlipY(void) { return _flipY; }; 44 | 45 | void setOpacity(RD_uchar opacity); 46 | RD_uchar getOpacity(void) { return _opacity; }; 47 | 48 | void setFrame(RDSpriteFrame *frame); 49 | private: 50 | // ref only, manage by cache. 51 | GLuint _indexBuffer; 52 | // ref only, manage by cache. 53 | RDProgram *_program; 54 | // ref only, manage by lua cache. 55 | RDSpriteFrame *_spriteFrame; 56 | 57 | // sprite have 4 vertexs 58 | RDVertex _vertex[RD_SPRITE_VERTEX_COUNT]; 59 | bool _isVertexDirty; 60 | // OpenGL VBO for the sprite 61 | GLuint _vertexBuffer; 62 | // AnchorPoint 63 | RDPoint _anchorPoint; 64 | // vertexColor 65 | RDColor _color[RD_SPRITE_VERTEX_COUNT]; 66 | // flip 67 | bool _flipX; 68 | bool _flipY; 69 | RD_uchar _opacity; 70 | 71 | bool init(RDSpriteFrame *frame); 72 | void updateTexcoord(void); 73 | }; 74 | 75 | #endif // __RDSprite_H__ 76 | -------------------------------------------------------------------------------- /core/sprite/RDSpriteFrame.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDSpriteFrame_h__ 16 | #define __RDSpriteFrame_h__ 17 | 18 | #include "RDTypes.h" 19 | #include "RDTexture.h" 20 | 21 | typedef struct { 22 | char *name; 23 | bool rotated;// direction clockwise, The amount of rotation is always 90°. 24 | bool trimmed;// frameSize is small than soruceSize 25 | // frame.origin is left up corner 26 | RDRect frame;// coordinates of original picture in texture 27 | RDRect source;// coordinate of trimmed pic in original picture 28 | RDSize sourceSize;// original picture size 29 | RDTexture *texture;// Ref only 30 | } RDSpriteFrame; 31 | 32 | #endif /* __RDSpriteFrame_h__ */ 33 | -------------------------------------------------------------------------------- /core/utils/RDData.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "RDData.h" 18 | 19 | RDData::RDData() 20 | :_buffer(NULL) 21 | ,_hasBOM(false) 22 | ,_size(0) 23 | { 24 | } 25 | 26 | RDData::RDData(RD_uchar *buffer, size_t size) 27 | :_hasBOM(false) 28 | { 29 | _buffer = buffer; 30 | _size = size; 31 | } 32 | 33 | RDData::~RDData() 34 | { 35 | if (_buffer) { 36 | free(_buffer); 37 | } 38 | } 39 | 40 | size_t RDData::getSize() 41 | { 42 | return _hasBOM ? _size - 3 : _size; 43 | } 44 | 45 | RD_uchar *RDData::getBuffer() 46 | { 47 | return _hasBOM ? _buffer + 3 : _buffer; 48 | } 49 | -------------------------------------------------------------------------------- /core/utils/RDData.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDData_H__ 16 | #define __RDData_H__ 17 | 18 | #include "RDPortingTypes.h" 19 | 20 | class RDData 21 | { 22 | public: 23 | RDData(); 24 | RDData(RD_uchar *buffer, size_t size); 25 | ~RDData(); 26 | 27 | size_t getSize(); 28 | void setBOM(bool bom) { _hasBOM = bom; }; 29 | RD_uchar *getBuffer(); 30 | private: 31 | RD_uchar *_buffer; 32 | bool _hasBOM; 33 | size_t _size; 34 | }; 35 | 36 | #endif // __RDData_H__ 37 | -------------------------------------------------------------------------------- /core/utils/RDFileSystem.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDFileSystem_H__ 16 | #define __RDFileSystem_H__ 17 | 18 | #include "RDData.h" 19 | 20 | typedef enum { 21 | RD_FILETYPE_UNKNOWN = -1, 22 | 23 | // texture file type 24 | RD_FILETYPE_TEXTURE_START, 25 | RD_FILETYPE_PNG, 26 | RD_FILETYPE_TEXTURE_END, 27 | // end of texture type 28 | 29 | // music type 30 | RD_FILETYPE_MUSIC_START, 31 | RD_FILETYPE_OGG, 32 | RD_FILETYPE_MUSIC_END, 33 | }RD_FileType; 34 | 35 | typedef enum { 36 | // texture file type 37 | RD_FILEDIR_RES, // place picture,font etc. 38 | RD_FILEDIR_LUA, // place lua source file. 39 | RD_FILEDIR_DATA,// place writeable data. 40 | RD_FILEDIR_FULLPATH, // no need to convert 41 | // end of texture type 42 | }RD_FileDir; 43 | 44 | class RDFileSystem 45 | { 46 | public: 47 | RDFileSystem(); 48 | ~RDFileSystem(); 49 | static RDFileSystem *getInstance(void); 50 | 51 | // get data from res dir, delete data by caller 52 | RDData *getData(RD_FileDir type, const char *path, bool isTextMode = false); 53 | // write data to documentPath 54 | bool putData(const char *path, const char *buffer, size_t size); 55 | // auto insert '/' into path1 and path2 56 | char *appendPath(const char *path1, const char *path2); 57 | RD_FileType getFileType(const char *fileName); 58 | char *getFullPath(RD_FileDir type, const char *path); 59 | private: 60 | static RDFileSystem *_instance; 61 | 62 | char *_documentsPath; 63 | char *_bundlePath; 64 | char *_luaPath; 65 | char *_resPath; 66 | }; 67 | 68 | #endif // __RDFileSystem_H__ 69 | -------------------------------------------------------------------------------- /core/utils/RDLog.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include "RDLog.h" 19 | #include "RDPortingPrint.h" 20 | 21 | void RDLog(const char *format, ...) 22 | { 23 | va_list args; 24 | va_start(args, format); 25 | RDPortingPrint_log(format, args); 26 | va_end(args); 27 | } 28 | -------------------------------------------------------------------------------- /core/utils/RDLog.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDLog_H__ 16 | #define __RDLog_H__ 17 | 18 | #include "RDMacros.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | void RDLog(const char *format, ...); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif // __RDLog_H__ 31 | -------------------------------------------------------------------------------- /core/utils/RDMacros.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __RDMacros_H__ 16 | #define __RDMacros_H__ 17 | 18 | #include 19 | #include "RDLog.h" 20 | 21 | #define RD_MIN(x,y) (((x) > (y)) ? (y) : (x)) 22 | #define RD_MAX(x,y) (((x) < (y)) ? (y) : (x)) 23 | 24 | #if !defined(RD_DEBUG) 25 | #define RD_CHECK_GL_ERROR() 26 | #else 27 | #define RD_CHECK_GL_ERROR() \ 28 | do { \ 29 | GLenum __error = glGetError(); \ 30 | if(__error) { \ 31 | RDLog("[OpenGL Error]: 0x%04X in %s %s %d\n", __error, __FILE__, __FUNCTION__, __LINE__); \ 32 | } \ 33 | } while (false) 34 | #endif 35 | 36 | #if !defined(RD_DEBUG) 37 | #define RD_ASSERT(cond, msg) 38 | #else 39 | #define RD_ASSERT(cond, msg) \ 40 | do { \ 41 | if (!(cond)) { \ 42 | RDLog("[Assert failed]: %s\n", msg);\ 43 | } \ 44 | } while (0) 45 | #endif 46 | 47 | #define RDToString(a) #a 48 | 49 | //#define RD_SAFE_FREE_NULL(p) do { if(p) { free(p); (p) = 0; } } while(0) 50 | 51 | #endif // __RDMacros_H__ 52 | -------------------------------------------------------------------------------- /samples/test/android/Rapid2D/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 10 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | sourceSets.main { 20 | jniLibs.srcDir 'src/main/Rapid2D' 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar']) 26 | compile 'com.android.support:appcompat-v7:23.3.0' 27 | } 28 | -------------------------------------------------------------------------------- /samples/test/android/Rapid2D/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/android/Rapid2D/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/test/android/Rapid2D/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 21 11:34:03 PDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip 7 | -------------------------------------------------------------------------------- /samples/test/android/Rapid2D/jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2009 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := Rapid2D 20 | LOCAL_SRC_FILES := main.c \ 21 | ../../../common/cpp/startup.cpp 22 | 23 | LOCAL_C_INCLUDES += $(RAPID2D_ROOT)/core/ 24 | 25 | LOCAL_STATIC_LIBRARIES := static_Rapid2D 26 | 27 | include $(BUILD_SHARED_LIBRARY) 28 | 29 | $(call import-module, core) 30 | -------------------------------------------------------------------------------- /samples/test/android/Rapid2D/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_ABI := armeabi 2 | APP_STL := gnustl_static 3 | APP_PLATFORM := android-10 4 | APP_CPPFLAGS := -std=c++11 -fsigned-char 5 | 6 | ifeq ($(NDK_DEBUG),1) 7 | APP_CPPFLAGS += -DRD_DEBUG 8 | endif 9 | -------------------------------------------------------------------------------- /samples/test/android/Rapid2D/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/u0u0/bin/adt-bundle-mac/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /samples/test/android/Rapid2D/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /samples/test/android/Rapid2D/src/main/java/org/rapid2d/library/Rapid2DActivity.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package org.rapid2d.library; 16 | 17 | import android.opengl.GLSurfaceView; 18 | import android.os.Bundle; 19 | 20 | 21 | public class Rapid2DActivity extends android.app.Activity { 22 | public int screenWidth; 23 | public int screenHeight; 24 | 25 | // Jni import and method define 26 | static { 27 | System.loadLibrary("Rapid2D"); 28 | } 29 | public native String stringFromJNI(); 30 | public native void init(int width, int height); 31 | public native void mainLoop(); 32 | public native void setFilesDir(String dir); 33 | public native void setAssetManager(android.content.res.AssetManager ass); 34 | public native void sendTouchs(String type, int count, int ids[], float xs[], float ys[]); 35 | public native void sendKeyEvent(String type, int code); 36 | // end of jni 37 | 38 | @Override 39 | protected void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | // init OpenGL ES 2.0 42 | GLSurfaceView glSurfaceView = new OpenGLSurfaceView(this); 43 | glSurfaceView.setRenderer(new OpenGLRender(this)); 44 | setContentView(glSurfaceView); 45 | 46 | // get jni build type 47 | android.util.Log.v("Rapid2D_LOG", stringFromJNI()); 48 | } 49 | 50 | @Override 51 | protected void onResume() { 52 | super.onResume(); 53 | 54 | // TODO engine resume 55 | } 56 | 57 | @Override 58 | protected void onPause() { 59 | super.onPause(); 60 | 61 | // TODO engine pause 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /samples/test/android/Rapid2D/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Rapid2D 3 | 4 | -------------------------------------------------------------------------------- /samples/test/android/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /samples/test/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "org.rapid2d.test" 9 | minSdkVersion 10 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:appcompat-v7:23.3.0' 25 | compile project(':Rapid2D') 26 | } 27 | -------------------------------------------------------------------------------- /samples/test/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/u0u0/bin/adt-bundle-mac/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /samples/test/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /samples/test/android/app/src/main/java/org/rapid2d/test/MainActivity.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package org.rapid2d.test; 16 | 17 | import android.os.Bundle; 18 | import org.rapid2d.library.Rapid2DActivity; 19 | 20 | public class MainActivity extends Rapid2DActivity { 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /samples/test/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /samples/test/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /samples/test/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /samples/test/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /samples/test/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /samples/test/android/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /samples/test/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Test 3 | 4 | -------------------------------------------------------------------------------- /samples/test/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /samples/test/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /samples/test/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /samples/test/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/test/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Aug 17 18:38:11 CST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /samples/test/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':Rapid2D' 2 | -------------------------------------------------------------------------------- /samples/test/common/cpp/startup.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "startup.h" 16 | 17 | void Rapid2D_startup(float width, float height) 18 | { 19 | // 1. init screen size 20 | Rapid2D_setFrameSize(width, height); 21 | // 2. set ResolutionModeSize, size equal to BG picture size 22 | Rapid2D_setResolutionModeSize(1, 640, 960); 23 | // 3. start main loop 24 | Rapid2D_start(0, 0);// from source files. 25 | //Rapid2D_start("game.rd", "11");//from luaChunks 26 | } 27 | -------------------------------------------------------------------------------- /samples/test/common/cpp/startup.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __STARTUP_H__ 16 | #define __STARTUP_H__ 17 | 18 | #include "Rapid2D.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | // porting setup sequence, Modify STEP 2 for different project. 25 | void Rapid2D_startup(float width, float height); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif // __STARTUP_H__ 32 | -------------------------------------------------------------------------------- /samples/test/common/lua/game/case/testAudio.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | local testBase = require("game.testBase") 16 | local TestAudioScene = class("TestAudioScene", testBase) 17 | 18 | function TestAudioScene:ctor() 19 | -- init case first 20 | self.testcase = {"audioTest"} 21 | -- then call super.ctor 22 | TestAudioScene.super.ctor(self) 23 | 24 | -- create success 25 | return self 26 | end 27 | 28 | function TestAudioScene:audioTest() 29 | local bgmcase = { 30 | "LoadFile", 31 | "playBGM", 32 | "playEffect", 33 | "pauseAll", 34 | "resumeAll", 35 | "stopAll", 36 | "setBGMVolume", 37 | "setEffectVolume", 38 | } 39 | 40 | for i,v in ipairs(bgmcase) do 41 | local btn = TestButton.newColorButton(v, function(target) 42 | self[target.v](self) 43 | end) 44 | btn:setPos(0, rd.screen.top - 50 - 100 * (i - 1)) 45 | btn:addTo(self) 46 | btn.v = v 47 | end 48 | end 49 | 50 | function TestAudioScene:LoadFile() 51 | rd.audio.loadFile("audio/bgm.ogg") 52 | rd.audio.loadFile("audio/effect.ogg") 53 | end 54 | 55 | function TestAudioScene:playBGM() 56 | rd.audio.playBGM("audio/bgm.ogg") 57 | end 58 | 59 | function TestAudioScene:playEffect() 60 | rd.audio.playEffect("audio/effect.ogg") 61 | end 62 | 63 | function TestAudioScene:pauseAll() 64 | rd.audio.pause() 65 | end 66 | 67 | function TestAudioScene:resumeAll() 68 | rd.audio.resume() 69 | end 70 | 71 | function TestAudioScene:stopAll() 72 | rd.audio.stop() 73 | end 74 | 75 | function TestAudioScene:setBGMVolume() 76 | rd.audio.setBGMVolume(0.5) 77 | end 78 | 79 | function TestAudioScene:setEffectVolume() 80 | rd.audio.setEffectVolume(0.5) 81 | end 82 | 83 | return TestAudioScene 84 | -------------------------------------------------------------------------------- /samples/test/common/lua/game/mainscene.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | require("game.button") 16 | 17 | local MainScene = class("MainScene", rd.scene) 18 | 19 | function MainScene:ctor() 20 | -- call super.ctor first 21 | MainScene.super.ctor(self) 22 | 23 | self:setBackgroundColor(250, 248, 239, 255) 24 | -- init scene objects 25 | local testcase = { 26 | "FileSystem", 27 | "Crypto", 28 | "Drawvertex", 29 | "Actions", 30 | "Audio", 31 | } 32 | 33 | for i,v in ipairs(testcase) do 34 | local btn = TestButton.newColorButton(v, function(target) 35 | local scene = require("game.case.test" .. v).new() 36 | rd.director.runScene(scene) 37 | end) 38 | btn:setPos(0, rd.screen.top - 50 - 100 * (i - 1)) 39 | btn:addTo(self) 40 | btn.v = v 41 | end 42 | 43 | -- create success 44 | return self 45 | end 46 | 47 | return MainScene 48 | -------------------------------------------------------------------------------- /samples/test/common/lua/game/testBase.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | local TestBase = class("TestBase", rd.scene) 16 | 17 | function TestBase:ctor() 18 | -- call super.ctor first 19 | TestBase.super.ctor(self) 20 | 21 | self:setBackgroundColor(250, 248, 239, 255) 22 | -- init scene objects 23 | TestButton.homeButton():addTo(self) 24 | TestButton.preButton(handler(self, TestBase.previousDeal)):addTo(self) 25 | TestButton.nextButton(handler(self, TestBase.nextDeal)):addTo(self) 26 | 27 | -- show first case 28 | if #self.testcase > 0 then 29 | self.caseIndex = 1 30 | self[self.testcase[self.caseIndex]](self) 31 | end 32 | 33 | -- create success 34 | return self 35 | end 36 | 37 | function TestBase:previousDeal(target) 38 | if self.caseIndex > 1 then 39 | if self.testNode then self.testNode:removeSelf() end 40 | self.caseIndex = self.caseIndex - 1 41 | self[self.testcase[self.caseIndex]](self) 42 | end 43 | end 44 | 45 | function TestBase:nextDeal(target) 46 | if self.caseIndex < #self.testcase then 47 | if self.testNode then self.testNode:removeSelf() end 48 | self.caseIndex = self.caseIndex + 1 49 | self[self.testcase[self.caseIndex]](self) 50 | end 51 | end 52 | 53 | return TestBase 54 | -------------------------------------------------------------------------------- /samples/test/common/lua/main.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | -- instance of mainscene 16 | return require("game.mainscene").new() 17 | -------------------------------------------------------------------------------- /samples/test/common/lua/rapid2d/action/init.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | require("rapid2d.action.manager") 16 | require("rapid2d.action.simple") 17 | require("rapid2d.action.complex") 18 | require("rapid2d.action.ease") 19 | -------------------------------------------------------------------------------- /samples/test/common/lua/rapid2d/crypto.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | -- Singleton class 16 | local crypto = {} 17 | 18 | -- if isRaw return is binary string, otherwise return hex string 19 | function crypto.md5(input, isRaw) 20 | isRaw = isRaw or false 21 | return Rapid2D_CCrypto.md5(tostring(input), isRaw) 22 | end 23 | 24 | function crypto.encryptXXTEA(input, key) 25 | return Rapid2D_CCrypto.encryptXXTEA(tostring(input), tostring(key)) 26 | end 27 | 28 | function crypto.decryptXXTEA(input, key) 29 | return Rapid2D_CCrypto.decryptXXTEA(tostring(input), tostring(key)) 30 | end 31 | 32 | function crypto.encodeBase64(input) 33 | return Rapid2D_CCrypto.encodeBase64(tostring(input)) 34 | end 35 | 36 | function crypto.decodeBase64(input) 37 | return Rapid2D_CCrypto.decodeBase64(tostring(input)) 38 | end 39 | 40 | rd.crypto = crypto 41 | -------------------------------------------------------------------------------- /samples/test/common/lua/rapid2d/filesystem.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | -- Singleton class 16 | local fs = {} 17 | fs.DIR_RES = 0 -- place picture,font etc. 18 | fs.DIR_LUA = 1 -- place lua source file. 19 | fs.DIR_DATA = 2 -- place writeable data. 20 | 21 | function fs.getData(where, name, isTextMode) 22 | isTextMode = isTextMode or true 23 | return Rapid2D_CFileSystem.getData(where, name, isTextMode) 24 | end 25 | 26 | -- wirte data ONLY on fs.DIR_DATA 27 | function fs.putData(name, data) 28 | return Rapid2D_CFileSystem.putData(name, data) 29 | end 30 | 31 | -- data must table 32 | -- key is use for xxtea encrypt 33 | function fs.profileSave(fileName, data, key) 34 | if type(data) ~= "table" then 35 | print("Error, profileSave ONLY save table data") 36 | return false 37 | end 38 | fileName = tostring(fileName) 39 | key = tostring(key) 40 | data = cjson.encode(data) 41 | data = rd.crypto.encryptXXTEA(data, key) 42 | if nil == data then 43 | print("Error: profileSave Fail for encryptXXTEA") 44 | return false 45 | end 46 | 47 | if false == fs.putData(fileName, data) then 48 | print("Error: profileSave Fail " .. fileName) 49 | return false 50 | end 51 | 52 | return true 53 | end 54 | 55 | -- return table data 56 | function fs.profileLoad(fileName, key) 57 | fileName = tostring(fileName) 58 | key = tostring(key) 59 | local data = fs.getData(fs.DIR_DATA, fileName, false) 60 | if data then 61 | data = rd.crypto.decryptXXTEA(data, key) 62 | end 63 | if data then 64 | return cjson.decode(data) 65 | end 66 | end 67 | 68 | rd.fs = fs 69 | -------------------------------------------------------------------------------- /samples/test/common/lua/rapid2d/init.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | print("==== Loading Lua Framework ====") 16 | print("Lua engine version: " .. _VERSION) 17 | 18 | ------------ First of all, set my searcher --------------- 19 | -- when require, lua will search in package.searchers 20 | -- 1. package.preload[modname] 21 | -- 2. package.path, HERE will replace with our own method 22 | -- 3. package.cpath, USELESS , set to nil 23 | -- 4. package.croot, USELESS , set to nil 24 | package.searchers[2] = function(name) 25 | return Rapid2D_CLuaLoader.fromFile(name) 26 | end 27 | package.searchers[3] = nil 28 | package.searchers[4] = nil 29 | 30 | -- loading engine module 31 | require("rapid2d.crypto") 32 | require("rapid2d.screen") 33 | require("rapid2d.audio") 34 | require("rapid2d.math") 35 | require("rapid2d.string") 36 | require("rapid2d.table") 37 | require("rapid2d.utils") 38 | require("rapid2d.filesystem") 39 | require("rapid2d.action.init") 40 | require("rapid2d.renderer.init") 41 | 42 | -- start game 43 | print("===== Loading FirstScene =====") 44 | local firstScene = require("main") 45 | rd.director.runScene(firstScene) 46 | -------------------------------------------------------------------------------- /samples/test/common/lua/rapid2d/math.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | function math.angle2radian(angle) 16 | return angle * math.pi / 180 17 | end 18 | 19 | function math.radian2angle(radian) 20 | return radian / math.pi * 180 21 | end 22 | 23 | function math.rectContainsPoint(rect, point) 24 | local ret = false 25 | 26 | if (point.x >= rect.x) and (point.x <= rect.x + rect.width) and 27 | (point.y >= rect.y) and (point.y <= rect.y + rect.height) then 28 | ret = true 29 | end 30 | 31 | return ret 32 | end 33 | 34 | -- cubic Bezier formula t{0, 1} 35 | function math.cubicBezier(p1, c1, c2, p2, t) 36 | return (1 - t)^3 * p1 + 37 | 3 * (1 - t)^2 * t * c1 + 38 | 3 * (1 - t) * t^2 * c2 + 39 | t^3 * p2 40 | end 41 | -------------------------------------------------------------------------------- /samples/test/common/lua/rapid2d/renderer/director.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | -- Singleton class 16 | local director = {} 17 | 18 | -- will call from C, every frame 19 | function director.drawScene(dt) 20 | if director.curScene then 21 | director.curScene:drawTree(dt) 22 | end 23 | 24 | -- after first draw 25 | rd.actionManager.update(dt) 26 | -- audio affair 27 | rd.audio.update() 28 | end 29 | 30 | function director.sendTouchEvent(t, points) 31 | if director.curScene then 32 | director.curScene:dispatchTouchEvent(t, points) 33 | end 34 | end 35 | 36 | function director.sendKeyBoardEvent(t, code) 37 | if director.curScene then 38 | director.curScene:dispatchKeyBoardEvent(t, code) 39 | end 40 | end 41 | 42 | function director.runScene(scene) 43 | director.curScene = scene 44 | -- do this here? 45 | collectgarbage("collect") 46 | end 47 | 48 | rd.director = director 49 | -------------------------------------------------------------------------------- /samples/test/common/lua/rapid2d/renderer/init.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | require("rapid2d.renderer.texturecache") 16 | require("rapid2d.renderer.spriteframecache") 17 | require("rapid2d.renderer.node") 18 | require("rapid2d.renderer.drawvertex") 19 | require("rapid2d.renderer.sprite") 20 | require("rapid2d.renderer.label") 21 | require("rapid2d.renderer.scene") 22 | require("rapid2d.renderer.director") 23 | -------------------------------------------------------------------------------- /samples/test/common/lua/rapid2d/renderer/label.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | local label = {} 16 | label.LEFT = 0 -- text Alignment left 17 | label.CENTER = 1 -- text Alignment center 18 | label.RIGHT = 2 -- text Alignment right 19 | 20 | local TTF = class("rd.label.TTF", rd.sprite) 21 | 22 | function TTF:ctor(text, fontSize, font, fontColor, align) 23 | if nil == text then 24 | return nil 25 | end 26 | -- call super.ctor first 27 | TTF.super.ctor(self) 28 | 29 | self.font = font or "Arial" 30 | self.fontSize = fontSize or 18 31 | self.fontColor = fontColor or {255, 255, 255, 255} -- white color 32 | self.align = align or label.LEFT 33 | 34 | self:_genFrame(text) 35 | self.csprite = Rapid2D_CSprite.new(self.frame.cframe) 36 | 37 | return self 38 | end 39 | 40 | -- internal use func 41 | function TTF:_genFrame(text) 42 | -- NEVER cache TTF texture and frame 43 | local texture = Rapid2D_CTexture.newTTF(text, self.font, self.fontSize, 44 | self.fontColor[1], self.fontColor[2], self.fontColor[3], self.fontColor[4], 45 | self.align) 46 | local frame = Rapid2D_CSriteFrame.new( 47 | "rd.label.TTF", -- frame name 48 | false, -- rotated 49 | false, -- trimmed 50 | 0, 0, texture:getWidth(), texture:getHeight(), -- frame 51 | 0, 0, texture:getWidth(), texture:getHeight(), -- source 52 | texture:getWidth(), texture:getHeight(), -- soruce size 53 | texture) -- texture 54 | local luaFrame = { 55 | cframe = frame, 56 | ctexture = texture, 57 | width = texture:getWidth(), 58 | height = texture:getHeight() 59 | } 60 | self.frame = luaFrame 61 | end 62 | 63 | function TTF:setText(text) 64 | self:_genFrame(text) 65 | self.csprite:setFrame(self.frame.cframe) 66 | end 67 | 68 | label.TTF = TTF 69 | rd.label = label 70 | -------------------------------------------------------------------------------- /samples/test/common/lua/rapid2d/renderer/texturecache.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | -- Singleton class 16 | local textureCache = {} 17 | textureCache.textures = {} 18 | 19 | function textureCache.getTexture(name) 20 | local texture = textureCache.textures[name] 21 | if nil ~= texture then 22 | return texture 23 | end 24 | 25 | texture = Rapid2D_CTexture.new(name) 26 | if nil == texture then 27 | print("[Error]: textureCache.getTexture() Fail for:", name) 28 | end 29 | textureCache.textures[name] = texture 30 | return texture 31 | end 32 | 33 | rd.textureCache = textureCache 34 | -------------------------------------------------------------------------------- /samples/test/common/lua/rapid2d/screen.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | local screen = {} 16 | 17 | screen.width = rd.const.resolutionWidth 18 | screen.height = rd.const.resolutionHeight 19 | screen.left = -rd.const.resolutionWidth / 2 20 | screen.right = rd.const.resolutionWidth / 2 21 | screen.top = rd.const.resolutionHeight / 2 22 | screen.bottom = -rd.const.resolutionHeight / 2 23 | screen.cx = 0 24 | screen.cy = 0 25 | 26 | rd.screen = screen 27 | -------------------------------------------------------------------------------- /samples/test/common/lua/rapid2d/string.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | -- Remove the head and tail whitespace of given string 16 | -- return trimed string 17 | function string.trim(input) 18 | input = string.gsub(input, "^[ \t\n\r]+", "") 19 | return string.gsub(input, "[ \t\n\r]+$", "") 20 | end 21 | 22 | -- local input = "Hello,World" 23 | -- local res = string.split(input, ",") 24 | -- res = {"Hello", "World"} 25 | function string.split(input, delimiter) 26 | input = tostring(input) 27 | delimiter = tostring(delimiter) 28 | if (delimiter=='') then return false end 29 | local pos,arr = 0, {} 30 | -- for each divider found 31 | for st,sp in function() return string.find(input, delimiter, pos, true) end do 32 | table.insert(arr, string.sub(input, pos, st - 1)) 33 | pos = sp + 1 34 | end 35 | table.insert(arr, string.sub(input, pos)) 36 | return arr 37 | end 38 | -------------------------------------------------------------------------------- /samples/test/common/lua/rapid2d/table.lua: -------------------------------------------------------------------------------- 1 | -- Copyright 2016 KeNan Liu 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | -- NOT nil value's count in table 16 | function table.nums(t) 17 | local count = 0 18 | for k, v in pairs(t) do 19 | count = count + 1 20 | end 21 | return count 22 | end 23 | -------------------------------------------------------------------------------- /samples/test/common/res/audio/bgm.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/common/res/audio/bgm.ogg -------------------------------------------------------------------------------- /samples/test/common/res/audio/effect.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/common/res/audio/effect.ogg -------------------------------------------------------------------------------- /samples/test/common/res/btnNext.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/common/res/btnNext.png -------------------------------------------------------------------------------- /samples/test/common/res/btnPrevious.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/common/res/btnPrevious.png -------------------------------------------------------------------------------- /samples/test/common/res/pig.json: -------------------------------------------------------------------------------- 1 | {"frames": [ 2 | 3 | { 4 | "filename": "pig_1.png", 5 | "frame": {"x":278,"y":2,"w":48,"h":54}, 6 | "rotated": false, 7 | "trimmed": true, 8 | "spriteSourceSize": {"x":10,"y":0,"w":48,"h":54}, 9 | "sourceSize": {"w":62,"h":54} 10 | }, 11 | { 12 | "filename": "pig_2.png", 13 | "frame": {"x":122,"y":2,"w":54,"h":54}, 14 | "rotated": false, 15 | "trimmed": true, 16 | "spriteSourceSize": {"x":4,"y":0,"w":54,"h":54}, 17 | "sourceSize": {"w":62,"h":54} 18 | }, 19 | { 20 | "filename": "pig_3.png", 21 | "frame": {"x":66,"y":2,"w":54,"h":54}, 22 | "rotated": false, 23 | "trimmed": true, 24 | "spriteSourceSize": {"x":4,"y":0,"w":54,"h":54}, 25 | "sourceSize": {"w":62,"h":54} 26 | }, 27 | { 28 | "filename": "pig_4.png", 29 | "frame": {"x":228,"y":2,"w":48,"h":54}, 30 | "rotated": false, 31 | "trimmed": true, 32 | "spriteSourceSize": {"x":10,"y":0,"w":48,"h":54}, 33 | "sourceSize": {"w":62,"h":54} 34 | }, 35 | { 36 | "filename": "pig_5.png", 37 | "frame": {"x":178,"y":2,"w":48,"h":54}, 38 | "rotated": false, 39 | "trimmed": true, 40 | "spriteSourceSize": {"x":10,"y":0,"w":48,"h":54}, 41 | "sourceSize": {"w":62,"h":54} 42 | }, 43 | { 44 | "filename": "pig_6.png", 45 | "frame": {"x":2,"y":2,"w":62,"h":54}, 46 | "rotated": false, 47 | "trimmed": false, 48 | "spriteSourceSize": {"x":0,"y":0,"w":62,"h":54}, 49 | "sourceSize": {"w":62,"h":54} 50 | }], 51 | "meta": { 52 | "app": "http://www.codeandweb.com/texturepacker ", 53 | "version": "1.0", 54 | "image": "pig.png", 55 | "format": "RGBA8888", 56 | "size": {"w":328,"h":58}, 57 | "scale": "1", 58 | "smartupdate": "$TexturePacker:SmartUpdate:9241ee198b56c2e38fdd79ca3303b147:c2ddba175d104f5266fd7e8777d38ec5:4dd13c7db2d2fc02b6406b8a7f7d5ecc$" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /samples/test/common/res/pig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/common/res/pig.png -------------------------------------------------------------------------------- /samples/test/ios/test/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import 16 | 17 | @interface AppDelegate : UIResponder 18 | 19 | @property (strong, nonatomic) UIWindow *window; 20 | 21 | 22 | @end 23 | 24 | -------------------------------------------------------------------------------- /samples/test/ios/test/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /samples/test/ios/test/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /samples/test/ios/test/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /samples/test/ios/test/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UIRequiresFullScreen 34 | 35 | UIStatusBarHidden 36 | 37 | UISupportedInterfaceOrientations 38 | 39 | UIInterfaceOrientationPortrait 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /samples/test/ios/test/RDGLView.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import 16 | 17 | // Call from ViewController 18 | 19 | #define MAX_TOUCH_COUNT (10) 20 | 21 | @interface RDGLView : UIView 22 | { 23 | intptr_t ids[MAX_TOUCH_COUNT]; 24 | float xs[MAX_TOUCH_COUNT]; 25 | float ys[MAX_TOUCH_COUNT]; 26 | } 27 | 28 | - (id) initWithFrame:(CGRect)frame; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /samples/test/ios/test/ViewController.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import 16 | 17 | @interface ViewController : UIViewController 18 | 19 | 20 | @end 21 | 22 | -------------------------------------------------------------------------------- /samples/test/ios/test/ViewController.mm: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "ViewController.h" 16 | #import "RDGLView.h" 17 | #import "startup.h" 18 | 19 | @interface ViewController () { 20 | CGFloat realWidth; 21 | CGFloat realHeight; 22 | } 23 | 24 | @end 25 | 26 | @implementation ViewController 27 | 28 | - (void)loadView 29 | { 30 | /* if locked' Orientations, here is same bug for view to get frame.size, 31 | * so the safe way is get real size by myself. 32 | */ 33 | CGFloat small = MIN([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); 34 | CGFloat big = MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); 35 | if ([self supportedInterfaceOrientations] == UIInterfaceOrientationMaskPortrait) { 36 | realWidth = small; 37 | realHeight = big; 38 | } else { 39 | realWidth = big; 40 | realHeight = small; 41 | } 42 | 43 | self.view = [[RDGLView alloc] initWithFrame:CGRectMake(0, 0, realWidth, realHeight)]; 44 | } 45 | 46 | - (void)viewDidLoad { 47 | [super viewDidLoad]; 48 | 49 | Rapid2D_startup(realWidth * self.view.contentScaleFactor, realHeight * self.view.contentScaleFactor); 50 | } 51 | 52 | - (void)didReceiveMemoryWarning { 53 | [super didReceiveMemoryWarning]; 54 | // Dispose of any resources that can be recreated. 55 | } 56 | 57 | - (BOOL)prefersStatusBarHidden { 58 | return YES; 59 | } 60 | 61 | // orientations support 62 | - (NSUInteger) supportedInterfaceOrientations { 63 | return UIInterfaceOrientationMaskPortrait; 64 | } 65 | 66 | - (BOOL) shouldAutorotate { 67 | return YES; 68 | } 69 | // end of orientations support 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /samples/test/ios/test/main.m: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import 16 | #import "AppDelegate.h" 17 | 18 | int main(int argc, char * argv[]) { 19 | @autoreleasepool { 20 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /samples/test/mac/test/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import 16 | 17 | @interface AppDelegate : NSObject 18 | 19 | 20 | @end 21 | 22 | -------------------------------------------------------------------------------- /samples/test/mac/test/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /samples/test/mac/test/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | $(MACOSX_DEPLOYMENT_TARGET) 27 | NSHumanReadableCopyright 28 | Copyright © 2015 u0u0. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /samples/test/mac/test/RDGLView.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import 16 | 17 | #define GLVIEW_WIDTH (480) 18 | #define GLVIEW_HEIGHT (800) 19 | 20 | @interface RDGLView : NSOpenGLView 21 | { 22 | bool isTouched; 23 | CGFloat orginalWidth; 24 | CGFloat orginalHeight; 25 | intptr_t ids[1]; 26 | float xs[1]; 27 | float ys[1]; 28 | } 29 | 30 | - (id) initWithFrame:(CGRect)frame; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /samples/test/mac/test/main.m: -------------------------------------------------------------------------------- 1 | // Copyright 2016 KeNan Liu 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import 16 | 17 | int main(int argc, const char * argv[]) { 18 | return NSApplicationMain(argc, argv); 19 | } 20 | -------------------------------------------------------------------------------- /samples/test/mac/test/test.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /samples/test/win32/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:test 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 test 应用程序。 6 | 7 | 本文件概要介绍组成 test 应用程序的每个文件的内容。 8 | 9 | 10 | test.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | test.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | test.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 test.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /samples/test/win32/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/win32/stdafx.cpp -------------------------------------------------------------------------------- /samples/test/win32/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/win32/stdafx.h -------------------------------------------------------------------------------- /samples/test/win32/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/samples/test/win32/targetver.h -------------------------------------------------------------------------------- /samples/test/win32/test.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test.vcxproj", "{B5C02067-20A4-4F6A-8CD3-6765435E9674}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {8088D57F-7396-4437-9925-3F5F74E6D0DD} = {8088D57F-7396-4437-9925-3F5F74E6D0DD} 9 | EndProjectSection 10 | EndProject 11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core", "..\..\..\core\projects\win32\core.vcxproj", "{8088D57F-7396-4437-9925-3F5F74E6D0DD}" 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Win32 = Debug|Win32 16 | Release|Win32 = Release|Win32 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {B5C02067-20A4-4F6A-8CD3-6765435E9674}.Debug|Win32.ActiveCfg = Debug|Win32 20 | {B5C02067-20A4-4F6A-8CD3-6765435E9674}.Debug|Win32.Build.0 = Debug|Win32 21 | {B5C02067-20A4-4F6A-8CD3-6765435E9674}.Release|Win32.ActiveCfg = Release|Win32 22 | {B5C02067-20A4-4F6A-8CD3-6765435E9674}.Release|Win32.Build.0 = Release|Win32 23 | {8088D57F-7396-4437-9925-3F5F74E6D0DD}.Debug|Win32.ActiveCfg = Debug|Win32 24 | {8088D57F-7396-4437-9925-3F5F74E6D0DD}.Debug|Win32.Build.0 = Debug|Win32 25 | {8088D57F-7396-4437-9925-3F5F74E6D0DD}.Release|Win32.ActiveCfg = Release|Win32 26 | {8088D57F-7396-4437-9925-3F5F74E6D0DD}.Release|Win32.Build.0 = Release|Win32 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /samples/test/win32/test.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 6 | h;hh;hpp;hxx;hm;inl;inc;xsd 7 | 8 | 9 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 10 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 11 | 12 | 13 | {7a63ad67-4ffd-4326-8653-60a2fb94281d} 14 | 15 | 16 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 17 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | header 26 | 27 | 28 | header 29 | 30 | 31 | source\cpp 32 | 33 | 34 | 35 | 36 | source 37 | 38 | 39 | source 40 | 41 | 42 | source\cpp 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /samples/test/win32/test.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /thirdParty/OpenAL/android/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | # lib al common 4 | include $(CLEAR_VARS) 5 | LOCAL_MODULE := static_alcommon 6 | LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libcommon.a 7 | include $(PREBUILT_STATIC_LIBRARY) 8 | 9 | # lib OpenAL 10 | include $(CLEAR_VARS) 11 | LOCAL_MODULE := static_OpenAL 12 | LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libopenal.a 13 | LOCAL_STATIC_LIBRARIES += static_alcommon 14 | include $(PREBUILT_STATIC_LIBRARY) 15 | -------------------------------------------------------------------------------- /thirdParty/OpenAL/android/armeabi-v7a/libcommon.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/OpenAL/android/armeabi-v7a/libcommon.a -------------------------------------------------------------------------------- /thirdParty/OpenAL/android/armeabi-v7a/libopenal.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/OpenAL/android/armeabi-v7a/libopenal.a -------------------------------------------------------------------------------- /thirdParty/OpenAL/android/armeabi/libcommon.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/OpenAL/android/armeabi/libcommon.a -------------------------------------------------------------------------------- /thirdParty/OpenAL/android/armeabi/libopenal.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/OpenAL/android/armeabi/libopenal.a -------------------------------------------------------------------------------- /thirdParty/OpenAL/android/x86/libcommon.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/OpenAL/android/x86/libcommon.a -------------------------------------------------------------------------------- /thirdParty/OpenAL/android/x86/libopenal.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/OpenAL/android/x86/libopenal.a -------------------------------------------------------------------------------- /thirdParty/OpenAL/inc/efx-creative.h: -------------------------------------------------------------------------------- 1 | /* The tokens that would be defined here are already defined in efx.h. This 2 | * empty file is here to provide compatibility with Windows-based projects 3 | * that would include it. */ 4 | -------------------------------------------------------------------------------- /thirdParty/OpenAL/win32/OpenAL32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/OpenAL/win32/OpenAL32.dll -------------------------------------------------------------------------------- /thirdParty/OpenAL/win32/OpenAL32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/OpenAL/win32/OpenAL32.lib -------------------------------------------------------------------------------- /thirdParty/OpenAL/win32/common.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/OpenAL/win32/common.lib -------------------------------------------------------------------------------- /thirdParty/glew/win32/glew32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/glew/win32/glew32.dll -------------------------------------------------------------------------------- /thirdParty/glew/win32/glew32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/glew/win32/glew32.lib -------------------------------------------------------------------------------- /thirdParty/glfw/win32/glfw3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/glfw/win32/glfw3.dll -------------------------------------------------------------------------------- /thirdParty/glfw/win32/glfw3dll.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/glfw/win32/glfw3dll.lib -------------------------------------------------------------------------------- /thirdParty/png/android/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | LOCAL_MODULE := static_png 5 | LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libpng.a 6 | LOCAL_STATIC_LIBRARIES += static_z 7 | include $(PREBUILT_STATIC_LIBRARY) 8 | -------------------------------------------------------------------------------- /thirdParty/png/android/armeabi-v7a/libpng.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/png/android/armeabi-v7a/libpng.a -------------------------------------------------------------------------------- /thirdParty/png/android/armeabi/libpng.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/png/android/armeabi/libpng.a -------------------------------------------------------------------------------- /thirdParty/png/android/x86/libpng.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/png/android/x86/libpng.a -------------------------------------------------------------------------------- /thirdParty/png/ios/libpng.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/png/ios/libpng.a -------------------------------------------------------------------------------- /thirdParty/png/mac/libpng.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/png/mac/libpng.a -------------------------------------------------------------------------------- /thirdParty/png/win32/libpng.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/png/win32/libpng.lib -------------------------------------------------------------------------------- /thirdParty/z/android/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | LOCAL_MODULE := static_z 5 | #LOCAL_MODULE_FILENAME := z 6 | LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libz.a 7 | include $(PREBUILT_STATIC_LIBRARY) 8 | -------------------------------------------------------------------------------- /thirdParty/z/android/armeabi-v7a/libz.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/z/android/armeabi-v7a/libz.a -------------------------------------------------------------------------------- /thirdParty/z/android/armeabi/libz.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/z/android/armeabi/libz.a -------------------------------------------------------------------------------- /thirdParty/z/android/x86/libz.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/z/android/x86/libz.a -------------------------------------------------------------------------------- /thirdParty/z/ios/libz.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/z/ios/libz.a -------------------------------------------------------------------------------- /thirdParty/z/mac/libz.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/z/mac/libz.a -------------------------------------------------------------------------------- /thirdParty/z/win32/zlib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/z/win32/zlib.dll -------------------------------------------------------------------------------- /thirdParty/z/win32/zlib.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/thirdParty/z/win32/zlib.lib -------------------------------------------------------------------------------- /tool/mac/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: UTF-8 -*- 3 | 4 | __all__ = ["xxtea"] 5 | -------------------------------------------------------------------------------- /tool/mac/luac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/tool/mac/luac -------------------------------------------------------------------------------- /tool/mac/xxtea.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/tool/mac/xxtea.so -------------------------------------------------------------------------------- /tool/win32/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: UTF-8 -*- 3 | 4 | __all__ = ["xxtea"] 5 | -------------------------------------------------------------------------------- /tool/win32/luac.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/tool/win32/luac.exe -------------------------------------------------------------------------------- /tool/win32/xxtea.pyd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u0u0/Rapid2D/f19b9e5def8bd87ff20dcd2641a30adb090b14db/tool/win32/xxtea.pyd --------------------------------------------------------------------------------