├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── faststream ├── api │ └── faststream.script_api ├── defold-fast-posh-vector2stream.code-workspace ├── ext.manifest ├── ext.manifest_debug ├── ext.manifest_release └── src │ └── faststream.cpp ├── game.project ├── input └── game.input_binding ├── main ├── debug.appmanifest ├── main.collection └── test.script └── script.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Defold Protocol Buffer Text Files (https://github.com/github/linguist/issues/5091) 2 | *.animationset linguist-language=JSON5 3 | *.atlas linguist-language=JSON5 4 | *.camera linguist-language=JSON5 5 | *.collection linguist-language=JSON5 6 | *.collectionfactory linguist-language=JSON5 7 | *.collectionproxy linguist-language=JSON5 8 | *.collisionobject linguist-language=JSON5 9 | *.cubemap linguist-language=JSON5 10 | *.display_profiles linguist-language=JSON5 11 | *.factory linguist-language=JSON5 12 | *.font linguist-language=JSON5 13 | *.gamepads linguist-language=JSON5 14 | *.go linguist-language=JSON5 15 | *.gui linguist-language=JSON5 16 | *.input_binding linguist-language=JSON5 17 | *.label linguist-language=JSON5 18 | *.material linguist-language=JSON5 19 | *.mesh linguist-language=JSON5 20 | *.model linguist-language=JSON5 21 | *.particlefx linguist-language=JSON5 22 | *.render linguist-language=JSON5 23 | *.sound linguist-language=JSON5 24 | *.sprite linguist-language=JSON5 25 | *.spinemodel linguist-language=JSON5 26 | *.spinescene linguist-language=JSON5 27 | *.texture_profiles linguist-language=JSON5 28 | *.tilemap linguist-language=JSON5 29 | *.tilesource linguist-language=JSON5 30 | 31 | # Defold JSON Files 32 | *.buffer linguist-language=JSON 33 | 34 | # Defold GLSL Shaders 35 | *.fp linguist-language=GLSL 36 | *.vp linguist-language=GLSL 37 | 38 | # Defold Lua Files 39 | *.editor_script linguist-language=Lua 40 | *.render_script linguist-language=Lua 41 | *.script linguist-language=Lua 42 | *.gui_script linguist-language=Lua 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.internal 2 | /build 3 | .externalToolBuilders 4 | .DS_Store 5 | Thumbs.db 6 | .lock-wscript 7 | *.pyc 8 | .project 9 | .cproject 10 | /.vscode 11 | *.pdb 12 | builtins 13 | /vs_debug 14 | *.der -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://github.com/user-attachments/assets/2c11ba97-163e-445f-bac5-21a1bfd97e92) 2 | 3 | # FastStream Defold Extension 4 | 5 | FastStream is a Defold extension that provides efficient buffer stream operations for handling vector data. 6 | 7 | ## API Reference 8 | 9 | ### Functions 10 | 11 | #### `faststream.set_table_raw(stream, table)` 12 | Sets multiple vector values from a table to the buffer stream without converting values to stream type. The table should contain either Vector3 or Vector4 values. 13 | 14 | **Parameters:** 15 | - `stream` (userdata) - The buffer stream to modify 16 | - `table` (table) - Table containing Vector3 or Vector4 values to set 17 | 18 | #### `faststream.set_table_universal(stream, table)` 19 | Sets multiple values from a table to the buffer stream. Supports Vector3, Vector4, or number values. 20 | 21 | **Parameters:** 22 | - `stream` (userdata) - The buffer stream to modify 23 | - `table` (table) - Table containing Vector3, Vector4, or number values to set 24 | 25 | #### `faststream.set_vector2(stream, index, vector)` 26 | Sets a Vector3 value at the specified index in the buffer stream. 27 | 28 | **Parameters:** 29 | - `stream` (userdata) - The buffer stream to modify 30 | - `index` (number) - The 1-based index where to set the vector 31 | - `vector` (vector3) - The Vector3 value to set (x,y components will be used) 32 | 33 | #### `faststream.set_vector3(stream, index, vector)` 34 | Sets a Vector3 value at the specified index in the buffer stream. 35 | 36 | **Parameters:** 37 | - `stream` (userdata) - The buffer stream to modify 38 | - `index` (number) - The 1-based index where to set the vector 39 | - `vector` (vector3) - The Vector3 value to set 40 | 41 | #### `faststream.set_vector4(stream, index, vector)` 42 | Sets a Vector4 value at the specified index in the buffer stream. 43 | 44 | **Parameters:** 45 | - `stream` (userdata) - The buffer stream to modify 46 | - `index` (number) - The 1-based index where to set the vector 47 | - `vector` (vector4) - The Vector4 value to set 48 | 49 | ## Usage Examples 50 | 51 | ```lua 52 | -- Set a single Vector3 value 53 | local stream = ... -- your buffer stream, like buffer.get_stream(buf, "position") 54 | local vector = vmath.vector3(1, 2, 3) 55 | faststream.set_vector3(stream, 1, vector) 56 | 57 | -- Set multiple values using a table 58 | local values = { 59 | vmath.vector3(1, 2, 3), 60 | vmath.vector3(4, 5, 6), 61 | vmath.vector3(7, 8, 9) 62 | } 63 | faststream.set_table_universal(stream, values) 64 | 65 | -- Set raw vector values without conversion 66 | local raw_values = { 67 | vmath.vector4(1, 2, 3, 4), 68 | vmath.vector4(5, 6, 7, 8) 69 | } 70 | faststream.set_table_raw(stream, raw_values) 71 | ``` 72 | -------------------------------------------------------------------------------- /faststream/api/faststream.script_api: -------------------------------------------------------------------------------- 1 | - name: faststream 2 | type: table 3 | desc: FastStream extension for efficient buffer stream operations in Defold. 4 | members: 5 | 6 | - name: set_vector2 7 | type: function 8 | desc: Sets a Vector3 value at the specified index in the buffer stream. 9 | parameters: 10 | - name: stream 11 | type: userdata 12 | desc: The buffer stream to modify 13 | - name: index 14 | type: number 15 | desc: The 1-based index where to set the vector 16 | - name: vector 17 | type: vector3 18 | desc: The Vector3 value to set (x,y components will be used) 19 | 20 | - name: set_vector3 21 | type: function 22 | desc: Sets a Vector3 value at the specified index in the buffer stream. 23 | parameters: 24 | - name: stream 25 | type: userdata 26 | desc: The buffer stream to modify 27 | - name: index 28 | type: number 29 | desc: The 1-based index where to set the vector 30 | - name: vector 31 | type: vector3 32 | desc: The Vector3 value to set 33 | 34 | - name: set_vector4 35 | type: function 36 | desc: Sets a Vector4 value at the specified index in the buffer stream. 37 | parameters: 38 | - name: stream 39 | type: userdata 40 | desc: The buffer stream to modify 41 | - name: index 42 | type: number 43 | desc: The 1-based index where to set the vector 44 | - name: vector 45 | type: vector4 46 | desc: The Vector4 value to set 47 | 48 | - name: set_table_raw 49 | type: function 50 | desc: Sets multiple vector values from a table to the buffer stream. The table should contain either Vector3 or Vector4 values. 51 | parameters: 52 | - name: stream 53 | type: userdata 54 | desc: The buffer stream to modify 55 | - name: table 56 | type: table 57 | desc: Table containing Vector3 or Vector4 values to set 58 | 59 | - name: set_table_universal 60 | type: function 61 | desc: Sets multiple values from a table to the buffer stream. Supports Vector3, Vector4, or number values. 62 | parameters: 63 | - name: stream 64 | type: userdata 65 | desc: The buffer stream to modify 66 | - name: table 67 | type: table 68 | desc: Table containing Vector3, Vector4, or number values to set 69 | -------------------------------------------------------------------------------- /faststream/defold-fast-posh-vector2stream.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": ".." 5 | } 6 | ], 7 | "settings": {} 8 | } -------------------------------------------------------------------------------- /faststream/ext.manifest: -------------------------------------------------------------------------------- 1 | # C++ symbol in your extension 2 | name: "faststream" 3 | 4 | platforms: 5 | x86_64-win32: 6 | context: 7 | flags: ["-O0"] -------------------------------------------------------------------------------- /faststream/ext.manifest_debug: -------------------------------------------------------------------------------- 1 | # C++ symbol in your extension 2 | name: "faststream" 3 | 4 | platforms: 5 | x86_64-win32: 6 | context: 7 | flags: ["-O0"] -------------------------------------------------------------------------------- /faststream/ext.manifest_release: -------------------------------------------------------------------------------- 1 | # C++ symbol in your extension 2 | name: "faststream" -------------------------------------------------------------------------------- /faststream/src/faststream.cpp: -------------------------------------------------------------------------------- 1 | // Extension lib defines 2 | #define LIB_NAME "FastStream" 3 | #define MODULE_NAME "faststream" 4 | #define SCRIPT_LIB_NAME "buffer" 5 | #define SCRIPT_TYPE_NAME_BUFFER "buffer" 6 | #define SCRIPT_TYPE_NAME_BUFFERSTREAM "bufferstream" 7 | 8 | // include the Defold SDK 9 | #include 10 | #include 11 | 12 | namespace dmScript { 13 | void* CheckUserType(lua_State* L, int user_data_index, uint32_t type_hash, const char* error_message); 14 | static uint32_t SCRIPT_BUFFERSTREAM_TYPE_HASH = dmHashString32(SCRIPT_TYPE_NAME_BUFFERSTREAM); 15 | } 16 | 17 | typedef void (*FStreamSetter)(void* data, int index, lua_Number v); 18 | typedef lua_Number (*FStreamGetter)(void* data, int index); 19 | 20 | struct BufferStream 21 | { 22 | dmBuffer::HBuffer m_Buffer; 23 | dmhash_t m_Name; // The stream name 24 | void* m_Data; // Pointer to the first struct in the stream 25 | FStreamSetter m_Set; 26 | FStreamGetter m_Get; 27 | uint32_t m_Count; // Number of structs contained in the stream (or buffer) 28 | uint32_t m_Stride; // The stride of the pointer, measured in the units of the value type 29 | uint32_t m_TypeCount;// number of components that make up an "element". E.g. 3 in a Vec3 30 | dmBuffer::ValueType m_Type; // The type of elements in the array 31 | int m_BufferRef;// Holds a reference to the Lua object 32 | }; 33 | 34 | static BufferStream* CheckStream(lua_State* L, int index) 35 | { 36 | if (lua_type(L, index) == LUA_TUSERDATA) 37 | { 38 | BufferStream* stream = (BufferStream*)dmScript::CheckUserType(L, index, dmScript::SCRIPT_BUFFERSTREAM_TYPE_HASH, 0); 39 | if (stream && dmBuffer::IsBufferValid(stream->m_Buffer)) 40 | { 41 | return stream; 42 | } 43 | luaL_error(L, "The buffer handle is invalid"); 44 | } 45 | // dmScript::Ref 46 | luaL_typerror(L, index, SCRIPT_TYPE_NAME_BUFFERSTREAM); 47 | return 0x0; 48 | } 49 | 50 | static int set_vector2_to_stream(lua_State* L) 51 | { 52 | DM_LUA_STACK_CHECK(L, 0); 53 | BufferStream* stream = CheckStream(L, 1); 54 | int index = luaL_checkinteger(L, 2) - 1; 55 | dmVMath::Vector3* v = dmScript::ToVector3(L, 3); 56 | 57 | uint32_t vector_sizeof = sizeof(float)*2; 58 | memcpy((uint8_t*)(stream->m_Data) + index*stream->m_Stride*sizeof(float), v, vector_sizeof); 59 | dmBuffer::UpdateContentVersion(stream->m_Buffer); 60 | return 0; 61 | } 62 | 63 | static int set_vector3_to_stream(lua_State* L) 64 | { 65 | DM_LUA_STACK_CHECK(L, 0); 66 | BufferStream* stream = CheckStream(L, 1); 67 | int index = luaL_checkinteger(L, 2) - 1; 68 | dmVMath::Vector3* v = dmScript::ToVector3(L, 3); 69 | 70 | uint32_t vector_sizeof = sizeof(float)*3; 71 | memcpy((uint8_t*)(stream->m_Data) + index*stream->m_Stride*sizeof(float), v, vector_sizeof); 72 | dmBuffer::UpdateContentVersion(stream->m_Buffer); 73 | return 0; 74 | } 75 | 76 | static int set_vector4_to_stream(lua_State* L) 77 | { 78 | DM_LUA_STACK_CHECK(L, 0); 79 | BufferStream* stream = CheckStream(L, 1); 80 | int index = luaL_checkinteger(L, 2) - 1; 81 | dmVMath::Vector4* v = dmScript::ToVector4(L, 3); 82 | 83 | uint32_t vector_sizeof = sizeof(float)*4; 84 | memcpy((uint8_t*)(stream->m_Data) + index*stream->m_Stride*sizeof(float), v, vector_sizeof); 85 | dmBuffer::UpdateContentVersion(stream->m_Buffer); 86 | return 0; 87 | } 88 | 89 | using sFStreamSetter = int *(void* data_stream, int *date_value, int data_width); 90 | using getVectorData = uint8_t* (lua_State* L, int index); 91 | // Stack 92 | // 1 stream 93 | // 2 table vector3 || vector4 94 | 95 | static int set_table(lua_State* L) 96 | { 97 | DM_LUA_STACK_CHECK(L, 0); 98 | 99 | BufferStream* stream = CheckStream(L, 1); 100 | if (!lua_istable(L, 2)) { 101 | return 0; 102 | } 103 | 104 | size_t data_count = lua_objlen(L, 2); // 2 - table 105 | 106 | if (data_count == 0) { 107 | return 0; 108 | } 109 | 110 | // Check table data type 111 | lua_pushnil(L); // first key 112 | lua_next(L, 2); 113 | 114 | size_t element_count; 115 | // getVectorData *func; 116 | if (dmScript::IsVector3(L, -1)) { 117 | element_count = 3; 118 | // func = reinterpret_cast (dmScript::ToVector3); 119 | } else { 120 | element_count = 4; 121 | } 122 | 123 | uint8_t *data; 124 | uint32_t vector_sizeof = sizeof(float)*element_count; 125 | for( int index = 0; index < data_count; index++, lua_next(L, -2)) { 126 | if (element_count == 3) 127 | { 128 | dmVMath::Vector3* v= dmScript::ToVector3(L, -1); 129 | data = (uint8_t*)v; 130 | } else { 131 | dmVMath::Vector4* v= dmScript::ToVector4(L, -1); 132 | data = (uint8_t*)v; 133 | } 134 | 135 | memcpy((uint8_t*)(stream->m_Data) + index*stream->m_Stride*sizeof(float), data, vector_sizeof); 136 | lua_pop(L, 1); 137 | } 138 | dmBuffer::UpdateContentVersion(stream->m_Buffer); 139 | return 0; 140 | } 141 | 142 | // PUSHER 143 | 144 | using pusherFunc = void (lua_State* L, int stack_index, BufferStream* stream, int &buffer_index); 145 | 146 | void pusherNumberByIndex(BufferStream* stream, int &buffer_index, float value) { 147 | uint32_t count = buffer_index / stream->m_TypeCount; 148 | uint32_t component = buffer_index % stream->m_TypeCount; 149 | stream->m_Set(stream->m_Data, count * stream->m_Stride + component, value); 150 | buffer_index++; 151 | } 152 | 153 | void pusherVector3(lua_State* L, int stack_index, BufferStream* stream, int &buffer_index) { 154 | dmVMath::Vector3* v = dmScript::ToVector3(L, stack_index); 155 | 156 | pusherNumberByIndex(stream, buffer_index, v->getX()); 157 | pusherNumberByIndex(stream, buffer_index, v->getY()); 158 | pusherNumberByIndex(stream, buffer_index, v->getZ()); 159 | } 160 | 161 | void pusherVector4(lua_State* L, int stack_index, BufferStream* stream, int &buffer_index){ 162 | dmVMath::Vector4* v = dmScript::ToVector4(L, stack_index); 163 | 164 | pusherNumberByIndex(stream, buffer_index, v->getX()); 165 | pusherNumberByIndex(stream, buffer_index, v->getY()); 166 | pusherNumberByIndex(stream, buffer_index, v->getZ()); 167 | pusherNumberByIndex(stream, buffer_index, v->getW()); 168 | } 169 | 170 | void pusherNumber(lua_State* L, int stack_index, BufferStream* stream, int &buffer_index) { 171 | pusherNumberByIndex(stream, buffer_index, lua_tonumber(L, stack_index)); 172 | } 173 | 174 | // Stack 175 | // 1 stream 176 | // 2 table vector3 || vector4 || number 177 | 178 | static int set_table_universal(lua_State* L) 179 | { 180 | DM_LUA_STACK_CHECK(L, 0); 181 | 182 | BufferStream* stream = CheckStream(L, 1); 183 | size_t table_length = lua_objlen(L, 2); // 2 - table 184 | 185 | if (table_length == 0) { 186 | return 0; 187 | } 188 | 189 | // Check table data type 190 | lua_pushnil(L); // first key 191 | lua_next(L, 2); 192 | 193 | 194 | pusherFunc *func = nullptr; 195 | 196 | if (dmScript::IsVector3(L, -1)) { 197 | func = pusherVector3; 198 | } 199 | 200 | if (dmScript::IsVector4(L, -1)) { 201 | func = pusherVector4; 202 | } 203 | 204 | if (lua_isnumber(L, -1)) { 205 | func = pusherNumber; 206 | } 207 | 208 | if (func == nullptr) { 209 | luaL_typerror(L, -1, "vector3 or vector4 or number"); 210 | } 211 | 212 | // Table iteration 213 | for(int table_index = 0, buffer_index = 0; table_index < table_length; table_index++, lua_next(L, 2)) { 214 | func(L, -1, stream, buffer_index); 215 | lua_pop(L, 1); 216 | } 217 | dmBuffer::UpdateContentVersion(stream->m_Buffer); 218 | return 0; 219 | } 220 | 221 | // Functions exposed to Lua 222 | static const luaL_reg Module_methods[] = 223 | { 224 | {"set_vector2", set_vector2_to_stream}, 225 | {"set_vector3", set_vector3_to_stream}, 226 | {"set_vector4", set_vector4_to_stream}, 227 | {"set_table_raw", set_table}, 228 | {"set_table_universal", set_table_universal}, 229 | {0, 0} 230 | }; 231 | 232 | #pragma region Extension 233 | static void LuaInit(lua_State* L) 234 | { 235 | int top = lua_gettop(L); 236 | 237 | // Register lua names 238 | luaL_register(L, MODULE_NAME, Module_methods); 239 | 240 | lua_pop(L, 1); 241 | assert(top == lua_gettop(L)); 242 | } 243 | 244 | static dmExtension::Result AppInitializeMyExtension(dmExtension::AppParams* params) 245 | { 246 | return dmExtension::RESULT_OK; 247 | } 248 | 249 | static dmExtension::Result InitializeMyExtension(dmExtension::Params* params) 250 | { 251 | // Init Lua 252 | LuaInit(params->m_L); 253 | return dmExtension::RESULT_OK; 254 | } 255 | 256 | static dmExtension::Result AppFinalizeMyExtension(dmExtension::AppParams* params) 257 | { 258 | return dmExtension::RESULT_OK; 259 | } 260 | 261 | static dmExtension::Result FinalizeMyExtension(dmExtension::Params* params) 262 | { 263 | return dmExtension::RESULT_OK; 264 | } 265 | 266 | static dmExtension::Result OnUpdateMyExtension(dmExtension::Params* params) 267 | { 268 | return dmExtension::RESULT_OK; 269 | } 270 | 271 | static void OnEventMyExtension(dmExtension::Params* params, const dmExtension::Event* event) {} 272 | 273 | DM_DECLARE_EXTENSION(faststream, LIB_NAME, AppInitializeMyExtension, AppFinalizeMyExtension, InitializeMyExtension, OnUpdateMyExtension, OnEventMyExtension, FinalizeMyExtension) 274 | #pragma endregion -------------------------------------------------------------------------------- /game.project: -------------------------------------------------------------------------------- 1 | [bootstrap] 2 | main_collection = /main/main.collectionc 3 | 4 | [script] 5 | shared_state = 1 6 | 7 | [display] 8 | width = 960 9 | height = 640 10 | 11 | [android] 12 | input_method = HiddenInputField 13 | 14 | [project] 15 | title = Fast Stream 16 | 17 | [library] 18 | include_dirs = faststream 19 | 20 | -------------------------------------------------------------------------------- /input/game.input_binding: -------------------------------------------------------------------------------- 1 | mouse_trigger { 2 | input: MOUSE_BUTTON_1 3 | action: "touch" 4 | } 5 | -------------------------------------------------------------------------------- /main/debug.appmanifest: -------------------------------------------------------------------------------- 1 | platforms: 2 | armv7-ios: 3 | context: 4 | excludeLibs: [] 5 | excludeSymbols: [] 6 | symbols: [] 7 | libs: [] 8 | frameworks: [] 9 | linkFlags: [] 10 | arm64-ios: 11 | context: 12 | excludeLibs: [] 13 | excludeSymbols: [] 14 | symbols: [] 15 | libs: [] 16 | frameworks: [] 17 | linkFlags: [] 18 | x86_64-ios: 19 | context: 20 | excludeLibs: [] 21 | excludeSymbols: [] 22 | symbols: [] 23 | libs: [] 24 | frameworks: [] 25 | linkFlags: [] 26 | armv7-android: 27 | context: 28 | excludeLibs: [] 29 | excludeJars: [] 30 | excludeSymbols: [] 31 | symbols: [] 32 | libs: [] 33 | linkFlags: [] 34 | jetifier: true 35 | arm64-android: 36 | context: 37 | excludeLibs: [] 38 | excludeJars: [] 39 | excludeSymbols: [] 40 | symbols: [] 41 | libs: [] 42 | linkFlags: [] 43 | jetifier: true 44 | x86_64-osx: 45 | context: 46 | excludeLibs: [] 47 | excludeSymbols: [] 48 | symbols: [] 49 | libs: [] 50 | frameworks: [] 51 | linkFlags: [] 52 | x86_64-linux: 53 | context: 54 | excludeLibs: [] 55 | excludeSymbols: [] 56 | symbols: [] 57 | libs: [] 58 | linkFlags: [] 59 | x86-win32: 60 | context: 61 | excludeLibs: [] 62 | excludeSymbols: [] 63 | symbols: [] 64 | libs: [] 65 | linkFlags: [] 66 | defines: ["DM_DEBUG"] 67 | x86_64-win32: 68 | context: 69 | excludeLibs: [] 70 | excludeSymbols: [] 71 | symbols: [] 72 | libs: [] 73 | linkFlags: [] 74 | defines: ["DM_DEBUG"] 75 | js-web: 76 | context: 77 | excludeLibs: [] 78 | excludeJsLibs: [] 79 | excludeSymbols: [] 80 | symbols: [] 81 | libs: [] 82 | linkFlags: [] 83 | wasm-web: 84 | context: 85 | excludeLibs: [] 86 | excludeJsLibs: [] 87 | excludeSymbols: [] 88 | symbols: [] 89 | libs: [] 90 | linkFlags: [] 91 | -------------------------------------------------------------------------------- /main/main.collection: -------------------------------------------------------------------------------- 1 | name: "main" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "go" 5 | data: "components {\n" 6 | " id: \"test\"\n" 7 | " component: \"/main/test.script\"\n" 8 | " position {\n" 9 | " x: 0.0\n" 10 | " y: 0.0\n" 11 | " z: 0.0\n" 12 | " }\n" 13 | " rotation {\n" 14 | " x: 0.0\n" 15 | " y: 0.0\n" 16 | " z: 0.0\n" 17 | " w: 1.0\n" 18 | " }\n" 19 | " property_decls {\n" 20 | " }\n" 21 | "}\n" 22 | "" 23 | position { 24 | x: 0.0 25 | y: 0.0 26 | z: 0.0 27 | } 28 | rotation { 29 | x: 0.0 30 | y: 0.0 31 | z: 0.0 32 | w: 1.0 33 | } 34 | scale3 { 35 | x: 1.0 36 | y: 1.0 37 | z: 1.0 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /main/test.script: -------------------------------------------------------------------------------- 1 | function init(self) 2 | points_count = 10 3 | local buf = buffer.create(points_count*2, { 4 | { name = hash("position"), type=buffer.VALUE_TYPE_FLOAT32, count = 3 }, 5 | { name = hash("texcoord0"), type=buffer.VALUE_TYPE_FLOAT32, count = 2 }, 6 | { name = hash("tint"), type=buffer.VALUE_TYPE_FLOAT32, count = 7 }, 7 | }) 8 | 9 | local vertex_position_stream = buffer.get_stream(buf, "position") 10 | local vertex_texcoord_stream = buffer.get_stream(buf, "texcoord0") 11 | 12 | -- faststream.set_vector2_to_stream(vertex_texcoord_stream, 1, vmath.vector3(2, 3, 4)) 13 | -- faststream.set_vector2_to_stream(vertex_texcoord_stream, 2, vmath.vector3(10, 11, 22)) 14 | -- faststream.set_vector2_to_stream(vertex_texcoord_stream, 3, vmath.vector3(13, 14, 52)) 15 | -- 16 | local t = {} 17 | t[1] = vmath.vector3(1,2,3) 18 | t[2] = vmath.vector3(1,2,3) 19 | t[3] = vmath.vector3(1,2,3) 20 | t[4] = vmath.vector3(1,2,3) 21 | local v = vmath.vector3(6.123233998228e-16, -10, 0) 22 | faststream.set_table_raw(vertex_position_stream, {v}) 23 | -- faststream.set_table(vertex_position_stream, t) 24 | faststream.set_table_universal(vertex_position_stream, t) 25 | for i=1, #vertex_position_stream do 26 | print(vertex_position_stream[i]) 27 | end 28 | end -------------------------------------------------------------------------------- /script.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | import json 4 | 5 | file_path_from_search = sys.argv[1] 6 | file_path_from_set = sys.argv[2] 7 | 8 | hash_str = "" 9 | with open(file_path_from_search) as file: 10 | lines = file.read() 11 | hash_str = re.search("job\d*", lines)[0] 12 | 13 | with open(file_path_from_set, "r") as file: 14 | data = json.load(file) 15 | 16 | with open(file_path_from_set, "w") as file: 17 | data['hash_folder'] = hash_str 18 | json.dump(data, file, indent=4) --------------------------------------------------------------------------------