├── pics ├── why.png ├── game1.png ├── game2.png ├── menu1.png └── menu2.png ├── .gitattributes ├── tutorials ├── README.md └── 01-Core-Initialization │ ├── bin │ └── 01-Core-Initialization.exe │ ├── src │ └── 01-Core-Initialization.c │ ├── vcproj │ ├── 01-Core-Initialization.vcxproj.filters │ └── 01-Core-Initialization.sln │ └── README.md ├── .gitignore ├── LICENSE ├── core ├── hash.h ├── thread.c ├── time.h ├── rect.c ├── byteorder.h ├── clipboard.h ├── rectpack.h ├── string_utils.h ├── base64.h ├── log.h ├── color.h ├── rect.h ├── byteorder.c ├── color.c ├── hash.c ├── utility.h ├── color_gradient.h ├── memmgr.h ├── event.h ├── memmgr.c ├── thread_posix.c ├── rectpack.c ├── path.h ├── log.c ├── config.h ├── thread_win32.c ├── utility.c ├── utf32string.c ├── thread.h ├── utf32string.h └── linked_list.h ├── math ├── mat3.c ├── mat3.h ├── triangulator.h ├── plane.h ├── frustum.h ├── plane.c ├── aabb.h └── quat.h ├── physics ├── physics.c ├── physics.h ├── gjk_epa.h └── octree.h ├── gui ├── canvas.h ├── stack_panel.h ├── image.h ├── check_box.h ├── text_box.h ├── border.h ├── scroll_viewer.h ├── button.h ├── slide_selector.h ├── scroll_content_presenter.h ├── canvas.c ├── text.h ├── window.h ├── image.c ├── check_box.c └── scroll_bar.h ├── fbx ├── fbx_binary.h ├── fbx_ascii.h ├── fbx.h └── fbx_node.h ├── sound ├── sound.c ├── listener.h ├── listener.c ├── device.h ├── context.h ├── decoder.h └── context.c ├── resources ├── model.h ├── image.h ├── texture.h ├── resource_fdecl.h ├── texture.c ├── resource.h └── model.c ├── editor └── editor.h ├── scene ├── mesh.h ├── camera.h ├── light.h ├── scene.h └── light.c ├── vg └── vgraster.h ├── de_main.c ├── font └── font.h └── input └── input.h /pics/why.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrDIMAS/DmitrysEngine/HEAD/pics/why.png -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /pics/game1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrDIMAS/DmitrysEngine/HEAD/pics/game1.png -------------------------------------------------------------------------------- /pics/game2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrDIMAS/DmitrysEngine/HEAD/pics/game2.png -------------------------------------------------------------------------------- /pics/menu1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrDIMAS/DmitrysEngine/HEAD/pics/menu1.png -------------------------------------------------------------------------------- /pics/menu2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrDIMAS/DmitrysEngine/HEAD/pics/menu2.png -------------------------------------------------------------------------------- /tutorials/README.md: -------------------------------------------------------------------------------- 1 | # Tutorials 2 | 3 | Here you can find tutorials for each part of engine. -------------------------------------------------------------------------------- /tutorials/01-Core-Initialization/bin/01-Core-Initialization.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrDIMAS/DmitrysEngine/HEAD/tutorials/01-Core-Initialization/bin/01-Core-Initialization.exe -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.lib 2 | *.exp 3 | *.pdb 4 | *.cmd 5 | *.log 6 | *.ilk 7 | *.iobj 8 | *.ipdb 9 | *.db 10 | *.user 11 | *.opendb 12 | *.tlog 13 | *.idb 14 | *.obj 15 | *.suo 16 | 17 | /tests/codeliteproj/.codelite 18 | /tests/codeliteproj/Debug 19 | /tests/codeliteproj/Release 20 | 21 | /tests/vcproj/Debug 22 | /tests/vcproj/x64 23 | /tests/vcproj/Release 24 | /tests/vcproj/.vs 25 | 26 | *.psess 27 | *.vsp 28 | -------------------------------------------------------------------------------- /tutorials/01-Core-Initialization/src/01-Core-Initialization.c: -------------------------------------------------------------------------------- 1 | #include "de_main.h" 2 | 3 | int main(int argc, char** argv) 4 | { 5 | /* Fill config using designated initializer. */ 6 | const de_core_config_t config = { 7 | .video_mode = { 8 | .width = 800, 9 | .height = 600, 10 | } 11 | }; 12 | 13 | /* Initialize core. */ 14 | de_core_t* core = de_core_init(&config); 15 | 16 | /* Run main loop. */ 17 | while (de_core_is_running(core)) { 18 | de_event_t evt; 19 | if (de_core_poll_event(core, &evt)) { 20 | switch (evt.type) { 21 | case DE_EVENT_TYPE_CLOSE: 22 | /* Stop engine if user closes main window. */ 23 | de_core_stop(core); 24 | break; 25 | case DE_EVENT_TYPE_KEY_DOWN: 26 | /* Esc will stop engine. */ 27 | if (evt.s.key.key == DE_KEY_ESC) { 28 | de_core_stop(core); 29 | } 30 | break; 31 | } 32 | } 33 | } 34 | 35 | /* Cleanup. */ 36 | de_core_shutdown(core); 37 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mrDIMAS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /core/hash.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | uint32_t de_hash_murmur3(const uint8_t* key, size_t len, uint32_t seed); -------------------------------------------------------------------------------- /math/mat3.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | float de_mat3_at(const de_mat3_t* m, unsigned int row, unsigned int column) 23 | { 24 | return m->f[row + 3 * column]; 25 | } -------------------------------------------------------------------------------- /core/thread.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | #if defined(__MINGW32__) || defined(__GNUC__) 23 | # include "core/thread_posix.c" 24 | #else 25 | # include "core/thread_win32.c" 26 | #endif -------------------------------------------------------------------------------- /physics/physics.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | #include "physics/octree.c" 23 | #include "physics/shape.c" 24 | #include "physics/body.c" 25 | #include "physics/collision.c" 26 | #include "physics/gjk_epa.c" -------------------------------------------------------------------------------- /tutorials/01-Core-Initialization/vcproj/01-Core-Initialization.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /gui/canvas.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief 24 | */ 25 | typedef struct de_gui_canvas_t { 26 | int dummy; 27 | } de_gui_canvas_t; 28 | 29 | struct de_gui_node_dispatch_table_t* de_gui_canvas_get_dispatch_table(); -------------------------------------------------------------------------------- /fbx/fbx_binary.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Reads Binary FBX into node hierarchy and initializes data buffer. 24 | */ 25 | de_fbx_node_t* de_fbx_binary_load_file(const char* filename, de_fbx_buffer_t* data_buf); -------------------------------------------------------------------------------- /sound/sound.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | #include "sound/device.c" 23 | #include "sound/decoder.c" 24 | #include "sound/listener.c" 25 | #include "sound/context.c" 26 | #include "sound/source.c" 27 | #include "sound/buffer.c" 28 | -------------------------------------------------------------------------------- /core/time.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Returns current process time in seconds 24 | * @return time in seconds 25 | * 26 | * Note: Implementation is platform specific. 27 | */ 28 | double de_time_get_seconds(void); 29 | -------------------------------------------------------------------------------- /math/mat3.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * Square 3x3 matrix is not implemented yet. 24 | */ 25 | 26 | struct de_mat3_t { 27 | float f[9]; 28 | }; 29 | 30 | float de_mat3_at(const de_mat3_t* m, unsigned int row, unsigned int column); -------------------------------------------------------------------------------- /core/rect.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | bool de_rect_contains(const de_rectf_t* rect, const de_vec2_t* point) 23 | { 24 | return 25 | point->x >= rect->x && 26 | point->x <= rect->x + rect->w && 27 | point->y >= rect->y && 28 | point->y <= rect->y + rect->h; 29 | } 30 | -------------------------------------------------------------------------------- /tutorials/01-Core-Initialization/vcproj/01-Core-Initialization.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "01-Core-Initialization", "01-Core-Initialization.vcxproj", "{68DA1276-2BBA-47F2-B436-21DAC40DAC5C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {68DA1276-2BBA-47F2-B436-21DAC40DAC5C}.Debug|x64.ActiveCfg = Debug|x64 17 | {68DA1276-2BBA-47F2-B436-21DAC40DAC5C}.Debug|x64.Build.0 = Debug|x64 18 | {68DA1276-2BBA-47F2-B436-21DAC40DAC5C}.Debug|x86.ActiveCfg = Debug|Win32 19 | {68DA1276-2BBA-47F2-B436-21DAC40DAC5C}.Debug|x86.Build.0 = Debug|Win32 20 | {68DA1276-2BBA-47F2-B436-21DAC40DAC5C}.Release|x64.ActiveCfg = Release|x64 21 | {68DA1276-2BBA-47F2-B436-21DAC40DAC5C}.Release|x64.Build.0 = Release|x64 22 | {68DA1276-2BBA-47F2-B436-21DAC40DAC5C}.Release|x86.ActiveCfg = Release|Win32 23 | {68DA1276-2BBA-47F2-B436-21DAC40DAC5C}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /core/byteorder.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | uint16_t de_byte_order_swap_u16(uint16_t val); 23 | int16_t de_byte_order_swap_int16(int16_t val); 24 | uint32_t de_byte_order_swap_uint32(uint32_t val); 25 | int32_t de_byte_order_swap_int32(int32_t val); 26 | uint64_t de_byte_order_swap_uint64(uint64_t val); 27 | int64_t de_byte_order_swap_int64(int64_t val); 28 | -------------------------------------------------------------------------------- /resources/model.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Model is an isolated scene which can be instantiated multiple times, the source 24 | * scene won't be rendered. 25 | */ 26 | typedef struct de_model_t { 27 | de_scene_t* scene; 28 | de_node_t* root; 29 | } de_model_t; 30 | 31 | de_node_t* de_model_instantiate(de_model_t* mdl, de_scene_t* dest_scene); 32 | 33 | de_resource_dispatch_table_t* de_model_get_dispatch_table(void); -------------------------------------------------------------------------------- /core/clipboard.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Returns pointer to null-terminated text. 24 | * 25 | * WARNING: You must call de_free to free data! Otherwise there will be memory leaks! 26 | * 27 | * Note: Implementation is platform-specific 28 | */ 29 | char* de_clipboard_get_text(); 30 | 31 | /** 32 | * @brief Sets text into clipboard 33 | * 34 | * Note: Implementation is platform-specific 35 | */ 36 | void de_clipboard_set_text(char* data); -------------------------------------------------------------------------------- /core/rectpack.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_rectpack_node_t { 23 | void* data; 24 | char split; 25 | int x; 26 | int y; 27 | int w; 28 | int h; 29 | struct de_rectpack_node_t * children[2]; 30 | } de_rectpack_node_t; 31 | 32 | de_rectpack_node_t* de_rectpack_create_node(int x, int y, int w, int h); 33 | de_rectpack_node_t* de_rectpack_get_free(de_rectpack_node_t* node, int w, int h, void* data); 34 | void de_rectpack_free(de_rectpack_node_t* node); -------------------------------------------------------------------------------- /sound/listener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_listener_t { 23 | de_vec3_t position; 24 | de_vec3_t look; 25 | de_vec3_t up; 26 | de_vec3_t ear_axis; 27 | } de_listener_t; 28 | 29 | void de_listener_init(de_listener_t* l); 30 | 31 | void de_listener_set_position(de_listener_t* l, const de_vec3_t* pos); 32 | 33 | void de_listener_get_position(de_listener_t* l, de_vec3_t* pos); 34 | 35 | void de_listener_set_orientation(de_listener_t* l, const de_vec3_t* look, const de_vec3_t* up); -------------------------------------------------------------------------------- /core/string_utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Converts UTF-8 string to UTF-32 string. 24 | */ 25 | int de_utf8_to_utf32(const char* in, size_t in_length, uint32_t* out, int out_length); 26 | 27 | /** 28 | * @brief Converts UTF-8 string to UTF-16 string. 29 | */ 30 | int de_utf8_to_utf16(const char* in, int in_length, uint16_t* out, int out_length); 31 | 32 | /** 33 | * @brief Converts UTF-16 string to UTF-32 string. 34 | */ 35 | int de_utf16_to_utf32(const uint16_t* in, size_t in_length, uint32_t* out, int out_length); -------------------------------------------------------------------------------- /gui/stack_panel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_gui_stack_panel_descriptor_t { 23 | de_gui_orientation_t orientation; 24 | } de_gui_stack_panel_descriptor_t; 25 | 26 | typedef struct de_gui_stack_panel_t { 27 | de_gui_orientation_t orientation; 28 | } de_gui_stack_panel_t; 29 | 30 | void de_gui_stack_panel_set_orientation(de_gui_node_t* n, de_gui_orientation_t orientation); 31 | 32 | de_gui_orientation_t de_gui_stack_panel_get_orientation(de_gui_node_t* n); 33 | 34 | struct de_gui_node_dispatch_table_t* de_gui_stack_panel_get_dispatch_table(); -------------------------------------------------------------------------------- /core/base64.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Encodes data into base64 string. You must provide buffer of 24 | * enough size (use de_base64_encode_data_size) 25 | */ 26 | char* de_base64_encode(const void* data, size_t size, size_t* out_size); 27 | 28 | /** 29 | * @brief Decodes base64 string. Returns pointer to decoded data. 30 | * Note: does not checks for correct base64 string! 31 | */ 32 | void* de_base64_decode(const char* data, size_t size, size_t* out_size); 33 | 34 | /** 35 | * @brief Runs basic sanity checks 36 | */ 37 | void de_base64_test(void); -------------------------------------------------------------------------------- /core/log.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Starts logging to specified file 24 | */ 25 | void de_log_open(const char* filename); 26 | 27 | /** 28 | * @brief Prints message to log 29 | * @param message Any valid format string 30 | */ 31 | void de_log(const char * message, ...); 32 | 33 | /** 34 | * @brief Prints error to log and terminates program execution 35 | * @param message Any valid format string 36 | */ 37 | void de_fatal_error(const char * message, ...); 38 | 39 | /** 40 | * @brief Closes current log file. 41 | */ 42 | void de_log_close(void); 43 | -------------------------------------------------------------------------------- /core/color.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief RGBA color 24 | */ 25 | typedef struct de_color_s { 26 | uint8_t r; /**< Red component */ 27 | uint8_t g; /**< Green component */ 28 | uint8_t b; /**< Blue component */ 29 | uint8_t a; /**< Alpha (opacity) component */ 30 | } de_color_t; 31 | 32 | /** 33 | * @brief Initializes RGBA color. 34 | */ 35 | void de_color_set(de_color_t* color, uint8_t r, uint8_t g, uint8_t b, uint8_t a); 36 | 37 | uint32_t de_color_to_int(const de_color_t* color); 38 | 39 | de_color_t de_color_interpolate(const de_color_t* a, const de_color_t* b, float t); -------------------------------------------------------------------------------- /core/rect.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @class de_rect_t 24 | * @brief Rectangle (float) 25 | */ 26 | typedef struct de_rectf_t { 27 | float x; /**< X coordinate */ 28 | float y; /**< Y coordinate */ 29 | float w; /**< Width */ 30 | float h; /**< Height */ 31 | } de_rectf_t; 32 | 33 | /** 34 | * @class de_rect_t 35 | * @brief Rectangle (int) 36 | */ 37 | typedef struct de_recti_t { 38 | int x; /**< X coordinate */ 39 | int y; /**< Y coordinate */ 40 | int w; /**< Width */ 41 | int h; /**< Height */ 42 | } de_recti_t; 43 | 44 | bool de_rect_contains(const de_rectf_t* rect, const de_vec2_t* point); 45 | -------------------------------------------------------------------------------- /gui/image.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_gui_image_t { 23 | de_texture_t* texture; 24 | } de_gui_image_t; 25 | 26 | typedef struct de_gui_image_descriptor_t { 27 | de_texture_t* texture; 28 | } de_gui_image_descriptor_t; 29 | 30 | struct de_gui_node_dispatch_table_t* de_gui_image_get_dispatch_table(); 31 | 32 | /** 33 | * @brief Sets texture for image widget. Automatically increases ref counter. 34 | */ 35 | void de_gui_image_set_texture(de_gui_node_t* n, de_texture_t* tex); 36 | 37 | /** 38 | * @brief Returns texture image uses. 39 | */ 40 | de_texture_t* de_gui_image_get_texture(de_gui_node_t* n); -------------------------------------------------------------------------------- /core/byteorder.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | 23 | uint16_t de_byte_order_swap_u16(uint16_t val) 24 | { 25 | return (val << 8) | (val >> 8); 26 | } 27 | 28 | 29 | int16_t de_byte_order_swap_int16(int16_t val) 30 | { 31 | return (val << 8) | ((val >> 8) & 0xFF); 32 | } 33 | 34 | 35 | uint32_t de_byte_order_swap_uint32(uint32_t val) 36 | { 37 | val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF); 38 | return (val << 16) | (val >> 16); 39 | } 40 | 41 | 42 | int32_t de_byte_order_swap_int32(int32_t val) 43 | { 44 | val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF); 45 | return (val << 16) | ((val >> 16) & 0xFFFF); 46 | } 47 | -------------------------------------------------------------------------------- /gui/check_box.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef void(*de_check_box_checked_changed_t)(de_gui_node_t* node, bool new_value); 23 | 24 | typedef struct de_gui_check_box_descriptor_t { 25 | bool checked; 26 | de_check_box_checked_changed_t checked_changed; 27 | } de_gui_check_box_descriptor_t; 28 | 29 | typedef struct de_gui_check_box_t { 30 | de_gui_node_t* border; 31 | de_gui_node_t* check_mark; 32 | bool checked; 33 | de_check_box_checked_changed_t checked_changed; 34 | } de_gui_check_box_t; 35 | 36 | struct de_gui_node_dispatch_table_t* de_gui_check_box_get_dispatch_table(); 37 | 38 | void de_gui_check_box_set_value(de_gui_node_t* node, bool value); 39 | 40 | bool de_gui_check_box_get_value(de_gui_node_t* node); -------------------------------------------------------------------------------- /resources/image.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_rgb8_t { 23 | unsigned char r; 24 | unsigned char g; 25 | unsigned char b; 26 | } de_rgb8_t; 27 | 28 | typedef struct de_rgba8_t { 29 | unsigned char r; 30 | unsigned char g; 31 | unsigned char b; 32 | unsigned char a; 33 | } de_rgba8_t; 34 | 35 | typedef struct de_image_t { 36 | char* data; 37 | unsigned int width; 38 | unsigned int height; 39 | unsigned int byte_per_pixel; 40 | } de_image_t; 41 | 42 | /** 43 | * @brief Loads image from tga file. Compressed images not supported yet! 44 | */ 45 | bool de_image_load_tga(const char* filename, de_image_t* img); 46 | 47 | /** 48 | * @brief Flips image upside down. 49 | */ 50 | void de_image_flip_y(de_image_t* img); -------------------------------------------------------------------------------- /core/color.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | void de_color_set(de_color_t* color, uint8_t r, uint8_t g, uint8_t b, uint8_t a) 23 | { 24 | color->r = r; 25 | color->g = g; 26 | color->b = b; 27 | color->a = a; 28 | } 29 | 30 | uint32_t de_color_to_int(const de_color_t* color) 31 | { 32 | return *((uint32_t*)color); /* CAVEAT: will fail if struct will be changed! */ 33 | } 34 | 35 | de_color_t de_color_interpolate(const de_color_t* a, const de_color_t* b, float t) { 36 | return (de_color_t) { 37 | .r = (uint8_t)((int)a->r + (int)(t * ((int)b->r - (int)a->r))), 38 | .g = (uint8_t)((int)a->g + (int)(t * ((int)b->g - (int)a->g))), 39 | .b = (uint8_t)((int)a->b + (int)(t * ((int)b->b - (int)a->b))), 40 | .a = (uint8_t)((int)a->a + (int)(t * ((int)b->a - (int)a->a))), 41 | }; 42 | } -------------------------------------------------------------------------------- /fbx/fbx_ascii.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | 23 | typedef struct de_fbx_rdbuf_t { 24 | char chunk[32768]; 25 | size_t chunk_size; 26 | size_t chunk_read_cursor; 27 | bool eof; 28 | } de_fbx_rdbuf_t; 29 | 30 | void de_fbx_rdbuf_init(de_fbx_rdbuf_t* rdbuf); 31 | 32 | char de_fbx_rdbuf_next_symbol(FILE* file, de_fbx_rdbuf_t* rdbuf); 33 | 34 | bool de_fbx_rdbuf_is_eof(de_fbx_rdbuf_t* rdbuf); 35 | 36 | /* custom isspace function, because standard implementation uses locale which is slow */ 37 | bool de_fbx_is_space(char c); 38 | 39 | /** 40 | * @brief Reads ASCII FBX into node hierarchy and initializes data buffer. 41 | */ 42 | de_fbx_node_t* de_fbx_ascii_load_file(const char* filename, de_fbx_buffer_t* data_buf); 43 | 44 | de_fbx_reference_t de_fbx_get_reference(const char* str); -------------------------------------------------------------------------------- /physics/physics.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | #define DE_MAX_CONTACTS (8) 23 | #define DE_AIR_FRICTION (0.01f) 24 | #define DE_DEFAULT_GRAVITY (de_vec3_t) { 0.0f, -9.81f, 0.0f } 25 | 26 | /** 27 | * @class de_contact_t 28 | * @brief Physical contact 29 | */ 30 | typedef struct de_contact_t { 31 | de_body_t* body; /**< Handle of body with which contact is appeared */ 32 | de_vec3_t position; /**< Position of contact */ 33 | de_vec3_t normal; /**< Normal vector in contact point */ 34 | de_static_triangle_t* triangle; /**< Pointer to triangle of static geometry */ 35 | de_static_geometry_t* geometry; 36 | } de_contact_t; 37 | 38 | #include "physics/octree.h" 39 | #include "physics/shape.h" 40 | #include "physics/body.h" 41 | #include "physics/collision.h" 42 | #include "physics/gjk_epa.h" -------------------------------------------------------------------------------- /sound/listener.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | void de_listener_init(de_listener_t* l) 23 | { 24 | l->position = (de_vec3_t) { 0 }; 25 | l->look = (de_vec3_t) { 0, 0, 1 }; 26 | l->up = (de_vec3_t) { 0, 1, 0 }; 27 | } 28 | 29 | void de_listener_set_position(de_listener_t* l, const de_vec3_t* pos) 30 | { 31 | DE_ASSERT(l); 32 | l->position = *pos; 33 | } 34 | 35 | void de_listener_get_position(de_listener_t* l, de_vec3_t* pos) 36 | { 37 | DE_ASSERT(l); 38 | *pos = l->position; 39 | } 40 | 41 | void de_listener_set_orientation(de_listener_t* l, const de_vec3_t* look, const de_vec3_t* up) 42 | { 43 | DE_ASSERT(l); 44 | DE_ASSERT(look); 45 | DE_ASSERT(up); 46 | de_vec3_cross(&l->ear_axis, look, up); 47 | de_vec3_normalize(&l->ear_axis, &l->ear_axis); 48 | de_vec3_normalize(&l->look, look); 49 | de_vec3_normalize(&l->up, up); 50 | } -------------------------------------------------------------------------------- /tutorials/01-Core-Initialization/README.md: -------------------------------------------------------------------------------- 1 | # 01 - Core initialization. 2 | 3 | Core (`de_core_t`) is the main part of the engine, it handles main render window and its event loop, initializes other subsystems (renderer, GUI, Sound context, etc.). It manages all resources (textures, models, fonts, sound buffers, etc.) giving you the unified way to work with resources. Before use the engine, you must initialize the core. Here is very simple way to initialize it. 4 | 5 | ```c 6 | #include "de_main.h" 7 | 8 | int main(int argc, char** argv) 9 | { 10 | /* Fill config using designated initializer. */ 11 | const de_core_config_t config = { 12 | .video_mode = { 13 | .width = 800, 14 | .height = 600, 15 | } 16 | }; 17 | 18 | /* Initialize core. */ 19 | de_core_t* core = de_core_init(&config); 20 | 21 | /* Cleanup. */ 22 | de_core_shutdown(core); 23 | } 24 | ``` 25 | 26 | If you run this example you'll see a window for a moment and then it will be closed. To prevent this you should add event handling loop. 27 | 28 | ```c 29 | #include "de_main.h" 30 | 31 | int main(int argc, char** argv) 32 | { 33 | /* Fill config using designated initializer. */ 34 | const de_core_config_t config = { 35 | .video_mode = { 36 | .width = 800, 37 | .height = 600, 38 | } 39 | }; 40 | 41 | /* Initialize core. */ 42 | de_core_t* core = de_core_init(&config); 43 | 44 | /* Run main loop. */ 45 | while (de_core_is_running(core)) { 46 | de_event_t evt; 47 | if (de_core_poll_event(core, &evt)) { 48 | switch (evt.type) { 49 | case DE_EVENT_TYPE_CLOSE: 50 | /* Stop engine if user closes main window. */ 51 | de_core_stop(core); 52 | break; 53 | case DE_EVENT_TYPE_KEY_DOWN: 54 | /* Esc will stop engine. */ 55 | if (evt.s.key.key == DE_KEY_ESC) { 56 | de_core_stop(core); 57 | } 58 | break; 59 | } 60 | } 61 | } 62 | 63 | /* Cleanup. */ 64 | de_core_shutdown(core); 65 | } 66 | ``` 67 | 68 | Now all you see is a window filled with white color, it can be closed by hitting Esc key or by close button on the window. -------------------------------------------------------------------------------- /core/hash.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /* Original algorithm by Austin Appleby */ 23 | uint32_t de_hash_murmur3(const uint8_t* key, size_t len, uint32_t seed) 24 | { 25 | uint32_t h = seed; 26 | if (len > 3) { 27 | size_t i = len >> 2; 28 | do { 29 | uint32_t k; 30 | memcpy(&k, key, sizeof(uint32_t)); 31 | key += sizeof(uint32_t); 32 | k *= 0xcc9e2d51; 33 | k = (k << 15) | (k >> 17); 34 | k *= 0x1b873593; 35 | h ^= k; 36 | h = (h << 13) | (h >> 19); 37 | h = h * 5 + 0xe6546b64; 38 | } while (--i); 39 | } 40 | if (len & 3) { 41 | size_t i = len & 3; 42 | uint32_t k = 0; 43 | do { 44 | k <<= 8; 45 | k |= key[i - 1]; 46 | } while (--i); 47 | k *= 0xcc9e2d51; 48 | k = (k << 15) | (k >> 17); 49 | k *= 0x1b873593; 50 | h ^= k; 51 | } 52 | h ^= len; 53 | h ^= h >> 16; 54 | h *= 0x85ebca6b; 55 | h ^= h >> 13; 56 | h *= 0xc2b2ae35; 57 | h ^= h >> 16; 58 | return h; 59 | } -------------------------------------------------------------------------------- /core/utility.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Loads file as a null-terminated string. 24 | * @param path file to load 25 | * @param out_size total bytes count, can be NULL 26 | */ 27 | char* de_load_file_into_memory(const char * path, size_t* out_size); 28 | 29 | /** 30 | * @brief Converts a file 'source' as array to file 'dest' 31 | * 32 | * Will create a file 'dest' with such content: 33 | * 34 | * static const char array[] = { 35 | * 123, 234, 12, 0, 34, 16, ... 36 | * }; 37 | * 38 | * Can be used to pack any file into a source code file. Useful when 39 | * you need to store some resource as data in your executable file. 40 | */ 41 | void de_convert_to_c_array(const char* source, const char* dest); 42 | 43 | /** 44 | * @brief Check if file exists. 45 | */ 46 | bool de_file_exists(const char* filename); 47 | 48 | /** 49 | * @brief Tests for file system utilities. 50 | */ 51 | void de_file_tests(void); -------------------------------------------------------------------------------- /gui/text_box.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef void(*de_gui_text_changed_event_t)(de_gui_node_t* node); 23 | 24 | /** 25 | * @brief 26 | */ 27 | typedef struct de_gui_text_box_t { 28 | bool multiline; 29 | de_str32_t str; 30 | de_font_t* font; 31 | de_gui_vertical_alignment_t ver_alignment; 32 | de_gui_horizontal_alignment_t hor_alignment; 33 | DE_ARRAY_DECLARE(de_gui_text_line_t, lines); 34 | float total_lines_height; 35 | int cursor_offset; /* relative offset from begin of line */ 36 | int cursor_line; /* index of line under cursor */ 37 | struct { 38 | int begin; 39 | int end; 40 | } select_span; 41 | bool show_cursor; 42 | size_t blink_interval; /* in frames (with fixed update at 60 fps, 60 fps = 1s)*/ 43 | size_t blink_timer; 44 | size_t cursor_visible; 45 | de_gui_text_changed_event_t text_changed; 46 | } de_gui_text_box_t; 47 | 48 | struct de_gui_node_dispatch_table_t* de_gui_text_box_get_dispatch_table(void); 49 | -------------------------------------------------------------------------------- /editor/editor.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_editor_t de_editor_t; 23 | 24 | typedef struct de_editor_property_window_t { 25 | de_editor_t* owner; 26 | de_gui_node_t* window; 27 | de_gui_node_t* grid; 28 | 29 | de_gui_node_t* name_label; 30 | de_gui_node_t* name_text; 31 | 32 | } de_editor_property_window_t; 33 | 34 | typedef struct de_editor_camera_controller_t { 35 | de_node_t* camera; 36 | de_node_t* camera_pivot; 37 | bool move_forward; 38 | bool move_backward; 39 | bool move_left; 40 | bool move_right; 41 | } de_editor_camera_controller_t; 42 | 43 | struct de_editor_t { 44 | de_core_t* core; 45 | de_editor_property_window_t prop; 46 | 47 | de_scene_t* scene; 48 | de_editor_camera_controller_t camera_ctrl; 49 | }; 50 | 51 | de_editor_t* de_editor_create(de_core_t* core); 52 | 53 | void de_editor_free(de_editor_t* ed); 54 | 55 | void de_editor_update(de_editor_t* ed); 56 | 57 | void de_editor_process_event(de_editor_t* ed, const de_event_t* evt); -------------------------------------------------------------------------------- /resources/texture.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Possible texture types 24 | */ 25 | typedef enum de_texture_type_e { 26 | DE_TEXTURE_TYPE_2D, 27 | DE_TEXTURE_TYPE_VOLUME, 28 | DE_TEXTURE_TYPE_CUBE 29 | } de_texture_type_t; 30 | 31 | /** 32 | * @brief Common texture. Can be 2D, volume or cube 33 | */ 34 | struct de_texture_t { 35 | unsigned int id; /**< OpenGL texture id */ 36 | int width; /**< Width of texture */ 37 | int height; /**< Height of texture */ 38 | int depth; /**< Depth of volume texture */ 39 | char* pixels; /**< Texture pixels */ 40 | int byte_per_pixel; /**< Count of bytes per pixel */ 41 | de_texture_type_t type; /**< Type of texture */ 42 | bool need_upload; /**< Indicates that texture needs to be uploaded to GPU */ 43 | }; 44 | 45 | de_resource_dispatch_table_t* de_texture_get_dispatch_table(void); 46 | 47 | /** 48 | * @brief Allocates pixels for rectangle image. 49 | */ 50 | void de_texture_alloc_pixels(de_texture_t* tex, int w, int h, size_t byte_per_pixel); -------------------------------------------------------------------------------- /gui/border.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_gui_border_descriptor_t { 23 | de_color_t stroke_color; 24 | de_gui_thickness_t thickness; 25 | } de_gui_border_descriptor_t; 26 | 27 | /** 28 | * @brief 29 | */ 30 | typedef struct de_gui_border_t { 31 | de_color_t stroke_color; 32 | de_gui_thickness_t thickness; 33 | } de_gui_border_t; 34 | 35 | struct de_gui_node_dispatch_table_t* de_gui_border_get_dispatch_table(); 36 | 37 | /** 38 | * @brief 39 | * @param node 40 | * @param color 41 | */ 42 | void de_gui_border_set_stroke_color(de_gui_node_t* node, const de_color_t* color); 43 | 44 | /** 45 | * @brief 46 | * @param node 47 | * @param r 48 | * @param g 49 | * @param b 50 | * @param a 51 | */ 52 | void de_gui_border_set_stroke_color_rgba(de_gui_node_t* node, uint8_t r, uint8_t g, uint8_t b, uint8_t a); 53 | 54 | void de_gui_border_set_thickness_uniform(de_gui_node_t* node, float thickness); 55 | 56 | void de_gui_border_set_thickness(de_gui_node_t* node, float left, float top, float right, float bottom); -------------------------------------------------------------------------------- /core/color_gradient.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_color_gradient_point_t { 23 | float location; 24 | de_color_t color; 25 | } de_color_gradient_point_t; 26 | 27 | /** 28 | * @brief 1D color gradient. 29 | */ 30 | typedef struct de_color_gradient_t { 31 | DE_ARRAY_DECLARE(de_color_gradient_point_t, points); 32 | } de_color_gradient_t; 33 | 34 | void de_color_gradient_init(de_color_gradient_t* gradient); 35 | 36 | /** 37 | * @brief Adds new color point to gradient at specified location. Location must be in [0; 1] range! 38 | */ 39 | void de_color_gradient_add_point(de_color_gradient_t* gradient, float location, const de_color_t* color); 40 | 41 | de_color_t de_color_gradient_get_color(const de_color_gradient_t* gradient, float location); 42 | 43 | void de_color_gradient_clear(de_color_gradient_t* gradient); 44 | 45 | void de_color_gradient_free(de_color_gradient_t* gradient); 46 | 47 | bool de_color_gradient_visit(de_object_visitor_t* visitor, de_color_gradient_t* gradient); 48 | 49 | void de_color_gradient_tests(); -------------------------------------------------------------------------------- /gui/scroll_viewer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief 24 | */ 25 | typedef struct de_gui_scroll_viewer_t { 26 | de_gui_node_t* border; /**< Background */ 27 | de_gui_node_t* grid; /**< Main layout panel */ 28 | de_gui_node_t* scroll_content_presenter; /**< Panel for content */ 29 | de_gui_node_t* ver_scroll_bar; /**< Vertical scroll bar */ 30 | de_gui_node_t* hor_scroll_bar; /**< Horizontal scroll bar */ 31 | de_gui_node_t* content; 32 | bool auto_hide_ver_scroll_bar; 33 | bool auto_hide_hor_scroll_bar; 34 | } de_gui_scroll_viewer_t; 35 | 36 | struct de_gui_node_dispatch_table_t* de_gui_scroll_viewer_get_dispatch_table(void); 37 | 38 | /** 39 | * @brief 40 | * @param sv_node 41 | * @param content 42 | */ 43 | void de_gui_scroll_viewer_set_content(de_gui_node_t* sv_node, de_gui_node_t* content); 44 | 45 | void de_gui_scroll_viewer_enable_vertical_scroll(de_gui_node_t* n, bool value); 46 | 47 | void de_gui_scroll_viewer_enable_horizontal_scroll(de_gui_node_t* n, bool value); -------------------------------------------------------------------------------- /gui/button.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_gui_button_descriptor_t { 23 | char* text; 24 | de_gui_callback_t click; 25 | } de_gui_button_descriptor_t; 26 | 27 | /** 28 | * @brief 29 | */ 30 | typedef struct de_gui_button_t { 31 | de_color_t normal_color; 32 | de_color_t pressed_color; 33 | de_color_t hover_color; 34 | struct de_gui_node_t* border; 35 | struct de_gui_node_t* text; 36 | de_gui_callback_t click; 37 | bool was_pressed; 38 | } de_gui_button_t; 39 | 40 | struct de_gui_node_dispatch_table_t* de_gui_button_get_dispatch_table(); 41 | 42 | /** 43 | * @brief 44 | * @param node 45 | */ 46 | void de_gui_button_set_click(de_gui_node_t* node, de_gui_callback_func_t click, void* user_data); 47 | 48 | /** 49 | * @brief 50 | * @param node 51 | * @return 52 | */ 53 | de_gui_node_t* de_gui_button_get_text(de_gui_node_t* node); 54 | 55 | /** 56 | * @brief 57 | * @param node 58 | * @return 59 | */ 60 | de_gui_node_t* de_gui_button_get_border(de_gui_node_t* node); 61 | 62 | void de_gui_button_set_text(de_gui_node_t* node, const char* txt); -------------------------------------------------------------------------------- /sound/device.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef enum de_mixer_status_t { 23 | DE_MIXER_STATUS_ACTIVE, 24 | DE_MIXER_STATUS_NEED_STOP, 25 | DE_MIXER_STATUS_STOPPED 26 | } de_mixer_status_t; 27 | 28 | struct de_sound_device_t { 29 | de_sound_context_t* ctx; 30 | de_cnd_t cnd; 31 | de_mixer_status_t mixer_status; 32 | int16_t* out_buffer; 33 | size_t sample_rate; 34 | size_t out_samples_count; 35 | size_t buffer_len_bytes; /* in bytes */ 36 | DE_ARRAY_DECLARE(de_sound_source_t*, active_sources); /**< Array of active sound sources */ 37 | #ifdef _WIN32 38 | /* dsound */ 39 | IDirectSound8* dsound; 40 | IDirectSoundBuffer8* buffer; 41 | IDirectSoundNotify* notify; 42 | HANDLE points[2]; 43 | #else 44 | /* alsa */ 45 | snd_pcm_t* playbackDevice; 46 | int frameCount; 47 | #endif 48 | }; 49 | 50 | /** 51 | * @brief Initializes sound device. 52 | */ 53 | bool de_sound_device_init(de_sound_context_t* ctx, de_sound_device_t* dev); 54 | 55 | /** 56 | * @brief Destroys sound device. 57 | */ 58 | void de_sound_device_free(de_sound_device_t* dev); -------------------------------------------------------------------------------- /gui/slide_selector.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | #define DE_GUI_SLIDE_SELECTOR_BUFFER_SIZE 1024 23 | 24 | typedef void(*de_gui_item_text_getter)(void* items, int n, char* out_buffer, int out_buffer_size); 25 | typedef void(*de_gui_selection_changed)(de_gui_node_t* node, void* items, int new_item); 26 | 27 | typedef struct de_gui_slide_selector_t { 28 | de_gui_node_t* current_item; 29 | int item_count; 30 | int selection_index; 31 | void* items; 32 | void* selection; 33 | de_gui_item_text_getter get_item_text; 34 | de_gui_selection_changed selection_changed; 35 | } de_gui_slide_selector_t; 36 | 37 | struct de_gui_node_dispatch_table_t* de_gui_slide_selector_get_dispatch_table(void); 38 | 39 | void de_gui_slide_selector_set_items(de_gui_node_t* node, void* items, int item_count, de_gui_item_text_getter getter); 40 | 41 | void* de_gui_slide_selector_get_selection(de_gui_node_t* node); 42 | 43 | void de_gui_slide_selector_set_selection_changed(de_gui_node_t* node, de_gui_selection_changed callback); 44 | 45 | void de_gui_slide_selector_override_selection_text(de_gui_node_t* node, const char* text); -------------------------------------------------------------------------------- /math/triangulator.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_triangulator_vertex_t { 23 | de_vec2_t position; 24 | size_t index; 25 | DE_LINKED_LIST_ITEM(struct de_triangulator_vertex_t); 26 | } de_triangulator_vertex_t; 27 | 28 | typedef DE_LINKED_LIST_DECLARE(de_triangulator_vertex_t, de_triangulator_polygon_t); 29 | 30 | /** 31 | * @brief Performs fast fan triangulation for quadrilaterals or ear-clipping triangulation 32 | * for simple arbitrary polygon. Function can fail if polygon is not simple or not enough 33 | * vertices was passed into (4 or more required). 34 | * 35 | * @return Returns count of indices that forms triangles. Negative number indicates error. 36 | */ 37 | int de_triangulate(de_vec3_t* polygon, size_t vertex_count, int* out_indices, int buffer_size); 38 | 39 | /** 40 | * @brief Returns approximate count of indices that is enough to store result 41 | * of triangulation. Count of triangles will be index_count / 3. 42 | */ 43 | int de_triangulate_get_approx_index_count(size_t vertex_count); 44 | 45 | /** 46 | * @brief Tests for triangulator. 47 | */ 48 | void de_triangulator_tests(void); -------------------------------------------------------------------------------- /scene/mesh.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Mesh. 24 | * 25 | * Described as set of surfaces 26 | */ 27 | struct de_mesh_t { 28 | DE_ARRAY_DECLARE(de_surface_t*, surfaces); /**< Array of pointer to surfaces */ 29 | bool cast_shadows; 30 | }; 31 | 32 | struct de_node_dispatch_table_t* de_mesh_get_dispatch_table(void); 33 | 34 | /** 35 | * @brief Calculates normals of each surface. Normals are per-face and not smooth. 36 | */ 37 | void de_mesh_calculate_normals(de_mesh_t * mesh); 38 | 39 | /** 40 | * @brief Adds surface to mesh. 41 | */ 42 | void de_mesh_add_surface(de_mesh_t* mesh, de_surface_t* surf); 43 | 44 | /** 45 | * @brief Returns true if any of surfaces is skinned. 46 | */ 47 | bool de_mesh_is_skinned(const de_mesh_t* mesh); 48 | 49 | /** 50 | * @brief Should mesh cast shadows or not. 51 | */ 52 | void de_mesh_set_cast_shadows(de_mesh_t* mesh, bool value); 53 | 54 | /** 55 | * @brief Returns true if mesh should cast shadows. 56 | */ 57 | bool de_mesh_get_cast_shadows(const de_mesh_t* mesh); 58 | 59 | /** 60 | * @brief Searches for root node that was instantiated from model resource. 61 | */ 62 | de_node_t* de_mesh_get_model_root(de_node_t* node); -------------------------------------------------------------------------------- /core/memmgr.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Allocates raw memory. On failure raises error 24 | * @param size requested size 25 | */ 26 | void* de_malloc(size_t size); 27 | 28 | /** 29 | * @brief Allocates clean (filled with zeroes) memory. On failure raises error 30 | * @param count count of objects 31 | * @param size size per object 32 | */ 33 | void* de_calloc(size_t count, size_t size); 34 | 35 | /** 36 | * @brief Reallocates memory. On failure raises error 37 | * @param ptr pointer 38 | */ 39 | void* de_realloc(void* ptr, size_t size); 40 | 41 | /** 42 | * @brief Returns memory to OS 43 | * @param ptr pointer 44 | */ 45 | void de_free(void* ptr); 46 | 47 | /** 48 | * @brief Returns total number of active memory allocations 49 | */ 50 | size_t de_get_alloc_count(void); 51 | 52 | /** 53 | * @brief Set all bytes of memory block to zeros 54 | */ 55 | void de_zero(void* data, size_t size); 56 | 57 | /** 58 | * Allocates memory for structure. Memory is filled with zeroes 59 | */ 60 | #define DE_NEW(type) (type*)de_calloc(1, sizeof(type)) 61 | 62 | /** 63 | * Calculates static array size 64 | */ 65 | #define DE_ARRAY_SIZE(array) (sizeof(array) / (sizeof(*array))) 66 | 67 | -------------------------------------------------------------------------------- /vg/vgraster.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_point_t { 23 | float x; 24 | float y; 25 | uint8_t flags; 26 | } de_point_t; 27 | 28 | typedef struct de_line2_t { 29 | de_point_t begin; 30 | de_point_t end; 31 | } de_line2_t; 32 | 33 | typedef DE_ARRAY_DECLARE(de_line2_t, line_array_t); 34 | typedef DE_ARRAY_DECLARE(de_point_t, point_array_t); 35 | 36 | typedef struct de_bitmap_t { 37 | uint8_t* pixels; 38 | int width; 39 | int height; 40 | } de_bitmap_t; 41 | 42 | typedef struct de_polygon_t { 43 | DE_ARRAY_DECLARE(de_point_t, points); 44 | } de_polygon_t; 45 | 46 | void de_bitmap_create(de_bitmap_t * bitmap, int width, int height); 47 | void de_bitmap_set_pixel(de_bitmap_t* bitmap, int x, int y, unsigned char pixel); 48 | point_array_t de_vg_eval_quad_bezier(const de_point_t * p0, const de_point_t * p1, const de_point_t * p2, int steps); 49 | bool de_vg_line_line_intersection(const de_line2_t* a, const de_line2_t* b, de_point_t *out); 50 | void de_vg_polys_to_scanlines(de_polygon_t* polys, size_t poly_count, float width, float height, float scale, line_array_t* out); 51 | de_bitmap_t de_bitmap_downscale4_box_filter(de_bitmap_t *src); 52 | de_bitmap_t de_vg_raster_scanlines(de_bitmap_t* bitmap, line_array_t lines); -------------------------------------------------------------------------------- /core/event.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef enum de_event_type_t { 23 | DE_EVENT_TYPE_CLOSE, 24 | DE_EVENT_TYPE_MOUSE_DOWN, 25 | DE_EVENT_TYPE_MOUSE_UP, 26 | DE_EVENT_TYPE_MOUSE_WHEEL, 27 | DE_EVENT_TYPE_MOUSE_MOVE, 28 | DE_EVENT_TYPE_MOUSE_LEAVE, 29 | DE_EVENT_TYPE_MOUSE_ENTER, 30 | DE_EVENT_TYPE_KEY_DOWN, 31 | DE_EVENT_TYPE_KEY_UP, 32 | DE_EVENT_TYPE_TEXT, 33 | DE_EVENT_TYPE_LOST_FOCUS, 34 | DE_EVENT_TYPE_GOT_FOCUS, 35 | DE_EVENT_TYPE_RESIZE 36 | } de_event_type_t; 37 | 38 | typedef struct de_event_t { 39 | de_event_type_t type; 40 | 41 | union { 42 | struct { 43 | enum de_key key; 44 | int alt : 1; 45 | int control : 1; 46 | int shift : 1; 47 | int system : 1; 48 | } key; 49 | 50 | struct { 51 | enum de_mouse_button button; 52 | int x, y; /* position */ 53 | } mouse_down; 54 | 55 | struct { 56 | enum de_mouse_button button; 57 | int x, y; /* position */ 58 | } mouse_up; 59 | 60 | struct { 61 | int delta; 62 | int x, y; /* position */ 63 | } mouse_wheel; 64 | 65 | struct { 66 | int x, y; /* position */ 67 | int vx, vy; /* velocity */ 68 | } mouse_move; 69 | 70 | struct { 71 | uint32_t code; 72 | } text; 73 | 74 | struct { 75 | int w, h; 76 | } resize; 77 | } s; 78 | } de_event_t; -------------------------------------------------------------------------------- /core/memmgr.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | static int de_alloc_count; 23 | 24 | void* de_malloc(size_t size) 25 | { 26 | void* mem; 27 | 28 | mem = malloc(size); 29 | 30 | if (!mem) { 31 | de_fatal_error("Failed to allocate %d bytes of memory!", size); 32 | } 33 | 34 | ++de_alloc_count; 35 | 36 | return mem; 37 | } 38 | 39 | void* de_calloc(size_t count, size_t size) 40 | { 41 | void* mem; 42 | 43 | mem = calloc(count, size); 44 | 45 | if (!mem) { 46 | de_fatal_error("Failed to allocate %d bytes of clean memory!", count * size); 47 | } 48 | 49 | ++de_alloc_count; 50 | 51 | return mem; 52 | } 53 | 54 | void* de_realloc(void* ptr, size_t size) 55 | { 56 | void* mem; 57 | 58 | if (ptr == NULL && size > 0) { 59 | ++de_alloc_count; 60 | } 61 | 62 | mem = realloc(ptr, size); 63 | 64 | if (size != 0) { 65 | if (!mem) { 66 | de_fatal_error("Failed to reallocate %d bytes of memory!", size); 67 | } 68 | } else { 69 | --de_alloc_count; 70 | } 71 | 72 | return mem; 73 | } 74 | 75 | void de_free(void* ptr) 76 | { 77 | if (ptr) { 78 | --de_alloc_count; 79 | } 80 | free(ptr); 81 | } 82 | 83 | size_t de_get_alloc_count() 84 | { 85 | return de_alloc_count; 86 | } 87 | 88 | void de_zero(void* data, size_t size) 89 | { 90 | memset(data, 0, size); 91 | } -------------------------------------------------------------------------------- /gui/scroll_content_presenter.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief 24 | */ 25 | typedef struct de_gui_scroll_content_presenter_t { 26 | de_vec2_t scroll; 27 | bool can_horizontally_scroll; 28 | bool can_vertically_scroll; 29 | } de_gui_scroll_content_presenter_t; 30 | 31 | struct de_gui_node_dispatch_table_t* de_gui_scroll_content_presenter_get_dispatch_table(void); 32 | 33 | /** 34 | * @brief 35 | * @param node 36 | * @param val 37 | */ 38 | void de_gui_scroll_content_presenter_set_v_scroll(de_gui_node_t* node, float val); 39 | 40 | /** 41 | * @brief 42 | * @param node 43 | * @param val 44 | */ 45 | void de_gui_scroll_content_presenter_set_h_scroll(de_gui_node_t* node, float val); 46 | 47 | /** 48 | * @brief Enables or disables vertical scroll for content. If scroll 49 | * is enabled infinite bounds will be provided for content, so it can contain 50 | * control of any size. 51 | */ 52 | void de_gui_scroll_content_presenter_enable_vertical_scroll(de_gui_node_t* n, bool value); 53 | 54 | /** 55 | * @brief Enables or disables horizontal scroll for content. If scroll 56 | * is enabled infinite bounds will be provided for content, so it can contain 57 | * control of any size. 58 | */ 59 | void de_gui_scroll_content_presenter_enable_horizontal_scroll(de_gui_node_t* n, bool value); -------------------------------------------------------------------------------- /physics/gjk_epa.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /* Vertex in space of Minkowski sum */ 23 | typedef struct de_minkowski_vertex_t { 24 | /* World space position of vertex of shape A. This position will be used 25 | * to compute contact point in world space. */ 26 | de_vec3_t shape_a_world_space; 27 | /* Minkowski difference between point in shape A and point in shape B. 28 | * This position will be used to do all simplex and polytope operations. 29 | * https://en.wikipedia.org/wiki/Minkowski_addition */ 30 | de_vec3_t minkowski_dif; 31 | } de_minkowski_vertex_t; 32 | 33 | typedef struct de_simplex_t { 34 | /* Vertices of simplex. 35 | * Important: a is most recently added point! */ 36 | de_minkowski_vertex_t a, b, c, d; 37 | /* Rank of simplex 38 | * 1 - point 39 | * 2 - line 40 | * 3 - triangle 41 | * 4 - tetrahedron */ 42 | int rank; 43 | } de_simplex_t; 44 | 45 | bool de_gjk_is_intersects(de_convex_shape_t* shape1, const de_vec3_t* shape1_position, 46 | de_convex_shape_t* shape2, const de_vec3_t* shape2_position, de_simplex_t* out_simplex); 47 | 48 | bool de_epa_get_penetration_info(de_simplex_t* simplex, de_convex_shape_t* shape1, const de_vec3_t* shape1_position, 49 | de_convex_shape_t* shape2, const de_vec3_t* shape2_position, de_vec3_t* penetration_vector, de_vec3_t* contact_point); -------------------------------------------------------------------------------- /gui/canvas.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | de_vec2_t de_gui_canvas_measure_override(de_gui_node_t* n, const de_vec2_t* available_size) 23 | { 24 | DE_UNUSED(available_size); 25 | 26 | const de_vec2_t size_for_child = { INFINITY, INFINITY }; 27 | for (size_t i = 0; i < n->children.size; ++i) { 28 | de_gui_node_t* child = n->children.data[i]; 29 | de_gui_node_measure(child, &size_for_child); 30 | } 31 | 32 | return (de_vec2_t) { 0, 0 }; 33 | } 34 | 35 | de_vec2_t de_gui_canvas_arrange_override(de_gui_node_t* n, const de_vec2_t* final_size) 36 | { 37 | for (size_t i = 0; i < n->children.size; ++i) { 38 | de_gui_node_t* child = n->children.data[i]; 39 | const de_rectf_t rect = { child->desired_local_position.x, child->desired_local_position.y, child->desired_size.x, child->desired_size.y }; 40 | de_gui_node_arrange(child, &rect); 41 | } 42 | 43 | return *final_size; 44 | } 45 | 46 | static void de_gui_canvas_init(de_gui_node_t* n) 47 | { 48 | DE_UNUSED(n); 49 | } 50 | 51 | de_gui_node_dispatch_table_t* de_gui_canvas_get_dispatch_table() 52 | { 53 | static de_gui_node_dispatch_table_t dispatch_table = { 54 | .init = de_gui_canvas_init, 55 | .measure_override = de_gui_canvas_measure_override, 56 | .arrange_override = de_gui_canvas_arrange_override, 57 | }; 58 | return &dispatch_table; 59 | } 60 | -------------------------------------------------------------------------------- /math/plane.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * Fixed plane class. 24 | */ 25 | typedef enum de_plane_class_t { 26 | DE_PLANE_OXY = 1, 27 | DE_PLANE_OXZ = 2, 28 | DE_PLANE_OYZ = 3 29 | } de_plane_class_t; 30 | 31 | /** 32 | * @brief Arbitrary plane 33 | */ 34 | struct de_plane_t { 35 | de_vec3_t n; /**< Normal vector of the plane */ 36 | float d; /**< Distance to the plane from the origin */ 37 | }; 38 | 39 | /** 40 | * @brief Creates plane directly from plane equation coefficients. 41 | */ 42 | de_plane_t* de_plane_set_abcd(de_plane_t* p, float a, float b, float c, float d); 43 | 44 | /** 45 | * @brief Creates plane from point and normal in that point. 46 | */ 47 | de_plane_t* de_plane_set(de_plane_t* p, const de_vec3_t* plane_point, const de_vec3_t* plane_normal); 48 | 49 | /** 50 | * @brief Returns unsigned distance from point to plane. 51 | */ 52 | float de_plane_distance(const de_plane_t* p, const de_vec3_t* point); 53 | 54 | /** 55 | * @brief Returns signed distance from point to plane. 56 | */ 57 | float de_plane_dot(const de_plane_t* p, const de_vec3_t* point); 58 | 59 | /** 60 | * @brief Normalizes plane. 61 | */ 62 | de_plane_t* de_plane_normalize(de_plane_t* p); 63 | 64 | /** 65 | * @brief Returns closest class of plane by its normal. 66 | */ 67 | de_plane_class_t de_plane_classify(const de_vec3_t * triangle_normal); -------------------------------------------------------------------------------- /core/thread_posix.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | int de_thrd_create(de_thrd_t* thr, de_thrd_start_t func, void* arg) 23 | { 24 | pthread_create(thr, NULL, (void*(*)(void*)) func, arg); 25 | return true; 26 | } 27 | 28 | int de_thrd_detach(de_thrd_t* thr) 29 | { 30 | return pthread_detach(*thr) == 0; 31 | } 32 | 33 | int de_thrd_join(de_thrd_t* thr) 34 | { 35 | void* code; 36 | return pthread_join(*thr, &code); 37 | } 38 | 39 | void de_mtx_init(de_mtx_t* mtx) 40 | { 41 | pthread_mutexattr_t attr; 42 | pthread_mutexattr_init(&attr); 43 | pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); 44 | pthread_mutex_init(mtx, &attr); 45 | } 46 | 47 | void de_mtx_lock(de_mtx_t* mtx) 48 | { 49 | pthread_mutex_lock(mtx); 50 | } 51 | 52 | void de_mtx_unlock(de_mtx_t* mtx) 53 | { 54 | pthread_mutex_unlock(mtx); 55 | } 56 | 57 | void de_mtx_destroy(de_mtx_t* mtx) 58 | { 59 | pthread_mutex_destroy(mtx); 60 | } 61 | 62 | void de_cnd_init(de_cnd_t* cnd) 63 | { 64 | pthread_cond_init(cnd, NULL); 65 | } 66 | 67 | void de_cnd_destroy(de_cnd_t* cnd) 68 | { 69 | pthread_cond_destroy(cnd); 70 | } 71 | 72 | void de_cnd_signal(de_cnd_t* cnd) 73 | { 74 | pthread_cond_signal(cnd); 75 | } 76 | 77 | void de_cnd_broadcast(de_cnd_t* cnd) 78 | { 79 | pthread_cond_broadcast(cnd); 80 | } 81 | 82 | void de_cnd_wait(de_cnd_t* cnd, de_mtx_t* mtx) 83 | { 84 | pthread_cond_wait(cnd, mtx); 85 | } -------------------------------------------------------------------------------- /physics/octree.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_octree_node_t { 23 | int * triangle_indices; 24 | int index_count; 25 | char split; 26 | de_vec3_t min; 27 | de_vec3_t max; 28 | struct de_octree_node_t* children[8]; 29 | } de_octree_node_t; 30 | 31 | typedef struct de_trace_buffer { 32 | de_octree_node_t** nodes; 33 | int size; 34 | } de_trace_buffer; 35 | 36 | typedef struct de_octree_t { 37 | de_trace_buffer trace_buffer; 38 | de_octree_node_t* root; 39 | } de_octree_t; 40 | 41 | /** 42 | * @brief Builds octree using a set of vertices and indices. 43 | * @param vertices Set of vertices 44 | * @param stride Offset between positions in vertices. Can be zero, if you have tigthly packed array of positios. 45 | * @param index_count Count of indices 46 | * @param 47 | */ 48 | de_octree_t * de_octree_build(const void* src_triangles, size_t triangle_count, int pos_stride, size_t max_triangles_per_node); 49 | 50 | /** 51 | * @brief 52 | */ 53 | void de_octree_free(de_octree_t * octree); 54 | 55 | /** 56 | * @brief Fills trace buffer with octree nodes which intersects with sphere. 57 | */ 58 | void de_octree_trace_sphere(de_octree_t * octree, const de_vec3_t* position, float radius); 59 | 60 | /** 61 | * @brief Fills trace buffer with octree nodes which itersects with ray. 62 | */ 63 | void de_octree_trace_ray(de_octree_t * octree, const de_ray_t * ray); 64 | -------------------------------------------------------------------------------- /resources/resource_fdecl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /* Forward declarations for resources. */ 23 | 24 | typedef enum de_resource_type_t { 25 | DE_RESOURCE_TYPE_MODEL, 26 | DE_RESOURCE_TYPE_TEXTURE, 27 | DE_RESOURCE_TYPE_SOUND_BUFFER 28 | } de_resource_type_t; 29 | 30 | typedef enum de_resource_flag_t { 31 | /** 32 | * Resource is created in runtime. Will be serialized unless 33 | * DE_RESOURCE_FLAG_PERSISTENT is set. Useful for dynamic resource like procedural 34 | * textures. 35 | */ 36 | DE_RESOURCE_FLAG_PROCEDURAL = DE_BIT(0), 37 | 38 | /** 39 | * Resource is will exist until core is destroyed. Such resource WON'T be serialized 40 | * by object visitor! For example such resources may be useful for UI textures which will 41 | * exist all the time game is running. 42 | **/ 43 | DE_RESOURCE_FLAG_PERSISTENT = DE_BIT(1), 44 | 45 | /** 46 | * Internal. Do not use. 47 | * 48 | * Internal persistent engine resources will be marked with this flag. 49 | */ 50 | DE_RESOURCE_FLAG_INTERNAL = DE_BIT(2), 51 | } de_resource_flags_t; 52 | 53 | typedef struct de_resource_dispatch_table_t { 54 | void(*init)(de_resource_t* res); 55 | void(*deinit)(de_resource_t* res); 56 | bool(*visit)(de_object_visitor_t* visitor, de_resource_t* res); 57 | /* load implementation for external resources */ 58 | bool(*load)(de_resource_t* res); 59 | } de_resource_dispatch_table_t; 60 | 61 | -------------------------------------------------------------------------------- /de_main.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | #include "de_main.h" 23 | #include "external/miniz_tinfl.c" 24 | #include "resources/image.c" 25 | #include "core/byteorder.c" 26 | #include "core/array.c" 27 | #include "core/hash.c" 28 | #include "core/color.c" 29 | #include "core/color_gradient.c" 30 | #include "core/log.c" 31 | #include "core/config.c" 32 | #include "core/memmgr.c" 33 | #include "core/base64.c" 34 | #include "core/string_utils.c" 35 | #include "core/string.c" 36 | #include "core/utf32string.c" 37 | #include "core/path.c" 38 | #include "core/rectpack.c" 39 | #include "core/rect.c" 40 | #include "core/utility.c" 41 | #include "core/serialization.c" 42 | #include "core/pathfinder.c" 43 | #include "core/core.c" 44 | #include "physics/physics.c" 45 | #include "fbx/fbx.c" 46 | #include "font/font.c" 47 | #include "math/mathlib.c" 48 | #include "math/triangulator.c" 49 | #include "scene/animation.c" 50 | #include "scene/camera.c" 51 | #include "scene/light.c" 52 | #include "scene/mesh.c" 53 | #include "scene/node.c" 54 | #include "scene/particle_system.c" 55 | #include "scene/scene.c" 56 | #include "renderer/renderer.c" 57 | #include "renderer/surface.c" 58 | #include "resources/texture.c" 59 | #include "gui/gui.c" 60 | #include "vg/vgraster.c" 61 | #include "core/thread.c" 62 | #include "sound/sound.c" 63 | #include "resources/resource.c" 64 | 65 | #if DE_EDITOR_ENABLED 66 | #include "editor/editor.c" 67 | #endif -------------------------------------------------------------------------------- /font/font.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_glyph_t { 23 | float bitmap_top; 24 | float bitmap_left; 25 | int bitmap_width; 26 | int bitmap_height; 27 | uint8_t* pixels; 28 | float advance; 29 | char has_outline; 30 | de_vec2_t texCoords[4]; 31 | } de_glyph_t; 32 | 33 | typedef struct de_font_charmap_entry_t { 34 | uint32_t unicode; 35 | uint32_t glyph_index; 36 | } de_font_charmap_entry_t; 37 | 38 | typedef struct de_font_t { 39 | de_core_t* core; 40 | DE_LINKED_LIST_ITEM(struct de_font_t); 41 | float height; 42 | int glyph_count; 43 | de_glyph_t* glyphs; 44 | int glyphsSorted; 45 | float ascender; 46 | float descender; 47 | float line_gap; 48 | de_texture_t* texture; 49 | DE_ARRAY_DECLARE(de_font_charmap_entry_t, charmap); 50 | } de_font_t; 51 | 52 | /** 53 | * @brief Loads font from TTF file 54 | */ 55 | de_font_t* de_font_load_ttf(de_core_t* core, const char * ttf, float height, const int* char_set, int char_count); 56 | 57 | /** 58 | * @brief Loads font from memory 59 | */ 60 | de_font_t* de_font_load_ttf_from_memory(de_core_t* core, void* data, float height, const int* char_set, int char_count); 61 | 62 | /** 63 | * @brief Frees resources associated with font 64 | */ 65 | void de_font_free(de_font_t* font); 66 | 67 | /** 68 | * @brief Tries to find a glyph by its unicode value. 69 | * Returns NULL if glyph not found 70 | */ 71 | de_glyph_t* de_font_get_glyph(const de_font_t* font, uint32_t code); -------------------------------------------------------------------------------- /core/rectpack.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | 23 | de_rectpack_node_t* de_rectpack_create_node(int x, int y, int w, int h) 24 | { 25 | de_rectpack_node_t* node = DE_NEW(de_rectpack_node_t); 26 | node->x = x; 27 | node->y = y; 28 | node->w = w; 29 | node->h = h; 30 | return node; 31 | } 32 | 33 | 34 | de_rectpack_node_t* de_rectpack_get_free(de_rectpack_node_t* node, int w, int h, void* data) 35 | { 36 | if (node->split) { 37 | de_rectpack_node_t* newNode = de_rectpack_get_free(node->children[0], w, h, data); 38 | if (newNode) { 39 | return newNode; 40 | } 41 | return de_rectpack_get_free(node->children[1], w, h, data); 42 | } 43 | if (node->data || node->w < w || node->h < h) { 44 | return NULL; 45 | } 46 | if (node->w == w && node->h == h) { 47 | node->data = data; 48 | return node; 49 | } 50 | if (node->w - w > node->h - h) { 51 | node->children[0] = de_rectpack_create_node(node->x, node->y, w, node->h); 52 | node->children[1] = de_rectpack_create_node(node->x + w, node->y, node->w - w, node->h); 53 | } else { 54 | node->children[0] = de_rectpack_create_node(node->x, node->y, node->w, h); 55 | node->children[1] = de_rectpack_create_node(node->x, node->y + h, node->w, node->h - h); 56 | } 57 | node->split = 1; 58 | return de_rectpack_get_free(node->children[0], w, h, data); 59 | } 60 | 61 | 62 | void de_rectpack_free(de_rectpack_node_t * node) 63 | { 64 | if (node && node->split) { 65 | de_rectpack_free(node->children[0]); 66 | de_rectpack_free(node->children[1]); 67 | } 68 | de_free(node); 69 | } 70 | -------------------------------------------------------------------------------- /gui/text.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | 23 | /** 24 | * 25 | */ 26 | typedef struct de_gui_text_descriptor_t { 27 | char* text; 28 | de_gui_vertical_alignment_t vertical_alignment; 29 | de_gui_horizontal_alignment_t horizontal_alignment; 30 | } de_gui_text_descriptor_t; 31 | 32 | /** 33 | * @brief 34 | */ 35 | typedef struct de_gui_text_line_t { 36 | size_t begin; 37 | size_t end; 38 | float width; 39 | float x; /* relative */ 40 | } de_gui_text_line_t; 41 | 42 | /** 43 | * @brief Lightweight text block. 44 | */ 45 | typedef struct de_gui_text_t { 46 | de_str32_t str; 47 | de_font_t* font; 48 | de_gui_vertical_alignment_t ver_alignment; 49 | de_gui_horizontal_alignment_t hor_alignment; 50 | DE_ARRAY_DECLARE(de_gui_text_line_t, lines); 51 | float total_lines_height; 52 | } de_gui_text_t; 53 | 54 | struct de_gui_node_dispatch_table_t* de_gui_text_get_dispatch_table(void); 55 | 56 | /** 57 | * @brief 58 | * @param node 59 | * @param font 60 | */ 61 | void de_gui_text_set_font(de_gui_node_t* node, de_font_t* font); 62 | 63 | /** 64 | * @brief 65 | * @param node 66 | * @param utf8str 67 | */ 68 | void de_gui_text_set_text_utf8(de_gui_node_t* node, const char* utf8str); 69 | 70 | void de_gui_text_set_text_utf32(de_gui_node_t* node, const uint32_t* utf32str); 71 | 72 | /** 73 | * @brief 74 | * @param node 75 | * @param alignment 76 | */ 77 | void de_gui_text_set_vertical_alignment(de_gui_node_t* node, de_gui_vertical_alignment_t alignment); 78 | 79 | void de_gui_text_set_horizontal_alignment(de_gui_node_t* node, de_gui_horizontal_alignment_t alignment); -------------------------------------------------------------------------------- /scene/camera.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Camera component. 24 | */ 25 | typedef struct de_camera_t { 26 | float fov; /**< Field-of-view in degrees. Read-only. */ 27 | float aspect; /**< Aspect ratio of camera viewport. Read-only. */ 28 | float z_near; /**< Distance to near clipping plane */ 29 | float z_far; /**< Distance to far clipping plane */ 30 | de_mat4_t view_matrix; /**< View matrix */ 31 | de_mat4_t projection_matrix; /**< Projection matrix */ 32 | de_mat4_t view_projection_matrix; /**< Combined view * projection matrix. Read-only. */ 33 | de_mat4_t inv_view_proj; 34 | de_rectf_t viewport; /**< Viewport rectangle in ratio. Default: 0,0,1,1 */ 35 | 36 | float depth_hack_value; 37 | bool in_depth_hack_mode; 38 | } de_camera_t; 39 | 40 | struct de_node_dispatch_table_t* de_camera_get_dispatch_table(void); 41 | 42 | /** 43 | * @brief Builds camera matrices. Camera have to be attached to some node. 44 | * @param camera pointer to camera component 45 | */ 46 | void de_camera_update(de_camera_t* c); 47 | 48 | /** 49 | * @brief Sets camera viewport in pixels 50 | * @param camera pointer to camera 51 | * @param x 52 | * @param y 53 | * @param w 54 | * @param h 55 | */ 56 | void de_camera_set_viewport(de_camera_t* camera, const de_rectf_t* viewport); 57 | 58 | void de_camera_set_fov(de_camera_t* camera, float fov); 59 | 60 | void de_camera_enter_depth_hack(de_camera_t* camera, float value); 61 | 62 | void de_camera_leave_depth_hack(de_camera_t* camera); -------------------------------------------------------------------------------- /gui/window.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef enum de_gui_window_flags_t { 23 | DE_GUI_WINDOW_FLAGS_NO_MOVE = DE_BIT(0) 24 | } de_gui_window_flags_t; 25 | 26 | /** 27 | * @brief 28 | */ 29 | typedef struct de_gui_window_t { 30 | de_gui_node_t* border; 31 | de_gui_node_t* grid; 32 | de_gui_node_t* header; 33 | de_gui_node_t* header_grid; 34 | de_gui_node_t* title; 35 | de_gui_node_t* scroll_viewer; 36 | de_gui_node_t* close_button; 37 | de_gui_node_t* collapse_button; 38 | bool is_dragging; 39 | de_vec2_t mouse_click_pos; 40 | de_vec2_t init_pos; 41 | uint32_t flags; 42 | } de_gui_window_t; 43 | 44 | struct de_gui_node_dispatch_table_t* de_gui_window_get_dispatch_table(); 45 | 46 | de_gui_node_t* de_gui_window_get_title(de_gui_node_t* window); 47 | 48 | void de_gui_window_set_content(de_gui_node_t* window, de_gui_node_t* content); 49 | 50 | de_gui_node_t* de_gui_window_get_content(de_gui_node_t* window); 51 | 52 | void de_gui_window_set_flags(de_gui_node_t* window, uint32_t flags); 53 | 54 | bool de_gui_window_is_flags_set(de_gui_node_t* window, uint32_t flags); 55 | 56 | /** 57 | * @brief Enables or disables vertical scroll for window content. If scroll 58 | * is enabled infinite bounds will be provided for content, so it can contain 59 | * control of any size. 60 | */ 61 | void de_gui_window_enable_vertical_scroll(de_gui_node_t* window, bool value); 62 | 63 | /** 64 | * @brief Enables or disables horizontal scroll for window content. If scroll 65 | * is enabled infinite bounds will be provided for content, so it can contain 66 | * control of any size. 67 | */ 68 | void de_gui_window_enable_horizontal_scroll(de_gui_node_t* window, bool value); -------------------------------------------------------------------------------- /math/frustum.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * Culling frustum 24 | */ 25 | typedef struct de_frustum_t { 26 | de_plane_t planes[6]; /**< Six planes that "cuts" frustum volume */ 27 | } de_frustum_t; 28 | 29 | /** 30 | * @brief Extracts frustum planes from view-projection matrix. 31 | */ 32 | de_frustum_t* de_frustum_from_matrix(de_frustum_t* f, const de_mat4_t* m); 33 | 34 | /** 35 | * @brief Checks intersection between frustum and specified cloud of points. 36 | */ 37 | bool de_frustum_point_cloud_intersection(const de_frustum_t* f, const de_vec3_t* points, size_t count); 38 | 39 | /** 40 | * @brief Checks intersection between frustum and axis-aligned bounding box. 41 | */ 42 | bool de_frustum_box_intersection(const de_frustum_t* f, const de_aabb_t* aabb); 43 | 44 | /** 45 | * @brief Checks intersection between frustum and axis-aligned bounding box with offset. 46 | */ 47 | bool de_frustum_box_intersection_offset(const de_frustum_t* f, const de_aabb_t* aabb, const de_vec3_t* aabb_offset); 48 | 49 | /** 50 | * @brief Checks intersection between frustum and transformed axis-aligned bounding box. 51 | * 52 | * AABB will be transformed into OBB (oriented bounding box) and only then intersection check 53 | * will be performed! 54 | */ 55 | bool de_frustum_box_intersection_transform(const de_frustum_t* f, const de_aabb_t* aabb, const de_mat4_t* world_matrix); 56 | 57 | /** 58 | * @brief Checks if point is inside frustum volume. 59 | */ 60 | bool de_frustum_contains_point(const de_frustum_t* f, const de_vec3_t* p); 61 | 62 | /** 63 | * @brief Checks if sphere intersect frustum. 64 | */ 65 | bool de_frustum_sphere_intersection(const de_frustum_t* f, const de_vec3_t* p, float r); -------------------------------------------------------------------------------- /math/plane.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | de_plane_t* de_plane_set_abcd(de_plane_t* p, float a, float b, float c, float d) 23 | { 24 | p->n.x = a; 25 | p->n.y = b; 26 | p->n.z = c; 27 | p->d = d; 28 | de_plane_normalize(p); 29 | return p; 30 | } 31 | 32 | de_plane_t* de_plane_set(de_plane_t* p, const de_vec3_t* plane_point, const de_vec3_t* plane_normal) 33 | { 34 | de_vec3_normalize(&p->n, plane_normal); 35 | p->d = -de_vec3_dot(plane_point, &p->n); 36 | return p; 37 | } 38 | 39 | float de_plane_distance(const de_plane_t* p, const de_vec3_t* point) 40 | { 41 | return (float)fabs(de_vec3_dot(&p->n, point) + p->d); 42 | } 43 | 44 | float de_plane_dot(const de_plane_t* p, const de_vec3_t* point) 45 | { 46 | return de_vec3_dot(&p->n, point) + p->d; 47 | } 48 | 49 | de_plane_t* de_plane_normalize(de_plane_t* p) 50 | { 51 | const float denominator = de_vec3_len(&p->n); 52 | #if DE_MATH_CHECKS 53 | if (denominator == 0.0f) { 54 | de_fatal_error("Cannot normalize plane with degenerated normal vector!"); 55 | } 56 | #endif 57 | const float d = 1.0f / denominator; 58 | de_vec3_scale(&p->n, &p->n, d); 59 | p->d *= d; 60 | return p; 61 | } 62 | 63 | de_plane_class_t de_plane_classify(const de_vec3_t * triangle_normal) 64 | { 65 | float longest = 0.0f; 66 | 67 | de_plane_class_t plane = DE_PLANE_OXY; 68 | 69 | if (fabs(triangle_normal->x) > longest) { 70 | longest = (float)fabs(triangle_normal->x); 71 | plane = DE_PLANE_OYZ; 72 | } 73 | 74 | if (fabs(triangle_normal->y) > longest) { 75 | longest = (float)fabs(triangle_normal->y); 76 | plane = DE_PLANE_OXZ; 77 | } 78 | 79 | if (fabs(triangle_normal->z) > longest) { 80 | plane = DE_PLANE_OXY; 81 | } 82 | 83 | return plane; 84 | } -------------------------------------------------------------------------------- /core/path.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_path_t { 23 | de_str8_t str; 24 | } de_path_t; 25 | 26 | void de_path_init(de_path_t* path); 27 | 28 | void de_path_free(de_path_t* path); 29 | 30 | void de_path_clear(de_path_t* path); 31 | 32 | /** 33 | * @brief Initializes path as view of c-string. !!! Do NOT call de_path_free or any path_append function 34 | * on such path, this is very dangerous, only read operations are allowed !!! 35 | */ 36 | void de_path_from_cstr_as_view(de_path_t* path, const char* cstr); 37 | 38 | /** 39 | * @brief Initializes path as string view. Useful to temporarily use existing string as path. 40 | */ 41 | void de_path_as_str8_view(de_path_t* path, de_str8_t* str); 42 | 43 | const char* de_path_cstr(const de_path_t* path); 44 | 45 | void de_path_append_cstr(de_path_t* path, const char* utf8str); 46 | 47 | void de_path_append_str8(de_path_t* path, const de_str8_t* str); 48 | 49 | void de_path_append_str_view(de_path_t* path, const de_str8_view_t* view); 50 | 51 | bool de_path_eq(const de_path_t* a, const de_path_t* b); 52 | 53 | void de_path_copy(const de_path_t* src, de_path_t* dest); 54 | 55 | bool de_path_is_empty(const de_path_t* src); 56 | 57 | uint32_t de_path_hash(const de_path_t* path); 58 | 59 | /** 60 | * @brief Extracts extension from file path with dot. 61 | * 62 | * Example: "baz/bar/foo.bar" 63 | * ^^^^ -> .bar 64 | */ 65 | void de_path_extension(const de_path_t* p, de_str8_view_t* ext); 66 | 67 | /** 68 | * @brief Extracts only name from file path without extension. 69 | * 70 | * Example: "baz/bar/foo.bar" 71 | * ^^^ -> foo 72 | */ 73 | void de_path_file_name(const de_path_t* p, de_str8_view_t* name); 74 | -------------------------------------------------------------------------------- /core/log.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | static FILE* de_log_file; 23 | 24 | void de_log_open(const char* filename) 25 | { 26 | if (!de_log_file) { 27 | de_log_file = fopen(filename, "w"); 28 | } 29 | } 30 | 31 | static void de_write_log(const char* message, bool error) 32 | { 33 | time_t rawtime; 34 | struct tm* timeinfo; 35 | 36 | /* Get time stamp */ 37 | time(&rawtime); 38 | timeinfo = localtime(&rawtime); 39 | 40 | if (de_log_file) { 41 | fprintf(de_log_file, "[%dh:%dm:%ds] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, message); 42 | fflush(de_log_file); 43 | } 44 | 45 | /* Duplicate message into standard streams, but without time stamps */ 46 | if (error) { 47 | fprintf(stderr, "Error: %s\n", message); 48 | } else { 49 | fprintf(stdout, "%s\n", message); 50 | fflush(stdout); 51 | } 52 | } 53 | 54 | void de_log(const char* message, ...) 55 | { 56 | static char format_buffer[65536]; 57 | va_list argument_list; 58 | va_start(argument_list, message); 59 | vsnprintf(format_buffer, sizeof(format_buffer), message, argument_list); 60 | va_end(argument_list); 61 | de_write_log(format_buffer, false); 62 | } 63 | 64 | void de_fatal_error(const char* message, ...) 65 | { 66 | static char format_buffer[65536]; 67 | va_list argument_list; 68 | va_start(argument_list, message); 69 | vsnprintf(format_buffer, sizeof(format_buffer), message, argument_list); 70 | va_end(argument_list); 71 | de_write_log(format_buffer, true); 72 | de_message_box(format_buffer, "Fatal Error"); 73 | #ifdef _MSC_VER 74 | __debugbreak(); 75 | #else 76 | __asm__("int $3"); 77 | #endif 78 | exit(EXIT_FAILURE); 79 | } 80 | 81 | void de_log_close(void) 82 | { 83 | if (de_log_file) { 84 | fclose(de_log_file); 85 | } 86 | } -------------------------------------------------------------------------------- /sound/context.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | struct de_sound_context_t { 23 | de_mtx_t mtx; 24 | de_core_t* core; 25 | de_sound_device_t dev; 26 | float master_volume; 27 | de_listener_t listener; 28 | DE_ARRAY_DECLARE(de_sound_source_t*, sounds); 29 | }; 30 | 31 | /** 32 | * @brief Internal. Creates new sound context. 33 | */ 34 | de_sound_context_t* de_sound_context_create(de_core_t* core); 35 | 36 | /** 37 | * @brief Internal. Destroys sound context. 38 | */ 39 | void de_sound_context_free(de_sound_context_t* ctx); 40 | 41 | /** 42 | * @brief Applies properties of every sounds source. This function is blocking, which 43 | * means that mixer thread will be paused until every sound source isn't updated. 44 | * You should call this function at least 10 times per second to get decent 45 | * results. See sound.h to more detailed explanation. 46 | */ 47 | void de_sound_context_update(de_sound_context_t* ctx); 48 | 49 | /** 50 | * @brief Internal. 51 | */ 52 | void de_sound_context_clear(de_sound_context_t* ctx); 53 | 54 | /** 55 | * @brief Internal. Locks context, use with caution. 56 | */ 57 | void de_sound_context_lock(de_sound_context_t* ctx); 58 | 59 | /** 60 | * @brief Internal. Unlocks context, use with caution. 61 | */ 62 | void de_sound_context_unlock(de_sound_context_t* ctx); 63 | 64 | /** 65 | * @brief Returns pointer to current listener. 66 | */ 67 | de_listener_t* de_sound_context_get_listener(de_sound_context_t* ctx); 68 | 69 | /** 70 | * @brief Sets master volume of sound context, defines global sound volume 71 | */ 72 | void de_sound_context_set_master_volume(de_sound_context_t* ctx, float vol); 73 | 74 | /** 75 | * @brief Internal. Visits sound context. 76 | */ 77 | bool de_sound_context_visit(de_object_visitor_t* visitor, de_sound_context_t* ctx); -------------------------------------------------------------------------------- /core/config.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_config_entry_t { 23 | char* name; 24 | char* value; 25 | } de_config_entry_t; 26 | 27 | typedef struct de_config_t { 28 | char* data; 29 | DE_ARRAY_DECLARE(de_config_entry_t, entries); 30 | } de_config_t; 31 | 32 | /** 33 | * @brief Loads file into memory and then parses it. 34 | */ 35 | bool de_config_parse_file(de_config_t* cfg, const de_path_t* path); 36 | 37 | /** 38 | * @brief Parses given source string. 39 | * 40 | * IMPORTANT: src must be allocated on heap! 41 | */ 42 | bool de_config_parse(de_config_t* cfg, char* src, size_t len); 43 | 44 | /** 45 | * @brief Frees memory used by specified config. 46 | */ 47 | void de_config_free(de_config_t* cfg); 48 | 49 | /** 50 | * @brief Prints config as set of strings "name = value". 51 | */ 52 | void de_config_print(de_config_t* cfg); 53 | 54 | /** 55 | * @brief Performs linear search of value by specified name. 56 | */ 57 | de_config_entry_t* de_config_find(de_config_t* cfg, const char* name); 58 | 59 | /** 60 | * @brief Tries to get float value by given name. Returns true on success. 61 | */ 62 | bool de_config_get_float(de_config_t* cfg, const char* name, float* f); 63 | 64 | /** 65 | * @brief Tries to get 32 bit integer value by given name. Returns true on success. 66 | */ 67 | bool de_config_get_int32(de_config_t* cfg, const char* name, int32_t* i); 68 | 69 | /** 70 | * @brief Tries to get 64 bit integer value by given name. Returns true on success. 71 | */ 72 | bool de_config_get_int64(de_config_t* cfg, const char* name, int64_t* i); 73 | 74 | /** 75 | * @brief Tries to get string value by given name. Returns true on success. 76 | */ 77 | bool de_config_get_str(de_config_t* cfg, const char* name, const char** str); 78 | 79 | /** 80 | * @brief Tests for config. 81 | */ 82 | void de_config_test(void); -------------------------------------------------------------------------------- /core/thread_win32.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | int de_thrd_create(de_thrd_t* thr, de_thrd_start_t func, void* arg) 23 | { 24 | thr->handle = (intptr_t)_beginthreadex(NULL, 0, (_beginthreadex_proc_type)func, arg, 0, 0); 25 | return thr->handle != 0; 26 | } 27 | 28 | int de_thrd_detach(de_thrd_t* thr) 29 | { 30 | CloseHandle((HANDLE)thr->handle); 31 | return true; 32 | } 33 | 34 | int de_thrd_join(de_thrd_t* thr) 35 | { 36 | WaitForSingleObject((HANDLE)thr->handle, INFINITE); 37 | return true; 38 | } 39 | 40 | void de_mtx_init(de_mtx_t* mtx) 41 | { 42 | CRITICAL_SECTION* ptr = de_malloc(sizeof(CRITICAL_SECTION)); 43 | InitializeCriticalSection(ptr); 44 | mtx->handle = (intptr_t)ptr; 45 | } 46 | 47 | void de_mtx_lock(de_mtx_t* mtx) 48 | { 49 | EnterCriticalSection((CRITICAL_SECTION*)mtx->handle); 50 | } 51 | 52 | void de_mtx_unlock(de_mtx_t* mtx) 53 | { 54 | LeaveCriticalSection((CRITICAL_SECTION*)mtx->handle); 55 | } 56 | 57 | void de_mtx_destroy(de_mtx_t* mtx) 58 | { 59 | DeleteCriticalSection((CRITICAL_SECTION*)mtx->handle); 60 | de_free((void*)mtx->handle); 61 | } 62 | 63 | void de_cnd_init(de_cnd_t* cnd) 64 | { 65 | CONDITION_VARIABLE* ptr = de_malloc(sizeof(CONDITION_VARIABLE)); 66 | InitializeConditionVariable(ptr); 67 | cnd->handle = (intptr_t)ptr; 68 | } 69 | 70 | void de_cnd_destroy(de_cnd_t* cnd) 71 | { 72 | /* no WinAPI call needed */ 73 | de_free((CONDITION_VARIABLE*)cnd->handle); 74 | } 75 | 76 | void de_cnd_signal(de_cnd_t* cnd) 77 | { 78 | WakeConditionVariable((CONDITION_VARIABLE*)cnd->handle); 79 | } 80 | 81 | void de_cnd_broadcast(de_cnd_t* cnd) 82 | { 83 | WakeAllConditionVariable((CONDITION_VARIABLE*)cnd->handle); 84 | } 85 | 86 | void de_cnd_wait(de_cnd_t* cnd, de_mtx_t* mtx) 87 | { 88 | SleepConditionVariableCS((CONDITION_VARIABLE*)cnd->handle, (CRITICAL_SECTION*)mtx->handle, INFINITE); 89 | } 90 | -------------------------------------------------------------------------------- /resources/texture.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | static void de_texture_init(de_resource_t* res) 23 | { 24 | de_texture_t* tex = de_resource_to_texture(res); 25 | tex->width = 0; 26 | tex->height = 0; 27 | tex->byte_per_pixel = 0; 28 | tex->depth = 0; 29 | tex->id = 0; 30 | tex->type = DE_TEXTURE_TYPE_2D; 31 | tex->pixels = 0; 32 | tex->need_upload = true; 33 | } 34 | 35 | static void de_texture_deinit(de_resource_t* res) 36 | { 37 | de_texture_t* tex = de_resource_to_texture(res); 38 | de_renderer_remove_texture(res->core->renderer, tex); 39 | de_free(tex->pixels); 40 | } 41 | 42 | static bool de_texture_load(de_resource_t* res) 43 | { 44 | de_texture_t* tex = de_resource_to_texture(res); 45 | de_image_t img = { 0 }; 46 | if (de_image_load_tga(de_path_cstr(&res->source), &img)) { 47 | tex->width = img.width; 48 | tex->height = img.height; 49 | tex->byte_per_pixel = img.byte_per_pixel; 50 | tex->pixels = img.data; 51 | tex->need_upload = true; 52 | return true; 53 | } 54 | return false; 55 | } 56 | 57 | void de_texture_alloc_pixels(de_texture_t* tex, int w, int h, size_t byte_per_pixel) 58 | { 59 | tex->width = w; 60 | tex->height = h; 61 | tex->byte_per_pixel = byte_per_pixel; 62 | tex->pixels = de_calloc(w*h, byte_per_pixel); 63 | tex->need_upload = true; 64 | } 65 | 66 | static bool de_texture_visit(de_object_visitor_t* visitor, de_resource_t* res) 67 | { 68 | de_texture_t* tex = de_resource_to_texture(res); 69 | DE_UNUSED(tex); 70 | DE_UNUSED(visitor); 71 | bool result = true; 72 | /* todo: visit dynamic textures here */ 73 | return result; 74 | } 75 | 76 | de_resource_dispatch_table_t* de_texture_get_dispatch_table(void) 77 | { 78 | static de_resource_dispatch_table_t table = { 79 | .init = de_texture_init, 80 | .deinit = de_texture_deinit, 81 | .load = de_texture_load, 82 | .visit = de_texture_visit, 83 | }; 84 | return &table; 85 | } -------------------------------------------------------------------------------- /core/utility.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | char * de_load_file_into_memory(const char * path, size_t* out_size) 23 | { 24 | size_t file_size; 25 | size_t content_size; 26 | char* content; 27 | FILE* file; 28 | 29 | /* try to open file */ 30 | file = fopen(path, "rb"); 31 | if (!file) { 32 | de_fatal_error("unable to read file: %s", path); 33 | } 34 | 35 | /* get file size */ 36 | fseek(file, 0, SEEK_END); 37 | file_size = ftell(file); 38 | content_size = file_size + 1; 39 | fseek(file, 0, SEEK_SET); 40 | 41 | /* read file */ 42 | content = (char*)de_malloc(content_size); 43 | if (fread(content, sizeof(char), file_size, file) != file_size) { 44 | de_fatal_error("file %s is corrupted", path); 45 | } 46 | 47 | if (out_size) { 48 | *out_size = file_size; 49 | } 50 | 51 | /* close file and write trailing zero at end of content array */ 52 | fclose(file); 53 | content[file_size] = '\0'; 54 | 55 | return content; 56 | } 57 | 58 | 59 | void de_convert_to_c_array(const char* source, const char* dest) 60 | { 61 | size_t i; 62 | size_t size; 63 | FILE* out; 64 | unsigned char* data; 65 | 66 | data = (unsigned char*)de_load_file_into_memory(source, &size); 67 | 68 | out = fopen(dest, "w"); 69 | 70 | fprintf(out, "static const unsigned char array[] = {\n"); 71 | for (i = 0; i < size; ++i) { 72 | fprintf(out, "%u, ", data[i]); 73 | 74 | if (i % 20 == 0) { 75 | fprintf(out, "\n\t"); 76 | } 77 | } 78 | 79 | fprintf(out, "\n};"); 80 | 81 | de_free(data); 82 | fclose(out); 83 | } 84 | 85 | bool de_file_exists(const char* filename) 86 | { 87 | /* TODO: look for a better way */ 88 | FILE* file = fopen(filename, "r"); 89 | if(file) { 90 | fclose(file); 91 | return true; 92 | } 93 | return false; 94 | } 95 | 96 | void de_file_tests(void) 97 | { 98 | DE_ASSERT(de_file_exists("___foobar_1234") == false); 99 | /* TODO: add more */ 100 | } -------------------------------------------------------------------------------- /fbx/fbx.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * ASCII + Binary FBX Loader 24 | * 25 | * ------------------- 26 | * | IMPORTANT STUFF | 27 | * vvvvvvvvvvvvvvvvvvv 28 | * 29 | * What is NOT supported: 30 | * - Animated geometric transform (scale, translation, rotation), basically there is only 31 | * translation, rotation, scale is supported as animated properties. Poke me if you need 32 | * support of other properties to be animated. 33 | * - Cameras 34 | * - Area and Volume lights 35 | * - Some of vertex components mappings. Engine will shoot error if will see unsupported 36 | * mapping. This stuff is still in progress. 37 | * - Embedded media 38 | * - Maybe some other stuff, about which I don't know. 39 | * 40 | * Important conventions: 41 | * 42 | * To make life easier, here is some convetions for textures that you can use in 43 | * development. 44 | * 45 | * - For normal maps you should add suffix "_normal" to your normal map, so engine 46 | * can correctly assign it to surface. So if you using diffuse texture called "foo.tga" 47 | * you should create a normap map texture called "foo_normal.tga", and engine will 48 | * automatically link them together. 49 | * - For height maps suffix is "_height" 50 | * 51 | **/ 52 | 53 | /* Supported versions */ 54 | #define DE_FBX_VERSION_MIN 7000 55 | #define DE_FBX_VERSION_MAX 7400 56 | 57 | typedef enum de_fbx_mapping_t { 58 | DE_FBX_MAPPING_UNKNOWN, 59 | DE_FBX_MAPPING_BY_POLYGON, 60 | DE_FBX_MAPPING_BY_POLYGON_VERTEX, 61 | DE_FBX_MAPPING_BY_VERTEX, 62 | DE_FBX_MAPPING_BY_EDGE, 63 | DE_FBX_MAPPING_ALL_SAME 64 | } de_fbx_mapping_t; 65 | 66 | typedef enum de_fbx_reference_t { 67 | DE_FBX_REFERENCE_UNKNOWN, 68 | DE_FBX_REFERENCE_DIRECT, 69 | DE_FBX_REFERENCE_INDEX_TO_DIRECT 70 | } de_fbx_reference_t; 71 | 72 | #include "fbx/fbx_node.h" 73 | #include "fbx/fbx_ascii.h" 74 | #include "fbx/fbx_binary.h" 75 | 76 | /** 77 | * @brief 78 | * @param file 79 | * @return 80 | */ 81 | de_node_t* de_fbx_load_to_scene(de_scene_t* scene, const char* file); 82 | 83 | bool de_fbx_is_binary(const char* filename); -------------------------------------------------------------------------------- /fbx/fbx_node.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef struct de_fbx_buffer_t { 23 | char* data; 24 | char* ptr; 25 | char* end; 26 | size_t size; 27 | } de_fbx_buffer_t; 28 | 29 | void de_fbx_buffer_init(de_fbx_buffer_t* buf, size_t size); 30 | 31 | /** 32 | * @brief Performs very fast continuous memory "allocations" in fixed-size buffer 33 | * 34 | * Main purpose of this method is to reduce memory thrashing when loading FBX 35 | * properties so every property will be placed in the single memory block. 36 | */ 37 | void* de_fbx_buffer_alloc(de_fbx_buffer_t* buf, size_t size); 38 | 39 | void de_fbx_buffer_free(de_fbx_buffer_t* buf); 40 | 41 | typedef struct de_fbx_node_s { 42 | /* Name of a node */ 43 | de_str8_t name; 44 | 45 | /* Means that each attribute is binary so no conversion needed on fetch */ 46 | bool is_binary; 47 | 48 | /* Array of attributes */ 49 | DE_ARRAY_DECLARE(char*, attributes); 50 | 51 | /* Pointer to parent node */ 52 | struct de_fbx_node_s* parent; 53 | 54 | /* Array of pointers to children nodes */ 55 | DE_ARRAY_DECLARE(struct de_fbx_node_s*, children); 56 | } de_fbx_node_t; 57 | 58 | int de_fbx_get_int(const de_fbx_node_t* node, int index); 59 | 60 | int64_t de_fbx_get_int64(const de_fbx_node_t* node, int index); 61 | 62 | float de_fbx_get_float(const de_fbx_node_t* node, int index); 63 | 64 | double de_fbx_get_double(const de_fbx_node_t* node, int index); 65 | 66 | /* reads 3 elements from passed index */ 67 | void de_fbx_get_vec3(const de_fbx_node_t* node, int index, de_vec3_t* out); 68 | 69 | /* reads 2 elements from passed index */ 70 | void de_fbx_get_vec2(const de_fbx_node_t* node, int index, de_vec2_t* out); 71 | 72 | char* de_fbx_get_string(const de_fbx_node_t* node, int index); 73 | 74 | /* Allocates new hierarchy node with passed name, returns pointer to new node. */ 75 | de_fbx_node_t* de_fbx_create_node(const char* name); 76 | 77 | de_fbx_node_t* de_fbx_node_get_child(de_fbx_node_t* node, const char* name); 78 | 79 | de_fbx_node_t* de_fbx_node_find_child(de_fbx_node_t* node, const char* name); 80 | 81 | void de_fbx_node_free(de_fbx_node_t* node); -------------------------------------------------------------------------------- /gui/image.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | static void de_gui_image_apply_descriptor(de_gui_node_t* n, const de_gui_node_descriptor_t* desc) 23 | { 24 | DE_ASSERT_GUI_NODE_TYPE(n, DE_GUI_NODE_IMAGE); 25 | const de_gui_image_descriptor_t* img_desc = &desc->s.image; 26 | de_gui_image_set_texture(n, img_desc->texture); 27 | } 28 | 29 | static void de_gui_image_render(de_gui_draw_list_t* dl, de_gui_node_t* n, uint8_t nesting) 30 | { 31 | const de_vec2_t* scr_pos = &n->screen_position; 32 | const de_gui_image_t* img = &n->s.image; 33 | de_vec2_t tex_coords[4] = { 34 | { 0, 0 }, 35 | { 1, 0 }, 36 | { 1, 1 }, 37 | { 0, 1 } 38 | }; 39 | 40 | DE_ASSERT_GUI_NODE_TYPE(n, DE_GUI_NODE_IMAGE); 41 | 42 | DE_UNUSED(nesting); 43 | 44 | de_gui_draw_list_push_rect_filled(dl, scr_pos, &n->actual_size, &n->color, tex_coords); 45 | de_gui_draw_list_commit(dl, DE_GUI_DRAW_COMMAND_TYPE_GEOMETRY, img->texture ? img->texture->id : 0, n); 46 | } 47 | 48 | static void de_gui_image_deinit(de_gui_node_t* n) 49 | { 50 | DE_ASSERT_GUI_NODE_TYPE(n, DE_GUI_NODE_IMAGE); 51 | const de_gui_image_t* img = &n->s.image; 52 | if (img->texture) { 53 | de_resource_t* res = de_resource_from_texture(img->texture); 54 | de_resource_release(res); 55 | } 56 | } 57 | 58 | struct de_gui_node_dispatch_table_t* de_gui_image_get_dispatch_table() 59 | { 60 | static de_gui_node_dispatch_table_t dispatch_table = { 61 | .render = de_gui_image_render, 62 | .deinit = de_gui_image_deinit, 63 | .apply_descriptor = de_gui_image_apply_descriptor 64 | }; 65 | return &dispatch_table; 66 | } 67 | 68 | void de_gui_image_set_texture(de_gui_node_t* n, de_texture_t* tex) 69 | { 70 | DE_ASSERT_GUI_NODE_TYPE(n, DE_GUI_NODE_IMAGE); 71 | de_gui_image_t* img = &n->s.image; 72 | if (img->texture) { 73 | de_resource_release(de_resource_from_texture(img->texture)); 74 | } 75 | img->texture = tex; 76 | if (img->texture) { 77 | de_resource_add_ref(de_resource_from_texture(img->texture)); 78 | } 79 | } 80 | 81 | de_texture_t* de_gui_image_get_texture(de_gui_node_t* n) 82 | { 83 | DE_ASSERT_GUI_NODE_TYPE(n, DE_GUI_NODE_IMAGE); 84 | const de_gui_image_t* img = &n->s.image; 85 | return img->texture; 86 | } -------------------------------------------------------------------------------- /sound/decoder.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef enum de_sound_decoder_type_t { 23 | DE_SOUND_DECODER_TYPE_WAV = 1 24 | } de_sound_decoder_type_t; 25 | 26 | struct de_sound_decoder_t { 27 | uint32_t channel_count; 28 | uint32_t sample_per_channel; 29 | uint32_t sample_rate; 30 | /* private */ 31 | de_sound_decoder_type_t type; 32 | FILE* file; 33 | uint32_t source_byte_per_sample; 34 | size_t total_bytes; 35 | size_t bytes_read; 36 | }; 37 | 38 | /** 39 | * @brief Opens stream. Automatically detects type of data. 40 | */ 41 | de_sound_decoder_t* de_sound_decoder_create(const char* filename); 42 | 43 | /** 44 | * @brief Reads next portion of decoded PCM data. Returns actual count of samples per channel. 45 | * 46 | * Returns actual sample count per channel that was readed. 47 | * 48 | * Explanation: We don't care about size in bytes of data since we using floats to store samples, 49 | * so this method expects amount of samples that it should read per channel in source stream. 50 | * For example, we have 2-channel with 44100 Hz sample rate source file and we want to read one 51 | * second of data from it we need to pass 44100 as @sample_per_channel argument. The function will 52 | * actually read 2*44100*internal_sample_size bytes from source and will convert it to 53 | * 2*44100 float samples. In this case @out_data must be 2*44100*sizeof(float)=352800 bytes long. 54 | * You may wonder why we do take care of sample rate of source? Answer is simple: sample rate will be 55 | * used as parameter to calculate playback speed of a sound source. Thus we will eliminate resampling 56 | * stage, it will be performed automatically. 57 | */ 58 | size_t de_sound_decoder_read(de_sound_decoder_t* dec, float* out_data, size_t sample_per_channel, size_t offset, size_t count); 59 | 60 | /** 61 | * @brief Rewinds read head to beginning of the stream. 62 | */ 63 | void de_sound_decoder_rewind(de_sound_decoder_t* dec); 64 | 65 | 66 | /** 67 | * @brief Returns true if buffer source file is valid and its format is supported. 68 | */ 69 | bool de_sound_decoder_is_source_valid(const de_path_t* path); 70 | 71 | /** 72 | * @brief Frees stream. 73 | */ 74 | void de_sound_decoder_free(de_sound_decoder_t* dec); 75 | -------------------------------------------------------------------------------- /scene/light.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Possible light types 24 | * 25 | * If numeric values changed, keep shaders in sync! 26 | */ 27 | typedef enum de_light_type_t { 28 | DE_LIGHT_TYPE_POINT = 0, 29 | DE_LIGHT_TYPE_DIRECTIONAL = 1, 30 | DE_LIGHT_TYPE_SPOT = 2, 31 | } de_light_type_t; 32 | 33 | /** 34 | * @brief Common light component. 35 | * 36 | * Can be any possible light type (point, directional, spot) 37 | */ 38 | struct de_light_t { 39 | de_light_type_t type; /**< Actual type of light */ 40 | float radius; /**< Radius of point light */ 41 | de_color_t color; /**< Color of light */ 42 | float cone_angle; /**< Angle at cone vertex in radians. Do not set directly! Use de_light_set_cone_angle.*/ 43 | float cone_angle_cos; /**< Precomputed cosine of angle at cone vertex. */ 44 | bool cast_shadows; 45 | }; 46 | 47 | struct de_node_dispatch_table_t* de_light_get_dispatch_table(void); 48 | 49 | /** 50 | * @brief Sets current radius of light. Radius defines maximum distance to a point 51 | * at which this point can be lit. 52 | */ 53 | void de_light_set_radius(de_light_t* light, float radius); 54 | 55 | /** 56 | * @brief Returns current radius of light. Radius defines maximum distance to a point 57 | * at which this point can be lit. 58 | */ 59 | float de_light_get_radius(const de_light_t* light); 60 | 61 | /** 62 | * @brief Sets angle in radians at cone vertex of a spot light. 63 | */ 64 | void de_light_set_cone_angle(de_light_t* light, float angle); 65 | 66 | /** 67 | * @brief Returns angle in radians at cone vertex of a spot light. 68 | */ 69 | float de_light_get_cone_angle(const de_light_t* light); 70 | 71 | /** 72 | * @brief Sets current color of a light source. 73 | */ 74 | void de_light_set_color(de_light_t* light, const de_color_t* color); 75 | 76 | /** 77 | * @brief Returns current color of a light source. 78 | */ 79 | void de_light_get_color(const de_light_t* light, de_color_t* color); 80 | 81 | /** 82 | * @brief Should light cast shadows or not. 83 | */ 84 | void de_light_set_cast_shadows(de_light_t* light, bool value); 85 | 86 | /** 87 | * @brief Returns true if light should cast shadows. 88 | */ 89 | bool de_light_get_cast_shadows(const de_light_t* light); -------------------------------------------------------------------------------- /scene/scene.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | struct de_scene_t { 23 | de_resource_t* res; /**< Resource which contains this scene. When not NULL, scene will be ignored in all calculations. */ 24 | de_core_t* core; 25 | DE_LINKED_LIST_DECLARE(de_node_t, nodes); 26 | DE_LINKED_LIST_DECLARE(de_body_t, bodies); 27 | DE_LINKED_LIST_DECLARE(de_static_geometry_t, static_geometries); 28 | DE_LINKED_LIST_DECLARE(de_animation_t, animations); 29 | de_node_t* active_camera; 30 | DE_LINKED_LIST_ITEM(de_scene_t); 31 | }; 32 | 33 | /** 34 | * @brief Creates new empty scene and attaches it to engine instance. 35 | */ 36 | de_scene_t* de_scene_create(de_core_t* core); 37 | 38 | /** 39 | * @brief Destroys all scene resources and deallocates memory. 40 | */ 41 | void de_scene_free(de_scene_t* s); 42 | 43 | /** 44 | * @brief Creates new empty static geometry 45 | * @return pointer to new static geometry 46 | */ 47 | de_static_geometry_t* de_scene_create_static_geometry(de_scene_t* s); 48 | 49 | /** 50 | * @brief Frees static geometry. Removes it from scene. 51 | */ 52 | void de_scene_free_static_geometry(de_scene_t* s, de_static_geometry_t* geom); 53 | 54 | /** 55 | * @brief Adds node to scene. Only attached nodes can interact and be renderered. 56 | */ 57 | void de_scene_add_node(de_scene_t* s, de_node_t* handle); 58 | 59 | /** 60 | * @brief Removes node from scene (does not frees node!). Node will not be renderered and 61 | * interaction will be suspended. 62 | */ 63 | void de_scene_remove_node(de_scene_t* s, de_node_t* handle); 64 | 65 | /** 66 | * @brief Tries to find a node with specified name. Performs linear search O(n). 67 | */ 68 | de_node_t* de_scene_find_node(const de_scene_t* s, const char* name); 69 | 70 | /** 71 | * @brief Returns head node in the linked list of scene nodes. Typical usage is 72 | * to iterate over all nodes like this: 73 | * 74 | * for(de_node_t* node = de_scene_get_first_node(scene); node; node = de_node_get_next(node->next)) { ... } 75 | */ 76 | de_node_t* de_scene_get_first_node(de_scene_t* s); 77 | 78 | /** 79 | * @brief Update scene components (i.e. animations) 80 | */ 81 | void de_scene_update(de_scene_t* s, double dt); 82 | 83 | bool de_scene_visit(de_object_visitor_t* visitor, de_scene_t* scene); -------------------------------------------------------------------------------- /math/aabb.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Axis-aligned bounding box (AABB) 24 | */ 25 | typedef struct de_aabb_t { 26 | de_vec3_t min; /**< Corner with with set of minimal coordinates, describing the AABB */ 27 | de_vec3_t max; /**< Corner with with set of maximal coordinates, describing the AABB */ 28 | } de_aabb_t; 29 | 30 | /** 31 | * @brief Initializes axis-aligned bounding box from specified corner points. 32 | */ 33 | void de_aabb_set(de_aabb_t* aabb, const de_vec3_t* min, const de_vec3_t* max); 34 | 35 | /** 36 | * @brief Checks intersection between specified sphere and aabb. 37 | */ 38 | bool de_aabb_sphere_intersection(const de_aabb_t* aabb, const de_vec3_t* aabb_offset, const de_vec3_t* position, float radius); 39 | 40 | /** 41 | * @brief Checks if axis-aligned bounding box contains specified point. 42 | */ 43 | bool de_aabb_contains_point(const de_aabb_t* aabb, const de_vec3_t* point); 44 | 45 | /** 46 | * @brief Chechs intersection between two axis-aligned bounding boxes. 47 | */ 48 | bool de_aabb_aabb_intersection(const de_aabb_t* aabb, const de_aabb_t* other); 49 | 50 | /** 51 | * @brief Checks intersection between triangle and axis-aligned bounding box. 52 | * 53 | * This is just rough check - check for intersection between aabb of triangle with specified aabb. 54 | */ 55 | bool de_aabb_triangle_intersection(const de_aabb_t* aabb, const de_vec3_t* a, const de_vec3_t* b, const de_vec3_t* c); 56 | 57 | /** 58 | * @brief Adds point to axis-aligned bounding box. 59 | */ 60 | de_aabb_t* de_aabb_push_point(de_aabb_t* aabb, const de_vec3_t* p); 61 | 62 | /** 63 | * @brief Returns size of axis-aligned bounding box. 64 | */ 65 | void de_aabb_get_size(const de_aabb_t* aabb, de_vec3_t* size); 66 | 67 | /** 68 | * @brief Returns center of axis-aligned bounding box. 69 | */ 70 | void de_aabb_get_center(const de_aabb_t* aabb, de_vec3_t* center); 71 | 72 | /** 73 | * @brief Sets extremal points to invalid values (min -> (huge_value), max -> (-huge_value)) 74 | */ 75 | void de_aabb_invalidate(de_aabb_t* aabb); 76 | 77 | /** 78 | * @brief Merges specified axis-aligned bounding box with other box. Specified aabb becomes large 79 | * enough to contain two boxes. 80 | */ 81 | void de_aabb_merge(de_aabb_t* aabb, const de_aabb_t* other); -------------------------------------------------------------------------------- /core/utf32string.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | void de_str32_init(de_str32_t* str) 23 | { 24 | DE_ARRAY_INIT(str->str); 25 | } 26 | 27 | void de_str32_free(de_str32_t* str) 28 | { 29 | DE_ARRAY_FREE(str->str); 30 | } 31 | 32 | void de_str32_move(de_str32_t* src, de_str32_t* dest) 33 | { 34 | DE_ARRAY_MOVE(src->str, dest->str); 35 | } 36 | 37 | void de_str32_insert(de_str32_t* str, int pos, uint32_t unicode) 38 | { 39 | DE_ARRAY_INSERT(str->str, pos, unicode); 40 | } 41 | 42 | void de_str32_append(de_str32_t* str, uint32_t unicode) 43 | { 44 | de_str32_insert(str, str->str.size, unicode); 45 | } 46 | 47 | void de_str32_clear(de_str32_t* str) 48 | { 49 | DE_ARRAY_CLEAR(str->str); 50 | } 51 | 52 | void de_str32_remove(de_str32_t* str, int pos, int amount) 53 | { 54 | uint32_t* data = str->str.data; 55 | int size = (int)str->str.size; 56 | pos = pos < 0 ? 0 : pos; 57 | amount = (pos + amount) >= size ? size - pos : amount; 58 | memmove(data + pos, data + pos + amount, sizeof(*data) * (size - (pos + amount))); 59 | str->str.size -= amount; 60 | } 61 | 62 | size_t de_str32_length(de_str32_t* str) 63 | { 64 | return str->str.size; 65 | } 66 | 67 | const uint32_t* de_str32_get_data(const de_str32_t* str) 68 | { 69 | return str->str.data; 70 | } 71 | 72 | uint32_t de_str32_at(const de_str32_t* str, size_t i) 73 | { 74 | return str->str.data[i]; 75 | } 76 | 77 | void de_str32_set_utf8(de_str32_t* str, const de_str8_view_t* view) 78 | { 79 | int reserved_size = view->len * 4; 80 | de_str32_clear(str); 81 | DE_ARRAY_GROW(str->str, reserved_size); 82 | str->str.size = (size_t)de_utf8_to_utf32(view->data, view->len, str->str.data, reserved_size); 83 | } 84 | 85 | void de_str32_append_utf8(de_str32_t* str, const de_str8_view_t* view) 86 | { 87 | size_t old_size, decoded; 88 | int reserved_size = view->len * 4; 89 | old_size = str->str.size; 90 | DE_ARRAY_GROW(str->str, reserved_size); 91 | decoded = (size_t)de_utf8_to_utf32(view->data, view->len, str->str.data + old_size, reserved_size); 92 | str->str.size = old_size + decoded; 93 | } 94 | 95 | void de_str32_append_cstr(de_str32_t* str, const char* cstr) 96 | { 97 | de_str8_view_t view; 98 | de_str8_view_set_cstr(&view, cstr); 99 | de_str32_append_utf8(str, &view); 100 | } -------------------------------------------------------------------------------- /core/thread.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /* Partial implementation of C11 threads.h 23 | * Threads are optional in C11 and most compilers ignore them. 24 | * 25 | * WARNING: Current implementation for Windows have minumum supported version 26 | * Windows Vista. WinXP is not supported! 27 | * 28 | * Note: Implementation is platform-specific. */ 29 | 30 | #if defined(__GNUC__) || defined(__MINGW32__) 31 | 32 | #include 33 | 34 | typedef pthread_cond_t de_cnd_t; 35 | typedef pthread_t de_thrd_t; 36 | typedef pthread_mutex_t de_mtx_t; 37 | 38 | #else /* Win32 */ 39 | 40 | typedef struct de_mtx_t { 41 | intptr_t handle; 42 | } de_mtx_t; 43 | 44 | typedef struct de_thrd_t { 45 | intptr_t handle; 46 | } de_thrd_t; 47 | 48 | typedef struct de_cnd_t { 49 | intptr_t handle; 50 | } de_cnd_t; 51 | 52 | #endif 53 | 54 | typedef int(*de_thrd_start_t)(void*); 55 | 56 | /** 57 | * @brief Forces thread to sleep specified time 58 | * @param milliseconds time to sleep in milliseconds 59 | */ 60 | void de_sleep(int milliseconds); 61 | 62 | /** 63 | * @brief Creates new suspended thread. 64 | */ 65 | int de_thrd_create(de_thrd_t* thr, de_thrd_start_t func, void* arg); 66 | 67 | /** 68 | * @brief Runs specified thread. 69 | */ 70 | int de_thrd_detach(de_thrd_t* thr); 71 | 72 | /** 73 | * @brief Runs specified thread and blocks callee thread until specified thread is finished. 74 | */ 75 | int de_thrd_join(de_thrd_t* thr); 76 | 77 | /** 78 | * @brief Creates recursive mutex. 79 | */ 80 | void de_mtx_init(de_mtx_t* mtx); 81 | 82 | /** 83 | * @brief Locks mutex. 84 | */ 85 | void de_mtx_lock(de_mtx_t* mtx); 86 | 87 | /** 88 | * @brief Unlocks mutex. 89 | */ 90 | void de_mtx_unlock(de_mtx_t* mtx); 91 | 92 | /** 93 | * @brief Destroys mutex. 94 | */ 95 | void de_mtx_destroy(de_mtx_t* mtx); 96 | 97 | /** 98 | * @brief Initializes new condition variable. 99 | */ 100 | void de_cnd_init(de_cnd_t* cnd); 101 | 102 | /** 103 | * @brief Destroys condition variable. 104 | */ 105 | void de_cnd_destroy(de_cnd_t* cnd); 106 | 107 | /** 108 | * @brief Wake up single thread. 109 | */ 110 | void de_cnd_signal(de_cnd_t* cnd); 111 | 112 | /** 113 | * @brief Wake up all awaiting threads. 114 | */ 115 | void de_cnd_broadcast(de_cnd_t* cnd); 116 | 117 | /** 118 | * @brief Waits until awake signal is received. 119 | */ 120 | void de_cnd_wait(de_cnd_t* cnd, de_mtx_t* mtx); -------------------------------------------------------------------------------- /gui/check_box.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | static void de_gui_check_box_apply_descriptor(de_gui_node_t* n, const de_gui_node_descriptor_t* desc) 23 | { 24 | DE_ASSERT_GUI_NODE_TYPE(n, DE_GUI_NODE_CHECK_BOX); 25 | de_gui_check_box_t* cb = &n->s.check_box; 26 | const de_gui_check_box_descriptor_t* cbdesc = &desc->s.check_box; 27 | de_gui_check_box_set_value(n, cbdesc->checked); 28 | cb->checked_changed = cbdesc->checked_changed; 29 | } 30 | 31 | static void de_gui_check_box_mouse_down(de_gui_node_t* n, de_gui_routed_event_args_t* args) 32 | { 33 | DE_UNUSED(args); 34 | DE_ASSERT_GUI_NODE_TYPE(n, DE_GUI_NODE_CHECK_BOX); 35 | de_gui_check_box_t* cb = &n->s.check_box; 36 | de_gui_check_box_set_value(n, !cb->checked); 37 | } 38 | 39 | static void de_gui_check_box_init(de_gui_node_t* n) 40 | { 41 | DE_ASSERT_GUI_NODE_TYPE(n, DE_GUI_NODE_CHECK_BOX); 42 | de_gui_check_box_t* cb = &n->s.check_box; 43 | n->mouse_down = de_gui_check_box_mouse_down; 44 | 45 | cb->border = de_gui_node_create_with_desc(n->gui, DE_GUI_NODE_BORDER, &(de_gui_node_descriptor_t){ 46 | .parent = n, .s.border = (de_gui_border_descriptor_t) 47 | { 48 | .thickness = { 2, 2, 2, 2 }, .stroke_color = { 80, 80, 80, 255 } 49 | }, 50 | .color = (de_color_t) { .r = 120, .g = 120, .b = 120, .a = 255 }, 51 | }); 52 | 53 | cb->check_mark = de_gui_node_create_with_desc(n->gui, DE_GUI_NODE_BORDER, &(de_gui_node_descriptor_t){ 54 | .margin = (de_gui_thickness_t) { .left = 4, .right = 4, .top = 4, .bottom = 4 }, 55 | .parent = n, 56 | .visibility = DE_GUI_NODE_VISIBILITY_COLLAPSED, 57 | .color = { 200, 200, 200, 255 } 58 | }); 59 | } 60 | 61 | struct de_gui_node_dispatch_table_t* de_gui_check_box_get_dispatch_table() 62 | { 63 | static de_gui_node_dispatch_table_t table = { 64 | .init = de_gui_check_box_init, 65 | .apply_descriptor = de_gui_check_box_apply_descriptor, 66 | }; 67 | return &table; 68 | } 69 | 70 | void de_gui_check_box_set_value(de_gui_node_t* n, bool value) 71 | { 72 | DE_ASSERT_GUI_NODE_TYPE(n, DE_GUI_NODE_CHECK_BOX); 73 | de_gui_check_box_t* cb = &n->s.check_box; 74 | cb->checked = value; 75 | if(cb->checked_changed) { 76 | cb->checked_changed(n, value); 77 | } 78 | de_gui_node_set_visibility(cb->check_mark, cb->checked ? DE_GUI_NODE_VISIBILITY_VISIBLE : DE_GUI_NODE_VISIBILITY_COLLAPSED); 79 | } 80 | 81 | bool de_gui_check_box_get_value(de_gui_node_t* n) 82 | { 83 | DE_ASSERT_GUI_NODE_TYPE(n, DE_GUI_NODE_CHECK_BOX); 84 | de_gui_check_box_t* cb = &n->s.check_box; 85 | return cb->checked; 86 | } -------------------------------------------------------------------------------- /resources/resource.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | #include "resources/model.h" 23 | 24 | struct de_resource_t { 25 | de_resource_type_t type; 26 | de_path_t source; 27 | de_core_t* core; 28 | de_resource_dispatch_table_t* dispatch_table; 29 | int32_t ref_count; /** TODO: Probably should be atomic? */ 30 | uint32_t flags; 31 | union { 32 | de_sound_buffer_t sound_buffer; 33 | de_texture_t texture; 34 | de_model_t model; 35 | } s; 36 | }; 37 | 38 | const char* de_resource_type_to_cstr(de_resource_type_t type); 39 | 40 | /** 41 | * @brief Creates new resource of specified type with specified flags. Automatically 42 | * registers self in core. path can be null for runtime resources. 43 | */ 44 | de_resource_t* de_resource_create(de_core_t* core, const de_path_t* path, de_resource_type_t type); 45 | 46 | void de_resource_set_flags(de_resource_t* res, de_resource_flags_t flags); 47 | 48 | /** 49 | * @brief Increases reference counter of resource. You must call de_resource_release when you do not 50 | * need resource anymore. 51 | */ 52 | void de_resource_add_ref(de_resource_t* res); 53 | 54 | /** 55 | * @brief Frees resource 56 | */ 57 | int de_resource_release(de_resource_t* res); 58 | 59 | bool de_resource_visit(de_object_visitor_t* visitor, de_resource_t* res); 60 | 61 | /** 62 | * @brief Returns pointer to model based on resource pointer. 63 | */ 64 | de_model_t* de_resource_to_model(de_resource_t* res); 65 | 66 | /** 67 | * @brief Returns pointer to resource from pointer to model resource. 68 | */ 69 | de_resource_t* de_resource_from_model(de_model_t* mdl); 70 | 71 | /** 72 | * @brief Returns pointer to model resource based on resource pointer. 73 | */ 74 | de_sound_buffer_t* de_resource_to_sound_buffer(de_resource_t* res); 75 | 76 | /** 77 | * @brief Returns pointer to resource from pointer to sound buffer resource. 78 | */ 79 | de_resource_t* de_resource_from_sound_buffer(de_sound_buffer_t* buf); 80 | 81 | /** 82 | * @brief Returns pointer to texture resource based on resource pointer. 83 | */ 84 | de_texture_t* de_resource_to_texture(de_resource_t* res); 85 | 86 | /** 87 | * @brief Returns pointer to resource from pointer to texture resource. 88 | */ 89 | de_resource_t* de_resource_from_texture(de_texture_t* buf); 90 | 91 | 92 | de_resource_dispatch_table_t* de_resource_get_dispatch_table_by_type(de_resource_type_t type); 93 | 94 | /** 95 | * @brief Internal. Performs dispatch call to type-specific loading routine. 96 | */ 97 | bool de_resource_load(de_resource_t* res); 98 | 99 | de_resource_type_t de_resource_get_type(de_resource_t* res); -------------------------------------------------------------------------------- /math/quat.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * Possible rotation orders 24 | */ 25 | typedef enum de_euler_t { 26 | DE_EULER_XYZ, 27 | DE_EULER_XZY, 28 | DE_EULER_YZX, 29 | DE_EULER_YXZ, 30 | DE_EULER_ZXY, 31 | DE_EULER_ZYX 32 | } de_euler_t; 33 | 34 | /** 35 | * Rotation quaternion 36 | */ 37 | struct de_quat_t { 38 | float x; /**< X component */ 39 | float y; /**< Y component */ 40 | float z; /**< Z component */ 41 | float w; /**< W component */ 42 | }; 43 | 44 | /** 45 | * @brief Directly sets quaternion components. 46 | */ 47 | de_quat_t* de_quat_set(de_quat_t* out, float x, float y, float z, float w); 48 | 49 | /** 50 | * @brief Initializes quaternion using axis and angle (in radians) 51 | */ 52 | de_quat_t* de_quat_from_axis_angle(de_quat_t* out, const de_vec3_t* axis, float angle); 53 | 54 | /** 55 | * @brief 56 | */ 57 | float de_quat_dot(const de_quat_t* a, const de_quat_t* b); 58 | 59 | /** 60 | * @brief Returns length of specified quaternion. 61 | */ 62 | float de_quat_len(const de_quat_t* a); 63 | 64 | /** 65 | * @brief Returns square length of specified quaternion. 66 | */ 67 | float de_quat_sqr_len(const de_quat_t* a); 68 | 69 | /** 70 | * @brief Returns angle between quaternions. 71 | */ 72 | float de_quat_angle(const de_quat_t* a, const de_quat_t* b); 73 | 74 | /** 75 | * @brief Performs spherical interpolation between two quaternions 76 | */ 77 | de_quat_t* de_quat_slerp(de_quat_t* out, const de_quat_t* a, const de_quat_t* b, float t); 78 | 79 | /** 80 | * @brief Initializes new quaternion using Euler angles with given order of rotation (XYZ, YXZ, etc) 81 | */ 82 | void de_quat_from_euler(de_quat_t* out, const de_vec3_t* euler_radians, de_euler_t order); 83 | 84 | /** 85 | * @brief Multiplies two quaternions. Allows to combine rotations. 86 | */ 87 | de_quat_t* de_quat_mul(de_quat_t* out, const de_quat_t* a, const de_quat_t* b); 88 | 89 | /** 90 | * @brief Normalizes quaternion. 91 | */ 92 | de_quat_t* de_quat_normalize(de_quat_t* out, de_quat_t* a); 93 | 94 | /** 95 | * @brief Returns main axis of quaternion. 96 | */ 97 | de_vec3_t* de_quat_get_axis(const de_quat_t* q, de_vec3_t* out_axis); 98 | 99 | /** 100 | * @brief 101 | */ 102 | float de_quat_get_angle(const de_quat_t* q); 103 | 104 | /** 105 | * @brief Checks equality of quaternions by per-component equality check. 106 | */ 107 | bool de_quat_equals(const de_quat_t* a, const de_quat_t* b); 108 | 109 | void de_quat_set_at(de_quat_t * quat, float f, unsigned int index); -------------------------------------------------------------------------------- /gui/scroll_bar.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | typedef void(*de_scroll_bar_value_changed_event_t)(de_gui_node_t*, float old_value, float new_value); 23 | 24 | typedef struct de_gui_scroll_bar_descriptor_t { 25 | de_scroll_bar_value_changed_event_t value_changed; 26 | float value; /**< Current scroll value */ 27 | float min; /**< Maximum scroll value */ 28 | float max; /**< Minimum scroll value */ 29 | float step; /**< Increment/decrement step for value. Used when user clicks on arrows */ 30 | de_gui_orientation_t orientation; /**< Orientation: vertical or horizontal */ 31 | } de_gui_scroll_bar_descriptor_t; 32 | 33 | /** 34 | * @brief 35 | */ 36 | typedef struct de_gui_scroll_bar_t { 37 | de_gui_node_t* border; /**< Background of scrollbar */ 38 | de_gui_node_t* grid; /**< Lives on border */ 39 | de_gui_node_t* canvas; /**< Lives on 2nd grid cell */ 40 | de_gui_node_t* indicator; /**< Lives on canvas */ 41 | de_gui_node_t* up_button; /**< Lives on 1st grid cell */ 42 | de_gui_node_t* down_button; /**< Lives on 3rd grid cell */ 43 | de_gui_orientation_t orientation; /**< Orientation: vertical or horizontal */ 44 | float value; /**< Current scroll value */ 45 | float min; /**< Maximum scroll value */ 46 | float max; /**< Minimum scroll value */ 47 | float step; /**< Increment/decrement step for value. Used when user clicks on arrows */ 48 | bool is_dragging; /**< Indicates that indicator is being dragging */ 49 | de_vec2_t offset; /**< Offset from left top corner of indicator to mouse position */ 50 | de_scroll_bar_value_changed_event_t value_changed; 51 | } de_gui_scroll_bar_t; 52 | 53 | struct de_gui_node_dispatch_table_t* de_gui_scroll_bar_get_dispatch_table(void); 54 | 55 | /** 56 | * @brief 57 | * @param node 58 | * @param dir 59 | */ 60 | void de_gui_scroll_bar_set_orientation(de_gui_node_t* node, de_gui_orientation_t dir); 61 | 62 | /** 63 | * @brief 64 | * @param node 65 | * @param min 66 | */ 67 | void de_gui_scroll_bar_set_min_value(de_gui_node_t* node, float min); 68 | 69 | float de_gui_scroll_bar_get_min_value(de_gui_node_t* node); 70 | 71 | float de_gui_scroll_bar_get_max_value(de_gui_node_t* node); 72 | 73 | /** 74 | * @brief 75 | * @param node 76 | * @param max 77 | */ 78 | void de_gui_scroll_bar_set_max_value(de_gui_node_t* node, float max); 79 | 80 | /** 81 | * @brief 82 | * @param node 83 | * @param evt 84 | */ 85 | void de_gui_scroll_bar_set_value_changed(de_gui_node_t* node, de_scroll_bar_value_changed_event_t evt); 86 | 87 | void de_gui_scroll_bar_set_value(de_gui_node_t* node, float value); 88 | 89 | float de_gui_scroll_bar_get_value(de_gui_node_t* node); 90 | 91 | void de_gui_scroll_bar_set_step(de_gui_node_t* node, float value); -------------------------------------------------------------------------------- /sound/context.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | de_sound_context_t* de_sound_context_create(de_core_t* core) 23 | { 24 | de_sound_context_t* ctx = DE_NEW(de_sound_context_t); 25 | de_mtx_init(&ctx->mtx); 26 | ctx->core = core; 27 | ctx->master_volume = 1.0f; 28 | de_listener_init(&ctx->listener); 29 | de_sound_device_init(ctx, &ctx->dev); 30 | return ctx; 31 | } 32 | 33 | void de_sound_context_free(de_sound_context_t* ctx) 34 | { 35 | de_sound_context_clear(ctx); 36 | de_sound_device_free(&ctx->dev); 37 | for (size_t i = 0; i < ctx->sounds.size; ++i) { 38 | de_sound_source_t* src = ctx->sounds.data[i]; 39 | de_log("unfreed sound source found -> mem leaks. details:\n\tsource: %s", 40 | src->buffer ? de_path_cstr(&de_resource_from_sound_buffer(src->buffer)->source) : "not set"); 41 | } 42 | DE_ARRAY_FREE(ctx->sounds); 43 | de_mtx_destroy(&ctx->mtx); 44 | de_free(ctx); 45 | } 46 | 47 | void de_sound_context_clear(de_sound_context_t* ctx) 48 | { 49 | for (int i = (int)ctx->sounds.size - 1; i >= 0; --i) { 50 | de_sound_source_t* src = ctx->sounds.data[i]; 51 | if (src->play_once) { 52 | de_sound_source_free(src); 53 | } 54 | } 55 | } 56 | 57 | void de_sound_context_update(de_sound_context_t* ctx) 58 | { 59 | de_sound_context_lock(ctx); 60 | 61 | for (size_t i = 0; i < ctx->sounds.size; ++i) { 62 | de_sound_source_t* src = ctx->sounds.data[i]; 63 | de_sound_source_update(src); 64 | } 65 | 66 | for (int i = (int)ctx->sounds.size - 1; i >= 0; --i) { 67 | de_sound_source_t* src = ctx->sounds.data[i]; 68 | if (src->play_once && (src->status & DE_SOUND_SOURCE_STATUS_STOPPED)) { 69 | de_sound_source_free(src); 70 | } 71 | } 72 | 73 | for (size_t i = 0; i < ctx->core->resources.size; ++i) { 74 | de_resource_t* res = ctx->core->resources.data[i]; 75 | if (res->type == DE_RESOURCE_TYPE_SOUND_BUFFER) { 76 | de_sound_buffer_t* buf = de_resource_to_sound_buffer(res); 77 | de_sound_buffer_update(buf); 78 | } 79 | } 80 | 81 | de_sound_context_unlock(ctx); 82 | } 83 | 84 | void de_sound_context_lock(de_sound_context_t* ctx) 85 | { 86 | de_mtx_lock(&ctx->mtx); 87 | } 88 | 89 | void de_sound_context_unlock(de_sound_context_t* ctx) 90 | { 91 | de_mtx_unlock(&ctx->mtx); 92 | } 93 | 94 | de_listener_t* de_sound_context_get_listener(de_sound_context_t* ctx) 95 | { 96 | return &ctx->listener; 97 | } 98 | 99 | bool de_sound_context_visit(de_object_visitor_t* visitor, de_sound_context_t* ctx) 100 | { 101 | bool result = true; 102 | result &= DE_OBJECT_VISITOR_VISIT_POINTER_ARRAY(visitor, "Sources", ctx->sounds, de_sound_source_visit); 103 | return result; 104 | } 105 | 106 | void de_sound_context_set_master_volume(de_sound_context_t* ctx, float vol) 107 | { 108 | ctx->master_volume = de_clamp(vol, 0.0f, 1.0f); 109 | } -------------------------------------------------------------------------------- /input/input.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /** 23 | * @brief Keyboard possible keys 24 | */ 25 | enum de_key { 26 | DE_KEY_UKNOWN = -1, 27 | DE_KEY_A = 0, 28 | DE_KEY_B, 29 | DE_KEY_C, 30 | DE_KEY_D, 31 | DE_KEY_E, 32 | DE_KEY_F, 33 | DE_KEY_G, 34 | DE_KEY_H, 35 | DE_KEY_I, 36 | DE_KEY_J, 37 | DE_KEY_K, 38 | DE_KEY_L, 39 | DE_KEY_M, 40 | DE_KEY_N, 41 | DE_KEY_O, 42 | DE_KEY_P, 43 | DE_KEY_Q, 44 | DE_KEY_R, 45 | DE_KEY_S, 46 | DE_KEY_T, 47 | DE_KEY_U, 48 | DE_KEY_V, 49 | DE_KEY_W, 50 | DE_KEY_X, 51 | DE_KEY_Y, 52 | DE_KEY_Z, 53 | DE_KEY_NUM0, 54 | DE_KEY_NUM1, 55 | DE_KEY_NUM2, 56 | DE_KEY_NUM3, 57 | DE_KEY_NUM4, 58 | DE_KEY_NUM5, 59 | DE_KEY_NUM6, 60 | DE_KEY_NUM7, 61 | DE_KEY_NUM8, 62 | DE_KEY_NUM9, 63 | DE_KEY_ESC, 64 | DE_KEY_LCONTROL, 65 | DE_KEY_LSHIFT, 66 | DE_KEY_LAlt, 67 | DE_KEY_LSystem, 68 | DE_KEY_RControl, 69 | DE_KEY_RShift, 70 | DE_KEY_RAlt, 71 | DE_KEY_RSystem, 72 | DE_KEY_Menu, 73 | DE_KEY_LBracket, 74 | DE_KEY_RBracket, 75 | DE_KEY_SemiColon, 76 | DE_KEY_Comma, 77 | DE_KEY_Period, 78 | DE_KEY_Quote, 79 | DE_KEY_Slash, 80 | DE_KEY_BackSlash, 81 | DE_KEY_Tilde, 82 | DE_KEY_Equal, 83 | DE_KEY_Dash, 84 | DE_KEY_Space, 85 | DE_KEY_Return, 86 | DE_KEY_BACKSPACE, 87 | DE_KEY_Tab, 88 | DE_KEY_PageUp, 89 | DE_KEY_PageDown, 90 | DE_KEY_End, 91 | DE_KEY_Home, 92 | DE_KEY_Insert, 93 | DE_KEY_DELETE, 94 | DE_KEY_Add, 95 | DE_KEY_Subtract, 96 | DE_KEY_Multiply, 97 | DE_KEY_Divide, 98 | DE_KEY_LEFT, 99 | DE_KEY_RIGHT, 100 | DE_KEY_UP, 101 | DE_KEY_DOWN, 102 | DE_KEY_NUMPAD0, /**< Numpad 0 key */ 103 | DE_KEY_NUMPAD1, /**< Numpad 1 key */ 104 | DE_KEY_NUMPAD2, /**< Numpad 2 key */ 105 | DE_KEY_NUMPAD3, /**< Numpad 3 key */ 106 | DE_KEY_NUMPAD4, /**< Numpad 4 key */ 107 | DE_KEY_NUMPAD5, /**< Numpad 5 key */ 108 | DE_KEY_NUMPAD6, /**< Numpad 6 key */ 109 | DE_KEY_NUMPAD7, /**< Numpad 7 key */ 110 | DE_KEY_NUMPAD8, /**< Numpad 8 key */ 111 | DE_KEY_NUMPAD9, /**< Numpad 9 key */ 112 | DE_KEY_F1, /**< F1 key */ 113 | DE_KEY_F2, /**< F2 key */ 114 | DE_KEY_F3, /**< F3 key */ 115 | DE_KEY_F4, /**< F4 key */ 116 | DE_KEY_F5, /**< F5 key */ 117 | DE_KEY_F6, /**< F6 key */ 118 | DE_KEY_F7, /**< F7 key */ 119 | DE_KEY_F8, /**< F8 key */ 120 | DE_KEY_F9, /**< F9 key */ 121 | DE_KEY_F10, /**< F10 key */ 122 | DE_KEY_F11, /**< F11 key */ 123 | DE_KEY_F12, /**< F12 key */ 124 | DE_KEY_F13, /**< F13 key */ 125 | DE_KEY_F14, /**< F14 key */ 126 | DE_KEY_F15, /**< F15 key */ 127 | DE_KEY_Pause /**< Pause\break key */ 128 | }; 129 | 130 | /** 131 | * @brief Possible mouse buttons codes 132 | */ 133 | enum de_mouse_button { 134 | DE_BUTTON_LEFT, /**< Left mouse button */ 135 | DE_BUTTON_RIGHT, /**< Right mouse button */ 136 | DE_BUTTON_MIDDLE /**< Middle (wheel) mouse button */ 137 | }; 138 | -------------------------------------------------------------------------------- /scene/light.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | static void de_light_init(de_node_t* node) 23 | { 24 | de_light_t* light = de_node_to_light(node); 25 | de_color_set(&light->color, 255, 255, 255, 255); 26 | light->radius = 2.0f; 27 | light->type = DE_LIGHT_TYPE_POINT; 28 | light->cone_angle = (float)M_PI; 29 | light->cone_angle_cos = -1.0f; 30 | light->cast_shadows = true; 31 | } 32 | 33 | void de_light_set_cast_shadows(de_light_t* light, bool value) 34 | { 35 | DE_ASSERT(light); 36 | light->cast_shadows = value; 37 | } 38 | 39 | bool de_light_get_cast_shadows(const de_light_t* light) 40 | { 41 | DE_ASSERT(light); 42 | return light->cast_shadows; 43 | } 44 | 45 | static void de_light_copy(de_node_t* src_node, de_node_t* dest_node) 46 | { 47 | de_light_t* src = de_node_to_light(src_node); 48 | de_light_t* dest = de_node_to_light(dest_node); 49 | dest->color = src->color; 50 | dest->cone_angle = src->cone_angle; 51 | dest->cone_angle_cos = src->cone_angle_cos; 52 | dest->radius = src->radius; 53 | dest->type = src->type; 54 | dest->cast_shadows = src->cast_shadows; 55 | } 56 | 57 | static bool de_light_visit(de_object_visitor_t* visitor, de_node_t* node) 58 | { 59 | de_light_t* light = de_node_to_light(node); 60 | bool result = true; 61 | result &= DE_OBJECT_VISITOR_VISIT_ENUM(visitor, "Type", &light->type); 62 | result &= de_object_visitor_visit_color(visitor, "Color", &light->color); 63 | result &= de_object_visitor_visit_float(visitor, "ConeAngle", &light->cone_angle); 64 | result &= de_object_visitor_visit_float(visitor, "CosConeAngle", &light->cone_angle_cos); 65 | result &= de_object_visitor_visit_float(visitor, "Radius", &light->radius); 66 | result &= de_object_visitor_visit_bool(visitor, "CastShadows", &light->cast_shadows); 67 | return result; 68 | } 69 | 70 | struct de_node_dispatch_table_t* de_light_get_dispatch_table(void) 71 | { 72 | static de_node_dispatch_table_t tbl = { 73 | .init = de_light_init, 74 | .copy = de_light_copy, 75 | .visit = de_light_visit, 76 | }; 77 | return &tbl; 78 | } 79 | 80 | void de_light_set_radius(de_light_t* light, float radius) 81 | { 82 | DE_ASSERT(light); 83 | light->radius = de_maxf(FLT_EPSILON, radius); 84 | } 85 | 86 | float de_light_get_radius(const de_light_t* light) 87 | { 88 | DE_ASSERT(light); 89 | return light->radius; 90 | } 91 | 92 | void de_light_set_cone_angle(de_light_t* light, float angle) 93 | { 94 | DE_ASSERT(light); 95 | light->cone_angle = angle; 96 | light->cone_angle_cos = (float)cos(angle); 97 | } 98 | 99 | float de_light_get_cone_angle(const de_light_t* light) 100 | { 101 | DE_ASSERT(light); 102 | return light->cone_angle; 103 | } 104 | 105 | void de_light_set_color(de_light_t* light, const de_color_t* color) 106 | { 107 | DE_ASSERT(light); 108 | DE_ASSERT(color); 109 | light->color = *color; 110 | } 111 | 112 | void de_light_get_color(const de_light_t* light, de_color_t* color) 113 | { 114 | DE_ASSERT(light); 115 | DE_ASSERT(color); 116 | *color = light->color; 117 | } -------------------------------------------------------------------------------- /resources/model.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | static void de_model_deinit(de_resource_t* res) 23 | { 24 | de_model_t* mdl = de_resource_to_model(res); 25 | /* reset pointer to resource here, so scene will not try to release 26 | * a resource which have ownership of this scene */ 27 | DE_LINKED_LIST_FOR_EACH_T(de_node_t*, node, mdl->scene->nodes) 28 | { 29 | node->model_resource = NULL; 30 | } 31 | de_scene_free(mdl->scene); 32 | } 33 | 34 | static void de_model_set_node_resource(de_node_t* node, de_resource_t* res) 35 | { 36 | DE_ASSERT(node); 37 | DE_ASSERT(res); 38 | /* assign resource, but do *NOT* increase reference count because these 39 | * nodes are ALREADY in resource and resource have ownership */ 40 | node->model_resource = res; 41 | for (size_t i = 0; i < node->children.size; ++i) { 42 | de_model_set_node_resource(node->children.data[i], res); 43 | } 44 | } 45 | 46 | static bool de_model_load(de_resource_t* res) 47 | { 48 | de_model_t* mdl = de_resource_to_model(res); 49 | de_core_t* core = res->core; 50 | mdl->scene = de_scene_create(core); 51 | DE_LINKED_LIST_REMOVE(core->scenes, mdl->scene); 52 | mdl->root = de_fbx_load_to_scene(mdl->scene, de_path_cstr(&res->source)); 53 | if (mdl->root) { 54 | de_model_set_node_resource(mdl->root, res); 55 | DE_LINKED_LIST_FOR_EACH_T(de_animation_t*, anim, mdl->scene->animations) 56 | { 57 | anim->resource = res; 58 | } 59 | } else { 60 | de_log("failed to load model %s", de_path_cstr(&res->source)); 61 | } 62 | return mdl->root != NULL; 63 | } 64 | 65 | static bool de_model_visit(de_object_visitor_t* visitor, de_resource_t* res) 66 | { 67 | DE_ASSERT(visitor); 68 | DE_ASSERT(res); 69 | bool result = true; 70 | /* todo: visit dynamic models here */ 71 | return result; 72 | } 73 | 74 | de_resource_dispatch_table_t* de_model_get_dispatch_table(void) 75 | { 76 | static de_resource_dispatch_table_t table = { 77 | .deinit = de_model_deinit, 78 | .visit = de_model_visit, 79 | .load = de_model_load 80 | }; 81 | return &table; 82 | } 83 | 84 | 85 | 86 | 87 | 88 | 89 | de_node_t* de_model_instantiate(de_model_t* mdl, de_scene_t* dest_scene) 90 | { 91 | DE_ASSERT(mdl); 92 | DE_ASSERT(dest_scene); 93 | 94 | if (!mdl->root) { 95 | return NULL; 96 | } 97 | 98 | /* Instantiate nodes. */ 99 | de_node_t* copy = de_node_copy(dest_scene, mdl->root); 100 | 101 | /* Instantiate animations. */ 102 | DE_LINKED_LIST_FOR_EACH_T(de_animation_t*, ref_anim, mdl->scene->animations) 103 | { 104 | de_animation_t* anim_copy = de_animation_copy(ref_anim, dest_scene); 105 | 106 | /* Remap animation track nodes. */ 107 | for (size_t i = 0; i < ref_anim->tracks.size; ++i) { 108 | de_animation_track_t* ref_track = ref_anim->tracks.data[i]; 109 | 110 | /* Find instantiated node that corresponds to node in resource */ 111 | DE_LINKED_LIST_FOR_EACH_T(de_node_t*, node, dest_scene->nodes) 112 | { 113 | if (ref_track->node && node->original == ref_track->node) { 114 | anim_copy->tracks.data[i]->node = node; 115 | } 116 | } 117 | } 118 | } 119 | 120 | return copy; 121 | } -------------------------------------------------------------------------------- /core/utf32string.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /* UTF32 string 23 | * 24 | * WARNING: Unlike de_str8_t does NOT contain null-terminator! */ 25 | 26 | /* Wrap-struct to prevent using string with DE_ARRAY_XXX functions 27 | * which can lead to undefined behaviour */ 28 | typedef struct de_str32_t { 29 | DE_ARRAY_DECLARE(uint32_t, str); 30 | } de_str32_t; 31 | 32 | /** 33 | * @brief Prepares string. 34 | */ 35 | void de_str32_init(de_str32_t* str); 36 | 37 | /** 38 | * @brief Frees memory. Must be called for every string! 39 | */ 40 | void de_str32_free(de_str32_t* str); 41 | 42 | /** 43 | * @brief Moves source string to destination. @src will be empty array after. 44 | * 45 | * Notes: Automatically frees memory from @dest if such was allocated. 46 | */ 47 | void de_str32_move(de_str32_t* src, de_str32_t* dest); 48 | 49 | /** 50 | * @brief Inserts single character into @pos 51 | * 52 | * Performs out-of-bounds checks! @pos will be clamped to [0; size] 53 | */ 54 | void de_str32_insert(de_str32_t* str, int pos, uint32_t unicode); 55 | 56 | /** 57 | * @brief Appends single character to the end of the string. 58 | */ 59 | void de_str32_append(de_str32_t* str, uint32_t unicode); 60 | 61 | /** 62 | * @brief Remove @amount of characters from string starting from @pos 63 | * 64 | * Performs out-of-bounds checks, remove range will be clamped to [0; size]. 65 | */ 66 | void de_str32_remove(de_str32_t* str, int pos, int amount); 67 | 68 | /** 69 | * @brief Sets size of string to zero. Does not reallocates memory! 70 | */ 71 | void de_str32_clear(de_str32_t* str); 72 | 73 | /** 74 | * @brief Returns total count of characters in string. Unlike strlen this method is O(1). 75 | */ 76 | size_t de_str32_length(de_str32_t* str); 77 | 78 | /** 79 | * @brief Returns pointer to immutable string data. 80 | * 81 | * WARNING: DO NOT modify internals of string using returned pointer! 82 | */ 83 | const uint32_t* de_str32_get_data(const de_str32_t* str); 84 | 85 | /** 86 | * @brief Returns single character from string. 87 | * 88 | * WARNING: There is no out-of-bound checks! 89 | */ 90 | uint32_t de_str32_at(const de_str32_t* str, size_t i); 91 | 92 | /** 93 | * @brief Sets string. 94 | */ 95 | void de_str32_set_utf8(de_str32_t* str, const de_str8_view_t* view); 96 | 97 | /** 98 | * @brief Appends UTF8 string view. 99 | */ 100 | void de_str32_append_utf8(de_str32_t* str, const de_str8_view_t* view); 101 | 102 | /** 103 | * @brief Appends null-terminated string as UTF8 string. 104 | */ 105 | void de_str32_append_cstr(de_str32_t* str, const char* cstr); 106 | 107 | /** 108 | * @brief Inserts UTF-8 string at @pos by converting it to UTF-32. 109 | */ 110 | 111 | #if 0 112 | void de_str32_insert_utf8(de_str32_t* str, const de_str8_view_t* view) 113 | { 114 | size_t old_size, decoded; 115 | int reserved_size = view->len * 4; 116 | old_size = str->str.size; 117 | DE_ARRAY_GROW(str->str, reserved_size); 118 | memmove(str->str.data + old_size + reserved_size, str->str.data + old_size, old_size - ) 119 | decoded = (size_t)de_utf8_to_utf32(view->data, view->len, str->str.data + old_size, reserved_size); 120 | str->str.size = old_size + decoded; 121 | } 122 | #endif -------------------------------------------------------------------------------- /core/linked_list.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2019 Dmitry Stepanov a.k.a mr.DIMAS 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | /********************************************/ 23 | 24 | #define DE_LINKED_LIST_DECLARE(type, name) \ 25 | struct { \ 26 | type* head; \ 27 | type* tail; \ 28 | } name 29 | 30 | /********************************************/ 31 | 32 | #define DE_LINKED_LIST_INIT(list) \ 33 | memset(&list, 0, sizeof(list)) 34 | 35 | /********************************************/ 36 | 37 | #define DE_LINKED_LIST_ITEM(type) \ 38 | type* prev; \ 39 | type* next 40 | 41 | /********************************************/ 42 | 43 | #define DE_LINKED_LIST_APPEND(list, i) \ 44 | do { \ 45 | if(!list.head) { \ 46 | list.head = i; \ 47 | } \ 48 | if(list.tail) { \ 49 | i->prev = list.tail; \ 50 | list.tail->next = i; \ 51 | } \ 52 | list.tail = i; \ 53 | } while (0) 54 | 55 | /********************************************/ 56 | 57 | #define DE_LINKED_LIST_REMOVE(list, i) \ 58 | do { \ 59 | if(!i) { \ 60 | break; \ 61 | } \ 62 | if(i->next) { \ 63 | i->next->prev = i->prev; \ 64 | } \ 65 | if(i->prev) { \ 66 | i->prev->next = i->next; \ 67 | } \ 68 | if(list.head) { \ 69 | if(i == list.head) { \ 70 | list.head = i->next; \ 71 | } \ 72 | } \ 73 | if(list.tail) { \ 74 | if(i == list.tail) { \ 75 | list.tail = i->prev; \ 76 | } \ 77 | } \ 78 | } while (0) 79 | 80 | /********************************************/ 81 | 82 | #define DE_LINKED_LIST_GET_AT(list, n, i) \ 83 | do { \ 84 | i = NULL; \ 85 | int _counter = 0; \ 86 | void* head = list.head; \ 87 | while(list.head) { \ 88 | if(_counter == n) { \ 89 | i = list.head; \ 90 | } \ 91 | list.head = list.head->next; \ 92 | ++_counter; \ 93 | } \ 94 | list.head = head; \ 95 | } while(0) 96 | 97 | /********************************************/ 98 | 99 | #define DE_LINKED_LIST_REMOVE_AT(list, n) \ 100 | do { \ 101 | void* item; \ 102 | DE_LINKED_LIST_GET_AT(list, n, item) \ 103 | DE_LINKED_LIST_REMOVE(list, item) \ 104 | } while(0) 105 | 106 | /********************************************/ 107 | 108 | #define DE_LINKED_LIST_FOR_EACH(list, i) \ 109 | for(i = (list).head; i; i = i->next) 110 | 111 | /********************************************/ 112 | 113 | #define DE_LINKED_LIST_FOR_EACH_T(t, n, list)\ 114 | for(t n = (list).head; n; n = n->next) 115 | 116 | /********************************************/ 117 | 118 | #define DE_LINKED_LIST_FOR_EACH_H(t, n, h)\ 119 | for(t n = h; n; n = n->next) 120 | 121 | /********************************************/ 122 | 123 | #define DE_LINKED_LIST_FOR_EACH_REV(list, i) \ 124 | for(i = (list).tail; i; i = i->prev) 125 | 126 | /********************************************/ 127 | 128 | #define DE_LINKED_LIST_MAKE_CIRCULAR(list) \ 129 | (list).head->prev = (list).tail; \ 130 | (list).tail->next = (list).head; 131 | --------------------------------------------------------------------------------