From 6ee36e26be652450837773089842f8435840715a Mon Sep 17 00:00:00 2001 From: kaj dijkstra Date: Mon, 17 Nov 2025 10:28:09 +0100 Subject: [PATCH] Initial commit --- Libraries | 24 + Readme.md | 788 + application/demos/example.console.log/array.c | 231 + application/demos/example.console.log/array.h | 71 + application/demos/example.console.log/char.c | 169 + application/demos/example.console.log/char.h | 56 + .../example.console.log/classConfiguration.c | 394 + .../example.console.log/classConfiguration.h | 61 + .../demos/example.console.log/console.c | 269 + .../demos/example.console.log/console.h | 66 + .../examples/example.console.log.c | 76 + .../examples/example.console.log.h | 30 + .../demos/example.console.log/street.c | 30 + .../demos/example.console.log/street.h | 39 + application/demos/example.console.log/text.c | 205 + application/demos/example.console.log/text.h | 75 + application/demos/example.console.log/user.c | 47 + application/demos/example.console.log/user.h | 47 + .../demos/example.console.log/vector2.c | 88 + .../demos/example.console.log/vector2.h | 49 + application/demos/example.opengl/array.c | 231 + application/demos/example.opengl/array.h | 71 + application/demos/example.opengl/cache.c | 93 + application/demos/example.opengl/cache.h | 49 + application/demos/example.opengl/char.c | 169 + application/demos/example.opengl/char.h | 56 + .../demos/example.opengl/classConfiguration.c | 1530 ++ .../demos/example.opengl/classConfiguration.h | 133 + application/demos/example.opengl/console.c | 269 + application/demos/example.opengl/console.h | 66 + .../demos/example.opengl/engine/block.c | 583 + .../demos/example.opengl/engine/block.h | 96 + .../demos/example.opengl/engine/element.c | 366 + .../demos/example.opengl/engine/element.h | 107 + .../demos/example.opengl/engine/event.c | 87 + .../demos/example.opengl/engine/event.h | 110 + .../example.opengl/engine/eventManager.c | 309 + .../example.opengl/engine/eventManager.h | 70 + .../demos/example.opengl/engine/floatArray.c | 193 + .../demos/example.opengl/engine/floatArray.h | 71 + .../example.opengl/engine/fontRenderer.c | 194 + .../example.opengl/engine/fontRenderer.h | 60 + .../demos/example.opengl/engine/hints.c | 23 + .../demos/example.opengl/engine/hints.h | 43 + .../demos/example.opengl/engine/member.c | 23 + .../demos/example.opengl/engine/member.h | 56 + .../demos/example.opengl/engine/mesh.c | 724 + .../demos/example.opengl/engine/mesh.h | 98 + .../demos/example.opengl/engine/opengl.c | 369 + .../demos/example.opengl/engine/opengl.h | 142 + .../demos/example.opengl/engine/pipeline.c | 113 + .../demos/example.opengl/engine/pipeline.h | 55 + .../demos/example.opengl/engine/program.c | 568 + .../demos/example.opengl/engine/program.h | 100 + .../demos/example.opengl/engine/quadMesh.c | 23 + .../demos/example.opengl/engine/quadMesh.h | 55 + .../engine/renderPasses/renderPass.c | 46 + .../engine/renderPasses/renderPass.h | 47 + .../engine/renderPasses/renderPassCompute.c | 115 + .../engine/renderPasses/renderPassCompute.h | 63 + .../engine/renderPasses/renderPassCompute2.c | 99 + .../engine/renderPasses/renderPassCompute2.h | 59 + .../engine/renderPasses/renderPassFont.c | 193 + .../engine/renderPasses/renderPassFont.h | 63 + .../engine/renderPasses/renderPassQuads.c | 731 + .../engine/renderPasses/renderPassQuads.h | 95 + .../renderPasses/renderPassTesselation.c | 137 + .../renderPasses/renderPassTesselation.h | 63 + .../example.opengl/engine/resourceManager.c | 127 + .../example.opengl/engine/resourceManager.h | 43 + .../demos/example.opengl/engine/sampler2D.c | 293 + .../demos/example.opengl/engine/sampler2D.h | 96 + .../demos/example.opengl/engine/shader.c | 125 + .../demos/example.opengl/engine/shader.h | 87 + .../demos/example.opengl/engine/texture2D.c | 23 + .../demos/example.opengl/engine/texture2D.h | 54 + .../demos/example.opengl/engine/uniform.c | 23 + .../demos/example.opengl/engine/uniform.h | 54 + .../engine/unsignedIntegerArray.c | 182 + .../engine/unsignedIntegerArray.h | 65 + .../demos/example.opengl/engine/vector.c | 997 ++ .../demos/example.opengl/engine/vector.h | 217 + .../demos/example.opengl/engine/vector4.c | 75 + .../demos/example.opengl/engine/vector4.h | 49 + .../example.opengl/engine/windowManager.c | 179 + .../example.opengl/engine/windowManager.h | 64 + .../example.opengl/examples/example.opengl.c | 13 + .../example.opengl/examples/example.opengl.h | 22 + application/demos/example.opengl/file.c | 23 + application/demos/example.opengl/file.h | 39 + application/demos/example.opengl/fileSystem.c | 279 + application/demos/example.opengl/fileSystem.h | 73 + application/demos/example.opengl/header.c | 23 + application/demos/example.opengl/header.h | 37 + application/demos/example.opengl/headers.c | 186 + application/demos/example.opengl/headers.h | 53 + application/demos/example.opengl/http.c | 546 + application/demos/example.opengl/http.h | 97 + application/demos/example.opengl/int.c | 21 + application/demos/example.opengl/int.h | 24 + application/demos/example.opengl/mimeTypes.c | 93 + application/demos/example.opengl/mimeTypes.h | 45 + application/demos/example.opengl/request.c | 112 + application/demos/example.opengl/request.h | 62 + application/demos/example.opengl/text.c | 205 + application/demos/example.opengl/text.h | 75 + application/demos/example.opengl/vector2.c | 88 + application/demos/example.opengl/vector2.h | 49 + application/demos/example.opengl/vector3.c | 72 + application/demos/example.opengl/vector3.h | 47 + application/opengl.c | 233 + application/source/application.c | 845 + application/source/array.c | 205 + application/source/arrayText.c | 178 + application/source/assets/test | 1 + application/source/cache.c | 75 + application/source/callbacks.c | 60 + application/source/char.c | 171 + application/source/console.c | 264 + application/source/define.c | 3 + .../source/engine/arrayUnsignedInteger.c | 138 + application/source/engine/block.c | 560 + application/source/engine/element.c | 302 + application/source/engine/event.c | 100 + application/source/engine/eventManager.c | 290 + application/source/engine/floatArray.c | 167 + application/source/engine/fontRenderer.c | 176 + application/source/engine/hints.c | 11 + application/source/engine/member.c | 28 + application/source/engine/mesh.c | 703 + application/source/engine/opengl.c | 338 + application/source/engine/pipeline.c | 82 + application/source/engine/program.c | 534 + application/source/engine/quadMesh.c | 40 + .../source/engine/renderPasses/renderPass.c | 27 + .../engine/renderPasses/renderPassCompute.c | 96 + .../engine/renderPasses/renderPassCompute2.c | 80 + .../engine/renderPasses/renderPassFont.c | 174 + .../engine/renderPasses/renderPassQuads.c | 700 + .../renderPasses/renderPassTesselation.c | 118 + application/source/engine/resourceManager.c | 112 + application/source/engine/sampler2D.c | 208 + application/source/engine/shader.c | 90 + application/source/engine/texture2D.c | 26 + application/source/engine/uniform.c | 27 + application/source/engine/uniformBlock.c | 167 + .../source/engine/unsignedIntegerArray.c | 156 + application/source/engine/vector.c | 213 + application/source/engine/vector4.c | 56 + application/source/engine/windowManager.c | 164 + .../source/examples/example.console.log.c | 75 + .../source/examples/example.file.system.c | 57 + .../examples/example.multiple.inheritance.c | 38 + application/source/examples/example.opengl.c | 12 + .../examples/example.operator.overload.c | 166 + application/source/examples/example.sqlite3.c | 154 + application/source/examples/example.text.c | 78 + application/source/examples/example.vector.c | 138 + application/source/examples/example.vulkan.c | 18 + .../source/examples/example.web.server.c | 70 + application/source/extends.c | 87 + application/source/file.c | 10 + application/source/fileSystem.c | 264 + application/source/header.c | 8 + application/source/headers.c | 167 + application/source/http.c | 507 + application/source/http.c.old | 504 + application/source/int.c | 22 + application/source/integerArray.c | 167 + application/source/mimeTypes.c | 66 + application/source/reflection.c | 13 + application/source/request.c | 61 + application/source/sqlite.c | 817 + application/source/street.c | 16 + application/source/text.c | 178 + application/source/toolset.c | 28 + application/source/triangle.c | 18 + application/source/user.c | 24 + application/source/vector2.c | 72 + application/source/vector3.c | 53 + application/sqlite.c | 818 + application/target/application.c | 713 + application/target/application.h | 69 + application/target/array.c | 202 + application/target/array.h | 61 + application/target/char.c | 156 + application/target/char.h | 54 + application/target/classConfiguration.c | 480 + application/target/classConfiguration.h | 86 + application/target/console.c | 273 + application/target/console.h | 60 + application/target/define.c | 7 + application/target/define.h | 20 + application/target/extends.c | 222 + application/target/extends.h | 107 + application/target/fileSystem.c | 263 + application/target/fileSystem.h | 67 + application/target/floatArray.c | 197 + application/target/floatArray.h | 67 + application/target/header.c | 27 + application/target/header.h | 33 + application/target/headers.c | 190 + application/target/headers.h | 49 + application/target/http.c | 547 + application/target/http.h | 91 + application/target/int.c | 21 + application/target/int.h | 24 + application/target/mesh.c | 365 + application/target/mesh.h | 66 + application/target/mimeTypes.c | 97 + application/target/mimeTypes.h | 41 + application/target/opengl.c | 697 + application/target/opengl.h | 124 + application/target/request.c | 116 + application/target/request.h | 58 + application/target/shader.c | 344 + application/target/shader.h | 92 + application/target/sqlite.c | 840 + application/target/sqlite.h | 73 + application/target/street.c | 34 + application/target/street.h | 35 + application/target/text.c | 209 + application/target/text.h | 71 + application/target/toolset.c | 47 + application/target/toolset.h | 37 + application/target/triangle.c | 49 + application/target/triangle.h | 39 + application/target/unsignedIntegerArray.c | 197 + application/target/unsignedIntegerArray.h | 67 + application/target/user.c | 51 + application/target/user.h | 43 + application/target/vector2.c | 106 + application/target/vector2.h | 57 + application/target/vector3.c | 76 + application/target/vector3.h | 45 + binaries/1.png | Bin 0 -> 2601 bytes binaries/10.png | Bin 0 -> 340426 bytes binaries/2.png | Bin 0 -> 2907 bytes binaries/3.png | Bin 0 -> 3262 bytes binaries/4.png | Bin 0 -> 3445 bytes binaries/5.png | Bin 0 -> 4047 bytes binaries/6.png | Bin 0 -> 4547 bytes binaries/7.png | Bin 0 -> 5771 bytes binaries/8.png | Bin 0 -> 8310 bytes binaries/9.png | Bin 0 -> 11304 bytes binaries/android.png | Bin 0 -> 104053 bytes binaries/application.dump | 14567 +++++++++++++++ .../fonts/WorkSans/WorkSans-Regular.ttf | Bin 0 -> 188920 bytes binaries/assets/shaders/addition.comp | 38 + binaries/assets/shaders/addition2.comp | 29 + binaries/assets/shaders/color.fragment | 21 + binaries/assets/shaders/color.vertex | 84 + binaries/assets/shaders/multiQuad.fragment | 90 + binaries/assets/shaders/multiQuad.vertex | 164 + binaries/assets/shaders/quad.fragment | 101 + binaries/assets/shaders/quad.vertex | 64 + binaries/assets/shaders/quadScale.vertex | 64 + .../shaders/tesselation.geometry.shader | 17 + .../shaders/tesselation.triangle.shader | 10 + .../shaders/tesselation.triangle.tsc.shader | 14 + binaries/assets/test | 1 + binaries/assets/testFile | 1 + binaries/database/users.sqlite | Bin 0 -> 8192 bytes binaries/example.console.log | Bin 0 -> 21792 bytes binaries/example.sqlite3 | Bin 0 -> 2044416 bytes binaries/preprocessor | Bin 0 -> 119608 bytes binaries/show_includes.sh | 9 + binaries/www/assets/css/main.css | 899 + .../assets/fonts/workSans/WorkSans-Black.ttf | Bin 0 -> 192180 bytes .../fonts/workSans/WorkSans-BlackItalic.ttf | Bin 0 -> 176956 bytes .../assets/fonts/workSans/WorkSans-Bold.ttf | Bin 0 -> 191308 bytes .../fonts/workSans/WorkSans-BoldItalic.ttf | Bin 0 -> 175776 bytes .../fonts/workSans/WorkSans-ExtraBold.ttf | Bin 0 -> 192652 bytes .../workSans/WorkSans-ExtraBoldItalic.ttf | Bin 0 -> 177164 bytes .../fonts/workSans/WorkSans-ExtraLight.ttf | Bin 0 -> 188592 bytes .../workSans/WorkSans-ExtraLightItalic.ttf | Bin 0 -> 174540 bytes .../WorkSans-Italic-VariableFont_wght.ttf | Bin 0 -> 337492 bytes .../assets/fonts/workSans/WorkSans-Italic.ttf | Bin 0 -> 174284 bytes .../assets/fonts/workSans/WorkSans-Light.ttf | Bin 0 -> 188940 bytes .../fonts/workSans/WorkSans-LightItalic.ttf | Bin 0 -> 174420 bytes .../assets/fonts/workSans/WorkSans-Medium.ttf | Bin 0 -> 189560 bytes .../fonts/workSans/WorkSans-MediumItalic.ttf | Bin 0 -> 175048 bytes .../fonts/workSans/WorkSans-Regular.ttf | Bin 0 -> 188920 bytes .../fonts/workSans/WorkSans-SemiBold.ttf | Bin 0 -> 191020 bytes .../workSans/WorkSans-SemiBoldItalic.ttf | Bin 0 -> 175508 bytes .../assets/fonts/workSans/WorkSans-Thin.ttf | Bin 0 -> 188072 bytes .../fonts/workSans/WorkSans-ThinItalic.ttf | Bin 0 -> 174228 bytes .../workSans/WorkSans-VariableFont_wght.ttf | Bin 0 -> 362304 bytes binaries/www/assets/images/api.png | Bin 0 -> 16246 bytes binaries/www/assets/images/c.png | Bin 0 -> 37251 bytes binaries/www/assets/images/code.png | Bin 0 -> 831 bytes binaries/www/assets/images/sqlite3.svg | 2 + binaries/www/assets/images/webGPU.png | Bin 0 -> 33475 bytes binaries/www/assets/js/main.js | 154 + binaries/www/index.html | 347 + .../Tesselation_Tutorial/Tesselation.sln | 25 + .../Tesselation_Tutorial/Tesselation.suo | Bin 0 -> 59392 bytes .../Tesselation_Tutorial/bin32/glut32.dll | Bin 0 -> 237568 bytes .../bin64/Tesselation.exe | Bin 0 -> 293888 bytes .../Tesselation_Tutorial/bin64/glut32.dll | Bin 0 -> 320000 bytes documents/Tesselation_Tutorial/ext/GL/glext.h | 6495 +++++++ .../Tesselation_Tutorial/ext/GL/glut.def | 126 + documents/Tesselation_Tutorial/ext/GL/glut.h | 787 + .../Tesselation_Tutorial/ext/GL/glxext.h | 610 + .../Tesselation_Tutorial/ext/GL/wglext.h | 631 + documents/Tesselation_Tutorial/ext/glew.cpp | 14599 +++++++++++++++ documents/Tesselation_Tutorial/ext/glew.h | 14703 ++++++++++++++++ documents/Tesselation_Tutorial/ext/glsl.cpp | 906 + documents/Tesselation_Tutorial/ext/glsl.h | 186 + documents/Tesselation_Tutorial/ext/glxew.h | 1510 ++ documents/Tesselation_Tutorial/ext/wglew.h | 1260 ++ .../Tesselation_Tutorial/lib32/glut32.lib | Bin 0 -> 28704 bytes .../Tesselation_Tutorial/lib64/glut32.lib | Bin 0 -> 27492 bytes .../Tesselation_Tutorial/shader/tess_frag.txt | 10 + .../Tesselation_Tutorial/shader/tess_geo.txt | 19 + .../shader/tess_quad_tcs.txt | 16 + .../shader/tess_quad_tes.txt | 20 + .../shader/tess_tri_tcs.txt | 14 + .../shader/tess_tri_tes.txt | 10 + .../Tesselation_Tutorial/shader/tess_vs.txt | 15 + documents/Tesselation_Tutorial/src/Main.cpp | 121 + .../src/Tesselation.vcproj | 404 + .../src/Tesselation.vcxproj | 205 + .../src/Tesselation.vcxproj.filters | 59 + .../src/Tesselation.vcxproj.user | 7 + documents/Tesselation_Tutorial/src/glsl.h | 122 + documents/preprocess.md | 0 documents/program.dump | 0 freetype.c | 156 + scripts/all.sh | 8 + scripts/application.dump | 0 scripts/classes.dump | 0 scripts/compileAndRunApplication.sh | 7 + scripts/compileAndRunPreprocessor.sh | 9 + scripts/compileApplication.sh | 70 + scripts/compilePreprocessor.sh | 10 + scripts/disassemble.sh | 2 + scripts/menu | Bin 0 -> 82720 bytes scripts/menu.c | 114 + scripts/runApplication.sh | 31 + scripts/runPreprocessor.sh | 29 + scripts/runServer.sh | 10 + source/application.c | 115 + source/application.h | 39 + source/argument.c | 88 + source/argument.h | 27 + source/array.c | 184 + source/array.h | 40 + source/class.c | 916 + source/class.h | 99 + source/codeBundle.c | 2 + source/codeBundle.h | 14 + source/configuration.c | 180 + source/configuration.h | 33 + source/console.c | 16 + source/console.h | 24 + source/file.c | 3416 ++++ source/file.h | 165 + source/fileManager.c | 430 + source/fileManager.h | 65 + source/fileSystem.c | 209 + source/fileSystem.h | 43 + source/function.c | 112 + source/function.h | 52 + source/include.c | 12 + source/include.h | 28 + source/index.c | 83 + source/index.h | 85 + source/lexer.c | 593 + source/lexer.h | 79 + source/macro.c | 3 + source/macro.h | 17 + source/method.c | 2570 +++ source/method.h | 140 + source/property.c | 107 + source/property.h | 44 + source/replacement.c | 49 + source/replacement.h | 24 + source/template.c | 140 + source/template.h | 48 + source/templateInstance.c | 12 + source/templateInstance.h | 23 + source/templateInstanceProperty.c | 3 + source/templateInstanceProperty.h | 19 + source/text.c | 1761 ++ source/text.h | 133 + source/tools.c | 88 + source/tools.h | 24 + source/variable.c | 220 + source/variable.h | 42 + todo | 1 + 391 files changed, 110253 insertions(+) create mode 100644 Libraries create mode 100644 Readme.md create mode 100644 application/demos/example.console.log/array.c create mode 100644 application/demos/example.console.log/array.h create mode 100644 application/demos/example.console.log/char.c create mode 100644 application/demos/example.console.log/char.h create mode 100644 application/demos/example.console.log/classConfiguration.c create mode 100644 application/demos/example.console.log/classConfiguration.h create mode 100644 application/demos/example.console.log/console.c create mode 100644 application/demos/example.console.log/console.h create mode 100644 application/demos/example.console.log/examples/example.console.log.c create mode 100644 application/demos/example.console.log/examples/example.console.log.h create mode 100644 application/demos/example.console.log/street.c create mode 100644 application/demos/example.console.log/street.h create mode 100644 application/demos/example.console.log/text.c create mode 100644 application/demos/example.console.log/text.h create mode 100644 application/demos/example.console.log/user.c create mode 100644 application/demos/example.console.log/user.h create mode 100644 application/demos/example.console.log/vector2.c create mode 100644 application/demos/example.console.log/vector2.h create mode 100644 application/demos/example.opengl/array.c create mode 100644 application/demos/example.opengl/array.h create mode 100644 application/demos/example.opengl/cache.c create mode 100644 application/demos/example.opengl/cache.h create mode 100644 application/demos/example.opengl/char.c create mode 100644 application/demos/example.opengl/char.h create mode 100644 application/demos/example.opengl/classConfiguration.c create mode 100644 application/demos/example.opengl/classConfiguration.h create mode 100644 application/demos/example.opengl/console.c create mode 100644 application/demos/example.opengl/console.h create mode 100644 application/demos/example.opengl/engine/block.c create mode 100644 application/demos/example.opengl/engine/block.h create mode 100644 application/demos/example.opengl/engine/element.c create mode 100644 application/demos/example.opengl/engine/element.h create mode 100644 application/demos/example.opengl/engine/event.c create mode 100644 application/demos/example.opengl/engine/event.h create mode 100644 application/demos/example.opengl/engine/eventManager.c create mode 100644 application/demos/example.opengl/engine/eventManager.h create mode 100644 application/demos/example.opengl/engine/floatArray.c create mode 100644 application/demos/example.opengl/engine/floatArray.h create mode 100644 application/demos/example.opengl/engine/fontRenderer.c create mode 100644 application/demos/example.opengl/engine/fontRenderer.h create mode 100644 application/demos/example.opengl/engine/hints.c create mode 100644 application/demos/example.opengl/engine/hints.h create mode 100644 application/demos/example.opengl/engine/member.c create mode 100644 application/demos/example.opengl/engine/member.h create mode 100644 application/demos/example.opengl/engine/mesh.c create mode 100644 application/demos/example.opengl/engine/mesh.h create mode 100644 application/demos/example.opengl/engine/opengl.c create mode 100644 application/demos/example.opengl/engine/opengl.h create mode 100644 application/demos/example.opengl/engine/pipeline.c create mode 100644 application/demos/example.opengl/engine/pipeline.h create mode 100644 application/demos/example.opengl/engine/program.c create mode 100644 application/demos/example.opengl/engine/program.h create mode 100644 application/demos/example.opengl/engine/quadMesh.c create mode 100644 application/demos/example.opengl/engine/quadMesh.h create mode 100644 application/demos/example.opengl/engine/renderPasses/renderPass.c create mode 100644 application/demos/example.opengl/engine/renderPasses/renderPass.h create mode 100644 application/demos/example.opengl/engine/renderPasses/renderPassCompute.c create mode 100644 application/demos/example.opengl/engine/renderPasses/renderPassCompute.h create mode 100644 application/demos/example.opengl/engine/renderPasses/renderPassCompute2.c create mode 100644 application/demos/example.opengl/engine/renderPasses/renderPassCompute2.h create mode 100644 application/demos/example.opengl/engine/renderPasses/renderPassFont.c create mode 100644 application/demos/example.opengl/engine/renderPasses/renderPassFont.h create mode 100644 application/demos/example.opengl/engine/renderPasses/renderPassQuads.c create mode 100644 application/demos/example.opengl/engine/renderPasses/renderPassQuads.h create mode 100644 application/demos/example.opengl/engine/renderPasses/renderPassTesselation.c create mode 100644 application/demos/example.opengl/engine/renderPasses/renderPassTesselation.h create mode 100644 application/demos/example.opengl/engine/resourceManager.c create mode 100644 application/demos/example.opengl/engine/resourceManager.h create mode 100644 application/demos/example.opengl/engine/sampler2D.c create mode 100644 application/demos/example.opengl/engine/sampler2D.h create mode 100644 application/demos/example.opengl/engine/shader.c create mode 100644 application/demos/example.opengl/engine/shader.h create mode 100644 application/demos/example.opengl/engine/texture2D.c create mode 100644 application/demos/example.opengl/engine/texture2D.h create mode 100644 application/demos/example.opengl/engine/uniform.c create mode 100644 application/demos/example.opengl/engine/uniform.h create mode 100644 application/demos/example.opengl/engine/unsignedIntegerArray.c create mode 100644 application/demos/example.opengl/engine/unsignedIntegerArray.h create mode 100644 application/demos/example.opengl/engine/vector.c create mode 100644 application/demos/example.opengl/engine/vector.h create mode 100644 application/demos/example.opengl/engine/vector4.c create mode 100644 application/demos/example.opengl/engine/vector4.h create mode 100644 application/demos/example.opengl/engine/windowManager.c create mode 100644 application/demos/example.opengl/engine/windowManager.h create mode 100644 application/demos/example.opengl/examples/example.opengl.c create mode 100644 application/demos/example.opengl/examples/example.opengl.h create mode 100644 application/demos/example.opengl/file.c create mode 100644 application/demos/example.opengl/file.h create mode 100644 application/demos/example.opengl/fileSystem.c create mode 100644 application/demos/example.opengl/fileSystem.h create mode 100644 application/demos/example.opengl/header.c create mode 100644 application/demos/example.opengl/header.h create mode 100644 application/demos/example.opengl/headers.c create mode 100644 application/demos/example.opengl/headers.h create mode 100644 application/demos/example.opengl/http.c create mode 100644 application/demos/example.opengl/http.h create mode 100644 application/demos/example.opengl/int.c create mode 100644 application/demos/example.opengl/int.h create mode 100644 application/demos/example.opengl/mimeTypes.c create mode 100644 application/demos/example.opengl/mimeTypes.h create mode 100644 application/demos/example.opengl/request.c create mode 100644 application/demos/example.opengl/request.h create mode 100644 application/demos/example.opengl/text.c create mode 100644 application/demos/example.opengl/text.h create mode 100644 application/demos/example.opengl/vector2.c create mode 100644 application/demos/example.opengl/vector2.h create mode 100644 application/demos/example.opengl/vector3.c create mode 100644 application/demos/example.opengl/vector3.h create mode 100644 application/opengl.c create mode 100755 application/source/application.c create mode 100755 application/source/array.c create mode 100644 application/source/arrayText.c create mode 100755 application/source/assets/test create mode 100644 application/source/cache.c create mode 100644 application/source/callbacks.c create mode 100755 application/source/char.c create mode 100644 application/source/console.c create mode 100644 application/source/define.c create mode 100644 application/source/engine/arrayUnsignedInteger.c create mode 100644 application/source/engine/block.c create mode 100644 application/source/engine/element.c create mode 100644 application/source/engine/event.c create mode 100644 application/source/engine/eventManager.c create mode 100644 application/source/engine/floatArray.c create mode 100644 application/source/engine/fontRenderer.c create mode 100644 application/source/engine/hints.c create mode 100644 application/source/engine/member.c create mode 100644 application/source/engine/mesh.c create mode 100644 application/source/engine/opengl.c create mode 100644 application/source/engine/pipeline.c create mode 100644 application/source/engine/program.c create mode 100644 application/source/engine/quadMesh.c create mode 100644 application/source/engine/renderPasses/renderPass.c create mode 100644 application/source/engine/renderPasses/renderPassCompute.c create mode 100644 application/source/engine/renderPasses/renderPassCompute2.c create mode 100644 application/source/engine/renderPasses/renderPassFont.c create mode 100644 application/source/engine/renderPasses/renderPassQuads.c create mode 100644 application/source/engine/renderPasses/renderPassTesselation.c create mode 100644 application/source/engine/resourceManager.c create mode 100644 application/source/engine/sampler2D.c create mode 100644 application/source/engine/shader.c create mode 100644 application/source/engine/texture2D.c create mode 100644 application/source/engine/uniform.c create mode 100644 application/source/engine/uniformBlock.c create mode 100644 application/source/engine/unsignedIntegerArray.c create mode 100644 application/source/engine/vector.c create mode 100644 application/source/engine/vector4.c create mode 100644 application/source/engine/windowManager.c create mode 100644 application/source/examples/example.console.log.c create mode 100644 application/source/examples/example.file.system.c create mode 100644 application/source/examples/example.multiple.inheritance.c create mode 100644 application/source/examples/example.opengl.c create mode 100644 application/source/examples/example.operator.overload.c create mode 100644 application/source/examples/example.sqlite3.c create mode 100755 application/source/examples/example.text.c create mode 100644 application/source/examples/example.vector.c create mode 100644 application/source/examples/example.vulkan.c create mode 100644 application/source/examples/example.web.server.c create mode 100644 application/source/extends.c create mode 100644 application/source/file.c create mode 100755 application/source/fileSystem.c create mode 100644 application/source/header.c create mode 100644 application/source/headers.c create mode 100644 application/source/http.c create mode 100644 application/source/http.c.old create mode 100755 application/source/int.c create mode 100644 application/source/integerArray.c create mode 100644 application/source/mimeTypes.c create mode 100644 application/source/reflection.c create mode 100644 application/source/request.c create mode 100755 application/source/sqlite.c create mode 100644 application/source/street.c create mode 100755 application/source/text.c create mode 100644 application/source/toolset.c create mode 100755 application/source/triangle.c create mode 100644 application/source/user.c create mode 100755 application/source/vector2.c create mode 100644 application/source/vector3.c create mode 100755 application/sqlite.c create mode 100644 application/target/application.c create mode 100644 application/target/application.h create mode 100644 application/target/array.c create mode 100644 application/target/array.h create mode 100644 application/target/char.c create mode 100644 application/target/char.h create mode 100644 application/target/classConfiguration.c create mode 100644 application/target/classConfiguration.h create mode 100644 application/target/console.c create mode 100644 application/target/console.h create mode 100644 application/target/define.c create mode 100644 application/target/define.h create mode 100644 application/target/extends.c create mode 100644 application/target/extends.h create mode 100644 application/target/fileSystem.c create mode 100644 application/target/fileSystem.h create mode 100644 application/target/floatArray.c create mode 100644 application/target/floatArray.h create mode 100644 application/target/header.c create mode 100644 application/target/header.h create mode 100644 application/target/headers.c create mode 100644 application/target/headers.h create mode 100644 application/target/http.c create mode 100644 application/target/http.h create mode 100644 application/target/int.c create mode 100644 application/target/int.h create mode 100644 application/target/mesh.c create mode 100644 application/target/mesh.h create mode 100644 application/target/mimeTypes.c create mode 100644 application/target/mimeTypes.h create mode 100644 application/target/opengl.c create mode 100644 application/target/opengl.h create mode 100644 application/target/request.c create mode 100644 application/target/request.h create mode 100644 application/target/shader.c create mode 100644 application/target/shader.h create mode 100644 application/target/sqlite.c create mode 100644 application/target/sqlite.h create mode 100644 application/target/street.c create mode 100644 application/target/street.h create mode 100644 application/target/text.c create mode 100644 application/target/text.h create mode 100644 application/target/toolset.c create mode 100644 application/target/toolset.h create mode 100644 application/target/triangle.c create mode 100644 application/target/triangle.h create mode 100644 application/target/unsignedIntegerArray.c create mode 100644 application/target/unsignedIntegerArray.h create mode 100644 application/target/user.c create mode 100644 application/target/user.h create mode 100644 application/target/vector2.c create mode 100644 application/target/vector2.h create mode 100644 application/target/vector3.c create mode 100644 application/target/vector3.h create mode 100644 binaries/1.png create mode 100755 binaries/10.png create mode 100644 binaries/2.png create mode 100755 binaries/3.png create mode 100755 binaries/4.png create mode 100644 binaries/5.png create mode 100644 binaries/6.png create mode 100644 binaries/7.png create mode 100644 binaries/8.png create mode 100644 binaries/9.png create mode 100644 binaries/android.png create mode 100644 binaries/application.dump create mode 100644 binaries/assets/fonts/WorkSans/WorkSans-Regular.ttf create mode 100644 binaries/assets/shaders/addition.comp create mode 100644 binaries/assets/shaders/addition2.comp create mode 100644 binaries/assets/shaders/color.fragment create mode 100644 binaries/assets/shaders/color.vertex create mode 100644 binaries/assets/shaders/multiQuad.fragment create mode 100644 binaries/assets/shaders/multiQuad.vertex create mode 100644 binaries/assets/shaders/quad.fragment create mode 100644 binaries/assets/shaders/quad.vertex create mode 100644 binaries/assets/shaders/quadScale.vertex create mode 100644 binaries/assets/shaders/tesselation.geometry.shader create mode 100644 binaries/assets/shaders/tesselation.triangle.shader create mode 100644 binaries/assets/shaders/tesselation.triangle.tsc.shader create mode 100755 binaries/assets/test create mode 100644 binaries/assets/testFile create mode 100644 binaries/database/users.sqlite create mode 100755 binaries/example.console.log create mode 100755 binaries/example.sqlite3 create mode 100755 binaries/preprocessor create mode 100644 binaries/show_includes.sh create mode 100644 binaries/www/assets/css/main.css create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-Black.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-BlackItalic.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-Bold.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-BoldItalic.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-ExtraBold.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-ExtraBoldItalic.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-ExtraLight.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-ExtraLightItalic.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-Italic-VariableFont_wght.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-Italic.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-Light.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-LightItalic.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-Medium.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-MediumItalic.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-Regular.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-SemiBold.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-SemiBoldItalic.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-Thin.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-ThinItalic.ttf create mode 100644 binaries/www/assets/fonts/workSans/WorkSans-VariableFont_wght.ttf create mode 100644 binaries/www/assets/images/api.png create mode 100644 binaries/www/assets/images/c.png create mode 100644 binaries/www/assets/images/code.png create mode 100644 binaries/www/assets/images/sqlite3.svg create mode 100644 binaries/www/assets/images/webGPU.png create mode 100644 binaries/www/assets/js/main.js create mode 100644 binaries/www/index.html create mode 100644 documents/Tesselation_Tutorial/Tesselation.sln create mode 100644 documents/Tesselation_Tutorial/Tesselation.suo create mode 100644 documents/Tesselation_Tutorial/bin32/glut32.dll create mode 100644 documents/Tesselation_Tutorial/bin64/Tesselation.exe create mode 100644 documents/Tesselation_Tutorial/bin64/glut32.dll create mode 100644 documents/Tesselation_Tutorial/ext/GL/glext.h create mode 100644 documents/Tesselation_Tutorial/ext/GL/glut.def create mode 100644 documents/Tesselation_Tutorial/ext/GL/glut.h create mode 100644 documents/Tesselation_Tutorial/ext/GL/glxext.h create mode 100644 documents/Tesselation_Tutorial/ext/GL/wglext.h create mode 100644 documents/Tesselation_Tutorial/ext/glew.cpp create mode 100644 documents/Tesselation_Tutorial/ext/glew.h create mode 100644 documents/Tesselation_Tutorial/ext/glsl.cpp create mode 100644 documents/Tesselation_Tutorial/ext/glsl.h create mode 100644 documents/Tesselation_Tutorial/ext/glxew.h create mode 100644 documents/Tesselation_Tutorial/ext/wglew.h create mode 100644 documents/Tesselation_Tutorial/lib32/glut32.lib create mode 100644 documents/Tesselation_Tutorial/lib64/glut32.lib create mode 100644 documents/Tesselation_Tutorial/shader/tess_frag.txt create mode 100644 documents/Tesselation_Tutorial/shader/tess_geo.txt create mode 100644 documents/Tesselation_Tutorial/shader/tess_quad_tcs.txt create mode 100644 documents/Tesselation_Tutorial/shader/tess_quad_tes.txt create mode 100644 documents/Tesselation_Tutorial/shader/tess_tri_tcs.txt create mode 100644 documents/Tesselation_Tutorial/shader/tess_tri_tes.txt create mode 100644 documents/Tesselation_Tutorial/shader/tess_vs.txt create mode 100644 documents/Tesselation_Tutorial/src/Main.cpp create mode 100644 documents/Tesselation_Tutorial/src/Tesselation.vcproj create mode 100644 documents/Tesselation_Tutorial/src/Tesselation.vcxproj create mode 100644 documents/Tesselation_Tutorial/src/Tesselation.vcxproj.filters create mode 100644 documents/Tesselation_Tutorial/src/Tesselation.vcxproj.user create mode 100644 documents/Tesselation_Tutorial/src/glsl.h create mode 100755 documents/preprocess.md create mode 100755 documents/program.dump create mode 100644 freetype.c create mode 100755 scripts/all.sh create mode 100644 scripts/application.dump create mode 100644 scripts/classes.dump create mode 100755 scripts/compileAndRunApplication.sh create mode 100755 scripts/compileAndRunPreprocessor.sh create mode 100755 scripts/compileApplication.sh create mode 100755 scripts/compilePreprocessor.sh create mode 100755 scripts/disassemble.sh create mode 100755 scripts/menu create mode 100755 scripts/menu.c create mode 100755 scripts/runApplication.sh create mode 100755 scripts/runPreprocessor.sh create mode 100644 scripts/runServer.sh create mode 100644 source/application.c create mode 100644 source/application.h create mode 100644 source/argument.c create mode 100644 source/argument.h create mode 100755 source/array.c create mode 100755 source/array.h create mode 100644 source/class.c create mode 100644 source/class.h create mode 100644 source/codeBundle.c create mode 100644 source/codeBundle.h create mode 100644 source/configuration.c create mode 100644 source/configuration.h create mode 100644 source/console.c create mode 100644 source/console.h create mode 100644 source/file.c create mode 100644 source/file.h create mode 100644 source/fileManager.c create mode 100644 source/fileManager.h create mode 100755 source/fileSystem.c create mode 100755 source/fileSystem.h create mode 100644 source/function.c create mode 100644 source/function.h create mode 100644 source/include.c create mode 100644 source/include.h create mode 100644 source/index.c create mode 100755 source/index.h create mode 100755 source/lexer.c create mode 100755 source/lexer.h create mode 100644 source/macro.c create mode 100644 source/macro.h create mode 100644 source/method.c create mode 100644 source/method.h create mode 100644 source/property.c create mode 100644 source/property.h create mode 100644 source/replacement.c create mode 100644 source/replacement.h create mode 100644 source/template.c create mode 100644 source/template.h create mode 100644 source/templateInstance.c create mode 100644 source/templateInstance.h create mode 100644 source/templateInstanceProperty.c create mode 100644 source/templateInstanceProperty.h create mode 100755 source/text.c create mode 100755 source/text.h create mode 100644 source/tools.c create mode 100644 source/tools.h create mode 100644 source/variable.c create mode 100644 source/variable.h create mode 100644 todo diff --git a/Libraries b/Libraries new file mode 100644 index 0000000..0e135d4 --- /dev/null +++ b/Libraries @@ -0,0 +1,24 @@ + + + + Libraries Without images + + +------------------------------------------------------------------------------------------------------------------------ + + + Tiny C Compiler - https://bellard.org/tcc/tcc-doc.html C Compiler + + LibPng - http://www.libpng.org/pub/png/libpng.html Load Png Images + + FreeType - https://freetype.org/ Font renderer + + Sqlite 3 - https://www.sqlite.org/ Sql Database Storage + + OpenGL - https://www.opengl.org/ Fast Graphics and Computations + + OpenSSL - https://openssl-library.org/ Security, Encryption and Certifications + + + + diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..e540307 --- /dev/null +++ b/Readme.md @@ -0,0 +1,788 @@ +# What is C prime + +C Prime is a new language very close related to C, C Prime is an very simple addition to c, You could say c prime is c with classes without the bloat. Also unique about C Prime is the C Prime compiler, Because the C Prime compiler will convert your C Prime code to readable, high-performance C code. This code can than be compiled with a normal C compiler. + +As c compiler i use the tiny c compiler. The C Prime Preprocessor can be compiled using the tiny c compiler using Musl or Gnu libc. Also your preprocessed code can be compiled using the Tiny c compiler. + +Then you can preprocess your Object Oriented c code using the compiled binary. This will generate a folder with readable c files. These can then be compiled using the tiny c compiler. + +Compiling the C Prime preprocessor takes only a few milliseconds. and using the C Prime preprocessor to preprocess your object oriented c code to pure c also takes a few milliseconds. It is almost instantaneous. Then compiling your resulting c code with the tiny c compiler takes somewhat longer. still less then 1 second. + +# Classes + +Creating simple classes. + +```C++ +#include "console.h" + +class application{ + + sayHi( char * name ) { + + console.log( "Hi ", name ); + + } + + launch() { + + this->sayHi( "John" ); + + } + +} + +void main() { + + application * instance = new application(); + + instance->launch(); + +} +``` + +# Constructors +Instantiate a class using an constructor. + + +```C++ +class vector3{ + + float x; + + float y; + + float z; + + constructor( float x, float y, float z ) { + + this->x = x; + + this->y = y; + + this->z = z; + + } + + display() { + + printf("x: %f, y: %f, z: %f", this->x, this->y, this->z); + + } + +} + +void main() { + + vector3 * a = new vector3( 1.0, 0.0, 1.0 ); + + a->display(); + +} +``` + +# Running a webserver +For example to setup a server you can write: + + +```C++ +#include "../http.h" + +#include "./fileSystem.h" + +#include "./text.h" + +#include "./mimeTypes.h" + + +void handleRequest( struct request * requestInstance, struct text * response ) { + + text * filePath = new text("www/"); + + filePath += requestInstance->url; + + // Request information + printf("server address: [%s:%u]\n", requestInstance->address, requestInstance->port ); + + printf("mimeType: %-30s \n", requestInstance->mimeType); + + printf("header: %-30s \n", requestInstance->extension ); + + printf("method: %-30s \n", requestInstance->method ); + + printf("version: %-30s \n\n", requestInstance->version ); + + if( filesystem->exists( filePath->value ) ) { + + text * content = filesystem->readFile( filePath->value, "binary" ); + + response += "HTTP/1.0 200 OK\r\n"; + + response += "Server: webserver-c\r\n"; + + response += "Content-type: " + requestInstance->mimeType + "\r\n\r\n"; + + response += "Simple test server\r\n"; + //response->appendObject( content ); + + free( content ); + + } else { + + printf("file does not exists... %s\n", filePath->value); + + } + + +} + +void main() { + + http * serverInstance = new http(); + + serverInstance->createServer( handleRequest ); + + serverInstance->listen( 8080 ); + +} +``` + + + + + + + + +```C++ +#include "../fileSystem.h" + +#include "../console.h" + +void main() { + + char * directory2 = "./assets/"; + + fileSystem * filesystem = new fileSystem(); + + char * directory = "./assets/"; + + + + filesystem->writeFile( "./assets/testFile", "content of file" ); + + + array * files = filesystem->readDir( directory ); + + int fileCount = files->length(); + + for ( int i = 0; i < fileCount; ++i ) + { + + char * filename = files->get( i ); + + char * path = directory->concatenate( filename ); + + char * source = filesystem->readFile( path ); + + + printf("filename: %s\n", path); + + printf("source: %s\n\n\n", source); + + } + + if( filesystem->ensureDirectory("./Some/example/assure") ) { + + console.log("Directories successfuly created."); + + } + + if( filesystem->exists( "Some" ) ) { + + console.log("Directories 'Some' does exist."); + + } + +} + +void abort() { + + +} +``` + + + + +# Extending classes +You can extend one or more classes. This will overide the methods and properties, with the methods and properties of the extended class. + + +```C++ +#include "stdio.h" + +class classB{ + + int propertyA = 1; + + void test() { + + printf("%s\n", this->propertyA ); + + } + +} + +class classA{ + + int propertyA = 2; + + void test() { + + printf("%s\n", this->propertyA ); + + } + +} + + +class inherit extends classB, classA{ + + int propertyA = 3; + + void test() { + + printf("%s\n", this->propertyA ); + + } + +} + + +#include + +#include "extends.h" + +void main() { + + struct inherit * pointer = new inherit(); + + for (int i = 0; i < 10; ++i) + { + + struct inherit instance = new inherit(); + + instance.propertyA = i; + + instance.test(); + + } + +} +``` + +# Console.log + +You can print all class instances and arrays using console.log. This is all possible because of datatype overloading and automatic reflection. + +Reflection means that the structure of the class is always available at runtime. + + +```C++ +#include "../console.h" + +#include "../street.h" + +#include "../user.h" + +#include "../array.h" + + + +void main() { + + struct user * newUser = new user(); + + newUser->id = 1; + + newUser->username = "peter"; + + newUser->userlevel = 2134; + + newUser->hash = "#234234325"; + + + + struct array * addresses = newUser->addresses; + + + address * someAddress = new address(); + + someAddress->street = "HiLane"; + + someAddress->number = 1234; + + addresses->add( someAddress ); + + + + + address * otherAddress = new address(); + + otherAddress->street = "OtherLane"; + + otherAddress->number = 4567; + + addresses->add( otherAddress ); + + // todo newUser->addresses->add( otherAddress ); + + + printf("adresses count: %i\n\n", addresses->length() ); + + + char * something = "this is from an char * "; + + int somethingElse = 123; + + + console.log( "Goedendag", + 123456, + "en een andere text.", + something, + somethingElse, + "something en something", + "in native c", + 23456, + newUser, + "and some text again" ); + +} + +void abort() { + + +} +``` + + + + + + + + +# Datatype overloading +This demostrates how an datatype can be accessed within the called method when using argument overload. + +```C++ +class console{ + + void log( ... ) { + + va_list args; + + va_start( args, count ); + + //printf("count: %i\n\n", count); + + for (int i = 0; i < count; ++i) + { + int datatype = datatypes[i]; // va_arg_type( argumentIndex ) + + // this will print the datatype of the argument + printf("datatype %i\n", datatype); + + if( datatype == 1 ) { + + // do something + + } + + + printf(" "); + + } + + printf("\n"); + + va_end( args); + + } + +} +``` + +# Operator overload + +With operator overload you can manipulate your class instances using operators. + +```C++ +class vector2{ + + int x = 123; + + int y = 234; + + constructor( int x, int y ) { + + this->x = x; + + this->y = y; + + } + + vector2 * operator+( vector2 * b ){ + + this->add( b ); + + return this; + + } + + vector2 * operator+=( struct vector2 * b ) { + + this->add( b ); + + return this; + + } + + add( vector2 * a ) { + + this->x += a->x; + + this->y += a->y; + + addition( this->y, a->x ); + + } + +} +``` + + +# Then you can use those classes like this: + + +```C++ +#include "../text.h" + +#include "../vector2.h" + +#include "../vector3.h" + +#include "../console.h" + + + +void main() { + + text * textB = new text("ook mooi"); + + char * other = malloc(5000); + + vector3 * newVector3 = new vector3(); + + newVector3->x = 2; + + newVector3->y = 2; + + newVector3->z = 3; + + + for (int i = 0; i < 1000; ++i) + { + + vector3 * vector3B = new vector3(); + + + vector3B->x = 2; + + vector3B->y = 3; + + vector3B->z = 4; + + + vector3 * vector3C = new vector3(); + + + vector3C->x = 2; + + vector3C->y = 3; + + vector3C->z = 4; + + newVector3 = vector3C + ( vector3C + newVector3 + ( ( ( ( vector3B + vector3C ) ) + vector3C ) + vector3B ) ); + + newVector3 = newVector3 + ( ( vector3B + vector3C ) + vector3C ); + + } + + console->log( newVector3 ); + + text * textA = new text("mooi"); + + if( textA == textB ) { + + printf("mooi zo"); + + } + + text * textC = new text("mooi"); + + text * textD = new text("mooi"); + + + if( ( ( textA == textC ) && ( textA == textD ) ) && textA == textD ) { + + printf("Good, This works.\n\n"); + + } + + char * realChar = "something"; + + if( "something" == realChar ) { + + printf("Great.\n\n"); + + } + + if( realChar == "something" ) { + + printf("Great.\n\n"); + + } + + if( realChar == realChar ) { + + printf("Great.\n\n"); + + } + + if( "something" == "something" && realChar == "something" ) { + + printf("Great.\n\n"); + + } + + +// Easy concatenation + + char * fancy = "aaa "; + + char * aaaa = " bbb "; + + char * bbbb = " ccc "; + + char * dddd = " dddd "; + + other += ( fancy + ( bbbb + aaaa ) + dddd ) + " eee" + " het is een wonder "; + + other += ("boven wonder" + returnText("this is a normal function") + " and this " + ( "works just good..." + dddd )); + + other += "something" + ( returnText("this is a normal function") + textB->toNative() + textB->value ); + + other += ("and here some text") + (textB->toNative()) ; + + other += ( textB->value + ( ( textB->value ) + returnText("this is a normal function") ) + (textB->toNative() + "here some text" + textB->value ) ); + + other += textB->value + textB->value + ( textB->value + textB->value ) + ( textB->value + textB->value ) + textB->value + textB->value; + + console.log( "Great ", other ); + + + + + + + + + + vector2 testVector = new vector2( 1, 450 ); + + + //int count = 0; + + for (int i = 0; i < 2000000; ++i) + { + vector2 testVector1 = new vector2( 2, 450 ); + + vector2 * testVector2 = new vector2( 10, 450 ); + + testVector += testVector1 + testVector2; + + } + +} + + +char * returnText( char * text ) { + + return text; + +} + +void abort() { + + +} +``` + + + +# Sqlite3 +Using these features C Prime also provides an simplistic sqlite3 class. + +```C++ +#include "../sqlite.h" + +#include "../array.h" + +#include "../console.h" + +#include "../street.h" + +#include "../user.h" + +#include "time.h" + +void main() { + + // sqlite * sql = new sqlite("./database/users.sqlite"); + + sqlite * sql = new sqlite(":memory:"); + + sql->selectModel( "user" ); + + + sql->createTable(); + + char * names[20] = { "piet", "gurbe", "siebe", "gerben", "twain", "piet", "gurbe", "siebe", "gerben", "twain", "piet", "gurbe", "siebe", "gerben", "twain" }; + + clock_t tic = clock(); + + + array * usersInsertArray = new array(); + + for (int i = 0; i <10; ++i) //20000 + { + + char * name = names[i]; + + struct user * userInstance = new user(); + + userInstance->id = i; + + userInstance->username = name; + + userInstance->userlevel = 3; + + userInstance->hash = "12345"; + + usersInsertArray.add( userInstance ); + + //sql->addRow( userInstance ); + + } + + + sql->addRows( usersInsertArray ); + + + + clock_t toc = clock(); + + printf("Multiply: %f seconds, rows: %i\n", (double)( toc - tic ) / CLOCKS_PER_SEC, 10000); + + + + array * usersA = sql->fetchRows( "SELECT * FROM user" ); + + //user * firstUser = new user(); + + user * firstUser = usersA->get( 1 ); + + //firstUser->id =10; + + firstUser->username = "updated"; + + firstUser->userlevel = 1111; + + firstUser->hash = "new hash"; + + console->log( "??", firstUser, "Yeey console.log workswith , , " ); + + + sql->update( firstUser ); + + printf("before log\n\n"); + + + + + array * users = sql->fetchRows( "SELECT * FROM user " ); + + int userCount = users->total; + + + printf("added rows: %i\n", userCount); + + console->createHorisontalLine(); + + printf("\e[1m"); + + printf(" "); + + printf("%-20s", "id" ); + + printf("%-30s", "username" ); + + printf("%-20s", "userLevel" ); + + printf("%-30s", "Hash"); + + printf("\e[m"); + + printf("\n"); + + console->createHorisontalLine(); + + printf("users: %i\n", userCount); + + for (int i = 0; i < userCount; ++i) + { + + struct user * userInstance = users->get( i ); + + userInstance->id; + + userInstance->username; + + printf(" "); + + printf("%-20i", userInstance->id); + + printf("%-30s", userInstance->username); + + printf("%-20i", userInstance->userlevel); + + printf("%-30s", userInstance->hash); + + printf( "\n" );//%-30s + + } + + sql->free(); + + console->createHorisontalLine(); + + + +} + +void abort() { + + +} +``` diff --git a/application/demos/example.console.log/array.c b/application/demos/example.console.log/array.c new file mode 100644 index 0000000..de777ed --- /dev/null +++ b/application/demos/example.console.log/array.c @@ -0,0 +1,231 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + +int array_length( array * this ) { + + return this->total; + + } + + +void * * array_data( array * this ) { + + return this->items; + + } + + +void * array_get( array * this, int index ) { + + if ( index >= 0 && index < this->total ){ + + return this->items[index]; + + } + + return NULL; + + } + + +void array_set( array * this, int index, void * item ) { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + +void array_resize( array * this, int capacity ) { + + void * * items = realloc( this->items, sizeof( void * ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + +void array_add( array * this, void * item ) { + + if ( this->capacity == this->total ){ + + array_resize( this, this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + +char * array_join( array * this, char * separator ) { + + int count = array_length( this ); + + text * result = text_newPointer( "" ); + + for (int i = 0; i < count; ++i) + { + + char * currentPart = this->items[ i ]; + + if( i > 0 ) { + + text_append( result, separator ); + + } + + text_append( result, currentPart ); + + } + + + + return result->value; + + } + +void array_delete( array * this, int index ) { + if ( index < 0 || index >= this->total ){ + + return; + + } + + this->items[index] = NULL; + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + this->items[i + 1] = NULL; + + } + + this->total--; + + if ( this->total > 0 && this->total == this->capacity / 4 ){ + + array_resize( this, this->capacity / 2 ); + + } + + } + + +int array_array_push( array * this, void * item ) { + + array_add( this, item ); + + return this->total; + + } + +void array_unshift( array * this, void * item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + array_resize( this, this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } + +void * array_pop( array * this ) { + + int length = this->total; + + int lastIndex = length - 1; + + void * lastItem = array_get( this, lastIndex ); + + array_delete( this, lastIndex ); + + return lastItem; + + } + +bool array_includes( array * this, char * value ) { + + int count = array_length( this ); + + for ( int index = 0; index < count; ++index ) + { + + char * currentText = array_get( this, index); + + + + if( char_operator_compare( currentText , value) ) { + + return true; + + } + + } + + return false; + + } + +array array_new() { + + array instance; + + instance.capacity = 10; + + instance.total = 0; + + instance.items = malloc( 10000000 ); + + return instance; + +} + +array * array_newPointer() { + + struct array * pointer = malloc( sizeof ( struct array ) ); + + pointer->capacity = 10; + + pointer->total = 0; + + pointer->items = malloc( 10000000 ); + + return pointer; + +} + diff --git a/application/demos/example.console.log/array.h b/application/demos/example.console.log/array.h new file mode 100644 index 0000000..171a06d --- /dev/null +++ b/application/demos/example.console.log/array.h @@ -0,0 +1,71 @@ +#ifndef _array + +#define _array + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + + +typedef struct array{ + + int capacity; + + int total; + + void * * items; + + +} array; + +int array_length( array * this ); + +void * * array_data( array * this ); + +void * array_get( array * this, int index ); + +void array_set( array * this, int index, void * item ); + +void array_resize( array * this, int capacity ); + +void array_add( array * this, void * item ); + +char * array_join( array * this, char * separator ); + +void array_delete( array * this, int index ); + +int array_array_push( array * this, void * item ); + +void array_unshift( array * this, void * item ); + +void * array_pop( array * this ); + +bool array_includes( array * this, char * value ); + +array array_new( ); + +array * array_newPointer( ); + +#endif + + +typedef struct array array; + + + diff --git a/application/demos/example.console.log/char.c b/application/demos/example.console.log/char.c new file mode 100644 index 0000000..78e7c91 --- /dev/null +++ b/application/demos/example.console.log/char.c @@ -0,0 +1,169 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + +int char_operator_compare( char * this, char * b ) { + + return char_compare( this, b ); + + } + +void char_operator_add( char * this, char * b ) { + + + strcat( this, b ); + + } + +char * char_operator_plus( char * this, char * b ) { + + return char_concatenate( this, b ); + + } + +int char_compare( char * this, char * b ) { + + return strcmp( this, b ) == 0; + + } + +char * char_concatenate( char * this, char * b ) { + + int lengthA = strlen( this ); + + int lengthB = strlen( b ); + + char * pointer = this; + + char * copy = ( char * ) malloc( ( lengthA + lengthB + 1 ) * sizeof( char ) ); + + int idx = 0; + + while ( * pointer != '\0' ){ + + copy[idx++] = *pointer++; + + } + + pointer = &b[0]; + + while ( * pointer != '\0' ){ + + copy[idx++] = *pointer++; + + } + + copy[ idx++ ] = '\0'; + + return ©[0]; + + } + +int char_includes( char * this, char * compare ) { + + if ( strstr( this, compare ) != NULL ) { + + return 1; + + } else { + + return 0; + + } + } + +char * char_clone( char * this ) { + + char * newCopy = malloc( sizeof( char ) * strlen( this ) ); + + strcpy( newCopy, this ); + + return newCopy; + + } + +char * char_copy( char * this ) { + + char * newCopy = malloc( sizeof( char ) * strlen( this ) ); + + strcpy( newCopy, this ); + + return newCopy; + + } + +struct array * char_split( char * this, char * needle ) { + + char * haystack = char_clone( this ); + + struct array * keys = array_newPointer(); + + int count = 0; + + char * tmp = haystack; + + char * token = strtok( haystack, needle ); + + int i = 0; + + while ( token ) { + + array_add( keys, token ); + + + + token = (char *) strtok( NULL, needle ); + + } + + return keys; + + + } + + + +char * char_removeWhitespaceLeft( char * this ) { + char * s = this; + + while(isspace(*s)) s++; + + return s; + } + + +char * char_removeWhitespaceRight( char * this ) { + char * s = this; + + char* back = s + strlen(s); + + while( isspace( *--back ) ); + + *( back + 1 ) = '\0'; + + return s; + } + + +char * char_removeWhitespace( char * this ) { + + return char_removeWhitespaceRight(char_removeWhitespaceLeft( this ) ); + + } + diff --git a/application/demos/example.console.log/char.h b/application/demos/example.console.log/char.h new file mode 100644 index 0000000..494d5e8 --- /dev/null +++ b/application/demos/example.console.log/char.h @@ -0,0 +1,56 @@ +#ifndef _char + +#define _char + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + + +int char_operator_compare( char * this, char * b ); + +void char_operator_add( char * this, char * b ); + +char * char_operator_plus( char * this, char * b ); + +int char_compare( char * this, char * b ); + +char * char_concatenate( char * this, char * b ); + +int char_includes( char * this, char * compare ); + +char * char_clone( char * this ); + +char * char_copy( char * this ); + +struct array * char_split( char * this, char * needle ); + +char * char_removeWhitespaceLeft( char * this ); + +char * char_removeWhitespaceRight( char * this ); + +char * char_removeWhitespace( char * this ); + +#endif diff --git a/application/demos/example.console.log/classConfiguration.c b/application/demos/example.console.log/classConfiguration.c new file mode 100644 index 0000000..199157d --- /dev/null +++ b/application/demos/example.console.log/classConfiguration.c @@ -0,0 +1,394 @@ +#include + +char * __ClassNames[TOTAL_CLASS_COUNT] = { "array", "text", "char", "user", "address", "consoleManager", "vector2" }; + +int __ClassMethodCount[TOTAL_CLASS_COUNT] = { 12, 12, 12, 1, 1, 5, 6 }; + +int __ClassPropertyCount[TOTAL_CLASS_COUNT] = { 3, 4, 0, 5, 2, 0, 2 }; + +char * __ClassPropertyNames[TOTAL_CLASS_COUNT][30] = { + { "capacity" , "total" , "items" }, + { "value" , "usevalue" , "length" , "capacity" }, + { }, + { "username" , "id" , "userlevel" , "hash" , "addresses" }, + { "street" , "number" }, + { }, + { "x" , "y" } + }; + +char * __ClassMethodNames[TOTAL_CLASS_COUNT][30] = { + { "length" , "data" , "get" , "set" , "resize" , "add" , "join" , "delete" , "array_push" , "unshift" , "pop" , "includes" }, + { "operator_compare" , "operator_add" , "constructor" , "get" , "resize" , "append" , "appendBinary" , "appendObject" , "concatenate" , "toNative" , "whiteSpace" , "free" }, + { "operator_compare" , "operator_add" , "operator_plus" , "compare" , "concatenate" , "includes" , "clone" , "copy" , "split" , "removeWhitespaceLeft" , "removeWhitespaceRight" , "removeWhitespace" }, + { "constructor" }, + { "someMethod" }, + { "whiteSpace" , "logObject" , "log" , "error" , "createHorisontalLine" }, + { "constructor" , "operator_plus" , "operator_add" , "add" , "subtract" , "length" } + }; + +int __ClassPropertyOffsets[TOTAL_CLASS_COUNT][30] = { + { offsetof( array, capacity ) , offsetof( array, total ) , offsetof( array, items ) }, + { offsetof( text, value ) , offsetof( text, usevalue ) , offsetof( text, length ) , offsetof( text, capacity ) }, + { }, + { offsetof( user, username ) , offsetof( user, id ) , offsetof( user, userlevel ) , offsetof( user, hash ) , offsetof( user, addresses ) }, + { offsetof( address, street ) , offsetof( address, number ) }, + { }, + { offsetof( vector2, x ) , offsetof( vector2, y ) } + }; + +int __ClassPropertyDatatypeIndices[TOTAL_CLASS_COUNT][30] = { + {-5 , -5 , 1 }, + {-3 , -5 , -5 , -5 }, + { }, + {-3 , -5 , -5 , -3 , 0 }, + {-3 , -5 }, + { }, + {1 , 1 } + }; + +void getArrayByClassIndex( int size, void * * voidArray, int * structByteSize, int classIndex ) { + + switch( classIndex ) { + + case 0: + + voidArray = ( void ** ) ( struct array * ) malloc( sizeof( struct array ) * size ); + + *structByteSize = sizeof( struct array ); + + break; + + case 1: + + voidArray = ( void ** ) ( struct text * ) malloc( sizeof( struct text ) * size ); + + *structByteSize = sizeof( struct text ); + + break; + + case 3: + + voidArray = ( void ** ) ( struct user * ) malloc( sizeof( struct user ) * size ); + + *structByteSize = sizeof( struct user ); + + break; + + case 4: + + voidArray = ( void ** ) ( struct address * ) malloc( sizeof( struct address ) * size ); + + *structByteSize = sizeof( struct address ); + + break; + + case 5: + + voidArray = ( void ** ) ( struct consoleManager * ) malloc( sizeof( struct consoleManager ) * size ); + + *structByteSize = sizeof( struct consoleManager ); + + break; + + case 6: + + voidArray = ( void ** ) ( struct vector2 * ) malloc( sizeof( struct vector2 ) * size ); + + *structByteSize = sizeof( struct vector2 ); + + break; + + } + +} + +void callMethodOfClass( int classIndex, int methodIndex, void * object ) { + + switch( classIndex ) { + + case 0: + + switch( methodIndex ) { + + case 0: + + array_length( object ); + + break; + + case 1: + + array_data( object ); + + break; + + case 10: + + array_pop( object ); + + break; + + } + + break; + + case 1: + + switch( methodIndex ) { + + case 9: + + text_toNative( object ); + + break; + + case 11: + + text_free( object ); + + break; + + } + + break; + + case 3: + + switch( methodIndex ) { + + case 0: + + user_constructor( object ); + + break; + + } + + break; + + case 4: + + switch( methodIndex ) { + + case 0: + + address_someMethod( object ); + + break; + + } + + break; + + case 5: + + switch( methodIndex ) { + + case 4: + + consoleManager_createHorisontalLine( object ); + + break; + + } + + break; + + case 6: + + switch( methodIndex ) { + + case 5: + + vector2_length( object ); + + break; + + } + + break; + + } + +} + + + +// #include "sqlite.h" + +int getPropertyIndexOfClassIndex( int propertyCount, char ** propertyNames ) { + + int propertyIdOfIndex = -1; + + for ( int i = 0; i < propertyCount; ++i ) + { + char * propertyName = propertyNames[i]; + + //printf("propertyName: %s\n", propertyName); + + if( strcmp( propertyName, "id" ) == 0 ) { + + propertyIdOfIndex = i; + + break; + + } + + } + + return propertyIdOfIndex; + +} + +/* +void getArrayByClassIndex( int items, void * * voidArray, int * structByteSize, int classIndex ) { + + struct user * array; + + switch( classIndex ) { + + case 8: + + array = ( struct user * ) malloc( sizeof( struct user ) * 1000 ); + + voidArray = ( void ** ) array; + + *structByteSize = sizeof( struct user ); + + break; + + default: + + array = ( struct user * ) malloc( sizeof( struct user ) * 1000 ); + + voidArray = ( void ** ) array; + + *structByteSize = sizeof( struct user ); + + } + +}*/ + +char * getClassName( int classIndex ) { + + return __ClassNames[ classIndex ]; + +} + + +int getClassIndexByClassName( char * className ) { + + for (int i = 0; i < TOTAL_CLASS_COUNT; ++i) + { + char * currentClassName = __ClassNames[ i ]; + + if( strcmp( className, currentClassName ) == 0 ) { + + //printf("find classname: %s\n", className); + + return i; + + } + + } + + return -1; + +} + +int getPropertyCountByClassIndex( int classIndex ) { + + return __ClassPropertyCount[ classIndex ]; + +} + +char * * getPropertiesByClassIndex( int classIndex ) { + + return __ClassPropertyNames[ classIndex ]; + +} + +int * getPropertyOffsetsByClassIndex( int classIndex ) { + + return __ClassPropertyOffsets[ classIndex ]; + +} + +int getPropertyOffsetByPropertyIndex( int * propertyOffsets, int propertyIndex ) { + + return propertyOffsets[ propertyIndex ]; + +} + +int * getPropertyDatatypeIndexesByClassIndex( int classIndex ) { + + return __ClassPropertyDatatypeIndices[ classIndex ]; + +} + +int getPropertyDatatypeIndex( int * propertyDatatypeIndices, int propertyIndex ) { + + return propertyDatatypeIndices[ propertyIndex ]; + +} + + +int getPropertyIndexByPropertyName( int classID, char * propertyName ) { + + int propertyCount = getPropertyCountByClassIndex( classID ); + + char * * propertyNames = getPropertiesByClassIndex( classID ); + + for (int i = 0; i < propertyCount; ++i) + { + + char * propertyNameCompare = propertyNames[i]; + + if( strcmp( propertyName, propertyNameCompare ) == 0 ) { + + return i; + + } + + } + + return -1; + +} + +int getMethodCountByClassIndex( int classIndex ) { + + return __ClassMethodCount[ classIndex ]; + +} + + +char * * getMethodNamesByClassIndex( int classIndex ) { + + return __ClassMethodNames[ classIndex ]; + +} + + +int getMethodIndexByPropertyName( int classID, char * propertyName ) { + + int methodCount = getMethodCountByClassIndex( classID ); + + char * * methodNames = getMethodNamesByClassIndex( classID ); + + for (int i = 0; i < methodCount; ++i) + { + + char * propertyNameCompare = methodNames[i]; + + if( strcmp( propertyName, propertyNameCompare ) == 0 ) { + + return i; + + } + + } + + return -1; + +} \ No newline at end of file diff --git a/application/demos/example.console.log/classConfiguration.h b/application/demos/example.console.log/classConfiguration.h new file mode 100644 index 0000000..0172943 --- /dev/null +++ b/application/demos/example.console.log/classConfiguration.h @@ -0,0 +1,61 @@ +#ifndef __classConfiguration + +#define __classConfiguration + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#define TOTAL_CLASS_COUNT 7 + +extern char * __ClassNames[TOTAL_CLASS_COUNT]; +extern int __ClassPropertyCount[TOTAL_CLASS_COUNT]; +extern char * __ClassPropertyNames[TOTAL_CLASS_COUNT][30]; +extern int __ClassPropertyOffsets[TOTAL_CLASS_COUNT][30]; +extern int __ClassPropertyOffsets[TOTAL_CLASS_COUNT][30]; + +#include + +int getPropertyIndexOfClassIndex( int propertyCount, char ** propertyNames ); + +void getArrayByClassIndex( int size, void * * voidArray, int * structByteSize, int classIndex ); + +int getClassIndexByClassName( char * className ); + +char * getClassName( int classIndex ); + +int getPropertyCountByClassIndex( int classIndex ); + +char * * getPropertiesByClassIndex( int classIndex ); + +int * getPropertyOffsetsByClassIndex( int classIndex ); + +int getPropertyOffsetByPropertyIndex( int * propertyOffsets, int propertyIndex ); + +int getPropertyIndexByPropertyName( int classID, char * propertyName ); + +int * getPropertyDatatypeIndexesByClassIndex( int classIndex ); + +int getPropertyDatatypeIndex( int * propertyDatatypeIndices, int propertyIndex ); + +int getMethodCountByClassIndex( int classIndex ); + +char * * getMethodNamesByClassIndex( int classIndex ); + + +int getMethodIndexByPropertyName( int classID, char * propertyName ); + +void callMethodOfClass( int classIndex, int methodIndex, void * object ); +#endif diff --git a/application/demos/example.console.log/console.c b/application/demos/example.console.log/console.c new file mode 100644 index 0000000..88a8774 --- /dev/null +++ b/application/demos/example.console.log/console.c @@ -0,0 +1,269 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + +struct consoleManager * console; + + + +char * consoleManager_whiteSpace( consoleManager * this, int whiteSpaceCount ) { + + char * output = malloc( whiteSpaceCount + 1 ); + + for (int i = 0; i < whiteSpaceCount; ++i) + { + + strcat( output, " " ); + + } + + output[whiteSpaceCount] = 0; + + return output; + + } + +void consoleManager_logObject( consoleManager * this, void * voidPointer, int classIndex, int level ) { + + + char * whiteSpace = consoleManager_whiteSpace( this, level ); + + level++; + + char * className = getClassName( classIndex ); + + printf( "\n\n" ); + + printf( whiteSpace ); + + printf(" %s : {\n", className ); + + + + char * * propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + char * pointer = voidPointer; + + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + printf( whiteSpace ); + + printf(" %-20s : ", propertyName); + + int propertyDatatypeIndex = getPropertyDatatypeIndex( datatypeIndices, propertyIndex ); + + int propertyOffset = getPropertyOffsetByPropertyIndex( propertyOffsets, propertyIndex ); + + + if( propertyDatatypeIndex == -5 ) { + + int value = *( int * )(pointer + propertyOffset); + + printf( whiteSpace ); + + printf("%-20i ", value ); + + + + } else if( propertyDatatypeIndex == -3 ) { + + + + uintptr_t * value = ( uintptr_t * ) ( pointer + propertyOffset ); + + + + printf( whiteSpace ); + + printf( "%-20s", ( char * ) * value ); + + } else if( propertyDatatypeIndex > 0 ) { + + char * memberClassName = getClassName( propertyDatatypeIndex ); + + if( strcmp( memberClassName, "array" ) == 0 ) { + + struct array * memberArray = *(struct array ** )(pointer + propertyOffset) ; + + if( memberArray == NULL ) { + + printf(" this has to be fixed, array is not created.\n"); + + continue; + + } + + int numberRows = array_length( memberArray ); + + int * arrayPointer = ( int * ) memberArray->items; + + for (int k = 0; k < numberRows; ++k) + { + + void * pointer = array_get( memberArray, k ); + + short * row = (short*)(pointer); + + consoleManager_logObject( this, pointer, (int) *row, level ); + + } + + } + + + + } + + + printf("\n"); + + + } + + printf( whiteSpace ); + + printf( " }\n" ); + + + + } + +void consoleManager_log( consoleManager * this, int count, int datatypes[], ... ) { + + + + int level = 0; + + va_list args; + + va_start( args, count ); + + + + for (int i = 0; i < count; ++i) + { + int datatype = datatypes[i]; + + + + if( datatype == -2 ) { + + char * message = va_arg( args, char * ); + + printf("%s", message); + + } + + if( datatype == -1 ) { + + int message = va_arg( args, int ); + + printf("%i", message); + } + + if( datatype > 0 ) { + + + + void * voidPointer = va_arg( args, void * ); + + consoleManager_logObject( this, voidPointer, datatype, level++ ); + + + } + + printf(" "); + + } + + printf("\n"); + + va_end( args); + + } + +void consoleManager_error( consoleManager * this, char * message ) { + + #define ANSI_COLOR_RED "\x1b[31m" + #define ANSI_COLOR_GREEN "\x1b[32m" + #define ANSI_COLOR_DIM_YELLOW "\x1b[33m" + #define ANSI_COLOR_BLUE "\x1b[34m" + #define ANSI_COLOR_MAGENTA "\x1b[35m" + #define ANSI_COLOR_CYAN "\x1b[36m" + #define ANSI_COLOR_RESET "\x1b[0m" + + #define ANSI_COLOR_BRIGHT_YELLOW "\x1b[93m" + + printf( ANSI_COLOR_RED ); + + printf( "\n\n Error: " ); + + printf( "%s\n\n", message ); + + printf( ANSI_COLOR_RESET ); + + exit( 0 ); + + } + +void consoleManager_createHorisontalLine( consoleManager * this ) { + + struct winsize w; + + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + + for (int i = 0; i < w.ws_col; ++i) + { + + printf("-"); + + }; + + printf("\n"); + + } + +consoleManager consoleManager_new() { + + consoleManager instance; + + return instance; + +} + +consoleManager * consoleManager_newPointer() { + + struct consoleManager * pointer = malloc( sizeof ( struct consoleManager ) ); + + return pointer; + +} + diff --git a/application/demos/example.console.log/console.h b/application/demos/example.console.log/console.h new file mode 100644 index 0000000..57d565e --- /dev/null +++ b/application/demos/example.console.log/console.h @@ -0,0 +1,66 @@ +#ifndef _console + +#define _console + + +// Macros + +#define isCompatible(x, type) _Generic(x, type: true, default: false) + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + + +typedef struct consoleManager{ + + +} consoleManager; + +char * consoleManager_whiteSpace( consoleManager * this, int whiteSpaceCount ); + +void consoleManager_logObject( consoleManager * this, void * voidPointer, int classIndex, int level ); + +void consoleManager_log( consoleManager * this, int count, int datatypes[], ... ); + +void consoleManager_error( consoleManager * this, char * message ); + +void consoleManager_createHorisontalLine( consoleManager * this ); + +extern struct consoleManager * console; + +consoleManager consoleManager_new( ); + +consoleManager * consoleManager_newPointer( ); + +#endif + + +typedef struct consoleManager consoleManager; + + + diff --git a/application/demos/example.console.log/examples/example.console.log.c b/application/demos/example.console.log/examples/example.console.log.c new file mode 100644 index 0000000..f1aa82d --- /dev/null +++ b/application/demos/example.console.log/examples/example.console.log.c @@ -0,0 +1,76 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + +void main( ) { + + struct user * newUser = user_newPointer(); + + newUser->id = 1; + + newUser->username = "peter"; + + newUser->userlevel = 2134; + + newUser->hash = "#234234325"; + + + + struct array * addresses = newUser->addresses; + + + address * someAddress = address_newPointer(); + + someAddress->street = "HiLane"; + + someAddress->number = 1234; + + array_add( addresses, someAddress ); + + + + + address * otherAddress = address_newPointer(); + + otherAddress->street = "OtherLane"; + + otherAddress->number = 4567; + + array_add( addresses, otherAddress ); + + + + + printf("adresses count: %i\n\n", array_length( addresses ) ); + + + char * something = "this is from an char * "; + + int somethingElse = 123; + + + consoleManager_log( console, 10, (int[10]){ -2,-1,-2,-2,-1,-2,-2,-1,3,-2 }, "Goedendag", + 123456, + "en een andere text.", + something, + somethingElse, + "something en something", + "in native c", + 23456, + newUser, + "and some text again" ); + +} + +void abort( ) { + + +} + diff --git a/application/demos/example.console.log/examples/example.console.log.h b/application/demos/example.console.log/examples/example.console.log.h new file mode 100644 index 0000000..0bc52b1 --- /dev/null +++ b/application/demos/example.console.log/examples/example.console.log.h @@ -0,0 +1,30 @@ +#ifndef _example_console_log + +#define _example_console_log + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "../array.h" + +#include "../user.h" + +#include "../street.h" + +#include "../console.h" + + +void abort( ); + +void main( ); + +#endif diff --git a/application/demos/example.console.log/street.c b/application/demos/example.console.log/street.c new file mode 100644 index 0000000..13e612f --- /dev/null +++ b/application/demos/example.console.log/street.c @@ -0,0 +1,30 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + +void address_someMethod( address * this ) { + + + } + +address address_new() { + + address instance; + + return instance; + +} + +address * address_newPointer() { + + struct address * pointer = malloc( sizeof ( struct address ) ); + + return pointer; + +} + diff --git a/application/demos/example.console.log/street.h b/application/demos/example.console.log/street.h new file mode 100644 index 0000000..28c28f9 --- /dev/null +++ b/application/demos/example.console.log/street.h @@ -0,0 +1,39 @@ +#ifndef _street + +#define _street + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + + +typedef struct address{ + + char * street; + + int number; + + +} address; + +void address_someMethod( address * this ); + +address address_new( ); + +address * address_newPointer( ); + +#endif + + +typedef struct address address; + + + diff --git a/application/demos/example.console.log/text.c b/application/demos/example.console.log/text.c new file mode 100644 index 0000000..b9fa739 --- /dev/null +++ b/application/demos/example.console.log/text.c @@ -0,0 +1,205 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + +int text_operator_compare( text * this, text * b ) { + + if( strcmp( this->value, b->value ) == 0 ) { + + return 1; + + } else { + + return 0; + + } + + } + +text * text_operator_add( text * this, char * b ) { + + text_append( this, b ); + + return this; + + } + +void text_constructor( text * this, char * value ) { + + this->length = strlen( value ); + + if( this->length > this->capacity ) { + + this->capacity = this->length * 2; + + } + + this->value = malloc( sizeof( char ) * this->capacity ); + + strcpy( this->value, value ); + } + +char text_get( text * this, int index ) { + + return this->value[ index ]; + + } + +void text_resize( text * this, int size ) { + + this->value = realloc( this->value, size ); + + this->capacity = size; + + } + +text * text_append( text * this, char * value ) { + + int originalLength = this->length; + + int newValueLength = strlen( value ); + + this->length += newValueLength; + + if( this->length > this->capacity ) { + + text_resize( this, this->length * 2 ); + + } + + memcpy( this->value + originalLength, value, newValueLength + 1 ); + + return this; + + } + +text * text_appendBinary( text * this, char * value, int size ) { + + int originalLength = this->length; + + int newValueLength = size; + + this->length += newValueLength; + + if( this->length > this->capacity ) { + + text_resize( this, this->length * 2 ); + + } + + memcpy( this->value + originalLength, value, newValueLength + 1 ); + + return this; + + } + + +text * text_appendObject( text * this, text * object ) { + + int originalLength = this->length; + + int newValueLength = object->length; + + this->length += newValueLength; + + if( this->length > this->capacity ) { + + text_resize( this, this->length * 2 ); + + } + + memcpy(this->value + originalLength, object->value, newValueLength + 1); + + return this; + + } + +text * text_concatenate( text * this, char * value ) { + + text * copy = text_newPointer( this->value ); + + strcat( copy->value, value ); + + return copy; + + } + +char * text_toNative( text * this ) { + + return this->value; + + } + +char * text_whiteSpace( text * this, int whiteSpaceCount ) { + + char * output = malloc( 400 ); + + for (int i = 0; i < whiteSpaceCount; ++i) + { + + strcat( output, " " ); + + } + + return output; + + } + +void text_free( text * this ) { + + free( this->value ); + + free( this ); + + } + +text text_new(char * value) { + + text instance; + + instance.usevalue = -1; + + instance.capacity = 500; + + text_constructor( &instance, value); + + return instance; + +} + +text * text_newPointer(char * value) { + + struct text * pointer = malloc( sizeof ( struct text ) ); + + pointer->usevalue = -1; + + pointer->capacity = 500; + + text_constructor( pointer , value); + + return pointer; + +} + diff --git a/application/demos/example.console.log/text.h b/application/demos/example.console.log/text.h new file mode 100644 index 0000000..dd8f2e7 --- /dev/null +++ b/application/demos/example.console.log/text.h @@ -0,0 +1,75 @@ +#ifndef _text + +#define _text + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + + +typedef struct text{ + + char * value; + + int usevalue; + + int length; + + int capacity; + + +} text; + +int text_operator_compare( text * this, text * b ); + +text * text_operator_add( text * this, char * b ); + +void text_constructor( text * this, char * value ); + +char text_get( text * this, int index ); + +void text_resize( text * this, int size ); + +text * text_append( text * this, char * value ); + +text * text_appendBinary( text * this, char * value, int size ); + +text * text_appendObject( text * this, text * object ); + +text * text_concatenate( text * this, char * value ); + +char * text_toNative( text * this ); + +char * text_whiteSpace( text * this, int whiteSpaceCount ); + +void text_free( text * this ); + +text text_new( char * value ); + +text * text_newPointer( char * value ); + +#endif + + +typedef struct text text; + + + diff --git a/application/demos/example.console.log/user.c b/application/demos/example.console.log/user.c new file mode 100644 index 0000000..7853575 --- /dev/null +++ b/application/demos/example.console.log/user.c @@ -0,0 +1,47 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + +void user_constructor( user * this ) { + + + + + + } + +user user_new() { + + user instance; + + instance.addresses = array_newPointer(); + + user_constructor( &instance); + + return instance; + +} + +user * user_newPointer() { + + struct user * pointer = malloc( sizeof ( struct user ) ); + + pointer->addresses = array_newPointer(); + + user_constructor( pointer ); + + return pointer; + +} + diff --git a/application/demos/example.console.log/user.h b/application/demos/example.console.log/user.h new file mode 100644 index 0000000..94c07a4 --- /dev/null +++ b/application/demos/example.console.log/user.h @@ -0,0 +1,47 @@ +#ifndef _user + +#define _user + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + + +typedef struct user{ + + char * username; + + int id; + + int userlevel; + + char * hash; + + struct array * addresses; + + +} user; + +void user_constructor( user * this ); + +user user_new( ); + +user * user_newPointer( ); + +#endif + + +typedef struct user user; + + + diff --git a/application/demos/example.console.log/vector2.c b/application/demos/example.console.log/vector2.c new file mode 100644 index 0000000..0f3cf2e --- /dev/null +++ b/application/demos/example.console.log/vector2.c @@ -0,0 +1,88 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + +void vector2_constructor( vector2 * this, float x, float y ) { + + + + this->x = x; + + this->y = y; + + + + + + + } + + + +vector2 * vector2_operator_plus( vector2 * this, vector2 * b ) { + + vector2_add( this, b ); + + return this; + + } + +vector2 * vector2_operator_add( vector2 * this, struct vector2 * b ) { + + + + + + + return b; + } + +void vector2_add( vector2 * this, vector2 * a ) { + + this->x += a->x; + + this->y += a->y; + + } + +void vector2_subtract( vector2 * this, vector2 * a ) { + + this->x -= a->x; + + this->y -= a->y; + + } + +int vector2_length( vector2 * this ) { + + return this->x + this->y; + + } + +vector2 vector2_new(float x, float y) { + + vector2 instance; + + vector2_constructor( &instance, x, y); + + return instance; + +} + +vector2 * vector2_newPointer(float x, float y) { + + struct vector2 * pointer = malloc( sizeof ( struct vector2 ) ); + + vector2_constructor( pointer , x, y); + + return pointer; + +} + diff --git a/application/demos/example.console.log/vector2.h b/application/demos/example.console.log/vector2.h new file mode 100644 index 0000000..df6577b --- /dev/null +++ b/application/demos/example.console.log/vector2.h @@ -0,0 +1,49 @@ +#ifndef _vector2 + +#define _vector2 + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + + +typedef struct vector2{ + + float x; + + float y; + + +} vector2; + +void vector2_constructor( vector2 * this, float x, float y ); + +vector2 * vector2_operator_plus( vector2 * this, vector2 * b ); + +vector2 * vector2_operator_add( vector2 * this, struct vector2 * b ); + +void vector2_add( vector2 * this, vector2 * a ); + +void vector2_subtract( vector2 * this, vector2 * a ); + +int vector2_length( vector2 * this ); + +vector2 vector2_new( float x, float y ); + +vector2 * vector2_newPointer( float x, float y ); + +#endif + + +typedef struct vector2 vector2; + + + diff --git a/application/demos/example.opengl/array.c b/application/demos/example.opengl/array.c new file mode 100644 index 0000000..de777ed --- /dev/null +++ b/application/demos/example.opengl/array.c @@ -0,0 +1,231 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + +int array_length( array * this ) { + + return this->total; + + } + + +void * * array_data( array * this ) { + + return this->items; + + } + + +void * array_get( array * this, int index ) { + + if ( index >= 0 && index < this->total ){ + + return this->items[index]; + + } + + return NULL; + + } + + +void array_set( array * this, int index, void * item ) { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + +void array_resize( array * this, int capacity ) { + + void * * items = realloc( this->items, sizeof( void * ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + +void array_add( array * this, void * item ) { + + if ( this->capacity == this->total ){ + + array_resize( this, this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + +char * array_join( array * this, char * separator ) { + + int count = array_length( this ); + + text * result = text_newPointer( "" ); + + for (int i = 0; i < count; ++i) + { + + char * currentPart = this->items[ i ]; + + if( i > 0 ) { + + text_append( result, separator ); + + } + + text_append( result, currentPart ); + + } + + + + return result->value; + + } + +void array_delete( array * this, int index ) { + if ( index < 0 || index >= this->total ){ + + return; + + } + + this->items[index] = NULL; + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + this->items[i + 1] = NULL; + + } + + this->total--; + + if ( this->total > 0 && this->total == this->capacity / 4 ){ + + array_resize( this, this->capacity / 2 ); + + } + + } + + +int array_array_push( array * this, void * item ) { + + array_add( this, item ); + + return this->total; + + } + +void array_unshift( array * this, void * item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + array_resize( this, this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } + +void * array_pop( array * this ) { + + int length = this->total; + + int lastIndex = length - 1; + + void * lastItem = array_get( this, lastIndex ); + + array_delete( this, lastIndex ); + + return lastItem; + + } + +bool array_includes( array * this, char * value ) { + + int count = array_length( this ); + + for ( int index = 0; index < count; ++index ) + { + + char * currentText = array_get( this, index); + + + + if( char_operator_compare( currentText , value) ) { + + return true; + + } + + } + + return false; + + } + +array array_new() { + + array instance; + + instance.capacity = 10; + + instance.total = 0; + + instance.items = malloc( 10000000 ); + + return instance; + +} + +array * array_newPointer() { + + struct array * pointer = malloc( sizeof ( struct array ) ); + + pointer->capacity = 10; + + pointer->total = 0; + + pointer->items = malloc( 10000000 ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/array.h b/application/demos/example.opengl/array.h new file mode 100644 index 0000000..171a06d --- /dev/null +++ b/application/demos/example.opengl/array.h @@ -0,0 +1,71 @@ +#ifndef _array + +#define _array + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + + +typedef struct array{ + + int capacity; + + int total; + + void * * items; + + +} array; + +int array_length( array * this ); + +void * * array_data( array * this ); + +void * array_get( array * this, int index ); + +void array_set( array * this, int index, void * item ); + +void array_resize( array * this, int capacity ); + +void array_add( array * this, void * item ); + +char * array_join( array * this, char * separator ); + +void array_delete( array * this, int index ); + +int array_array_push( array * this, void * item ); + +void array_unshift( array * this, void * item ); + +void * array_pop( array * this ); + +bool array_includes( array * this, char * value ); + +array array_new( ); + +array * array_newPointer( ); + +#endif + + +typedef struct array array; + + + diff --git a/application/demos/example.opengl/cache.c b/application/demos/example.opengl/cache.c new file mode 100644 index 0000000..d3659a8 --- /dev/null +++ b/application/demos/example.opengl/cache.c @@ -0,0 +1,93 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + +text * cache_getFile( cache * this, char * filePath ) { + + struct file * currentFile = cache_getCachedFileByPath( this, filePath ); + + if( currentFile == NULL ) { + + + + struct text * content = fileSystem_readFile( filesystem, filePath, "binary" ); + + cache_addFile( this, filePath, content ); + + return content; + + } else { + + return currentFile->content; + + } + + } + +void cache_addFile( cache * this, char * filePath, struct text * content ) { + + struct file * newFile = file_newPointer(); + + newFile->filePath = filePath; + + newFile->content = content; + + array_add( this->files, newFile ); + + } + +struct file * cache_getCachedFileByPath( cache * this, char * filePath ) { + + struct array * files = this->files; + + int count = array_length( files ); + + for (int i = 0; i < count; ++i) + { + + file * currentFile = array_get( files, i ); + + if( char_operator_compare( currentFile->filePath , filePath) ) { + + + + return currentFile; + + } + + } + + return NULL; + + } + +cache cache_new() { + + cache instance; + + instance.files = array_newPointer(); + + return instance; + +} + +cache * cache_newPointer() { + + struct cache * pointer = malloc( sizeof ( struct cache ) ); + + pointer->files = array_newPointer(); + + return pointer; + +} + diff --git a/application/demos/example.opengl/cache.h b/application/demos/example.opengl/cache.h new file mode 100644 index 0000000..8630ff8 --- /dev/null +++ b/application/demos/example.opengl/cache.h @@ -0,0 +1,49 @@ +#ifndef _cache + +#define _cache + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "fileSystem.h" + +#include "file.h" + +#include "text.h" + +#include "array.h" + + +typedef struct cache{ + + struct array * files; + + +} cache; + +text * cache_getFile( cache * this, char * filePath ); + +void cache_addFile( cache * this, char * filePath, struct text * content ); + +struct file * cache_getCachedFileByPath( cache * this, char * filePath ); + +cache cache_new( ); + +cache * cache_newPointer( ); + +#endif + + +typedef struct cache cache; + + + diff --git a/application/demos/example.opengl/char.c b/application/demos/example.opengl/char.c new file mode 100644 index 0000000..78e7c91 --- /dev/null +++ b/application/demos/example.opengl/char.c @@ -0,0 +1,169 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + +int char_operator_compare( char * this, char * b ) { + + return char_compare( this, b ); + + } + +void char_operator_add( char * this, char * b ) { + + + strcat( this, b ); + + } + +char * char_operator_plus( char * this, char * b ) { + + return char_concatenate( this, b ); + + } + +int char_compare( char * this, char * b ) { + + return strcmp( this, b ) == 0; + + } + +char * char_concatenate( char * this, char * b ) { + + int lengthA = strlen( this ); + + int lengthB = strlen( b ); + + char * pointer = this; + + char * copy = ( char * ) malloc( ( lengthA + lengthB + 1 ) * sizeof( char ) ); + + int idx = 0; + + while ( * pointer != '\0' ){ + + copy[idx++] = *pointer++; + + } + + pointer = &b[0]; + + while ( * pointer != '\0' ){ + + copy[idx++] = *pointer++; + + } + + copy[ idx++ ] = '\0'; + + return ©[0]; + + } + +int char_includes( char * this, char * compare ) { + + if ( strstr( this, compare ) != NULL ) { + + return 1; + + } else { + + return 0; + + } + } + +char * char_clone( char * this ) { + + char * newCopy = malloc( sizeof( char ) * strlen( this ) ); + + strcpy( newCopy, this ); + + return newCopy; + + } + +char * char_copy( char * this ) { + + char * newCopy = malloc( sizeof( char ) * strlen( this ) ); + + strcpy( newCopy, this ); + + return newCopy; + + } + +struct array * char_split( char * this, char * needle ) { + + char * haystack = char_clone( this ); + + struct array * keys = array_newPointer(); + + int count = 0; + + char * tmp = haystack; + + char * token = strtok( haystack, needle ); + + int i = 0; + + while ( token ) { + + array_add( keys, token ); + + + + token = (char *) strtok( NULL, needle ); + + } + + return keys; + + + } + + + +char * char_removeWhitespaceLeft( char * this ) { + char * s = this; + + while(isspace(*s)) s++; + + return s; + } + + +char * char_removeWhitespaceRight( char * this ) { + char * s = this; + + char* back = s + strlen(s); + + while( isspace( *--back ) ); + + *( back + 1 ) = '\0'; + + return s; + } + + +char * char_removeWhitespace( char * this ) { + + return char_removeWhitespaceRight(char_removeWhitespaceLeft( this ) ); + + } + diff --git a/application/demos/example.opengl/char.h b/application/demos/example.opengl/char.h new file mode 100644 index 0000000..494d5e8 --- /dev/null +++ b/application/demos/example.opengl/char.h @@ -0,0 +1,56 @@ +#ifndef _char + +#define _char + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + + +int char_operator_compare( char * this, char * b ); + +void char_operator_add( char * this, char * b ); + +char * char_operator_plus( char * this, char * b ); + +int char_compare( char * this, char * b ); + +char * char_concatenate( char * this, char * b ); + +int char_includes( char * this, char * compare ); + +char * char_clone( char * this ); + +char * char_copy( char * this ); + +struct array * char_split( char * this, char * needle ); + +char * char_removeWhitespaceLeft( char * this ); + +char * char_removeWhitespaceRight( char * this ); + +char * char_removeWhitespace( char * this ); + +#endif diff --git a/application/demos/example.opengl/classConfiguration.c b/application/demos/example.opengl/classConfiguration.c new file mode 100644 index 0000000..be2069c --- /dev/null +++ b/application/demos/example.opengl/classConfiguration.c @@ -0,0 +1,1530 @@ +#include + +char * __ClassNames[TOTAL_CLASS_COUNT] = { "opengl", "event", "keyboard", "screen", "mouse", "vector2", "vector", "int", "quadMesh", "element", "vector4", "windowManager", "Hints", "resourceManager", "texture2D", "tesselation", "mesh", "unsignedIntegerArray", "floatArray", "program", "shader", "attribute", "sampler2D", "vector3", "array", "text", "char", "fileSystem", "consoleManager", "http", "headerManager", "header", "request", "cache", "file", "mimeTypes", "uniform", "member", "block", "fontRenderer", "renderPass", "compute2", "compute", "font", "quads", "pipeline", "eventManger", "vector_char_pointer", "vector_quadMesh", "vector_element", "vector_int", "vector_vector2" }; + +int __ClassMethodCount[TOTAL_CLASS_COUNT] = { 14, 0, 0, 0, 0, 6, 8, 2, 0, 14, 4, 2, 0, 1, 0, 3, 9, 11, 11, 14, 3, 0, 4, 4, 12, 12, 12, 8, 5, 7, 7, 0, 2, 3, 0, 3, 0, 0, 12, 3, 2, 2, 2, 3, 8, 2, 2, 8, 8, 8, 8, 8 }; + +int __ClassPropertyCount[TOTAL_CLASS_COUNT] = { 11, 3, 5, 2, 3, 2, 3, 0, 8, 14, 4, 4, 5, 0, 5, 4, 14, 3, 3, 6, 1, 3, 19, 3, 3, 4, 0, 0, 0, 9, 1, 2, 9, 1, 2, 2, 6, 7, 9, 1, 3, 2, 2, 4, 7, 3, 5, 3, 3, 3, 3, 3 }; + +char * __ClassPropertyNames[TOTAL_CLASS_COUNT][30] = { + { "mainDisplay" , "mainWindow" , "MainScreen" , "RootWindow" , "lastTime" , "startTime" , "frameCount" , "testSampler" , "windowManager" , "eventManger" , "pipeline" }, + { "mouse" , "screen" , "keyboard" }, + { "keyCode" , "shiftKey" , "ctrlKey" , "altKey" , "metaKey" }, + { "size" , "position" }, + { "position" , "button" , "eventTypes" }, + { "x" , "y" }, + { "capacity" , "total" , "items" }, + { }, + { "position" , "size" , "color" , "zIndex" , "opacity" , "textureIndex" , "features" , "elementIndex" }, + { "index" , "position" , "size" , "backgroundColor" , "originalPosition" , "originalSize" , "originalBackgroundColor" , "opacity" , "backgroundImagePath" , "useBackgroundImage" , "features" , "featureNames" , "textureIndex" , "background" }, + { "x" , "y" , "z" , "w" }, + { "mainDisplay" , "mainWindow" , "MainScreen" , "RootWindow" }, + { "flags" , "functions" , "decorations" , "inputMode" , "status" }, + { }, + { "data" , "width" , "height" , "hasAlpha" , "offset" }, + { "program" , "mesh" , "font" , "samplerArray" }, + { "program" , "indices" , "textureCoordinates" , "vertexCoordinates" , "normalCoordinates" , "blocks" , "vertexArrayObject" , "uniformBuffer" , "indexBuffer" , "vertexbuffer" , "textureCoordinateBuffer" , "meshIndexBuffer" , "uvBuffer" , "uniformBuffers" }, + { "capacity" , "total" , "items" }, + { "capacity" , "total" , "items" }, + { "samplerIndex" , "uniforms" , "attributes" , "blocks" , "shaders" , "glProgram" }, + { "glShader" }, + { "name[64]" , "location" , "type" }, + { "texture" , "textures" , "glTexture" , "binded" , "filter" , "MIN_FILTER" , "MAG_FILTER" , "WRAP_S" , "WRAP_T" , "datatype" , "format" , "internalFormat" , "target" , "type" , "cubeSize" , "border" , "generateMipmap" , "UNPACK_ALIGNMENT" , "index" }, + { "x" , "y" , "z" }, + { "capacity" , "total" , "items" }, + { "value" , "usevalue" , "length" , "capacity" }, + { }, + { }, + { }, + { "socket" , "hostAddress" , "hostAddresslength" , "filesystem" , "mimetypes" , "headers" , "useSSL" , "sslContext" , "requestCallback" }, + { "headers" }, + { "name" , "value" }, + { "connection" , "address" , "port" , "url" , "method" , "version" , "mimeType" , "extension" , "headers" }, + { "files" }, + { "filePath" , "content" }, + { "extensions" , "mimeTypes" }, + { "name[64]" , "index" , "location" , "offset" , "size" , "type" }, + { "name" , "index" , "offset" , "size" , "type" , "arrayStride" , "topLevelSize" }, + { "members" , "buffer" , "index" , "bufferType" , "bufferSize" , "bindingPoint" , "name" , "data" , "autoUpload" }, + { "data" }, + { "enabled" , "shader" , "mesh" }, + { "program" , "active" }, + { "program" , "active" }, + { "program" , "mesh" , "font" , "samplerArray" }, + { "mesh" , "font" , "samplerArray" , "program" , "meshes" , "elements" , "mouseOverElements" }, + { "renderPasses" , "classIndices" , "methodIndices" }, + { "mainDisplay" , "mainWindow" , "RootWindow" , "lastEvent" , "lastMouseDownTime" }, + { "capacity" , "total" , "items" }, + { "capacity" , "total" , "items" }, + { "capacity" , "total" , "items" }, + { "capacity" , "total" , "items" }, + { "capacity" , "total" , "items" } + }; + +char * __ClassMethodNames[TOTAL_CLASS_COUNT][30] = { + { "initialize" , "showExtensions" , "showVersion" , "setupTime" , "setupManagers" , "setupWindow" , "setupRenderLoop" , "setupPipeline" , "clockToMilliseconds" , "render" , "displayFPS" , "clear" , "clearColor" , "swapBuffers" }, + { }, + { }, + { }, + { }, + { "constructor" , "operator_plus" , "operator_add" , "add" , "subtract" , "length" }, + { "length" , "get" , "set" , "resize" , "add" , "delete" , "array_push" , "unshift" }, + { "toText" , "negative" }, + { }, + { "constructor" , "colorConverter" , "setOriginal" , "setter_size" , "setter_position" , "featureIsEnabled" , "getFeatureValueByFeatureName" , "updateFeature" , "setter_background" , "click" , "mousedown" , "mouseup" , "mouseover" , "mouseleave" }, + { "constructor" , "operator_plus" , "operator_add" , "add" }, + { "setupDisplay" , "setupWindow" }, + { }, + { "loadPngImage" }, + { }, + { "textFromNumber" , "prepare" , "render" }, + { "getUniformBlock" , "bindBlock" , "setProgram" , "getGLTypeSize" , "getComponentType" , "getItemSize" , "createBuffer" , "createBuffers" , "createOrderedTriangleStripQuad" }, + { "length" , "get" , "set" , "resize" , "addVector2" , "addVector3" , "add" , "delete" , "array_push" , "unshift" , "pop" }, + { "length" , "get" , "set" , "resize" , "addVector2" , "addVector3" , "add" , "delete" , "array_push" , "unshift" , "pop" }, + { "addShader" , "glGetProgramResourceiv" , "glGetProgramResourceName" , "extractBlocks" , "createNewBlock" , "getBlock" , "create" , "bindBlock" , "use" , "extractUniforms" , "extractAttributes" , "getAttributeByName" , "setUniform" , "updateSampler2D" }, + { "constructor" , "loadFromFile" , "checkShaderForErrors" }, + { }, + { "constructor" , "addTexture" , "getTextureIndex" , "bind" }, + { "constructor" , "operator_plus" , "operator_add" , "add" }, + { "length" , "data" , "get" , "set" , "resize" , "add" , "join" , "delete" , "array_push" , "unshift" , "pop" , "includes" }, + { "operator_compare" , "operator_add" , "constructor" , "get" , "resize" , "append" , "appendBinary" , "appendObject" , "concatenate" , "toNative" , "whiteSpace" , "free" }, + { "operator_compare" , "operator_add" , "operator_plus" , "compare" , "concatenate" , "includes" , "clone" , "copy" , "split" , "removeWhitespaceLeft" , "removeWhitespaceRight" , "removeWhitespace" }, + { "writeFile" , "readDir" , "readFile" , "readBinaryFile" , "ensureDirectory" , "makeDirectory" , "exists" , "isDirectory" }, + { "whiteSpace" , "logObject" , "log" , "error" , "createHorisontalLine" }, + { "createServer" , "initializeOpenSSL" , "listen" , "getExtension" , "logRequest" , "acceptConnection" , "dump_buffer" }, + { "parse" , "display" , "add" , "set" , "getHeaderIndex" , "getValue" , "get" }, + { }, + { "constructor" , "free" }, + { "getFile" , "addFile" , "getCachedFileByPath" }, + { }, + { "constructor" , "add" , "getByExtension" }, + { }, + { }, + { "add" , "enableAutoUpload" , "getBufferTypeText" , "createBuffer" , "upload" , "mapBufferError" , "getMemberArray" , "setMemberArrayRow" , "setMemberArray" , "setMemberItem" , "setData" , "setMember" }, + { "loadFont" , "draw_bitmap" , "show_image" }, + { "prepare" , "render" }, + { "prepare" , "render" }, + { "prepare" , "render" }, + { "textFromNumber" , "prepare" , "render" }, + { "textFromNumber" , "prepare" , "sortOpacity" , "createMeshes" , "updateMesh" , "callElementEvents" , "integerContains" , "render" }, + { "addRenderPass" , "render" }, + { "constructor" , "fetchEvent" }, + { "length" , "get" , "set" , "resize" , "add" , "delete" , "array_push" , "unshift" }, + { "length" , "get" , "set" , "resize" , "add" , "delete" , "array_push" , "unshift" }, + { "length" , "get" , "set" , "resize" , "add" , "delete" , "array_push" , "unshift" }, + { "length" , "get" , "set" , "resize" , "add" , "delete" , "array_push" , "unshift" }, + { "length" , "get" , "set" , "resize" , "add" , "delete" , "array_push" , "unshift" } + }; + +int __ClassPropertyOffsets[TOTAL_CLASS_COUNT][30] = { + { offsetof( opengl, mainDisplay ) , offsetof( opengl, mainWindow ) , offsetof( opengl, MainScreen ) , offsetof( opengl, RootWindow ) , offsetof( opengl, lastTime ) , offsetof( opengl, startTime ) , offsetof( opengl, frameCount ) , offsetof( opengl, testSampler ) , offsetof( opengl, windowManager ) , offsetof( opengl, eventManger ) , offsetof( opengl, pipeline ) }, + { offsetof( event, mouse ) , offsetof( event, screen ) , offsetof( event, keyboard ) }, + { offsetof( keyboard, keyCode ) , offsetof( keyboard, shiftKey ) , offsetof( keyboard, ctrlKey ) , offsetof( keyboard, altKey ) , offsetof( keyboard, metaKey ) }, + { offsetof( screen, size ) , offsetof( screen, position ) }, + { offsetof( mouse, position ) , offsetof( mouse, button ) , offsetof( mouse, eventTypes ) }, + { offsetof( vector2, x ) , offsetof( vector2, y ) }, + { }, + { offsetof( quadMesh, position ) , offsetof( quadMesh, size ) , offsetof( quadMesh, color ) , offsetof( quadMesh, zIndex ) , offsetof( quadMesh, opacity ) , offsetof( quadMesh, textureIndex ) , offsetof( quadMesh, features ) , offsetof( quadMesh, elementIndex ) }, + { offsetof( element, index ) , offsetof( element, position ) , offsetof( element, size ) , offsetof( element, backgroundColor ) , offsetof( element, originalPosition ) , offsetof( element, originalSize ) , offsetof( element, originalBackgroundColor ) , offsetof( element, opacity ) , offsetof( element, backgroundImagePath ) , offsetof( element, useBackgroundImage ) , offsetof( element, features ) , offsetof( element, featureNames ) , offsetof( element, textureIndex ) , offsetof( element, background ) }, + { offsetof( vector4, x ) , offsetof( vector4, y ) , offsetof( vector4, z ) , offsetof( vector4, w ) }, + { offsetof( windowManager, mainDisplay ) , offsetof( windowManager, mainWindow ) , offsetof( windowManager, MainScreen ) , offsetof( windowManager, RootWindow ) }, + { offsetof( Hints, flags ) , offsetof( Hints, functions ) , offsetof( Hints, decorations ) , offsetof( Hints, inputMode ) , offsetof( Hints, status ) }, + { }, + { offsetof( texture2D, data ) , offsetof( texture2D, width ) , offsetof( texture2D, height ) , offsetof( texture2D, hasAlpha ) , offsetof( texture2D, offset ) }, + { offsetof( tesselation, program ) , offsetof( tesselation, mesh ) , offsetof( tesselation, font ) , offsetof( tesselation, samplerArray ) }, + { offsetof( mesh, program ) , offsetof( mesh, indices ) , offsetof( mesh, textureCoordinates ) , offsetof( mesh, vertexCoordinates ) , offsetof( mesh, normalCoordinates ) , offsetof( mesh, blocks ) , offsetof( mesh, vertexArrayObject ) , offsetof( mesh, uniformBuffer ) , offsetof( mesh, indexBuffer ) , offsetof( mesh, vertexbuffer ) , offsetof( mesh, textureCoordinateBuffer ) , offsetof( mesh, meshIndexBuffer ) , offsetof( mesh, uvBuffer ) , offsetof( mesh, uniformBuffers ) }, + { offsetof( unsignedIntegerArray, capacity ) , offsetof( unsignedIntegerArray, total ) , offsetof( unsignedIntegerArray, items ) }, + { offsetof( floatArray, capacity ) , offsetof( floatArray, total ) , offsetof( floatArray, items ) }, + { offsetof( program, samplerIndex ) , offsetof( program, uniforms ) , offsetof( program, attributes ) , offsetof( program, blocks ) , offsetof( program, shaders ) , offsetof( program, glProgram ) }, + { offsetof( shader, glShader ) }, + { offsetof( attribute, name[64] ) , offsetof( attribute, location ) , offsetof( attribute, type ) }, + { offsetof( sampler2D, texture ) , offsetof( sampler2D, textures ) , offsetof( sampler2D, glTexture ) , offsetof( sampler2D, binded ) , offsetof( sampler2D, filter ) , offsetof( sampler2D, MIN_FILTER ) , offsetof( sampler2D, MAG_FILTER ) , offsetof( sampler2D, WRAP_S ) , offsetof( sampler2D, WRAP_T ) , offsetof( sampler2D, datatype ) , offsetof( sampler2D, format ) , offsetof( sampler2D, internalFormat ) , offsetof( sampler2D, target ) , offsetof( sampler2D, type ) , offsetof( sampler2D, cubeSize ) , offsetof( sampler2D, border ) , offsetof( sampler2D, generateMipmap ) , offsetof( sampler2D, UNPACK_ALIGNMENT ) , offsetof( sampler2D, index ) }, + { offsetof( vector3, x ) , offsetof( vector3, y ) , offsetof( vector3, z ) }, + { offsetof( array, capacity ) , offsetof( array, total ) , offsetof( array, items ) }, + { offsetof( text, value ) , offsetof( text, usevalue ) , offsetof( text, length ) , offsetof( text, capacity ) }, + { }, + { }, + { }, + { offsetof( http, socket ) , offsetof( http, hostAddress ) , offsetof( http, hostAddresslength ) , offsetof( http, filesystem ) , offsetof( http, mimetypes ) , offsetof( http, headers ) , offsetof( http, useSSL ) , offsetof( http, sslContext ) }, + { offsetof( headerManager, headers ) }, + { offsetof( header, name ) , offsetof( header, value ) }, + { offsetof( request, connection ) , offsetof( request, address ) , offsetof( request, port ) , offsetof( request, url ) , offsetof( request, method ) , offsetof( request, version ) , offsetof( request, mimeType ) , offsetof( request, extension ) , offsetof( request, headers ) }, + { offsetof( cache, files ) }, + { offsetof( file, filePath ) , offsetof( file, content ) }, + { offsetof( mimeTypes, extensions ) , offsetof( mimeTypes, mimeTypes ) }, + { offsetof( uniform, name[64] ) , offsetof( uniform, index ) , offsetof( uniform, location ) , offsetof( uniform, offset ) , offsetof( uniform, size ) , offsetof( uniform, type ) }, + { offsetof( member, name ) , offsetof( member, index ) , offsetof( member, offset ) , offsetof( member, size ) , offsetof( member, type ) , offsetof( member, arrayStride ) , offsetof( member, topLevelSize ) }, + { offsetof( block, members ) , offsetof( block, buffer ) , offsetof( block, index ) , offsetof( block, bufferType ) , offsetof( block, bufferSize ) , offsetof( block, bindingPoint ) , offsetof( block, name ) , offsetof( block, data ) , offsetof( block, autoUpload ) }, + { offsetof( fontRenderer, data ) }, + { offsetof( renderPass, enabled ) , offsetof( renderPass, shader ) , offsetof( renderPass, mesh ) }, + { offsetof( compute2, program ) , offsetof( compute2, active ) }, + { offsetof( compute, program ) , offsetof( compute, active ) }, + { offsetof( font, program ) , offsetof( font, mesh ) , offsetof( font, font ) , offsetof( font, samplerArray ) }, + { offsetof( quads, mesh ) , offsetof( quads, font ) , offsetof( quads, samplerArray ) , offsetof( quads, program ) , offsetof( quads, meshes ) , offsetof( quads, elements ) , offsetof( quads, mouseOverElements ) }, + { offsetof( pipeline, renderPasses ) , offsetof( pipeline, classIndices ) , offsetof( pipeline, methodIndices ) }, + { offsetof( eventManger, mainDisplay ) , offsetof( eventManger, mainWindow ) , offsetof( eventManger, RootWindow ) , offsetof( eventManger, lastEvent ) , offsetof( eventManger, lastMouseDownTime ) } + }; + +int __ClassPropertyDatatypeIndices[TOTAL_CLASS_COUNT][30] = { + {1 , 1 , -5 , 1 , -5 , 1 , -5 , 22 , 11 , 46 , 45 }, + {4 , 3 , 2 }, + {-5 , 1 , 1 , 1 , 1 }, + {5 , 5 }, + {5 , -5 , 6 }, + {1 , 1 }, + {-5 , -5 , 1 }, + { }, + {5 , 5 , 23 , 1 , 1 , -5 , -5 , -5 }, + {-5 , 23 , 5 , 23 , 23 , 5 , 23 , 1 , -3 , 1 , -5 , 6 , -5 , 1 }, + {1 , 1 , 1 , 1 }, + {1 , 1 , -5 , 1 }, + {-6 , -6 , -6 , -6 , -6 }, + { }, + {1 , -5 , -5 , -5 , 5 }, + {19 , 16 , 39 , 22 }, + {19 , 17 , 18 , 18 , 18 , 24 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 17 }, + {-5 , -5 , -5 }, + {-5 , -5 , 1 }, + {1 , 24 , 24 , 24 , 24 , 1 }, + {1 }, + {1 , 1 , 1 }, + {14 , 24 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 23 , 1 , 1 , 1 , 1 }, + {1 , 1 , 1 }, + {-5 , -5 , 1 }, + {-3 , -5 , -5 , -5 }, + { }, + { }, + { }, + {-5 , 1 , -5 , 27 , 35 , 30 , -5 , 1 , 1 }, + {24 }, + {-3 , -3 }, + {-3 , -3 , -5 , -3 , -3 , -3 , -3 , -3 , 30 }, + {24 }, + {-3 , 25 }, + {24 , 24 }, + {-2 , 1 , 1 , 1 , 1 , 1 }, + {-3 , 1 , 1 , 1 , 1 , 1 , 1 }, + {24 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 }, + {1 }, + {1 , 20 , 16 }, + {19 , -5 }, + {19 , -5 }, + {19 , 16 , 39 , 22 }, + {16 , 39 , 22 , 19 , 6 , 6 , 6 }, + {24 , 6 , 6 }, + {1 , 1 , 1 , 1 , 1 }, + {-5 , -5 , 1 }, + {-5 , -5 , 8 }, + {-5 , -5 , 9 }, + {-5 , -5 , -5 }, + {-5 , -5 , 5 } + }; + +void getArrayByClassIndex( int size, void * * voidArray, int * structByteSize, int classIndex ) { + + switch( classIndex ) { + + case 0: + + voidArray = ( void ** ) ( struct opengl * ) malloc( sizeof( struct opengl ) * size ); + + *structByteSize = sizeof( struct opengl ); + + break; + + case 1: + + voidArray = ( void ** ) ( struct event * ) malloc( sizeof( struct event ) * size ); + + *structByteSize = sizeof( struct event ); + + break; + + case 2: + + voidArray = ( void ** ) ( struct keyboard * ) malloc( sizeof( struct keyboard ) * size ); + + *structByteSize = sizeof( struct keyboard ); + + break; + + case 3: + + voidArray = ( void ** ) ( struct screen * ) malloc( sizeof( struct screen ) * size ); + + *structByteSize = sizeof( struct screen ); + + break; + + case 4: + + voidArray = ( void ** ) ( struct mouse * ) malloc( sizeof( struct mouse ) * size ); + + *structByteSize = sizeof( struct mouse ); + + break; + + case 5: + + voidArray = ( void ** ) ( struct vector2 * ) malloc( sizeof( struct vector2 ) * size ); + + *structByteSize = sizeof( struct vector2 ); + + break; + + case 8: + + voidArray = ( void ** ) ( struct quadMesh * ) malloc( sizeof( struct quadMesh ) * size ); + + *structByteSize = sizeof( struct quadMesh ); + + break; + + case 9: + + voidArray = ( void ** ) ( struct element * ) malloc( sizeof( struct element ) * size ); + + *structByteSize = sizeof( struct element ); + + break; + + case 10: + + voidArray = ( void ** ) ( struct vector4 * ) malloc( sizeof( struct vector4 ) * size ); + + *structByteSize = sizeof( struct vector4 ); + + break; + + case 11: + + voidArray = ( void ** ) ( struct windowManager * ) malloc( sizeof( struct windowManager ) * size ); + + *structByteSize = sizeof( struct windowManager ); + + break; + + case 12: + + voidArray = ( void ** ) ( struct Hints * ) malloc( sizeof( struct Hints ) * size ); + + *structByteSize = sizeof( struct Hints ); + + break; + + case 13: + + voidArray = ( void ** ) ( struct resourceManager * ) malloc( sizeof( struct resourceManager ) * size ); + + *structByteSize = sizeof( struct resourceManager ); + + break; + + case 14: + + voidArray = ( void ** ) ( struct texture2D * ) malloc( sizeof( struct texture2D ) * size ); + + *structByteSize = sizeof( struct texture2D ); + + break; + + case 15: + + voidArray = ( void ** ) ( struct tesselation * ) malloc( sizeof( struct tesselation ) * size ); + + *structByteSize = sizeof( struct tesselation ); + + break; + + case 16: + + voidArray = ( void ** ) ( struct mesh * ) malloc( sizeof( struct mesh ) * size ); + + *structByteSize = sizeof( struct mesh ); + + break; + + case 17: + + voidArray = ( void ** ) ( struct unsignedIntegerArray * ) malloc( sizeof( struct unsignedIntegerArray ) * size ); + + *structByteSize = sizeof( struct unsignedIntegerArray ); + + break; + + case 18: + + voidArray = ( void ** ) ( struct floatArray * ) malloc( sizeof( struct floatArray ) * size ); + + *structByteSize = sizeof( struct floatArray ); + + break; + + case 19: + + voidArray = ( void ** ) ( struct program * ) malloc( sizeof( struct program ) * size ); + + *structByteSize = sizeof( struct program ); + + break; + + case 20: + + voidArray = ( void ** ) ( struct shader * ) malloc( sizeof( struct shader ) * size ); + + *structByteSize = sizeof( struct shader ); + + break; + + case 21: + + voidArray = ( void ** ) ( struct attribute * ) malloc( sizeof( struct attribute ) * size ); + + *structByteSize = sizeof( struct attribute ); + + break; + + case 22: + + voidArray = ( void ** ) ( struct sampler2D * ) malloc( sizeof( struct sampler2D ) * size ); + + *structByteSize = sizeof( struct sampler2D ); + + break; + + case 23: + + voidArray = ( void ** ) ( struct vector3 * ) malloc( sizeof( struct vector3 ) * size ); + + *structByteSize = sizeof( struct vector3 ); + + break; + + case 24: + + voidArray = ( void ** ) ( struct array * ) malloc( sizeof( struct array ) * size ); + + *structByteSize = sizeof( struct array ); + + break; + + case 25: + + voidArray = ( void ** ) ( struct text * ) malloc( sizeof( struct text ) * size ); + + *structByteSize = sizeof( struct text ); + + break; + + case 27: + + voidArray = ( void ** ) ( struct fileSystem * ) malloc( sizeof( struct fileSystem ) * size ); + + *structByteSize = sizeof( struct fileSystem ); + + break; + + case 28: + + voidArray = ( void ** ) ( struct consoleManager * ) malloc( sizeof( struct consoleManager ) * size ); + + *structByteSize = sizeof( struct consoleManager ); + + break; + + case 29: + + voidArray = ( void ** ) ( struct http * ) malloc( sizeof( struct http ) * size ); + + *structByteSize = sizeof( struct http ); + + break; + + case 30: + + voidArray = ( void ** ) ( struct headerManager * ) malloc( sizeof( struct headerManager ) * size ); + + *structByteSize = sizeof( struct headerManager ); + + break; + + case 31: + + voidArray = ( void ** ) ( struct header * ) malloc( sizeof( struct header ) * size ); + + *structByteSize = sizeof( struct header ); + + break; + + case 32: + + voidArray = ( void ** ) ( struct request * ) malloc( sizeof( struct request ) * size ); + + *structByteSize = sizeof( struct request ); + + break; + + case 33: + + voidArray = ( void ** ) ( struct cache * ) malloc( sizeof( struct cache ) * size ); + + *structByteSize = sizeof( struct cache ); + + break; + + case 34: + + voidArray = ( void ** ) ( struct file * ) malloc( sizeof( struct file ) * size ); + + *structByteSize = sizeof( struct file ); + + break; + + case 35: + + voidArray = ( void ** ) ( struct mimeTypes * ) malloc( sizeof( struct mimeTypes ) * size ); + + *structByteSize = sizeof( struct mimeTypes ); + + break; + + case 36: + + voidArray = ( void ** ) ( struct uniform * ) malloc( sizeof( struct uniform ) * size ); + + *structByteSize = sizeof( struct uniform ); + + break; + + case 37: + + voidArray = ( void ** ) ( struct member * ) malloc( sizeof( struct member ) * size ); + + *structByteSize = sizeof( struct member ); + + break; + + case 38: + + voidArray = ( void ** ) ( struct block * ) malloc( sizeof( struct block ) * size ); + + *structByteSize = sizeof( struct block ); + + break; + + case 39: + + voidArray = ( void ** ) ( struct fontRenderer * ) malloc( sizeof( struct fontRenderer ) * size ); + + *structByteSize = sizeof( struct fontRenderer ); + + break; + + case 40: + + voidArray = ( void ** ) ( struct renderPass * ) malloc( sizeof( struct renderPass ) * size ); + + *structByteSize = sizeof( struct renderPass ); + + break; + + case 41: + + voidArray = ( void ** ) ( struct compute2 * ) malloc( sizeof( struct compute2 ) * size ); + + *structByteSize = sizeof( struct compute2 ); + + break; + + case 42: + + voidArray = ( void ** ) ( struct compute * ) malloc( sizeof( struct compute ) * size ); + + *structByteSize = sizeof( struct compute ); + + break; + + case 43: + + voidArray = ( void ** ) ( struct font * ) malloc( sizeof( struct font ) * size ); + + *structByteSize = sizeof( struct font ); + + break; + + case 44: + + voidArray = ( void ** ) ( struct quads * ) malloc( sizeof( struct quads ) * size ); + + *structByteSize = sizeof( struct quads ); + + break; + + case 45: + + voidArray = ( void ** ) ( struct pipeline * ) malloc( sizeof( struct pipeline ) * size ); + + *structByteSize = sizeof( struct pipeline ); + + break; + + case 46: + + voidArray = ( void ** ) ( struct eventManger * ) malloc( sizeof( struct eventManger ) * size ); + + *structByteSize = sizeof( struct eventManger ); + + break; + + } + +} + +void callMethodOfClass( int classIndex, int methodIndex, void * object ) { + + switch( classIndex ) { + + case 0: + + switch( methodIndex ) { + + case 0: + + opengl_initialize( object ); + + break; + + case 1: + + opengl_showExtensions( object ); + + break; + + case 2: + + opengl_showVersion( object ); + + break; + + case 3: + + opengl_setupTime( object ); + + break; + + case 4: + + opengl_setupManagers( object ); + + break; + + case 5: + + opengl_setupWindow( object ); + + break; + + case 6: + + opengl_setupRenderLoop( object ); + + break; + + case 7: + + opengl_setupPipeline( object ); + + break; + + case 9: + + opengl_render( object ); + + break; + + case 10: + + opengl_displayFPS( object ); + + break; + + case 13: + + opengl_swapBuffers( object ); + + break; + + } + + break; + + case 1: + + switch( methodIndex ) { + + } + + break; + + case 2: + + switch( methodIndex ) { + + } + + break; + + case 3: + + switch( methodIndex ) { + + } + + break; + + case 4: + + switch( methodIndex ) { + + } + + break; + + case 5: + + switch( methodIndex ) { + + case 5: + + vector2_length( object ); + + break; + + } + + break; + + case 8: + + switch( methodIndex ) { + + } + + break; + + case 9: + + switch( methodIndex ) { + + case 0: + + element_constructor( object ); + + break; + + case 2: + + element_setOriginal( object ); + + break; + + case 7: + + element_updateFeature( object ); + + break; + + case 9: + + element_click( object ); + + break; + + case 10: + + element_mousedown( object ); + + break; + + case 11: + + element_mouseup( object ); + + break; + + case 12: + + element_mouseover( object ); + + break; + + case 13: + + element_mouseleave( object ); + + break; + + } + + break; + + case 10: + + switch( methodIndex ) { + + } + + break; + + case 11: + + switch( methodIndex ) { + + case 0: + + windowManager_setupDisplay( object ); + + break; + + case 1: + + windowManager_setupWindow( object ); + + break; + + } + + break; + + case 12: + + switch( methodIndex ) { + + } + + break; + + case 13: + + switch( methodIndex ) { + + } + + break; + + case 14: + + switch( methodIndex ) { + + } + + break; + + case 15: + + switch( methodIndex ) { + + case 1: + + tesselation_prepare( object ); + + break; + + case 2: + + tesselation_render( object ); + + break; + + } + + break; + + case 16: + + switch( methodIndex ) { + + case 7: + + mesh_createBuffers( object ); + + break; + + case 8: + + mesh_createOrderedTriangleStripQuad( object ); + + break; + + } + + break; + + case 17: + + switch( methodIndex ) { + + case 0: + + unsignedIntegerArray_length( object ); + + break; + + case 10: + + unsignedIntegerArray_pop( object ); + + break; + + } + + break; + + case 18: + + switch( methodIndex ) { + + case 0: + + floatArray_length( object ); + + break; + + case 10: + + floatArray_pop( object ); + + break; + + } + + break; + + case 19: + + switch( methodIndex ) { + + case 3: + + program_extractBlocks( object ); + + break; + + case 6: + + program_create( object ); + + break; + + case 8: + + program_use( object ); + + break; + + case 9: + + program_extractUniforms( object ); + + break; + + case 10: + + program_extractAttributes( object ); + + break; + + } + + break; + + case 20: + + switch( methodIndex ) { + + } + + break; + + case 21: + + switch( methodIndex ) { + + } + + break; + + case 22: + + switch( methodIndex ) { + + case 0: + + sampler2D_constructor( object ); + + break; + + case 2: + + sampler2D_getTextureIndex( object ); + + break; + + case 3: + + sampler2D_bind( object ); + + break; + + } + + break; + + case 23: + + switch( methodIndex ) { + + } + + break; + + case 24: + + switch( methodIndex ) { + + case 0: + + array_length( object ); + + break; + + case 1: + + array_data( object ); + + break; + + case 10: + + array_pop( object ); + + break; + + } + + break; + + case 25: + + switch( methodIndex ) { + + case 9: + + text_toNative( object ); + + break; + + case 11: + + text_free( object ); + + break; + + } + + break; + + case 27: + + switch( methodIndex ) { + + } + + break; + + case 28: + + switch( methodIndex ) { + + case 4: + + consoleManager_createHorisontalLine( object ); + + break; + + } + + break; + + case 29: + + switch( methodIndex ) { + + case 1: + + http_initializeOpenSSL( object ); + + break; + + case 5: + + http_acceptConnection( object ); + + break; + + } + + break; + + case 30: + + switch( methodIndex ) { + + case 1: + + headerManager_display( object ); + + break; + + } + + break; + + case 31: + + switch( methodIndex ) { + + } + + break; + + case 32: + + switch( methodIndex ) { + + case 0: + + request_constructor( object ); + + break; + + case 1: + + request_free( object ); + + break; + + } + + break; + + case 33: + + switch( methodIndex ) { + + } + + break; + + case 34: + + switch( methodIndex ) { + + } + + break; + + case 35: + + switch( methodIndex ) { + + case 0: + + mimeTypes_constructor( object ); + + break; + + } + + break; + + case 36: + + switch( methodIndex ) { + + } + + break; + + case 37: + + switch( methodIndex ) { + + } + + break; + + case 38: + + switch( methodIndex ) { + + case 1: + + block_enableAutoUpload( object ); + + break; + + case 2: + + block_getBufferTypeText( object ); + + break; + + case 3: + + block_createBuffer( object ); + + break; + + case 4: + + block_upload( object ); + + break; + + } + + break; + + case 39: + + switch( methodIndex ) { + + } + + break; + + case 40: + + switch( methodIndex ) { + + case 0: + + renderPass_prepare( object ); + + break; + + case 1: + + renderPass_render( object ); + + break; + + } + + break; + + case 41: + + switch( methodIndex ) { + + case 0: + + compute2_prepare( object ); + + break; + + case 1: + + compute2_render( object ); + + break; + + } + + break; + + case 42: + + switch( methodIndex ) { + + case 0: + + compute_prepare( object ); + + break; + + case 1: + + compute_render( object ); + + break; + + } + + break; + + case 43: + + switch( methodIndex ) { + + case 1: + + font_prepare( object ); + + break; + + case 2: + + font_render( object ); + + break; + + } + + break; + + case 44: + + switch( methodIndex ) { + + case 1: + + quads_prepare( object ); + + break; + + case 3: + + quads_createMeshes( object ); + + break; + + case 7: + + quads_render( object ); + + break; + + } + + break; + + case 45: + + switch( methodIndex ) { + + case 1: + + pipeline_render( object ); + + break; + + } + + break; + + case 46: + + switch( methodIndex ) { + + case 0: + + eventManger_constructor( object ); + + break; + + case 1: + + eventManger_fetchEvent( object ); + + break; + + } + + break; + + } + +} + + + +// #include "sqlite.h" + +int getPropertyIndexOfClassIndex( int propertyCount, char ** propertyNames ) { + + int propertyIdOfIndex = -1; + + for ( int i = 0; i < propertyCount; ++i ) + { + char * propertyName = propertyNames[i]; + + //printf("propertyName: %s\n", propertyName); + + if( strcmp( propertyName, "id" ) == 0 ) { + + propertyIdOfIndex = i; + + break; + + } + + } + + return propertyIdOfIndex; + +} + +/* +void getArrayByClassIndex( int items, void * * voidArray, int * structByteSize, int classIndex ) { + + struct user * array; + + switch( classIndex ) { + + case 8: + + array = ( struct user * ) malloc( sizeof( struct user ) * 1000 ); + + voidArray = ( void ** ) array; + + *structByteSize = sizeof( struct user ); + + break; + + default: + + array = ( struct user * ) malloc( sizeof( struct user ) * 1000 ); + + voidArray = ( void ** ) array; + + *structByteSize = sizeof( struct user ); + + } + +}*/ + +char * getClassName( int classIndex ) { + + return __ClassNames[ classIndex ]; + +} + + +int getClassIndexByClassName( char * className ) { + + for (int i = 0; i < TOTAL_CLASS_COUNT; ++i) + { + char * currentClassName = __ClassNames[ i ]; + + if( strcmp( className, currentClassName ) == 0 ) { + + //printf("find classname: %s\n", className); + + return i; + + } + + } + + return -1; + +} + +int getPropertyCountByClassIndex( int classIndex ) { + + return __ClassPropertyCount[ classIndex ]; + +} + +char * * getPropertiesByClassIndex( int classIndex ) { + + return __ClassPropertyNames[ classIndex ]; + +} + +int * getPropertyOffsetsByClassIndex( int classIndex ) { + + return __ClassPropertyOffsets[ classIndex ]; + +} + +int getPropertyOffsetByPropertyIndex( int * propertyOffsets, int propertyIndex ) { + + return propertyOffsets[ propertyIndex ]; + +} + +int * getPropertyDatatypeIndexesByClassIndex( int classIndex ) { + + return __ClassPropertyDatatypeIndices[ classIndex ]; + +} + +int getPropertyDatatypeIndex( int * propertyDatatypeIndices, int propertyIndex ) { + + return propertyDatatypeIndices[ propertyIndex ]; + +} + + +int getPropertyIndexByPropertyName( int classID, char * propertyName ) { + + int propertyCount = getPropertyCountByClassIndex( classID ); + + char * * propertyNames = getPropertiesByClassIndex( classID ); + + for (int i = 0; i < propertyCount; ++i) + { + + char * propertyNameCompare = propertyNames[i]; + + if( strcmp( propertyName, propertyNameCompare ) == 0 ) { + + return i; + + } + + } + + return -1; + +} + +int getMethodCountByClassIndex( int classIndex ) { + + return __ClassMethodCount[ classIndex ]; + +} + + +char * * getMethodNamesByClassIndex( int classIndex ) { + + return __ClassMethodNames[ classIndex ]; + +} + + +int getMethodIndexByPropertyName( int classID, char * propertyName ) { + + int methodCount = getMethodCountByClassIndex( classID ); + + char * * methodNames = getMethodNamesByClassIndex( classID ); + + for (int i = 0; i < methodCount; ++i) + { + + char * propertyNameCompare = methodNames[i]; + + if( strcmp( propertyName, propertyNameCompare ) == 0 ) { + + return i; + + } + + } + + return -1; + +} \ No newline at end of file diff --git a/application/demos/example.opengl/classConfiguration.h b/application/demos/example.opengl/classConfiguration.h new file mode 100644 index 0000000..0a27cc3 --- /dev/null +++ b/application/demos/example.opengl/classConfiguration.h @@ -0,0 +1,133 @@ +#ifndef __classConfiguration + +#define __classConfiguration + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#define TOTAL_CLASS_COUNT 52 + +extern char * __ClassNames[TOTAL_CLASS_COUNT]; +extern int __ClassPropertyCount[TOTAL_CLASS_COUNT]; +extern char * __ClassPropertyNames[TOTAL_CLASS_COUNT][30]; +extern int __ClassPropertyOffsets[TOTAL_CLASS_COUNT][30]; +extern int __ClassPropertyOffsets[TOTAL_CLASS_COUNT][30]; + +#include + +int getPropertyIndexOfClassIndex( int propertyCount, char ** propertyNames ); + +void getArrayByClassIndex( int size, void * * voidArray, int * structByteSize, int classIndex ); + +int getClassIndexByClassName( char * className ); + +char * getClassName( int classIndex ); + +int getPropertyCountByClassIndex( int classIndex ); + +char * * getPropertiesByClassIndex( int classIndex ); + +int * getPropertyOffsetsByClassIndex( int classIndex ); + +int getPropertyOffsetByPropertyIndex( int * propertyOffsets, int propertyIndex ); + +int getPropertyIndexByPropertyName( int classID, char * propertyName ); + +int * getPropertyDatatypeIndexesByClassIndex( int classIndex ); + +int getPropertyDatatypeIndex( int * propertyDatatypeIndices, int propertyIndex ); + +int getMethodCountByClassIndex( int classIndex ); + +char * * getMethodNamesByClassIndex( int classIndex ); + + +int getMethodIndexByPropertyName( int classID, char * propertyName ); + +void callMethodOfClass( int classIndex, int methodIndex, void * object ); +#endif diff --git a/application/demos/example.opengl/console.c b/application/demos/example.opengl/console.c new file mode 100644 index 0000000..88a8774 --- /dev/null +++ b/application/demos/example.opengl/console.c @@ -0,0 +1,269 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + +struct consoleManager * console; + + + +char * consoleManager_whiteSpace( consoleManager * this, int whiteSpaceCount ) { + + char * output = malloc( whiteSpaceCount + 1 ); + + for (int i = 0; i < whiteSpaceCount; ++i) + { + + strcat( output, " " ); + + } + + output[whiteSpaceCount] = 0; + + return output; + + } + +void consoleManager_logObject( consoleManager * this, void * voidPointer, int classIndex, int level ) { + + + char * whiteSpace = consoleManager_whiteSpace( this, level ); + + level++; + + char * className = getClassName( classIndex ); + + printf( "\n\n" ); + + printf( whiteSpace ); + + printf(" %s : {\n", className ); + + + + char * * propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + char * pointer = voidPointer; + + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + printf( whiteSpace ); + + printf(" %-20s : ", propertyName); + + int propertyDatatypeIndex = getPropertyDatatypeIndex( datatypeIndices, propertyIndex ); + + int propertyOffset = getPropertyOffsetByPropertyIndex( propertyOffsets, propertyIndex ); + + + if( propertyDatatypeIndex == -5 ) { + + int value = *( int * )(pointer + propertyOffset); + + printf( whiteSpace ); + + printf("%-20i ", value ); + + + + } else if( propertyDatatypeIndex == -3 ) { + + + + uintptr_t * value = ( uintptr_t * ) ( pointer + propertyOffset ); + + + + printf( whiteSpace ); + + printf( "%-20s", ( char * ) * value ); + + } else if( propertyDatatypeIndex > 0 ) { + + char * memberClassName = getClassName( propertyDatatypeIndex ); + + if( strcmp( memberClassName, "array" ) == 0 ) { + + struct array * memberArray = *(struct array ** )(pointer + propertyOffset) ; + + if( memberArray == NULL ) { + + printf(" this has to be fixed, array is not created.\n"); + + continue; + + } + + int numberRows = array_length( memberArray ); + + int * arrayPointer = ( int * ) memberArray->items; + + for (int k = 0; k < numberRows; ++k) + { + + void * pointer = array_get( memberArray, k ); + + short * row = (short*)(pointer); + + consoleManager_logObject( this, pointer, (int) *row, level ); + + } + + } + + + + } + + + printf("\n"); + + + } + + printf( whiteSpace ); + + printf( " }\n" ); + + + + } + +void consoleManager_log( consoleManager * this, int count, int datatypes[], ... ) { + + + + int level = 0; + + va_list args; + + va_start( args, count ); + + + + for (int i = 0; i < count; ++i) + { + int datatype = datatypes[i]; + + + + if( datatype == -2 ) { + + char * message = va_arg( args, char * ); + + printf("%s", message); + + } + + if( datatype == -1 ) { + + int message = va_arg( args, int ); + + printf("%i", message); + } + + if( datatype > 0 ) { + + + + void * voidPointer = va_arg( args, void * ); + + consoleManager_logObject( this, voidPointer, datatype, level++ ); + + + } + + printf(" "); + + } + + printf("\n"); + + va_end( args); + + } + +void consoleManager_error( consoleManager * this, char * message ) { + + #define ANSI_COLOR_RED "\x1b[31m" + #define ANSI_COLOR_GREEN "\x1b[32m" + #define ANSI_COLOR_DIM_YELLOW "\x1b[33m" + #define ANSI_COLOR_BLUE "\x1b[34m" + #define ANSI_COLOR_MAGENTA "\x1b[35m" + #define ANSI_COLOR_CYAN "\x1b[36m" + #define ANSI_COLOR_RESET "\x1b[0m" + + #define ANSI_COLOR_BRIGHT_YELLOW "\x1b[93m" + + printf( ANSI_COLOR_RED ); + + printf( "\n\n Error: " ); + + printf( "%s\n\n", message ); + + printf( ANSI_COLOR_RESET ); + + exit( 0 ); + + } + +void consoleManager_createHorisontalLine( consoleManager * this ) { + + struct winsize w; + + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + + for (int i = 0; i < w.ws_col; ++i) + { + + printf("-"); + + }; + + printf("\n"); + + } + +consoleManager consoleManager_new() { + + consoleManager instance; + + return instance; + +} + +consoleManager * consoleManager_newPointer() { + + struct consoleManager * pointer = malloc( sizeof ( struct consoleManager ) ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/console.h b/application/demos/example.opengl/console.h new file mode 100644 index 0000000..57d565e --- /dev/null +++ b/application/demos/example.opengl/console.h @@ -0,0 +1,66 @@ +#ifndef _console + +#define _console + + +// Macros + +#define isCompatible(x, type) _Generic(x, type: true, default: false) + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + + +typedef struct consoleManager{ + + +} consoleManager; + +char * consoleManager_whiteSpace( consoleManager * this, int whiteSpaceCount ); + +void consoleManager_logObject( consoleManager * this, void * voidPointer, int classIndex, int level ); + +void consoleManager_log( consoleManager * this, int count, int datatypes[], ... ); + +void consoleManager_error( consoleManager * this, char * message ); + +void consoleManager_createHorisontalLine( consoleManager * this ); + +extern struct consoleManager * console; + +consoleManager consoleManager_new( ); + +consoleManager * consoleManager_newPointer( ); + +#endif + + +typedef struct consoleManager consoleManager; + + + diff --git a/application/demos/example.opengl/engine/block.c b/application/demos/example.opengl/engine/block.c new file mode 100644 index 0000000..76a03b8 --- /dev/null +++ b/application/demos/example.opengl/engine/block.c @@ -0,0 +1,583 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void block_add( block * this, struct member * memberInstance ) { + + array_add( this->members, memberInstance ); + + } + +void block_enableAutoUpload( block * this ) { + + this->autoUpload = 1; + + } + + +char * block_getBufferTypeText( block * this ) { + + switch( this->bufferType ) { + + case GL_SHADER_STORAGE_BUFFER: + + return "GL_SHADER_STORAGE_BUFFER"; + + break; + + case GL_UNIFORM_BUFFER: + + return "GL_UNIFORM_BUFFER"; + + break; + } + + return "buffer message not found"; + + } + +void block_createBuffer( block * this ) { + + unsigned int blockBufferSize = this->bufferSize; + + + + this->data = ( float * ) malloc( blockBufferSize ); + + glGenBuffers( 1, &this->buffer ); + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->index, this->buffer ); + + glBufferData( this->bufferType, blockBufferSize, 0, GL_DYNAMIC_DRAW ); + + } + +void block_upload( block * this ) { + + + + + + + + + + + + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + glBufferSubData( this->bufferType, 0, this->bufferSize, this->data ); + + } + +void block_mapBufferError( block * this, void * pointer ) { + + if ( pointer == NULL ){ + + GLenum errorCode = glGetError(); + + switch( errorCode ) { + + case GL_INVALID_ENUM: + + printf("GL_INVALID_ENUM\n"); + + break; + + case GL_INVALID_OPERATION: + + printf("GL_INVALID_OPERATION\n"); + + break; + + case GL_INVALID_VALUE: + + printf("GL_INVALID_VALUE\n"); + + break; + + } + + + printf("null pointer on buffer: %i\n", errorCode); + + return; + + } + + } + +void * block_getMemberArray( block * this, char * name ) { + + glMemoryBarrier( GL_SHADER_STORAGE_BARRIER_BIT ); + + vector_vector2 * output = vector_vector2_newPointer(); + + + int uniformCount = array_length( this->members ); + + for (int i = 0; i < uniformCount; ++i) + { + member * currentMember = array_get( this->members, i ); + + char * memberName = ( char * ) currentMember->name; + + if( char_operator_compare( memberName , name) ) { + + int size = currentMember->size * 8; + + int offset = currentMember->offset / 4; + + output->items = glMapBufferRange( GL_SHADER_STORAGE_BUFFER, 0, size, GL_MAP_WRITE_BIT ); + + output->total = currentMember->size; + + block_mapBufferError( this, output->items ); + + + } + + } + + glUnmapBuffer( GL_SHADER_STORAGE_BUFFER ); + + + return output; + + } + +void block_setMemberArrayRow( block * this, char * name, int arrayIndex, float * data ) { + + int memberCount = array_length( this->members ); + + for (int i = 0; i < memberCount; ++i) + { + member * currentMember = array_get( this->members, i ); + + char * memberName = ( char * ) currentMember->name; + + if( char_operator_compare( memberName , name) ) { + + int size = currentMember->size * 8; + + int arrayStride = currentMember->arrayStride; + + int offset = arrayStride * arrayIndex; + + + + + + + if( this->autoUpload ) { + + + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + glBufferSubData( this->bufferType, offset, arrayStride, data ); + + } + + + memcpy( this->data + offset, data, arrayStride ); + + + + } + + } + + } + +void block_setMemberArray( block * this, char * name, float * data ) { + + int memberCount = array_length( this->members ); + + for (int i = 0; i < memberCount; ++i) + { + member * currentMember = array_get( this->members, i ); + + char * memberName = ( char * ) currentMember->name; + + if( char_operator_compare( memberName , name) ) { + + int size = currentMember->size * 8; + + int offset = currentMember->offset / 4; + + memcpy( this->data + offset, data, size ); + + } + + } + + } + +void block_setMemberItem( block * this, char * name, int index, void * value ) { + + + int uniformCount = array_length( this->members ); + + + + for (int i = 0; i < uniformCount; ++i) + { + member * currentMember = array_get( this->members, i ); + + char * memberName = ( char * ) currentMember->name; + + if( char_operator_compare( memberName , name) ) { + + + int stride; + + int strideNormalized; + + int size; + + int offset; + + + switch( currentMember->type ) { + + case GL_FLOAT_VEC2: + + stride = currentMember->arrayStride; + + strideNormalized = stride / sizeof( float ) ; + + + + + + vector2 * vector2Value = ( vector2 * ) value; + + size = 8; + + offset = currentMember->offset; + + + + if( this->autoUpload ) { + + GLint arrayIndex = ( strideNormalized * index * 2 * 8 ); + + float data[2] = { vector2Value->x, vector2Value->y }; + + printf("%i: (size:%i) %f %f\n", arrayIndex, data[0], data[1]); + + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + glBufferSubData( this->bufferType, arrayIndex, size, data ); + + + + } else { + + GLint dataOffset = offset / sizeof( float ); + + GLint arrayIndex = ( strideNormalized * index ); + + + if( currentMember->topLevelSize == 1 ) { + + + + } + + + + + this->data[ dataOffset + arrayIndex ] = vector2Value->x; + + this->data[ dataOffset + 1 + arrayIndex ] = vector2Value->y; + + } + + + + break; + + case GL_FLOAT_VEC3: + + stride = currentMember->arrayStride; + + strideNormalized = stride / sizeof( float ) ; + + + vector3 * vector3Value = ( vector3 * ) value; + + size = 12; + + offset = currentMember->offset; + + + + if( this->autoUpload ) { + + float data[3] = { vector3Value->x, vector3Value->y, vector3Value->z }; + + + + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + glBufferSubData( this->bufferType, offset, size, data ); + + + + } else { + + GLint dataOffset = offset / sizeof( float ); + + GLint arrayIndex = ( strideNormalized * index ); + + this->data[ dataOffset + arrayIndex ] = vector3Value->x; + + this->data[ dataOffset + 1 + arrayIndex ] = vector3Value->y; + + this->data[ dataOffset + 2 + arrayIndex ] = vector3Value->z; + + } + + break; + + case GL_SAMPLER_2D: + + + break; + + } + + } + + } + + } + +void block_setData( block * this, float * data ) { + + this->data = data; + + } + +void block_setMember( block * this, char * name, void * value ) { + + int uniformCount = array_length( this->members ); + + + + for (int i = 0; i < uniformCount; ++i) + { + member * currentMember = array_get( this->members, i ); + + char * memberName = ( char * ) currentMember->name; + + if( char_operator_compare( memberName , name) ) { + + + + GLuint size = 8; + + GLint offset = currentMember->offset; + + switch( currentMember->type ) { + + case GL_INT: + + int intValue = *( int * ) value; + + printf("set int value: %i offset: %i\n", intValue, offset); + + + + if( this->autoUpload ) { + + float data[1] = { value }; + + + + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + glBufferSubData( this->bufferType, offset, size, data ); + + + + } else { + + GLint dataOffset = offset / sizeof( float ); + + this->data[ dataOffset ] = intValue; + + + + } + + break; + + case GL_FLOAT: + + float floatValue = *( float * ) value; + + printf("set int value: %f offset: %i\n", floatValue, offset); + + + + if( this->autoUpload ) { + + float data[1] = { value }; + + + + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + glBufferSubData( this->bufferType, offset, size, data ); + + + + } else { + + GLint dataOffset = offset / sizeof( float ); + + this->data[ dataOffset ] = floatValue; + + + + } + + break; + + case GL_FLOAT_VEC2: + + vector2 * vector2Value = ( vector2 * ) value; + + if( this->autoUpload ) { + + float data[2] = { vector2Value->x, vector2Value->y }; + + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + glBufferSubData( this->bufferType, offset, size, data ); + + + + } else { + + GLint dataOffset = offset / sizeof( float ); + + this->data[ dataOffset ] = vector2Value->x; + + this->data[ dataOffset + 1 ] = vector2Value->y; + + } + + break; + + case GL_FLOAT_VEC3: + + vector3 * vector3Value = ( vector3 * ) value; + + + + break; + + case GL_SAMPLER_2D: + + + break; + + } + + } + + + } + + + } + +block block_new() { + + block instance; + + instance.members = array_newPointer(); + + instance.autoUpload = 0; + + return instance; + +} + +block * block_newPointer() { + + struct block * pointer = malloc( sizeof ( struct block ) ); + + pointer->members = array_newPointer(); + + pointer->autoUpload = 0; + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/block.h b/application/demos/example.opengl/engine/block.h new file mode 100644 index 0000000..d938b7f --- /dev/null +++ b/application/demos/example.opengl/engine/block.h @@ -0,0 +1,96 @@ +#ifndef _block + +#define _block + + +// Macros + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "member.h" + +#include "sampler2D.h" + +#include "char.h" + +#include "array.h" + +#include "fileSystem.h" + +#include + +#include + +#include + +#include + + +typedef struct block{ + + array * members; + + GLint buffer; + + GLuint index; + + GLenum bufferType; + + GLint bufferSize; + + GLint bindingPoint; + + GLchar * name; + + float * data; + + GLint autoUpload; + + +} block; + +void block_add( block * this, struct member * memberInstance ); + +void block_enableAutoUpload( block * this ); + +char * block_getBufferTypeText( block * this ); + +void block_createBuffer( block * this ); + +void block_upload( block * this ); + +void block_mapBufferError( block * this, void * pointer ); + +void * block_getMemberArray( block * this, char * name ); + +void block_setMemberArrayRow( block * this, char * name, int arrayIndex, float * data ); + +void block_setMemberArray( block * this, char * name, float * data ); + +void block_setMemberItem( block * this, char * name, int index, void * value ); + +void block_setData( block * this, float * data ); + +void block_setMember( block * this, char * name, void * value ); + +block block_new( ); + +block * block_newPointer( ); + +#endif + + +typedef struct block block; + + + diff --git a/application/demos/example.opengl/engine/element.c b/application/demos/example.opengl/engine/element.c new file mode 100644 index 0000000..a4ff7de --- /dev/null +++ b/application/demos/example.opengl/engine/element.c @@ -0,0 +1,366 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void element_constructor( element * this ) { + + vector_char_pointer_add( this->featureNames, "useBackgroundImage" ); + + vector_char_pointer_add( this->featureNames, "useBorder" ); + + } + + +vector4 element_colorConverter( element * this, char * hexValue ) { + + int r; + + int g; + + int b; + + int a; + + sscanf( hexValue, "%02x%02x%02x%02x", &r, &g, &b, &a ); + + printf("opacity: %i\n"); + + struct vector4 rgbColor = vector4_new( r, g, b, (float)a ); + + return rgbColor; + } + + + + + + + +void element_setOriginal( element * this ) { + + this->originalSize = this->size; + + this->originalPosition = this->position; + + this->originalBackgroundColor = this->backgroundColor; + + } + +void element_setter_size( element * this, vector2 a ) { + + this->size.x = a.x; + + this->size.y = a.y; + + printf("set size: %f %f\n", this->size.x, this->size.y); + + + + } + +void element_setter_position( element * this, vector3 a ) { + + this->position.x = a.x; + + this->position.y = a.y; + + this->position.z = a.z; + + printf("set position: %f %f\n", this->position.x, this->position.y); + + + + } + +bool element_featureIsEnabled( element * this, int featureValue ) { + + return ( this->features & featureValue ) > 0; + + } + + + +int element_getFeatureValueByFeatureName( element * this, char * featureName ) { + + int count = vector_char_pointer_length( this->featureNames ); + + for (int i = 0; i < count; ++i) + { + char * currentFeatureName = vector_char_pointer_get( this->featureNames, i ); + + if( char_operator_compare( featureName , currentFeatureName) ) { + + return powf( 2, i ); + + } + + } + + return 0; + + } + +int element_updateFeature( element * this ) { + + int currentFeatureValue; + + currentFeatureValue = element_getFeatureValueByFeatureName( this, "useBackgroundImage" ); + + if( element_featureIsEnabled( this, currentFeatureValue ) ) { + + if( !this->useBackgroundImage ) { + + this->features -= currentFeatureValue; + + } + + } else { + + if( this->useBackgroundImage ) { + + this->features += currentFeatureValue; + + } + + } + + + return this->features; + + + + + } + +void element_setter_background( element * this, int count, int datatypes[], ... ) { + + va_list args; + + va_start( args, count ); + + int datatype = datatypes[0]; + + + printf("datatype: %i\n\n\n", datatype); + + if( datatype == -2 ) { + + char * message = va_arg( args, char * ); + + if( ( char ) message[0] == 35 ) { + + printf("Hex color\n\n\n"); + + message++; + + vector4 rgba = element_colorConverter( this, message ); + + this->backgroundColor = vector3_new( rgba.x, rgba.y, rgba.z ); + + this->opacity = rgba.w / 256; + + this->useBackgroundImage = false; + + } else { + + this->backgroundImagePath = message; + + this->useBackgroundImage = true; + + printf("path\n\n\n"); + + } + + printf(" char *: %s\n\n\n ", message); + + } + + if( datatype > 0 ) { + + char * className = getClassName( datatype ); + + if( char_operator_compare( className , "vector3") ) { + + vector3 message = va_arg( args, vector3 ); + + this->backgroundColor = message; + + this->useBackgroundImage = false; + + } + + if( char_operator_compare( className , "vector4") ) { + + vector4 message = va_arg( args, vector4 ); + + this->backgroundColor = vector3_new( message.x, message.y, message.z ); + + this->opacity = message.w; + + this->useBackgroundImage = false; + + } + + } + + + + + + + + + } + +void element_click( element * this ) { + + + this->backgroundColor = vector3_new( 0, 256, 256 ); + + } + +void element_mousedown( element * this ) { + + + + this->backgroundColor = vector3_new( 0, 256, 256 ); + + element_setter_position( this, vector3_new( 256, 256, 100 ) ); + + } + +void element_mouseup( element * this ) { + + + + this->backgroundColor = this->originalBackgroundColor; + + element_setter_position( this, this->originalPosition ); + + } + +void element_mouseover( element * this ) { + + this->backgroundColor = vector3_new( 256, 256, 256 ); + + } + +void element_mouseleave( element * this ) { + + printf("mouse leave\n"); + + this->backgroundColor = this->originalBackgroundColor; + + } + +element element_new() { + + element instance; + + instance.position = vector3_new( 0, 0, 0 ); + + instance.size = vector2_new( 0, 0 ); + + instance.backgroundColor = vector3_new( 0, 0, 0 ); + + instance.originalPosition = vector3_new( 0, 0, 0 ); + + instance.originalSize = vector2_new( 0, 0 ); + + instance.originalBackgroundColor = vector3_new( 0, 0, 0 ); + + instance.opacity = 1; + + instance.backgroundImagePath = ""; + + instance.useBackgroundImage = false; + + instance.features = 0; + + instance.featureNames = vector_char_pointer_newPointer(); + + element_constructor( &instance); + + return instance; + +} + +element * element_newPointer() { + + struct element * pointer = malloc( sizeof ( struct element ) ); + + pointer->position = vector3_new( 0, 0, 0 ); + + pointer->size = vector2_new( 0, 0 ); + + pointer->backgroundColor = vector3_new( 0, 0, 0 ); + + pointer->originalPosition = vector3_new( 0, 0, 0 ); + + pointer->originalSize = vector2_new( 0, 0 ); + + pointer->originalBackgroundColor = vector3_new( 0, 0, 0 ); + + pointer->opacity = 1; + + pointer->backgroundImagePath = ""; + + pointer->useBackgroundImage = false; + + pointer->features = 0; + + pointer->featureNames = vector_char_pointer_newPointer(); + + element_constructor( pointer ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/element.h b/application/demos/example.opengl/engine/element.h new file mode 100644 index 0000000..e179e04 --- /dev/null +++ b/application/demos/example.opengl/engine/element.h @@ -0,0 +1,107 @@ +#ifndef _element + +#define _element + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include "classConfiguration.h" + +#include "char.h" + +#include "vector.h" + +#include "vector4.h" + +#include "vector3.h" + +#include "vector2.h" + + +typedef struct element{ + + int index; + + vector3 position; + + vector2 size; + + vector3 backgroundColor; + + vector3 originalPosition; + + vector2 originalSize; + + vector3 originalBackgroundColor; + + float opacity; + + char * backgroundImagePath; + + bool useBackgroundImage; + + int features; + + vector_char_pointer * featureNames; + + int textureIndex; + + void * background; + + +} element; + +void element_constructor( element * this ); + +vector4 element_colorConverter( element * this, char * hexValue ); + +void element_setOriginal( element * this ); + +void element_setter_size( element * this, vector2 a ); + +void element_setter_position( element * this, vector3 a ); + +bool element_featureIsEnabled( element * this, int featureValue ); + +int element_getFeatureValueByFeatureName( element * this, char * featureName ); + +int element_updateFeature( element * this ); + +void element_setter_background( element * this, int count, int datatypes[], ... ); + +void element_click( element * this ); + +void element_mousedown( element * this ); + +void element_mouseup( element * this ); + +void element_mouseover( element * this ); + +void element_mouseleave( element * this ); + +element element_new( ); + +element * element_newPointer( ); + +#endif + + +typedef struct element element; + + + diff --git a/application/demos/example.opengl/engine/event.c b/application/demos/example.opengl/engine/event.c new file mode 100644 index 0000000..423f2df --- /dev/null +++ b/application/demos/example.opengl/engine/event.c @@ -0,0 +1,87 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + +event event_new() { + + event instance; + + instance.mouse = mouse_newPointer(); + + instance.screen = screen_newPointer(); + + instance.keyboard = keyboard_newPointer(); + + return instance; + +} + +event * event_newPointer() { + + struct event * pointer = malloc( sizeof ( struct event ) ); + + pointer->mouse = mouse_newPointer(); + + pointer->screen = screen_newPointer(); + + pointer->keyboard = keyboard_newPointer(); + + return pointer; + +} + +keyboard keyboard_new() { + + keyboard instance; + + return instance; + +} + +keyboard * keyboard_newPointer() { + + struct keyboard * pointer = malloc( sizeof ( struct keyboard ) ); + + return pointer; + +} + +screen screen_new() { + + screen instance; + + return instance; + +} + +screen * screen_newPointer() { + + struct screen * pointer = malloc( sizeof ( struct screen ) ); + + return pointer; + +} + +mouse mouse_new() { + + mouse instance; + + instance.eventTypes = vector_char_pointer_newPointer(); + + return instance; + +} + +mouse * mouse_newPointer() { + + struct mouse * pointer = malloc( sizeof ( struct mouse ) ); + + pointer->eventTypes = vector_char_pointer_newPointer(); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/event.h b/application/demos/example.opengl/engine/event.h new file mode 100644 index 0000000..5095dce --- /dev/null +++ b/application/demos/example.opengl/engine/event.h @@ -0,0 +1,110 @@ +#ifndef _event + +#define _event + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "stdbool.h" + +#include "../vector2.h" + +#include "vector.h" + + +typedef struct event{ + + struct mouse * mouse; + + struct screen * screen; + + struct keyboard * keyboard; + + +} event; + +typedef struct keyboard{ + + int keyCode; + + bool shiftKey; + + bool ctrlKey; + + bool altKey; + + bool metaKey; + + +} keyboard; + +typedef struct screen{ + + vector2 size; + + vector2 position; + + +} screen; + +typedef struct mouse{ + + vector2 position; + + int button; + + vector_char_pointer * eventTypes; + + +} mouse; + +event event_new( ); + +event * event_newPointer( ); + +keyboard keyboard_new( ); + +keyboard * keyboard_newPointer( ); + +screen screen_new( ); + +screen * screen_newPointer( ); + +mouse mouse_new( ); + +mouse * mouse_newPointer( ); + +#endif + + +typedef struct event event; + + + + + +typedef struct keyboard keyboard; + + + + + +typedef struct screen screen; + + + + + +typedef struct mouse mouse; + + + diff --git a/application/demos/example.opengl/engine/eventManager.c b/application/demos/example.opengl/engine/eventManager.c new file mode 100644 index 0000000..84d58c0 --- /dev/null +++ b/application/demos/example.opengl/engine/eventManager.c @@ -0,0 +1,309 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void eventManger_constructor( eventManger * this ) { + + this->lastEvent = event_newPointer(); + + this->lastEvent->mouse->button = -1; + + + } + +event * eventManger_fetchEvent( eventManger * this ) { + + event * currentEvent = event_newPointer(); + + + currentEvent->mouse->button = -1; + + Window qRoot; + + Window qChild; + + unsigned int qMask; + + int childX; + + int childY; + + int mouseX; + + int mouseY; + + int child; + + + XWindowAttributes window; + + if( XGetWindowAttributes( this->mainDisplay, this->mainWindow, &window ) ) { + + } + + + + if( XQueryPointer( this->mainDisplay, this->RootWindow, &qRoot, &qChild, &mouseX, &mouseY, &childX, &childY, &qMask ) ) + { + + mouseX -= window.x; + + mouseY -= window.y; + + for(int i = 0; i < sizeof(int) * 8; i++) + { + int mask = 1 << sizeof(int) * 8 - i - 1; + + if(mask & qMask) + { + + } + else + { + + } + + } + + + + if( qMask == Button1MotionMask ) { + + + + currentEvent->mouse->button = 0; + + } + + + if( qMask == Button2MotionMask ) { + + printf("Button2MotionMask\n"); + + } + + + if( qMask == Button3MotionMask ) { + + printf("RightMouse\n"); + + } + + if( qMask == Button4MotionMask ) { + + printf("Button2MotionMask\n"); + + } + + + if( qMask == Button5MotionMask ) { + + printf("Button2MotionMask\n"); + + } + + if( qMask == ShiftMask ) { + + printf("Pressed shift\n"); + + } + + if( qMask == ControlMask ) { + + printf("Pressed control\n"); + + } + + + if( qMask == EnterWindowMask ) { + + + + } + + + + XEvent event; + + int keyboardEventCount = XPending( this->mainDisplay ); + + + + while( XPending( this->mainDisplay ) ) { + + + XNextEvent( this->mainDisplay, &event ); + + switch ( event.type ) { + + case KeyPress: + + printf("key has been pressed. %i\n\n", event.xkey.keycode); + + break; + + + case KeyRelease: + + printf("key has been released. %i\n\n", event.xkey.keycode); + + break; + + + + + case Expose: + + break; + + + + default: + + + + + + } + + + + } + + + + + + + + + + + } + + bool hasBorder = true; + + int borderCorrection = 0; + + + + if( hasBorder ) { + + borderCorrection = 12; + + } + + + currentEvent->mouse->position = vector2_new( mouseX, mouseY + borderCorrection ); + + currentEvent->screen->size = vector2_new( window.width, window.height + borderCorrection ); + + + + vector_char_pointer * mouseEvents = currentEvent->mouse->eventTypes; + + mouseEvents = vector_char_pointer_newPointer(); + + if( this->lastEvent->mouse->position.x != currentEvent->mouse->position.x || + this->lastEvent->mouse->position.y != currentEvent->mouse->position.y ) { + + vector_char_pointer_add( mouseEvents, "mousemove" ); + + } + + if( this->lastEvent->mouse->button != 0 && currentEvent->mouse->button == 0 ) { + + this->lastMouseDownTime = clock(); + + printf("Mouse down\n\n"); + + vector_char_pointer_add( mouseEvents, "mousedown" ); + + } + + if( this->lastEvent->mouse->button == 0 && currentEvent->mouse->button != 0 ) { + + clock_t difference = clock() - this->lastMouseDownTime; + + int milliseconds = difference * 1000 / CLOCKS_PER_SEC; + + if( milliseconds < 150 ) { + + printf("click event\n\n"); + + + vector_char_pointer_add( mouseEvents, "click" ); + + } + + printf("mouseup event\n\n"); + + vector_char_pointer_add( mouseEvents, "mouseup" ); + + + + } + + currentEvent->mouse->eventTypes = mouseEvents; + + + this->lastEvent = currentEvent; + + return currentEvent; + + } + +eventManger eventManger_new() { + + eventManger instance; + + eventManger_constructor( &instance); + + return instance; + +} + +eventManger * eventManger_newPointer() { + + struct eventManger * pointer = malloc( sizeof ( struct eventManger ) ); + + eventManger_constructor( pointer ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/eventManager.h b/application/demos/example.opengl/engine/eventManager.h new file mode 100644 index 0000000..8afdc74 --- /dev/null +++ b/application/demos/example.opengl/engine/eventManager.h @@ -0,0 +1,70 @@ +#ifndef _eventManager + +#define _eventManager + + +// Macros + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + + +typedef struct eventManger{ + + Display * mainDisplay; + + Window mainWindow; + + Window RootWindow; + + event * lastEvent; + + clock_t lastMouseDownTime; + + +} eventManger; + +void eventManger_constructor( eventManger * this ); + +event * eventManger_fetchEvent( eventManger * this ); + +eventManger eventManger_new( ); + +eventManger * eventManger_newPointer( ); + +#endif + + +typedef struct eventManger eventManger; + + + diff --git a/application/demos/example.opengl/engine/floatArray.c b/application/demos/example.opengl/engine/floatArray.c new file mode 100644 index 0000000..8d0806a --- /dev/null +++ b/application/demos/example.opengl/engine/floatArray.c @@ -0,0 +1,193 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + +int floatArray_length( floatArray * this ) { + + return this->total; + + } + + +float floatArray_get( floatArray * this, int index ) { + + if ( index >= 0 && index < this->total ){ + + return this->items[index]; + + } + + return NULL; + + } + + +void floatArray_set( floatArray * this, int index, float item ) { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + +void floatArray_resize( floatArray * this, int capacity ) { + + float * items = realloc( this->items, sizeof( float ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + +void floatArray_addVector2( floatArray * this, struct vector2 * item ) { + + floatArray_add( this, item->x ); + + floatArray_add( this, item->y ); + + } + +void floatArray_addVector3( floatArray * this, struct vector3 * item ) { + + floatArray_add( this, item->x ); + + floatArray_add( this, item->y ); + + floatArray_add( this, item->z ); + + } + +void floatArray_add( floatArray * this, float item ) { + + if ( this->capacity == this->total ){ + + floatArray_resize( this, this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + +void floatArray_delete( floatArray * this, int index ) { + if ( index < 0 || index >= this->total ){ + + return; + + } + + this->items[index] = NULL; + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + this->items[i + 1] = NULL; + + } + + this->total--; + + if ( this->total > 0 && this->total == this->capacity / 4 ){ + + floatArray_resize( this, this->capacity / 2 ); + + } + + } + + +int floatArray_array_push( floatArray * this, float item ) { + + floatArray_add( this, item ); + + return this->total; + + } + +void floatArray_unshift( floatArray * this, float item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + floatArray_resize( this, this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } + +float floatArray_pop( floatArray * this ) { + + int length = this->total; + + int lastIndex = length - 1; + + float lastItem = floatArray_get( this, lastIndex ); + + floatArray_delete( this, lastIndex ); + + return lastItem; + + } + +floatArray floatArray_new() { + + floatArray instance; + + instance.capacity = 10; + + instance.total = 0; + + instance.items = malloc( 10000000 ); + + return instance; + +} + +floatArray * floatArray_newPointer() { + + struct floatArray * pointer = malloc( sizeof ( struct floatArray ) ); + + pointer->capacity = 10; + + pointer->total = 0; + + pointer->items = malloc( 10000000 ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/floatArray.h b/application/demos/example.opengl/engine/floatArray.h new file mode 100644 index 0000000..36614dd --- /dev/null +++ b/application/demos/example.opengl/engine/floatArray.h @@ -0,0 +1,71 @@ +#ifndef _floatArray + +#define _floatArray + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + + +typedef struct floatArray{ + + int capacity; + + int total; + + float * items; + + +} floatArray; + +int floatArray_length( floatArray * this ); + +float floatArray_get( floatArray * this, int index ); + +void floatArray_set( floatArray * this, int index, float item ); + +void floatArray_resize( floatArray * this, int capacity ); + +void floatArray_addVector2( floatArray * this, struct vector2 * item ); + +void floatArray_addVector3( floatArray * this, struct vector3 * item ); + +void floatArray_add( floatArray * this, float item ); + +void floatArray_delete( floatArray * this, int index ); + +int floatArray_array_push( floatArray * this, float item ); + +void floatArray_unshift( floatArray * this, float item ); + +float floatArray_pop( floatArray * this ); + +floatArray floatArray_new( ); + +floatArray * floatArray_newPointer( ); + +#endif + + +typedef struct floatArray floatArray; + + + diff --git a/application/demos/example.opengl/engine/fontRenderer.c b/application/demos/example.opengl/engine/fontRenderer.c new file mode 100644 index 0000000..5e45e33 --- /dev/null +++ b/application/demos/example.opengl/engine/fontRenderer.c @@ -0,0 +1,194 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + +texture2D * fontRenderer_loadFont( fontRenderer * this, char character ) { + + FT_Library ft; + + if ( FT_Init_FreeType( &ft ) ) + { + + printf("ERROR::FREETYPE: Could not init FreeType Library"); + + + + } else { + + + + } + + + + FT_Face face; + + if ( FT_New_Face( ft, "assets/fonts/WorkSans/WorkSans-Regular.ttf", 0, &face ) ) + { + + printf("ERROR::FREETYPE: Failed to load font\n\n"); + + + + } else { + + + + } + + int fontSize = 118; + + if ( FT_Set_Pixel_Sizes( face, 0, fontSize ) ) { + + printf("ERROR::FREETYPE: Failed to set font size\n\n"); + + } else { + + + + } + + + + FT_Matrix matrix; + + FT_UInt glyph_index; + + FT_Vector pen; + + int n; + + FT_GlyphSlot slot = face->glyph; + + + pen.x = 0; + + pen.y = 0; + + if( FT_Load_Char( face, character, FT_LOAD_RENDER ) ) { + + printf("ERROR error loading char."); + + } else { + + + + } + + + + + + FT_Bitmap * bitmap = &slot->bitmap; + + texture2D * texture = texture2D_newPointer(); + + texture->width = bitmap->width; + + texture->height = bitmap->rows; + + texture->hasAlpha = 1; + + texture->offset = vector2_newPointer( ( float ) slot->bitmap_left, ( float ) slot->bitmap_top ); + + + + + + + + + + texture->data = bitmap->buffer; + + for (int x = 0; x < texture->width; ++x) + { + + } + + + + + + + + return texture; + + + + + } + +void fontRenderer_draw_bitmap( fontRenderer * this, FT_Bitmap * bitmap, FT_Int x, FT_Int y ) { + + FT_Int i, j, p, q; + + FT_Int x_max = x + bitmap->width; + FT_Int y_max = y + bitmap->rows; + + int WIDTH = 512; + + int HEIGHT = 512; + + printf("x_max: %i\n", x_max); + + printf("y_max: %i\n", y_max); + + + for ( i = x, p = 0; i < x_max; i++, p++ ) + { + for ( j = y, q = 0; j < y_max; j++, q++ ) + { + + + + + + } + } + + } + +void fontRenderer_show_image( fontRenderer * this, void ) { + } + +fontRenderer fontRenderer_new() { + + fontRenderer instance; + + instance.data = malloc( 512 * 512 * 4 ); + + return instance; + +} + +fontRenderer * fontRenderer_newPointer() { + + struct fontRenderer * pointer = malloc( sizeof ( struct fontRenderer ) ); + + pointer->data = malloc( 512 * 512 * 4 ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/fontRenderer.h b/application/demos/example.opengl/engine/fontRenderer.h new file mode 100644 index 0000000..a219990 --- /dev/null +++ b/application/demos/example.opengl/engine/fontRenderer.h @@ -0,0 +1,60 @@ +#ifndef _fontRenderer + +#define _fontRenderer + + +// Macros + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + + +typedef struct fontRenderer{ + + GLubyte * data; + + +} fontRenderer; + +texture2D * fontRenderer_loadFont( fontRenderer * this, char character ); + +void fontRenderer_draw_bitmap( fontRenderer * this, FT_Bitmap * bitmap, FT_Int x, FT_Int y ); + +void fontRenderer_show_image( fontRenderer * this, void ); + +fontRenderer fontRenderer_new( ); + +fontRenderer * fontRenderer_newPointer( ); + +#endif + + +typedef struct fontRenderer fontRenderer; + + + diff --git a/application/demos/example.opengl/engine/hints.c b/application/demos/example.opengl/engine/hints.c new file mode 100644 index 0000000..464f593 --- /dev/null +++ b/application/demos/example.opengl/engine/hints.c @@ -0,0 +1,23 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + +Hints Hints_new() { + + Hints instance; + + return instance; + +} + +Hints * Hints_newPointer() { + + struct Hints * pointer = malloc( sizeof ( struct Hints ) ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/hints.h b/application/demos/example.opengl/engine/hints.h new file mode 100644 index 0000000..4c3f285 --- /dev/null +++ b/application/demos/example.opengl/engine/hints.h @@ -0,0 +1,43 @@ +#ifndef _hints + +#define _hints + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + + +typedef struct Hints{ + + unsigned long flags; + + unsigned long functions; + + unsigned long decorations; + + long inputMode; + + unsigned long status; + + +} Hints; + +Hints Hints_new( ); + +Hints * Hints_newPointer( ); + +#endif + + +typedef struct Hints Hints; + + + diff --git a/application/demos/example.opengl/engine/member.c b/application/demos/example.opengl/engine/member.c new file mode 100644 index 0000000..79be214 --- /dev/null +++ b/application/demos/example.opengl/engine/member.c @@ -0,0 +1,23 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + +member member_new() { + + member instance; + + return instance; + +} + +member * member_newPointer() { + + struct member * pointer = malloc( sizeof ( struct member ) ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/member.h b/application/demos/example.opengl/engine/member.h new file mode 100644 index 0000000..c9f6f10 --- /dev/null +++ b/application/demos/example.opengl/engine/member.h @@ -0,0 +1,56 @@ +#ifndef _member + +#define _member + + +// Macros + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + + +typedef struct member{ + + char * name; + + GLint index; + + GLint offset; + + GLint size; + + GLenum type; + + GLuint arrayStride; + + GLuint topLevelSize; + + +} member; + +member member_new( ); + +member * member_newPointer( ); + +#endif + + +typedef struct member member; + + + diff --git a/application/demos/example.opengl/engine/mesh.c b/application/demos/example.opengl/engine/mesh.c new file mode 100644 index 0000000..c9d1f1d --- /dev/null +++ b/application/demos/example.opengl/engine/mesh.c @@ -0,0 +1,724 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +struct block * mesh_getUniformBlock( mesh * this, char * blockName ) { + + int blockCount = array_length( this->blocks ); + + for ( int i = 0; i < blockCount; ++i ) + { + struct block * currentBlock = array_get( this->blocks, i ); + + char * currentBlockName = currentBlock->name; + + if( char_operator_compare( currentBlockName , blockName) ) { + + return currentBlock; + + } + + } + + return NULL; + + } + + + +void mesh_bindBlock( mesh * this, struct block * blockInstance ) { + + + + block_createBuffer( blockInstance ); + + array_add( this->blocks, blockInstance ); + + } + +void mesh_setProgram( mesh * this, struct program * currentProgram ) { + + this->program = currentProgram; + + } + +GLuint mesh_getGLTypeSize( mesh * this, GLuint type ) { + + switch( type ) { + + case GL_FLOAT: + + return sizeof( GLfloat ); + + break; + + case GL_INT: + + return sizeof( GLint ); + + break; + + + case GL_UNSIGNED_INT: + + return sizeof( GLuint ); + + break; + } + + return 0; + + } + +GLuint mesh_getComponentType( mesh * this, GLuint type ) { + + + switch( type ) { + + case GL_FLOAT: + + return GL_FLOAT; + + break; + + case GL_FLOAT_VEC2: + + return GL_FLOAT; + + break; + + case GL_FLOAT_VEC3: + + return GL_FLOAT; + + break; + + case GL_FLOAT_VEC4: + + return GL_FLOAT; + + break; + + + case GL_INT: + + return GL_INT; + + break; + + case GL_INT_VEC2: + + return GL_INT; + + break; + + case GL_INT_VEC3: + + return GL_INT; + + break; + + case GL_INT_VEC4: + + return GL_INT; + + break; + + + case GL_UNSIGNED_INT: + + return GL_UNSIGNED_INT; + + break; + + case GL_UNSIGNED_INT_VEC2: + + return GL_UNSIGNED_INT; + + break; + + case GL_UNSIGNED_INT_VEC3: + + return GL_UNSIGNED_INT; + + break; + + case GL_UNSIGNED_INT_VEC4: + + return GL_UNSIGNED_INT; + + break; + + } + + + return 0; + + } + +GLuint mesh_getItemSize( mesh * this, GLuint type ) { + + switch( type ) { + + case GL_FLOAT: + + return 1; + + break; + + case GL_FLOAT_VEC2: + + return 2; + + break; + + case GL_FLOAT_VEC3: + + return 3; + + break; + + case GL_FLOAT_VEC4: + + return 4; + + break; + + + case GL_INT: + + return 1; + + break; + + case GL_INT_VEC2: + + return 2; + + break; + + case GL_INT_VEC3: + + return 3; + + break; + + case GL_INT_VEC4: + + return 4; + + break; + + + case GL_UNSIGNED_INT: + + return 1; + + break; + + case GL_UNSIGNED_INT_VEC2: + + return 2; + + break; + + case GL_UNSIGNED_INT_VEC3: + + return 3; + + break; + + case GL_UNSIGNED_INT_VEC4: + + return 4; + + break; + + } + + return 0; + + } + +GLuint mesh_createBuffer( mesh * this, char * attributeName, void * data, GLenum target, GLenum usage ) { + + GLuint itemSize; + + GLuint componentType; + + GLuint componentSize; + + GLuint attributeLocation; + + + + GLuint isIndexBuffer = 0; + + GLuint buffer; + + glGenBuffers( 1, &buffer ); + + + if( char_operator_compare( attributeName , "index") ) { + + isIndexBuffer = 1; + + componentType = GL_INT; + + componentSize = mesh_getGLTypeSize( this, componentType ); + + target = GL_ELEMENT_ARRAY_BUFFER; + + glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, buffer ); + + } else { + + attribute * attribute = program_getAttributeByName( this->program, attributeName ); + + if( attribute == NULL ) { + + return 0; + + } + + itemSize = mesh_getItemSize( this, attribute->type ); + + componentType = mesh_getComponentType( this, attribute->type ); + + componentSize = mesh_getGLTypeSize( this, componentType ); + + attributeLocation = attribute->location; + + target = GL_ARRAY_BUFFER; + + glEnableVertexAttribArray( attribute->location ); + + glBindBuffer( GL_ARRAY_BUFFER, buffer ); + + } + + + + + int itemCount; + + GLuint bufferSize; + + + if( componentType == GL_UNSIGNED_INT || componentType == GL_INT ) { + + unsignedIntegerArray * test = ( unsignedIntegerArray * ) data; + + itemCount = unsignedIntegerArray_length( test ); + + bufferSize = itemCount * componentSize; + + glBufferData( target, bufferSize, test->items, usage ); + + if( isIndexBuffer == NULL ) { + + glVertexAttribIPointer( attributeLocation, itemSize, componentType, 0, ( void * ) 0 ); + + } + + } else if( componentType == GL_FLOAT ) { + + floatArray * test = ( floatArray * ) data; + + itemCount = test->total; + + bufferSize = itemCount * componentSize; + + glBufferData( GL_ARRAY_BUFFER, bufferSize, test->items, usage ); + + if( isIndexBuffer == NULL ) { + + glVertexAttribPointer( attributeLocation, itemSize, componentType, GL_FALSE, 0, ( void * ) 0 ); + + } + } + + + + GLint compareSize = 0; + + glGetBufferParameteriv( target, GL_BUFFER_SIZE, &compareSize ); + + if( bufferSize != compareSize ) + { + + glDeleteBuffers(1, &buffer); + + printf("ERROR: size error"); + + return 0; + + } + + return buffer; + + } + + +void mesh_createBuffers( mesh * this ) { + + struct unsignedIntegerArray * indices = unsignedIntegerArray_newPointer(); + + struct floatArray * textureCoordinates = floatArray_newPointer(); + + struct floatArray * vertexCoordinates = floatArray_newPointer(); + + struct floatArray * normalCoordinates = floatArray_newPointer(); + + struct unsignedIntegerArray * meshIndices = unsignedIntegerArray_newPointer(); + + int subdivisionsDepth = 1; + + int subdivisionsWidth = 1; + + float width = 2; + + float depth = 2; + + + int meshCount = 100 * 50; + + int meshStartIndex = 0; + + for (int meshIndex = 0; meshIndex < meshCount; ++meshIndex) + { + + + meshStartIndex = unsignedIntegerArray_length( meshIndices ); + + + + int numVertsAcross = subdivisionsWidth + 1; + + for ( int z = 0; z < subdivisionsDepth; z++ ) { + + for ( int x = 0; x < subdivisionsWidth; x++ ) { + + + unsignedIntegerArray_add( indices, ( z + 0 ) * numVertsAcross + x + meshStartIndex ); + + unsignedIntegerArray_add( indices, ( z + 1 ) * numVertsAcross + x + meshStartIndex ); + + unsignedIntegerArray_add( indices, ( z + 0 ) * numVertsAcross + x + 1 + meshStartIndex ); + + + unsignedIntegerArray_add( indices, ( z + 1 ) * numVertsAcross + x + meshStartIndex ); + + unsignedIntegerArray_add( indices, ( z + 1 ) * numVertsAcross + x + 1 + meshStartIndex ); + + unsignedIntegerArray_add( indices, ( z + 0 ) * numVertsAcross + x + 1 + meshStartIndex ); + + } + + } + + + for ( int z = 0; z <= subdivisionsDepth; z++ ) { + + for ( int x = 0; x <= subdivisionsWidth; x++ ) { + + + float u = ( float ) x; + + float v = ( float ) z; + + + floatArray_add( textureCoordinates, u ); + + floatArray_add( textureCoordinates, ( 1 - v ) ); + + + floatArray_add( vertexCoordinates, width * u - width * 0.5 ); + + floatArray_add( vertexCoordinates, depth * v - depth * 0.5 ); + + floatArray_add( vertexCoordinates, 0 ); + + + floatArray_add( normalCoordinates, 0 ); + + floatArray_add( normalCoordinates, 0 ); + + floatArray_add( normalCoordinates, 1 ); + + + unsignedIntegerArray_add( meshIndices, meshIndex ); + + + } + + } + + + } + + glGenVertexArrays( 1, &this->vertexArrayObject ); + + glBindVertexArray( this->vertexArrayObject ); + + + this->vertexbuffer = mesh_createBuffer( this, "position", vertexCoordinates, GL_ARRAY_BUFFER, GL_STATIC_DRAW ); + + this->textureCoordinateBuffer = mesh_createBuffer( this, "textureCoordinates", textureCoordinates, GL_ARRAY_BUFFER, GL_STATIC_DRAW ); + + this->vertexbuffer = mesh_createBuffer( this, "meshIndex", meshIndices, GL_ARRAY_BUFFER, GL_STATIC_DRAW ); + + this->indexBuffer = mesh_createBuffer( this, "index", indices, GL_ARRAY_BUFFER, GL_STATIC_DRAW ); + + + + int blockCount = array_length( this->blocks ); + + for (int i = 0; i < blockCount; ++i) + { + + block * currentBlock = array_get( this->blocks, i ); + + int size = currentBlock->bufferSize; + + printf("Bind block %s bufferSize: %i bindingPoint: %i bufferType: %s \n\n", currentBlock->name, currentBlock->bufferSize, currentBlock->bindingPoint, block_getBufferTypeText( currentBlock ) ); + + + + glBindBuffer( currentBlock->bufferType, currentBlock->buffer ); + + glBindBufferBase( currentBlock->bufferType, currentBlock->bindingPoint, currentBlock->buffer ); + + glBufferData( currentBlock->bufferType, currentBlock->bufferSize, 0, GL_DYNAMIC_DRAW ); + + } + + + glBindVertexArray( 0 ); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + this->indices = indices; + + this->textureCoordinates = textureCoordinates; + + this->vertexCoordinates = vertexCoordinates; + + this->normalCoordinates = normalCoordinates; + + } + +void mesh_createOrderedTriangleStripQuad( mesh * this ) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +mesh mesh_new() { + + mesh instance; + + instance.blocks = array_newPointer(); + + instance.uniformBuffers = unsignedIntegerArray_newPointer(); + + return instance; + +} + +mesh * mesh_newPointer() { + + struct mesh * pointer = malloc( sizeof ( struct mesh ) ); + + pointer->blocks = array_newPointer(); + + pointer->uniformBuffers = unsignedIntegerArray_newPointer(); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/mesh.h b/application/demos/example.opengl/engine/mesh.h new file mode 100644 index 0000000..700edaa --- /dev/null +++ b/application/demos/example.opengl/engine/mesh.h @@ -0,0 +1,98 @@ +#ifndef _mesh + +#define _mesh + + +// Macros + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "unsignedIntegerArray.h" + +#include "floatArray.h" + +#include "program.h" + +#include "shader.h" + +#include "block.h" + +#include + +#include + +#include + + +typedef struct mesh{ + + struct program * program; + + struct unsignedIntegerArray * indices; + + struct floatArray * textureCoordinates; + + struct floatArray * vertexCoordinates; + + struct floatArray * normalCoordinates; + + struct array * blocks; + + GLuint vertexArrayObject; + + GLuint uniformBuffer; + + GLuint indexBuffer; + + GLuint vertexbuffer; + + GLuint textureCoordinateBuffer; + + GLuint meshIndexBuffer; + + GLuint uvBuffer; + + struct unsignedIntegerArray * uniformBuffers; + + +} mesh; + +struct block * mesh_getUniformBlock( mesh * this, char * blockName ); + +void mesh_bindBlock( mesh * this, struct block * blockInstance ); + +void mesh_setProgram( mesh * this, struct program * currentProgram ); + +GLuint mesh_getGLTypeSize( mesh * this, GLuint type ); + +GLuint mesh_getComponentType( mesh * this, GLuint type ); + +GLuint mesh_getItemSize( mesh * this, GLuint type ); + +GLuint mesh_createBuffer( mesh * this, char * attributeName, void * data, GLenum target, GLenum usage ); + +void mesh_createBuffers( mesh * this ); + +void mesh_createOrderedTriangleStripQuad( mesh * this ); + +mesh mesh_new( ); + +mesh * mesh_newPointer( ); + +#endif + + +typedef struct mesh mesh; + + + diff --git a/application/demos/example.opengl/engine/opengl.c b/application/demos/example.opengl/engine/opengl.c new file mode 100644 index 0000000..60b0e23 --- /dev/null +++ b/application/demos/example.opengl/engine/opengl.c @@ -0,0 +1,369 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +event * globalEvent; + +resourceManager * resources; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void opengl_initialize( opengl * this ) { + + printf("initialize opengl.\n"); + + resources = resourceManager_newPointer(); + + opengl_setupWindow( this ); + + opengl_setupManagers( this ); + + opengl_showVersion( this ); + + + + opengl_setupPipeline( this ); + + + + opengl_setupTime( this ); + + opengl_setupRenderLoop( this ); + + } + +void opengl_showExtensions( opengl * this ) { + + GLint max_layers; + + glGetIntegerv ( GL_MAX_ARRAY_TEXTURE_LAYERS, &max_layers ); + + printf("GL_MAX_ARRAY_TEXTURE_LAYERS: %i\n", max_layers); + + + GLint max_texture_size; + + glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_texture_size); + + printf("GL_MAX_TEXTURE_SIZE: %i\n", max_texture_size); + + + } + +void opengl_showVersion( opengl * this ) { + + printf("opengl version : %s\n\n", glGetString(GL_VERSION) ); + + } + +void opengl_setupTime( opengl * this ) { + + clock_gettime( CLOCK_REALTIME, &this->startTime ); + + } + +void opengl_setupManagers( opengl * this ) { + + this->eventManger->mainDisplay = this->mainDisplay; + + this->eventManger->mainWindow = this->mainWindow; + + this->eventManger->RootWindow = this->RootWindow; + + } + +void opengl_setupWindow( opengl * this ) { + + windowManager_setupDisplay( this->windowManager ); + + windowManager_setupWindow( this->windowManager ); + + + this->mainDisplay = this->windowManager->mainDisplay; + + this->mainWindow = this->windowManager->mainWindow; + + this->RootWindow = this->windowManager->RootWindow; + + } + +void opengl_setupRenderLoop( opengl * this ) { + + int IsProgramRunning = 1; + + while( IsProgramRunning ) { + + while( XPending( this->mainDisplay ) ) { + + XEvent GeneralEvent = {}; + + XNextEvent( this->mainDisplay, &GeneralEvent ); + + switch( GeneralEvent.type ) { + + case ClientMessage: + + + IsProgramRunning = 0; + + break; + } + + } + + opengl_render( this ); + + } + + } + +void opengl_setupPipeline( opengl * this ) { + + quads * quadsPass = quads_newPointer(); + + font * fontPass = font_newPointer(); + + compute * computePass = compute_newPointer(); + + compute2 * computePass2 = compute2_newPointer(); + + tesselation * tesselationPass = tesselation_newPointer(); + + + + + pipeline_addRenderPass( this->pipeline, 1, (int[1]){ 44 }, quadsPass ); + + + + + + + + + } + +double opengl_clockToMilliseconds( opengl * this, clock_t ticks ) { + + return ( ticks / ( double ) CLOCKS_PER_SEC ); + + } + +void opengl_render( opengl * this ) { + + + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + opengl_clear( this, GL_DEPTH_BUFFER_BIT ); + + globalEvent = eventManger_fetchEvent( this->eventManger ); + + pipeline_render( this->pipeline ); + + opengl_swapBuffers( this ); + + + + } + +void opengl_displayFPS( opengl * this ) { + + struct timespec now; + + clock_gettime( CLOCK_REALTIME, &now ); + + this->frameCount++; + + int elapsedTime = now.tv_sec - this->startTime.tv_sec; + + if( elapsedTime != this->lastTime ) { + + printf("%i fps.\n\n", this->frameCount ); + + this->lastTime = elapsedTime; + + this->frameCount = 0; + + } + + } + +void opengl_clear( opengl * this, GLbitfield mask ) { + + glClear( mask ); + + } + +void opengl_clearColor( opengl * this, float r, float g, float b, float a ) { + + glClearColor( r, g, b, a ); + + } + +void opengl_swapBuffers( opengl * this ) { + + PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT; + + PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA; + + PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI; + + + glXSwapIntervalEXT = ( PFNGLXSWAPINTERVALEXTPROC ) glXGetProcAddress( ( const GLubyte * ) "glXSwapIntervalEXT" ); + + if ( glXSwapIntervalEXT != NULL ) { + + glXSwapIntervalEXT( this->mainDisplay, this->mainWindow, 0 ); + + } else { + + glXSwapIntervalMESA = ( PFNGLXSWAPINTERVALMESAPROC ) glXGetProcAddress( ( const GLubyte * ) "glXSwapIntervalMESA" ); + + if ( glXSwapIntervalMESA != NULL ) { + + glXSwapIntervalMESA( 0 ); + + } else { + + glXSwapIntervalSGI = ( PFNGLXSWAPINTERVALSGIPROC ) glXGetProcAddress( ( const GLubyte * ) "glXSwapIntervalSGI" ); + + if ( glXSwapIntervalSGI != NULL ) { + + glXSwapIntervalSGI( 0 ); + + } + } + } + + glXSwapBuffers( this->mainDisplay, this->mainWindow ); + + } + +opengl opengl_new() { + + opengl instance; + + instance.lastTime = clock(); + + instance.frameCount = 0; + + instance.windowManager = windowManager_newPointer(); + + instance.eventManger = eventManger_newPointer(); + + instance.pipeline = pipeline_newPointer(); + + return instance; + +} + +opengl * opengl_newPointer() { + + struct opengl * pointer = malloc( sizeof ( struct opengl ) ); + + pointer->lastTime = clock(); + + pointer->frameCount = 0; + + pointer->windowManager = windowManager_newPointer(); + + pointer->eventManger = eventManger_newPointer(); + + pointer->pipeline = pipeline_newPointer(); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/opengl.h b/application/demos/example.opengl/engine/opengl.h new file mode 100644 index 0000000..d52521d --- /dev/null +++ b/application/demos/example.opengl/engine/opengl.h @@ -0,0 +1,142 @@ +#ifndef _opengl + +#define _opengl + + +// Macros + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include "./event.h" + +#include "./windowManager.h" + +#include "./resourceManager.h" + +#include "./renderPasses/renderPassTesselation.h" + +#include "./renderPasses/renderPassCompute2.h" + +#include "./renderPasses/renderPassCompute.h" + +#include "./renderPasses/renderPassFont.h" + +#include "./renderPasses/renderPassQuads.h" + +#include "./pipeline.h" + +#include "./eventManager.h" + +#include "./unsignedIntegerArray.h" + +#include "./floatArray.h" + +#include "./texture2D.h" + +#include "./sampler2D.h" + +#include "./shader.h" + +#include "./mesh.h" + + +typedef struct opengl{ + + Display * mainDisplay; + + Window mainWindow; + + int MainScreen; + + Window RootWindow; + + int lastTime; + + struct timespec startTime; + + int frameCount; + + sampler2D * testSampler; + + struct windowManager * windowManager; + + struct eventManger * eventManger; + + struct pipeline * pipeline; + + +} opengl; + +void opengl_initialize( opengl * this ); + +void opengl_showExtensions( opengl * this ); + +void opengl_showVersion( opengl * this ); + +void opengl_setupTime( opengl * this ); + +void opengl_setupManagers( opengl * this ); + +void opengl_setupWindow( opengl * this ); + +void opengl_setupRenderLoop( opengl * this ); + +void opengl_setupPipeline( opengl * this ); + +double opengl_clockToMilliseconds( opengl * this, clock_t ticks ); + +void opengl_render( opengl * this ); + +void opengl_displayFPS( opengl * this ); + +void opengl_clear( opengl * this, GLbitfield mask ); + +void opengl_clearColor( opengl * this, float r, float g, float b, float a ); + +void opengl_swapBuffers( opengl * this ); + +resourceManager * resources; + +event * globalEvent; + +opengl opengl_new( ); + +opengl * opengl_newPointer( ); + +#endif + + +typedef struct opengl opengl; + + + diff --git a/application/demos/example.opengl/engine/pipeline.c b/application/demos/example.opengl/engine/pipeline.c new file mode 100644 index 0000000..00bd420 --- /dev/null +++ b/application/demos/example.opengl/engine/pipeline.c @@ -0,0 +1,113 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + +void pipeline_addRenderPass( pipeline * this, int count, int datatypes[], ... ) { + + va_list args; + + va_start( args, count ); + + int classIndex = datatypes[0]; + + vector_int_add( this->classIndices, classIndex ); + + + + void * voidPointer = va_arg( args, void * ); + + int methodIndex = getMethodIndexByPropertyName( classIndex, "prepare" ); + + int renderMethodIndex = getMethodIndexByPropertyName( classIndex, "render" ); + + + vector_int_add( this->methodIndices, renderMethodIndex ); + + + + int classIndexTest = vector_int_get( this->classIndices, 0 ); + + + + callMethodOfClass( classIndex, methodIndex, voidPointer ); + + printf("\n"); + + va_end( args ); + + + array_add( this->renderPasses, voidPointer ); + + } + +void pipeline_render( pipeline * this ) { + + array * renderPasses = this->renderPasses; + + int renderPassCount = array_length( renderPasses ); + + for (int i = 0; i < renderPassCount; ++i) + { + + int classIndex = vector_int_get( this->classIndices, i ); + + void * voidPointer = array_get( renderPasses, i ); + + int methodIndex = vector_int_get( this->methodIndices, i ); + + callMethodOfClass( classIndex, methodIndex, voidPointer ); + + } + + } + +pipeline pipeline_new() { + + pipeline instance; + + instance.__classIndex = 45; + + instance.renderPasses = array_newPointer(); + + instance.classIndices = vector_int_newPointer(); + + instance.methodIndices = vector_int_newPointer(); + + return instance; + +} + +pipeline * pipeline_newPointer() { + + struct pipeline * pointer = malloc( sizeof ( struct pipeline ) ); + + pointer->__classIndex = 45; + + pointer->renderPasses = array_newPointer(); + + pointer->classIndices = vector_int_newPointer(); + + pointer->methodIndices = vector_int_newPointer(); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/pipeline.h b/application/demos/example.opengl/engine/pipeline.h new file mode 100644 index 0000000..e4d6242 --- /dev/null +++ b/application/demos/example.opengl/engine/pipeline.h @@ -0,0 +1,55 @@ +#ifndef _pipeline + +#define _pipeline + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "../classConfiguration.h" + +#include "./vector.h" + +#include "./renderPasses/renderPass.h" + +#include "../array.h" + +#include "../int.h" + + +typedef struct pipeline{ + + unsigned short __classIndex; + + array * renderPasses; + + vector_int * classIndices; + + vector_int * methodIndices; + + +} pipeline; + +void pipeline_addRenderPass( pipeline * this, int count, int datatypes[], ... ); + +void pipeline_render( pipeline * this ); + +pipeline pipeline_new( ); + +pipeline * pipeline_newPointer( ); + +#endif + + +typedef struct pipeline pipeline; + + + diff --git a/application/demos/example.opengl/engine/program.c b/application/demos/example.opengl/engine/program.c new file mode 100644 index 0000000..486fd4b --- /dev/null +++ b/application/demos/example.opengl/engine/program.c @@ -0,0 +1,568 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void program_addShader( program * this, struct shader * shaderInstance ) { + + array_add( this->shaders, shaderInstance ); + + } + + +GLint program_glGetProgramResourceiv( program * this, GLint programProperty, GLint index, GLint Property ) { + + GLint offsetValues; + + glGetProgramResourceiv( this->glProgram, programProperty, index, 1, &Property , 1, 0, &offsetValues ); + + return offsetValues; + + } + +GLchar * program_glGetProgramResourceName( program * this, GLint programProperty, GLint index, GLint nameLength ) { + + + GLchar name[ GL_NAME_LENGTH + 1 ]; + + glGetProgramResourceName( + this->glProgram, + + programProperty, + index, + GL_NAME_LENGTH + 1, + 0, + name ); + + + return name; + + } + + +void program_extractBlocks( program * this ) { + + GLint programInterfaces[2] = { GL_SHADER_STORAGE_BLOCK, GL_UNIFORM_BLOCK }; + + GLint programProperties[2] = { GL_BUFFER_VARIABLE, GL_UNIFORM }; + + GLenum programBufferTypes[2] = { GL_SHADER_STORAGE_BUFFER, GL_UNIFORM_BUFFER }; + + + + for (int blockTypeIndex = 0; blockTypeIndex < 2; ++blockTypeIndex) + { + + + GLint program = this->glProgram; + + GLint numActiveResources; + + GLint programInterface = programInterfaces[blockTypeIndex]; + + GLint programProperty = programProperties[blockTypeIndex]; + + GLenum programBufferType = programBufferTypes[blockTypeIndex]; + + glGetProgramInterfaceiv( program, programInterface, GL_ACTIVE_RESOURCES, &numActiveResources ); + + + + for ( GLuint blockIndex = 0; blockIndex < numActiveResources; blockIndex++ ) { + + struct block * blockInstance = block_newPointer(); + + + + GLint blockNameLength = program_glGetProgramResourceiv( this, programInterface, blockIndex, GL_NAME_LENGTH ); + + blockInstance->bufferSize = program_glGetProgramResourceiv( this, programInterface, blockIndex, GL_BUFFER_DATA_SIZE ); + + GLint numberActiveVariables = program_glGetProgramResourceiv( this, programInterface, blockIndex, GL_NUM_ACTIVE_VARIABLES ); + + blockInstance->bindingPoint = program_glGetProgramResourceiv( this, programInterface, blockIndex, GL_BUFFER_BINDING ); + + + GLchar name[ GL_NAME_LENGTH + 1 ]; + + glGetProgramResourceName( this->glProgram, programInterface, blockIndex, GL_NAME_LENGTH + 1, NULL, name ); + + blockInstance->name = malloc( GL_NAME_LENGTH ); + + strcpy( blockInstance->name, name ); + + + blockInstance->bufferType = programBufferType; + + printf("block:%s \n\n", blockInstance->name ); + + printf(" block name %s\n", blockInstance->name); + + printf(" block buffer size: %i\n", blockInstance->bufferSize); + + printf(" block binding point: %i\n\n", blockInstance->bindingPoint); + + + + + GLint indices[ numberActiveVariables ]; + + GLenum member = GL_ACTIVE_VARIABLES; + + glGetProgramResourceiv( program, programInterface, blockIndex, 1, &member, numberActiveVariables, 0, indices ); + + printf(" number of variables: %i\n\n\n", numberActiveVariables); + + + + + for ( GLuint index = 0; index < numberActiveVariables; index++ ) + { + + struct member * memberInstance = member_newPointer(); + + + GLint itemIndex = indices[ index ]; + + memberInstance->index = itemIndex; + + GLint nameLength = program_glGetProgramResourceiv( this, programProperty, itemIndex, GL_NAME_LENGTH ); + + memberInstance->offset = program_glGetProgramResourceiv( this, programProperty, itemIndex, GL_OFFSET ); + + memberInstance->type = program_glGetProgramResourceiv( this, programProperty, itemIndex, GL_TYPE ); + + memberInstance->arrayStride = program_glGetProgramResourceiv( this, programProperty, itemIndex, GL_ARRAY_STRIDE ); + + + memberInstance->size = program_glGetProgramResourceiv( this, programProperty, itemIndex, GL_ARRAY_SIZE ); + + int topLevelSize = program_glGetProgramResourceiv( this, programProperty, itemIndex, GL_TOP_LEVEL_ARRAY_SIZE ); + + int topLevelStride = program_glGetProgramResourceiv( this, programProperty, itemIndex, GL_TOP_LEVEL_ARRAY_STRIDE ); + + + if( memberInstance->arrayStride == 0 ) { + + memberInstance->arrayStride = topLevelStride; + + } + + memberInstance->topLevelSize = topLevelSize; + + + + + + GLchar memberName[ GL_NAME_LENGTH + 1 ]; + + glGetProgramResourceName( this->glProgram, programProperty, itemIndex, GL_NAME_LENGTH + 1, NULL, memberName ); + + memberInstance->name = malloc( GL_NAME_LENGTH ); + + strcpy( memberInstance->name, memberName ); + + + + printf(" offset: #%i name: %s vec2: %i offset: %i itemSize / arrayStride: %i Array size: %i toplevel size: %i top level size: %i \n\n", + + memberInstance->index, + memberInstance->name, + memberInstance->type == GL_FLOAT_VEC2, + memberInstance->offset, + memberInstance->arrayStride, + memberInstance->size, topLevelSize, + topLevelStride ); + + + + block_add( blockInstance, memberInstance ); + + } + + block_createBuffer( blockInstance ); + + array_add( this->blocks, blockInstance ); + + } + + } + + + } + +struct block * program_createNewBlock( program * this, char * blockName ) { + + printf("Copy buffer: %s\n\n", blockName); + + block * originalBlock = program_getBlock( this, blockName ); + + block * blockCopy = block_newPointer(); + + blockCopy->members = originalBlock->members; + + blockCopy->bindingPoint = originalBlock->bindingPoint; + + blockCopy->index = originalBlock->index; + + blockCopy->bufferSize = originalBlock->bufferSize; + + block_createBuffer( blockCopy ); + + return blockCopy; + + } + +struct block * program_getBlock( program * this, char * blockName ) { + + int blockCount = array_length( this->blocks ); + + for ( int i = 0; i < blockCount; ++i ) + { + block * currentBlock = array_get( this->blocks, i ); + + char * currentBlockName = currentBlock->name; + + if( char_operator_compare( currentBlockName , blockName) ) { + + return currentBlock; + + } + + } + + return NULL; + + } + +void program_create( program * this ) { + + this->glProgram = glCreateProgram(); + + + array * shaders = this->shaders; + + int shaderCount = array_length( shaders ); + + + for (int i = 0; i < shaderCount; ++i) + { + + shader * currentShader = array_get( shaders, i ); + + glAttachShader( this->glProgram, currentShader->glShader ); + + } + + glLinkProgram( this->glProgram ); + + glUseProgram( this->glProgram ); + + + program_extractBlocks( this ); + + program_extractAttributes( this ); + + program_extractUniforms( this ); + + } + +void program_bindBlock( program * this, char * blockName ) { + + block * currentBlock = program_getBlock( this, blockName ); + + glBindBufferBase( currentBlock->bufferType, currentBlock->bindingPoint, currentBlock->buffer ); + + } + +void program_use( program * this ) { + + glUseProgram( this->glProgram ); + + } + + +void program_extractUniforms( program * this ) { + + int attributeCount = 0; + + GLsizei bufSize = 64; + + GLsizei length; + + GLint size; + + GLenum type; + + int uniformCount = 0; + + glGetProgramiv( this->glProgram, GL_ACTIVE_UNIFORMS, &uniformCount ); + + for (int i = 0; i < uniformCount; i++) + { + + struct uniform * uniformInstance = uniform_newPointer(); + + GLenum type; + + GLchar name[bufSize]; + + glGetActiveUniform( this->glProgram, ( GLuint ) i, bufSize, &length, &size, &type, uniformInstance->name ); + + + + GLint uniformLocation = glGetUniformLocation( this->glProgram, uniformInstance->name ); + + uniformInstance->location = uniformLocation; + + uniformInstance->type = type; + + array_add( this->uniforms, uniformInstance ); + + } + + } + +void program_extractAttributes( program * this ) { + + int attributeCount = 0; + + GLsizei bufSize = 64; + + GLsizei length; + + GLint size; + + GLenum type; + + glGetProgramiv( this->glProgram, GL_ACTIVE_ATTRIBUTES, &attributeCount ); + + for (int i = 0; i < attributeCount; i++) + { + GLenum type; + + attribute * attributeInstance = attribute_newPointer(); + + glGetActiveAttrib( this->glProgram, ( GLuint ) i, bufSize, &length, &size, &type, attributeInstance->name); + + + + GLint attributeLocation = glGetAttribLocation( this->glProgram, attributeInstance->name ); + + glEnableVertexAttribArray( attributeLocation ); + + + attributeInstance->location = attributeLocation; + + + + attributeInstance->type = type; + + array_add( this->attributes, attributeInstance ); + + + } + + } + +struct attribute * program_getAttributeByName( program * this, char * attributeName ) { + + int attributeCount = array_length( this->attributes ); + + + + for ( int i = 0; i < attributeCount; ++i ) + { + struct attribute * currentAttribute = array_get( this->attributes, i ); + + char * currentAttributeName = currentAttribute->name; + + + + if( char_operator_compare( currentAttributeName , attributeName) ) { + + return currentAttribute; + + } + + } + + return NULL; + + } + +void program_setUniform( program * this, char * name, void * value ) { + + int uniformCount = array_length( this->uniforms ); + + + + for (int i = 0; i < uniformCount; ++i) + { + uniform * currentUniform = array_get( this->uniforms, i ); + + char * uniformName = (char *)currentUniform->name; + + + + if( char_operator_compare( uniformName , name) ) { + + + + switch( currentUniform->type ) { + + + case GL_FLOAT_VEC2: + + vector2 * vector2Value = ( vector2 * ) value; + + + + glUniform2f( currentUniform->location, vector2Value->x, vector2Value->y ); + + break; + + case GL_FLOAT_VEC3: + + vector3 * vector3Value = ( vector3 * ) value; + + + + glUniform3f( currentUniform->location, vector3Value->x, vector3Value->y, vector3Value->z ); + + break; + + case GL_SAMPLER_2D: + + program_updateSampler2D( this, currentUniform, value ); + + break; + + + case GL_SAMPLER_2D_ARRAY: + + program_updateSampler2D( this, currentUniform, value ); + + break; + + + + + } + + } + + + } + + + } + +void program_updateSampler2D( program * this, uniform * currentUniform, void * value ) { + + glEnable( GL_BLEND ); + + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + + sampler2D * sampler = ( sampler2D * ) value; + + + if( !sampler->binded ) { + + sampler->index = this->samplerIndex++; + + sampler2D_bind( sampler ); + + + + } + + + + glActiveTexture( GL_TEXTURE0 + sampler->index ); + + glBindTexture( sampler->target, sampler->glTexture ); + + + + glUniform1i( currentUniform->location, sampler->index ); + + + } + +program program_new() { + + program instance; + + instance.samplerIndex = 0; + + instance.uniforms = array_newPointer(); + + instance.attributes = array_newPointer(); + + instance.blocks = array_newPointer(); + + instance.shaders = array_newPointer(); + + return instance; + +} + +program * program_newPointer() { + + struct program * pointer = malloc( sizeof ( struct program ) ); + + pointer->samplerIndex = 0; + + pointer->uniforms = array_newPointer(); + + pointer->attributes = array_newPointer(); + + pointer->blocks = array_newPointer(); + + pointer->shaders = array_newPointer(); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/program.h b/application/demos/example.opengl/engine/program.h new file mode 100644 index 0000000..49be66c --- /dev/null +++ b/application/demos/example.opengl/engine/program.h @@ -0,0 +1,100 @@ +#ifndef _program + +#define _program + + +// Macros + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "shader.h" + +#include "sampler2D.h" + +#include "../char.h" + +#include "../array.h" + +#include "fileSystem.h" + +#include + +#include + +#include + +#include + +#include "uniform.h" + +#include "member.h" + +#include "block.h" + + +typedef struct program{ + + GLuint samplerIndex; + + array * uniforms; + + array * attributes; + + array * blocks; + + array * shaders; + + GLuint glProgram; + + +} program; + +void program_addShader( program * this, struct shader * shaderInstance ); + +GLint program_glGetProgramResourceiv( program * this, GLint programProperty, GLint index, GLint Property ); + +GLchar * program_glGetProgramResourceName( program * this, GLint programProperty, GLint index, GLint nameLength ); + +void program_extractBlocks( program * this ); + +struct block * program_createNewBlock( program * this, char * blockName ); + +struct block * program_getBlock( program * this, char * blockName ); + +void program_create( program * this ); + +void program_bindBlock( program * this, char * blockName ); + +void program_use( program * this ); + +void program_extractUniforms( program * this ); + +void program_extractAttributes( program * this ); + +struct attribute * program_getAttributeByName( program * this, char * attributeName ); + +void program_setUniform( program * this, char * name, void * value ); + +void program_updateSampler2D( program * this, uniform * currentUniform, void * value ); + +program program_new( ); + +program * program_newPointer( ); + +#endif + + +typedef struct program program; + + + diff --git a/application/demos/example.opengl/engine/quadMesh.c b/application/demos/example.opengl/engine/quadMesh.c new file mode 100644 index 0000000..e966129 --- /dev/null +++ b/application/demos/example.opengl/engine/quadMesh.c @@ -0,0 +1,23 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + +quadMesh quadMesh_new() { + + quadMesh instance; + + return instance; + +} + +quadMesh * quadMesh_newPointer() { + + struct quadMesh * pointer = malloc( sizeof ( struct quadMesh ) ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/quadMesh.h b/application/demos/example.opengl/engine/quadMesh.h new file mode 100644 index 0000000..4612d5c --- /dev/null +++ b/application/demos/example.opengl/engine/quadMesh.h @@ -0,0 +1,55 @@ +#ifndef _quadMesh + +#define _quadMesh + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "vector.h" + +#include "vector3.h" + +#include "vector2.h" + + +typedef struct quadMesh{ + + vector2 position; + + vector2 size; + + vector3 color; + + float zIndex; + + float opacity; + + int textureIndex; + + int features; + + int elementIndex; + + +} quadMesh; + +quadMesh quadMesh_new( ); + +quadMesh * quadMesh_newPointer( ); + +#endif + + +typedef struct quadMesh quadMesh; + + + diff --git a/application/demos/example.opengl/engine/renderPasses/renderPass.c b/application/demos/example.opengl/engine/renderPasses/renderPass.c new file mode 100644 index 0000000..a3107ef --- /dev/null +++ b/application/demos/example.opengl/engine/renderPasses/renderPass.c @@ -0,0 +1,46 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + +void renderPass_prepare( renderPass * this ) { + + + } + + +void renderPass_render( renderPass * this ) { + + + + } + +renderPass renderPass_new() { + + renderPass instance; + + instance.enabled = true; + + return instance; + +} + +renderPass * renderPass_newPointer() { + + struct renderPass * pointer = malloc( sizeof ( struct renderPass ) ); + + pointer->enabled = true; + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/renderPasses/renderPass.h b/application/demos/example.opengl/engine/renderPasses/renderPass.h new file mode 100644 index 0000000..850837a --- /dev/null +++ b/application/demos/example.opengl/engine/renderPasses/renderPass.h @@ -0,0 +1,47 @@ +#ifndef _renderPass + +#define _renderPass + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "mesh.h" + +#include "shader.h" + + +typedef struct renderPass{ + + bool enabled; + + struct shader * shader; + + struct mesh * mesh; + + +} renderPass; + +void renderPass_prepare( renderPass * this ); + +void renderPass_render( renderPass * this ); + +renderPass renderPass_new( ); + +renderPass * renderPass_newPointer( ); + +#endif + + +typedef struct renderPass renderPass; + + + diff --git a/application/demos/example.opengl/engine/renderPasses/renderPassCompute.c b/application/demos/example.opengl/engine/renderPasses/renderPassCompute.c new file mode 100644 index 0000000..90d5f69 --- /dev/null +++ b/application/demos/example.opengl/engine/renderPasses/renderPassCompute.c @@ -0,0 +1,115 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void compute_prepare( compute * this ) { + + printf("\n\n\n Prepare renderPass Compute\n\n\n\n\n"); + + shader * computeShader = shader_newPointer( GL_COMPUTE_SHADER ); + + shader_loadFromFile( computeShader, "assets/shaders/addition.comp" ); + + + this->program = program_newPointer(); + + program_addShader( this->program, computeShader ); + + program_create( this->program ); + + + vector_vector2 * inputA = vector_vector2_newPointer(); + + for (int i = 0; i < 100; ++i) + { + + vector2 a = vector2_new( i, i ); + + vector_vector2_add( inputA, a ); + + } + + vector_vector2 * inputB = vector_vector2_newPointer(); + + for (int i = 0; i < 100; ++i) + { + + vector2 a = vector2_new( 0, 10 ); + + vector_vector2_add( inputB, a ); + + } + + block * inputBlock = program_getBlock( this->program, "inputBlock" ); + + block_setMemberArray( inputBlock, "array_a[0]", ( float * ) inputA->items ); + + block_setMemberArray( inputBlock, "array_b[0]", ( float * ) inputB->items ); + + block_upload( inputBlock ); + + } + +void compute_render( compute * this ) { + + program_use( this->program ); + + program_bindBlock( this->program, "inputBlock"); + + program_bindBlock( this->program, "outputBlock"); + + + glDispatchCompute( 1, 1, 1 ); + + glMemoryBarrier( GL_SHADER_STORAGE_BARRIER_BIT ); + + } + +compute compute_new() { + + compute instance; + + instance.active = true; + + return instance; + +} + +compute * compute_newPointer() { + + struct compute * pointer = malloc( sizeof ( struct compute ) ); + + pointer->active = true; + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/renderPasses/renderPassCompute.h b/application/demos/example.opengl/engine/renderPasses/renderPassCompute.h new file mode 100644 index 0000000..25cab5a --- /dev/null +++ b/application/demos/example.opengl/engine/renderPasses/renderPassCompute.h @@ -0,0 +1,63 @@ +#ifndef _renderPassCompute + +#define _renderPassCompute + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "../mesh.h" + +#include "../vector.h" + +#include "../block.h" + +#include "stdbool.h" + +#include "../sampler2D.h" + +#include "../int.h" + +#include "../program.h" + +#include "../shader.h" + +#include "../vector2.h" + +#include "../event.h" + +#include "./renderPass.h" + + +typedef struct compute{ + + struct program * program; + + int active; + + +} compute; + +void compute_prepare( compute * this ); + +void compute_render( compute * this ); + +compute compute_new( ); + +compute * compute_newPointer( ); + +#endif + + +typedef struct compute compute; + + + diff --git a/application/demos/example.opengl/engine/renderPasses/renderPassCompute2.c b/application/demos/example.opengl/engine/renderPasses/renderPassCompute2.c new file mode 100644 index 0000000..b6865ac --- /dev/null +++ b/application/demos/example.opengl/engine/renderPasses/renderPassCompute2.c @@ -0,0 +1,99 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + +void compute2_prepare( compute2 * this ) { + + printf("\n\n\n Prepare renderPass Compute 2\n\n\n\n\n"); + + shader * computeShader = shader_newPointer( GL_COMPUTE_SHADER ); + + shader_loadFromFile( computeShader, "assets/shaders/addition2.comp" ); + + + this->program = program_newPointer(); + + program_addShader( this->program, computeShader ); + + program_create( this->program ); + + } + +void compute2_render( compute2 * this ) { + + if( this->active ) { + + program_use( this->program ); + + program_bindBlock( this->program, "outputBlock2" ); + + + glDispatchCompute( 1, 1, 1 ); + + + block * outputBlock = program_getBlock( this->program, "outputBlock2" ); + + vector_vector2 * output = block_getMemberArray( outputBlock, "array_d[0]" ); + + int count = vector_vector2_length( output ); + + for (int i = 0; i < count; ++i) + { + + vector2 currentVector = vector_vector2_get( output, i ); + + printf("%i = %f %f \n", i, i, currentVector.x, currentVector.y ); + + } + + printf("length: %i\n\n", count); + + this->active = false; + + } + + } + +compute2 compute2_new() { + + compute2 instance; + + instance.active = true; + + return instance; + +} + +compute2 * compute2_newPointer() { + + struct compute2 * pointer = malloc( sizeof ( struct compute2 ) ); + + pointer->active = true; + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/renderPasses/renderPassCompute2.h b/application/demos/example.opengl/engine/renderPasses/renderPassCompute2.h new file mode 100644 index 0000000..5e6215b --- /dev/null +++ b/application/demos/example.opengl/engine/renderPasses/renderPassCompute2.h @@ -0,0 +1,59 @@ +#ifndef _renderPassCompute2 + +#define _renderPassCompute2 + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "../block.h" + +#include "stdbool.h" + +#include "../sampler2D.h" + +#include "../../int.h" + +#include "../program.h" + +#include "../shader.h" + +#include "../../vector2.h" + +#include "../event.h" + +#include "renderPass.h" + + +typedef struct compute2{ + + struct program * program; + + int active; + + +} compute2; + +void compute2_prepare( compute2 * this ); + +void compute2_render( compute2 * this ); + +compute2 compute2_new( ); + +compute2 * compute2_newPointer( ); + +#endif + + +typedef struct compute2 compute2; + + + diff --git a/application/demos/example.opengl/engine/renderPasses/renderPassFont.c b/application/demos/example.opengl/engine/renderPasses/renderPassFont.c new file mode 100644 index 0000000..4aa4531 --- /dev/null +++ b/application/demos/example.opengl/engine/renderPasses/renderPassFont.c @@ -0,0 +1,193 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + +char * font_textFromNumber( font * this, int i ) { + + char * fileName = malloc( sizeof( char ) * 100 ); + + sprintf( fileName, "%d", i ); + + return fileName; + + } + +void font_prepare( font * this ) { + + printf("\n\n\n Prepare renderPass Font\n\n\n\n\n"); + + + + + shader * vertexShader = shader_newPointer( GL_VERTEX_SHADER ); + + shader_loadFromFile( vertexShader, "assets/shaders/quad.vertex" ); + + + shader * fragmentShader = shader_newPointer( GL_FRAGMENT_SHADER ); + + shader_loadFromFile( fragmentShader, "assets/shaders/quad.fragment" ); + + + + this->program = program_newPointer(); + + program_addShader( this->program, vertexShader ); + + program_addShader( this->program, fragmentShader ); + + program_create( this->program ); + + + sampler2D * samplerArray = sampler2D_newPointer(); + + samplerArray->target = GL_TEXTURE_2D_ARRAY; + + samplerArray->format = GL_RED; + + samplerArray->internalFormat = GL_RED; + + samplerArray->WRAP_S = GL_CLAMP_TO_EDGE; + + samplerArray->WRAP_S = GL_CLAMP_TO_EDGE; + + samplerArray->cubeSize = vector3_newPointer( 128, 128, 170 ); + + samplerArray->UNPACK_ALIGNMENT = true; + + + this->samplerArray = samplerArray; + + block * fontBlock = program_getBlock( this->program, "fontData" ); + + + this->mesh = mesh_newPointer(); + + mesh_setProgram( this->mesh, this->program ); + + mesh_createBuffers( this->mesh ); + + + glUseProgram( this->program->glProgram ); + + for ( int i = 1; i < 170; ++i ) + { + texture2D * characterTexture = fontRenderer_loadFont( this->font, 34 + i ); + + vector2 * offset = characterTexture->offset; + + printf("%c offset left: %f, offset top: %f bitmap->rows: %i\n", (char) 34 + i, offset->x, offset->y, characterTexture->height ); + + vector2 * size = vector2_newPointer( characterTexture->width, characterTexture->height ); + + block_setMemberItem( fontBlock, "fontOffsets[0]", i - 35, offset ); + + + + block_setMemberItem( fontBlock, "fontSizes[0]", i - 35, size ); + + + + sampler2D_addTexture( samplerArray, characterTexture ); + + } + + block_upload( fontBlock ); + + program_setUniform( this->program, "samplerArray", samplerArray ); + + + + vector_int * textArray = vector_int_newPointer(); + + char * someText = "Wauw this is myp first text."; + + for (int i = 0; i < strlen(someText); ++i) + { + + int charNumber = ( char ) someText[i] - 35; + + printf(" %i\n", charNumber ); + + vector_int_add( textArray, charNumber ); + + } + + block * inputBlock = program_getBlock( this->program, "inputBlock" ); + + block_setMemberArray( inputBlock, "characters[0]", ( float * ) textArray->items ); + + block_upload( inputBlock ); + + } + +void font_render( font * this ) { + + int numItems = 12; + + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + + program_use( this->program ); + + program_bindBlock( this->program, "inputBlock"); + + program_bindBlock( this->program, "fontData"); + + + program_setUniform( this->program, "samplerArray", this->samplerArray ); + + + + glBindVertexArray( this->mesh->vertexArrayObject ); + + glDrawElements( GL_TRIANGLES, numItems, GL_UNSIGNED_INT, ( void * ) 0 ); + + } + +font font_new() { + + font instance; + + instance.font = fontRenderer_newPointer(); + + return instance; + +} + +font * font_newPointer() { + + struct font * pointer = malloc( sizeof ( struct font ) ); + + pointer->font = fontRenderer_newPointer(); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/renderPasses/renderPassFont.h b/application/demos/example.opengl/engine/renderPasses/renderPassFont.h new file mode 100644 index 0000000..63fc770 --- /dev/null +++ b/application/demos/example.opengl/engine/renderPasses/renderPassFont.h @@ -0,0 +1,63 @@ +#ifndef _renderPassFont + +#define _renderPassFont + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "../mesh.h" + +#include "../program.h" + +#include "../fontRenderer.h" + +#include "int.h" + +#include "../shader.h" + +#include "../vector2.h" + +#include "../event.h" + +#include "renderPass.h" + + +typedef struct font{ + + struct program * program; + + struct mesh * mesh; + + fontRenderer * font; + + sampler2D * samplerArray; + + +} font; + +char * font_textFromNumber( font * this, int i ); + +void font_prepare( font * this ); + +void font_render( font * this ); + +font font_new( ); + +font * font_newPointer( ); + +#endif + + +typedef struct font font; + + + diff --git a/application/demos/example.opengl/engine/renderPasses/renderPassQuads.c b/application/demos/example.opengl/engine/renderPasses/renderPassQuads.c new file mode 100644 index 0000000..39a88d1 --- /dev/null +++ b/application/demos/example.opengl/engine/renderPasses/renderPassQuads.c @@ -0,0 +1,731 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + +event * globalEvent; + +resourceManager * resources; + + + + + + + + + + + + + + + + + + + +char * quads_textFromNumber( quads * this, int i ) { + + char * fileName = malloc( sizeof( char ) * 100 ); + + sprintf( fileName, "%d", i ); + + return fileName; + + } + +void quads_prepare( quads * this ) { + + printf("\n\n\n Prepare renderPass Quad\n\n\n\n\n"); + + + + + + + + + this->samplerArray = sampler2D_newPointer(); + + + for (int i = 1; i < 10; ++i ) + { + + char * fileName = quads_textFromNumber( this, i ); + + char_operator_add( fileName , ".png"); + + printf("load png: %s\n", fileName); + + + + } + + printf("\n\n"); + + this->samplerArray->target = GL_TEXTURE_2D_ARRAY; + + + shader * vertexShader = shader_newPointer( GL_VERTEX_SHADER ); + + shader_loadFromFile( vertexShader, "assets/shaders/multiQuad.vertex" ); + + + shader * fragmentShader = shader_newPointer( GL_FRAGMENT_SHADER ); + + shader_loadFromFile( fragmentShader, "assets/shaders/multiQuad.fragment" ); + + + this->program = program_newPointer(); + + program_addShader( this->program, vertexShader ); + + program_addShader( this->program, fragmentShader ); + + program_create( this->program ); + + + + + + block * orientationBlock = program_getBlock( this->program, "orientation" ); + + block * meshesBlock = program_getBlock( this->program, "meshes" ); + + + this->mesh = mesh_newPointer(); + + mesh_setProgram( this->mesh, this->program ); + + mesh_createBuffers( this->mesh ); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + quads_createMeshes( this ); + + + + + sampler2D_addTexture( this->samplerArray, resourceManager_loadPngImage( resources, "1.png" ) ); + + + block_upload( meshesBlock ); + + } + +void quads_sortOpacity( quads * this, vector_quadMesh * meshes ) { + + + int count = vector_quadMesh_length( meshes ); + + int i, j; + + struct quadMesh temp; + + for (i = 0; i < (count - 1); ++i) + { + for (j = 0; j < count - 1 - i; ++j ) + { + + struct quadMesh quadA = vector_quadMesh_get( meshes, j ); + + struct quadMesh quadB = vector_quadMesh_get( meshes, j + 1 ); + + float a = ( intptr_t ) quadA.zIndex; + + float b = ( intptr_t ) quadB.zIndex; + + if ( a > b ) + { + + temp = meshes->items[j+1]; + + meshes->items[ j + 1 ] = meshes->items[j]; + + meshes->items[ j ] = temp; + + } + } + } + + } + +void quads_createMeshes( quads * this ) { + + + vector_quadMesh * meshes = this->meshes; + + vector_quadMesh_resize( meshes, 100 ); + + + + + + + + + + + + + + + + + + + + + + + vector_element * elements = this->elements; + + + { + + element instance = element_new(); + + element_setter_position( &instance, vector3_new( 200, 200, 1100 ) ); + + element_setter_size( &instance, vector2_new( 200., 200. ) ); + + + + instance.opacity = 1; + + element_setter_background( &instance, 1, (int[1]){ -2 }, "9.png" ); + + + + vector_element_add( elements, instance ); + + + + + } + + + { + + element instance = element_new(); + + element_setter_position( &instance, vector3_new( 100, 100, 500 ) ); + + element_setter_size( &instance, vector2_new( 400., 400. ) ); + + element_setter_background( &instance, 1, (int[1]){ -2 }, "3.png" ); + + + + + + instance.opacity = .9; + + + + + + + + + + + + + + + + + + + + + + + + + vector_element_add( elements, instance ); + + + + { + + element instance = element_new(); + + element_setter_position( &instance, vector3_new( 20, 0, 1300 ) ); + + element_setter_size( &instance, vector2_new( 40., 40. ) ); + + element_setter_background( &instance, 1, (int[1]){ -2 }, "7.png" ); + + instance.opacity = 1; + + vector_element_add( elements, instance ); + + + } + + + + + + + int count = vector_element_length( elements ); + + for (int i = 0; i < count; ++i) + { + + element currentElement = vector_element_get( elements, i ); + + quadMesh meshInstance = quadMesh_new(); + + + meshInstance.elementIndex = i; + + meshInstance.position = vector2_new( currentElement.position.x, currentElement.position.y ); + + meshInstance.zIndex = currentElement.position.z; + + meshInstance.size = currentElement.size; + + + printf("zIndex: %f\n", currentElement.position.z); + + int features = 0; + + if( currentElement.useBackgroundImage ) { + + + + + + meshInstance.textureIndex = sampler2D_getTextureIndex( this->samplerArray ); + + printf("use background image. %s \n", currentElement.backgroundImagePath ); + + sampler2D_addTexture( this->samplerArray, resourceManager_loadPngImage( resources, currentElement.backgroundImagePath ) ); + + } else { + + printf("dont use background color. %f %f %f \n", currentElement.backgroundColor.x, currentElement.backgroundColor.y, currentElement.backgroundColor.z); + + meshInstance.color = currentElement.backgroundColor; + + } + + + meshInstance.features = element_updateFeature( ¤tElement ); + + meshInstance.opacity = currentElement.opacity; + + + + + element_setOriginal( ¤tElement ); + + vector_element_set( elements, i, currentElement ); + + + vector_quadMesh_add( meshes, meshInstance ); + + } + + + + quads_sortOpacity( this, meshes ); + + + + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + block * meshesBlock = program_getBlock( this->program, "meshes" ); + + block_setData( meshesBlock, ( float * ) meshes->items ); + + } + + +quadMesh quads_updateMesh( quads * this, quadMesh currentMesh, element currentElement ) { + + vector2 position = vector2_new( currentElement.position.x, currentElement.position.y ); + + currentMesh.position = position; + + currentMesh.zIndex = currentElement.position.z; + + currentMesh.size = currentElement.size; + + currentMesh.color = currentElement.backgroundColor; + + return currentMesh; + + } + +void quads_callElementEvents( quads * this, event * currentEvent, element * currentElement, int elementIndex ) { + + vector_char_pointer * mouseEvents = currentEvent->mouse->eventTypes; + + int mouseEventCount = vector_char_pointer_length( mouseEvents ); + + for (int k = 0; k < mouseEventCount; ++k) + { + char * mouseEventCode = vector_char_pointer_get( mouseEvents, k ); + + printf(" mouse event: %s\n", mouseEventCode); + + + if( char_operator_compare( mouseEventCode , "click") ) { + + element_click( currentElement ); + + + + } + + if( char_operator_compare( mouseEventCode , "mousedown") ) { + + element_mousedown( currentElement ); + + + + } + + + if( char_operator_compare( mouseEventCode , "mouseup") ) { + + element_mouseup( currentElement ); + + + + } + + if( char_operator_compare( mouseEventCode , "mousemove") ) { + + if( !quads_integerContains( this, this->mouseOverElements, elementIndex ) ) { + + element_mouseover( currentElement ); + + vector_int_add( this->mouseOverElements, elementIndex ); + + } + + } + + } + + } + +bool quads_integerContains( quads * this, vector_int * numbers, int a ) { + + int count = vector_int_length( numbers ); + + for (int j = 0; j < count; ++j) + { + + int b = vector_int_get( numbers, j ); + + if( a == b ) { + + return true; + + } + + } + + return false; + + } + +void quads_render( quads * this ) { + + program * currentProgram = this->program; + + event * currentEvent = globalEvent; + + + block * eventsBlock = program_getBlock( currentProgram, "events" ); + + + + + block * meshesBlock = program_getBlock( currentProgram, "meshes" ); + + + eventsBlock->autoUpload = true; + + block_setMember( eventsBlock, "window", ¤tEvent->screen->size ); + + + meshesBlock->autoUpload = true; + + vector2 mousePosition = globalEvent->mouse->position; + + + int mouseX = ( int ) mousePosition.x; + + int mouseY = ( int ) mousePosition.y; + + + vector_element * elements = this->elements; + + vector_quadMesh * meshes = this->meshes; + + + vector_int * mouseOverElements = this->mouseOverElements; + + int count = vector_quadMesh_length( meshes ); + + for (int i = 0; i < count; ++i) + { + quadMesh currentMesh = vector_quadMesh_get( meshes, i ); + + int left = currentMesh.position.x; + + int top = currentMesh.position.y; + + int right = currentMesh.position.x + currentMesh.size.x; + + int bottom = currentMesh.position.y + currentMesh.size.y; + + int elementIndex = currentMesh.elementIndex; + + + if( mouseX > left && mouseX < right && mouseY > top && mouseY < bottom ) { + + element currentElement = vector_element_get( elements, elementIndex ); + + quads_callElementEvents( this, currentEvent, ¤tElement, elementIndex ); + + currentMesh = quads_updateMesh( this, currentMesh, currentElement ); + + vector_element_set( elements, elementIndex, currentElement ); + + block_setMemberArrayRow( meshesBlock, "meshArray[0].color", i, ( float * ) & currentMesh ); + + } else { + + if( quads_integerContains( this, this->mouseOverElements, elementIndex ) ) { + + printf("mouseout\n\n"); + + vector_int_delete( this->mouseOverElements, elementIndex ); + + element currentElement = vector_element_get( elements, elementIndex ); + + + element_mouseleave( ¤tElement ); + + + + currentMesh = quads_updateMesh( this, currentMesh, currentElement ); + + vector_element_set( elements, elementIndex, currentElement ); + + block_setMemberArrayRow( meshesBlock, "meshArray[0].color", i, ( float * ) & currentMesh ); + + } + + + } + + } + + + + + + + + + + + + + vector2 * position2 = vector2_newPointer( 0.4, 0 ); + + + + + + program_setUniform( this->program, "samplerArray", this->samplerArray ); + + glUseProgram( currentProgram->glProgram ); + + int numItems = 200; + + + + + + + + + + + glDisable(GL_DEPTH_TEST); + + + + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + + + glDepthRange(0.0, 1.0); + + glDepthFunc(GL_ALWAYS); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_CULL_FACE); + + + + + + glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); + + + + glBindVertexArray( this->mesh->vertexArrayObject ); + + glDrawElements( GL_TRIANGLES, numItems, GL_UNSIGNED_INT, ( void * ) 0 ); + + } + +quads quads_new() { + + quads instance; + + instance.font = fontRenderer_newPointer(); + + instance.meshes = vector_quadMesh_newPointer(); + + instance.elements = vector_element_newPointer(); + + instance.mouseOverElements = vector_int_newPointer(); + + return instance; + +} + +quads * quads_newPointer() { + + struct quads * pointer = malloc( sizeof ( struct quads ) ); + + pointer->font = fontRenderer_newPointer(); + + pointer->meshes = vector_quadMesh_newPointer(); + + pointer->elements = vector_element_newPointer(); + + pointer->mouseOverElements = vector_int_newPointer(); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/renderPasses/renderPassQuads.h b/application/demos/example.opengl/engine/renderPasses/renderPassQuads.h new file mode 100644 index 0000000..d430335 --- /dev/null +++ b/application/demos/example.opengl/engine/renderPasses/renderPassQuads.h @@ -0,0 +1,95 @@ +#ifndef _renderPassQuads + +#define _renderPassQuads + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "../element.h" + +#include "../quadMesh.h" + +#include "../mesh.h" + +#include "../resourceManager.h" + +#include "../fontRenderer.h" + +#include "../../int.h" + +#include "../program.h" + +#include "../shader.h" + +#include "../program.h" + +#include "../vector4.h" + +#include "../vector3.h" + +#include "../vector2.h" + +#include "../event.h" + +#include "renderPass.h" + + +typedef struct quads{ + + mesh * mesh; + + fontRenderer * font; + + sampler2D * samplerArray; + + program * program; + + vector_quadMesh * meshes; + + vector_element * elements; + + vector_int * mouseOverElements; + + +} quads; + +char * quads_textFromNumber( quads * this, int i ); + +void quads_prepare( quads * this ); + +void quads_sortOpacity( quads * this, vector_quadMesh * meshes ); + +void quads_createMeshes( quads * this ); + +quadMesh quads_updateMesh( quads * this, quadMesh currentMesh, element currentElement ); + +void quads_callElementEvents( quads * this, event * currentEvent, element * currentElement, int elementIndex ); + +bool quads_integerContains( quads * this, vector_int * numbers, int a ); + +void quads_render( quads * this ); + +extern resourceManager * resources; + +extern event * globalEvent; + +quads quads_new( ); + +quads * quads_newPointer( ); + +#endif + + +typedef struct quads quads; + + + diff --git a/application/demos/example.opengl/engine/renderPasses/renderPassTesselation.c b/application/demos/example.opengl/engine/renderPasses/renderPassTesselation.c new file mode 100644 index 0000000..42aa10d --- /dev/null +++ b/application/demos/example.opengl/engine/renderPasses/renderPassTesselation.c @@ -0,0 +1,137 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + +char * tesselation_textFromNumber( tesselation * this, int i ) { + + char * fileName = malloc( sizeof( char ) * 100 ); + + sprintf( fileName, "%d", i ); + + return fileName; + + } + +void tesselation_prepare( tesselation * this ) { + + shader * vertexShader = shader_newPointer( GL_VERTEX_SHADER ); + + shader_loadFromFile( vertexShader, "assets/shaders/quadScale.vertex" ); + + + shader * fragmentShader = shader_newPointer( GL_FRAGMENT_SHADER ); + + shader_loadFromFile( fragmentShader, "assets/shaders/color.fragment" ); + + + shader * geometryShader = shader_newPointer( GL_GEOMETRY_SHADER ); + + shader_loadFromFile( geometryShader, "assets/shaders/tesselation.geometry.shader" ); + + + shader * tesselationControlShader = shader_newPointer( GL_TESS_CONTROL_SHADER ); + + shader_loadFromFile( tesselationControlShader, "assets/shaders/tesselation.triangle.tsc.shader" ); + + + shader * tesselationEvaluationShader = shader_newPointer( GL_TESS_EVALUATION_SHADER ); + + shader_loadFromFile( tesselationEvaluationShader, "assets/shaders/tesselation.triangle.shader" ); + + + + this->program = program_newPointer(); + + program_addShader( this->program, vertexShader ); + + program_addShader( this->program, fragmentShader ); + + + + + + + + + + program_create( this->program ); + + + + + this->mesh = mesh_newPointer(); + + mesh_setProgram( this->mesh, this->program ); + + mesh_createBuffers( this->mesh ); + + + glUseProgram( this->program->glProgram ); + + + } + +void tesselation_render( tesselation * this ) { + + glUseProgram( this->program->glProgram ); + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + int numItems = 12; + + + + glBindVertexArray( this->mesh->vertexArrayObject ); + + + + + glDrawElements( GL_LINE_STRIP, numItems, GL_UNSIGNED_INT, ( void * ) 0 ); + + } + +tesselation tesselation_new() { + + tesselation instance; + + instance.font = fontRenderer_newPointer(); + + return instance; + +} + +tesselation * tesselation_newPointer() { + + struct tesselation * pointer = malloc( sizeof ( struct tesselation ) ); + + pointer->font = fontRenderer_newPointer(); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/renderPasses/renderPassTesselation.h b/application/demos/example.opengl/engine/renderPasses/renderPassTesselation.h new file mode 100644 index 0000000..de25cb6 --- /dev/null +++ b/application/demos/example.opengl/engine/renderPasses/renderPassTesselation.h @@ -0,0 +1,63 @@ +#ifndef _renderPassTesselation + +#define _renderPassTesselation + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "../mesh.h" + +#include "../program.h" + +#include "../fontRenderer.h" + +#include "int.h" + +#include "../shader.h" + +#include "../vector2.h" + +#include "../event.h" + +#include "renderPass.h" + + +typedef struct tesselation{ + + struct program * program; + + struct mesh * mesh; + + fontRenderer * font; + + sampler2D * samplerArray; + + +} tesselation; + +char * tesselation_textFromNumber( tesselation * this, int i ); + +void tesselation_prepare( tesselation * this ); + +void tesselation_render( tesselation * this ); + +tesselation tesselation_new( ); + +tesselation * tesselation_newPointer( ); + +#endif + + +typedef struct tesselation tesselation; + + + diff --git a/application/demos/example.opengl/engine/resourceManager.c b/application/demos/example.opengl/engine/resourceManager.c new file mode 100644 index 0000000..15fe0c7 --- /dev/null +++ b/application/demos/example.opengl/engine/resourceManager.c @@ -0,0 +1,127 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + +texture2D * resourceManager_loadPngImage( resourceManager * this, char * name ) { + + texture2D * texture = texture2D_newPointer(); + + png_structp png_ptr; + + png_infop info_ptr; + + unsigned int sig_read = 0; + + int color_type; + + int interlace_type; + + FILE * fp; + + if ( ( fp = fopen( name, "rb" ) ) == NULL ) { + + return NULL; + + } + + png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL ); + + if ( png_ptr == NULL ) { + + fclose( fp ); + + return false; + + } + + info_ptr = png_create_info_struct( png_ptr ); + + if ( info_ptr == NULL ) { + + fclose(fp); + + png_destroy_read_struct( &png_ptr, NULL, NULL ); + + return false; + + } + + if ( setjmp( png_jmpbuf( png_ptr ) ) ) { + + png_destroy_read_struct( &png_ptr, &info_ptr, NULL ); + + fclose( fp ); + + return false; + + } + + png_init_io( png_ptr, fp ); + + png_set_sig_bytes( png_ptr, sig_read ); + + png_read_png( png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND, NULL ); + + png_uint_32 width, height; + + int bit_depth; + + png_get_IHDR( png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL ); + + unsigned int row_bytes = png_get_rowbytes( png_ptr, info_ptr ); + + + + texture->width = width; + + texture->height = height; + + texture->hasAlpha = ( color_type == PNG_COLOR_TYPE_RGBA ); + + texture->data = ( unsigned char * ) malloc( row_bytes * texture->height ); + + + png_bytepp row_pointers = png_get_rows( png_ptr, info_ptr ); + + for (int i = 0; i < texture->height; i++) { + + + + + + memcpy( texture->data + ( row_bytes * ( texture->height - 1 - i ) ), row_pointers[ i ], row_bytes ); + + } + + png_destroy_read_struct( &png_ptr, &info_ptr, NULL ); + + fclose( fp ); + + return texture; + + } + +resourceManager resourceManager_new() { + + resourceManager instance; + + return instance; + +} + +resourceManager * resourceManager_newPointer() { + + struct resourceManager * pointer = malloc( sizeof ( struct resourceManager ) ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/resourceManager.h b/application/demos/example.opengl/engine/resourceManager.h new file mode 100644 index 0000000..1934110 --- /dev/null +++ b/application/demos/example.opengl/engine/resourceManager.h @@ -0,0 +1,43 @@ +#ifndef _resourceManager + +#define _resourceManager + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "string.h" + +#include "stdbool.h" + +#include + +#include "texture2D.h" + + +typedef struct resourceManager{ + + +} resourceManager; + +texture2D * resourceManager_loadPngImage( resourceManager * this, char * name ); + +resourceManager resourceManager_new( ); + +resourceManager * resourceManager_newPointer( ); + +#endif + + +typedef struct resourceManager resourceManager; + + + diff --git a/application/demos/example.opengl/engine/sampler2D.c b/application/demos/example.opengl/engine/sampler2D.c new file mode 100644 index 0000000..a008aa5 --- /dev/null +++ b/application/demos/example.opengl/engine/sampler2D.c @@ -0,0 +1,293 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void sampler2D_constructor( sampler2D * this ) { + + glGenTextures( 1, &this->glTexture ); + + } + +void sampler2D_addTexture( sampler2D * this, texture2D * texture ) { + + array_add( this->textures, texture ); + + } + +int sampler2D_getTextureIndex( sampler2D * this ) { + + int numberOfTextures = array_length( this->textures ); + + return numberOfTextures; + + } + +void sampler2D_bind( sampler2D * this ) { + + this->binded = true; + + + + + + + + + + + + + + glActiveTexture( GL_TEXTURE0 + this->index ); + + glBindTexture( this->target, this->glTexture ); + + glTexParameteri( this->target, GL_TEXTURE_WRAP_S, this->WRAP_S ); + + glTexParameteri( this->target, GL_TEXTURE_WRAP_T, this->WRAP_T ); + + glTexParameteri( this->target, GL_TEXTURE_MIN_FILTER, this->MIN_FILTER ); + + glTexParameteri( this->target, GL_TEXTURE_MAG_FILTER, this->MAG_FILTER ); + + + + if( this->target == GL_TEXTURE_2D_ARRAY ) { + + + + int offsetX = 0; + + int offsetY = 0; + + int offsetZ = 0; + + int depth = 1; + + int levelOfDetail = 0; + + int layerCount = 2; + + int mipLevelCount = 1; + + int currentLayer = 0; + + texture2D * texture1 = array_get( this->textures, 0 ); + + int numberOfTextures = array_length( this->textures ); + + + if( this->cubeSize == NULL ) { + + this->cubeSize = vector3_newPointer( texture1->width, texture1->height, numberOfTextures ); + + } + + + + if( this->UNPACK_ALIGNMENT ) { + + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + } else { + + glPixelStorei( GL_UNPACK_ALIGNMENT, 0 ); + + } + + glTexStorage3D( this->target, mipLevelCount, this->format, this->cubeSize->x, this->cubeSize->y, numberOfTextures ); + + GLint data[ texture1->width * texture1->height * numberOfTextures ]; + + glTexImage3D( GL_TEXTURE_2D_ARRAY, levelOfDetail, this->internalFormat, this->cubeSize->x, this->cubeSize->y, numberOfTextures, this->border, this->format, this->type, data); + + for (int i = 0; i < numberOfTextures; ++i) + { + + texture2D * currentTexture = array_get( this->textures, i ); + + float test = 0; + + glTexSubImage3D( this->target, + 0, + offsetX, test , i, + currentTexture->width, currentTexture->height, 1, + this->format, + this->type, + currentTexture->data ); + + } + + + + } else { + + texture2D * texture = array_get( this->textures, 0 ); + + glTexImage2D( this->target, 0, this->internalFormat, texture->width, texture->height, this->border, this->format, this->type, texture->data ); + + } + + + if( this->generateMipmap ) { + + glGenerateMipmap( this->target ); + + } + + + + + } + +sampler2D sampler2D_new() { + + sampler2D instance; + + instance.textures = array_newPointer(); + + instance.binded = false; + + instance.filter = GL_LINEAR; + + instance.MIN_FILTER = GL_LINEAR; + + instance.MAG_FILTER = GL_LINEAR; + + instance.WRAP_S = GL_REPEAT; + + instance.WRAP_T = GL_REPEAT; + + instance.datatype = GL_RGBA; + + instance.format = GL_RGBA; + + instance.internalFormat = GL_RGBA; + + instance.target = GL_TEXTURE_2D; + + instance.type = GL_UNSIGNED_BYTE; + + instance.cubeSize = NULL; + + instance.border = false; + + instance.generateMipmap = true; + + instance.UNPACK_ALIGNMENT = false; + + instance.index = 0; + + sampler2D_constructor( &instance); + + return instance; + +} + +sampler2D * sampler2D_newPointer() { + + struct sampler2D * pointer = malloc( sizeof ( struct sampler2D ) ); + + pointer->textures = array_newPointer(); + + pointer->binded = false; + + pointer->filter = GL_LINEAR; + + pointer->MIN_FILTER = GL_LINEAR; + + pointer->MAG_FILTER = GL_LINEAR; + + pointer->WRAP_S = GL_REPEAT; + + pointer->WRAP_T = GL_REPEAT; + + pointer->datatype = GL_RGBA; + + pointer->format = GL_RGBA; + + pointer->internalFormat = GL_RGBA; + + pointer->target = GL_TEXTURE_2D; + + pointer->type = GL_UNSIGNED_BYTE; + + pointer->cubeSize = NULL; + + pointer->border = false; + + pointer->generateMipmap = true; + + pointer->UNPACK_ALIGNMENT = false; + + pointer->index = 0; + + sampler2D_constructor( pointer ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/sampler2D.h b/application/demos/example.opengl/engine/sampler2D.h new file mode 100644 index 0000000..7cf3f81 --- /dev/null +++ b/application/demos/example.opengl/engine/sampler2D.h @@ -0,0 +1,96 @@ +#ifndef _sampler2D + +#define _sampler2D + + +// Macros + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "../vector3.h" + +#include "../array.h" + +#include "stdbool.h" + +#include "./texture2D.h" + +#include + +#include + +#include + + +typedef struct sampler2D{ + + texture2D * texture; + + array * textures; + + GLuint glTexture; + + GLint binded; + + GLint filter; + + GLint MIN_FILTER; + + GLint MAG_FILTER; + + GLint WRAP_S; + + GLint WRAP_T; + + GLint datatype; + + GLint format; + + GLint internalFormat; + + GLint target; + + GLint type; + + vector3 * cubeSize; + + GLint border; + + GLint generateMipmap; + + bool UNPACK_ALIGNMENT; + + GLuint index; + + +} sampler2D; + +void sampler2D_constructor( sampler2D * this ); + +void sampler2D_addTexture( sampler2D * this, texture2D * texture ); + +int sampler2D_getTextureIndex( sampler2D * this ); + +void sampler2D_bind( sampler2D * this ); + +sampler2D sampler2D_new( ); + +sampler2D * sampler2D_newPointer( ); + +#endif + + +typedef struct sampler2D sampler2D; + + + diff --git a/application/demos/example.opengl/engine/shader.c b/application/demos/example.opengl/engine/shader.c new file mode 100644 index 0000000..42bb520 --- /dev/null +++ b/application/demos/example.opengl/engine/shader.c @@ -0,0 +1,125 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void shader_constructor( shader * this, GLuint shaderType ) { + + this->glShader = glCreateShader( shaderType ); + + } + +void shader_loadFromFile( shader * this, char * shaderPath ) { + + text * shaderSource = fileSystem_readFile( filesystem, shaderPath, "utf8" ); + + glShaderSource( this->glShader, 1, &shaderSource->value, NULL ); + + glCompileShader( this->glShader ); + + shader_checkShaderForErrors( this, this->glShader ); + + } + +void shader_checkShaderForErrors( shader * this, GLuint shader ) { + + GLint isCompiled = 0; + + glGetShaderiv( shader, GL_COMPILE_STATUS, &isCompiled ); + + if( isCompiled == GL_FALSE ) + { + GLint maxLength = 0; + + glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &maxLength ); + + GLchar errorMessage[ maxLength ]; + + glGetShaderInfoLog( shader, maxLength, &maxLength, errorMessage ); + + printf("\n\n\n\n Error: %s\n\n\n\n\n\n", errorMessage); + + + glDeleteShader( shader ); + + exit( 0 ); + + return; + + } + + } + +shader shader_new(GLuint shaderType) { + + shader instance; + + shader_constructor( &instance, shaderType); + + return instance; + +} + +shader * shader_newPointer(GLuint shaderType) { + + struct shader * pointer = malloc( sizeof ( struct shader ) ); + + shader_constructor( pointer , shaderType); + + return pointer; + +} + +attribute attribute_new() { + + attribute instance; + + return instance; + +} + +attribute * attribute_newPointer() { + + struct attribute * pointer = malloc( sizeof ( struct attribute ) ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/shader.h b/application/demos/example.opengl/engine/shader.h new file mode 100644 index 0000000..b96e861 --- /dev/null +++ b/application/demos/example.opengl/engine/shader.h @@ -0,0 +1,87 @@ +#ifndef _shader + +#define _shader + + +// Macros + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "sampler2D.h" + +#include "../char.h" + +#include "../array.h" + +#include "../fileSystem.h" + +#include + +#include + +#include + +#include + +#include "uniform.h" + +#include "member.h" + +#include "block.h" + + +typedef struct shader{ + + GLuint glShader; + + +} shader; + +void shader_constructor( shader * this, GLuint shaderType ); + +void shader_loadFromFile( shader * this, char * shaderPath ); + +void shader_checkShaderForErrors( shader * this, GLuint shader ); + +typedef struct attribute{ + + GLchar name[64]; + + GLint location; + + GLenum type; + + +} attribute; + +shader shader_new( GLuint shaderType ); + +shader * shader_newPointer( GLuint shaderType ); + +attribute attribute_new( ); + +attribute * attribute_newPointer( ); + +#endif + + +typedef struct shader shader; + + + + + +typedef struct attribute attribute; + + + diff --git a/application/demos/example.opengl/engine/texture2D.c b/application/demos/example.opengl/engine/texture2D.c new file mode 100644 index 0000000..51be857 --- /dev/null +++ b/application/demos/example.opengl/engine/texture2D.c @@ -0,0 +1,23 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + +texture2D texture2D_new() { + + texture2D instance; + + return instance; + +} + +texture2D * texture2D_newPointer() { + + struct texture2D * pointer = malloc( sizeof ( struct texture2D ) ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/texture2D.h b/application/demos/example.opengl/engine/texture2D.h new file mode 100644 index 0000000..ca5cf58 --- /dev/null +++ b/application/demos/example.opengl/engine/texture2D.h @@ -0,0 +1,54 @@ +#ifndef _texture2D + +#define _texture2D + + +// Macros + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "vector2.h" + +#include + +#include + +#include + + +typedef struct texture2D{ + + GLubyte * data; + + int width; + + int height; + + int hasAlpha; + + vector2 * offset; + + +} texture2D; + +texture2D texture2D_new( ); + +texture2D * texture2D_newPointer( ); + +#endif + + +typedef struct texture2D texture2D; + + + diff --git a/application/demos/example.opengl/engine/uniform.c b/application/demos/example.opengl/engine/uniform.c new file mode 100644 index 0000000..32ff0d5 --- /dev/null +++ b/application/demos/example.opengl/engine/uniform.c @@ -0,0 +1,23 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + +uniform uniform_new() { + + uniform instance; + + return instance; + +} + +uniform * uniform_newPointer() { + + struct uniform * pointer = malloc( sizeof ( struct uniform ) ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/uniform.h b/application/demos/example.opengl/engine/uniform.h new file mode 100644 index 0000000..b04cb23 --- /dev/null +++ b/application/demos/example.opengl/engine/uniform.h @@ -0,0 +1,54 @@ +#ifndef _uniform + +#define _uniform + + +// Macros + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + + +typedef struct uniform{ + + char name[64]; + + GLint index; + + GLint location; + + GLint offset; + + GLint size; + + GLenum type; + + +} uniform; + +uniform uniform_new( ); + +uniform * uniform_newPointer( ); + +#endif + + +typedef struct uniform uniform; + + + diff --git a/application/demos/example.opengl/engine/unsignedIntegerArray.c b/application/demos/example.opengl/engine/unsignedIntegerArray.c new file mode 100644 index 0000000..9c5c85f --- /dev/null +++ b/application/demos/example.opengl/engine/unsignedIntegerArray.c @@ -0,0 +1,182 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + +int unsignedIntegerArray_length( unsignedIntegerArray * this ) { + + return this->total; + + } + + +unsigned int unsignedIntegerArray_get( unsignedIntegerArray * this, int index ) { + + return this->items[index]; + + } + + +void unsignedIntegerArray_set( unsignedIntegerArray * this, int index, unsigned int item ) { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + +void unsignedIntegerArray_resize( unsignedIntegerArray * this, int capacity ) { + + int * items = realloc( this->items, sizeof( int ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + +void unsignedIntegerArray_addVector2( unsignedIntegerArray * this, struct vector2 * item ) { + + unsignedIntegerArray_add( this, item->x ); + + unsignedIntegerArray_add( this, item->y ); + + } + +void unsignedIntegerArray_addVector3( unsignedIntegerArray * this, struct vector3 * item ) { + + unsignedIntegerArray_add( this, item->x ); + + unsignedIntegerArray_add( this, item->y ); + + unsignedIntegerArray_add( this, item->z ); + + } + +void unsignedIntegerArray_add( unsignedIntegerArray * this, unsigned int item ) { + + if ( this->capacity == this->total ){ + + unsignedIntegerArray_resize( this, this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + +void unsignedIntegerArray_delete( unsignedIntegerArray * this, int index ) { + if ( index < 0 || index >= this->total ){ + + return; + + } + + this->items[index] = 0.0; + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + this->items[i + 1] = 0.0; + + } + + this->total--; + + if ( this->total > 0 && this->total == this->capacity / 4 ){ + + unsignedIntegerArray_resize( this, this->capacity / 2 ); + + } + + } + + +unsigned int unsignedIntegerArray_array_push( unsignedIntegerArray * this, unsigned int item ) { + + unsignedIntegerArray_add( this, item ); + + return this->total; + + } + +void unsignedIntegerArray_unshift( unsignedIntegerArray * this, int item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + unsignedIntegerArray_resize( this, this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } + +unsigned int unsignedIntegerArray_pop( unsignedIntegerArray * this ) { + + int length = this->total; + + int lastIndex = length - 1; + + int lastItem = unsignedIntegerArray_get( this, lastIndex ); + + unsignedIntegerArray_delete( this, lastIndex ); + + return lastItem; + + } + +unsignedIntegerArray unsignedIntegerArray_new() { + + unsignedIntegerArray instance; + + instance.capacity = 10; + + instance.total = 0; + + instance.items = malloc( 10000000 ); + + return instance; + +} + +unsignedIntegerArray * unsignedIntegerArray_newPointer() { + + struct unsignedIntegerArray * pointer = malloc( sizeof ( struct unsignedIntegerArray ) ); + + pointer->capacity = 10; + + pointer->total = 0; + + pointer->items = malloc( 10000000 ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/unsignedIntegerArray.h b/application/demos/example.opengl/engine/unsignedIntegerArray.h new file mode 100644 index 0000000..0255a2a --- /dev/null +++ b/application/demos/example.opengl/engine/unsignedIntegerArray.h @@ -0,0 +1,65 @@ +#ifndef _unsignedIntegerArray + +#define _unsignedIntegerArray + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + + +typedef struct unsignedIntegerArray{ + + int capacity; + + int total; + + unsigned int * items; + + +} unsignedIntegerArray; + +int unsignedIntegerArray_length( unsignedIntegerArray * this ); + +unsigned int unsignedIntegerArray_get( unsignedIntegerArray * this, int index ); + +void unsignedIntegerArray_set( unsignedIntegerArray * this, int index, unsigned int item ); + +void unsignedIntegerArray_resize( unsignedIntegerArray * this, int capacity ); + +void unsignedIntegerArray_addVector2( unsignedIntegerArray * this, struct vector2 * item ); + +void unsignedIntegerArray_addVector3( unsignedIntegerArray * this, struct vector3 * item ); + +void unsignedIntegerArray_add( unsignedIntegerArray * this, unsigned int item ); + +void unsignedIntegerArray_delete( unsignedIntegerArray * this, int index ); + +unsigned int unsignedIntegerArray_array_push( unsignedIntegerArray * this, unsigned int item ); + +void unsignedIntegerArray_unshift( unsignedIntegerArray * this, int item ); + +unsigned int unsignedIntegerArray_pop( unsignedIntegerArray * this ); + +unsignedIntegerArray unsignedIntegerArray_new( ); + +unsignedIntegerArray * unsignedIntegerArray_newPointer( ); + +#endif + + +typedef struct unsignedIntegerArray unsignedIntegerArray; + + + diff --git a/application/demos/example.opengl/engine/vector.c b/application/demos/example.opengl/engine/vector.c new file mode 100644 index 0000000..7439bd9 --- /dev/null +++ b/application/demos/example.opengl/engine/vector.c @@ -0,0 +1,997 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + +int vector_char_pointer_length( vector_char_pointer * this ) { + + return this->total; + + } + + + + + + + + + +char * vector_char_pointer_get( vector_char_pointer * this, int index ) { + + return this->items[index]; + + } + + + + + + + + + + + + + +void vector_char_pointer_set( vector_char_pointer * this, int index, char * item ) { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + + + + + + + + + +void vector_char_pointer_resize( vector_char_pointer * this, int capacity ) { + + char * * items = realloc( this->items, sizeof( char * ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + + + + + + + + + +void vector_char_pointer_add( vector_char_pointer * this, char * item ) { + + if ( this->capacity == this->total ){ + + vector_char_pointer_resize( this, this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + + + + + + + + + + + + + + + + + + + + + + + + +void vector_char_pointer_delete( vector_char_pointer * this, int index ) { + + + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + + + } + + + + + + + + this->total--; + + + + + + + + }int vector_char_pointer_array_push( vector_char_pointer * this, char * item ) { + + vector_char_pointer_add( this, item ); + + return this->total; + + } + + + + + + + + + + + + + +void vector_char_pointer_unshift( vector_char_pointer * this, char * item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + vector_char_pointer_resize( this, this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + }int vector_quadMesh_length( vector_quadMesh * this ) { + + return this->total; + + } + + + +quadMesh vector_quadMesh_get( vector_quadMesh * this, int index ) { + + return this->items[index]; + + } + + + + + + + + + + + + + +void vector_quadMesh_set( vector_quadMesh * this, int index, quadMesh item ) { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + + + + + + + + + +void vector_quadMesh_resize( vector_quadMesh * this, int capacity ) { + + quadMesh * items = realloc( this->items, sizeof( quadMesh ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + + + + + + + + + +void vector_quadMesh_add( vector_quadMesh * this, quadMesh item ) { + + if ( this->capacity == this->total ){ + + vector_quadMesh_resize( this, this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + + + + + + + + + + + + + + + + + + + + + + + + +void vector_quadMesh_delete( vector_quadMesh * this, int index ) { + + + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + + + } + + + + + + + + this->total--; + + + + + + + + }int vector_quadMesh_array_push( vector_quadMesh * this, quadMesh item ) { + + vector_quadMesh_add( this, item ); + + return this->total; + + } + + + + + + + + + + + + + +void vector_quadMesh_unshift( vector_quadMesh * this, quadMesh item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + vector_quadMesh_resize( this, this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + }int vector_element_length( vector_element * this ) { + + return this->total; + + } + + + +element vector_element_get( vector_element * this, int index ) { + + return this->items[index]; + + } + + + + + + + + + + + + + +void vector_element_set( vector_element * this, int index, element item ) { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + + + + + + + + + +void vector_element_resize( vector_element * this, int capacity ) { + + element * items = realloc( this->items, sizeof( element ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + + + + + + + + + +void vector_element_add( vector_element * this, element item ) { + + if ( this->capacity == this->total ){ + + vector_element_resize( this, this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + + + + + + + + + + + + + + + + + + + + + + + + +void vector_element_delete( vector_element * this, int index ) { + + + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + + + } + + + + + + + + this->total--; + + + + + + + + }int vector_element_array_push( vector_element * this, element item ) { + + vector_element_add( this, item ); + + return this->total; + + } + + + + + + + + + + + + + +void vector_element_unshift( vector_element * this, element item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + vector_element_resize( this, this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + }int vector_int_length( vector_int * this ) { + + return this->total; + + } + + + +int vector_int_get( vector_int * this, int index ) { + + return this->items[index]; + + } + + + + + + + + + + + + + +void vector_int_set( vector_int * this, int index, int item ) { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + + + + + + + + + +void vector_int_resize( vector_int * this, int capacity ) { + + int * items = realloc( this->items, sizeof( int ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + + + + + + + + + +void vector_int_add( vector_int * this, int item ) { + + if ( this->capacity == this->total ){ + + vector_int_resize( this, this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + + + + + + + + + + + + + + + + + + + + + + + + +void vector_int_delete( vector_int * this, int index ) { + + + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + + + } + + + + + + + + this->total--; + + + + + + + + }int vector_int_array_push( vector_int * this, int item ) { + + vector_int_add( this, item ); + + return this->total; + + } + + + + + + + + + + + + + +void vector_int_unshift( vector_int * this, int item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + vector_int_resize( this, this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + }int vector_vector2_length( vector_vector2 * this ) { + + return this->total; + + } + + + +vector2 vector_vector2_get( vector_vector2 * this, int index ) { + + return this->items[index]; + + } + + + + + + + + + + + + + +void vector_vector2_set( vector_vector2 * this, int index, vector2 item ) { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + + + + + + + + + +void vector_vector2_resize( vector_vector2 * this, int capacity ) { + + vector2 * items = realloc( this->items, sizeof( vector2 ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + + + + + + + + + +void vector_vector2_add( vector_vector2 * this, vector2 item ) { + + if ( this->capacity == this->total ){ + + vector_vector2_resize( this, this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + + + + + + + + + + + + + + + + + + + + + + + + +void vector_vector2_delete( vector_vector2 * this, int index ) { + + + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + + + } + + + + + + + + this->total--; + + + + + + + + }int vector_vector2_array_push( vector_vector2 * this, vector2 item ) { + + vector_vector2_add( this, item ); + + return this->total; + + } + + + + + + + + + + + + + +void vector_vector2_unshift( vector_vector2 * this, vector2 item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + vector_vector2_resize( this, this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } + +vector_char_pointer vector_char_pointer_new() { + + vector_char_pointer instance; + + instance.capacity = 10; + + instance.total = 0; + + instance.items = malloc( 10000000 ); + + return instance; + +} + +vector_char_pointer * vector_char_pointer_newPointer() { + + struct vector_char_pointer * pointer = malloc( sizeof ( struct vector_char_pointer ) ); + + pointer->capacity = 10; + + pointer->total = 0; + + pointer->items = malloc( 10000000 ); + + return pointer; + +} + +vector_quadMesh vector_quadMesh_new() { + + vector_quadMesh instance; + + instance.capacity = 10; + + instance.total = 0; + + instance.items = malloc( 10000000 ); + + return instance; + +} + +vector_quadMesh * vector_quadMesh_newPointer() { + + struct vector_quadMesh * pointer = malloc( sizeof ( struct vector_quadMesh ) ); + + pointer->capacity = 10; + + pointer->total = 0; + + pointer->items = malloc( 10000000 ); + + return pointer; + +} + +vector_element vector_element_new() { + + vector_element instance; + + instance.capacity = 10; + + instance.total = 0; + + instance.items = malloc( 10000000 ); + + return instance; + +} + +vector_element * vector_element_newPointer() { + + struct vector_element * pointer = malloc( sizeof ( struct vector_element ) ); + + pointer->capacity = 10; + + pointer->total = 0; + + pointer->items = malloc( 10000000 ); + + return pointer; + +} + +vector_int vector_int_new() { + + vector_int instance; + + instance.capacity = 10; + + instance.total = 0; + + instance.items = malloc( 10000000 ); + + return instance; + +} + +vector_int * vector_int_newPointer() { + + struct vector_int * pointer = malloc( sizeof ( struct vector_int ) ); + + pointer->capacity = 10; + + pointer->total = 0; + + pointer->items = malloc( 10000000 ); + + return pointer; + +} + +vector_vector2 vector_vector2_new() { + + vector_vector2 instance; + + instance.capacity = 10; + + instance.total = 0; + + instance.items = malloc( 10000000 ); + + return instance; + +} + +vector_vector2 * vector_vector2_newPointer() { + + struct vector_vector2 * pointer = malloc( sizeof ( struct vector_vector2 ) ); + + pointer->capacity = 10; + + pointer->total = 0; + + pointer->items = malloc( 10000000 ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/vector.h b/application/demos/example.opengl/engine/vector.h new file mode 100644 index 0000000..6363fcf --- /dev/null +++ b/application/demos/example.opengl/engine/vector.h @@ -0,0 +1,217 @@ +#ifndef _vector + +#define _vector + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "../int.h" + +#include "../vector2.h" + +#include "quadMesh.h" + +#include "element.h" + + +typedef struct vector_char_pointer{ + + int capacity; + + int total; + + char * * items; + + +} vector_char_pointer; + +int vector_char_pointer_length( vector_char_pointer * this ); + +char * vector_char_pointer_get( vector_char_pointer * this, int index ); + +void vector_char_pointer_set( vector_char_pointer * this, int index, char * item ); + +void vector_char_pointer_resize( vector_char_pointer * this, int capacity ); + +void vector_char_pointer_add( vector_char_pointer * this, char * item ); + +void vector_char_pointer_delete( vector_char_pointer * this, int index ); + +int vector_char_pointer_array_push( vector_char_pointer * this, char * item ); + +void vector_char_pointer_unshift( vector_char_pointer * this, char * item ); + +typedef struct vector_quadMesh{ + + int capacity; + + int total; + + quadMesh * items; + + +} vector_quadMesh; + +int vector_quadMesh_length( vector_quadMesh * this ); + +quadMesh vector_quadMesh_get( vector_quadMesh * this, int index ); + +void vector_quadMesh_set( vector_quadMesh * this, int index, quadMesh item ); + +void vector_quadMesh_resize( vector_quadMesh * this, int capacity ); + +void vector_quadMesh_add( vector_quadMesh * this, quadMesh item ); + +void vector_quadMesh_delete( vector_quadMesh * this, int index ); + +int vector_quadMesh_array_push( vector_quadMesh * this, quadMesh item ); + +void vector_quadMesh_unshift( vector_quadMesh * this, quadMesh item ); + +typedef struct vector_element{ + + int capacity; + + int total; + + element * items; + + +} vector_element; + +int vector_element_length( vector_element * this ); + +element vector_element_get( vector_element * this, int index ); + +void vector_element_set( vector_element * this, int index, element item ); + +void vector_element_resize( vector_element * this, int capacity ); + +void vector_element_add( vector_element * this, element item ); + +void vector_element_delete( vector_element * this, int index ); + +int vector_element_array_push( vector_element * this, element item ); + +void vector_element_unshift( vector_element * this, element item ); + +typedef struct vector_int{ + + int capacity; + + int total; + + int * items; + + +} vector_int; + +int vector_int_length( vector_int * this ); + +int vector_int_get( vector_int * this, int index ); + +void vector_int_set( vector_int * this, int index, int item ); + +void vector_int_resize( vector_int * this, int capacity ); + +void vector_int_add( vector_int * this, int item ); + +void vector_int_delete( vector_int * this, int index ); + +int vector_int_array_push( vector_int * this, int item ); + +void vector_int_unshift( vector_int * this, int item ); + +typedef struct vector_vector2{ + + int capacity; + + int total; + + vector2 * items; + + +} vector_vector2; + +int vector_vector2_length( vector_vector2 * this ); + +vector2 vector_vector2_get( vector_vector2 * this, int index ); + +void vector_vector2_set( vector_vector2 * this, int index, vector2 item ); + +void vector_vector2_resize( vector_vector2 * this, int capacity ); + +void vector_vector2_add( vector_vector2 * this, vector2 item ); + +void vector_vector2_delete( vector_vector2 * this, int index ); + +int vector_vector2_array_push( vector_vector2 * this, vector2 item ); + +void vector_vector2_unshift( vector_vector2 * this, vector2 item ); + +vector_char_pointer vector_char_pointer_new( ); + +vector_char_pointer * vector_char_pointer_newPointer( ); + +vector_quadMesh vector_quadMesh_new( ); + +vector_quadMesh * vector_quadMesh_newPointer( ); + +vector_element vector_element_new( ); + +vector_element * vector_element_newPointer( ); + +vector_int vector_int_new( ); + +vector_int * vector_int_newPointer( ); + +vector_vector2 vector_vector2_new( ); + +vector_vector2 * vector_vector2_newPointer( ); + +#endif + + +typedef struct vector vector; + + + + + +typedef struct vector_char_pointer vector_char_pointer; + + + + + +typedef struct vector_quadMesh vector_quadMesh; + + + + + +typedef struct vector_element vector_element; + + + + + +typedef struct vector_int vector_int; + + + + + +typedef struct vector_vector2 vector_vector2; + + + diff --git a/application/demos/example.opengl/engine/vector4.c b/application/demos/example.opengl/engine/vector4.c new file mode 100644 index 0000000..217d99f --- /dev/null +++ b/application/demos/example.opengl/engine/vector4.c @@ -0,0 +1,75 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + +void vector4_constructor( vector4 * this, float x, float y, float z, float w ) { + + this->x = x; + + this->y = y; + + this->z = z; + + this->w = w; + + } + +vector4 * vector4_operator_plus( vector4 * this, vector4 * b ) { + + vector4_add( this, b ); + + return this; + + } + +vector4 * vector4_operator_add( vector4 * this, vector4 * b ) { + + vector4_add( this, b ); + + return this; + + } + +void vector4_add( vector4 * this, vector4 * b ) { + + this->x += b->x; + + this->y += b->y; + + this->z += b->z; + + this->w += b->w; + + } + +vector4 vector4_new(float x, float y, float z, float w) { + + vector4 instance; + + vector4_constructor( &instance, x, y, z, w); + + return instance; + +} + +vector4 * vector4_newPointer(float x, float y, float z, float w) { + + struct vector4 * pointer = malloc( sizeof ( struct vector4 ) ); + + vector4_constructor( pointer , x, y, z, w); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/vector4.h b/application/demos/example.opengl/engine/vector4.h new file mode 100644 index 0000000..6f70469 --- /dev/null +++ b/application/demos/example.opengl/engine/vector4.h @@ -0,0 +1,49 @@ +#ifndef _vector4 + +#define _vector4 + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + + +typedef struct vector4{ + + float x; + + float y; + + float z; + + float w; + + +} vector4; + +void vector4_constructor( vector4 * this, float x, float y, float z, float w ); + +vector4 * vector4_operator_plus( vector4 * this, vector4 * b ); + +vector4 * vector4_operator_add( vector4 * this, vector4 * b ); + +void vector4_add( vector4 * this, vector4 * b ); + +vector4 vector4_new( float x, float y, float z, float w ); + +vector4 * vector4_newPointer( float x, float y, float z, float w ); + +#endif + + +typedef struct vector4 vector4; + + + diff --git a/application/demos/example.opengl/engine/windowManager.c b/application/demos/example.opengl/engine/windowManager.c new file mode 100644 index 0000000..53be531 --- /dev/null +++ b/application/demos/example.opengl/engine/windowManager.c @@ -0,0 +1,179 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + +static int DoubleBufferAttributes[] = { + GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DEPTH_SIZE, 12, + GLX_DOUBLEBUFFER, + None, +}; + + + + + + +void windowManager_setupDisplay( windowManager * this ) { + + this->mainDisplay = XOpenDisplay( 0 ); + + this->MainScreen = XDefaultScreen( this->mainDisplay ); + + } + +void windowManager_setupWindow( windowManager * this ) { + + + this->RootWindow = XDefaultRootWindow( this->mainDisplay ); + + + int empty; + + int ResultStatus = glXQueryExtension( this->mainDisplay, &empty, &empty ); + + XVisualInfo* VisualInfo = glXChooseVisual( this->mainDisplay, this->MainScreen, DoubleBufferAttributes ); + + GLXContext ShareList = None; + + int IsDirectRendering = True; + + + + + + GLXContext OpenGLContext = glXCreateContext( this->mainDisplay, VisualInfo, ShareList, IsDirectRendering ); + + + + int WindowX = 0; + + int WindowY = 0; + + int WindowWidth = 1000; + + int WindowHeight = 1024; + + int BorderWidth = 0; + + int WindowClass = InputOutput; + + int WindowDepth = VisualInfo->depth; + + + Visual* WindowVisual = VisualInfo->visual; + + int AttributeValueMask = CWBackPixel | CWEventMask | CWColormap; + + + + + + + XSetWindowAttributes WindowAttributes = {}; + + WindowAttributes.colormap = XCreateColormap( this->mainDisplay, this->RootWindow, VisualInfo->visual, AllocNone ); + + + + WindowAttributes.background_pixel = 0; + + + WindowAttributes.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | PointerMotionMask; + + this->mainWindow = XCreateWindow( this->mainDisplay, this->RootWindow, + WindowX, WindowY, WindowWidth, WindowHeight, + BorderWidth, WindowDepth, WindowClass, WindowVisual, + AttributeValueMask, &WindowAttributes); + + + + + XMoveWindow( this->mainDisplay, this->mainWindow, -400, 0 ); + + XStoreName( this->mainDisplay, this->mainWindow, "Opengl: Fixed function pipeline" ); + + glXMakeCurrent( this->mainDisplay, this->mainWindow, OpenGLContext ); + + XMapWindow( this->mainDisplay, this->mainWindow ); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Atom WM_DELETE_WINDOW = XInternAtom( this->mainDisplay, "WM_DELETE_WINDOW", False ); + + + if( !XSetWMProtocols( this->mainDisplay, this->mainWindow, &WM_DELETE_WINDOW, 1) ) { + + printf( "Couldn't register WM_DELETE_WINDOW\n" ); + + } + + } + +windowManager windowManager_new() { + + windowManager instance; + + return instance; + +} + +windowManager * windowManager_newPointer() { + + struct windowManager * pointer = malloc( sizeof ( struct windowManager ) ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/engine/windowManager.h b/application/demos/example.opengl/engine/windowManager.h new file mode 100644 index 0000000..9e7e856 --- /dev/null +++ b/application/demos/example.opengl/engine/windowManager.h @@ -0,0 +1,64 @@ +#ifndef _windowManager + +#define _windowManager + + +// Macros + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + + +typedef struct windowManager{ + + Display * mainDisplay; + + Window mainWindow; + + int MainScreen; + + Window RootWindow; + + +} windowManager; + +void windowManager_setupDisplay( windowManager * this ); + +void windowManager_setupWindow( windowManager * this ); + +static int DoubleBufferAttributes[] ; + +windowManager windowManager_new( ); + +windowManager * windowManager_newPointer( ); + +#endif + + +typedef struct windowManager windowManager; + + + diff --git a/application/demos/example.opengl/examples/example.opengl.c b/application/demos/example.opengl/examples/example.opengl.c new file mode 100644 index 0000000..0937207 --- /dev/null +++ b/application/demos/example.opengl/examples/example.opengl.c @@ -0,0 +1,13 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + +void main( ) { + + opengl * instance = opengl_newPointer(); + + opengl_initialize( instance ); + +} + diff --git a/application/demos/example.opengl/examples/example.opengl.h b/application/demos/example.opengl/examples/example.opengl.h new file mode 100644 index 0000000..6ba04e4 --- /dev/null +++ b/application/demos/example.opengl/examples/example.opengl.h @@ -0,0 +1,22 @@ +#ifndef _example_opengl + +#define _example_opengl + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "../engine/opengl.h" + + +void main( ); + +#endif diff --git a/application/demos/example.opengl/file.c b/application/demos/example.opengl/file.c new file mode 100644 index 0000000..d477385 --- /dev/null +++ b/application/demos/example.opengl/file.c @@ -0,0 +1,23 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + +file file_new() { + + file instance; + + return instance; + +} + +file * file_newPointer() { + + struct file * pointer = malloc( sizeof ( struct file ) ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/file.h b/application/demos/example.opengl/file.h new file mode 100644 index 0000000..bc8670f --- /dev/null +++ b/application/demos/example.opengl/file.h @@ -0,0 +1,39 @@ +#ifndef _file + +#define _file + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "text.h" + + +typedef struct file{ + + char * filePath; + + text * content; + + +} file; + +file file_new( ); + +file * file_newPointer( ); + +#endif + + +typedef struct file file; + + + diff --git a/application/demos/example.opengl/fileSystem.c b/application/demos/example.opengl/fileSystem.c new file mode 100644 index 0000000..eced996 --- /dev/null +++ b/application/demos/example.opengl/fileSystem.c @@ -0,0 +1,279 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + +struct fileSystem * filesystem; + + + +void fileSystem_writeFile( fileSystem * this, char * filepath, char * data ) { + FILE *fp = fopen( filepath, "wb" ); + + if (fp != NULL) + { + fputs( data, fp ); + + fclose( fp ); + } + + } + + +struct array * fileSystem_readDir( fileSystem * this, char * filePath ) { + + DIR * dir; + + struct dirent * entry; + + struct array * files = array_newPointer(); + + if ( ( dir = opendir( filePath ) ) == NULL ){ + + perror("opendir() error"); + + } else { + + while( ( entry = readdir( dir ) ) != NULL ) { + + char * filename = (char *)entry->d_name; + + if ( strcmp( filename, ".." ) != 0 && strcmp( filename, "." ) != 0 ) { + + array_add( files, filename ); + + + + } + } + } + + return files; + + } + + +struct text * fileSystem_readFile( fileSystem * this, char * name, char * mode ) { + + char * readMode; + + if( char_operator_compare( mode , "utf8") ) { + + readMode = "r"; + + } else { + + readMode = "rb"; + + } + + FILE * file = fopen( name, readMode ); + + if ( file == NULL ) { + + fprintf( stderr, "Error: Can't open file '%s'.", name ); + + exit( EXIT_FAILURE ); + + } + + fseek( file, 0, SEEK_END ); + + long length = ftell( file ); + + + + fseek( file, 0, SEEK_SET ); + + char * buffer = malloc( sizeof( char ) * ( length + 1 ) ); + + fread( buffer, sizeof( char ), length, file ); + + fclose( file ); + + if( char_operator_compare( mode , "utf8") ) { + + buffer[ length ] = 0; + + } + + text * output = text_newPointer( "" ); + + output->length = 0; + + text_appendBinary( output, buffer, length ); + + return output; + + } + + + +char * fileSystem_readBinaryFile( fileSystem * this, char * name, char * mode, int * size ) { + + char * readMode; + + if( char_operator_compare( mode , "utf8") ) { + + readMode = "r"; + + } else { + + readMode = "rb"; + + printf("readmode = rb binary\n\n"); + + } + + FILE * file = fopen( name, readMode ); + + if ( file == NULL ) { + + fprintf( stderr, "Error: Can't open file '%s'.", name ); + + exit( EXIT_FAILURE ); + + } + + fseek( file, 0, SEEK_END ); + + long length = ftell( file ); + + printf("buffer length is '%i' \n\n", length); + + fseek( file, 0, SEEK_SET ); + + char * buffer = malloc( sizeof( char ) * ( length + 1 ) ); + + buffer[ length ] = '\0'; + + fread( buffer, sizeof( char ), length, file ); + + fclose( file ); + + + + + *size = length; + + printf("strlen: %i \n\n", length); + + return buffer; + + } + +int fileSystem_ensureDirectory( fileSystem * this, char * path ) { + + char * pathCopy = char_copy( path ); + + struct array * parts = char_split( pathCopy, "/" ); + + int count = array_length( parts ); + + for ( int i = 1; i < count; ++i ) + { + struct array * tempParts = char_split( pathCopy, "/" ); + + for ( int j = 0; j < count-i-1; ++j ) + { + array_pop( tempParts ); + } + + char * tempPath = array_join( tempParts, "/" ); + + if( fileSystem_exists( this, tempPath ) ) { + + } else { + + fileSystem_makeDirectory( this, tempPath ); + + } + + } + + return 1; + + } + +int fileSystem_makeDirectory( fileSystem * this, char * path ) { + + if ( fileSystem_exists( this, path ) == NULL ) { + + mkdir( path, 0700 ); + + } + + return 1; + + } + +int fileSystem_exists( fileSystem * this, char * path ) { + + if ( access( path, F_OK ) == 0 ) { + + return 1; + + } else { + + return 0; + + } + + } + +int fileSystem_isDirectory( fileSystem * this, char * path ) { + + struct stat path_stat; + + stat( path, & path_stat ); + + if( S_ISREG( path_stat.st_mode ) ) { + + return 0; + + } else { + + return 1; + + } + + } + +fileSystem fileSystem_new() { + + fileSystem instance; + + return instance; + +} + +fileSystem * fileSystem_newPointer() { + + struct fileSystem * pointer = malloc( sizeof ( struct fileSystem ) ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/fileSystem.h b/application/demos/example.opengl/fileSystem.h new file mode 100644 index 0000000..3250fcd --- /dev/null +++ b/application/demos/example.opengl/fileSystem.h @@ -0,0 +1,73 @@ +#ifndef _fileSystem + +#define _fileSystem + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + + +typedef struct fileSystem{ + + +} fileSystem; + +void fileSystem_writeFile( fileSystem * this, char * filepath, char * data ); + +struct array * fileSystem_readDir( fileSystem * this, char * filePath ); + +struct text * fileSystem_readFile( fileSystem * this, char * name, char * mode ); + +char * fileSystem_readBinaryFile( fileSystem * this, char * name, char * mode, int * size ); + +int fileSystem_ensureDirectory( fileSystem * this, char * path ); + +int fileSystem_makeDirectory( fileSystem * this, char * path ); + +int fileSystem_exists( fileSystem * this, char * path ); + +int fileSystem_isDirectory( fileSystem * this, char * path ); + +extern struct fileSystem * filesystem; + +fileSystem fileSystem_new( ); + +fileSystem * fileSystem_newPointer( ); + +#endif + + +typedef struct fileSystem fileSystem; + + + diff --git a/application/demos/example.opengl/header.c b/application/demos/example.opengl/header.c new file mode 100644 index 0000000..4f7c26f --- /dev/null +++ b/application/demos/example.opengl/header.c @@ -0,0 +1,23 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + +header header_new() { + + header instance; + + return instance; + +} + +header * header_newPointer() { + + struct header * pointer = malloc( sizeof ( struct header ) ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/header.h b/application/demos/example.opengl/header.h new file mode 100644 index 0000000..c746146 --- /dev/null +++ b/application/demos/example.opengl/header.h @@ -0,0 +1,37 @@ +#ifndef _header + +#define _header + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + + +typedef struct header{ + + char * name; + + char * value; + + +} header; + +header header_new( ); + +header * header_newPointer( ); + +#endif + + +typedef struct header header; + + + diff --git a/application/demos/example.opengl/headers.c b/application/demos/example.opengl/headers.c new file mode 100644 index 0000000..b6e7bd1 --- /dev/null +++ b/application/demos/example.opengl/headers.c @@ -0,0 +1,186 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + +void headerManager_parse( headerManager * this, char * headerContent ) { + + array * headerRows = char_split( headerContent, "\n"); + + int headerCount = array_length( headerRows ); + + for (int i = 1; i < headerCount; ++i) + { + + char * headerRow = array_get( headerRows, i ); + + array * headerRowParts = char_split( headerRow, ":"); + + int headerRowPartsCount = array_length( headerRowParts ); + + + if( headerRowPartsCount == 2 ) { + + char * headerName = array_get( headerRowParts, 0 ); + + char * headerValue = array_get( headerRowParts, 1 ); + + + + + + headerManager_add( this, headerName, char_removeWhitespace( headerValue ) ); + + } + + } + + printf("\n\n"); + + } + +void headerManager_display( headerManager * this ) { + + struct array * headerRows = this->headers; + + int headerCount = array_length( headerRows ); + + for (int i = 0; i < headerCount; ++i) + { + struct header * headerInstance = array_get( headerRows, i ); + + printf("%-20s %-30s \n", headerInstance->name, headerInstance->value); + + } + + } + +void headerManager_add( headerManager * this, char * name, char * value ) { + + header * headerInstance = header_newPointer(); + + headerInstance->name = name; + + headerInstance->value = value; + + array_add( this->headers, headerInstance ); + + } + +void headerManager_set( headerManager * this, char * name, char * value ) { + + struct header * headerInstance = headerManager_get( this, name ); + + if( headerInstance == NULL ) { + + headerManager_add( this, name, value ); + + } else { + + int headerIndex = headerManager_getHeaderIndex( this, name ); + + array * headers = this->headers; + + + header * headerInstance = array_get( headers, headerIndex ); + + headerInstance->value = value; + + + } + + } + +int headerManager_getHeaderIndex( headerManager * this, char * name ) { + + array * headers = this->headers; + + int count = array_length( headers ); + + for (int i = 0; i < count; ++i) + { + + header * headerInstance = array_get( headers, i ); + + if( char_operator_compare( headerInstance->name , name) ) { + + return i; + + } + + } + + return -1; + + } + +char * headerManager_getValue( headerManager * this, char * name ) { + + array * headers = this->headers; + + int count = array_length( headers ); + + for (int i = 0; i < count; ++i) + { + + header * headerInstance = array_get( headers, i ); + + if( char_operator_compare( headerInstance->name , name) ) { + + return headerInstance->value; + + } + + } + + return NULL; + + } + +header * headerManager_get( headerManager * this, char * name ) { + + array * headers = this->headers; + + int count = array_length( headers ); + + for (int i = 0; i < count; ++i) + { + + header * headerInstance = array_get( headers, i ); + + if( char_operator_compare( headerInstance->name , name) ) { + + return headerInstance; + + } + + } + + return NULL; + + } + +headerManager headerManager_new() { + + headerManager instance; + + instance.headers = array_newPointer(); + + return instance; + +} + +headerManager * headerManager_newPointer() { + + struct headerManager * pointer = malloc( sizeof ( struct headerManager ) ); + + pointer->headers = array_newPointer(); + + return pointer; + +} + diff --git a/application/demos/example.opengl/headers.h b/application/demos/example.opengl/headers.h new file mode 100644 index 0000000..a31d8d2 --- /dev/null +++ b/application/demos/example.opengl/headers.h @@ -0,0 +1,53 @@ +#ifndef _headers + +#define _headers + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "header.h" + +#include "array.h" + + +typedef struct headerManager{ + + struct array * headers; + + +} headerManager; + +void headerManager_parse( headerManager * this, char * headerContent ); + +void headerManager_display( headerManager * this ); + +void headerManager_add( headerManager * this, char * name, char * value ); + +void headerManager_set( headerManager * this, char * name, char * value ); + +int headerManager_getHeaderIndex( headerManager * this, char * name ); + +char * headerManager_getValue( headerManager * this, char * name ); + +header * headerManager_get( headerManager * this, char * name ); + +headerManager headerManager_new( ); + +headerManager * headerManager_newPointer( ); + +#endif + + +typedef struct headerManager headerManager; + + + diff --git a/application/demos/example.opengl/http.c b/application/demos/example.opengl/http.c new file mode 100644 index 0000000..46c493f --- /dev/null +++ b/application/demos/example.opengl/http.c @@ -0,0 +1,546 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void http_createServer( http * this, void ( * requestCallback )( request * req, text * response ) ) { + + this->requestCallback = requestCallback; + + + if( this->useSSL == 1 ) { + + http_initializeOpenSSL( this ); + + } + + printf("after initializeOpenSSL\n\n"); + + } + +void http_initializeOpenSSL( http * this ) { + + + + + + + + SSL_load_error_strings(); + + OpenSSL_add_ssl_algorithms(); + + SSLeay_add_ssl_algorithms(); + + return; + + } + +int http_listen( http * this, int port ) { + + this->socket = socket( AF_INET, SOCK_STREAM, 0 ); + + int iSetOption = 1; + + setsockopt( this->socket, SOL_SOCKET, SO_REUSEADDR, ( char * ) & iSetOption, sizeof( iSetOption ) ); + + if ( this->socket == -1 ) { + + perror("webserver (socket)"); + + exit( 0 ); + + } else { + + printf("socket created successfully\n"); + + } + + + + this->hostAddress->sin_family = AF_INET; + + this->hostAddress->sin_port = htons( port ); + + this->hostAddress->sin_addr.s_addr = htonl( INADDR_ANY ); + + + + if ( bind( this->socket, ( struct sockaddr * ) this->hostAddress, this->hostAddresslength ) != 0 ) { + + perror("webserver (bind)"); + + exit( 0 ); + + } else { + + printf("socket successfully bound to address\n"); + + } + + + if ( listen( this->socket, SOMAXCONN ) != 0 ) { + + perror("webserver (listen)"); + + exit( 0 ); + + } else { + + printf("server listening for connections\n"); + + } + + + + for (;;) { + + http_acceptConnection( this ); + + } + + + + + printf("exit"); + + + return 0; + + } + +char * http_getExtension( http * this, char * path ) { + + array * parts = char_split( path, "."); + + int count = array_length( parts ); + + return array_get( parts, count - 1 ); + + } + +void http_logRequest( http * this, request * requestInstance ) { + + printf("server address: [%s:%u]\n", requestInstance->address, requestInstance->port ); + + printf("mimeType: %-30s \n", requestInstance->mimeType); + + printf("header: %-30s \n", requestInstance->extension ); + + printf("method: %-30s \n", requestInstance->method ); + + printf("version: %-30s \n\n", requestInstance->version ); + + } + +void http_acceptConnection( http * this ) { + + fileSystem * filesystem = this->filesystem; + + mimeTypes * mimetypes = this->mimetypes; + + text * response = text_newPointer(""); + + + + char buffer[ 4096 ]; + + + struct sockaddr_in client_addr; + + int client_addrlen = sizeof(client_addr); + + + int socketConnection = accept( this->socket, + (struct sockaddr *)this->hostAddress, + ( socklen_t * ) & this->hostAddresslength ); + + + + + + + + + + + + + + + SSL * ssl = NULL; + + if( this->useSSL == 1 ) { + + const SSL_METHOD * method = SSLv23_server_method(); + + this->sslContext = SSL_CTX_new( method ); + + if ( this->sslContext == NULL ) { + + printf("Error loading SSL_CTX_NEW '%s'\n\n", stderr); + + } + + SSL_CTX_set_options( this->sslContext, SSL_OP_SINGLE_DH_USE ); + + int use_cert = SSL_CTX_use_certificate_file( this->sslContext, "/etc/letsencrypt/live/unifyjs.org/fullchain.pem" , SSL_FILETYPE_PEM ); + + int use_prv = SSL_CTX_use_PrivateKey_file( this->sslContext, "/etc/letsencrypt/live/unifyjs.org/privkey.pem", SSL_FILETYPE_PEM ); + + if( use_cert != 1 ) { + + printf( "error: SSL_CTX_use_certificate_file\n\n" ); + + } + + if( use_prv != 1 ) { + + printf( "error: SSL_CTX_use_PrivateKey_file\n\n" ); + + } + + if ( !SSL_CTX_check_private_key(this->sslContext) ) { + + printf("Private key does not match the certificate public key\n"); + + + } + + ssl = SSL_new( this->sslContext ); + + SSL_set_fd( ssl, socketConnection ); + + + int ssl_err = SSL_accept( ssl ); + + + + + + if( ssl_err == 0 ){ + + printf("SSL_accept returned zero\n"); + + } + + + int n; + + if( ssl_err < 0 ) { + + int err; + + if( ( err = SSL_get_error(ssl,n ) ) == SSL_ERROR_WANT_READ) { + + printf("SSL_accept wants more data\n"); + + return ; + + } + + exit(7); + + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } else { + printf("connection accepted\n\n"); + + + int sockn = getsockname( socketConnection, + ( struct sockaddr * ) &client_addr, + ( socklen_t * ) &client_addrlen); + + + if ( sockn == -1 ) { + + perror("webserver (getsockname)"); + + } + + } + + int valread; + + if( this->useSSL == 1 ) { + + valread = SSL_read( ssl, buffer, 4096 - 1 ); + + } else { + + printf("read without ssl\n\n"); + + int valread = read( socketConnection, buffer, 4096 -1 ); + + if ( valread == -1 ) { + + perror("webserver (read)"); + + + + } + + } + + + if ( valread == -1 ) { + + perror("webserver (read)"); + + + } + + + request * requestInstance = request_newPointer(); + + + sscanf( buffer, "%s %s %s", requestInstance->method, requestInstance->url, requestInstance->version ); + + + requestInstance->address = inet_ntoa( client_addr.sin_addr ); + + requestInstance->port = ntohs( client_addr.sin_port ); + + requestInstance->extension = http_getExtension( this, requestInstance->url ); + + requestInstance->mimeType = mimeTypes_getByExtension( mimetypes, requestInstance->extension ); + + this->requestCallback( requestInstance, response ); + + + + + + + int writeResponse; + + if( this->useSSL == 1 ) { + + writeResponse = SSL_write( ssl, response->value, response->length ); + + } else { + + + int writeResponse = write( socketConnection, response->value, response->length ); + + printf("close connection"); + + if ( writeResponse == -1 ) { + + perror("webserver (write)"); + + return; + + } + } + + if ( writeResponse == -1 ) { + + perror("webserver (write)"); + + return; + + } else { + + + + } + + + + + + + + + + + close( socketConnection ); + + + + + + + + + + } + +void http_dump_buffer( http * this, void *buffer, int buffer_size ) { + int i; + + for(i = 0;i < buffer_size;++i){ + + printf( "%c", ( (char *) buffer )[i]); + + } + + } + + + + +void abort( ) { + + +} + +http http_new() { + + http instance; + + instance.hostAddress = malloc( sizeof( struct sockaddr_in ) ); + + instance.hostAddresslength = sizeof( struct sockaddr_in ); + + instance.filesystem = fileSystem_newPointer(); + + instance.mimetypes = mimeTypes_newPointer(); + + instance.headers = headerManager_newPointer(); + + instance.useSSL = -1; + + return instance; + +} + +http * http_newPointer() { + + struct http * pointer = malloc( sizeof ( struct http ) ); + + pointer->hostAddress = malloc( sizeof( struct sockaddr_in ) ); + + pointer->hostAddresslength = sizeof( struct sockaddr_in ); + + pointer->filesystem = fileSystem_newPointer(); + + pointer->mimetypes = mimeTypes_newPointer(); + + pointer->headers = headerManager_newPointer(); + + pointer->useSSL = -1; + + return pointer; + +} + diff --git a/application/demos/example.opengl/http.h b/application/demos/example.opengl/http.h new file mode 100644 index 0000000..0bac8b2 --- /dev/null +++ b/application/demos/example.opengl/http.h @@ -0,0 +1,97 @@ +#ifndef _http + +#define _http + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include "./mimeTypes.h" + +#include "./text.h" + +#include "./fileSystem.h" + + +typedef struct http{ + + int socket; + + struct sockaddr_in * hostAddress; + + int hostAddresslength; + + struct fileSystem * filesystem; + + struct mimeTypes * mimetypes; + + struct headerManager * headers; + + int useSSL; + + SSL_CTX * sslContext; + + void ( * requestCallback )( struct request * requestInstance, struct text * response ); + + +} http; + +void http_createServer( http * this, void ( * requestCallback )( request * req, text * response ) ); + +void http_initializeOpenSSL( http * this ); + +int http_listen( http * this, int port ); + +char * http_getExtension( http * this, char * path ); + +void http_logRequest( http * this, request * requestInstance ); + +void http_acceptConnection( http * this ); + +void http_dump_buffer( http * this, void *buffer, int buffer_size ); + +void abort( ); + +http http_new( ); + +http * http_newPointer( ); + +#endif + + +typedef struct http http; + + + diff --git a/application/demos/example.opengl/int.c b/application/demos/example.opengl/int.c new file mode 100644 index 0000000..59cad2f --- /dev/null +++ b/application/demos/example.opengl/int.c @@ -0,0 +1,21 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + +char * int_toText( int * this ) { + + char * textNumber = malloc( sizeof( char ) * 20 ); + + sprintf( textNumber, "%d", this ); + + return textNumber; + + } + +int int_negative( int * this ) { + + return 12; + + } + diff --git a/application/demos/example.opengl/int.h b/application/demos/example.opengl/int.h new file mode 100644 index 0000000..1dc2992 --- /dev/null +++ b/application/demos/example.opengl/int.h @@ -0,0 +1,24 @@ +#ifndef _int + +#define _int + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + + +char * int_toText( int * this ); + +int int_negative( int * this ); + +#endif diff --git a/application/demos/example.opengl/mimeTypes.c b/application/demos/example.opengl/mimeTypes.c new file mode 100644 index 0000000..dc58d33 --- /dev/null +++ b/application/demos/example.opengl/mimeTypes.c @@ -0,0 +1,93 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + +void mimeTypes_constructor( mimeTypes * this ) { + + mimeTypes_add( this, "html", "text/html"); + + mimeTypes_add( this, "css", "text/css"); + + mimeTypes_add( this, "ttf", "application/x-font-ttf"); + + mimeTypes_add( this, "png", "image/png"); + + mimeTypes_add( this, "svg", "image/svg+xml"); + + } + +void mimeTypes_add( mimeTypes * this, char * extension, char * mimeType ) { + + struct array * extensions = this->extensions; + + array_add( extensions, extension ); + + + struct array * mimeTypes = this->mimeTypes; + + array_add( mimeTypes, mimeType ); + + } + +char * mimeTypes_getByExtension( mimeTypes * this, char * extension ) { + + struct array * extensions = this->extensions; + + struct array * mimeTypes = this->mimeTypes; + + int count = array_length( extensions ); + + for (int i = 0; i < count; ++i) + { + + char * currentExtension = array_get( extensions, i ); + + if( char_operator_compare( currentExtension , extension) ) { + + char * mimeType = array_get( mimeTypes, i ); + + return mimeType; + + } + + } + + return "no-mimetype"; + + } + +mimeTypes mimeTypes_new() { + + mimeTypes instance; + + instance.extensions = array_newPointer(); + + instance.mimeTypes = array_newPointer(); + + mimeTypes_constructor( &instance); + + return instance; + +} + +mimeTypes * mimeTypes_newPointer() { + + struct mimeTypes * pointer = malloc( sizeof ( struct mimeTypes ) ); + + pointer->extensions = array_newPointer(); + + pointer->mimeTypes = array_newPointer(); + + mimeTypes_constructor( pointer ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/mimeTypes.h b/application/demos/example.opengl/mimeTypes.h new file mode 100644 index 0000000..e0e9bbc --- /dev/null +++ b/application/demos/example.opengl/mimeTypes.h @@ -0,0 +1,45 @@ +#ifndef _mimeTypes + +#define _mimeTypes + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "array.h" + + +typedef struct mimeTypes{ + + array * extensions; + + array * mimeTypes; + + +} mimeTypes; + +void mimeTypes_constructor( mimeTypes * this ); + +void mimeTypes_add( mimeTypes * this, char * extension, char * mimeType ); + +char * mimeTypes_getByExtension( mimeTypes * this, char * extension ); + +mimeTypes mimeTypes_new( ); + +mimeTypes * mimeTypes_newPointer( ); + +#endif + + +typedef struct mimeTypes mimeTypes; + + + diff --git a/application/demos/example.opengl/request.c b/application/demos/example.opengl/request.c new file mode 100644 index 0000000..7da555f --- /dev/null +++ b/application/demos/example.opengl/request.c @@ -0,0 +1,112 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + +void request_constructor( request * this ) { + + + } + +void request_free( request * this ) { + + + + + + + + + + + + + + + + + + + + + + free( this ); + + + } + +request request_new() { + + request instance; + + instance.connection = malloc( BUFFER_SIZE ); + + instance.address = malloc( BUFFER_SIZE ); + + instance.url = malloc( BUFFER_SIZE ); + + instance.method = malloc( BUFFER_SIZE ); + + instance.version = malloc( BUFFER_SIZE ); + + instance.mimeType = malloc( BUFFER_SIZE ); + + instance.extension = malloc( BUFFER_SIZE ); + + instance.headers = headerManager_newPointer(); + + request_constructor( &instance); + + return instance; + +} + +request * request_newPointer() { + + struct request * pointer = malloc( sizeof ( struct request ) ); + + pointer->connection = malloc( BUFFER_SIZE ); + + pointer->address = malloc( BUFFER_SIZE ); + + pointer->url = malloc( BUFFER_SIZE ); + + pointer->method = malloc( BUFFER_SIZE ); + + pointer->version = malloc( BUFFER_SIZE ); + + pointer->mimeType = malloc( BUFFER_SIZE ); + + pointer->extension = malloc( BUFFER_SIZE ); + + pointer->headers = headerManager_newPointer(); + + request_constructor( pointer ); + + return pointer; + +} + diff --git a/application/demos/example.opengl/request.h b/application/demos/example.opengl/request.h new file mode 100644 index 0000000..85481ea --- /dev/null +++ b/application/demos/example.opengl/request.h @@ -0,0 +1,62 @@ +#ifndef _request + +#define _request + + +// Macros + +#define BUFFER_SIZE 1024 + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "headers.h" + +#include "stdlib.h" + + +typedef struct request{ + + char * connection; + + char * address; + + int port; + + char * url; + + char * method; + + char * version; + + char * mimeType; + + char * extension; + + struct headerManager * headers; + + +} request; + +void request_constructor( request * this ); + +void request_free( request * this ); + +request request_new( ); + +request * request_newPointer( ); + +#endif + + +typedef struct request request; + + + diff --git a/application/demos/example.opengl/text.c b/application/demos/example.opengl/text.c new file mode 100644 index 0000000..b9fa739 --- /dev/null +++ b/application/demos/example.opengl/text.c @@ -0,0 +1,205 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + +int text_operator_compare( text * this, text * b ) { + + if( strcmp( this->value, b->value ) == 0 ) { + + return 1; + + } else { + + return 0; + + } + + } + +text * text_operator_add( text * this, char * b ) { + + text_append( this, b ); + + return this; + + } + +void text_constructor( text * this, char * value ) { + + this->length = strlen( value ); + + if( this->length > this->capacity ) { + + this->capacity = this->length * 2; + + } + + this->value = malloc( sizeof( char ) * this->capacity ); + + strcpy( this->value, value ); + } + +char text_get( text * this, int index ) { + + return this->value[ index ]; + + } + +void text_resize( text * this, int size ) { + + this->value = realloc( this->value, size ); + + this->capacity = size; + + } + +text * text_append( text * this, char * value ) { + + int originalLength = this->length; + + int newValueLength = strlen( value ); + + this->length += newValueLength; + + if( this->length > this->capacity ) { + + text_resize( this, this->length * 2 ); + + } + + memcpy( this->value + originalLength, value, newValueLength + 1 ); + + return this; + + } + +text * text_appendBinary( text * this, char * value, int size ) { + + int originalLength = this->length; + + int newValueLength = size; + + this->length += newValueLength; + + if( this->length > this->capacity ) { + + text_resize( this, this->length * 2 ); + + } + + memcpy( this->value + originalLength, value, newValueLength + 1 ); + + return this; + + } + + +text * text_appendObject( text * this, text * object ) { + + int originalLength = this->length; + + int newValueLength = object->length; + + this->length += newValueLength; + + if( this->length > this->capacity ) { + + text_resize( this, this->length * 2 ); + + } + + memcpy(this->value + originalLength, object->value, newValueLength + 1); + + return this; + + } + +text * text_concatenate( text * this, char * value ) { + + text * copy = text_newPointer( this->value ); + + strcat( copy->value, value ); + + return copy; + + } + +char * text_toNative( text * this ) { + + return this->value; + + } + +char * text_whiteSpace( text * this, int whiteSpaceCount ) { + + char * output = malloc( 400 ); + + for (int i = 0; i < whiteSpaceCount; ++i) + { + + strcat( output, " " ); + + } + + return output; + + } + +void text_free( text * this ) { + + free( this->value ); + + free( this ); + + } + +text text_new(char * value) { + + text instance; + + instance.usevalue = -1; + + instance.capacity = 500; + + text_constructor( &instance, value); + + return instance; + +} + +text * text_newPointer(char * value) { + + struct text * pointer = malloc( sizeof ( struct text ) ); + + pointer->usevalue = -1; + + pointer->capacity = 500; + + text_constructor( pointer , value); + + return pointer; + +} + diff --git a/application/demos/example.opengl/text.h b/application/demos/example.opengl/text.h new file mode 100644 index 0000000..dd8f2e7 --- /dev/null +++ b/application/demos/example.opengl/text.h @@ -0,0 +1,75 @@ +#ifndef _text + +#define _text + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + + +typedef struct text{ + + char * value; + + int usevalue; + + int length; + + int capacity; + + +} text; + +int text_operator_compare( text * this, text * b ); + +text * text_operator_add( text * this, char * b ); + +void text_constructor( text * this, char * value ); + +char text_get( text * this, int index ); + +void text_resize( text * this, int size ); + +text * text_append( text * this, char * value ); + +text * text_appendBinary( text * this, char * value, int size ); + +text * text_appendObject( text * this, text * object ); + +text * text_concatenate( text * this, char * value ); + +char * text_toNative( text * this ); + +char * text_whiteSpace( text * this, int whiteSpaceCount ); + +void text_free( text * this ); + +text text_new( char * value ); + +text * text_newPointer( char * value ); + +#endif + + +typedef struct text text; + + + diff --git a/application/demos/example.opengl/vector2.c b/application/demos/example.opengl/vector2.c new file mode 100644 index 0000000..0f3cf2e --- /dev/null +++ b/application/demos/example.opengl/vector2.c @@ -0,0 +1,88 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + +void vector2_constructor( vector2 * this, float x, float y ) { + + + + this->x = x; + + this->y = y; + + + + + + + } + + + +vector2 * vector2_operator_plus( vector2 * this, vector2 * b ) { + + vector2_add( this, b ); + + return this; + + } + +vector2 * vector2_operator_add( vector2 * this, struct vector2 * b ) { + + + + + + + return b; + } + +void vector2_add( vector2 * this, vector2 * a ) { + + this->x += a->x; + + this->y += a->y; + + } + +void vector2_subtract( vector2 * this, vector2 * a ) { + + this->x -= a->x; + + this->y -= a->y; + + } + +int vector2_length( vector2 * this ) { + + return this->x + this->y; + + } + +vector2 vector2_new(float x, float y) { + + vector2 instance; + + vector2_constructor( &instance, x, y); + + return instance; + +} + +vector2 * vector2_newPointer(float x, float y) { + + struct vector2 * pointer = malloc( sizeof ( struct vector2 ) ); + + vector2_constructor( pointer , x, y); + + return pointer; + +} + diff --git a/application/demos/example.opengl/vector2.h b/application/demos/example.opengl/vector2.h new file mode 100644 index 0000000..df6577b --- /dev/null +++ b/application/demos/example.opengl/vector2.h @@ -0,0 +1,49 @@ +#ifndef _vector2 + +#define _vector2 + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + + +typedef struct vector2{ + + float x; + + float y; + + +} vector2; + +void vector2_constructor( vector2 * this, float x, float y ); + +vector2 * vector2_operator_plus( vector2 * this, vector2 * b ); + +vector2 * vector2_operator_add( vector2 * this, struct vector2 * b ); + +void vector2_add( vector2 * this, vector2 * a ); + +void vector2_subtract( vector2 * this, vector2 * a ); + +int vector2_length( vector2 * this ); + +vector2 vector2_new( float x, float y ); + +vector2 * vector2_newPointer( float x, float y ); + +#endif + + +typedef struct vector2 vector2; + + + diff --git a/application/demos/example.opengl/vector3.c b/application/demos/example.opengl/vector3.c new file mode 100644 index 0000000..aecc862 --- /dev/null +++ b/application/demos/example.opengl/vector3.c @@ -0,0 +1,72 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + +void vector3_constructor( vector3 * this, float x, float y, float z ) { + + this->x = x; + + this->y = y; + + this->z = z; + + } + +vector3 * vector3_operator_plus( vector3 * this, vector3 * b ) { + + vector3_add( this, b ); + + return this; + + } + +vector3 * vector3_operator_add( vector3 * this, vector3 * b ) { + + vector3_add( this, b ); + + return this; + + } + + + +void vector3_add( vector3 * this, vector3 * b ) { + + this->x += b->x; + + this->y += b->y; + + this->z += b->z; + + } + +vector3 vector3_new(float x, float y, float z) { + + vector3 instance; + + vector3_constructor( &instance, x, y, z); + + return instance; + +} + +vector3 * vector3_newPointer(float x, float y, float z) { + + struct vector3 * pointer = malloc( sizeof ( struct vector3 ) ); + + vector3_constructor( pointer , x, y, z); + + return pointer; + +} + diff --git a/application/demos/example.opengl/vector3.h b/application/demos/example.opengl/vector3.h new file mode 100644 index 0000000..352de30 --- /dev/null +++ b/application/demos/example.opengl/vector3.h @@ -0,0 +1,47 @@ +#ifndef _vector3 + +#define _vector3 + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + + +typedef struct vector3{ + + float x; + + float y; + + float z; + + +} vector3; + +void vector3_constructor( vector3 * this, float x, float y, float z ); + +vector3 * vector3_operator_plus( vector3 * this, vector3 * b ); + +vector3 * vector3_operator_add( vector3 * this, vector3 * b ); + +void vector3_add( vector3 * this, vector3 * b ); + +vector3 vector3_new( float x, float y, float z ); + +vector3 * vector3_newPointer( float x, float y, float z ); + +#endif + + +typedef struct vector3 vector3; + + + diff --git a/application/opengl.c b/application/opengl.c new file mode 100644 index 0000000..dbeae53 --- /dev/null +++ b/application/opengl.c @@ -0,0 +1,233 @@ + + + +#include + +#include + +#include + +#include + +// Opengl is old + +static int DoubleBufferAttributes[] = { + GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DEPTH_SIZE, 12, + GLX_DOUBLEBUFFER, + None, +}; + + + +class opengl{ + + Display * mainDisplay; + + Window mainWindow; + + initialize() { + + this->mainDisplay = XOpenDisplay( 0 ); + + int MainScreen = XDefaultScreen( this->mainDisplay ); + + Window RootWindow = XDefaultRootWindow( this->mainDisplay ); + + int empty; + + int ResultStatus = glXQueryExtension( this->mainDisplay, &empty, &empty ); + + XVisualInfo* VisualInfo = glXChooseVisual( this->mainDisplay, MainScreen, DoubleBufferAttributes ); + + GLXContext ShareList = None; + + int IsDirectRendering = True; + + GLXContext OpenGLContext = glXCreateContext( this->mainDisplay, VisualInfo, ShareList, IsDirectRendering ); + + + + int WindowX = 0; + + int WindowY = 0; + + int WindowWidth = 800; + + int WindowHeight = 600; + + int BorderWidth = 0; + + int WindowClass = InputOutput; + + int WindowDepth = VisualInfo->depth; + + + Visual* WindowVisual = VisualInfo->visual; + + int AttributeValueMask = CWBackPixel | CWEventMask | CWColormap; + + + XSetWindowAttributes WindowAttributes = {}; + + WindowAttributes.colormap = XCreateColormap( this->mainDisplay, RootWindow, VisualInfo->visual, AllocNone); + + WindowAttributes.background_pixel = 0xffafe9af; + + WindowAttributes.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | PointerMotionMask; + + this->mainWindow = XCreateWindow( this->mainDisplay, RootWindow, + WindowX, WindowY, WindowWidth, WindowHeight, + BorderWidth, WindowDepth, WindowClass, WindowVisual, + AttributeValueMask, &WindowAttributes); + + XStoreName( this->mainDisplay, this->mainWindow, "Opengl: Fixed function pipeline" ); + + glXMakeCurrent( this->mainDisplay, this->mainWindow, OpenGLContext ); + + XMapWindow( this->mainDisplay, this->mainWindow ); + + Atom WM_DELETE_WINDOW = XInternAtom( this->mainDisplay, "WM_DELETE_WINDOW", False ); + + if( !XSetWMProtocols( this->mainDisplay, this->mainWindow, &WM_DELETE_WINDOW, 1) ) { + + printf( "Couldn't register WM_DELETE_WINDOW\n" ); + + } + + printf("opengl version: %s\n\n", glGetString(GL_VERSION) ); + + this->createShaders(); + + + int IsProgramRunning = 1; + + while( IsProgramRunning ) { + + while( XPending( this->mainDisplay ) ) { + + XEvent GeneralEvent = {}; + + XNextEvent( this->mainDisplay, &GeneralEvent ); + + switch( GeneralEvent.type ) { + + case ClientMessage: + { + + IsProgramRunning = 0; + + } break; + } + + } + + { + + this->render(); + + } + } + + } + + createShaders() { + + const char* vertex_shader = + "#version 400\n" + "in vec3 vp;" + "void main() {" + " gl_Position = vec4(vp, 1.0);" + "}"; + + const char* fragment_shader = + "#version 400\n" + "out vec4 frag_colour;" + "void main() {" + " frag_colour = vec4(0.5, 0.0, 0.5, 1.0);" + "}"; + + GLuint vs = glCreateShader(GL_VERTEX_SHADER); + + glShaderSource(vs, 1, &vertex_shader, NULL); + glCompileShader(vs); + + + GLuint fs = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(fs, 1, &fragment_shader, NULL); + glCompileShader(fs); + } + + render() { + + this->clearColor( 0.0, 1.0, 0.6, 1.0 ); + + this->clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + this->begin( GL_TRIANGLES ); + + this->color3f(1.0, 0.0, 0.0); + this->vertex2f(0, 0.9); + + this->color3f(0.0, 1.0, 0.0); + this->vertex2f(0.9, -0.9); + + this->color3f(1.0, 1.0, 1.0); + this->vertex2f(-0.9, -0.9); + + this->end(); + + this->flush(); + + } + + vertex2f( float x, float y ) { + + glVertex2f( x, y ); + + } + + color3f( float r, float g, float b ) { + + glColor3f( r, g, b ); + + } + + clear( GLbitfield mask ) { + + glClear( mask ); + + } + + clearColor( float r, float g, float b, float a ) { + + glClearColor( r, g, b, a ); + + } + + begin( GLenum mode ) { + + glBegin( mode ); + + } + + end() { + + glEnd(); + + } + + flush() { + + glXSwapBuffers( this->mainDisplay, this->mainWindow ); + + } + +} + + + + diff --git a/application/source/application.c b/application/source/application.c new file mode 100755 index 0000000..63bde74 --- /dev/null +++ b/application/source/application.c @@ -0,0 +1,845 @@ + + + +// Classes + +// #include + +#define LINUX + +#include + +#include "text.h" + +#include "vector2.h" + +#include "vector3.h" + +#include "triangle.h" + +#include "array.h" + +#include "fileSystem.h" + +#include "sqlite.h" + +#include "char.h" + +#include "int.h" + +#include "extends.h" + +#include "toolset.h" + +#include "console.h" + +#include "street.h" + +#include "opengl.h" + + +// C includes + +#include + +#include + +#include + + + + +#include + +#include + + + +#include + + + + + + +// globals + +char * someArray[10] = {"a", "b", "c"}; + + + + + +void startOpenGL() { + + opengl * instance = new opengl(); + + instance->initialize(); + + +} + +/* + +class thread{ + + int index; + + int vectorCount; + +} + + + +void multiThread() { + + clock_t tic = clock(); + + printf("This system has %d threads configured and %d threads available.\n", get_nprocs_conf(), get_nprocs()); + + + int vectorCount = 10000; + + int numberOfThreads = get_nprocs(); + + pthread_t thread[numberOfThreads]; + + for (int i = 0; i < numberOfThreads; ++i) + { + + struct thread data = new thread(); + + data.index = i; + + data.vectorCount = vectorCount; + + + pthread_create( &thread[i], NULL, mythread2, &data ); + + } + + + //waiting for completion + + for (int i = 0; i < numberOfThreads; ++i) + { + + pthread_join( thread[i], NULL ); + + printf("Thread %i has finished\n\n", i); + + } + + clock_t toc = clock(); + + printf("\n\nAll threads have finished\n\n"); + + + printf("Multiply: %f seconds, Threads: %i Vectors: %i\n\n\n", (double)( toc - tic ) / CLOCKS_PER_SEC, numberOfThreads, numberOfThreads * vectorCount ); + + + + printf("Now doing the same total number of vector additions on only the main thread.\n\n"); + + tic = clock(); + + + struct thread data = new thread(); + + data.index = 0; + + data.vectorCount = numberOfThreads * vectorCount; + + mythread2( &data ); + + + toc = clock(); + + printf("Multiply: %f seconds, Threads: 1 Vectors: %i\n", (double)( toc - tic ) / CLOCKS_PER_SEC, numberOfThreads * vectorCount ); + + +} + +static void * mythread2( void * args) { + + struct thread * currentThread = ( struct thread * ) args; + + clock_t tic = clock(); + + int threadIndex = currentThread->index; + + int vectorCount = currentThread->vectorCount; + + + vector3 * newVector3 = new vector3(); + + newVector3->x = 0; + + newVector3->y = 2; + + newVector3->z = 3; + + + for (int i = 0; i < vectorCount; ++i) + { + + vector3 vector3B = new vector3(); + + vector3B.x = 1; + + vector3B.y = 3; + + vector3B.z = 4; + + + + vector3 vector3C = new vector3(); + + vector3C.x = 0; + + vector3C.y = 3; + + vector3C.z = 4; + + //newVector3 = vector3C + ( vector3C + newVector3 + ( ( ( ( vector3B + vector3C ) ) + vector3C ) + vector3B ) ); + + newVector3 = newVector3 + ( ( vector3B + vector3C ) + vector3C ); + + //printf("thread %i: x: %i y: %i z: %i \n", threadIndex, newVector3->x, newVector3->y, newVector3->z); + + } + + clock_t toc = clock(); + + printf("\nThread .., threadIndex: %i finished, time: %f Computing %i * 2 vectors.\n\n\n", threadIndex, (double)( toc - tic ) / CLOCKS_PER_SEC, vectorCount); + + return NULL; +} + +void textAndArraysExamples() { + + + clock_t tic = clock(); + + text * sometext = new text(" my first text"); + + struct text * a = new text(" Mooi "); + + for (int i = 0; i < 100; ++i) { + + + sometext->appendObject( a )->append("something"); + + } + + //printf("append: %s \n\n", sometext->buffer); + + clock_t toc = clock(); + + printf("Multiply: %f seconds\n", (double)( toc - tic ) / CLOCKS_PER_SEC); + + + char * testText = "a,"; + + array * splitParts = testText->concatenate( "b, " )->concatenate("c,d,e")->concatenate(",f ")->split(",g"); + + char * compareString = "something"; + + splitParts.unshift((char *) "first"); + + splitParts.unshift((char *) "this first"); + + + printf( "joined: %s\n\n", splitParts.join(", ") ); + + char * lastElement = splitParts->pop(); + + printf( "pop joined: %s\n\n", splitParts.join(", ") ); + + printf( "pop removed element: %s\n\n", lastElement ); + + + if( compareString.compare("something") ) { + + printf("this is true\n"); + + } else { + + printf("this is not true\n"); + + } + + printf("first: %s \n\n", splitParts.get( 0 ) ); + + int splitCount = splitParts->length(); + + printf("splitCount: %i\n", splitCount); + + for (int i = 0; i < splitCount; ++i) + { + + char * splitPart = splitParts.get( i ); + + //printf("splitPart: %s \n\n", splitPart->trim() ); + + } + + +} + + + +void sqlite3Example() { + + // sqlite * sql = new sqlite("./database/users.sqlite"); + + sqlite * sql = new sqlite(":memory:"); + + sql->selectModel( "user" ); + + + sql->createTable(); + + char * names[20] = { "piet", "gurbe", "siebe", "gerben", "twain", "piet", "gurbe", "siebe", "gerben", "twain", "piet", "gurbe", "siebe", "gerben", "twain" }; + + clock_t tic = clock(); + + + array * usersInsertArray = new array(); + + for (int i = 0; i <10; ++i) //20000 + { + + char * name = names[i]; + + struct user * userInstance = new user(); + + userInstance->id = i; + + userInstance->username = name; + + userInstance->userlevel = 3; + + userInstance->hash = "12345"; + + usersInsertArray.add( userInstance ); + + //sql->addRow( userInstance ); + + } + + + sql->addRows( usersInsertArray ); + + + + clock_t toc = clock(); + + printf("Multiply: %f seconds, rows: %i\n", (double)( toc - tic ) / CLOCKS_PER_SEC, 10000); + + + + array * usersA = sql->fetchRows( "SELECT * FROM user" ); + + //user * firstUser = new user(); + + user * firstUser = usersA->get( 1 ); + + //firstUser->id =10; + + firstUser->username = "updated"; + + firstUser->userlevel = 1111; + + firstUser->hash = "new hash"; + + console->log( "??", firstUser, "Yeey console.log workswith , , " ); + + sql->update( firstUser ); + + printf("before log\n\n"); + + + + + array * users = sql->fetchRows( "SELECT * FROM user " ); + + int userCount = users->total; + + + printf("added rows: %i\n", userCount); + + console->createHorisontalLine(); + printf("\e[1m"); + + printf(" "); + + printf("%-20s", "id" ); + + printf("%-30s", "username" ); + + printf("%-20s", "userLevel" ); + + printf("%-30s", "Hash"); + + printf("\e[m"); + + printf("\n"); + + console->createHorisontalLine(); + + printf("users: %i\n", userCount); + + for (int i = 0; i < userCount; ++i) + { + + struct user * userInstance = users->get( i ); + + userInstance->id; + + userInstance->username; + + printf(" "); + + printf("%-20i", userInstance->id); + + printf("%-30s", userInstance->username); + + printf("%-20i", userInstance->userlevel); + + printf("%-30s", userInstance->hash); + + printf( "\n" );//%-30s + + } + + sql->free(); + + console->createHorisontalLine(); + +} + +void multiInherintence() { + + + + struct inherit * pointer = new inherit(); + + //pointer->propertyFromC = 20; + + + printf("pointer->propertyFromC: %i\n\n", pointer->propertyFromC ); + + pointer->methodFromC(); + + printf("\n\n\n\n"); + + + for (int i = 0; i < 1; ++i) + { + + struct inherit instance = new inherit(); + + instance.propertyFromA = i; + + instance.propertyFromB = i; + + instance.propertyFromC = i; + + instance.methodFromC(); + + } + +} +*/ + + +//int main() +//{ + + //startOpenGL(); + +/* + return 1; + + struct user * newUser = new user(); + + newUser->id = 1; + + newUser->username = "peter"; + + newUser->userlevel = 2134; + + newUser->hash = "#234234325"; + + + + struct array * addresses = newUser->addresses; + + + address * someAddress = new address(); + + someAddress->street = "HiLane"; + + someAddress->number = 1234; + + addresses->add( someAddress ); + + + + + address * otherAddress = new address(); + + otherAddress->street = "OtherLane"; + + otherAddress->number = 4567; + + addresses->add( otherAddress ); + + // todo newUser->addresses->add( otherAddress ); + + + printf("adresses count: %i\n\n", addresses->length() ); + + + char * something = "this is from an char * "; + + int somethingElse = 123; + + + console.log( "Goedendag", + 123456, + "en een andere text.", + something, + somethingElse, + "something en something", + "in native c", + 23456, + newUser, + "and some text again" ); //&(int[3]){ 1, 2, 1 }, 3, + + + + + sqlite3Example(); + + textAndArraysExamples(); + + + multiInherintence(); + + //tools->createHorisontalLine(); + + //createHorisontalLine(); + + + printf("\n\n\n\n\n\n\n"); + + + int totalInteger = 0; + + printf("This just works out of the box.. \n"); + + for (int i = 0; i < 1; ++i) + { + + int someInteger = 10; + + int theNegative = someInteger->negative(); + + totalInteger += theNegative; + + //printf("this int is negative: %i\n\n", someInteger->negative() ); + + } + + + + char somechar = 56; + + + char * directory2 = "./assets/"; + + fileSystem * filesystem = new fileSystem(); + + char * directory = "./assets/"; + + array * files = filesystem->readDir( directory ); + + int fileCount = files->length(); + + for ( int i = 0; i < fileCount; ++i ) + { + + char * file = files->get( i ); + + char * path = directory->concatenate( file ); + + text * source = filesystem->readFile( path, "binary" ); + + + printf("filename: %s\n", path); + + printf("source: %s\n\n\n", source->value); + + } + + + array * arrayA = new array(); + + clock_t tic = clock(); + + + int count = 0; + + for (int i = 0; i < 1000000; ++i) + { + vector2 testVector = new vector2( i, i * 450 ); + + vector2 testVector2 = new vector2( 10, 450 ); + + testVector->add( &testVector2 ); + + count++; + + } + + + printf("count: %i\n", count); + + + for ( int i = 0; i < 1; ++i ) + { + + vector2 testVector = new vector2( 10, 450 ); + + + arrayA->add( &testVector ); + + arrayA->add( &testVector ); + + + //printf("number of items in array: %i \n ", arrayA->length() ); + + vector2 * returned = arrayA->get( i ); + + //printf("returned vector x: %i \n ", returned->x ); + + //printf("returned vector y: %i \n ", returned->y ); + + vector2 testVector3 = new vector2( 2, 3 ); + + arrayA->set( i, &testVector3 ); + + vector2 * secondReturn = arrayA->get( 0 ); + + //printf("returned vector x: %i \n ", secondReturn->x ); + + //printf("returned vector y: %i \n ", secondReturn->y ); + + returned->add( secondReturn ); + + printf( "returned vector x: %i \n ", returned->x ); + + printf("returned vector y: %i \n ", returned->y ); + + } + + + for ( int i = 0; i < 1; ++i ) + { + + vector2 a = new vector2( 10, 10 ); + + vector2 b = new vector2( 10, 10 ); + + a->add( &b ); + + printf( "a->x: %i, a->y: %i\n", a.x, a.y); + + } + + + + for (int i = 0; i < 1; ++i) + { + triangle * a = new triangle(); + + triangle * b = new triangle(); + + + a->add( b ); + } + + + vector2 * t = new vector2( 2,2 ); + + int totalLength = 0; + + for (int i = 0; i < 1; ++i) + { + + t->x = 100; + + vector2 b = new vector2( 123, 2 ); + + b.x = 50; + + vector2 c = new vector2( 1, 12 ); + + + c.x = i; + + t->add( &b ); + + b.add( &c ); + + c.add( &b ); + + printf("a, %i\n", t->x); + + printf("b, %i\n", b.x); + + printf("c, %i\n", c.x); + + } + + + + operatorOverload(); + + //printf("%s", other); + + */ + +} +/* +void operatorOverload() { + + text * textB = new text("ook mooi"); + + char * other = malloc(5000); + + vector3 * newVector3 = new vector3(); + + newVector3->x = 2; + + newVector3->y = 2; + + newVector3->z = 3; + + + for (int i = 0; i < 1000; ++i) + { + + vector3 * vector3B = new vector3(); + + + vector3B->x = 2; + + vector3B->y = 3; + + vector3B->z = 4; + + + vector3 * vector3C = new vector3(); + + + vector3C->x = 2; + + vector3C->y = 3; + + vector3C->z = 4; + + newVector3 = vector3C + ( vector3C + newVector3 + ( ( ( ( vector3B + vector3C ) ) + vector3C ) + vector3B ) ); + + newVector3 = newVector3 + ( ( vector3B + vector3C ) + vector3C ); + + } + + console->log( newVector3 ); + + text * textA = new text("mooi"); + + if( textA == textB ) { + + printf("mooi zo"); + + } + + text * textC = new text("mooi"); + + text * textD = new text("mooi"); + + + if( ( ( textA == textC ) && ( textA == textD ) ) && textA == textD ) { + + printf("Good, This works.\n\n"); + + } + + char * realChar = "something"; + + if( "something" == realChar ) { + + printf("Wauw.\n\n"); + + } + + if( realChar == "something" ) { + + printf("Wauw.\n\n"); + + } + + if( realChar == realChar ) { + + printf("Wauw.\n\n"); + + } + + if( "something" == "something" && realChar == "something" ) { + + printf("Wauw.\n\n"); + + } + + char * fancy = "aaa "; + + char * aaaa = " bbb "; + + char * bbbb = " ccc "; + + char * dddd = " dddd "; + + other += ( fancy + ( bbbb + aaaa ) + dddd ) + " eee" + " het is een wonder "; + + other += ("boven wonder" + returnText("this is a normal function") + " and this " + ( "works just good..." + dddd )); + + other += "something" + ( returnText("this is a normal function") + textB->toNative() + textB->value ); + + other += ("and here some text") + (textB->toNative()) ; + + other += ( textB->value + ( ( textB->value ) + returnText("this is a normal function") ) + (textB->toNative() + "here some text" + textB->value ) ); + + other += textB->value + textB->value + ( textB->value + textB->value ) + ( textB->value + textB->value ) + textB->value + textB->value; + + console.log( "Mooi zo ", other ); + + + multiThread(); + + vector3 * VectorTester = new vector3(); +*/ +//} + + +char * returnText( char * text ) { + + return text; +} + +void abort() { + + +} diff --git a/application/source/array.c b/application/source/array.c new file mode 100755 index 0000000..67d46f7 --- /dev/null +++ b/application/source/array.c @@ -0,0 +1,205 @@ + +#include + +#include + +#include + +#include + + +class array{ + + int capacity = 10; + + int total = 0; + + void * * items = malloc( 10000000 ); + + int length() + { + + return this->total; + + } + + void * * data() { + + return this->items; + + } + + + void * get( int index ) + { + + if ( index >= 0 && index < this->total ){ + + return this->items[index]; + + } + + return NULL; + + } + + void set( int index, void * item ) + { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + void resize( int capacity ) + { + + void * * items = realloc( this->items, sizeof( void * ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + void add( void * item ) + { + + if ( this->capacity == this->total ){ + + this->resize( this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + char * join( char * separator ) { + + int count = this->length(); + + text * result = new text( "" ); + + for (int i = 0; i < count; ++i) + { + + char * currentPart = this->items[ i ]; + + if( i > 0 ) { + + result->append( separator ); + + } + + result->append( currentPart ); + + } + + + + return result->value; + + } + + void delete( int index ) + { + if ( index < 0 || index >= this->total ){ + + return; + + } + + this->items[index] = NULL; + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + this->items[i + 1] = NULL; + + } + + this->total--; + + if ( this->total > 0 && this->total == this->capacity / 4 ){ + + this->resize( this->capacity / 2 ); + + } + + } + + int array_push( void * item ) { + + this->add( item ); + + return this->total; + + } + + void unshift( void * item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + this->resize( this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } + + void * pop() { + + int length = this->total; + + int lastIndex = length - 1; + + void * lastItem = this->get( lastIndex ); + + this->delete( lastIndex ); + + return lastItem; + + } + + bool includes( char * value ) { + + int count = this->length(); + + for ( int index = 0; index < count; ++index ) + { + + char * currentText = this->get(index); + + //printf("test: %s \n", this->items[index]); + + if( currentText == value ) { + + return true; + + } + + } + + return false; + + } + + +} \ No newline at end of file diff --git a/application/source/arrayText.c b/application/source/arrayText.c new file mode 100644 index 0000000..e7394c3 --- /dev/null +++ b/application/source/arrayText.c @@ -0,0 +1,178 @@ + +#include + +#include "stdbool.h" + +#include "char.h" + + +class arrayText{ + + int capacity = 40; + + int total = 0; + + char * * items = malloc( 10000000 ); + + int length() + { + + return this->total; + + } + + bool includes( char * value ) { + + int count = this->length(); + + for ( int index = 0; index < count; ++index ) + { + + char * currentText = this->get(index); + + //printf("test: %s \n", this->items[index]); + + if( currentText == value ) { + + return true; + + } + + } + + return false; + + } + + char * get( int index ) + { + + if ( index >= 0 && index < this->total ){ + + return this->items[index]; + + } + + return "NULL"; + + } + + void set( int index, char * item ) + { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + void resize( int capacity ) + { + + char * * items = realloc( this->items, sizeof( char * ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + void add( char * item ) + { + + + if ( this->capacity == this->total ){ + + this->resize( this->capacity * 2 ); + + } + + + this->items[ this->total ] = ( char * ) malloc( 200 * sizeof( char ) ); + + strcpy(this->items[ this->total ], item); + + + this->total++; + + + + } + + void delete( int index ) + { + if ( index < 0 || index >= this->total ){ + + return; + + } + + //this->items[index] = ""; + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + this->items[i + 1] = ""; + + } + + this->total--; + + if ( this->total > 0 && this->total == this->capacity / 4 ){ + + this->resize( this->capacity / 2 ); + + } + + } + + unsigned int array_push( char * item ) { + + this->add( item ); + + return this->total; + + } + + void unshift( char * item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + this->resize( this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } + + char * pop() { + + int length = this->total; + + int lastIndex = length - 1; + + char * lastItem = this->get( lastIndex ); + + this->delete( lastIndex ); + + return lastItem; + + } + + +} \ No newline at end of file diff --git a/application/source/assets/test b/application/source/assets/test new file mode 100755 index 0000000..394d407 --- /dev/null +++ b/application/source/assets/test @@ -0,0 +1 @@ +this is just a test. \ No newline at end of file diff --git a/application/source/cache.c b/application/source/cache.c new file mode 100644 index 0000000..f15ca5d --- /dev/null +++ b/application/source/cache.c @@ -0,0 +1,75 @@ + +#include "array.h" + +#include "text.h" + +#include "file.h" + +#include "fileSystem.h" + + +class cache { + + struct array * files = new array(); + + text * getFile( char * filePath ) { + + struct file * currentFile = this->getCachedFileByPath( filePath ); + + if( currentFile == NULL ) { + + //printf("reading new file: %s\n\n", filePath); + + struct text * content = filesystem->readFile( filePath, "binary" ); + + this->addFile( filePath, content ); + + return content; + + } else { + + return currentFile->content; + + } + + } + + addFile( char * filePath, struct text * content ) { + + struct file * newFile = new file(); + + newFile->filePath = filePath; + + newFile->content = content; + + this->files->add( newFile ); + + } + + struct file * getCachedFileByPath( char * filePath ) { + + struct array * files = this->files; + + int count = files->length(); + + for (int i = 0; i < count; ++i) + { + + file * currentFile = files->get( i ); + + if( currentFile->filePath == filePath ) { + + //printf("using cached file: %s\n\n", filePath); + + return currentFile; + + } + + } + + return NULL; + + } + + +} \ No newline at end of file diff --git a/application/source/callbacks.c b/application/source/callbacks.c new file mode 100644 index 0000000..3f0bbed --- /dev/null +++ b/application/source/callbacks.c @@ -0,0 +1,60 @@ + +#include + +class someClass{ + + char * value = "someValue"; + +} + + + + +class callback{ + + constructor() { + + this->testCallbacks(); + + } + + void callCallback( void ( * function )( struct someClass * caller, int ) , int number, struct someClass * caller ) { + + function( caller, number ); + + } + + void printTest( struct someClass * caller, int a ) { + + printf("print test: %i %s .\n\n\n\n", a, caller->value); + + } + + void anotherPrintTest( struct someClass * caller, int a ) { + + //struct user * someUser = someObject; + + printf("another print test: %i %s .\n\n\n\n", a, caller->value); + + } + + + void testCallbacks() { + + someClass * instance = new someClass(); + + this->callCallback( this->printTest, 1234, instance ); + + this->callCallback( this->printTest, 5678, instance ); + + this->callCallback( this->printTest, 910, instance ); + + this->callCallback( this->anotherPrintTest, 910, instance ); + + this->callCallback( this->anotherPrintTest, 910, instance ); + + } + + +} + diff --git a/application/source/char.c b/application/source/char.c new file mode 100755 index 0000000..bffff6c --- /dev/null +++ b/application/source/char.c @@ -0,0 +1,171 @@ + + +#include + +#include + +#include + +#include + +#include + +#include + +#include + + +class char{ + + + int operator==( char * b ) { + + return this->compare( b ); + + } + + void operator+=( char * b ) { + + // not proper + strcat( this, b ); + + } + + char * operator+( char * b ) { + + return this->concatenate( b ); + + } + + int compare( char * b ) { + + return strcmp( this, b ) == 0; + + } + + char * concatenate( char * b ) { + + int lengthA = strlen( this ); + + int lengthB = strlen( b ); + + char * pointer = this; + + char * copy = ( char * ) malloc( ( lengthA + lengthB + 1 ) * sizeof( char ) ); + + int idx = 0; + + while ( * pointer != '\0' ){ + + copy[idx++] = *pointer++; + + } + + pointer = &b[0]; + + while ( * pointer != '\0' ){ + + copy[idx++] = *pointer++; + + } + + copy[ idx++ ] = '\0'; + + return ©[0]; + + } + + int includes( char * compare ) { + + if ( strstr( this, compare ) != NULL ) { + + return 1; + + } else { + + return 0; + + } + } + + char * clone( ) { + + char * newCopy = malloc( sizeof( char ) * strlen( this ) ); + + strcpy( newCopy, this ); + + return newCopy; + + } + + char * copy( ) { + + char * newCopy = malloc( sizeof( char ) * strlen( this ) ); + + strcpy( newCopy, this ); + + return newCopy; + + } + + struct array * split( char * needle ) + { + + char * haystack = this->clone(); + + struct array * keys = new array(); + + int count = 0; + + char * tmp = haystack; + + char * token = strtok( haystack, needle ); + + int i = 0; + + while ( token ) { + + array_add( keys, token ); + + //printf("strtok: %s \n", token ); + + token = (char *) strtok( NULL, needle ); + + } + + return keys; + + + } + + + char * removeWhitespaceLeft() + { + char * s = this; + + while(isspace(*s)) s++; + + return s; + } + + char * removeWhitespaceRight() + { + char * s = this; + + char* back = s + strlen(s); + + while( isspace( *--back ) ); + + *( back + 1 ) = '\0'; + + return s; + } + + char * removeWhitespace( ) + { + + return this->removeWhitespaceLeft()->removeWhitespaceRight(); + + } + +} \ No newline at end of file diff --git a/application/source/console.c b/application/source/console.c new file mode 100644 index 0000000..5777b67 --- /dev/null +++ b/application/source/console.c @@ -0,0 +1,264 @@ + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#define isCompatible(x, type) _Generic(x, type: true, default: false) + + +extern struct consoleManager * console; + +class consoleManager{ + + char * whiteSpace( int whiteSpaceCount ) { + + char * output = malloc( whiteSpaceCount + 1 ); + + for (int i = 0; i < whiteSpaceCount; ++i) + { + + strcat( output, " " ); + + } + + output[whiteSpaceCount] = 0; + + return output; + + } + + logObject( void * voidPointer, int classIndex, int level ) { + + + char * whiteSpace = this->whiteSpace( level ); + + level++; + + char * className = getClassName( classIndex ); + + printf( "\n\n" ); + + printf( whiteSpace ); + + printf(" %s : {\n", className ); + + + + char * * propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + char * pointer = voidPointer; + + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + printf( whiteSpace ); + + printf(" %-20s : ", propertyName); + + int propertyDatatypeIndex = getPropertyDatatypeIndex( datatypeIndices, propertyIndex ); + + int propertyOffset = getPropertyOffsetByPropertyIndex( propertyOffsets, propertyIndex ); + + + if( propertyDatatypeIndex == -5 ) { + + int value = *( int * )(pointer + propertyOffset); + + printf( whiteSpace ); + + printf("%-20i ", value ); + + + + } else if( propertyDatatypeIndex == -3 ) { + + //char * columnValueCopy = ( char * ) malloc( 8 ); + + uintptr_t * value = ( uintptr_t * ) ( pointer + propertyOffset ); + + //strncpy( &columnValueCopy, value, 8 ); + + printf( whiteSpace ); + + printf( "%-20s", ( char * ) * value ); + + } else if( propertyDatatypeIndex > 0 ) { + + char * memberClassName = getClassName( propertyDatatypeIndex ); + + if( strcmp( memberClassName, "array" ) == 0 ) { + + struct array * memberArray = *(struct array ** )(pointer + propertyOffset) ; + + if( memberArray == NULL ) { + + printf(" this has to be fixed, array is not created.\n"); + + continue; + + } + + int numberRows = memberArray->length(); + + int * arrayPointer = ( int * ) memberArray->items; + + for (int k = 0; k < numberRows; ++k) + { + + void * pointer = memberArray->get( k ); + + short * row = (short*)(pointer); + + this->logObject( pointer, (int) *row, level ); + + } + + } + + //printf("This is another class: %s\n\n", memberClassName); + + } + + + printf("\n"); + + + } + + printf( whiteSpace ); + + printf( " }\n" ); + + + + } + + void log( ... ) { + + //int datatypes[], int count, + + int level = 0; + + va_list args; + + va_start( args, count ); + + //printf("count: %i\n\n", count); + + for (int i = 0; i < count; ++i) + { + int datatype = datatypes[i]; // va_arg_type( argumentIndex ) + + //printf("datatype %i\n", datatype); + + if( datatype == -2 ) { + + char * message = va_arg( args, char * ); + + printf("%s", message); + + } + + if( datatype == -1 ) { + + int message = va_arg( args, int ); + + printf("%i", message); + } + + if( datatype > 0 ) { + + //int classIndex = va_arg( args, int ); + + void * voidPointer = va_arg( args, void * ); + + this->logObject( voidPointer, datatype, level++ ); + + + } + + printf(" "); + + } + + printf("\n"); + + va_end( args); + + } + + void error( char * message ) { + + #define ANSI_COLOR_RED "\x1b[31m" + #define ANSI_COLOR_GREEN "\x1b[32m" + #define ANSI_COLOR_DIM_YELLOW "\x1b[33m" + #define ANSI_COLOR_BLUE "\x1b[34m" + #define ANSI_COLOR_MAGENTA "\x1b[35m" + #define ANSI_COLOR_CYAN "\x1b[36m" + #define ANSI_COLOR_RESET "\x1b[0m" + + #define ANSI_COLOR_BRIGHT_YELLOW "\x1b[93m" + + printf( ANSI_COLOR_RED ); + + printf( "\n\n Error: " ); + + printf( "%s\n\n", message ); + + printf( ANSI_COLOR_RESET ); + + exit( 0 ); + + } + + void createHorisontalLine() { + + struct winsize w; + + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + + for (int i = 0; i < w.ws_col; ++i) + { + + printf("-"); + + }; + + printf("\n"); + + } + +} + + + + + + + + + + diff --git a/application/source/define.c b/application/source/define.c new file mode 100644 index 0000000..729baf6 --- /dev/null +++ b/application/source/define.c @@ -0,0 +1,3 @@ + + +#define someImportantDefine \ No newline at end of file diff --git a/application/source/engine/arrayUnsignedInteger.c b/application/source/engine/arrayUnsignedInteger.c new file mode 100644 index 0000000..3e516d4 --- /dev/null +++ b/application/source/engine/arrayUnsignedInteger.c @@ -0,0 +1,138 @@ + + +class arrayUnsignedInteger{ + + int capacity = 10; + + int total = 0; + + unsigned int * items = malloc( 10000000 ); + + int length() + { + + return this->total; + + } + + unsigned int get( int index ) + { + + + return this->items[index]; + + + + } + + void set( int index, unsigned int item ) + { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + void resize( int capacity ) + { + + int * items = realloc( this->items, sizeof( unsigned int ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + + void add( unsigned int item ) + { + + if ( this->capacity == this->total ){ + + this->resize( this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + void delete( int index ) + { + if ( index < 0 || index >= this->total ){ + + return; + + } + + this->items[index] = 0.0; + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + this->items[i + 1] = 0.0; + + } + + this->total--; + + if ( this->total > 0 && this->total == this->capacity / 4 ){ + + this->resize( this->capacity / 2 ); + + } + + } + + unsigned int array_push( unsigned int item ) { + + this->add( item ); + + return this->total; + + } + + void unshift( int item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + this->resize( this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } + + unsigned int pop() { + + int length = this->total; + + int lastIndex = length - 1; + + int lastItem = this->get( lastIndex ); + + this->delete( lastIndex ); + + return lastItem; + + } + + +} \ No newline at end of file diff --git a/application/source/engine/block.c b/application/source/engine/block.c new file mode 100644 index 0000000..e06cf0e --- /dev/null +++ b/application/source/engine/block.c @@ -0,0 +1,560 @@ + +#define GL_GLEXT_PROTOTYPES + +#include + +#include // GL 1.1 functions + +#include + +#include + +#include "fileSystem.h" + +#include "array.h" + +#include "char.h" + +#include "sampler2D.h" + +#include "member.h" + +class block{ + + array * members = new array(); + + GLint buffer; + + GLuint index; + + GLenum bufferType; + + GLint bufferSize; + + GLint bindingPoint; + + GLchar * name; + + float * data; + + GLint autoUpload = 0; + + + + add( struct member * memberInstance ) { + + this->members->add( memberInstance ); + + } + + enableAutoUpload() { + + this->autoUpload = 1; + + } + + + char * getBufferTypeText( ) { + + switch( this->bufferType ) { + + case GL_SHADER_STORAGE_BUFFER: + + return "GL_SHADER_STORAGE_BUFFER"; + + break; + + case GL_UNIFORM_BUFFER: + + return "GL_UNIFORM_BUFFER"; + + break; + } + + return "buffer message not found"; + + } + + createBuffer() { + + unsigned int blockBufferSize = this->bufferSize; // allocate 152 bytes of memory + + //printf(" create array for block %s os size %i \n", this->name, this->bufferSize ); + + this->data = ( float * ) malloc( blockBufferSize ); + + glGenBuffers( 1, &this->buffer ); + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->index, this->buffer ); + + glBufferData( this->bufferType, blockBufferSize, 0, GL_DYNAMIC_DRAW ); + + } + + void upload() { + + //printf("upload uniform buffer: %f %f %f %f\n", this->data[0], this->data[1], this->data[2], this->data[3]); + + //printf("upload uniform buffer: %i\n", this->index); + + //glBindBuffer( this->bufferType, this->buffer ); + + //glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + //glBufferData( this->bufferType, this->bufferSize, this->data, GL_DYNAMIC_DRAW ); + + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + glBufferSubData( this->bufferType, 0, this->bufferSize, this->data ); + + } + + mapBufferError( void * pointer ) { + + if ( pointer == NULL ){ + + GLenum errorCode = glGetError(); + + switch( errorCode ) { + + case GL_INVALID_ENUM: + + printf("GL_INVALID_ENUM\n"); + + break; + + case GL_INVALID_OPERATION: + + printf("GL_INVALID_OPERATION\n"); + + break; + + case GL_INVALID_VALUE: + + printf("GL_INVALID_VALUE\n"); + + break; + + } + + + printf("null pointer on buffer: %i\n", errorCode); + + return; + + } + + } + + void * getMemberArray( char * name ) { + + glMemoryBarrier( GL_SHADER_STORAGE_BARRIER_BIT ); + + vector * output = new vector(); + + + int uniformCount = this->members->length(); + + for (int i = 0; i < uniformCount; ++i) + { + member * currentMember = this->members->get( i ); + + char * memberName = ( char * ) currentMember->name; + + if( memberName == name ) { + + int size = currentMember->size * 8; + + int offset = currentMember->offset / 4; + + output->items = glMapBufferRange( GL_SHADER_STORAGE_BUFFER, 0, size, GL_MAP_WRITE_BIT ); + + output->total = currentMember->size; + + this->mapBufferError( output->items ); + + + } + + } + + glUnmapBuffer( GL_SHADER_STORAGE_BUFFER ); + + + return output; + + } + + void setMemberArrayRow( char * name, int arrayIndex, float * data ) { + + int memberCount = this->members->length(); + + for (int i = 0; i < memberCount; ++i) + { + member * currentMember = this->members->get( i ); + + char * memberName = ( char * ) currentMember->name; + + if( memberName == name ) { + + int size = currentMember->size * 8; + + int arrayStride = currentMember->arrayStride; + + int offset = arrayStride * arrayIndex; + + //printf("set array stride: %i %i\n", arrayIndex, arrayStride); + + //int offset = currentMember->offset / 4; + + + if( this->autoUpload ) { + + + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + glBufferSubData( this->bufferType, offset, arrayStride, data ); + + } + + + memcpy( this->data + offset, data, arrayStride ); + + + + } + + } + + } + + void setMemberArray( char * name, float * data ) { + + int memberCount = this->members->length(); + + for (int i = 0; i < memberCount; ++i) + { + member * currentMember = this->members->get( i ); + + char * memberName = ( char * ) currentMember->name; + + if( memberName == name ) { + + int size = currentMember->size * 8; + + int offset = currentMember->offset / 4; + + memcpy( this->data + offset, data, size ); + + } + + } + + } + + void setMemberItem( char * name, int index, void * value ) { + + + int uniformCount = this->members->length(); + + //printf("uniformCount: %i\n\n", uniformCount); + + for (int i = 0; i < uniformCount; ++i) + { + member * currentMember = this->members->get( i ); + + char * memberName = ( char * ) currentMember->name; + + if( memberName == name ) { + + //printf("\n\n Update this uniform from uniform block %s\n\n", name); + int stride; + + int strideNormalized; + + int size; + + int offset; + + + switch( currentMember->type ) { + + case GL_FLOAT_VEC2: + + stride = currentMember->arrayStride; + + strideNormalized = stride / sizeof( float ) ; + + //printf("get size of item: %i\n",strideNormalized ); + + + + vector2 * vector2Value = ( vector2 * ) value; + + size = 8; + + offset = currentMember->offset; + + + + if( this->autoUpload ) { + + GLint arrayIndex = ( strideNormalized * index * 2 * 8 ); + + float data[2] = { vector2Value->x, vector2Value->y }; + + printf("%i: (size:%i) %f %f\n", arrayIndex, data[0], data[1]); + + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + glBufferSubData( this->bufferType, arrayIndex, size, data ); + + + + } else { + + GLint dataOffset = offset / sizeof( float ); + + GLint arrayIndex = ( strideNormalized * index ); + + // need to fix this + if( currentMember->topLevelSize == 1 ) { + + //arrayIndex = 0; + + } + + + //printf(" %i: %f \n", dataOffset + 1 + arrayIndex , vector2Value->y ); + + this->data[ dataOffset + arrayIndex ] = vector2Value->x; + + this->data[ dataOffset + 1 + arrayIndex ] = vector2Value->y; + + } + + + + break; + + case GL_FLOAT_VEC3: + + stride = currentMember->arrayStride; + + strideNormalized = stride / sizeof( float ) ; + + + vector3 * vector3Value = ( vector3 * ) value; + + size = 12; + + offset = currentMember->offset; + + + + if( this->autoUpload ) { + + float data[3] = { vector3Value->x, vector3Value->y, vector3Value->z }; + + // printf("%f %f\n", data[0], data[1]); + + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + glBufferSubData( this->bufferType, offset, size, data ); + + + + } else { + + GLint dataOffset = offset / sizeof( float ); + + GLint arrayIndex = ( strideNormalized * index ); + + this->data[ dataOffset + arrayIndex ] = vector3Value->x; + + this->data[ dataOffset + 1 + arrayIndex ] = vector3Value->y; + + this->data[ dataOffset + 2 + arrayIndex ] = vector3Value->z; + + } + + break; + + case GL_SAMPLER_2D: + + + break; + + } + + } + + } + + } + + void setData( float * data ) { + + this->data = data; + + } + + void setMember( char * name, void * value ) { + + int uniformCount = this->members->length(); + + //printf("uniformCount: %i\n\n", uniformCount); + + for (int i = 0; i < uniformCount; ++i) + { + member * currentMember = this->members->get( i ); + + char * memberName = ( char * ) currentMember->name; + + if( memberName == name ) { + + //printf("\n\n Update this uniform from uniform block %s\n\n", name); + + GLuint size = 8; + + GLint offset = currentMember->offset; + + switch( currentMember->type ) { + + case GL_INT: + + int intValue = *( int * ) value; + + printf("set int value: %i offset: %i\n", intValue, offset); + + + + if( this->autoUpload ) { + + float data[1] = { value }; + + // printf("%f %f\n", data[0], data[1]); + + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + glBufferSubData( this->bufferType, offset, size, data ); + + + + } else { + + GLint dataOffset = offset / sizeof( float ); + + this->data[ dataOffset ] = intValue; + + //this->data[ dataOffset + 1 ] = vector2Value->y; + + } + + break; + + case GL_FLOAT: + + float floatValue = *( float * ) value; + + printf("set int value: %f offset: %i\n", floatValue, offset); + + + + if( this->autoUpload ) { + + float data[1] = { value }; + + // printf("%f %f\n", data[0], data[1]); + + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + glBufferSubData( this->bufferType, offset, size, data ); + + + + } else { + + GLint dataOffset = offset / sizeof( float ); + + this->data[ dataOffset ] = floatValue; + + //this->data[ dataOffset + 1 ] = vector2Value->y; + + } + + break; + + case GL_FLOAT_VEC2: + + vector2 * vector2Value = ( vector2 * ) value; + + if( this->autoUpload ) { + + float data[2] = { vector2Value->x, vector2Value->y }; + + + glBindBuffer( this->bufferType, this->buffer ); + + glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer ); + + glBufferSubData( this->bufferType, offset, size, data ); + + + + } else { + + GLint dataOffset = offset / sizeof( float ); + + this->data[ dataOffset ] = vector2Value->x; + + this->data[ dataOffset + 1 ] = vector2Value->y; + + } + + break; + + case GL_FLOAT_VEC3: + + vector3 * vector3Value = ( vector3 * ) value; + + + + break; + + case GL_SAMPLER_2D: + + + break; + + } + + } + + + } + + + } + +} diff --git a/application/source/engine/element.c b/application/source/engine/element.c new file mode 100644 index 0000000..fe90bf0 --- /dev/null +++ b/application/source/engine/element.c @@ -0,0 +1,302 @@ + +#include "vector2.h" + +#include "vector3.h" + +#include "vector4.h" + +#include "vector.h" + +#include "char.h" + +#include "classConfiguration.h" + +#include + +#include + +#include + + +class element{ + + int index; + + vector3 position = new vector3( 0, 0, 0 ); + + vector2 size = new vector2( 0, 0 ); + + vector3 backgroundColor = new vector3( 0, 0, 0 ); + + + + vector3 originalPosition = new vector3( 0, 0, 0 ); + + vector2 originalSize = new vector2( 0, 0 ); + + vector3 originalBackgroundColor = new vector3( 0, 0, 0 ); + + + + float opacity = 1; + + char * backgroundImagePath = ""; + + bool useBackgroundImage = false; + + int features = 0; + + vector * featureNames = new vector(); + + + constructor() { + + this->featureNames->add( "useBackgroundImage" ); + + this->featureNames->add( "useBorder" ); + + } + + + vector4 colorConverter( char * hexValue ) + { + + int r; + + int g; + + int b; + + int a; + + sscanf( hexValue, "%02x%02x%02x%02x", &r, &g, &b, &a ); + + printf("opacity: %i\n"); + + struct vector4 rgbColor = new vector4( r, g, b, (float)a ); + + return rgbColor; + } + + + int textureIndex; + + void * background; + + setOriginal() { + + this->originalSize = this->size; + + this->originalPosition = this->position; + + this->originalBackgroundColor = this->backgroundColor; + + } + + set size( vector2 a ) { + + this->size.x = a.x; + + this->size.y = a.y; + + printf("set size: %f %f\n", this->size.x, this->size.y); + + + + } + + set position( vector3 a ) { + + this->position.x = a.x; + + this->position.y = a.y; + + this->position.z = a.z; + + printf("set position: %f %f\n", this->position.x, this->position.y); + + + + } + + bool featureIsEnabled( int featureValue ) { + + return ( this->features & featureValue ) > 0; + + } + + + + int getFeatureValueByFeatureName( char * featureName ) { + + int count = this->featureNames->length(); + + for (int i = 0; i < count; ++i) + { + char * currentFeatureName = this->featureNames->get( i ); + + if( featureName == currentFeatureName ) { + + return powf( 2, i ); + + } + + } + + return 0; + + } + + int updateFeature() { + + int currentFeatureValue; + + currentFeatureValue = this->getFeatureValueByFeatureName( "useBackgroundImage" ); + + if( this->featureIsEnabled( currentFeatureValue ) ) { + + if( !this->useBackgroundImage ) { + + this->features -= currentFeatureValue; + + } + + } else { + + if( this->useBackgroundImage ) { + + this->features += currentFeatureValue; + + } + + } + + + return this->features; + + //featureIsEnabled( int featureValue ) + + + } + + set background( ... ) { + + va_list args; + + va_start( args, count ); + + int datatype = datatypes[0]; + + + printf("datatype: %i\n\n\n", datatype); + + if( datatype == -2 ) { + + char * message = va_arg( args, char * ); + + if( ( char ) message[0] == 35 ) { + + printf("Hex color\n\n\n"); + + message++; + + vector4 rgba = this->colorConverter( message ); + + this->backgroundColor = new vector3( rgba.x, rgba.y, rgba.z ); + + this->opacity = rgba.w / 256; + + this->useBackgroundImage = false; + + } else { + + this->backgroundImagePath = message; + + this->useBackgroundImage = true; + + printf("path\n\n\n"); + + } + + printf(" char *: %s\n\n\n ", message); + + } + + if( datatype > 0 ) { + + char * className = getClassName( datatype ); + + if( className == "vector3" ) { + + vector3 message = va_arg( args, vector3 ); + + this->backgroundColor = message; + + this->useBackgroundImage = false; + + } + + if( className == "vector4" ) { + + vector4 message = va_arg( args, vector4 ); + + this->backgroundColor = new vector3( message.x, message.y, message.z ); + + this->opacity = message.w; + + this->useBackgroundImage = false; + + } + + } + + + + //printf(" %f %f %f %f \n\n\n ", this->backgroundColor.x, this->backgroundColor.y, this->backgroundColor.z, this->opacity); + + + + + } + + click() { + + + this->backgroundColor = new vector3( 0, 256, 256 ); + + } + + mousedown() { + + //printf("executed click event\n\n"); + + this->backgroundColor = new vector3( 0, 256, 256 ); + + this->position = new vector3( 256, 256, 100 ); + + } + + mouseup() { + + //printf("executed click event\n\n"); + + this->backgroundColor = this->originalBackgroundColor; + + this->position = this->originalPosition; + + } + + mouseover() { + + this->backgroundColor = new vector3( 256, 256, 256 ); + + } + + mouseleave() { + + printf("mouse leave\n"); + + this->backgroundColor = this->originalBackgroundColor; + + } +} \ No newline at end of file diff --git a/application/source/engine/event.c b/application/source/engine/event.c new file mode 100644 index 0000000..a44755e --- /dev/null +++ b/application/source/engine/event.c @@ -0,0 +1,100 @@ + +#include "vector.h" + +#include "../vector2.h" + +#include "stdbool.h" + + +/* + + DOM Level 3 defines nine mouse events. + + event + + keyboard + + key : ArrowUp + + keyCode : 123 + + shiftKey : false + + ctrlKey : true + + altKey : false + + metaKey : false + + + screen + + position + + vector2 + + size + + vector2 + + + mouse + + position + + vector2 + + button: + 0 Left + + 1 middle + + 2 right + + + +*/ + + + +class mouse{ + + vector2 position; + + int button; + + vector * eventTypes = new vector(); + +} + +class screen{ + + vector2 size; + + vector2 position; + +} + +class keyboard{ + + int keyCode; + + bool shiftKey; + + bool ctrlKey; + + bool altKey; + + bool metaKey; + +} + +class event{ + + struct mouse * mouse = new mouse(); + + struct screen * screen = new screen(); + + struct keyboard * keyboard = new keyboard(); + +} \ No newline at end of file diff --git a/application/source/engine/eventManager.c b/application/source/engine/eventManager.c new file mode 100644 index 0000000..ce6593d --- /dev/null +++ b/application/source/engine/eventManager.c @@ -0,0 +1,290 @@ + +#include + +#include + +#define GL_GLEXT_PROTOTYPES + +#include + +#include // GL 1.1 functions + +#include + +#include + +#include + +#include + +#include + + +#include + + + +class eventManger{ + + Display * mainDisplay; + + Window mainWindow; + + Window RootWindow; + + event * lastEvent; + + clock_t lastMouseDownTime; + + constructor() { + + this->lastEvent = new event(); + + this->lastEvent->mouse->button = -1; + + + } + + event * fetchEvent() { + + event * currentEvent = new event(); + + + currentEvent->mouse->button = -1; + + Window qRoot; + + Window qChild; + + unsigned int qMask; + + int childX; + + int childY; + + int mouseX; + + int mouseY; + + int child; + + + XWindowAttributes window; + + if( XGetWindowAttributes( this->mainDisplay, this->mainWindow, &window ) ) { + + } + + + + if( XQueryPointer( this->mainDisplay, this->RootWindow, &qRoot, &qChild, &mouseX, &mouseY, &childX, &childY, &qMask ) ) + { + + mouseX -= window.x; + + mouseY -= window.y; + + for(int i = 0; i < sizeof(int) * 8; i++) + { + int mask = 1 << sizeof(int) * 8 - i - 1; + + if(mask & qMask) + { + //printf("1"); + } + else + { + //printf("0"); + } + + } + + //printf("(%d)\n", qMask); + + if( qMask == Button1MotionMask ) { + + //printf("LeftMouse\n"); + + currentEvent->mouse->button = 0; + + } + + + if( qMask == Button2MotionMask ) { + + printf("Button2MotionMask\n"); + + } + + + if( qMask == Button3MotionMask ) { + + printf("RightMouse\n"); + + } + + if( qMask == Button4MotionMask ) { + + printf("Button2MotionMask\n"); + + } + + + if( qMask == Button5MotionMask ) { + + printf("Button2MotionMask\n"); + + } + + if( qMask == ShiftMask ) { + + printf("Pressed shift\n"); + + } + + if( qMask == ControlMask ) { + + printf("Pressed control\n"); + + } + + + if( qMask == EnterWindowMask ) { + + //printf("EnterWindowMask\n"); + + } + + + + XEvent event; + + int keyboardEventCount = XPending( this->mainDisplay ); + + //printf("eventCount: %i\n\n", keyboardEventCount); + + while( XPending( this->mainDisplay ) ) { + + + XNextEvent( this->mainDisplay, &event ); + + switch ( event.type ) { + + case KeyPress: + + printf("key has been pressed. %i\n\n", event.xkey.keycode); + + break; + + + case KeyRelease: + + printf("key has been released. %i\n\n", event.xkey.keycode); + + break; + + + + + case Expose: + + break; + + + + default: + + //printf("event not defined: %i\n\n", event.type); + + //break; + + } + + //printf("event: %i\n\n", event.type); + + } + + //printf(" Mouse is at (%d,%d)\n", windowX, windowY ); + + //printf(" Mouse X: %d mouse Y: %d \n", mouseX, mouseY ); + + //XGrabKeyboard( this->mainDisplay, this->RootWindow, 0, GrabModeAsync, GrabModeAsync, CurrentTime); + + + //printf("qchild is at (%d,%d)\n", mouseX, mouseY); + + } + + bool hasBorder = true; + + int borderCorrection = 0; + + + + if( hasBorder ) { + + borderCorrection = 12; + + } + + + currentEvent->mouse->position = new vector2( mouseX, mouseY + borderCorrection ); + + currentEvent->screen->size = new vector2( window.width, window.height + borderCorrection ); + + //currentEvent->mouse->eventTypes = new vector(); + + vector * mouseEvents = currentEvent->mouse->eventTypes; + + mouseEvents = new vector(); + + if( this->lastEvent->mouse->position.x != currentEvent->mouse->position.x || + this->lastEvent->mouse->position.y != currentEvent->mouse->position.y ) { + + mouseEvents->add( "mousemove" ); + + } + + if( this->lastEvent->mouse->button != 0 && currentEvent->mouse->button == 0 ) { + + this->lastMouseDownTime = clock(); + + printf("Mouse down\n\n"); + + mouseEvents->add( "mousedown" ); + + } + + if( this->lastEvent->mouse->button == 0 && currentEvent->mouse->button != 0 ) { + + clock_t difference = clock() - this->lastMouseDownTime; + + int milliseconds = difference * 1000 / CLOCKS_PER_SEC; + + if( milliseconds < 150 ) { + + printf("click event\n\n"); + + + mouseEvents->add( "click" ); + + } + + printf("mouseup event\n\n"); + + mouseEvents->add( "mouseup" ); + //printf("%i\n\n", milliseconds); + + + } + + currentEvent->mouse->eventTypes = mouseEvents; + + + this->lastEvent = currentEvent; + + return currentEvent; + + } + +} \ No newline at end of file diff --git a/application/source/engine/floatArray.c b/application/source/engine/floatArray.c new file mode 100644 index 0000000..f017620 --- /dev/null +++ b/application/source/engine/floatArray.c @@ -0,0 +1,167 @@ + +#include + +#include + +#include + +#include + +#include + +class floatArray{ + + int capacity = 10; + + int total = 0; + + float * items = malloc( 10000000 ); + + int length() + { + + return this->total; + + } + + float get( int index ) + { + + if ( index >= 0 && index < this->total ){ + + return this->items[index]; + + } + + return NULL; + + } + + void set( int index, float item ) + { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + void resize( int capacity ) + { + + float * items = realloc( this->items, sizeof( float ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + void addVector2( struct vector2 * item ) { + + this->add( item->x ); + + this->add( item->y ); + + } + + void addVector3( struct vector3 * item ) { + + this->add( item->x ); + + this->add( item->y ); + + this->add( item->z ); + + } + + void add( float item ) + { + + if ( this->capacity == this->total ){ + + this->resize( this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + void delete( int index ) + { + if ( index < 0 || index >= this->total ){ + + return; + + } + + this->items[index] = NULL; + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + this->items[i + 1] = NULL; + + } + + this->total--; + + if ( this->total > 0 && this->total == this->capacity / 4 ){ + + this->resize( this->capacity / 2 ); + + } + + } + + int array_push( float item ) { + + this->add( item ); + + return this->total; + + } + + void unshift( float item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + this->resize( this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } + + float pop() { + + int length = this->total; + + int lastIndex = length - 1; + + float lastItem = this->get( lastIndex ); + + this->delete( lastIndex ); + + return lastItem; + + } + + +} \ No newline at end of file diff --git a/application/source/engine/fontRenderer.c b/application/source/engine/fontRenderer.c new file mode 100644 index 0000000..8a005ca --- /dev/null +++ b/application/source/engine/fontRenderer.c @@ -0,0 +1,176 @@ + +#include + +#include + +#include + +#include + +#include + +#define GL_GLEXT_PROTOTYPES + +#include + +#include // GL 1.1 functions + +#include + + +class fontRenderer{ + + GLubyte * data = malloc( 512 * 512 * 4 ); + + texture2D * loadFont( char character ) { + + FT_Library ft; + + if ( FT_Init_FreeType( &ft ) ) + { + + printf("ERROR::FREETYPE: Could not init FreeType Library"); + + //return -1; + + } else { + + // printf("FreeType Library loaded\n\n"); + + } + + + + FT_Face face; + + if ( FT_New_Face( ft, "assets/fonts/WorkSans/WorkSans-Regular.ttf", 0, &face ) ) + { + + printf("ERROR::FREETYPE: Failed to load font\n\n"); + + //return -1; + + } else { + + // printf("FREETYPE: font loaded\n\n"); + + } + + int fontSize = 118; + + if ( FT_Set_Pixel_Sizes( face, 0, fontSize ) ) { + + printf("ERROR::FREETYPE: Failed to set font size\n\n"); + + } else { + + //printf("FREETYPE: font size set\n\n"); + + } + + + + FT_Matrix matrix; + + FT_UInt glyph_index; + + FT_Vector pen; + + int n; + + FT_GlyphSlot slot = face->glyph; /* a small shortcut */ + + + pen.x = 0; + + pen.y = 0; + + if( FT_Load_Char( face, character, FT_LOAD_RENDER ) ) { + + printf("ERROR error loading char."); + + } else { + + //printf("FREETYPE: Char loaded %c \n", character ); + + } + + + //printf( "%c: bitmap_left: %i, bitmap_top: %i\n", ( char ) character, slot->bitmap_left, slot->bitmap_top ); + + + FT_Bitmap * bitmap = &slot->bitmap; + + texture2D * texture = new texture2D(); + + texture->width = bitmap->width; + + texture->height = bitmap->rows; + + texture->hasAlpha = 1; + + texture->offset = new vector2( ( float ) slot->bitmap_left, ( float ) slot->bitmap_top ); + + + //printf("x_max: %i\n", texture->width); + + //printf("y_max: %i\n", texture->height); + + + + + texture->data = bitmap->buffer;//bitmap->buffer; + + for (int x = 0; x < texture->width; ++x) + { + //printf("%u ", (unsigned int)bitmap->buffer[0]); + } + + //FT_Done_Face(face); + + //FT_Done_FreeType(ft); + + + + return texture; + + //this->show_image(); + + + } + + void draw_bitmap( FT_Bitmap * bitmap, FT_Int x, FT_Int y ) { + + FT_Int i, j, p, q; + + FT_Int x_max = x + bitmap->width; + FT_Int y_max = y + bitmap->rows; + + int WIDTH = 512; + + int HEIGHT = 512; + + printf("x_max: %i\n", x_max); + + printf("y_max: %i\n", y_max); + + + for ( i = x, p = 0; i < x_max; i++, p++ ) + { + for ( j = y, q = 0; j < y_max; j++, q++ ) + { + //if ( i < 0 || j < 0 || i >= WIDTH || j >= HEIGHT ) + //continue; + + //this->data[j + (i * 512)] |= bitmap->buffer[q * bitmap->width + p]; + + } + } + + } + + void show_image( void ) + { + } + +} \ No newline at end of file diff --git a/application/source/engine/hints.c b/application/source/engine/hints.c new file mode 100644 index 0000000..490939c --- /dev/null +++ b/application/source/engine/hints.c @@ -0,0 +1,11 @@ + + + +class Hints +{ + unsigned long flags; + unsigned long functions; + unsigned long decorations; + long inputMode; + unsigned long status; +} \ No newline at end of file diff --git a/application/source/engine/member.c b/application/source/engine/member.c new file mode 100644 index 0000000..b919762 --- /dev/null +++ b/application/source/engine/member.c @@ -0,0 +1,28 @@ + +#define GL_GLEXT_PROTOTYPES + +#include + +#include // GL 1.1 functions + +#include + + + +class member{ + + char * name; + + GLint index; + + GLint offset; + + GLint size; + + GLenum type; + + GLuint arrayStride; + + GLuint topLevelSize; + +} diff --git a/application/source/engine/mesh.c b/application/source/engine/mesh.c new file mode 100644 index 0000000..3f7c8c8 --- /dev/null +++ b/application/source/engine/mesh.c @@ -0,0 +1,703 @@ + + +#define GL_GLEXT_PROTOTYPES + +#include + +#include // GL 1.1 functions + +#include + +#include "block.h" + +#include "shader.h" + +#include "program.h" + +#include "floatArray.h" + +#include "unsignedIntegerArray.h" + + + +class mesh{ + + struct program * program; + + struct unsignedIntegerArray * indices; + + + struct floatArray * textureCoordinates; + + struct floatArray * vertexCoordinates; + + struct floatArray * normalCoordinates; + + + struct array * blocks = new array(); + + + GLuint vertexArrayObject; + + + GLuint uniformBuffer; + + GLuint indexBuffer; + + GLuint vertexbuffer; + + GLuint textureCoordinateBuffer; + + GLuint meshIndexBuffer; + + GLuint uvBuffer; + + struct unsignedIntegerArray * uniformBuffers = new unsignedIntegerArray(); + + + + struct block * getUniformBlock( char * blockName ) { + + int blockCount = this->blocks->length(); + + for ( int i = 0; i < blockCount; ++i ) + { + struct block * currentBlock = this->blocks->get( i ); + + char * currentBlockName = currentBlock->name; + + if( currentBlockName == blockName ) { + + return currentBlock; + + } + + } + + return NULL; + + } + + + + void bindBlock( struct block * blockInstance ) { + + //printf("%s\n", blockInstance); + + blockInstance->createBuffer(); + + this->blocks->add( blockInstance ); + + } + + void setProgram( struct program * currentProgram ) { + + this->program = currentProgram; + + } + + GLuint getGLTypeSize( GLuint type ) { + + switch( type ) { + + case GL_FLOAT: + + return sizeof( GLfloat ); + + break; + + case GL_INT: + + return sizeof( GLint ); + + break; + + + case GL_UNSIGNED_INT: + + return sizeof( GLuint ); + + break; + } + + return 0; + + } + + GLuint getComponentType( GLuint type ) { + + + switch( type ) { + + case GL_FLOAT: + + return GL_FLOAT; + + break; + + case GL_FLOAT_VEC2: + + return GL_FLOAT; + + break; + + case GL_FLOAT_VEC3: + + return GL_FLOAT; + + break; + + case GL_FLOAT_VEC4: + + return GL_FLOAT; + + break; + + + case GL_INT: + + return GL_INT; + + break; + + case GL_INT_VEC2: + + return GL_INT; + + break; + + case GL_INT_VEC3: + + return GL_INT; + + break; + + case GL_INT_VEC4: + + return GL_INT; + + break; + + + case GL_UNSIGNED_INT: + + return GL_UNSIGNED_INT; + + break; + + case GL_UNSIGNED_INT_VEC2: + + return GL_UNSIGNED_INT; + + break; + + case GL_UNSIGNED_INT_VEC3: + + return GL_UNSIGNED_INT; + + break; + + case GL_UNSIGNED_INT_VEC4: + + return GL_UNSIGNED_INT; + + break; + + } + + + return 0; + + } + + GLuint getItemSize( GLuint type ) { + + switch( type ) { + + case GL_FLOAT: + + return 1; + + break; + + case GL_FLOAT_VEC2: + + return 2; + + break; + + case GL_FLOAT_VEC3: + + return 3; + + break; + + case GL_FLOAT_VEC4: + + return 4; + + break; + + + case GL_INT: + + return 1; + + break; + + case GL_INT_VEC2: + + return 2; + + break; + + case GL_INT_VEC3: + + return 3; + + break; + + case GL_INT_VEC4: + + return 4; + + break; + + + case GL_UNSIGNED_INT: + + return 1; + + break; + + case GL_UNSIGNED_INT_VEC2: + + return 2; + + break; + + case GL_UNSIGNED_INT_VEC3: + + return 3; + + break; + + case GL_UNSIGNED_INT_VEC4: + + return 4; + + break; + + } + + return 0; + + } + + GLuint createBuffer( char * attributeName, void * data, GLenum target, GLenum usage ) { + + GLuint itemSize; + + GLuint componentType; + + GLuint componentSize; + + GLuint attributeLocation; + + //GLenum target; + + GLuint isIndexBuffer = 0; + + GLuint buffer; + + glGenBuffers( 1, &buffer ); + + + if( attributeName == "index" ) { + + isIndexBuffer = 1; + + componentType = GL_INT; + + componentSize = this->getGLTypeSize( componentType ); + + target = GL_ELEMENT_ARRAY_BUFFER; + + glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, buffer ); + + } else { + + attribute * attribute = this->program->getAttributeByName( attributeName ); + + if( attribute == NULL ) { + + return 0; + + } + + itemSize = this->getItemSize( attribute->type ); + + componentType = this->getComponentType( attribute->type ); + + componentSize = this->getGLTypeSize( componentType ); + + attributeLocation = attribute->location; + + target = GL_ARRAY_BUFFER; + + glEnableVertexAttribArray( attribute->location ); + + glBindBuffer( GL_ARRAY_BUFFER, buffer ); + + } + + //printf("Name: %s itemSize: %i componentSize: %i ", attributeName, itemSize, componentSize); + + + int itemCount; + + GLuint bufferSize; + + + if( componentType == GL_UNSIGNED_INT || componentType == GL_INT ) { + + unsignedIntegerArray * test = ( unsignedIntegerArray * ) data; + + itemCount = test->length(); + + bufferSize = itemCount * componentSize; + + glBufferData( target, bufferSize, test->items, usage ); + + if( isIndexBuffer == NULL ) { + + glVertexAttribIPointer( attributeLocation, itemSize, componentType, 0, ( void * ) 0 ); + + } + + } else if( componentType == GL_FLOAT ) { + + floatArray * test = ( floatArray * ) data; + + itemCount = test->total; + + bufferSize = itemCount * componentSize; + + glBufferData( GL_ARRAY_BUFFER, bufferSize, test->items, usage ); + + if( isIndexBuffer == NULL ) { + + glVertexAttribPointer( attributeLocation, itemSize, componentType, GL_FALSE, 0, ( void * ) 0 ); + + } + } + + //printf("itemCount: %i\n\n", bufferSize); + + GLint compareSize = 0; + + glGetBufferParameteriv( target, GL_BUFFER_SIZE, &compareSize ); + + if( bufferSize != compareSize ) + { + + glDeleteBuffers(1, &buffer); + + printf("ERROR: size error"); + + return 0; + + } + + return buffer; + + } + + + void createBuffers( ) { + + struct unsignedIntegerArray * indices = new unsignedIntegerArray(); + + struct floatArray * textureCoordinates = new floatArray(); + + struct floatArray * vertexCoordinates = new floatArray(); + + struct floatArray * normalCoordinates = new floatArray(); + + struct unsignedIntegerArray * meshIndices = new unsignedIntegerArray(); + + int subdivisionsDepth = 1; + + int subdivisionsWidth = 1; + + float width = 2; + + float depth = 2; + + + int meshCount = 100 * 50; + + int meshStartIndex = 0; + + for (int meshIndex = 0; meshIndex < meshCount; ++meshIndex) + { + + + meshStartIndex = meshIndices->length(); + + //printf("Number of vectex cnumVertsAcrossoordinates: %i\n\n", vertexCoordinates->length()); + + int numVertsAcross = subdivisionsWidth + 1; + + for ( int z = 0; z < subdivisionsDepth; z++ ) { + + for ( int x = 0; x < subdivisionsWidth; x++ ) { + + // triangle 1 of quad + indices->add( ( z + 0 ) * numVertsAcross + x + meshStartIndex ); + + indices->add( ( z + 1 ) * numVertsAcross + x + meshStartIndex ); + + indices->add( ( z + 0 ) * numVertsAcross + x + 1 + meshStartIndex ); + + // triangle 2 of quad + indices->add( ( z + 1 ) * numVertsAcross + x + meshStartIndex ); + + indices->add( ( z + 1 ) * numVertsAcross + x + 1 + meshStartIndex ); + + indices->add( ( z + 0 ) * numVertsAcross + x + 1 + meshStartIndex ); + + } + + } + + + for ( int z = 0; z <= subdivisionsDepth; z++ ) { + + for ( int x = 0; x <= subdivisionsWidth; x++ ) { + + + float u = ( float ) x;// / subdivisionsWidth; + + float v = ( float ) z;// / subdivisionsDepth; + + + textureCoordinates->add( u ); + + textureCoordinates->add( ( 1 - v ) ); + + + vertexCoordinates->add( width * u - width * 0.5 ); + + vertexCoordinates->add( depth * v - depth * 0.5 ); + + vertexCoordinates->add( 0 ); + + + normalCoordinates->add( 0 ); + + normalCoordinates->add( 0 ); + + normalCoordinates->add( 1 ); + + + meshIndices->add( meshIndex ); + + + } + + } + + + } + + glGenVertexArrays( 1, &this->vertexArrayObject ); + + glBindVertexArray( this->vertexArrayObject ); + + + this->vertexbuffer = this->createBuffer( "position", vertexCoordinates, GL_ARRAY_BUFFER, GL_STATIC_DRAW ); + + this->textureCoordinateBuffer = this->createBuffer( "textureCoordinates", textureCoordinates, GL_ARRAY_BUFFER, GL_STATIC_DRAW ); + + this->vertexbuffer = this->createBuffer( "meshIndex", meshIndices, GL_ARRAY_BUFFER, GL_STATIC_DRAW ); + + this->indexBuffer = this->createBuffer( "index", indices, GL_ARRAY_BUFFER, GL_STATIC_DRAW ); + + //this->subMeshPositions = this->createBuffer( "subMeshPositions", indices, GL_SHADER_STORAGE_BUFFER, GL_STATIC_DRAW ); + + int blockCount = this->blocks->length(); + + for (int i = 0; i < blockCount; ++i) + { + + block * currentBlock = this->blocks->get( i ); + + int size = currentBlock->bufferSize; + + printf("Bind block %s bufferSize: %i bindingPoint: %i bufferType: %s \n\n", currentBlock->name, currentBlock->bufferSize, currentBlock->bindingPoint, currentBlock->getBufferTypeText( ) ); + + + + glBindBuffer( currentBlock->bufferType, currentBlock->buffer ); + + glBindBufferBase( currentBlock->bufferType, currentBlock->bindingPoint, currentBlock->buffer ); + + glBufferData( currentBlock->bufferType, currentBlock->bufferSize, 0, GL_DYNAMIC_DRAW ); + + } + + + glBindVertexArray( 0 ); + + + + +/* + + unsigned int uniformBufferSize = 152; // allocate 152 bytes of memory + + glGenBuffers( 1, &this->uniformBuffer ); + + glBindBuffer( GL_UNIFORM_BUFFER, this->uniformBuffer ); + + glBufferData( GL_UNIFORM_BUFFER, uniformBufferSize, NULL, GL_DYNAMIC_DRAW ); + + + + + + + glBindBuffer( GL_UNIFORM_BUFFER, this->uniformBuffer ); + + //glBufferData( this->uniformBuffer, size, data ); + + glBufferSubData( this->uniformBuffer, offset, size, data ); +*/ + + //glBindBufferRange( GL_UNIFORM_BUFFER, 0, uboMatrices, 0, 2 * sizeof(glm::mat4) ); + + +/* +glm::mat4 projection = glm::perspective(glm::radians(45.0f), (float)width/(float)height, 0.1f, 100.0f); +glBindBuffer(GL_UNIFORM_BUFFER, uboMatrices); +glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), glm::value_ptr(projection)); +glBindBuffer(GL_UNIFORM_BUFFER, 0); + + +glm::mat4 view = camera.GetViewMatrix(); +glBindBuffer(GL_UNIFORM_BUFFER, uboMatrices); +glBufferSubData(GL_UNIFORM_BUFFER, sizeof(glm::mat4), sizeof(glm::mat4), glm::value_ptr(view)); +glBindBuffer(GL_UNIFORM_BUFFER, 0); */ + + + + + + //glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, 0, indexBufferSize, indices->items ); + + +/* + int vertexCount = vertexCoordinates->length(); + + for (int i = 0; i < vertexCount; ++i) + { + + float currentVertex = vertexCoordinates->get( i ); + + printf(" %i: %f \n", i, currentVertex); + + } + + int indexCount = indices->length(); + + printf("\n\n"); + + for (int i = 0; i < indexCount; ++i) + { + + int currentIndex = indices->get( i ); + + printf(" %i: %i \n", i, currentIndex); + + } + + printf("number of indices: %i\n", indices->length()); +*/ + + this->indices = indices; + + this->textureCoordinates = textureCoordinates; + + this->vertexCoordinates = vertexCoordinates; + + this->normalCoordinates = normalCoordinates; + + } + + createOrderedTriangleStripQuad() { + + +/* + vector3 * a = new vector3(0.0, 0.0, 0.0); + + vector3 * b = new vector3(0.0, 0.5, 0.0); + + vector3 * c = new vector3(0.5, 0.0, 0.0); + + vector3 * d = new vector3(0.5, 0.5, 0.0); + + GLfloat g_vertex_buffer_data[ 12 * 2 ]; + + for (int i = 0; i < 2; ++i) + { + + int vectorIndex = i * 3; + + float index = 0.5 *i; + + g_vertex_buffer_data[ vectorIndex + 0 ] = 0.0 - index; + + g_vertex_buffer_data[ vectorIndex + 1 ] = 0.; + + g_vertex_buffer_data[ vectorIndex + 2 ] = 0.0; + + + g_vertex_buffer_data[ vectorIndex + 3 ] = 0.0 - index; + + g_vertex_buffer_data[ vectorIndex + 4 ] = 0.5; + + g_vertex_buffer_data[ vectorIndex + 5 ] = 0.0; + + + g_vertex_buffer_data[ vectorIndex + 6 ] = 0.5 - index; + + g_vertex_buffer_data[ vectorIndex + 7 ] = 0.0; + + g_vertex_buffer_data[ vectorIndex + 8 ] = 0.0; + + + g_vertex_buffer_data[ vectorIndex + 9 ] = 0.5 - index; + + g_vertex_buffer_data[ vectorIndex + 10 ] = 0.5; + + g_vertex_buffer_data[ vectorIndex + 11 ] = 0.0; + + + } + + + GLfloat g_vertex_buffer_data[] = { + 0.0, 0.0, 0.0f, + 0.0, 0.5, 0.0f, + 0.5f, 0.0f, 0.0f, + .5, 0.5, 0.0 + + }; +*/ + + } + + + +} \ No newline at end of file diff --git a/application/source/engine/opengl.c b/application/source/engine/opengl.c new file mode 100644 index 0000000..bc8068e --- /dev/null +++ b/application/source/engine/opengl.c @@ -0,0 +1,338 @@ + +#include "./mesh.h" + +#include "./shader.h" + +#include "./sampler2D.h" + +#include "./texture2D.h" + +#include "./floatArray.h" + +#include "./unsignedIntegerArray.h" + +#include "./eventManager.h" + +#include "./pipeline.h" + + +#include "./renderPasses/renderPassQuads.h" + +#include "./renderPasses/renderPassFont.h" + +#include "./renderPasses/renderPassCompute.h" + +#include "./renderPasses/renderPassCompute2.h" + +#include "./renderPasses/renderPassTesselation.h" + + + +#include "./resourceManager.h" + +#include "./windowManager.h" + +#include "./event.h" + + +#include + +#include + +#include + +#include + +#include + +#define GL_GLEXT_PROTOTYPES + +#include + +#include // GL 1.1 functions + +#include + + +#include + +#include + + + + +event * globalEvent; + +resourceManager * resources; + + + +class opengl{ + + Display * mainDisplay; + + Window mainWindow; + + int MainScreen; + + Window RootWindow; + + + int lastTime = clock(); + + struct timespec startTime; + + int frameCount = 0; + + + + sampler2D * testSampler; + + struct windowManager * windowManager = new windowManager(); + + + + struct eventManger * eventManger = new eventManger(); + + struct pipeline * pipeline = new pipeline(); + + + + + initialize() { + + printf("initialize opengl.\n"); + + resources = new resourceManager(); + + this->setupWindow(); + + this->setupManagers(); + + this->showVersion(); + + //this->createTexture(); + + this->setupPipeline(); + + //this->loadFont(); + + this->setupTime(); + + this->setupRenderLoop(); + + } + + showExtensions() { + + GLint max_layers; + + glGetIntegerv ( GL_MAX_ARRAY_TEXTURE_LAYERS, &max_layers ); + + printf("GL_MAX_ARRAY_TEXTURE_LAYERS: %i\n", max_layers); + + + GLint max_texture_size; + + glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_texture_size); + + printf("GL_MAX_TEXTURE_SIZE: %i\n", max_texture_size); + + + } + + showVersion() { + + printf("opengl version : %s\n\n", glGetString(GL_VERSION) ); + + } + + setupTime() { + + clock_gettime( CLOCK_REALTIME, &this->startTime ); + + } + + setupManagers() { + + this->eventManger->mainDisplay = this->mainDisplay; + + this->eventManger->mainWindow = this->mainWindow; + + this->eventManger->RootWindow = this->RootWindow; + + } + + setupWindow() { + + this->windowManager->setupDisplay(); + + this->windowManager->setupWindow(); + + + this->mainDisplay = this->windowManager->mainDisplay; + + this->mainWindow = this->windowManager->mainWindow; + + this->RootWindow = this->windowManager->RootWindow; + + } + + setupRenderLoop() { + + int IsProgramRunning = 1; + + while( IsProgramRunning ) { + + while( XPending( this->mainDisplay ) ) { + + XEvent GeneralEvent = {}; + + XNextEvent( this->mainDisplay, &GeneralEvent ); + + switch( GeneralEvent.type ) { + + case ClientMessage: + + + IsProgramRunning = 0; + + break; + } + + } + + this->render(); + + } + + } + + setupPipeline() { + + quads * quadsPass = new quads(); + + font * fontPass = new font(); + + compute * computePass = new compute(); + + compute2 * computePass2 = new compute2(); + + tesselation * tesselationPass = new tesselation(); + + + //this->pipeline->addRenderPass( fontPass ); + + this->pipeline->addRenderPass( quadsPass ); + + //this->pipeline->addRenderPass( computePass ); + + //this->pipeline->addRenderPass( computePass2 ); + + //this->pipeline->addRenderPass( tesselationPass ); + + + } + + double clockToMilliseconds( clock_t ticks ){ + + return ( ticks / ( double ) CLOCKS_PER_SEC ); + + } + + render() { + + //this->clearColor( 0.0, 0.0, 0.0, 0.0 ); + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + this->clear( GL_DEPTH_BUFFER_BIT ); + + globalEvent = this->eventManger->fetchEvent(); + + this->pipeline->render(); + + this->swapBuffers(); + + //this->displayFPS(); + + } + + displayFPS() { + + struct timespec now; + + clock_gettime( CLOCK_REALTIME, &now ); + + this->frameCount++; + + int elapsedTime = now.tv_sec - this->startTime.tv_sec; + + if( elapsedTime != this->lastTime ) { + + printf("%i fps.\n\n", this->frameCount ); + + this->lastTime = elapsedTime; + + this->frameCount = 0; + + } + + } + + clear( GLbitfield mask ) { + + glClear( mask ); + + } + + clearColor( float r, float g, float b, float a ) { + + glClearColor( r, g, b, a ); + + } + + swapBuffers() { + + PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT; + + PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA; + + PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI; + + + glXSwapIntervalEXT = ( PFNGLXSWAPINTERVALEXTPROC ) glXGetProcAddress( ( const GLubyte * ) "glXSwapIntervalEXT" ); + + if ( glXSwapIntervalEXT != NULL ) { + + glXSwapIntervalEXT( this->mainDisplay, this->mainWindow, 0 ); + + } else { + + glXSwapIntervalMESA = ( PFNGLXSWAPINTERVALMESAPROC ) glXGetProcAddress( ( const GLubyte * ) "glXSwapIntervalMESA" ); + + if ( glXSwapIntervalMESA != NULL ) { + + glXSwapIntervalMESA( 0 ); + + } else { + + glXSwapIntervalSGI = ( PFNGLXSWAPINTERVALSGIPROC ) glXGetProcAddress( ( const GLubyte * ) "glXSwapIntervalSGI" ); + + if ( glXSwapIntervalSGI != NULL ) { + + glXSwapIntervalSGI( 0 ); + + } + } + } + + glXSwapBuffers( this->mainDisplay, this->mainWindow ); + + } + +} + + + + diff --git a/application/source/engine/pipeline.c b/application/source/engine/pipeline.c new file mode 100644 index 0000000..7628039 --- /dev/null +++ b/application/source/engine/pipeline.c @@ -0,0 +1,82 @@ + +#include "../int.h" + +#include "../array.h" + +#include "./renderPasses/renderPass.h" + +#include "./vector.h" + +#include "../classConfiguration.h" + + + +reflect +class pipeline{ + + array * renderPasses = new array(); + + vector * classIndices = new vector(); + + vector * methodIndices = new vector(); + + addRenderPass( ... ) { + + va_list args; + + va_start( args, count ); + + int classIndex = datatypes[0]; + + this->classIndices->add( classIndex ); + + + + void * voidPointer = va_arg( args, void * ); + + int methodIndex = getMethodIndexByPropertyName( classIndex, "prepare" ); + + int renderMethodIndex = getMethodIndexByPropertyName( classIndex, "render" ); + + + this->methodIndices->add( renderMethodIndex ); + + + + int classIndexTest = this->classIndices->get( 0 ); + + //printf("\n\n\n\n%i\n\n\n\n", classIndexTest); + + callMethodOfClass( classIndex, methodIndex, voidPointer ); + + printf("\n"); + + va_end( args ); + + + this->renderPasses->add( voidPointer ); + + } + + render() { + + array * renderPasses = this->renderPasses; + + int renderPassCount = renderPasses->length(); + + for (int i = 0; i < renderPassCount; ++i) + { + + int classIndex = this->classIndices->get( i ); + + void * voidPointer = renderPasses->get( i ); + + int methodIndex = this->methodIndices->get( i ); + + callMethodOfClass( classIndex, methodIndex, voidPointer ); + + } + + } + +} diff --git a/application/source/engine/program.c b/application/source/engine/program.c new file mode 100644 index 0000000..377f522 --- /dev/null +++ b/application/source/engine/program.c @@ -0,0 +1,534 @@ + +#include "block.h" + +#include "member.h" + +#include "uniform.h" + + +#define GL_GLEXT_PROTOTYPES + +#include + +#include // GL 1.1 functions + +#include + +#include + +#include "fileSystem.h" + +#include "../array.h" + +#include "../char.h" + +#include "sampler2D.h" + +#include "shader.h" + +class program{ + + + GLuint samplerIndex = 0; + + array * uniforms = new array(); + + array * attributes = new array(); + + array * blocks = new array(); + + array * shaders = new array(); + + GLuint glProgram; + + + + addShader( struct shader * shaderInstance ) { + + this->shaders->add( shaderInstance ); + + } + + + GLint glGetProgramResourceiv( GLint programProperty, GLint index, GLint Property ) { + + GLint offsetValues; + + glGetProgramResourceiv( this->glProgram, programProperty, index, 1, &Property , 1, 0, &offsetValues ); + + return offsetValues; + + } + + GLchar * glGetProgramResourceName( GLint programProperty, GLint index, GLint nameLength ) { + + + GLchar name[ GL_NAME_LENGTH + 1 ]; + + glGetProgramResourceName( + this->glProgram, + + programProperty, + index, + GL_NAME_LENGTH + 1, + 0, + name ); + + + return name; + + } + + + void extractBlocks() { + + GLint programInterfaces[2] = { GL_SHADER_STORAGE_BLOCK, GL_UNIFORM_BLOCK }; // GL_UNIFORM_BLOCK + + GLint programProperties[2] = { GL_BUFFER_VARIABLE, GL_UNIFORM }; // GL_UNIFORM , GL_PROGRAM_INPUT + + GLenum programBufferTypes[2] = { GL_SHADER_STORAGE_BUFFER, GL_UNIFORM_BUFFER }; + + + + for (int blockTypeIndex = 0; blockTypeIndex < 2; ++blockTypeIndex) + { + + + GLint program = this->glProgram; + + GLint numActiveResources; + + GLint programInterface = programInterfaces[blockTypeIndex]; // GL_UNIFORM_BLOCK + + GLint programProperty = programProperties[blockTypeIndex]; // GL_UNIFORM + + GLenum programBufferType = programBufferTypes[blockTypeIndex]; + + glGetProgramInterfaceiv( program, programInterface, GL_ACTIVE_RESOURCES, &numActiveResources ); + + //printf("extractShaderStorageBuffers %i\n\n", numActiveResources); + + for ( GLuint blockIndex = 0; blockIndex < numActiveResources; blockIndex++ ) { + + struct block * blockInstance = new block(); + + //GLint blockIndex = this->glGetProgramResourceiv( programInterface, blockIndex, GL_BLOCK_INDEX ); + + GLint blockNameLength = this->glGetProgramResourceiv( programInterface, blockIndex, GL_NAME_LENGTH ); + + blockInstance->bufferSize = this->glGetProgramResourceiv( programInterface, blockIndex, GL_BUFFER_DATA_SIZE ); + + GLint numberActiveVariables = this->glGetProgramResourceiv( programInterface, blockIndex, GL_NUM_ACTIVE_VARIABLES ); + + blockInstance->bindingPoint = this->glGetProgramResourceiv( programInterface, blockIndex, GL_BUFFER_BINDING ); + + //const GLchar * name = this->glGetProgramResourceName( programInterface, blockIndex, blockNameLength ); + GLchar name[ GL_NAME_LENGTH + 1 ]; + + glGetProgramResourceName( this->glProgram, programInterface, blockIndex, GL_NAME_LENGTH + 1, NULL, name ); + + blockInstance->name = malloc( GL_NAME_LENGTH ); + + strcpy( blockInstance->name, name ); + + + blockInstance->bufferType = programBufferType; + + printf("block:%s \n\n", blockInstance->name ); + + printf(" block name %s\n", blockInstance->name); + + printf(" block buffer size: %i\n", blockInstance->bufferSize); + + printf(" block binding point: %i\n\n", blockInstance->bindingPoint); + + + + + GLint indices[ numberActiveVariables ]; + + GLenum member = GL_ACTIVE_VARIABLES; + + glGetProgramResourceiv( program, programInterface, blockIndex, 1, &member, numberActiveVariables, 0, indices ); + + printf(" number of variables: %i\n\n\n", numberActiveVariables); + + // add block + + + for ( GLuint index = 0; index < numberActiveVariables; index++ ) + { + + struct member * memberInstance = new member(); + + + GLint itemIndex = indices[ index ]; + + memberInstance->index = itemIndex; + + GLint nameLength = this->glGetProgramResourceiv( programProperty, itemIndex, GL_NAME_LENGTH ); + + memberInstance->offset = this->glGetProgramResourceiv( programProperty, itemIndex, GL_OFFSET ); + + memberInstance->type = this->glGetProgramResourceiv( programProperty, itemIndex, GL_TYPE ); + + memberInstance->arrayStride = this->glGetProgramResourceiv( programProperty, itemIndex, GL_ARRAY_STRIDE ); + + + memberInstance->size = this->glGetProgramResourceiv( programProperty, itemIndex, GL_ARRAY_SIZE ); + + int topLevelSize = this->glGetProgramResourceiv( programProperty, itemIndex, GL_TOP_LEVEL_ARRAY_SIZE ); + + int topLevelStride = this->glGetProgramResourceiv( programProperty, itemIndex, GL_TOP_LEVEL_ARRAY_STRIDE ); + + + if( memberInstance->arrayStride == 0 ) { + + memberInstance->arrayStride = topLevelStride; + + } + + memberInstance->topLevelSize = topLevelSize; + + + // memberInstance->name = this->glGetProgramResourceName( programProperty, itemIndex, nameLength ); + + + GLchar memberName[ GL_NAME_LENGTH + 1 ]; + + glGetProgramResourceName( this->glProgram, programProperty, itemIndex, GL_NAME_LENGTH + 1, NULL, memberName ); + + memberInstance->name = malloc( GL_NAME_LENGTH ); + + strcpy( memberInstance->name, memberName ); + + + + printf(" offset: #%i name: %s vec2: %i offset: %i itemSize / arrayStride: %i Array size: %i toplevel size: %i top level size: %i \n\n", + + memberInstance->index, + memberInstance->name, + memberInstance->type == GL_FLOAT_VEC2, + memberInstance->offset, + memberInstance->arrayStride, + memberInstance->size, topLevelSize, + topLevelStride ); + + + + blockInstance->add( memberInstance ); + + } + + blockInstance->createBuffer(); + + this->blocks->add( blockInstance ); + + } + + } + + + } + + struct block * createNewBlock( char * blockName ) { + + printf("Copy buffer: %s\n\n", blockName); + + block * originalBlock = this->getBlock( blockName ); + + block * blockCopy = new block(); + + blockCopy->members = originalBlock->members; + + blockCopy->bindingPoint = originalBlock->bindingPoint; + + blockCopy->index = originalBlock->index; + + blockCopy->bufferSize = originalBlock->bufferSize; + + blockCopy->createBuffer(); + + return blockCopy; + + } + + struct block * getBlock( char * blockName ) { + + int blockCount = this->blocks->length(); + + for ( int i = 0; i < blockCount; ++i ) + { + block * currentBlock = this->blocks->get( i ); + + char * currentBlockName = currentBlock->name; + + if( currentBlockName == blockName ) { + + return currentBlock; + + } + + } + + return NULL; + + } + + create() { + + this->glProgram = glCreateProgram(); + + + array * shaders = this->shaders; + + int shaderCount = shaders->length(); + + + for (int i = 0; i < shaderCount; ++i) + { + + shader * currentShader = shaders->get( i ); + + glAttachShader( this->glProgram, currentShader->glShader ); + + } + + glLinkProgram( this->glProgram ); + + glUseProgram( this->glProgram ); + + + this->extractBlocks(); + + this->extractAttributes(); + + this->extractUniforms(); + + } + + bindBlock( char * blockName ) { + + block * currentBlock = this->getBlock( blockName ); + + glBindBufferBase( currentBlock->bufferType, currentBlock->bindingPoint, currentBlock->buffer ); + + } + + use() { + + glUseProgram( this->glProgram ); + + } + + + extractUniforms() { + + int attributeCount = 0; + + GLsizei bufSize = 64; + + GLsizei length; // name length + + GLint size; + + GLenum type; // type of the variable (float, vec3 or mat4, etc) + + int uniformCount = 0; + + glGetProgramiv( this->glProgram, GL_ACTIVE_UNIFORMS, &uniformCount ); + + for (int i = 0; i < uniformCount; i++) + { + + struct uniform * uniformInstance = new uniform(); + + GLenum type; + + GLchar name[bufSize]; + + glGetActiveUniform( this->glProgram, ( GLuint ) i, bufSize, &length, &size, &type, uniformInstance->name ); + + //printf( " Uniform #%d Type: %u Name: %s\n", i, type, uniformInstance->name ); + + GLint uniformLocation = glGetUniformLocation( this->glProgram, uniformInstance->name ); + + uniformInstance->location = uniformLocation; + + uniformInstance->type = type; + + this->uniforms->add( uniformInstance ); + + } + + } + + extractAttributes() { + + int attributeCount = 0; + + GLsizei bufSize = 64; + + GLsizei length; // name length + + GLint size; + + GLenum type; // type of the variable (float, vec3 or mat4, etc) + + glGetProgramiv( this->glProgram, GL_ACTIVE_ATTRIBUTES, &attributeCount ); + + for (int i = 0; i < attributeCount; i++) + { + GLenum type; + + attribute * attributeInstance = new attribute(); + + glGetActiveAttrib( this->glProgram, ( GLuint ) i, bufSize, &length, &size, &type, attributeInstance->name); + + //printf(" Attribute #%d Type: %u Name: %s size: %i\n", i, type, attributeInstance->name, size); + + GLint attributeLocation = glGetAttribLocation( this->glProgram, attributeInstance->name ); + + glEnableVertexAttribArray( attributeLocation ); + + + attributeInstance->location = attributeLocation; + + //attributeInstance.name = name; + + attributeInstance->type = type; + + this->attributes->add( attributeInstance ); + + + } + + } + + struct attribute * getAttributeByName( char * attributeName ) { + + int attributeCount = this->attributes->length(); + + //printf("uniformCount: %i\n\n", attributeCount); + + for ( int i = 0; i < attributeCount; ++i ) + { + struct attribute * currentAttribute = this->attributes->get( i ); + + char * currentAttributeName = currentAttribute->name; + + //printf("attributeName->name: %s %s\n\n", currentAttributeName, attributeName ); + + if( currentAttributeName == attributeName ) { + + return currentAttribute; + + } + + } + + return NULL; + + } + + void setUniform( char * name, void * value ) { + + int uniformCount = this->uniforms->length(); + + // printf("uniformCount: %i\n\n", uniformCount); + + for (int i = 0; i < uniformCount; ++i) + { + uniform * currentUniform = this->uniforms->get( i ); + + char * uniformName = (char *)currentUniform->name; + + // printf("currentUniform->name: %s\n\n", uniformName); + + if( uniformName == name ) { + + //printf("\n\n Update this uniform %s\n\n", name); + + switch( currentUniform->type ) { + + + case GL_FLOAT_VEC2: + + vector2 * vector2Value = ( vector2 * ) value; + + //printf("\n\n this is an float vec2 %f %f \n\n", vector2Value->x, vector2Value->y ); + + glUniform2f( currentUniform->location, vector2Value->x, vector2Value->y ); + + break; + + case GL_FLOAT_VEC3: + + vector3 * vector3Value = ( vector3 * ) value; + + //printf("\n\n this is an float vec3 %f %f %f \n\n", vector3Value->x, vector3Value->y, vector3Value->z); + + glUniform3f( currentUniform->location, vector3Value->x, vector3Value->y, vector3Value->z ); + + break; + + case GL_SAMPLER_2D: + + this->updateSampler2D( currentUniform, value ); + + break; + + + case GL_SAMPLER_2D_ARRAY: + + this->updateSampler2D( currentUniform, value ); + + break; + + + + + } + + } + + + } + + + } + + updateSampler2D( uniform * currentUniform, void * value ) { + + glEnable( GL_BLEND ); + + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + + sampler2D * sampler = ( sampler2D * ) value; + + + if( !sampler->binded ) { + + sampler->index = this->samplerIndex++; + + sampler->bind(); + + //printf("sampler->index: %i \n", sampler->index); + + } + + + + glActiveTexture( GL_TEXTURE0 + sampler->index ); + + glBindTexture( sampler->target, sampler->glTexture ); + + //glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,GL_UNSIGNED_BYTE, texture ); + + glUniform1i( currentUniform->location, sampler->index ); + + + } + + +} diff --git a/application/source/engine/quadMesh.c b/application/source/engine/quadMesh.c new file mode 100644 index 0000000..630bc87 --- /dev/null +++ b/application/source/engine/quadMesh.c @@ -0,0 +1,40 @@ + +#include "vector2.h" + +#include "vector3.h" + +#include "vector.h" + + + +class quadMesh { + + vector2 position; + + vector2 size; + + vector3 color; + + float zIndex; + + float opacity; + + int textureIndex; + + int features; + + int elementIndex; + + + + + // ------------ + + //float PADDING; + + // ----------- + + //struct vector * characters; + + +} \ No newline at end of file diff --git a/application/source/engine/renderPasses/renderPass.c b/application/source/engine/renderPasses/renderPass.c new file mode 100644 index 0000000..5a7613f --- /dev/null +++ b/application/source/engine/renderPasses/renderPass.c @@ -0,0 +1,27 @@ + +#include "shader.h" + +#include "mesh.h" + + +class renderPass{ + + bool enabled = true; + + struct shader * shader; + + struct mesh * mesh; + + prepare() { + + + } + + + render() { + + + + } + +} \ No newline at end of file diff --git a/application/source/engine/renderPasses/renderPassCompute.c b/application/source/engine/renderPasses/renderPassCompute.c new file mode 100644 index 0000000..72e5f3d --- /dev/null +++ b/application/source/engine/renderPasses/renderPassCompute.c @@ -0,0 +1,96 @@ + + +#include "./renderPass.h" + +#include "../event.h" + +#include "../vector2.h" + +#include "../shader.h" + +#include "../program.h" + +#include "../int.h" + +#include "../sampler2D.h" + +#include "stdbool.h" + +#include "../block.h" + +#include "../vector.h" + +#include "../mesh.h" + + +class compute extends renderPass{ + + + struct program * program; + + int active = true; + + prepare() { + + printf("\n\n\n Prepare renderPass Compute\n\n\n\n\n"); + + shader * computeShader = new shader( GL_COMPUTE_SHADER ); + + computeShader->loadFromFile( "assets/shaders/addition.comp" ); + + + this->program = new program(); + + this->program->addShader( computeShader ); + + this->program->create(); + + + vector * inputA = new vector(); + + for (int i = 0; i < 100; ++i) + { + + vector2 a = new vector2( i, i ); + + inputA->add( a ); + + } + + vector * inputB = new vector(); + + for (int i = 0; i < 100; ++i) + { + + vector2 a = new vector2( 0, 10 ); + + inputB->add( a ); + + } + + block * inputBlock = this->program->getBlock( "inputBlock" ); + + inputBlock->setMemberArray( "array_a[0]", ( float * ) inputA->items ); + + inputBlock->setMemberArray( "array_b[0]", ( float * ) inputB->items ); + + inputBlock->upload(); + + } + + render() { + + this->program->use(); + + this->program->bindBlock( "inputBlock"); + + this->program->bindBlock( "outputBlock"); + + + glDispatchCompute( 1, 1, 1 ); + + glMemoryBarrier( GL_SHADER_STORAGE_BARRIER_BIT ); + + } + +} \ No newline at end of file diff --git a/application/source/engine/renderPasses/renderPassCompute2.c b/application/source/engine/renderPasses/renderPassCompute2.c new file mode 100644 index 0000000..b646a60 --- /dev/null +++ b/application/source/engine/renderPasses/renderPassCompute2.c @@ -0,0 +1,80 @@ + +#include "renderPass.h" + +#include "../event.h" + +#include "../../vector2.h" + +#include "../shader.h" + +#include "../program.h" + +#include "../../int.h" + +#include "../sampler2D.h" + +#include "stdbool.h" + +#include "../block.h" + + +class compute2 extends renderPass{ + + struct program * program; + + int active = true; + + + prepare() { + + printf("\n\n\n Prepare renderPass Compute 2\n\n\n\n\n"); + + shader * computeShader = new shader( GL_COMPUTE_SHADER ); + + computeShader->loadFromFile( "assets/shaders/addition2.comp" ); + + + this->program = new program(); + + this->program->addShader( computeShader ); + + this->program->create(); + + } + + render() { + + if( this->active ) { + + this->program->use(); + + this->program->bindBlock( "outputBlock2" ); + + + glDispatchCompute( 1, 1, 1 ); + + + block * outputBlock = this->program->getBlock( "outputBlock2" ); + + vector * output = outputBlock->getMemberArray( "array_d[0]" ); + + int count = output->length(); + + for (int i = 0; i < count; ++i) + { + + vector2 currentVector = output->get( i ); + + printf("%i = %f %f \n", i, i, currentVector.x, currentVector.y ); + + } + + printf("length: %i\n\n", count); + + this->active = false; + + } + + } + +} \ No newline at end of file diff --git a/application/source/engine/renderPasses/renderPassFont.c b/application/source/engine/renderPasses/renderPassFont.c new file mode 100644 index 0000000..c2d580c --- /dev/null +++ b/application/source/engine/renderPasses/renderPassFont.c @@ -0,0 +1,174 @@ + + +#include "renderPass.h" + +#include "../event.h" + +#include "../vector2.h" + +#include "../shader.h" + +#include "int.h" + +#include "../fontRenderer.h" + +#include "../program.h" + +#include "../mesh.h" + +class font extends renderPass{ + + + struct program * program; + + struct mesh * mesh; + + fontRenderer * font = new fontRenderer(); + + sampler2D * samplerArray; + + char * textFromNumber( int i) { + + char * fileName = malloc( sizeof( char ) * 100 ); + + sprintf( fileName, "%d", i ); + + return fileName; + + } + + prepare() { + + printf("\n\n\n Prepare renderPass Font\n\n\n\n\n"); + + + + + shader * vertexShader = new shader( GL_VERTEX_SHADER ); + + vertexShader->loadFromFile( "assets/shaders/quad.vertex" ); + + + shader * fragmentShader = new shader( GL_FRAGMENT_SHADER ); + + fragmentShader->loadFromFile( "assets/shaders/quad.fragment" ); + + + + this->program = new program(); + + this->program->addShader( vertexShader ); + + this->program->addShader( fragmentShader ); + + this->program->create(); + + + sampler2D * samplerArray = new sampler2D(); + + samplerArray->target = GL_TEXTURE_2D_ARRAY; + + samplerArray->format = GL_RED; + + samplerArray->internalFormat = GL_RED; + + samplerArray->WRAP_S = GL_CLAMP_TO_EDGE; + + samplerArray->WRAP_S = GL_CLAMP_TO_EDGE; + + samplerArray->cubeSize = new vector3( 128, 128, 170 ); + + samplerArray->UNPACK_ALIGNMENT = true; + + + this->samplerArray = samplerArray; + + block * fontBlock = this->program->getBlock( "fontData" ); + + + this->mesh = new mesh(); + + this->mesh->setProgram( this->program ); + + this->mesh->createBuffers(); + + + glUseProgram( this->program->glProgram ); + + for ( int i = 1; i < 170; ++i ) + { + texture2D * characterTexture = this->font->loadFont( 34 + i ); + + vector2 * offset = characterTexture->offset; + + printf("%c offset left: %f, offset top: %f bitmap->rows: %i\n", (char) 34 + i, offset->x, offset->y, characterTexture->height ); + + vector2 * size = new vector2( characterTexture->width, characterTexture->height ); + + fontBlock->setMemberItem( "fontOffsets[0]", i - 35, offset ); + + //if( i > 34 ) { + + fontBlock->setMemberItem( "fontSizes[0]", i - 35, size ); + + //} + + samplerArray->addTexture( characterTexture ); + + } + + fontBlock->upload(); + + this->program->setUniform( "samplerArray", samplerArray ); + + + + vector * textArray = new vector(); + + char * someText = "Wauw this is myp first text."; + + for (int i = 0; i < strlen(someText); ++i) + { + + int charNumber = ( char ) someText[i] - 35; + + printf(" %i\n", charNumber ); + + textArray->add( charNumber );// + + } + + block * inputBlock = this->program->getBlock( "inputBlock" ); + + inputBlock->setMemberArray( "characters[0]", ( float * ) textArray->items ); + + inputBlock->upload(); + + } + + render() { + + int numItems = 12; + + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + + this->program->use(); + + this->program->bindBlock( "inputBlock"); + + this->program->bindBlock( "fontData"); + + + this->program->setUniform( "samplerArray", this->samplerArray ); + + + + glBindVertexArray( this->mesh->vertexArrayObject ); + + glDrawElements( GL_TRIANGLES, numItems, GL_UNSIGNED_INT, ( void * ) 0 ); + + } + +} \ No newline at end of file diff --git a/application/source/engine/renderPasses/renderPassQuads.c b/application/source/engine/renderPasses/renderPassQuads.c new file mode 100644 index 0000000..fa834ee --- /dev/null +++ b/application/source/engine/renderPasses/renderPassQuads.c @@ -0,0 +1,700 @@ + +#include "renderPass.h" + +#include "../event.h" + +#include "../vector2.h" + +#include "../vector3.h" + +#include "../vector4.h" + +#include "../program.h" + +#include "../shader.h" + +#include "../program.h" + +#include "../../int.h" + +#include "../fontRenderer.h" + +#include "../resourceManager.h" + +#include "../mesh.h" + +#include "../quadMesh.h" + +#include "../element.h" + + + + +extern event * globalEvent; + +extern resourceManager * resources; + + + +class quads extends renderPass{ + + mesh * mesh; + + fontRenderer * font = new fontRenderer(); + + sampler2D * samplerArray; + + program * program; + + vector * meshes = new vector(); + + vector * elements = new vector(); + + vector * mouseOverElements = new vector(); + + char * textFromNumber( int i) { + + char * fileName = malloc( sizeof( char ) * 100 ); + + sprintf( fileName, "%d", i ); + + return fileName; + + } + + prepare() { + + printf("\n\n\n Prepare renderPass Quad\n\n\n\n\n"); + +/* + sampler2D * sampler1 = new sampler2D(); + + sampler1->texture = resources->loadPngImage( "logo.png" ); + +*/ + + this->samplerArray = new sampler2D(); + + + for (int i = 1; i < 10; ++i ) + { + + char * fileName = this->textFromNumber( i ); + + fileName += ".png"; + + printf("load png: %s\n", fileName); + + //this->samplerArray->addTexture( resources->loadPngImage( fileName ) ); + + } + + printf("\n\n"); + + this->samplerArray->target = GL_TEXTURE_2D_ARRAY; + + + shader * vertexShader = new shader( GL_VERTEX_SHADER ); + + vertexShader->loadFromFile( "assets/shaders/multiQuad.vertex" ); + + + shader * fragmentShader = new shader( GL_FRAGMENT_SHADER ); + + fragmentShader->loadFromFile( "assets/shaders/multiQuad.fragment" ); + + + this->program = new program(); + + this->program->addShader( vertexShader ); + + this->program->addShader( fragmentShader ); + + this->program->create(); + + + + //block * eventsBlock = this->program->getBlock( "events" ); + + block * orientationBlock = this->program->getBlock( "orientation" ); + + block * meshesBlock = this->program->getBlock( "meshes" ); + + + this->mesh = new mesh(); + + this->mesh->setProgram( this->program ); + + this->mesh->createBuffers(); + + + + + /* + for (int vertexIndex = 0; vertexIndex < 100; ++vertexIndex) + { + + int mod = vertexIndex % 10; + + vector2 test = new vector2( mod * 0.1 , floor( vertexIndex / 10 ) * 0.1 ); + + meshesBlock->setMemberItem( "meshArray[0].position", vertexIndex, &test ); + + + vector2 size = new vector2( .05 , .05 ); + + meshesBlock->setMemberItem( "meshArray[0].size", vertexIndex, &size ); + + vector3 color = new vector3( (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX); + + + printf("Random: %f %f %f\n", color.x, color.y, color.z); + + meshesBlock->setMemberItem( "meshArray[0].color", vertexIndex, &color ); + + + + } + */ + + this->createMeshes(); + + //this->program->setUniform( "samplerArray", this->samplerArray ); + + + this->samplerArray->addTexture( resources->loadPngImage( "1.png" ) ); + + + meshesBlock->upload(); + + } + + sortOpacity( struct vector< struct quadMesh > * meshes ) { + + + int count = meshes->length(); + + int i, j; + + struct quadMesh temp; + + for (i = 0; i < (count - 1); ++i) + { + for (j = 0; j < count - 1 - i; ++j ) + { + + struct quadMesh quadA = meshes->get( j ); + + struct quadMesh quadB = meshes->get( j + 1 ); + + float a = ( intptr_t ) quadA.zIndex; + + float b = ( intptr_t ) quadB.zIndex; + + if ( a > b ) + { + + temp = meshes->items[j+1]; + + meshes->items[ j + 1 ] = meshes->items[j]; + + meshes->items[ j ] = temp; + + } + } + } + + } + + createMeshes() { + + + vector * meshes = this->meshes; + + meshes->resize( 100 ); + +/* + for (int i = 0; i < 100; ++i) + { + + int mod = i % 10; + + quadMesh meshInstance = new quadMesh(); + + meshInstance.position = new vector2( mod * 0.1 , floor( i / 10 ) * 0.1 ); + + meshInstance.size = new vector2( .05 , .05 ); + + meshInstance.color = new vector3( (float) rand() / RAND_MAX, (float) rand() / RAND_MAX, (float) rand() / RAND_MAX); + + // meshInstance.textureIndex = 0; + + meshes->add( meshInstance ); + + } + */ + + vector * elements = this->elements; + + + { + + element instance = new element(); + + instance.position = new vector3( 200, 200, 1100 ); + + instance.size = new vector2( 200., 200. ); + + //instance.background = new vector3( 0, 256, 0 ); + + instance.opacity = 1; + + instance.background = "9.png"; + + //instance.background = new vector3( 0, 256, 0 ); + + elements->add( instance ); + + + + + } + + + { + + element instance = new element(); + + instance.position = new vector3( 100, 100, 500 ); + + instance.size = new vector2( 400., 400. ); + + instance.background = "3.png"; + + //instance.background = "#2196f354"; + + //instance.background = new vector3( 0, 0, 256 ); + + instance.opacity = .9; + + + /* + + instance.addEventListener( "click", void clickEvent( event * e ) { + + + + + + } ); + + */ + + + + //instance.background = new vector2( 100, 200 ); + + //instance.background = new vector3( 100, 200, 300 ); + + // instance.background = new vector4( 100, 200, 300, 400 ); + + //instance.background = "something/something.png"; + + elements->add( instance ); + + + + { + + element instance = new element(); + + instance.position = new vector3( 20, 0, 1300 ); + + instance.size = new vector2( 40., 40. ); + + instance.background = "7.png"; + + instance.opacity = 1; + + elements->add( instance ); + + + } + + + + + + + int count = elements->length(); + + for (int i = 0; i < count; ++i) + { + + element currentElement = elements->get( i ); + + quadMesh meshInstance = new quadMesh(); + + + meshInstance.elementIndex = i; + + meshInstance.position = new vector2( currentElement.position.x, currentElement.position.y ); + + meshInstance.zIndex = currentElement.position.z; + + meshInstance.size = currentElement.size; + + + printf("zIndex: %f\n", currentElement.position.z); + + int features = 0; + + if( currentElement.useBackgroundImage ) { + + + //int featureValue = currentElement->getFeatureValueByFeatureName("useBackgroundImage"); + + + meshInstance.textureIndex = this->samplerArray->getTextureIndex(); + + printf("use background image. %s \n", currentElement.backgroundImagePath ); + + this->samplerArray->addTexture( resources->loadPngImage( currentElement.backgroundImagePath ) ); + + } else { + + printf("dont use background color. %f %f %f \n", currentElement.backgroundColor.x, currentElement.backgroundColor.y, currentElement.backgroundColor.z); + + meshInstance.color = currentElement.backgroundColor; + + } + + + meshInstance.features = currentElement.updateFeature(); + + meshInstance.opacity = currentElement.opacity; + + //printf("value: %i\n", value); + + + currentElement.setOriginal(); + + elements->set( i, currentElement ); + + + meshes->add( meshInstance ); + + } + + + + this->sortOpacity( meshes ); + + + + } +/* + + +{ + quadMesh meshInstance = new quadMesh(); + + meshInstance.position = new vector2( 0. , 0. ); + + meshInstance.size = new vector2( 50. , 50. ); + + meshInstance.color = new vector3( 0.0, 1.0, 1.0 ); + + + meshes->add( meshInstance ); + +} + +{ + + quadMesh meshInstance = new quadMesh(); + + meshInstance.position = new vector2( 50. , 50. ); + + meshInstance.size = new vector2( 100. , 100. ); + + meshInstance.color = new vector3( 0.0, 0.0, 1.0 ); + + + meshes->add( meshInstance ); + +} + +{ + + quadMesh meshInstance = new quadMesh(); + + meshInstance.position = new vector2( 150. , 150. ); + + meshInstance.size = new vector2( 50. , 50. ); + + meshInstance.color = new vector3( 1.0, 0.0, 1.0 ); + + + meshes->add( meshInstance ); + +} + +*/ + + block * meshesBlock = this->program->getBlock( "meshes" ); + + meshesBlock->setData( ( float * ) meshes->items ); + + } + + + quadMesh updateMesh( quadMesh currentMesh, element currentElement ) { + + vector2 position = new vector2( currentElement.position.x, currentElement.position.y ); + + currentMesh.position = position; + + currentMesh.zIndex = currentElement.position.z; + + currentMesh.size = currentElement.size; + + currentMesh.color = currentElement.backgroundColor; + + return currentMesh; + + } + + void callElementEvents( event * currentEvent, element * currentElement, int elementIndex ) { + + vector * mouseEvents = currentEvent->mouse->eventTypes; + + int mouseEventCount = mouseEvents->length(); + + for (int k = 0; k < mouseEventCount; ++k) + { + char * mouseEventCode = mouseEvents->get( k ); + + printf(" mouse event: %s\n", mouseEventCode); + + + if( mouseEventCode == "click" ) { + + currentElement->click(); + + //printf("trigger click event\n\n"); + + } + + if( mouseEventCode == "mousedown" ) { + + currentElement->mousedown(); + + //printf("trigger mousedown event\n\n"); + + } + + + if( mouseEventCode == "mouseup" ) { + + currentElement->mouseup(); + + //printf("trigger mouseup event\n\n"); + + } + + if( mouseEventCode == "mousemove" ) { + + if( !this->integerContains( this->mouseOverElements, elementIndex ) ) { + + currentElement->mouseover(); + + this->mouseOverElements->add( elementIndex ); + + } + + } + + } + + } + + bool integerContains( vector * numbers, int a ) { + + int count = numbers->length(); + + for (int j = 0; j < count; ++j) + { + + int b = numbers->get( j ); + + if( a == b ) { + + return true; + + } + + } + + return false; + + } + + render() { + + program * currentProgram = this->program; + + event * currentEvent = globalEvent; + + + block * eventsBlock = currentProgram->getBlock( "events" ); + + //block * orientationBlock = currentProgram->getBlock( "orientation" ); + + + block * meshesBlock = currentProgram->getBlock( "meshes" ); + + + eventsBlock->autoUpload = true; + + eventsBlock->setMember( "window", ¤tEvent->screen->size ); + + + meshesBlock->autoUpload = true; + + vector2 mousePosition = globalEvent->mouse->position; + + + int mouseX = ( int ) mousePosition.x; + + int mouseY = ( int ) mousePosition.y; + + + vector * elements = this->elements; + + vector * meshes = this->meshes; + + + vector * mouseOverElements = this->mouseOverElements; + + int count = meshes->length(); + + for (int i = 0; i < count; ++i) + { + quadMesh currentMesh = meshes->get( i ); + + int left = currentMesh.position.x; + + int top = currentMesh.position.y; + + int right = currentMesh.position.x + currentMesh.size.x; + + int bottom = currentMesh.position.y + currentMesh.size.y; + + int elementIndex = currentMesh.elementIndex; + + + if( mouseX > left && mouseX < right && mouseY > top && mouseY < bottom ) { + + element currentElement = elements->get( elementIndex ); + + this->callElementEvents( currentEvent, ¤tElement, elementIndex ); + + currentMesh = this->updateMesh( currentMesh, currentElement ); + + elements->set( elementIndex, currentElement ); + + meshesBlock->setMemberArrayRow( "meshArray[0].color", i, ( float * ) & currentMesh ); + + } else { + + if( this->integerContains( this->mouseOverElements, elementIndex ) ) { + + printf("mouseout\n\n"); + + this->mouseOverElements->delete( elementIndex ); + + element currentElement = elements->get( elementIndex ); + + + currentElement->mouseleave(); + + + + currentMesh = this->updateMesh( currentMesh, currentElement ); + + elements->set( elementIndex, currentElement ); + + meshesBlock->setMemberArrayRow( "meshArray[0].color", i, ( float * ) & currentMesh ); + + } + + + } + + } + + + //eventsBlock->setMember( "mouse", currentEvent->mouse->position ); + + + //vector2 * position = new vector2( 0.0, 0.0 ); + + //orientationBlock->setMember( "quadPosition", position ); + + // meshesBlock->upload(); + + + vector2 * position2 = new vector2( 0.4, 0 ); + + //meshesBlock->upload(); + + + + this->program->setUniform( "samplerArray", this->samplerArray ); + + glUseProgram( currentProgram->glProgram ); + + int numItems = 200; + + + + /* Depth buffer setup */ + //glClearDepth(1.0f); + + /* Enables Depth Testing */ + //glDisable(GL_CULL_FACE); + + //glClear(GL_DEPTH_BUFFER_BIT) + glDisable(GL_DEPTH_TEST); + + + + //glDepthMask(GL_TRUE); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + //glDepthMask(GL_FALSE); + + + glDepthRange(0.0, 1.0); + + glDepthFunc(GL_ALWAYS); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_CULL_FACE); + +/* The Type Of Depth Test To Do */ +//glDepthFunc( GL_LEQUAL ); + + + glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); + + + + glBindVertexArray( this->mesh->vertexArrayObject ); + + glDrawElements( GL_TRIANGLES, numItems, GL_UNSIGNED_INT, ( void * ) 0 ); + + } + +} \ No newline at end of file diff --git a/application/source/engine/renderPasses/renderPassTesselation.c b/application/source/engine/renderPasses/renderPassTesselation.c new file mode 100644 index 0000000..a5a59bd --- /dev/null +++ b/application/source/engine/renderPasses/renderPassTesselation.c @@ -0,0 +1,118 @@ + + +#include "renderPass.h" + +#include "../event.h" + +#include "../vector2.h" + +#include "../shader.h" + +#include "int.h" + +#include "../fontRenderer.h" + +#include "../program.h" + +#include "../mesh.h" + +class tesselation extends renderPass{ + + + struct program * program; + + struct mesh * mesh; + + fontRenderer * font = new fontRenderer(); + + sampler2D * samplerArray; + + char * textFromNumber( int i) { + + char * fileName = malloc( sizeof( char ) * 100 ); + + sprintf( fileName, "%d", i ); + + return fileName; + + } + + prepare() { + + shader * vertexShader = new shader( GL_VERTEX_SHADER ); + + vertexShader->loadFromFile( "assets/shaders/quadScale.vertex" ); + + + shader * fragmentShader = new shader( GL_FRAGMENT_SHADER ); + + fragmentShader->loadFromFile( "assets/shaders/color.fragment" ); + + + shader * geometryShader = new shader( GL_GEOMETRY_SHADER ); + + geometryShader->loadFromFile( "assets/shaders/tesselation.geometry.shader" ); + + + shader * tesselationControlShader = new shader( GL_TESS_CONTROL_SHADER ); + + tesselationControlShader->loadFromFile( "assets/shaders/tesselation.triangle.tsc.shader" ); + + + shader * tesselationEvaluationShader = new shader( GL_TESS_EVALUATION_SHADER ); + + tesselationEvaluationShader->loadFromFile( "assets/shaders/tesselation.triangle.shader" ); + + + + this->program = new program(); + + this->program->addShader( vertexShader ); + + this->program->addShader( fragmentShader );/* + + this->program->addShader( geometryShader ); + + this->program->addShader( tesselationControlShader ); + + this->program->addShader( tesselationEvaluationShader );*/ + + + + this->program->create(); + + + + + this->mesh = new mesh(); + + this->mesh->setProgram( this->program ); + + this->mesh->createBuffers(); + + + glUseProgram( this->program->glProgram ); + + + } + + render() { + + glUseProgram( this->program->glProgram ); + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + int numItems = 12; + + //this->program->setUniform( "samplerArray", this->samplerArray ); + + glBindVertexArray( this->mesh->vertexArrayObject ); + + + + + glDrawElements( GL_LINE_STRIP, numItems, GL_UNSIGNED_INT, ( void * ) 0 ); + + } + +} \ No newline at end of file diff --git a/application/source/engine/resourceManager.c b/application/source/engine/resourceManager.c new file mode 100644 index 0000000..341022f --- /dev/null +++ b/application/source/engine/resourceManager.c @@ -0,0 +1,112 @@ + + +#include "texture2D.h" + +#include + +#include "stdbool.h" + +#include "string.h" + +class resourceManager{ + + texture2D * loadPngImage( char * name ) { + + texture2D * texture = new texture2D(); + + png_structp png_ptr; + + png_infop info_ptr; + + unsigned int sig_read = 0; + + int color_type; + + int interlace_type; + + FILE * fp; + + if ( ( fp = fopen( name, "rb" ) ) == NULL ) { + + return NULL; + + } + + png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL ); + + if ( png_ptr == NULL ) { + + fclose( fp ); + + return false; + + } + + info_ptr = png_create_info_struct( png_ptr ); + + if ( info_ptr == NULL ) { + + fclose(fp); + + png_destroy_read_struct( &png_ptr, NULL, NULL ); + + return false; + + } + + if ( setjmp( png_jmpbuf( png_ptr ) ) ) { + + png_destroy_read_struct( &png_ptr, &info_ptr, NULL ); + + fclose( fp ); + + return false; + + } + + png_init_io( png_ptr, fp ); + + png_set_sig_bytes( png_ptr, sig_read ); + + png_read_png( png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND, NULL ); + + png_uint_32 width, height; + + int bit_depth; + + png_get_IHDR( png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL ); + + unsigned int row_bytes = png_get_rowbytes( png_ptr, info_ptr ); + + + + texture->width = width; + + texture->height = height; + + texture->hasAlpha = ( color_type == PNG_COLOR_TYPE_RGBA ); + + texture->data = ( unsigned char * ) malloc( row_bytes * texture->height ); + + + png_bytepp row_pointers = png_get_rows( png_ptr, info_ptr ); + + for (int i = 0; i < texture->height; i++) { + + // note that png is ordered top to + // bottom, but OpenGL expect it bottom to top + // so the order or swapped + + memcpy( texture->data + ( row_bytes * ( texture->height - 1 - i ) ), row_pointers[ i ], row_bytes ); + + } + + png_destroy_read_struct( &png_ptr, &info_ptr, NULL ); + + fclose( fp ); + + return texture; + + } + +} \ No newline at end of file diff --git a/application/source/engine/sampler2D.c b/application/source/engine/sampler2D.c new file mode 100644 index 0000000..114c6c8 --- /dev/null +++ b/application/source/engine/sampler2D.c @@ -0,0 +1,208 @@ + +#define GL_GLEXT_PROTOTYPES + +#include + +#include // GL 1.1 functions + +#include + +#include "./texture2D.h" + +#include "stdbool.h" + +#include "../array.h" + +#include "../vector3.h" + +class sampler2D{ + + texture2D * texture; + + array * textures = new array(); + + + GLuint glTexture; + + + GLint binded = false; + + + GLint filter = GL_LINEAR; + + + GLint MIN_FILTER = GL_LINEAR; + + GLint MAG_FILTER = GL_LINEAR; + + GLint WRAP_S = GL_REPEAT; + + GLint WRAP_T = GL_REPEAT; + + + GLint datatype = GL_RGBA; + + GLint format = GL_RGBA; + + GLint internalFormat = GL_RGBA; + + + GLint target = GL_TEXTURE_2D; + + GLint type = GL_UNSIGNED_BYTE;//gl.FLOAT; + + + vector3 * cubeSize = NULL; + + + GLint border = false; + + GLint generateMipmap = true; + + bool UNPACK_ALIGNMENT = false; + + //GLint FLIP_Y = true; pixelStorei + + GLuint index = 0; + + constructor() { + + glGenTextures( 1, &this->glTexture ); + + } + + addTexture( texture2D * texture ) { + + this->textures->add( texture ); + + } + + int getTextureIndex() { + + int numberOfTextures = this->textures->length(); + + return numberOfTextures; + + } + + bind() { + + this->binded = true; +/* + texture2D * texture = this->texture; + + if( texture == NULL ) { + + printf("Error: Texture not loaded.\n\n"); + + return ; + + } +*/ + //printf("Created sampler with id #%i\n", this->index); + + glActiveTexture( GL_TEXTURE0 + this->index ); + + glBindTexture( this->target, this->glTexture ); + + glTexParameteri( this->target, GL_TEXTURE_WRAP_S, this->WRAP_S ); + + glTexParameteri( this->target, GL_TEXTURE_WRAP_T, this->WRAP_T ); + + glTexParameteri( this->target, GL_TEXTURE_MIN_FILTER, this->MIN_FILTER ); + + glTexParameteri( this->target, GL_TEXTURE_MAG_FILTER, this->MAG_FILTER ); + + + + if( this->target == GL_TEXTURE_2D_ARRAY ) { + + //printf("create 2d array texture"); + + int offsetX = 0; + + int offsetY = 0; + + int offsetZ = 0; + + int depth = 1; + + int levelOfDetail = 0; + + int layerCount = 2; + + int mipLevelCount = 1; + + int currentLayer = 0; + + texture2D * texture1 = this->textures->get( 0 ); + + int numberOfTextures = this->textures->length(); + + + if( this->cubeSize == NULL ) { + + this->cubeSize = new vector3( texture1->width, texture1->height, numberOfTextures ); + + } + + //glTexSubImage3D( this->target, levelOfDetail, offsetX, offsetY, offsetZ, texture->width, texture->height, depth, this->format, this->type, texture->data ); + + if( this->UNPACK_ALIGNMENT ) { + + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + } else { + + glPixelStorei( GL_UNPACK_ALIGNMENT, 0 ); + + } + + glTexStorage3D( this->target, mipLevelCount, this->format, this->cubeSize->x, this->cubeSize->y, numberOfTextures ); + + GLint data[ texture1->width * texture1->height * numberOfTextures ]; + + glTexImage3D( GL_TEXTURE_2D_ARRAY, levelOfDetail, this->internalFormat, this->cubeSize->x, this->cubeSize->y, numberOfTextures, this->border, this->format, this->type, data); + + for (int i = 0; i < numberOfTextures; ++i) + { + + texture2D * currentTexture = this->textures->get( i ); + + float test = 0;//this->cubeSize->y - currentTexture->height - 1; + + glTexSubImage3D( this->target, + 0, + offsetX, test , i, + currentTexture->width, currentTexture->height, 1, + this->format, + this->type, + currentTexture->data ); + + } + + + + } else { + + texture2D * texture = this->textures->get( 0 ); + + glTexImage2D( this->target, 0, this->internalFormat, texture->width, texture->height, this->border, this->format, this->type, texture->data ); //GL_FLOAT + + } + + + if( this->generateMipmap ) { + + glGenerateMipmap( this->target ); + + } + + + //glBindTexture( this->target, NULL ); + + } + + + +} diff --git a/application/source/engine/shader.c b/application/source/engine/shader.c new file mode 100644 index 0000000..c30ec62 --- /dev/null +++ b/application/source/engine/shader.c @@ -0,0 +1,90 @@ + + +#include "block.h" + +#include "member.h" + +#include "uniform.h" + + +#define GL_GLEXT_PROTOTYPES + +#include + +#include // GL 1.1 functions + +#include + +#include + +#include "../fileSystem.h" + +#include "../array.h" + +#include "../char.h" + +#include "sampler2D.h" + + +class attribute{ + + GLchar name[64]; + + GLint location; + + GLenum type; + +} + +class shader{ + + GLuint glShader; + + constructor( GLuint shaderType ) { + + this->glShader = glCreateShader( shaderType ); + + } + + loadFromFile( char * shaderPath ) { + + text * shaderSource = filesystem->readFile( shaderPath, "utf8" ); + + glShaderSource( this->glShader, 1, &shaderSource->value, NULL ); + + glCompileShader( this->glShader ); + + this->checkShaderForErrors( this->glShader ); + + } + + checkShaderForErrors( GLuint shader ) { + + GLint isCompiled = 0; + + glGetShaderiv( shader, GL_COMPILE_STATUS, &isCompiled ); + + if( isCompiled == GL_FALSE ) + { + GLint maxLength = 0; + + glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &maxLength ); + + GLchar errorMessage[ maxLength ]; + + glGetShaderInfoLog( shader, maxLength, &maxLength, errorMessage ); + + printf("\n\n\n\n Error: %s\n\n\n\n\n\n", errorMessage); + + + glDeleteShader( shader ); + + exit( 0 ); + + return; + + } + + } + +} \ No newline at end of file diff --git a/application/source/engine/texture2D.c b/application/source/engine/texture2D.c new file mode 100644 index 0000000..9176d23 --- /dev/null +++ b/application/source/engine/texture2D.c @@ -0,0 +1,26 @@ + + +#define GL_GLEXT_PROTOTYPES + +#include + +#include // GL 1.1 functions + +#include + +#include "vector2.h" + + +class texture2D{ + + GLubyte * data; + + int width; + + int height; + + int hasAlpha; + + vector2 * offset; + +} \ No newline at end of file diff --git a/application/source/engine/uniform.c b/application/source/engine/uniform.c new file mode 100644 index 0000000..65c6137 --- /dev/null +++ b/application/source/engine/uniform.c @@ -0,0 +1,27 @@ + + +#define GL_GLEXT_PROTOTYPES + +#include + +#include // GL 1.1 functions + +#include + + + +class uniform{ + + char name[64]; + + GLint index; + + GLint location; + + GLint offset; + + GLint size; + + GLenum type; + +} \ No newline at end of file diff --git a/application/source/engine/uniformBlock.c b/application/source/engine/uniformBlock.c new file mode 100644 index 0000000..01de475 --- /dev/null +++ b/application/source/engine/uniformBlock.c @@ -0,0 +1,167 @@ + + +#include "block.h" + +#include "member.h" + +#include + + + + +#define GL_GLEXT_PROTOTYPES + +#include + +#include // GL 1.1 functions + +#include + +#include + +#include "fileSystem.h" + +#include "array.h" + +#include "char.h" + +#include "sampler2D.h" + + + +class uniformBlock{ + + array * uniforms = new array(); + + GLint buffer; + + GLuint index; + + GLint size; + + GLchar name[64]; + + GLuint bindingPoint; + + float * data; + + GLint autoUpload = 0; + + createBuffer() { + + unsigned int uniformBufferSize = this->size; // allocate 152 bytes of memory + + printf("create GL_UNIFORM_BUFFER of size: %i index: %i \n", uniformBufferSize, this->index); + + this->data = ( float * ) malloc( uniformBufferSize ); + + glGenBuffers( 1, &this->buffer ); + + glBindBuffer( GL_UNIFORM_BUFFER, this->buffer ); + + glBindBufferBase( GL_UNIFORM_BUFFER, this->index, this->buffer ); + + glBufferData( GL_UNIFORM_BUFFER, uniformBufferSize, 0, GL_DYNAMIC_DRAW ); + + //glBufferData( GL_UNIFORM_BUFFER, uniformBufferSize, NULL, GL_DYNAMIC_DRAW ); + + } + + void upload() { + + //printf("upload uniform buffer: %f %f %f %f\n", this->data[0], this->data[1], this->data[2], this->data[3]); + + //printf("upload uniform buffer: %i\n", this->index); + + glBindBuffer( GL_UNIFORM_BUFFER, this->buffer ); + + glBindBufferBase( GL_UNIFORM_BUFFER, this->bindingPoint, this->buffer ); + + glBufferData( GL_UNIFORM_BUFFER, this->size, this->data, GL_DYNAMIC_DRAW ); + + } + + enableAutoUpload() { + + this->autoUpload = 1; + + } + + void setUniform( char * name, void * value ) { + + int uniformCount = this->uniforms->length(); + + //printf("uniformCount: %i\n\n", uniformCount); + + for (int i = 0; i < uniformCount; ++i) + { + uniform * currentUniform = this->uniforms->get( i ); + + char * uniformName = (char *) currentUniform->name; + + if( uniformName == name ) { + + //printf("\n\n Update this uniform from uniform block %s\n\n", name); + + switch( currentUniform->type ) { + + case GL_FLOAT_VEC2: + + vector2 * vector2Value = ( vector2 * ) value; + + GLuint size = 8; + + GLint offset = currentUniform->offset; + + + if( this->autoUpload ) { + + float data[2] = { vector2Value->x, vector2Value->y }; + + + glBindBuffer( GL_UNIFORM_BUFFER, this->buffer ); + + glBindBufferBase( GL_UNIFORM_BUFFER, 0, this->buffer ); + + // glBufferData( GL_UNIFORM_BUFFER, 16, data2, GL_DYNAMIC_DRAW ); + + glBufferSubData( GL_UNIFORM_BUFFER, offset, size, data ); + + //printf("using autoUpload %i %i %f %f\n", offset, size, data[0], data[1]); + + } else { + + GLint dataOffset = offset / sizeof( float ); + + this->data[ dataOffset ] = vector2Value->x; + + this->data[ dataOffset + 1 ] = vector2Value->y; + + } + + break; + + case GL_FLOAT_VEC3: + + vector3 * vector3Value = ( vector3 * ) value; + + + + break; + + case GL_SAMPLER_2D: + + + break; + + } + + } + + + } + + + } + +} \ No newline at end of file diff --git a/application/source/engine/unsignedIntegerArray.c b/application/source/engine/unsignedIntegerArray.c new file mode 100644 index 0000000..3cdc921 --- /dev/null +++ b/application/source/engine/unsignedIntegerArray.c @@ -0,0 +1,156 @@ + +#include + +#include + + +class unsignedIntegerArray{ + + int capacity = 10; + + int total = 0; + + unsigned int * items = malloc( 10000000 ); + + int length() + { + + return this->total; + + } + + unsigned int get( int index ) + { + + return this->items[index]; + + } + + void set( int index, unsigned int item ) + { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + void resize( int capacity ) + { + + int * items = realloc( this->items, sizeof( int ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + void addVector2( struct vector2 * item ) { + + this->add( item->x ); + + this->add( item->y ); + + } + + void addVector3( struct vector3 * item ) { + + this->add( item->x ); + + this->add( item->y ); + + this->add( item->z ); + + } + + void add( unsigned int item ) + { + + if ( this->capacity == this->total ){ + + this->resize( this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + void delete( int index ) + { + if ( index < 0 || index >= this->total ){ + + return; + + } + + this->items[index] = 0.0; + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + this->items[i + 1] = 0.0; + + } + + this->total--; + + if ( this->total > 0 && this->total == this->capacity / 4 ){ + + this->resize( this->capacity / 2 ); + + } + + } + + unsigned int array_push( unsigned int item ) { + + this->add( item ); + + return this->total; + + } + + void unshift( int item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + this->resize( this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } + + unsigned int pop() { + + int length = this->total; + + int lastIndex = length - 1; + + int lastItem = this->get( lastIndex ); + + this->delete( lastIndex ); + + return lastItem; + + } + + +} \ No newline at end of file diff --git a/application/source/engine/vector.c b/application/source/engine/vector.c new file mode 100644 index 0000000..e666d47 --- /dev/null +++ b/application/source/engine/vector.c @@ -0,0 +1,213 @@ + + + +#include "element.h" + +#include "quadMesh.h" + +#include "../vector2.h" + +#include "../int.h" + + +template +class vector{ + + int capacity = 10; + + int total = 0; + + T * items = malloc( 10000000 ); + + int length() + { + + return this->total; + + } + + T get( int index ) + { + + return this->items[index]; + + } + + void set( int index, T item ) + { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + void resize( int capacity ) + { + + T * items = realloc( this->items, sizeof( T ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + void add( T item ) + { + + if ( this->capacity == this->total ){ + + this->resize( this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + void delete( int index ) + { + + //this->items[index] = NULL; + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + //this->items[i + 1] = NULL; + + } + + + + // bug preprocessor + operator on pointer of vector2 or vector3. + //memmove( this->items + index, this->items + index + 1, ( ( this->total - index ) - 1) * ( sizeof( T ) ) ); + + + this->total--; + + //if ( this->total > 0 && this->total == this->capacity / 4 ){ + + // this->resize( this->capacity / 2 ); + + //} + + } + + + + int array_push( T item ) { + + this->add( item ); + + return this->total; + + } + + void unshift( T item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + this->resize( this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } +/* + bool includes() { + + //#if TEMPLATE_1 + + } +*/ + +/* + T pop() { + + int length = this->total; + + int lastIndex = length - 1; + + T lastItem = this->get( lastIndex ); + + this->delete( lastIndex ); + + return lastItem; + + } +*/ + +} + +/* + +template<> +class vector{ + + includes( char * value ) { + + int count = this->items->length(); + + for (int i = 0; i < count; ++i) + { + + char * current = this->items->get( i ); + + if( current == value ) { + + return true; + + } + + } + + return false; + + } + +} + + +template<> +class vector{ + + bool includes( int value ) { + + int count = this->items->length(); + + for (int i = 0; i < count; ++i) + { + + int current = this->items->get( i ); + + if( current == value ) { + + return true; + + } + + } + + return false; + + } + +} + +*/ \ No newline at end of file diff --git a/application/source/engine/vector4.c b/application/source/engine/vector4.c new file mode 100644 index 0000000..c43b31a --- /dev/null +++ b/application/source/engine/vector4.c @@ -0,0 +1,56 @@ + + + + +class vector4{ + + float x; + + float y; + + float z; + + float w; + + + constructor( float x, float y, float z, float w ) { + + this->x = x; + + this->y = y; + + this->z = z; + + this->w = w; + + } + + vector4 * operator+( vector4 * b ) { + + this->add( b ); + + return this; + + } + + vector4 * operator+=( vector4 * b ) { + + this->add( b ); + + return this; + + } + + void add( vector4 * b ) { + + this->x += b->x; + + this->y += b->y; + + this->z += b->z; + + this->w += b->w; + + } + +} \ No newline at end of file diff --git a/application/source/engine/windowManager.c b/application/source/engine/windowManager.c new file mode 100644 index 0000000..5550127 --- /dev/null +++ b/application/source/engine/windowManager.c @@ -0,0 +1,164 @@ + + +#include + +#include + +#define GL_GLEXT_PROTOTYPES + +#include + +#include // GL 1.1 functions + +#include + +#include + +#include + +static int DoubleBufferAttributes[] = { + GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DEPTH_SIZE, 12, + GLX_DOUBLEBUFFER, + None, +}; + + + +class windowManager{ + + Display * mainDisplay; + + Window mainWindow; + + int MainScreen; + + Window RootWindow; + + + setupDisplay() { + + this->mainDisplay = XOpenDisplay( 0 ); + + this->MainScreen = XDefaultScreen( this->mainDisplay ); + + } + + setupWindow() { + + + this->RootWindow = XDefaultRootWindow( this->mainDisplay ); + + + int empty; + + int ResultStatus = glXQueryExtension( this->mainDisplay, &empty, &empty ); + + XVisualInfo* VisualInfo = glXChooseVisual( this->mainDisplay, this->MainScreen, DoubleBufferAttributes ); + + GLXContext ShareList = None; + + int IsDirectRendering = True; + + + //XMatchVisualInfo( this->mainDisplay, this->MainScreen, 32, TrueColor, &VisualInfo); + + + GLXContext OpenGLContext = glXCreateContext( this->mainDisplay, VisualInfo, ShareList, IsDirectRendering ); + + + + int WindowX = 0; + + int WindowY = 0; + + int WindowWidth = 1000;//;1920; + + int WindowHeight = 1024;//;72; + + int BorderWidth = 0; + + int WindowClass = InputOutput; + + int WindowDepth = VisualInfo->depth; + + + Visual* WindowVisual = VisualInfo->visual; + + int AttributeValueMask = CWBackPixel | CWEventMask | CWColormap; + + + + + + + XSetWindowAttributes WindowAttributes = {}; + + WindowAttributes.colormap = XCreateColormap( this->mainDisplay, this->RootWindow, VisualInfo->visual, AllocNone ); + + //WindowAttributes.background_pixel = 0xffafe9af; + + WindowAttributes.background_pixel = 0; + + + WindowAttributes.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | PointerMotionMask; + + this->mainWindow = XCreateWindow( this->mainDisplay, this->RootWindow, + WindowX, WindowY, WindowWidth, WindowHeight, + BorderWidth, WindowDepth, WindowClass, WindowVisual, + AttributeValueMask, &WindowAttributes); + + + //XMoveWindow( this->mainDisplay, this->mainWindow, 0, 800 ); + + XMoveWindow( this->mainDisplay, this->mainWindow, -400, 0 ); + + XStoreName( this->mainDisplay, this->mainWindow, "Opengl: Fixed function pipeline" ); + + glXMakeCurrent( this->mainDisplay, this->mainWindow, OpenGLContext ); + + XMapWindow( this->mainDisplay, this->mainWindow ); + + +//W = DisplayWidth(display, defaultScreen); +//H = DisplayHeight(display, defaultScreen); + + + /* + + Remove borders + + */ + +/* + + Atom window_type = XInternAtom( this->mainDisplay, "_MOTIF_WM_HINTS", True ); + + Hints hints; + + Atom property; + + hints.flags = 2; + + hints.decorations = 0; + + XChangeProperty( this->mainDisplay, this->mainWindow, window_type, window_type, 32, PropModeReplace, ( unsigned char * ) & hints, 5 ); + + +*/ + + Atom WM_DELETE_WINDOW = XInternAtom( this->mainDisplay, "WM_DELETE_WINDOW", False ); + + + if( !XSetWMProtocols( this->mainDisplay, this->mainWindow, &WM_DELETE_WINDOW, 1) ) { + + printf( "Couldn't register WM_DELETE_WINDOW\n" ); + + } + + } + +} \ No newline at end of file diff --git a/application/source/examples/example.console.log.c b/application/source/examples/example.console.log.c new file mode 100644 index 0000000..92fff2b --- /dev/null +++ b/application/source/examples/example.console.log.c @@ -0,0 +1,75 @@ + +#include "../console.h" + +#include "../street.h" + +#include "../user.h" + +#include "../array.h" + + + +void main() { + + struct user * newUser = new user(); + + newUser->id = 1; + + newUser->username = "peter"; + + newUser->userlevel = 2134; + + newUser->hash = "#234234325"; + + + + struct array * addresses = newUser->addresses; + + + address * someAddress = new address(); + + someAddress->street = "HiLane"; + + someAddress->number = 1234; + + addresses->add( someAddress ); + + + + + address * otherAddress = new address(); + + otherAddress->street = "OtherLane"; + + otherAddress->number = 4567; + + addresses->add( otherAddress ); + + // todo newUser->addresses->add( otherAddress ); + + + printf("adresses count: %i\n\n", addresses->length() ); + + + char * something = "this is from an char * "; + + int somethingElse = 123; + + + console.log( "Goedendag", + 123456, + "en een andere text.", + something, + somethingElse, + "something en something", + "in native c", + 23456, + newUser, + "and some text again" ); + +} + +void abort() { + + +} \ No newline at end of file diff --git a/application/source/examples/example.file.system.c b/application/source/examples/example.file.system.c new file mode 100644 index 0000000..5ecd800 --- /dev/null +++ b/application/source/examples/example.file.system.c @@ -0,0 +1,57 @@ + + +#include "../fileSystem.h" + +#include "../console.h" + +void main() { + + char * directory2 = "./assets/"; + + fileSystem * filesystem = new fileSystem(); + + char * directory = "./assets/"; + + + + filesystem->writeFile( "./assets/testFile", "content of file" ); + + + array * files = filesystem->readDir( directory ); + + int fileCount = files->length(); + + for ( int i = 0; i < fileCount; ++i ) + { + + char * filename = files->get( i ); + + char * path = directory->concatenate( filename ); + + char * source = filesystem->readFile( path ); + + + printf("filename: %s\n", path); + + printf("source: %s\n\n\n", source); + + } + + if( filesystem->ensureDirectory("./Some/example/assure") ) { + + console.log("Directories successfuly created."); + + } + + if( filesystem->exists( "Some" ) ) { + + console.log("Directories 'Some' does exist."); + + } + +} + +void abort() { + + +} \ No newline at end of file diff --git a/application/source/examples/example.multiple.inheritance.c b/application/source/examples/example.multiple.inheritance.c new file mode 100644 index 0000000..e0b6ddf --- /dev/null +++ b/application/source/examples/example.multiple.inheritance.c @@ -0,0 +1,38 @@ + + +#include + +#include "extends.h" + +void main() { + + + + struct inherit * pointer = new inherit(); + + //pointer->propertyFromC = 20; + + + printf("pointer->propertyFromC: %i\n\n", pointer->propertyFromC ); + + pointer->methodFromC(); + + printf("\n\n\n\n"); + + + for (int i = 0; i < 10; ++i) + { + + struct inherit instance = new inherit(); + + instance.propertyFromA = i; + + instance.propertyFromB = i; + + instance.propertyFromC = i; + + instance.methodFromC(); + + } + +} \ No newline at end of file diff --git a/application/source/examples/example.opengl.c b/application/source/examples/example.opengl.c new file mode 100644 index 0000000..d96737d --- /dev/null +++ b/application/source/examples/example.opengl.c @@ -0,0 +1,12 @@ + + +#include "../engine/opengl.h" + + +void main() { + + opengl * instance = new opengl(); + + instance->initialize(); + +} \ No newline at end of file diff --git a/application/source/examples/example.operator.overload.c b/application/source/examples/example.operator.overload.c new file mode 100644 index 0000000..9321893 --- /dev/null +++ b/application/source/examples/example.operator.overload.c @@ -0,0 +1,166 @@ + + + + +#include "../text.h" + +#include "../vector2.h" + +#include "../vector3.h" + +#include "../console.h" + + + +void main() { + + text * textB = new text("ook mooi"); + + char * other = malloc(5000); + + vector3 * newVector3 = new vector3(); + + newVector3->x = 2; + + newVector3->y = 2; + + newVector3->z = 3; + + + for (int i = 0; i < 1000; ++i) + { + + vector3 * vector3B = new vector3(); + + + vector3B->x = 2; + + vector3B->y = 3; + + vector3B->z = 4; + + + vector3 * vector3C = new vector3(); + + + vector3C->x = 2; + + vector3C->y = 3; + + vector3C->z = 4; + + newVector3 = vector3C + ( vector3C + newVector3 + ( ( ( ( vector3B + vector3C ) ) + vector3C ) + vector3B ) ); + + newVector3 = newVector3 + ( ( vector3B + vector3C ) + vector3C ); + + } + + console->log( newVector3 ); + + text * textA = new text("mooi"); + + if( textA == textB ) { + + printf("mooi zo"); + + } + + text * textC = new text("mooi"); + + text * textD = new text("mooi"); + + + if( ( ( textA == textC ) && ( textA == textD ) ) && textA == textD ) { + + printf("Good, This works.\n\n"); + + } + + char * realChar = "something"; + + if( "something" == realChar ) { + + printf("Wauw.\n\n"); + + } + + if( realChar == "something" ) { + + printf("Wauw.\n\n"); + + } + + if( realChar == realChar ) { + + printf("Wauw.\n\n"); + + } + + if( "something" == "something" && realChar == "something" ) { + + printf("Wauw.\n\n"); + + } + + char * fancy = "aaa "; + + char * aaaa = " bbb "; + + char * bbbb = " ccc "; + + char * dddd = " dddd "; + + other += ( fancy + ( bbbb + aaaa ) + dddd ) + " eee" + " het is een wonder "; + + other += ("boven wonder" + returnText("this is a normal function") + " and this " + ( "works just good..." + dddd )); + + other += "something" + ( returnText("this is a normal function") + textB->toNative() + textB->value ); + + other += ("and here some text") + (textB->toNative()) ; + + other += ( textB->value + ( ( textB->value ) + returnText("this is a normal function") ) + (textB->toNative() + "here some text" + textB->value ) ); + + other += textB->value + textB->value + ( textB->value + textB->value ) + ( textB->value + textB->value ) + textB->value + textB->value; + + console.log( "Mooi zo ", other ); + + + + + + + + + + vector2 testVector = new vector2( 1, 450 ); + + + //int count = 0; + + for (int i = 0; i < 2000000; ++i) + { + vector2 testVector1 = new vector2( 2, 450 ); + + vector2 * testVector2 = new vector2( 10, 450 ); + + testVector += testVector1 + testVector2; + + //count++; + + } + + + +} + + +char * returnText( char * text ) { + + return text; + +} + +void abort() { + + +} \ No newline at end of file diff --git a/application/source/examples/example.sqlite3.c b/application/source/examples/example.sqlite3.c new file mode 100644 index 0000000..daa7fb4 --- /dev/null +++ b/application/source/examples/example.sqlite3.c @@ -0,0 +1,154 @@ + + + + +#include "../sqlite.h" + +#include "../array.h" + +#include "../console.h" + +#include "../street.h" + +#include "../user.h" + +#include + +void main() { + + // sqlite * sql = new sqlite("./database/users.sqlite"); + + sqlite * sql = new sqlite(":memory:"); + + sql->selectModel( "user" ); + + + sql->createTable(); + + char * names[20] = { "piet", "gurbe", "siebe", "gerben", "twain", "piet", "gurbe", "siebe", "gerben", "twain", "piet", "gurbe", "siebe", "gerben", "twain" }; + + clock_t tic = clock(); + + + array * usersInsertArray = new array(); + + for (int i = 0; i <10; ++i) //20000 + { + + char * name = names[i]; + + struct user * userInstance = new user(); + + userInstance->id = i; + + userInstance->username = name; + + userInstance->userlevel = 3; + + userInstance->hash = "12345"; + + usersInsertArray.add( userInstance ); + + //sql->addRow( userInstance ); + + } + + + sql->addRows( usersInsertArray ); + + + + clock_t toc = clock(); + + printf("Multiply: %f seconds, rows: %i\n", (double)( toc - tic ) / CLOCKS_PER_SEC, 10000); + + + + array * usersA = sql->fetchRows( "SELECT * FROM user" ); + + //user * firstUser = new user(); + + user * firstUser = usersA->get( 1 ); + + //firstUser->id =10; + + firstUser->username = "updated"; + + firstUser->userlevel = 1111; + + firstUser->hash = "new hash"; + + console->log( "??", firstUser, "Yeey console.log workswith , , " ); + + + sql->update( firstUser ); + + printf("before log\n\n"); + + + + + array * users = sql->fetchRows( "SELECT * FROM user " ); + + int userCount = users->total; + + + printf("added rows: %i\n", userCount); + + console->createHorisontalLine(); + + printf("\e[1m"); + + printf(" "); + + printf("%-20s", "id" ); + + printf("%-30s", "username" ); + + printf("%-20s", "userLevel" ); + + printf("%-30s", "Hash"); + + printf("\e[m"); + + printf("\n"); + + console->createHorisontalLine(); + + printf("users: %i\n", userCount); + + for (int i = 0; i < userCount; ++i) + { + + struct user * userInstance = users->get( i ); + + userInstance->id; + + userInstance->username; + + printf(" "); + + printf("%-20i", userInstance->id); + + printf("%-30s", userInstance->username); + + printf("%-20i", userInstance->userlevel); + + printf("%-30s", userInstance->hash); + + printf( "\n" );//%-30s + + } + + sql->free(); + + console->createHorisontalLine(); + + + +} + +void abort() { + + +} \ No newline at end of file diff --git a/application/source/examples/example.text.c b/application/source/examples/example.text.c new file mode 100755 index 0000000..e8a200c --- /dev/null +++ b/application/source/examples/example.text.c @@ -0,0 +1,78 @@ + + +#include "../array.h" + +#include "../text.h" + +#include "time.h" + + + +void main() { + + clock_t tic = clock(); + + text * sometext = new text(" my first text"); + + struct text a = new text(" Mooi "); + + for ( int i = 0; i < 100; ++i ) { + + sometext->appendObject( a )->append("something")->appendObject( new text(" and this") ); + + } + + printf("append: %s \n\n", sometext->buffer); + + clock_t toc = clock(); + + printf("Multiply: %f seconds\n", (double)( toc - tic ) / CLOCKS_PER_SEC); + + + char * testText = "a,"; + + array * splitParts = testText->concatenate( "b, " )->concatenate("c,d,e")->concatenate(",f ")->split(",g"); + + char * compareString = "something"; + + splitParts.unshift((char *) "first"); + + splitParts.unshift((char *) "this first"); + + + printf( "joined: %s\n\n", splitParts.join(", ") ); + + char * lastElement = splitParts->pop(); + + printf( "pop joined: %s\n\n", splitParts.join(", ") ); + + printf( "pop removed element: %s\n\n", lastElement ); + + + if( compareString.compare("something") ) { + + printf("this is true\n"); + + } else { + + printf("this is not true\n"); + + } + + printf("first: %s \n\n", splitParts.get( 0 ) ); + + int splitCount = splitParts->length(); + + printf("splitCount: %i\n", splitCount); + + for (int i = 0; i < splitCount; ++i) + { + + char * splitPart = splitParts.get( i ); + + //printf("splitPart: %s \n\n", splitPart->trim() ); + + } + + +} diff --git a/application/source/examples/example.vector.c b/application/source/examples/example.vector.c new file mode 100644 index 0000000..d96f2c4 --- /dev/null +++ b/application/source/examples/example.vector.c @@ -0,0 +1,138 @@ + + + +#include "vector2.h" + +#include "vector3.h" + +#include + +#include "array.h" + +#include "triangle.h" + +void main() { + + array * arrayA = new array(); + + clock_t tic = clock(); + + vector2 * testVector = new vector2( 1, 450 ); + + + int count = 0; + + for (int i = 0; i < 1000000; ++i) + { + vector2 * testVector1 = new vector2( i, i * 450 ); + + vector2 * testVector2 = new vector2( 10, 450 ); + + testVector += testVector1 + testVector2; + + count++; + + } + + + printf("count: %i\n", count); + + + for ( int i = 0; i < 1; ++i ) + { + + vector2 testVector = new vector2( 10, 450 ); + + + arrayA->add( &testVector ); + + arrayA->add( &testVector ); + + + //printf("number of items in array: %i \n ", arrayA->length() ); + + vector2 * returned = arrayA->get( i ); + + //printf("returned vector x: %i \n ", returned->x ); + + //printf("returned vector y: %i \n ", returned->y ); + + vector2 testVector3 = new vector2( 2, 3 ); + + arrayA->set( i, &testVector3 ); + + vector2 * secondReturn = arrayA->get( 0 ); + + //printf("returned vector x: %i \n ", secondReturn->x ); + + //printf("returned vector y: %i \n ", secondReturn->y ); + + returned->add( secondReturn ); + + printf( "returned vector x: %i \n ", returned->x ); + + printf("returned vector y: %i \n ", returned->y ); + + } + + + for ( int i = 0; i < 1; ++i ) + { + + vector2 a = new vector2( 10, 10 ); + + vector2 b = new vector2( 10, 10 ); + + a->add( &b ); + + printf( "a->x: %i, a->y: %i\n", a.x, a.y); + + } + + + + for (int i = 0; i < 1; ++i) + { + triangle * a = new triangle(); + + triangle * b = new triangle(); + + + a->add( b ); + } + + + vector2 * t = new vector2( 2,2 ); + + int totalLength = 0; + + for (int i = 0; i < 1; ++i) + { + + t->x = 100; + + vector2 b = new vector2( 123, 2 ); + + b.x = 50; + + vector2 c = new vector2( 1, 12 ); + + + c.x = i; + + t->add( &b ); + + b.add( &c ); + + c.add( &b ); + + printf("a, %i\n", t->x); + + printf("b, %i\n", b.x); + + printf("c, %i\n", c.x); + + } + + +} \ No newline at end of file diff --git a/application/source/examples/example.vulkan.c b/application/source/examples/example.vulkan.c new file mode 100644 index 0000000..12a4790 --- /dev/null +++ b/application/source/examples/example.vulkan.c @@ -0,0 +1,18 @@ + + +#include "vulkan.h" +volatile sig_atomic_t stop; + +void inthand(int signum) { + stop = 1; +} + +int main() { + + vulkan * instance = new vulkan(); + + instance->setup(); + + + return 1; +} \ No newline at end of file diff --git a/application/source/examples/example.web.server.c b/application/source/examples/example.web.server.c new file mode 100644 index 0000000..759823f --- /dev/null +++ b/application/source/examples/example.web.server.c @@ -0,0 +1,70 @@ + +#include "../http.h" + +#include "./fileSystem.h" + +#include "./text.h" + +#include "./mimeTypes.h" + +#include "./cache.h" + + +struct cache * cacheManager; + + + +void handleRequest( struct request * requestInstance, struct text * response ) { + + text * filePath = new text("www/"); + + filePath += requestInstance->url; + + + if( filesystem->isDirectory( filePath->value ) ) { + + filePath->value += "index.html"; + + requestInstance->mimeType = "text/html"; + + } + + text * content = cacheManager->getFile( filePath->value ); + + //text * content = filesystem->readFile( filePath->value, "binary" ); + + response += "HTTP/1.0 200 OK\r\n"; + + response += "Server: webserver-c\r\n"; + + response += "Content-type: " + requestInstance->mimeType + "\r\n\r\n"; + + printf("Filename: %s\n", filePath->value); + + printf("Source: %s\n", content->value); + + response->appendObject( content ); + + response += "\r\n"; + + + + filePath->free(); + +} + + +void main() { + + + cacheManager = new cache(); + + + + http * serverInstance = new http(); + + serverInstance->createServer( handleRequest ); + + serverInstance->listen( 8080 ); + +} \ No newline at end of file diff --git a/application/source/extends.c b/application/source/extends.c new file mode 100644 index 0000000..2fca9cd --- /dev/null +++ b/application/source/extends.c @@ -0,0 +1,87 @@ + +#include + +class classB{ + + int propertyFromC = 111; + + void methodFromC() { + + printf("Please print much much.."); + + } + +} + + +class classA{ + + int propertyFromC = 100; + + void methodFromC() { + + printf("Don't print soo much..."); + + } + +} + + +class inherit extends a, classB, classA{ + + int propertyFromC = 20; + + void methodFromC() { + + printf("this is a method from c\n\n"); + + + + printf("from c: a : %i\n", this->propertyFromA); + printf("from c: b : %i\n", this->propertyFromB); + printf("from c: c : %i\n", this->propertyFromC); + + this->propertyFromB++; + + this->methodFromA(); + + this->propertyFromB++; + + this->methodFromB(); + + + } + +} + +class a extends b{ + + int propertyFromA = 10; + + void methodFromA() { + + printf("this is a method from a\n\n"); + + printf("from a: a : %i\n", this->propertyFromA); + printf("from a: b : %i\n", this->propertyFromB); + printf("from a: c : %i\n", this->propertyFromC); + + } + +} + +class b{ + + int propertyFromB = 1234; + + void methodFromB() { + + printf("this is a method from b\n\n"); + + printf("from b: a : %i\n", this->propertyFromA); + printf("from b: b : %i\n", this->propertyFromB); + printf("from b: c : %i\n", this->propertyFromC); + + } + +} diff --git a/application/source/file.c b/application/source/file.c new file mode 100644 index 0000000..45e7360 --- /dev/null +++ b/application/source/file.c @@ -0,0 +1,10 @@ + +#include "text.h" + +class file{ + + char * filePath; + + text * content; + +} \ No newline at end of file diff --git a/application/source/fileSystem.c b/application/source/fileSystem.c new file mode 100755 index 0000000..5486463 --- /dev/null +++ b/application/source/fileSystem.c @@ -0,0 +1,264 @@ + + +#include + +#include + +#include + +#include + +#include + +#include + + + +#include + +#include // "DIR *" + +#include // access + +#include + +#include + + +extern struct fileSystem * filesystem; + +class fileSystem{ + + void writeFile( char * filepath, char * data ) + { + FILE *fp = fopen( filepath, "wb" ); + + if (fp != NULL) + { + fputs( data, fp ); + + fclose( fp ); + } + + } + + struct array * readDir( char * filePath ) { + + DIR * dir; + + struct dirent * entry; + + struct array * files = new array(); + + if ( ( dir = opendir( filePath ) ) == NULL ){ + + perror("opendir() error"); + + } else { + + while( ( entry = readdir( dir ) ) != NULL ) { + + char * filename = (char *)entry->d_name; + + if ( strcmp( filename, ".." ) != 0 && strcmp( filename, "." ) != 0 ) { + + array_add( files, filename ); + + //printf("%s\n", filename); + + } + } + } + + return files; + //closedir(dir); + } + + + struct text * readFile( char * name, char * mode ) { + + char * readMode; + + if( mode == "utf8" ) { + + readMode = "r"; + + } else { + + readMode = "rb"; + + } + + FILE * file = fopen( name, readMode ); + + if ( file == NULL ) { + + fprintf( stderr, "Error: Can't open file '%s'.", name ); + + exit( EXIT_FAILURE ); + + } + + fseek( file, 0, SEEK_END ); + + long length = ftell( file ); + + //printf("buffer length is '%i' \n\n", length); + + fseek( file, 0, SEEK_SET ); + + char * buffer = malloc( sizeof( char ) * ( length + 1 ) ); + + fread( buffer, sizeof( char ), length, file ); + + fclose( file ); + + if( mode == "utf8" ) { + + buffer[ length ] = 0; + + } + + text * output = new text( "" ); + + output->length = 0; + + output->appendBinary( buffer, length ); + + return output; + + } + + + + char * readBinaryFile( char * name, char * mode, int * size ) { + + char * readMode; + + if( mode == "utf8" ) { + + readMode = "r"; + + } else { + + readMode = "rb"; + + printf("readmode = rb binary\n\n"); + + } + + FILE * file = fopen( name, readMode ); + + if ( file == NULL ) { + + fprintf( stderr, "Error: Can't open file '%s'.", name ); + + exit( EXIT_FAILURE ); + + } + + fseek( file, 0, SEEK_END ); + + long length = ftell( file ); + + printf("buffer length is '%i' \n\n", length); + + fseek( file, 0, SEEK_SET ); + + char * buffer = malloc( sizeof( char ) * ( length + 1 ) ); + + buffer[ length ] = '\0'; + + fread( buffer, sizeof( char ), length, file ); + + fclose( file ); + + + //buffer[ length ] = 0; + + *size = length; + + printf("strlen: %i \n\n", length); + + return buffer; + + } + + int ensureDirectory( char * path ) { + + char * pathCopy = path->copy(); + + struct array * parts = pathCopy->split( "/" ); + + int count = parts->length( ); + + for ( int i = 1; i < count; ++i ) + { + struct array * tempParts = pathCopy->split( "/" ); + + for ( int j = 0; j < count-i-1; ++j ) + { + tempParts->pop(); + } + + char * tempPath = tempParts->join( "/" ); + + if( this->exists( tempPath ) ) { + + } else { + + this->makeDirectory( tempPath ); + + } + + } + + return 1; + + } + + int makeDirectory( char * path ) { + + if ( this->exists( path ) == NULL ) { + + mkdir( path, 0700 ); + + } + + return 1; + + } + + int exists( char * path ) { + + if ( access( path, F_OK ) == 0 ) { + + return 1; + + } else { + + return 0; + + } + + } + + int isDirectory( char * path ) { + + struct stat path_stat; + + stat( path, & path_stat ); + + if( S_ISREG( path_stat.st_mode ) ) { + + return 0; + + } else { + + return 1; + + } + + } + +} \ No newline at end of file diff --git a/application/source/header.c b/application/source/header.c new file mode 100644 index 0000000..c07891e --- /dev/null +++ b/application/source/header.c @@ -0,0 +1,8 @@ + +class header{ + + char * name; + + char * value; + +} \ No newline at end of file diff --git a/application/source/headers.c b/application/source/headers.c new file mode 100644 index 0000000..a09d524 --- /dev/null +++ b/application/source/headers.c @@ -0,0 +1,167 @@ + +#include "array.h" + +#include "header.h" + +class headerManager{ + + struct array * headers = new array(); + + parse( char * headerContent ) { + + array * headerRows = headerContent->split("\n"); + + int headerCount = headerRows->length(); + + for (int i = 1; i < headerCount; ++i) + { + + char * headerRow = headerRows->get( i ); + + array * headerRowParts = headerRow->split(":"); + + int headerRowPartsCount = headerRowParts->length(); + + + if( headerRowPartsCount == 2 ) { + + char * headerName = headerRowParts->get( 0 ); + + char * headerValue = headerRowParts->get( 1 ); + + //printf("%-20s %-30s \n", headerName, headerValue->removeWhitespace()); + + //printf("header value: %s\n\n", headerValue->removeWhitespace() ); + + this->add( headerName, headerValue->removeWhitespace() ); + + } + + } + + printf("\n\n"); + + } + + void display() { + + struct array * headerRows = this->headers; + + int headerCount = headerRows->length(); + + for (int i = 0; i < headerCount; ++i) + { + struct header * headerInstance = headerRows->get( i ); + + printf("%-20s %-30s \n", headerInstance->name, headerInstance->value); + + } + + } + + void add( char * name, char * value ) { + + header * headerInstance = new header(); + + headerInstance->name = name; + + headerInstance->value = value; + + this->headers->add( headerInstance ); + + } + + void set( char * name, char * value ) { + + struct header * headerInstance = this->get( name ); + + if( headerInstance == NULL ) { + + this->add( name, value ); + + } else { + + int headerIndex = this->getHeaderIndex( name ); + + array * headers = this->headers; + + + header * headerInstance = headers->get( headerIndex ); + + headerInstance->value = value; + + + } + + } + + int getHeaderIndex( char * name ) { + + array * headers = this->headers; + + int count = headers->length(); + + for (int i = 0; i < count; ++i) + { + + header * headerInstance = headers->get( i ); + + if( headerInstance->name == name ) { + + return i; + + } + + } + + return -1; + + } + + char * getValue( char * name ) { + + array * headers = this->headers; + + int count = headers->length(); + + for (int i = 0; i < count; ++i) + { + + header * headerInstance = headers->get( i ); + + if( headerInstance->name == name ) { + + return headerInstance->value; + + } + + } + + return NULL; + + } + + header * get( char * name ) { + + array * headers = this->headers; + + int count = headers->length(); + + for (int i = 0; i < count; ++i) + { + + header * headerInstance = headers->get( i ); + + if( headerInstance->name == name ) { + + return headerInstance; + + } + + } + + return NULL; + + } + +} diff --git a/application/source/http.c b/application/source/http.c new file mode 100644 index 0000000..8c9497c --- /dev/null +++ b/application/source/http.c @@ -0,0 +1,507 @@ +// webserver.c + + +#include "./fileSystem.h" + +#include "./text.h" + +#include "./mimeTypes.h" + + + +#include + +#include + +#include + + +#include + +#include + +#include + +#include + +#include + +#include + + +#include + +#include + + +#include + + + + +class http{ + + int socket; + + struct sockaddr_in * hostAddress = malloc( sizeof( struct sockaddr_in ) ); + + int hostAddresslength = sizeof( struct sockaddr_in ); + + struct fileSystem * filesystem = new fileSystem(); + + struct mimeTypes * mimetypes = new mimeTypes(); + + struct headerManager * headers = new headerManager(); + + int useSSL = -1; + + + SSL_CTX * sslContext; + + + + void ( * requestCallback )( struct request * requestInstance, struct text * response ); + + + void createServer( void ( * requestCallback )( request * req, text * response ) ) { + + this->requestCallback = requestCallback; + + + if( this->useSSL == 1 ) { + + this->initializeOpenSSL(); + + } + + printf("after initializeOpenSSL\n\n"); + + } + + initializeOpenSSL() { + + // OpenSSL 1.1.0 or above initializes by itself + //SSL_load_error_strings(); + //ssl_load_ciphers(); + //OpenSSL_add_all_algorithms(); + + /* Lets get nice error messages */ + SSL_load_error_strings(); + + OpenSSL_add_ssl_algorithms(); + + SSLeay_add_ssl_algorithms(); + + return; + + } + + int listen( int port ) { + + this->socket = socket( AF_INET, SOCK_STREAM, 0 ); + + int iSetOption = 1; + + setsockopt( this->socket, SOL_SOCKET, SO_REUSEADDR, ( char * ) & iSetOption, sizeof( iSetOption ) ); + + if ( this->socket == -1 ) { + + perror("webserver (socket)"); + + exit( 0 ); + + } else { + + printf("socket created successfully\n"); + + } + + + // Create the address to bind the socket to + this->hostAddress->sin_family = AF_INET; + + this->hostAddress->sin_port = htons( port ); + + this->hostAddress->sin_addr.s_addr = htonl( INADDR_ANY ); + + + // Bind the socket to the address + if ( bind( this->socket, ( struct sockaddr * ) this->hostAddress, this->hostAddresslength ) != 0 ) { + + perror("webserver (bind)"); + + exit( 0 ); + + } else { + + printf("socket successfully bound to address\n"); + + } + + // Listen for incoming connections + if ( listen( this->socket, SOMAXCONN ) != 0 ) { + + perror("webserver (listen)"); + + exit( 0 ); + + } else { + + printf("server listening for connections\n"); + + } + + + + for (;;) { + + this->acceptConnection( ); + + } + + + //this->DestroySSL(); + + printf("exit"); + + + return 0; + + } + + char * getExtension( char * path ) { + + array * parts = path->split("."); + + int count = parts->length(); + + return parts->get( count - 1 ); + + } + + logRequest( request * requestInstance ) { + + printf("server address: [%s:%u]\n", requestInstance->address, requestInstance->port ); + + printf("mimeType: %-30s \n", requestInstance->mimeType); + + printf("header: %-30s \n", requestInstance->extension ); + + printf("method: %-30s \n", requestInstance->method ); + + printf("version: %-30s \n\n", requestInstance->version ); + + } + + acceptConnection( ) { + + fileSystem * filesystem = this->filesystem; + + mimeTypes * mimetypes = this->mimetypes; + + text * response = new text(""); + + + + char buffer[ 4096 ]; + + // Create client address + struct sockaddr_in client_addr; + + int client_addrlen = sizeof(client_addr); + + // Accept incoming connections + int socketConnection = accept( this->socket, + (struct sockaddr *)this->hostAddress, + ( socklen_t * ) & this->hostAddresslength ); + + +/* + + struct rusage r_usage; + + getrusage(RUSAGE_SELF,&r_usage); + // Print the maximum resident set size used (in kilobytes). + + printf("Memory usage: %ld kilobytes\n\n",r_usage.ru_maxrss); + + free( r_usage ); +*/ + + SSL * ssl = NULL; + + if( this->useSSL == 1 ) { + + const SSL_METHOD * method = SSLv23_server_method(); + + this->sslContext = SSL_CTX_new( method ); + + if ( this->sslContext == NULL ) { + + printf("Error loading SSL_CTX_NEW '%s'\n\n", stderr); + + } + + SSL_CTX_set_options( this->sslContext, SSL_OP_SINGLE_DH_USE ); + + int use_cert = SSL_CTX_use_certificate_file( this->sslContext, "/etc/letsencrypt/live/unifyjs.org/fullchain.pem" , SSL_FILETYPE_PEM ); + + int use_prv = SSL_CTX_use_PrivateKey_file( this->sslContext, "/etc/letsencrypt/live/unifyjs.org/privkey.pem", SSL_FILETYPE_PEM ); + + if( use_cert != 1 ) { + + printf( "error: SSL_CTX_use_certificate_file\n\n" ); + + } + + if( use_prv != 1 ) { + + printf( "error: SSL_CTX_use_PrivateKey_file\n\n" ); + + } + + if ( !SSL_CTX_check_private_key(this->sslContext) ) { + + printf("Private key does not match the certificate public key\n"); + + // initiate page describing error. + } + + ssl = SSL_new( this->sslContext ); + + SSL_set_fd( ssl, socketConnection ); + + //Here is the SSL Accept portion. Now all reads and writes must use SSL + int ssl_err = SSL_accept( ssl ); // SSL routines:SSL_UNDEFINED_FUNCTION:called a function you should not call + + //printf ("SSL connection using %s\n", SSL_get_cipher( ssl ) ); + + //ERR_print_errors_fp( stderr ); + + if( ssl_err == 0 ){ + + printf("SSL_accept returned zero\n"); + + } + + + int n; + + if( ssl_err < 0 ) { + + int err; + + if( ( err = SSL_get_error(ssl,n ) ) == SSL_ERROR_WANT_READ) { + + printf("SSL_accept wants more data\n"); + + return ; + + } + + exit(7); + + } + + +/* + + printf ("SSL connection using %s\n", SSL_get_cipher (this->sslContext)); + + #define CHK_NULL(x) if ((x)==NULL) exit (1) + + X509* client_cert; + + char* str; + + // Get client's certificate (note: beware of dynamic allocation) - opt + + client_cert = SSL_get_peer_certificate (this->sslContext); + + if ( client_cert != NULL ) { + + printf ("Client certificate:\n"); + + str = X509_NAME_oneline (X509_get_subject_name (client_cert), 0, 0); + + CHK_NULL(str); + + printf ("\t subject: %s\n", str); + + OPENSSL_free (str); + + str = X509_NAME_oneline (X509_get_issuer_name (client_cert), 0, 0); + + CHK_NULL(str); + + printf ("\t issuer: %s\n", str); + + OPENSSL_free (str); + + X509_free (client_cert); + + } else { + + printf ("Client does not have certificate.\n"); + + } + + + + if ( socketConnection == -1 ) { + + perror("webserver (accept)"); + + return; + + } + */ + + //printf("connection accepted2\n\n"); + + + + } else { + printf("connection accepted\n\n"); + + // Get client address + int sockn = getsockname( socketConnection, + ( struct sockaddr * ) &client_addr, + ( socklen_t * ) &client_addrlen); + + + if ( sockn == -1 ) { + + perror("webserver (getsockname)"); + + } + + } + + int valread; + + if( this->useSSL == 1 ) { + + valread = SSL_read( ssl, buffer, 4096 - 1 ); + + } else { + + printf("read without ssl\n\n"); + + int valread = read( socketConnection, buffer, 4096 -1 ); + + if ( valread == -1 ) { + + perror("webserver (read)"); + + //return; + + } + + } + + + if ( valread == -1 ) { + + perror("webserver (read)"); + + + } + + + request * requestInstance = new request(); + + + sscanf( buffer, "%s %s %s", requestInstance->method, requestInstance->url, requestInstance->version ); + + + requestInstance->address = inet_ntoa( client_addr.sin_addr ); + + requestInstance->port = ntohs( client_addr.sin_port ); + + requestInstance->extension = this->getExtension( requestInstance->url ); + + requestInstance->mimeType = mimetypes->getByExtension( requestInstance->extension ); + + this->requestCallback( requestInstance, response ); + + + + + //printf("response: %s",response->value); + + int writeResponse; + + if( this->useSSL == 1 ) { + + writeResponse = SSL_write( ssl, response->value, response->length ); + + } else { + + // Write to the socket + int writeResponse = write( socketConnection, response->value, response->length ); + + printf("close connection"); + + if ( writeResponse == -1 ) { + + perror("webserver (write)"); + + return; + + } + } + + if ( writeResponse == -1 ) { + + perror("webserver (write)"); + + return; + + } else { + + //printf("written a response\n"); + + } + + + //free( buffer ); + + //SSL_free( writeResponse ); + + //response->free(); + + //requestInstance->free(); + + close( socketConnection ); + + //SSL_free( response->value ); + + + + // SSL_CTX_free( this->sslContext ); + // close( this->socket ); + + + } + + void dump_buffer(void *buffer, int buffer_size) + { + int i; + + for(i = 0;i < buffer_size;++i){ + + printf( "%c", ( (char *) buffer )[i]); + + } + + } + +} + +void abort() { + + +} +//kill -9 $(lsof -t -i tcp:8080) + diff --git a/application/source/http.c.old b/application/source/http.c.old new file mode 100644 index 0000000..9375e6b --- /dev/null +++ b/application/source/http.c.old @@ -0,0 +1,504 @@ +// webserver.c + + +#include "./fileSystem.h" + +#include "./text.h" + +#include "./mimeTypes.h" + + + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + + +#include + +#include + + +#include + + + + +class http{ + + int socket; + + struct sockaddr_in * hostAddress = malloc( sizeof( struct sockaddr_in ) ); + + int hostAddresslength = sizeof( struct sockaddr_in ); + + struct fileSystem * filesystem = new fileSystem(); + + struct mimeTypes * mimetypes = new mimeTypes(); + + struct headerManager * headers = new headerManager(); + + int useSSL = -1; + + + SSL_CTX * sslContext; + + + + void ( * requestCallback )( struct request * requestInstance, struct text * response ); + + + void createServer( void ( * requestCallback )( request * req, text * response ) ) { + + this->requestCallback = requestCallback; + + + if( this->useSSL == 1 ) { + + this->initializeOpenSSL(); + + } + + printf("after initializeOpenSSL\n\n"); + + } + + initializeOpenSSL() { + + // OpenSSL 1.1.0 or above initializes by itself + //SSL_load_error_strings(); + //ssl_load_ciphers(); + //OpenSSL_add_all_algorithms(); + + /* Lets get nice error messages */ + SSL_load_error_strings(); + + OpenSSL_add_ssl_algorithms(); + + SSLeay_add_ssl_algorithms(); + + return; + + } + + int listen( int port ) { + + this->socket = socket( AF_INET, SOCK_STREAM, 0 ); + + int iSetOption = 1; + + setsockopt( this->socket, SOL_SOCKET, SO_REUSEADDR, ( char * ) & iSetOption, sizeof( iSetOption ) ); + + if ( this->socket == -1 ) { + + perror("webserver (socket)"); + + exit( 0 ); + + } else { + + printf("socket created successfully\n"); + + } + + + // Create the address to bind the socket to + this->hostAddress->sin_family = AF_INET; + + this->hostAddress->sin_port = htons( port ); + + this->hostAddress->sin_addr.s_addr = htonl( INADDR_ANY ); + + + // Bind the socket to the address + if ( bind( this->socket, ( struct sockaddr * ) this->hostAddress, this->hostAddresslength ) != 0 ) { + + perror("webserver (bind)"); + + exit( 0 ); + + } else { + + printf("socket successfully bound to address\n"); + + } + + // Listen for incoming connections + if ( listen( this->socket, SOMAXCONN ) != 0 ) { + + perror("webserver (listen)"); + + exit( 0 ); + + } else { + + printf("server listening for connections\n"); + + } + + + + for (;;) { + + this->acceptConnection( ); + + } + + + //this->DestroySSL(); + + printf("exit"); + + + return 0; + + } + + char * getExtension( char * path ) { + + array * parts = path->split("."); + + int count = parts->length(); + + return parts->get( count - 1 ); + + } + + logRequest( request * requestInstance ) { + + printf("server address: [%s:%u]\n", requestInstance->address, requestInstance->port ); + + printf("mimeType: %-30s \n", requestInstance->mimeType); + + printf("header: %-30s \n", requestInstance->extension ); + + printf("method: %-30s \n", requestInstance->method ); + + printf("version: %-30s \n\n", requestInstance->version ); + + } + + acceptConnection( ) { + + fileSystem * filesystem = this->filesystem; + + mimeTypes * mimetypes = this->mimetypes; + + text * response = new text(""); + + + + char buffer[ 4096 ]; + + // Create client address + struct sockaddr_in client_addr; + + int client_addrlen = sizeof(client_addr); + + // Accept incoming connections + int socketConnection = accept( this->socket, + (struct sockaddr *)this->hostAddress, + ( socklen_t * ) & this->hostAddresslength ); + + +/* + + struct rusage r_usage; + + getrusage(RUSAGE_SELF,&r_usage); + // Print the maximum resident set size used (in kilobytes). + + printf("Memory usage: %ld kilobytes\n\n",r_usage.ru_maxrss); + + free( r_usage ); +*/ + + SSL * ssl = NULL; + + if( this->useSSL == 1 ) { + + const SSL_METHOD * method = SSLv23_server_method(); + + this->sslContext = SSL_CTX_new( method ); + + if ( this->sslContext == NULL ) { + + printf("Error loading SSL_CTX_NEW '%s'\n\n", stderr); + + } + + SSL_CTX_set_options( this->sslContext, SSL_OP_SINGLE_DH_USE ); + + int use_cert = SSL_CTX_use_certificate_file( this->sslContext, "/etc/letsencrypt/live/unifyjs.org/fullchain.pem" , SSL_FILETYPE_PEM ); + + int use_prv = SSL_CTX_use_PrivateKey_file( this->sslContext, "/etc/letsencrypt/live/unifyjs.org/privkey.pem", SSL_FILETYPE_PEM ); + + if( use_cert != 1 ) { + + printf( "error: SSL_CTX_use_certificate_file\n\n" ); + + } + + if( use_prv != 1 ) { + + printf( "error: SSL_CTX_use_PrivateKey_file\n\n" ); + + } + + if ( !SSL_CTX_check_private_key(this->sslContext) ) { + + printf("Private key does not match the certificate public key\n"); + + // initiate page describing error. + } + + ssl = SSL_new( this->sslContext ); + + SSL_set_fd( ssl, socketConnection ); + + //Here is the SSL Accept portion. Now all reads and writes must use SSL + int ssl_err = SSL_accept( ssl ); // SSL routines:SSL_UNDEFINED_FUNCTION:called a function you should not call + + //printf ("SSL connection using %s\n", SSL_get_cipher( ssl ) ); + + //ERR_print_errors_fp( stderr ); + + if( ssl_err == 0 ){ + + printf("SSL_accept returned zero\n"); + + } + + + int n; + + if( ssl_err < 0 ) { + + int err; + + if( ( err = SSL_get_error(ssl,n ) ) == SSL_ERROR_WANT_READ) { + + printf("SSL_accept wants more data\n"); + + return ; + + } + + exit(7); + + } + + +/* + + printf ("SSL connection using %s\n", SSL_get_cipher (this->sslContext)); + + #define CHK_NULL(x) if ((x)==NULL) exit (1) + + X509* client_cert; + + char* str; + + // Get client's certificate (note: beware of dynamic allocation) - opt + + client_cert = SSL_get_peer_certificate (this->sslContext); + + if ( client_cert != NULL ) { + + printf ("Client certificate:\n"); + + str = X509_NAME_oneline (X509_get_subject_name (client_cert), 0, 0); + + CHK_NULL(str); + + printf ("\t subject: %s\n", str); + + OPENSSL_free (str); + + str = X509_NAME_oneline (X509_get_issuer_name (client_cert), 0, 0); + + CHK_NULL(str); + + printf ("\t issuer: %s\n", str); + + OPENSSL_free (str); + + X509_free (client_cert); + + } else { + + printf ("Client does not have certificate.\n"); + + } + + + + if ( socketConnection == -1 ) { + + perror("webserver (accept)"); + + return; + + } + */ + + //printf("connection accepted2\n\n"); + + + + } else { + printf("connection accepted\n\n"); + + // Get client address + int sockn = getsockname( socketConnection, + ( struct sockaddr * ) &client_addr, + ( socklen_t * ) &client_addrlen); + + + if ( sockn == -1 ) { + + perror("webserver (getsockname)"); + + } + + } + + int valread; + + if( this->useSSL == 1 ) { + + valread = SSL_read( ssl, buffer, 4096 - 1 ); + + } else { + + printf("read without ssl\n\n"); + + int valread = read( socketConnection, buffer, 4096 -1 ); + + if ( valread == -1 ) { + + perror("webserver (read)"); + + //return; + + } + + } + + + if ( valread == -1 ) { + + perror("webserver (read)"); + + + } + + + request * requestInstance = new request(); + + + sscanf( buffer, "%s %s %s", requestInstance->method, requestInstance->url, requestInstance->version ); + + + requestInstance->address = inet_ntoa( client_addr.sin_addr ); + + requestInstance->port = ntohs( client_addr.sin_port ); + + requestInstance->extension = this->getExtension( requestInstance->url ); + + requestInstance->mimeType = mimetypes->getByExtension( requestInstance->extension ); + + this->requestCallback( requestInstance, response ); + + + + + //printf("response: %s",response->value); + + int writeResponse; + + if( this->useSSL == 1 ) { + + writeResponse = SSL_write( ssl, response->value, response->length ); + + } else { + + // Write to the socket + int writeResponse = write( socketConnection, response->value, response->length ); + + printf("close connection"); + + if ( writeResponse == -1 ) { + + perror("webserver (write)"); + + return; + + } + } + + if ( writeResponse == -1 ) { + + perror("webserver (write)"); + + return; + + } else { + + //printf("written a response\n"); + + } + + + //free( buffer ); + + //SSL_free( writeResponse ); + + //response->free(); + + //requestInstance->free(); + + close( socketConnection ); + + //SSL_free( response->value ); + + + + // SSL_CTX_free( this->sslContext ); + // close( this->socket ); + + + } + + void dump_buffer(void *buffer, int buffer_size) + { + int i; + + for(i = 0;i < buffer_size;++i){ + + printf( "%c", ( (char *) buffer )[i]); + + } + + } + +} + +void abort() { + + +} +//kill -9 $(lsof -t -i tcp:8080) + diff --git a/application/source/int.c b/application/source/int.c new file mode 100755 index 0000000..9465538 --- /dev/null +++ b/application/source/int.c @@ -0,0 +1,22 @@ + +#include + +class int{ + + char * toText( ) { + + char * textNumber = malloc( sizeof( char ) * 20 ); + + sprintf( textNumber, "%d", this ); + + return textNumber; + + } + + int negative() { + + return 12; + + } + +} \ No newline at end of file diff --git a/application/source/integerArray.c b/application/source/integerArray.c new file mode 100644 index 0000000..93e2a1f --- /dev/null +++ b/application/source/integerArray.c @@ -0,0 +1,167 @@ + +#include + +#include + +#include + +#include + +#include + +class integerArray{ + + int capacity = 10; + + int total = 0; + + int * items = malloc( 10000000 ); + + int length() + { + + return this->total; + + } + + float get( int index ) + { + + if ( index >= 0 && index < this->total ){ + + return this->items[index]; + + } + + return NULL; + + } + + void set( int index, float item ) + { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + void resize( int capacity ) + { + + int * items = realloc( this->items, sizeof( int ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + void addVector2( struct vector2 * item ) { + + this->add( item->x ); + + this->add( item->y ); + + } + + void addVector3( struct vector3 * item ) { + + this->add( item->x ); + + this->add( item->y ); + + this->add( item->z ); + + } + + void add( int item ) + { + + if ( this->capacity == this->total ){ + + this->resize( this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + void delete( int index ) + { + if ( index < 0 || index >= this->total ){ + + return; + + } + + this->items[index] = 0.0; + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + this->items[i + 1] = 0.0; + + } + + this->total--; + + if ( this->total > 0 && this->total == this->capacity / 4 ){ + + this->resize( this->capacity / 2 ); + + } + + } + + int array_push( int item ) { + + this->add( item ); + + return this->total; + + } + + void unshift( int item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + this->resize( this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } + + int pop() { + + int length = this->total; + + int lastIndex = length - 1; + + int lastItem = this->get( lastIndex ); + + this->delete( lastIndex ); + + return lastItem; + + } + + +} \ No newline at end of file diff --git a/application/source/mimeTypes.c b/application/source/mimeTypes.c new file mode 100644 index 0000000..dc9f346 --- /dev/null +++ b/application/source/mimeTypes.c @@ -0,0 +1,66 @@ + +#include "array.h" + + + +class mimeTypes{ + + array * extensions = new array(); + + array * mimeTypes = new array(); + + constructor() { + + this->add("html", "text/html"); + + this->add("css", "text/css"); + + this->add("ttf", "application/x-font-ttf"); + + this->add("png", "image/png"); + + this->add("svg", "image/svg+xml"); + + } + + void add( char * extension, char * mimeType ) { + + struct array * extensions = this->extensions; + + extensions->add( extension ); + + + struct array * mimeTypes = this->mimeTypes; + + mimeTypes->add( mimeType ); + + } + + char * getByExtension( char * extension ) { + + struct array * extensions = this->extensions; + + struct array * mimeTypes = this->mimeTypes; + + int count = extensions->length(); + + for (int i = 0; i < count; ++i) + { + + char * currentExtension = extensions->get( i ); + + if( currentExtension == extension ) { + + char * mimeType = mimeTypes->get( i ); + + return mimeType; + + } + + } + + return "no-mimetype"; + + } + +} \ No newline at end of file diff --git a/application/source/reflection.c b/application/source/reflection.c new file mode 100644 index 0000000..b6d8b20 --- /dev/null +++ b/application/source/reflection.c @@ -0,0 +1,13 @@ + + +class reflection{ + + test() { + + + + + } + + +} \ No newline at end of file diff --git a/application/source/request.c b/application/source/request.c new file mode 100644 index 0000000..1c6c268 --- /dev/null +++ b/application/source/request.c @@ -0,0 +1,61 @@ + +#include "stdlib.h" + +#include "headers.h" + + +#define BUFFER_SIZE 1024 + +class request{ + + char * connection = malloc( BUFFER_SIZE ); + + char * address = malloc( BUFFER_SIZE ); + + int port; + + char * url = malloc( BUFFER_SIZE ); + + char * method = malloc( BUFFER_SIZE ); + + char * version = malloc( BUFFER_SIZE ); + + char * mimeType = malloc( BUFFER_SIZE ); + + char * extension = malloc( BUFFER_SIZE ); + + struct headerManager * headers = new headerManager(); + + void constructor() { + + + } + + free() { + + +/* + free( this->connection ); + + free( this->address ); + + free( this->port ); + + free( this->url ); + + free( this->method ); + + free( this->version ); + + free( this->mimeType ); + + free( this->headers ); + + */ + + free( this ); + + + } + +} \ No newline at end of file diff --git a/application/source/sqlite.c b/application/source/sqlite.c new file mode 100755 index 0000000..aff8244 --- /dev/null +++ b/application/source/sqlite.c @@ -0,0 +1,817 @@ + + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include "console.h" + + + + + + +class sqlite{ + + + sqlite3 * db; + + sqlite3_stmt * res; + + char * value; + + char * selectedModel; + + + void constructor( char * filePath ) + { + this->value = "good"; + + this.connect( filePath ); + + } + + void connect( char * filePath ) { + + printf("\n\ntrying to connect.. %s\n\n", filePath); + + int rc = sqlite3_open( filePath, & this->db ); + + if ( rc != SQLITE_OK ) { + + printf( "Cannot open database: %s\n", sqlite3_errmsg( this->db ) ); + + sqlite3_close( this->db ); + + console->error( ( char * ) sqlite3_errmsg( this->db ) ); + + return; + + } + + rc = sqlite3_prepare_v2( this->db, "SELECT SQLITE_VERSION()", -1, & this->res, 0 ); + + if (rc != SQLITE_OK) { + + console->error( ( char * ) sqlite3_errmsg( this->db ) ); + + sqlite3_close( this->db ); + + return; + + } + + rc = sqlite3_step(this->res); + + /*if ( rc == SQLITE_ROW ) { + + printf( "%s\n", ( char * ) sqlite3_column_text( this->res, 0 ) ); + + } + + printf( "Success \n"); +*/ + //return 1; + + } + + void free() { + + sqlite3_finalize( this->res ); + + sqlite3_close( this->db ); + + } + + void selectModel( char * className ) { + + this->selectedModel = className; + + /* + + printf("select className: %s\n", className); + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + printf("class index: %i\n", classIndex); + + + int propertyIndex = getPropertyIndexByPropertyName( classIndex, "username" ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + char ** propertyNames = getPropertiesByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + + printf("propertyIndex: %i\n\n", propertyIndex); + + for (int i = 0; i < propertyCount; ++i) + { + + char * propertyName = propertyNames[i]; + + int propertyOffset = propertyOffsets[i]; + + + printf("propertyName: %s offset: %i\n", propertyName, propertyOffset); + } + + + + + + char * shortPointer = malloc( sizeof( char * ) * 100000 ); + + void * * voidArray = malloc( sizeof( void * ) * 100000 ); + + int structByteSize; + + getArrayByClassIndex( 100000, voidArray, shortPointer, &structByteSize, 0 ); + + */ + } + + void createTable() { + + char * errorMessage = 0; + + char *sql = "DROP TABLE IF EXISTS user;" + "CREATE TABLE user( id INT, username TEXT, userlevel INT, hash TEXT );"; + + int rc = sqlite3_exec(this->db, sql, 0, 0, &errorMessage); + + if ( rc != SQLITE_OK ) { + + printf( "SQL error: %s\n", errorMessage ); + + sqlite3_free( errorMessage ); + + sqlite3_close(this->db); + + + } + + } + +/* + // Fast but unsave -> sql injection + void addRowsFast( array * insertArray ) { + + array * copy = insertArray; + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + text * query = new text( "" ); + + query->append( "INSERT INTO " ); + + query->append( this->selectedModel ); + + + sqlite3_stmt * result; + + + char * * propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + + + query->append( " ( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + // join table because this is an class + continue; + + } + + if( propertyIndex > 0 ) { + + query->append( ", " ); + + } + + query->append( propertyName ); + + } + + query->append( " ) " ); + + query->append(" VALUES " ); + + + + int insertItemCount = copy->total; + + char * voidArray = ( char * ) copy->items; + + //sqlite3_exec(result, "BEGIN TRANSACTION;", NULL, NULL, NULL); + + for (int i = 0; i < insertItemCount; ++i) + { + char * pointer = copy->get( i ); + + + + if( i > 0 ) { + + query->append( ", " ); + + } + + query->append( "( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + // join table because this is an class + continue; + + } + + int propertyOffset = propertyOffsets[propertyIndex]; + + int propertyDatatypeIndex = getPropertyDatatypeIndex( datatypeIndices, propertyIndex ); + + if( propertyIndex > 0 ) { + + query->append( ", " ); + + } + + if( propertyDatatypeIndex == -5 ) { + + int value = *( int * )(pointer + propertyOffset); + + char * textNumber = malloc( sizeof( char ) * 20 ); + + // Boost Spirit.Karma is faster + sprintf( textNumber, "%d", value ); + + query->append( textNumber ); + + } else if( propertyDatatypeIndex == -3 ) { + + char * columnValueCopy = ( char * ) malloc( 8 ); + + char * value = ( char * ) ( pointer + propertyOffset ); + + strncpy( &columnValueCopy, value, 8 ); + + query->append( "'" ); + + query->append( columnValueCopy ); + + query->append( "'" ); + + + } + + } + + query->append( " )" ); + + } + + //sqlite3_exec(result, "END TRANSACTION;", NULL, NULL, NULL); + sqlite3_prepare_v2( this->db, query->buffer, -1, &result, 0 ); + + sqlite3_step( result ); + + sqlite3_finalize( result ); + + //printf("insert query: %s\n", query->buffer); + + } +*/ + + + + + + + + void addRows( array * insertArray ) { + + array * copy = insertArray; + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + text * query = new text( "" ); + + query->append( "INSERT INTO " ); + + query->append( this->selectedModel ); + + + sqlite3_stmt * result; + + + char * * propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + + + query->append( " ( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + // join table because this is an class + continue; + + } + + if( propertyIndex > 0 ) { + + query->append( ", " ); + + } + + query->append( propertyName ); + + } + + query->append( " ) " ); + + query->append( " VALUES ( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + // join table because this is an class + continue; + + } + + if( propertyIndex > 0 ) { + + query->append( ", " ); + + } + + query->append( "?" ); + + } + + query->append(" ) " ); + + + + sqlite3_prepare_v2( this->db, query->value, -1, &result, 0 ); + + sqlite3_exec(this->db, this->selectedModel, NULL, NULL, 0); + + sqlite3_exec(this->db, "PRAGMA synchronous = OFF", NULL, NULL, 0); + + sqlite3_exec(this->db, "PRAGMA journal_mode = MEMORY", NULL, NULL, 0); + + + int insertItemCount = copy->total; + + char * voidArray = ( char * ) copy->items; + + //sqlite3_exec(result, "BEGIN TRANSACTION;", NULL, NULL, NULL); + + for (int i = 0; i < insertItemCount; ++i) + { + char * pointer = copy->get( i ); + + this->updateRow( result, propertyCount, propertyNames, propertyOffsets, datatypeIndices, pointer ); + + sqlite3_step( result ); + + sqlite3_reset( result ); + + } + + //sqlite3_exec(result, "END TRANSACTION;", NULL, NULL, NULL); + + sqlite3_finalize( result ); + + //printf("insert query: %s\n", query->buffer); + + } + + + + void updateRow( sqlite3_stmt * result, int propertyCount, char * * propertyNames, int * propertyOffsets, int * datatypeIndices, char * pointer ) { + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + int propertyOffset = propertyOffsets[propertyIndex]; + + int propertyDatatypeIndex = getPropertyDatatypeIndex( datatypeIndices, propertyIndex ); + + //printf("propertyName: %s offset: %i datatype: %i propertyIndex: %i\n", propertyName, propertyOffset, propertyDatatypeIndex, propertyIndex); + + if( propertyDatatypeIndex == -5 ) { + + int value = *( int * )(pointer + propertyOffset); + + //printf("integer value: %i %i\n", propertyIndex + 1, value); + + sqlite3_bind_int( result, propertyIndex + 1, value ); + + } else if( propertyDatatypeIndex == -3 ) { + + //char * columnValueCopy = ( char * ) malloc( 8 ); + + uintptr_t * value = ( uintptr_t * ) ( pointer + propertyOffset ); + + //strncpy( &columnValueCopy, value, 8 ); + + //printf("char * value: %i %s\n", propertyIndex + 1, columnValueCopy); + + sqlite3_bind_text( result, propertyIndex + 1, (char *) *value, -1, SQLITE_TRANSIENT ); + + } + + } + + //printf("\n\n\n"); + + } + + void update( void * row ) { + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + char ** propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + int propertyIdOfIndex = -1; + + + for ( int i = 0; i < propertyCount; ++i ) + { + char * propertyName = propertyNames[i]; + + //printf("propertyName: %s\n", propertyName); + + if( strcmp( propertyName, "id" ) == 0 ) { + + propertyIdOfIndex = i; + + break; + + } + } + + if( propertyIdOfIndex == -1 ) { + + printf("Class '%s' does not have an id field. "); + + } + + int idOffset = propertyOffsets[ propertyIdOfIndex ]; + + char * pointer = row; + + int id = *( pointer + idOffset ); + + text * query = new text( "" ); //"UPDATE user set username = '?' where id=?; " + + query->append( "UPDATE " ); + + query->append( this->selectedModel ); + + query->append( " SET " ); + + int activePropertyCount = 0; + + // set propertyCount + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + int datatypeIndex = datatypeIndices[propertyIndex]; + + // todo properties that are classes like "array" + if( datatypeIndex > 0 ) { + + continue; + + } + + activePropertyCount++; + + if( propertyIndex > 0 ) { + + query->append( ", " ); + + } + + query->append( propertyName ); + + query->append( " = ? " ); + + } + + query->append( " where id = ? " ); + + sqlite3_stmt * result; + + sqlite3_prepare_v2( this->db, query->value, -1, &result, 0 ); + + this->updateRow( result, propertyCount, propertyNames, propertyOffsets, datatypeIndices, pointer ); + + sqlite3_bind_int( result, activePropertyCount + 1, id ); + + //printf("propertyCount: %i %i\n", propertyCount, id ); + + sqlite3_step( result ); + + sqlite3_finalize( result ); + + //printf("update query: %s\n", query->buffer); + + } + + void addRow( void * row ) { + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + text * query = new text( "" ); + + query->append( "INSERT INTO " ); + + query->append( this->selectedModel ); + + + sqlite3_stmt * result; + + + char * * propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + char * pointer = row; + + + query->append( " ( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[ propertyIndex ]; + + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + // join table because this is an class + continue; + + } + + + if( propertyIndex > 0 ) { + + query->append( ", " ); + + } + + query->append( propertyName ); + + } + + query->append( " ) " ); + + query->append( " VALUES ( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + // set joined table id + continue; + + } + + + if( propertyIndex > 0 ) { + + query->append( ", " ); + + } + + query->append( "?" ); + + } + + query->append(" ) " ); + + + + // { + + sqlite3_prepare_v2( this->db, query->value, -1, &result, 0 ); + + this->updateRow( result, propertyCount, propertyNames, propertyOffsets, datatypeIndices, pointer ); + + sqlite3_step( result ); + + // } + + sqlite3_finalize( result ); + + //printf("query: %s\n", query->buffer); + + } + + struct array * fetchRows( char * sql ) { + + sqlite3_stmt * result; + + int rc = sqlite3_prepare_v2( this->db, sql, -1, &result, 0 ); + + if ( rc != SQLITE_OK ) { + + printf("Failed to execute statement: %s\n", sqlite3_errmsg( this->db ) ); + + } + +/* + if ( rc != SQLITE_ROW ) { + + printf("not rows found\n\n"); + + } +*/ + int rowIndex = 0; + + + //printf("select className: %s\n", this->selectedModel); + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + + //printf("class index: %i\n", classIndex); + + + int propertyIndex = getPropertyIndexByPropertyName( classIndex, "username" ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + char ** propertyNames = getPropertiesByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + + char * shortPointer = malloc( sizeof( char * ) * 100000 ); + + void * * voidArray = malloc( sizeof( void * ) * 100000 ); + + int structByteSize; + + getArrayByClassIndex( 1000, voidArray, &structByteSize, classIndex ); + + shortPointer = ( char * ) shortPointer; + + + while ( sqlite3_step( result ) != SQLITE_DONE ) { + + //if( rowsCount == 0 ) { + + int pointerIndex = ( rowIndex * ( structByteSize ) ); + + //==printf("pointerIndex: %i\n", pointerIndex); + + char * pointer = shortPointer + pointerIndex; + + int columnCount = sqlite3_data_count( result ); + + //printf("columnCount: %i\n\n", columnCount); + + for (int i = 0; i < columnCount; ++i) + { + + const char * columnName = sqlite3_column_name( result, i ); + + const int propertyIndex = getPropertyIndexByPropertyName( classIndex, (char *)columnName ); + + int propertyDatatypeIndex = getPropertyDatatypeIndex( datatypeIndices, propertyIndex ); + + int propertyOffset = getPropertyOffsetByPropertyIndex( propertyOffsets, propertyIndex ); + + //printf("sqlite3 column index: %i\n", i); + + //printf("sqlite3 columnName: %s\n", columnName); + + //printf("class property index: %i\n", propertyIndex); + + //printf("class property offset: %i\n", propertyOffset); + + if( propertyDatatypeIndex == -5 ) { + + const int columnValue = sqlite3_column_int( result, i ); + + + *( int * )( pointer + propertyOffset ) = columnValue; + + } else if( propertyDatatypeIndex == -3 ) { + + const char * columnValue = sqlite3_column_text( result, i ); + + char * columnValueCopy = malloc( strlen( columnValue ) ); + + strncpy( columnValueCopy, columnValue, strlen( columnValue ) ); + + //columnValueCopy[8] = "\0"; + + + // something wrong here. + + memcpy( pointer + propertyOffset, &columnValueCopy, 8 ); + + } + + //printf("class property datatype: %i\n\n\n", propertyDatatypeIndex); + + } + + + voidArray[rowIndex] = pointer; + + // printf("rowIndex: %i\n", rowIndex); + + rowIndex++; + + } + + struct array * rows = new array(); + + rows->items = voidArray; + + rows->total = rowIndex; + + return rows; + + } + +} \ No newline at end of file diff --git a/application/source/street.c b/application/source/street.c new file mode 100644 index 0000000..67876a8 --- /dev/null +++ b/application/source/street.c @@ -0,0 +1,16 @@ + + + +class address{ + + char * street; + + int number; + + void someMethod() { + + + } + +} + diff --git a/application/source/text.c b/application/source/text.c new file mode 100755 index 0000000..9af1119 --- /dev/null +++ b/application/source/text.c @@ -0,0 +1,178 @@ + + +#include + +#include + +#include + +#include + +#include + + + +class text{ + + char * value; + + + int usevalue = -1; + + int length; + + int capacity = 500; + + + int operator==( text * b ) { + + if( strcmp( this->value, b->value ) == 0 ) { + + return 1; + + } else { + + return 0; + + } + + } + + text * operator+=( char * b ) { + + this->append( b ); + + return this; + + } + + void constructor( char * value ) { + + this->length = strlen( value ); + + if( this->length > this->capacity ) { + + this->capacity = this->length * 2; + + } + + this->value = malloc( sizeof( char ) * this->capacity ); + + strcpy( this->value, value ); + } + + char get( int index ) { + + return this->value[ index ]; + + } + + void resize( int size ) { + + this->value = realloc( this->value, size ); + + this->capacity = size; + + } + + text * append( char * value ) { + + int originalLength = this->length; + + int newValueLength = strlen( value ); + + this->length += newValueLength; + + if( this->length > this->capacity ) { + + this->resize( this->length * 2 ); + + } + + memcpy( this->value + originalLength, value, newValueLength + 1 ); + + return this; + + } + + text * appendBinary( char * value, int size ) { + + int originalLength = this->length; + + int newValueLength = size; + + this->length += newValueLength; + + if( this->length > this->capacity ) { + + this->resize( this->length * 2 ); + + } + + memcpy( this->value + originalLength, value, newValueLength + 1 ); + + return this; + + } + + + text * appendObject( text * object ) { + + int originalLength = this->length; + + int newValueLength = object->length; + + this->length += newValueLength; + + if( this->length > this->capacity ) { + + this->resize( this->length * 2 ); + + } + + memcpy(this->value + originalLength, object->value, newValueLength + 1); + + return this; + + } + + text * concatenate( char * value ) { + + text * copy = new text( this->value ); + + strcat( copy->value, value ); + + return copy; + + } + + char * toNative() { + + return this->value; + + } + + char * whiteSpace( int whiteSpaceCount ) { + + char * output = malloc( 400 ); + + for (int i = 0; i < whiteSpaceCount; ++i) + { + + strcat( output, " " ); + + } + + return output; + + } + + void free() { + + free( this->value ); + + free( this ); + + } + +} \ No newline at end of file diff --git a/application/source/toolset.c b/application/source/toolset.c new file mode 100644 index 0000000..acdede4 --- /dev/null +++ b/application/source/toolset.c @@ -0,0 +1,28 @@ + +#include + +#include + +#include + + +class toolset{ + + void createHorisontalLine() { + + struct winsize w; + + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + + for (int i = 0; i < w.ws_col; ++i) + { + + printf("-"); + + }; + + printf("\n"); + + } + +} \ No newline at end of file diff --git a/application/source/triangle.c b/application/source/triangle.c new file mode 100755 index 0000000..2eba588 --- /dev/null +++ b/application/source/triangle.c @@ -0,0 +1,18 @@ + + +#include + +class triangle{ + + vector2 * a = new vector2( 1, 2 ); + + vector2 b = new vector2( 3, 400 ); + + vector2 c = new vector2( 5, 6 ); + + add( triangle * a ) { + + + } + +} \ No newline at end of file diff --git a/application/source/user.c b/application/source/user.c new file mode 100644 index 0000000..7e96086 --- /dev/null +++ b/application/source/user.c @@ -0,0 +1,24 @@ + +#include + +class user{ + + char * username; + + int id; + + int userlevel; + + char * hash; + + struct array * addresses = new array(); + + constructor() { + + //printf("create array();\n"); + + //this->addresses = new array(); + + } + +} diff --git a/application/source/vector2.c b/application/source/vector2.c new file mode 100755 index 0000000..947ef4a --- /dev/null +++ b/application/source/vector2.c @@ -0,0 +1,72 @@ + + + + +class vector2{ + + float x; + + float y; + + + constructor( float x, float y ) { + + //printf("constructor has been called.. x: %i, y: %i \n", x, y); + + this->x = x; + + this->y = y; + + // this causes an infinity loop. + // vector2 a = new vector2( 0, 0 ); + + // this->add( &a ); + + } + + + + vector2 * operator+( vector2 * b ){ + + this->add( b ); + + return this; + + } + + vector2 * operator+=( struct vector2 * b ) { + + // not proper + //strcat( this, b ); + + //printf("operator += triggered"); + + return b; + } + + add( vector2 * a ) { + + this->x += a->x; + + this->y += a->y; + + } + + subtract( vector2 * a ) { + + this->x -= a->x; + + this->y -= a->y; + + } + + int length() { + + return this->x + this->y; + + } + +} + + + diff --git a/application/source/vector3.c b/application/source/vector3.c new file mode 100644 index 0000000..7ca19ca --- /dev/null +++ b/application/source/vector3.c @@ -0,0 +1,53 @@ + + + + +class vector3{ + + float x; + + float y; + + float z; + + + + constructor( float x, float y, float z ) { + + this->x = x; + + this->y = y; + + this->z = z; + + } + + vector3 * operator+( vector3 * b ) { + + this->add( b ); + + return this; + + } + + vector3 * operator+=( vector3 * b ) { + + this->add( b ); + + return this; + + } + + + + void add( vector3 * b ) { + + this->x += b->x; + + this->y += b->y; + + this->z += b->z; + + } + +} \ No newline at end of file diff --git a/application/sqlite.c b/application/sqlite.c new file mode 100755 index 0000000..c33749c --- /dev/null +++ b/application/sqlite.c @@ -0,0 +1,818 @@ + + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include "console.h" + +#include "application.h" + + + + + +class sqlite{ + + + sqlite3 * db; + + sqlite3_stmt * res; + + char * value; + + char * selectedModel; + + + void constructor( char * filePath ) + { + this->value = "good"; + + this.connect( filePath ); + + } + + void connect( char * filePath ) { + + printf("\n\ntrying to connect.. %s\n\n", filePath); + + int rc = sqlite3_open( filePath, & this->db ); + + if ( rc != SQLITE_OK ) { + + printf( "Cannot open database: %s\n", sqlite3_errmsg( this->db ) ); + + sqlite3_close( this->db ); + + console->error( ( char * ) sqlite3_errmsg( this->db ) ); + + return; + + } + + rc = sqlite3_prepare_v2( this->db, "SELECT SQLITE_VERSION()", -1, & this->res, 0 ); + + if (rc != SQLITE_OK) { + + console->error( ( char * ) sqlite3_errmsg( this->db ) ); + + sqlite3_close( this->db ); + + return; + + } + + rc = sqlite3_step(this->res); + + /*if ( rc == SQLITE_ROW ) { + + printf( "%s\n", ( char * ) sqlite3_column_text( this->res, 0 ) ); + + } + + printf( "Success \n"); +*/ + //return 1; + + } + + void free() { + + sqlite3_finalize( this->res ); + + sqlite3_close( this->db ); + + } + + void selectModel( char * className ) { + + this->selectedModel = className; + + /* + + printf("select className: %s\n", className); + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + printf("class index: %i\n", classIndex); + + + int propertyIndex = getPropertyIndexByPropertyName( classIndex, "username" ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + char ** propertyNames = getPropertiesByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + + printf("propertyIndex: %i\n\n", propertyIndex); + + for (int i = 0; i < propertyCount; ++i) + { + + char * propertyName = propertyNames[i]; + + int propertyOffset = propertyOffsets[i]; + + + printf("propertyName: %s offset: %i\n", propertyName, propertyOffset); + } + + + + + + char * shortPointer = malloc( sizeof( char * ) * 100000 ); + + void * * voidArray = malloc( sizeof( void * ) * 100000 ); + + int structByteSize; + + getArrayByClassIndex( 100000, voidArray, shortPointer, &structByteSize, 0 ); + + */ + } + + void createTable() { + + char * errorMessage = 0; + + char *sql = "DROP TABLE IF EXISTS user;" + "CREATE TABLE user( id INT, username TEXT, userlevel INT, hash TEXT );"; + + int rc = sqlite3_exec(this->db, sql, 0, 0, &errorMessage); + + if ( rc != SQLITE_OK ) { + + printf( "SQL error: %s\n", errorMessage ); + + sqlite3_free( errorMessage ); + + sqlite3_close(this->db); + + + } + + } + +/* + // Fast but unsave -> sql injection + void addRowsFast( array * insertArray ) { + + array * copy = insertArray; + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + text * query = new text( "" ); + + query->append( "INSERT INTO " ); + + query->append( this->selectedModel ); + + + sqlite3_stmt * result; + + + char * * propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + + + query->append( " ( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + // join table because this is an class + continue; + + } + + if( propertyIndex > 0 ) { + + query->append( ", " ); + + } + + query->append( propertyName ); + + } + + query->append( " ) " ); + + query->append(" VALUES " ); + + + + int insertItemCount = copy->total; + + char * voidArray = ( char * ) copy->items; + + //sqlite3_exec(result, "BEGIN TRANSACTION;", NULL, NULL, NULL); + + for (int i = 0; i < insertItemCount; ++i) + { + char * pointer = copy->get( i ); + + + + if( i > 0 ) { + + query->append( ", " ); + + } + + query->append( "( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + // join table because this is an class + continue; + + } + + int propertyOffset = propertyOffsets[propertyIndex]; + + int propertyDatatypeIndex = getPropertyDatatypeIndex( datatypeIndices, propertyIndex ); + + if( propertyIndex > 0 ) { + + query->append( ", " ); + + } + + if( propertyDatatypeIndex == -5 ) { + + int value = *( int * )(pointer + propertyOffset); + + char * textNumber = malloc( sizeof( char ) * 20 ); + + // Boost Spirit.Karma is faster + sprintf( textNumber, "%d", value ); + + query->append( textNumber ); + + } else if( propertyDatatypeIndex == -3 ) { + + char * columnValueCopy = ( char * ) malloc( 8 ); + + char * value = ( char * ) ( pointer + propertyOffset ); + + strncpy( &columnValueCopy, value, 8 ); + + query->append( "'" ); + + query->append( columnValueCopy ); + + query->append( "'" ); + + + } + + } + + query->append( " )" ); + + } + + //sqlite3_exec(result, "END TRANSACTION;", NULL, NULL, NULL); + sqlite3_prepare_v2( this->db, query->buffer, -1, &result, 0 ); + + sqlite3_step( result ); + + sqlite3_finalize( result ); + + //printf("insert query: %s\n", query->buffer); + + } +*/ + + + + + + + + void addRows( array * insertArray ) { + + array * copy = insertArray; + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + text * query = new text( "" ); + + query->append( "INSERT INTO " ); + + query->append( this->selectedModel ); + + + sqlite3_stmt * result; + + + char * * propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + + + query->append( " ( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + // join table because this is an class + continue; + + } + + if( propertyIndex > 0 ) { + + query->append( ", " ); + + } + + query->append( propertyName ); + + } + + query->append( " ) " ); + + query->append( " VALUES ( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + // join table because this is an class + continue; + + } + + if( propertyIndex > 0 ) { + + query->append( ", " ); + + } + + query->append( "?" ); + + } + + query->append(" ) " ); + + + + sqlite3_prepare_v2( this->db, query->buffer, -1, &result, 0 ); + + sqlite3_exec(this->db, this->selectedModel, NULL, NULL, 0); + + sqlite3_exec(this->db, "PRAGMA synchronous = OFF", NULL, NULL, 0); + + sqlite3_exec(this->db, "PRAGMA journal_mode = MEMORY", NULL, NULL, 0); + + + int insertItemCount = copy->total; + + char * voidArray = ( char * ) copy->items; + + //sqlite3_exec(result, "BEGIN TRANSACTION;", NULL, NULL, NULL); + + for (int i = 0; i < insertItemCount; ++i) + { + char * pointer = copy->get( i ); + + this->updateRow( result, propertyCount, propertyNames, propertyOffsets, datatypeIndices, pointer ); + + sqlite3_step( result ); + + sqlite3_reset( result ); + + } + + //sqlite3_exec(result, "END TRANSACTION;", NULL, NULL, NULL); + + sqlite3_finalize( result ); + + //printf("insert query: %s\n", query->buffer); + + } + + + + void updateRow( sqlite3_stmt * result, int propertyCount, char * * propertyNames, int * propertyOffsets, int * datatypeIndices, char * pointer ) { + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + int propertyOffset = propertyOffsets[propertyIndex]; + + int propertyDatatypeIndex = getPropertyDatatypeIndex( datatypeIndices, propertyIndex ); + + //printf("propertyName: %s offset: %i datatype: %i propertyIndex: %i\n", propertyName, propertyOffset, propertyDatatypeIndex, propertyIndex); + + if( propertyDatatypeIndex == -5 ) { + + int value = *( int * )(pointer + propertyOffset); + + //printf("integer value: %i %i\n", propertyIndex + 1, value); + + sqlite3_bind_int( result, propertyIndex + 1, value ); + + } else if( propertyDatatypeIndex == -3 ) { + + //char * columnValueCopy = ( char * ) malloc( 8 ); + + uintptr_t * value = ( uintptr_t * ) ( pointer + propertyOffset ); + + //strncpy( &columnValueCopy, value, 8 ); + + //printf("char * value: %i %s\n", propertyIndex + 1, columnValueCopy); + + sqlite3_bind_text( result, propertyIndex + 1, (char *) *value, -1, SQLITE_TRANSIENT ); + + } + + } + + //printf("\n\n\n"); + + } + + void update( void * row ) { + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + char ** propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + int propertyIdOfIndex = -1; + + + for ( int i = 0; i < propertyCount; ++i ) + { + char * propertyName = propertyNames[i]; + + //printf("propertyName: %s\n", propertyName); + + if( strcmp( propertyName, "id" ) == 0 ) { + + propertyIdOfIndex = i; + + break; + + } + } + + if( propertyIdOfIndex == -1 ) { + + printf("Class '%s' does not have an id field. "); + + } + + int idOffset = propertyOffsets[ propertyIdOfIndex ]; + + char * pointer = row; + + int id = *( pointer + idOffset ); + + text * query = new text( "" ); //"UPDATE user set username = '?' where id=?; " + + query->append( "UPDATE " ); + + query->append( this->selectedModel ); + + query->append( " SET " ); + + int activePropertyCount = 0; + + // set propertyCount + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + int datatypeIndex = datatypeIndices[propertyIndex]; + + // todo properties that are classes like "array" + if( datatypeIndex > 0 ) { + + continue; + + } + + activePropertyCount++; + + if( propertyIndex > 0 ) { + + query->append( ", " ); + + } + + query->append( propertyName ); + + query->append( " = ? " ); + + } + + query->append( " where id = ? " ); + + sqlite3_stmt * result; + + sqlite3_prepare_v2( this->db, query->buffer, -1, &result, 0 ); + + this->updateRow( result, propertyCount, propertyNames, propertyOffsets, datatypeIndices, pointer ); + + sqlite3_bind_int( result, activePropertyCount + 1, id ); + + //printf("propertyCount: %i %i\n", propertyCount, id ); + + sqlite3_step( result ); + + sqlite3_finalize( result ); + + //printf("update query: %s\n", query->buffer); + + } + + void addRow( void * row ) { + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + text * query = new text( "" ); + + query->append( "INSERT INTO " ); + + query->append( this->selectedModel ); + + + sqlite3_stmt * result; + + + char * * propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + char * pointer = row; + + + query->append( " ( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[ propertyIndex ]; + + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + // join table because this is an class + continue; + + } + + + if( propertyIndex > 0 ) { + + query->append( ", " ); + + } + + query->append( propertyName ); + + } + + query->append( " ) " ); + + query->append( " VALUES ( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + // set joined table id + continue; + + } + + + if( propertyIndex > 0 ) { + + query->append( ", " ); + + } + + query->append( "?" ); + + } + + query->append(" ) " ); + + + + // { + + sqlite3_prepare_v2( this->db, query->buffer, -1, &result, 0 ); + + this->updateRow( result, propertyCount, propertyNames, propertyOffsets, datatypeIndices, pointer ); + + sqlite3_step( result ); + + // } + + sqlite3_finalize( result ); + + //printf("query: %s\n", query->buffer); + + } + + struct array * fetchRows( char * sql ) { + + sqlite3_stmt * result; + + int rc = sqlite3_prepare_v2( this->db, sql, -1, &result, 0 ); + + if ( rc != SQLITE_OK ) { + + printf("Failed to execute statement: %s\n", sqlite3_errmsg( this->db ) ); + + } + +/* + if ( rc != SQLITE_ROW ) { + + printf("not rows found\n\n"); + + } +*/ + int rowIndex = 0; + + + //printf("select className: %s\n", this->selectedModel); + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + + //printf("class index: %i\n", classIndex); + + + int propertyIndex = getPropertyIndexByPropertyName( classIndex, "username" ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + char ** propertyNames = getPropertiesByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + + char * shortPointer = malloc( sizeof( char * ) * 100000 ); + + void * * voidArray = malloc( sizeof( void * ) * 100000 ); + + int structByteSize; + + getArrayByClassIndex( 1000, voidArray, &structByteSize, classIndex ); + + shortPointer = ( char * ) shortPointer; + + + while ( sqlite3_step( result ) != SQLITE_DONE ) { + + //if( rowsCount == 0 ) { + + int pointerIndex = ( rowIndex * ( structByteSize ) ); + + //==printf("pointerIndex: %i\n", pointerIndex); + + char * pointer = shortPointer + pointerIndex; + + int columnCount = sqlite3_data_count( result ); + + //printf("columnCount: %i\n\n", columnCount); + + for (int i = 0; i < columnCount; ++i) + { + + const char * columnName = sqlite3_column_name( result, i ); + + const int propertyIndex = getPropertyIndexByPropertyName( classIndex, (char *)columnName ); + + int propertyDatatypeIndex = getPropertyDatatypeIndex( datatypeIndices, propertyIndex ); + + int propertyOffset = getPropertyOffsetByPropertyIndex( propertyOffsets, propertyIndex ); + + //printf("sqlite3 column index: %i\n", i); + + //printf("sqlite3 columnName: %s\n", columnName); + + //printf("class property index: %i\n", propertyIndex); + + //printf("class property offset: %i\n", propertyOffset); + + if( propertyDatatypeIndex == -5 ) { + + const int columnValue = sqlite3_column_int( result, i ); + + + *( int * )( pointer + propertyOffset ) = columnValue; + + } else if( propertyDatatypeIndex == -3 ) { + + const char * columnValue = sqlite3_column_text( result, i ); + + char * columnValueCopy = malloc( strlen( columnValue ) ); + + strncpy( columnValueCopy, columnValue, strlen( columnValue ) ); + + //columnValueCopy[8] = "\0"; + + + // something wrong here. + + memcpy( pointer + propertyOffset, &columnValueCopy, 8 ); + + } + + //printf("class property datatype: %i\n\n\n", propertyDatatypeIndex); + + } + + + voidArray[rowIndex] = pointer; + + // printf("rowIndex: %i\n", rowIndex); + + rowIndex++; + + } + + struct array * rows = new array(); + + rows->items = voidArray; + + rows->total = rowIndex; + + return rows; + + } + +} \ No newline at end of file diff --git a/application/target/application.c b/application/target/application.c new file mode 100644 index 0000000..20aa5da --- /dev/null +++ b/application/target/application.c @@ -0,0 +1,713 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +char * someArray[10] = {"a", "b", "c"}; + + + + + +void startOpenGL( ) { + + opengl * instance = opengl_newPointer(); + + opengl_initialize( instance ); + + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +int main( ) { + + startOpenGL(); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} + diff --git a/application/target/application.h b/application/target/application.h new file mode 100644 index 0000000..b45e4fe --- /dev/null +++ b/application/target/application.h @@ -0,0 +1,69 @@ +#ifndef _application + +#define _application + + +// Macros + +#define LINUX + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include "opengl.h" + +#include "street.h" + +#include "console.h" + +#include "toolset.h" + +#include "extends.h" + +#include "int.h" + +#include "char.h" + +#include "sqlite.h" + +#include "fileSystem.h" + +#include "array.h" + +#include "triangle.h" + +#include "vector3.h" + +#include "vector2.h" + +#include "text.h" + +#include + + +int main( ); + +void startOpenGL( ); + +char * someArray[10] ; + +#endif diff --git a/application/target/array.c b/application/target/array.c new file mode 100644 index 0000000..d0ac118 --- /dev/null +++ b/application/target/array.c @@ -0,0 +1,202 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + +int array_length( array * this ) { + + return this->total; + + } + + +void * array_get( array * this, int index ) { + + if ( index >= 0 && index < this->total ){ + + return this->items[index]; + + } + + return NULL; + + } + + +void array_set( array * this, int index, void * item ) { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + +void array_resize( array * this, int capacity ) { + + void * * items = realloc( this->items, sizeof( void * ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + +void array_add( array * this, void * item ) { + + if ( this->capacity == this->total ){ + + array_resize( this, this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + +char * array_join( array * this, char * separator ) { + + int count = array_length( this ); + + text * result = text_newPointer( "" ); + + for (int i = 0; i < count; ++i) + { + + char * currentPart = this->items[ i ]; + + if( i > 0 ) { + + text_append( result, separator ); + + } + + text_append( result, currentPart ); + + } + + + + return result->value; + + } + +void array_delete( array * this, int index ) { + if ( index < 0 || index >= this->total ){ + + return; + + } + + this->items[index] = NULL; + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + this->items[i + 1] = NULL; + + } + + this->total--; + + if ( this->total > 0 && this->total == this->capacity / 4 ){ + + array_resize( this, this->capacity / 2 ); + + } + + } + + +int array_array_push( array * this, void * item ) { + + array_add( this, item ); + + return this->total; + + } + +void array_unshift( array * this, void * item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + array_resize( this, this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } + +void * array_pop( array * this ) { + + int length = this->total; + + int lastIndex = length - 1; + + void * lastItem = array_get( this, lastIndex ); + + array_delete( this, lastIndex ); + + return lastItem; + + } + +array array_new() { + + array instance; + + instance.__classIndex = 5; + + instance.capacity = 10; + + instance.total = 0; + + instance.items = malloc( 10000000 ); + + return instance; + +} + +array * array_newPointer() { + + struct array * pointer = malloc( sizeof ( struct array ) ); + + pointer->__classIndex = 5; + + pointer->capacity = 10; + + pointer->total = 0; + + pointer->items = malloc( 10000000 ); + + return pointer; + +} + diff --git a/application/target/array.h b/application/target/array.h new file mode 100644 index 0000000..692f9ca --- /dev/null +++ b/application/target/array.h @@ -0,0 +1,61 @@ +#ifndef _array + +#define _array + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + + +typedef struct array{ + + unsigned short __classIndex; + + int capacity; + + int total; + + void * * items; + + +} array; + +int array_length( array * this ); + +void * array_get( array * this, int index ); + +void array_set( array * this, int index, void * item ); + +void array_resize( array * this, int capacity ); + +void array_add( array * this, void * item ); + +char * array_join( array * this, char * separator ); + +void array_delete( array * this, int index ); + +int array_array_push( array * this, void * item ); + +void array_unshift( array * this, void * item ); + +void * array_pop( array * this ); + +array array_new( ); + +array * array_newPointer( ); + +#endif diff --git a/application/target/char.c b/application/target/char.c new file mode 100644 index 0000000..1219f39 --- /dev/null +++ b/application/target/char.c @@ -0,0 +1,156 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + +int char_operator_compare( char * this, char * b ) { + + return char_compare( this, b ); + + } + +void char_operator_add( char * this, char * b ) { + + + strcat( this, b ); + + } + +char * char_operator_plus( char * this, char * b ) { + + return char_concatenate( this, b ); + + } + +int char_compare( char * this, char * b ) { + + return strcmp( this, b ) == 0; + + } + +char * char_concatenate( char * this, char * b ) { + + int lengthA = strlen( this ); + + int lengthB = strlen( b ); + + char * pointer = this; + + char * copy = ( char * ) malloc( ( lengthA + lengthB + 1 ) * sizeof( char ) ); + + int idx = 0; + + while ( * pointer != '\0' ){ + + copy[idx++] = *pointer++; + + } + + pointer = &b[0]; + + while ( * pointer != '\0' ){ + + copy[idx++] = *pointer++; + + } + + copy[ idx++ ] = '\0'; + + return ©[0]; + + } + +char * char_clone( char * this ) { + + char * newCopy = malloc( sizeof( char ) * strlen( this ) ); + + strcpy( newCopy, this ); + + return newCopy; + + } + +char * char_copy( char * this ) { + + char * newCopy = malloc( sizeof( char ) * strlen( this ) ); + + strcpy( newCopy, this ); + + return newCopy; + + } + +struct array * char_split( char * this, char * needle ) { + + char * haystack = char_clone( this ); + + struct array * keys = array_newPointer(); + + int count = 0; + + char * tmp = haystack; + + char * token = strtok( haystack, needle ); + + int i = 0; + + while ( token ) { + + array_add( keys, token ); + + + + token = (char *) strtok( NULL, needle ); + + } + + return keys; + + + } + + + +char * char_removeWhitespaceLeft( char * this ) { + char * s = this; + + while(isspace(*s)) s++; + + return s; + } + + +char * char_removeWhitespaceRight( char * this ) { + char * s = this; + + char* back = s + strlen(s); + + while( isspace( *--back ) ); + + *( back + 1 ) = '\0'; + + return s; + } + + +char * char_removeWhitespace( char * this ) { + + return char_removeWhitespaceRight(char_removeWhitespaceLeft( this ) ); + + } + diff --git a/application/target/char.h b/application/target/char.h new file mode 100644 index 0000000..364b6a2 --- /dev/null +++ b/application/target/char.h @@ -0,0 +1,54 @@ +#ifndef _char + +#define _char + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + + +int char_operator_compare( char * this, char * b ); + +void char_operator_add( char * this, char * b ); + +char * char_operator_plus( char * this, char * b ); + +int char_compare( char * this, char * b ); + +char * char_concatenate( char * this, char * b ); + +char * char_clone( char * this ); + +char * char_copy( char * this ); + +struct array * char_split( char * this, char * needle ); + +char * char_removeWhitespaceLeft( char * this ); + +char * char_removeWhitespaceRight( char * this ); + +char * char_removeWhitespace( char * this ); + +#endif diff --git a/application/target/classConfiguration.c b/application/target/classConfiguration.c new file mode 100644 index 0000000..4fb5204 --- /dev/null +++ b/application/target/classConfiguration.c @@ -0,0 +1,480 @@ +#include + +char * __ClassNames[TOTAL_CLASS_COUNT] = { "opengl", "unsignedIntegerArray", "vector2", "vector3", "text", "array", "char", "floatArray", "shader", "uniform", "attribute", "fileSystem", "consoleManager", "http", "headerManager", "header", "request", "mimeTypes", "mesh", "address", "toolset", "b", "a", "inherit", "classA", "classB", "int", "sqlite", "triangle", "user" }; + +int __ClassPropertyCount[TOTAL_CLASS_COUNT] = { 13, 3, 2, 3, 4, 3, 0, 3, 2, 3, 3, 0, 0, 9, 1, 2, 9, 2, 9, 2, 0, 1, 2, 3, 1, 1, 0, 4, 3, 5 }; + +char * __ClassPropertyNames[TOTAL_CLASS_COUNT][30] = { + { "mainDisplay" , "mainWindow" , "MainScreen" , "RootWindow" , "lastTime" , "deltaTime" , "startTime" , "frameCount" , "vertexbuffer" , "indexBuffer" , "currentShader" , "quads" , "image[HEIGHT][WIDTH]" }, + { "capacity" , "total" , "items" }, + { "x" , "y" }, + { "x" , "y" , "z" }, + { "value" , "usevalue" , "length" , "capacity" }, + { "capacity" , "total" , "items" }, + { }, + { "capacity" , "total" , "items" }, + { "uniforms" , "attributes" }, + { "name[64]" , "location" , "type" }, + { "name[64]" , "location" , "type" }, + { }, + { }, + { "socket" , "hostAddress" , "hostAddresslength" , "filesystem" , "mimetypes" , "headers" , "useSSL" , "sslContext" , "requestCallback" }, + { "headers" }, + { "name" , "value" }, + { "connection" , "address" , "port" , "url" , "method" , "version" , "mimeType" , "extension" , "headers" }, + { "extensions" , "mimeTypes" }, + { "indices" , "textureCoordinates" , "vertexCoordinates" , "normalCoordinates" , "indexBuffer" , "vertexbuffer" , "textureCoordinateBuffer" , "meshIndexBuffer" , "uvBuffer" }, + { "street" , "number" }, + { }, + { "propertyFromB" }, + { "propertyFromA" , "propertyFromB" }, + { "propertyFromC" , "propertyFromA" , "propertyFromB" }, + { "propertyFromC" }, + { "propertyFromC" }, + { }, + { "db" , "res" , "value" , "selectedModel" }, + { "a" , "b" , "c" }, + { "username" , "id" , "userlevel" , "hash" , "addresses" } + }; + +int __ClassPropertyOffsets[TOTAL_CLASS_COUNT][30] = { + { offsetof( opengl, mainDisplay ) , offsetof( opengl, mainWindow ) , offsetof( opengl, MainScreen ) , offsetof( opengl, RootWindow ) , offsetof( opengl, lastTime ) , offsetof( opengl, deltaTime ) , offsetof( opengl, startTime ) , offsetof( opengl, frameCount ) , offsetof( opengl, vertexbuffer ) , offsetof( opengl, indexBuffer ) , offsetof( opengl, currentShader ) , offsetof( opengl, quads ) , offsetof( opengl, image[HEIGHT][WIDTH] ) }, + { offsetof( unsignedIntegerArray, capacity ) , offsetof( unsignedIntegerArray, total ) , offsetof( unsignedIntegerArray, items ) }, + { offsetof( vector2, x ) , offsetof( vector2, y ) }, + { offsetof( vector3, x ) , offsetof( vector3, y ) , offsetof( vector3, z ) }, + { offsetof( text, value ) , offsetof( text, usevalue ) , offsetof( text, length ) , offsetof( text, capacity ) }, + { offsetof( array, capacity ) , offsetof( array, total ) , offsetof( array, items ) }, + { }, + { offsetof( floatArray, capacity ) , offsetof( floatArray, total ) , offsetof( floatArray, items ) }, + { offsetof( shader, uniforms ) , offsetof( shader, attributes ) }, + { offsetof( uniform, name[64] ) , offsetof( uniform, location ) , offsetof( uniform, type ) }, + { offsetof( attribute, name[64] ) , offsetof( attribute, location ) , offsetof( attribute, type ) }, + { }, + { }, + { offsetof( http, socket ) , offsetof( http, hostAddress ) , offsetof( http, hostAddresslength ) , offsetof( http, filesystem ) , offsetof( http, mimetypes ) , offsetof( http, headers ) , offsetof( http, useSSL ) , offsetof( http, sslContext ) }, + { offsetof( headerManager, headers ) }, + { offsetof( header, name ) , offsetof( header, value ) }, + { offsetof( request, connection ) , offsetof( request, address ) , offsetof( request, port ) , offsetof( request, url ) , offsetof( request, method ) , offsetof( request, version ) , offsetof( request, mimeType ) , offsetof( request, extension ) , offsetof( request, headers ) }, + { offsetof( mimeTypes, extensions ) , offsetof( mimeTypes, mimeTypes ) }, + { offsetof( mesh, indices ) , offsetof( mesh, textureCoordinates ) , offsetof( mesh, vertexCoordinates ) , offsetof( mesh, normalCoordinates ) , offsetof( mesh, indexBuffer ) , offsetof( mesh, vertexbuffer ) , offsetof( mesh, textureCoordinateBuffer ) , offsetof( mesh, meshIndexBuffer ) , offsetof( mesh, uvBuffer ) }, + { offsetof( address, street ) , offsetof( address, number ) }, + { }, + { offsetof( b, propertyFromB ) }, + { offsetof( a, propertyFromA ) , offsetof( a, propertyFromB ) }, + { offsetof( inherit, propertyFromC ) , offsetof( inherit, propertyFromA ) , offsetof( inherit, propertyFromB ) }, + { offsetof( classA, propertyFromC ) }, + { offsetof( classB, propertyFromC ) }, + { }, + { offsetof( sqlite, db ) , offsetof( sqlite, res ) , offsetof( sqlite, value ) , offsetof( sqlite, selectedModel ) }, + { offsetof( triangle, a ) , offsetof( triangle, b ) , offsetof( triangle, c ) }, + { offsetof( user, username ) , offsetof( user, id ) , offsetof( user, userlevel ) , offsetof( user, hash ) , offsetof( user, addresses ) } + }; + +int __ClassPropertyDatatypeIndices[TOTAL_CLASS_COUNT][30] = { + {1 , 1 , -5 , 1 , -5 , 1 , 1 , -5 , 1 , 1 , 8 , 18 , -2 }, + {-5 , -5 , -5 }, + {1 , 1 }, + {1 , 1 , 1 }, + {-3 , -5 , -5 , -5 }, + {-5 , -5 , 1 }, + { }, + {-5 , -5 , 1 }, + {5 , 5 }, + {-2 , 1 , 1 }, + {1 , 1 , 1 }, + { }, + { }, + {-5 , 1 , -5 , 11 , 17 , 14 , -5 , 1 , 1 }, + {5 }, + {-3 , -3 }, + {-3 , -3 , -5 , -3 , -3 , -3 , -3 , -3 , 14 }, + {5 , 5 }, + {1 , 7 , 7 , 7 , 1 , 1 , 1 , 1 , 1 }, + {-3 , -5 }, + { }, + {-5 }, + {-5 , -5 }, + {-5 , -5 , -5 }, + {-5 }, + {-5 }, + { }, + {1 , 1 , -3 , -3 }, + {2 , 2 , 2 }, + {-3 , -5 , -5 , -3 , 5 } + }; + +void getArrayByClassIndex( int size, void * * voidArray, int * structByteSize, int classIndex ) { + + switch( classIndex ) { + + case 0: + + voidArray = ( void ** ) ( struct opengl * ) malloc( sizeof( struct opengl ) * size ); + + *structByteSize = sizeof( struct opengl ); + + break; + + case 1: + + voidArray = ( void ** ) ( struct unsignedIntegerArray * ) malloc( sizeof( struct unsignedIntegerArray ) * size ); + + *structByteSize = sizeof( struct unsignedIntegerArray ); + + break; + + case 2: + + voidArray = ( void ** ) ( struct vector2 * ) malloc( sizeof( struct vector2 ) * size ); + + *structByteSize = sizeof( struct vector2 ); + + break; + + case 3: + + voidArray = ( void ** ) ( struct vector3 * ) malloc( sizeof( struct vector3 ) * size ); + + *structByteSize = sizeof( struct vector3 ); + + break; + + case 4: + + voidArray = ( void ** ) ( struct text * ) malloc( sizeof( struct text ) * size ); + + *structByteSize = sizeof( struct text ); + + break; + + case 5: + + voidArray = ( void ** ) ( struct array * ) malloc( sizeof( struct array ) * size ); + + *structByteSize = sizeof( struct array ); + + break; + + case 7: + + voidArray = ( void ** ) ( struct floatArray * ) malloc( sizeof( struct floatArray ) * size ); + + *structByteSize = sizeof( struct floatArray ); + + break; + + case 8: + + voidArray = ( void ** ) ( struct shader * ) malloc( sizeof( struct shader ) * size ); + + *structByteSize = sizeof( struct shader ); + + break; + + case 9: + + voidArray = ( void ** ) ( struct uniform * ) malloc( sizeof( struct uniform ) * size ); + + *structByteSize = sizeof( struct uniform ); + + break; + + case 10: + + voidArray = ( void ** ) ( struct attribute * ) malloc( sizeof( struct attribute ) * size ); + + *structByteSize = sizeof( struct attribute ); + + break; + + case 11: + + voidArray = ( void ** ) ( struct fileSystem * ) malloc( sizeof( struct fileSystem ) * size ); + + *structByteSize = sizeof( struct fileSystem ); + + break; + + case 12: + + voidArray = ( void ** ) ( struct consoleManager * ) malloc( sizeof( struct consoleManager ) * size ); + + *structByteSize = sizeof( struct consoleManager ); + + break; + + case 13: + + voidArray = ( void ** ) ( struct http * ) malloc( sizeof( struct http ) * size ); + + *structByteSize = sizeof( struct http ); + + break; + + case 14: + + voidArray = ( void ** ) ( struct headerManager * ) malloc( sizeof( struct headerManager ) * size ); + + *structByteSize = sizeof( struct headerManager ); + + break; + + case 15: + + voidArray = ( void ** ) ( struct header * ) malloc( sizeof( struct header ) * size ); + + *structByteSize = sizeof( struct header ); + + break; + + case 16: + + voidArray = ( void ** ) ( struct request * ) malloc( sizeof( struct request ) * size ); + + *structByteSize = sizeof( struct request ); + + break; + + case 17: + + voidArray = ( void ** ) ( struct mimeTypes * ) malloc( sizeof( struct mimeTypes ) * size ); + + *structByteSize = sizeof( struct mimeTypes ); + + break; + + case 18: + + voidArray = ( void ** ) ( struct mesh * ) malloc( sizeof( struct mesh ) * size ); + + *structByteSize = sizeof( struct mesh ); + + break; + + case 19: + + voidArray = ( void ** ) ( struct address * ) malloc( sizeof( struct address ) * size ); + + *structByteSize = sizeof( struct address ); + + break; + + case 20: + + voidArray = ( void ** ) ( struct toolset * ) malloc( sizeof( struct toolset ) * size ); + + *structByteSize = sizeof( struct toolset ); + + break; + + case 21: + + voidArray = ( void ** ) ( struct b * ) malloc( sizeof( struct b ) * size ); + + *structByteSize = sizeof( struct b ); + + break; + + case 22: + + voidArray = ( void ** ) ( struct a * ) malloc( sizeof( struct a ) * size ); + + *structByteSize = sizeof( struct a ); + + break; + + case 23: + + voidArray = ( void ** ) ( struct inherit * ) malloc( sizeof( struct inherit ) * size ); + + *structByteSize = sizeof( struct inherit ); + + break; + + case 24: + + voidArray = ( void ** ) ( struct classA * ) malloc( sizeof( struct classA ) * size ); + + *structByteSize = sizeof( struct classA ); + + break; + + case 25: + + voidArray = ( void ** ) ( struct classB * ) malloc( sizeof( struct classB ) * size ); + + *structByteSize = sizeof( struct classB ); + + break; + + case 27: + + voidArray = ( void ** ) ( struct sqlite * ) malloc( sizeof( struct sqlite ) * size ); + + *structByteSize = sizeof( struct sqlite ); + + break; + + case 28: + + voidArray = ( void ** ) ( struct triangle * ) malloc( sizeof( struct triangle ) * size ); + + *structByteSize = sizeof( struct triangle ); + + break; + + case 29: + + voidArray = ( void ** ) ( struct user * ) malloc( sizeof( struct user ) * size ); + + *structByteSize = sizeof( struct user ); + + break; + + } + +} + + + +// #include "sqlite.h" + +int getPropertyIndexOfClassIndex( int propertyCount, char ** propertyNames ) { + + int propertyIdOfIndex = -1; + + for ( int i = 0; i < propertyCount; ++i ) + { + char * propertyName = propertyNames[i]; + + //printf("propertyName: %s\n", propertyName); + + if( strcmp( propertyName, "id" ) == 0 ) { + + propertyIdOfIndex = i; + + break; + + } + + } + + return propertyIdOfIndex; + +} + +/* +void getArrayByClassIndex( int items, void * * voidArray, int * structByteSize, int classIndex ) { + + struct user * array; + + switch( classIndex ) { + + case 8: + + array = ( struct user * ) malloc( sizeof( struct user ) * 1000 ); + + voidArray = ( void ** ) array; + + *structByteSize = sizeof( struct user ); + + break; + + default: + + array = ( struct user * ) malloc( sizeof( struct user ) * 1000 ); + + voidArray = ( void ** ) array; + + *structByteSize = sizeof( struct user ); + + } + +}*/ + +char * getClassName( int classIndex ) { + + return __ClassNames[ classIndex ]; + +} + + +int getClassIndexByClassName( char * className ) { + + for (int i = 0; i < TOTAL_CLASS_COUNT; ++i) + { + char * currentClassName = __ClassNames[ i ]; + + if( strcmp( className, currentClassName ) == 0 ) { + + //printf("find classname: %s\n", className); + + return i; + + } + + } + + return -1; + +} + +int getPropertyCountByClassIndex( int classIndex ) { + + return __ClassPropertyCount[ classIndex ]; + +} + +char * * getPropertiesByClassIndex( int classIndex ) { + + return __ClassPropertyNames[ classIndex ]; + +} + +int * getPropertyOffsetsByClassIndex( int classIndex ) { + + return __ClassPropertyOffsets[ classIndex ]; + +} + +int getPropertyOffsetByPropertyIndex( int * propertyOffsets, int propertyIndex ) { + + return propertyOffsets[ propertyIndex ]; + +} + +int * getPropertyDatatypeIndexesByClassIndex( int classIndex ) { + + return __ClassPropertyDatatypeIndices[ classIndex ]; + +} + +int getPropertyDatatypeIndex( int * propertyDatatypeIndices, int propertyIndex ) { + + return propertyDatatypeIndices[ propertyIndex ]; + +} + + +int getPropertyIndexByPropertyName( int classID, char * propertyName ) { + + int propertyCount = getPropertyCountByClassIndex( classID ); + + char * * propertyNames = getPropertiesByClassIndex( classID ); + + for (int i = 0; i < propertyCount; ++i) + { + + char * propertyNameCompare = propertyNames[i]; + + if( strcmp( propertyName, propertyNameCompare ) == 0 ) { + + return i; + + } + + } + + return -1; + +} \ No newline at end of file diff --git a/application/target/classConfiguration.h b/application/target/classConfiguration.h new file mode 100644 index 0000000..666c732 --- /dev/null +++ b/application/target/classConfiguration.h @@ -0,0 +1,86 @@ +#ifndef __classConfiguration + +#define __classConfiguration + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#define TOTAL_CLASS_COUNT 30 + +extern char * __ClassNames[TOTAL_CLASS_COUNT]; +extern int __ClassPropertyCount[TOTAL_CLASS_COUNT]; +extern char * __ClassPropertyNames[TOTAL_CLASS_COUNT][30]; +extern int __ClassPropertyOffsets[TOTAL_CLASS_COUNT][30]; +extern int __ClassPropertyOffsets[TOTAL_CLASS_COUNT][30]; + +#include + +int getPropertyIndexOfClassIndex( int propertyCount, char ** propertyNames ); + +void getArrayByClassIndex( int size, void * * voidArray, int * structByteSize, int classIndex ); + +int getClassIndexByClassName( char * className ); + +char * getClassName( int classIndex ); + +int getPropertyCountByClassIndex( int classIndex ); + +char * * getPropertiesByClassIndex( int classIndex ); + +int * getPropertyOffsetsByClassIndex( int classIndex ); + +int getPropertyOffsetByPropertyIndex( int * propertyOffsets, int propertyIndex ); + +int getPropertyIndexByPropertyName( int classID, char * propertyName ); + +int * getPropertyDatatypeIndexesByClassIndex( int classIndex ); + +int getPropertyDatatypeIndex( int * propertyDatatypeIndices, int propertyIndex ); +#endif diff --git a/application/target/console.c b/application/target/console.c new file mode 100644 index 0000000..a22ccf7 --- /dev/null +++ b/application/target/console.c @@ -0,0 +1,273 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + +struct consoleManager * console; + + + +char * consoleManager_whiteSpace( consoleManager * this, int whiteSpaceCount ) { + + char * output = malloc( whiteSpaceCount + 1 ); + + for (int i = 0; i < whiteSpaceCount; ++i) + { + + strcat( output, " " ); + + } + + output[whiteSpaceCount] = 0; + + return output; + + } + +void consoleManager_logObject( consoleManager * this, void * voidPointer, int classIndex, int level ) { + + + char * whiteSpace = consoleManager_whiteSpace( this, level ); + + level++; + + char * className = getClassName( classIndex ); + + printf( "\n\n" ); + + printf( whiteSpace ); + + printf(" %s : {\n", className ); + + + + char * * propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + char * pointer = voidPointer; + + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + printf( whiteSpace ); + + printf(" %-20s : ", propertyName); + + int propertyDatatypeIndex = getPropertyDatatypeIndex( datatypeIndices, propertyIndex ); + + int propertyOffset = getPropertyOffsetByPropertyIndex( propertyOffsets, propertyIndex ); + + + if( propertyDatatypeIndex == -5 ) { + + int value = *( int * )(pointer + propertyOffset); + + printf( whiteSpace ); + + printf("%-20i ", value ); + + + + } else if( propertyDatatypeIndex == -3 ) { + + + + uintptr_t * value = ( uintptr_t * ) ( pointer + propertyOffset ); + + + + printf( whiteSpace ); + + printf( "%-20s", ( char * ) * value ); + + } else if( propertyDatatypeIndex > 0 ) { + + char * memberClassName = getClassName( propertyDatatypeIndex ); + + if( strcmp( memberClassName, "array" ) == 0 ) { + + struct array * memberArray = *(struct array ** )(pointer + propertyOffset) ; + + if( memberArray == NULL ) { + + printf(" this has to be fixed, array is not created.\n"); + + continue; + + } + + int numberRows = array_length( memberArray ); + + int * arrayPointer = ( int * ) memberArray->items; + + for (int k = 0; k < numberRows; ++k) + { + + void * pointer = array_get( memberArray, k ); + + short * row = (short*)(pointer); + + consoleManager_logObject( this, pointer, (int) *row, level ); + + } + + } + + + + } + + + printf("\n"); + + + } + + printf( whiteSpace ); + + printf( " }\n" ); + + + + } + +void consoleManager_log( consoleManager * this, int count, int datatypes[], ... ) { + + + + int level = 0; + + va_list args; + + va_start( args, count ); + + + + for (int i = 0; i < count; ++i) + { + int datatype = datatypes[i]; + + + + if( datatype == -2 ) { + + char * message = va_arg( args, char * ); + + printf("%s", message); + + } + + if( datatype == -1 ) { + + int message = va_arg( args, int ); + + printf("%i", message); + } + + if( datatype > 0 ) { + + + + void * voidPointer = va_arg( args, void * ); + + consoleManager_logObject( this, voidPointer, datatype, level++ ); + + + } + + printf(" "); + + } + + printf("\n"); + + va_end( args); + + } + +void consoleManager_error( consoleManager * this, char * message ) { + + #define ANSI_COLOR_RED "\x1b[31m" + #define ANSI_COLOR_GREEN "\x1b[32m" + #define ANSI_COLOR_DIM_YELLOW "\x1b[33m" + #define ANSI_COLOR_BLUE "\x1b[34m" + #define ANSI_COLOR_MAGENTA "\x1b[35m" + #define ANSI_COLOR_CYAN "\x1b[36m" + #define ANSI_COLOR_RESET "\x1b[0m" + + #define ANSI_COLOR_BRIGHT_YELLOW "\x1b[93m" + + printf( ANSI_COLOR_RED ); + + printf( "\n\n Error: " ); + + printf( "%s\n\n", message ); + + printf( ANSI_COLOR_RESET ); + + exit( 0 ); + + } + +void consoleManager_createHorisontalLine( consoleManager * this ) { + + struct winsize w; + + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + + for (int i = 0; i < w.ws_col; ++i) + { + + printf("-"); + + }; + + printf("\n"); + + } + +consoleManager consoleManager_new() { + + consoleManager instance; + + instance.__classIndex = 12; + + return instance; + +} + +consoleManager * consoleManager_newPointer() { + + struct consoleManager * pointer = malloc( sizeof ( struct consoleManager ) ); + + pointer->__classIndex = 12; + + return pointer; + +} + diff --git a/application/target/console.h b/application/target/console.h new file mode 100644 index 0000000..5d3c381 --- /dev/null +++ b/application/target/console.h @@ -0,0 +1,60 @@ +#ifndef _console + +#define _console + + +// Macros + +# define isCompatible(x, type) _Generic(x, type: true, default: false) + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + + +typedef struct consoleManager{ + + unsigned short __classIndex; + + +} consoleManager; + +char * consoleManager_whiteSpace( consoleManager * this, int whiteSpaceCount ); + +void consoleManager_logObject( consoleManager * this, void * voidPointer, int classIndex, int level ); + +void consoleManager_log( consoleManager * this, int count, int datatypes[], ... ); + +void consoleManager_error( consoleManager * this, char * message ); + +void consoleManager_createHorisontalLine( consoleManager * this ); + +extern struct consoleManager * console; + +consoleManager consoleManager_new( ); + +consoleManager * consoleManager_newPointer( ); + +#endif diff --git a/application/target/define.c b/application/target/define.c new file mode 100644 index 0000000..290eec6 --- /dev/null +++ b/application/target/define.c @@ -0,0 +1,7 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + diff --git a/application/target/define.h b/application/target/define.h new file mode 100644 index 0000000..4c54fe7 --- /dev/null +++ b/application/target/define.h @@ -0,0 +1,20 @@ +#ifndef _define + +#define _define + + +// Macros + + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + + +#endif diff --git a/application/target/extends.c b/application/target/extends.c new file mode 100644 index 0000000..f5c7b5f --- /dev/null +++ b/application/target/extends.c @@ -0,0 +1,222 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + +void classB_methodFromC( struct inherit * this ) { + + printf("Please print much much.."); + + } +void inherit_methodFromC( struct inherit * this ) { + + printf("Don't print soo much..."); + + } + + + +void classA_methodFromC( struct inherit * this ) { + + printf("Don't print soo much..."); + + }void inherit_methodFromA( struct inherit * this ) { + + printf("this is a method from a\n\n"); + + printf("from a: a : %i\n", this->propertyFromA); + printf("from a: b : %i\n", this->propertyFromB); + printf("from a: c : %i\n", this->propertyFromC); + + } + + + +void inherit_methodFromB( struct inherit * this ) { + + printf("this is a method from b\n\n"); + + printf("from b: a : %i\n", this->propertyFromA); + printf("from b: b : %i\n", this->propertyFromB); + printf("from b: c : %i\n", this->propertyFromC); + + } + + + + + + + + + + + + + + + +void a_methodFromA( struct inherit * this ) { + + printf("this is a method from a\n\n"); + + printf("from a: a : %i\n", this->propertyFromA); + printf("from a: b : %i\n", this->propertyFromB); + printf("from a: c : %i\n", this->propertyFromC); + + } + + + +void a_methodFromB( struct inherit * this ) { + + printf("this is a method from b\n\n"); + + printf("from b: a : %i\n", this->propertyFromA); + printf("from b: b : %i\n", this->propertyFromB); + printf("from b: c : %i\n", this->propertyFromC); + + }void b_methodFromB( struct inherit * this ) { + + printf("this is a method from b\n\n"); + + printf("from b: a : %i\n", this->propertyFromA); + printf("from b: b : %i\n", this->propertyFromB); + printf("from b: c : %i\n", this->propertyFromC); + + } + +b b_new() { + + b instance; + + instance.__classIndex = 21; + + instance.propertyFromB = 1234; + + return instance; + +} + +b * b_newPointer() { + + struct b * pointer = malloc( sizeof ( struct b ) ); + + pointer->__classIndex = 21; + + pointer->propertyFromB = 1234; + + return pointer; + +} + +a a_new() { + + a instance; + + instance.__classIndex = 22; + + instance.propertyFromA = 10; + + instance.propertyFromB = 1234; + + return instance; + +} + +a * a_newPointer() { + + struct a * pointer = malloc( sizeof ( struct a ) ); + + pointer->__classIndex = 22; + + pointer->propertyFromA = 10; + + pointer->propertyFromB = 1234; + + return pointer; + +} + +inherit inherit_new() { + + inherit instance; + + instance.__classIndex = 23; + + instance.propertyFromC = 100; + + instance.propertyFromA = 10; + + instance.propertyFromB = 1234; + + return instance; + +} + +inherit * inherit_newPointer() { + + struct inherit * pointer = malloc( sizeof ( struct inherit ) ); + + pointer->__classIndex = 23; + + pointer->propertyFromC = 100; + + pointer->propertyFromA = 10; + + pointer->propertyFromB = 1234; + + return pointer; + +} + +classA classA_new() { + + classA instance; + + instance.__classIndex = 24; + + instance.propertyFromC = 100; + + return instance; + +} + +classA * classA_newPointer() { + + struct classA * pointer = malloc( sizeof ( struct classA ) ); + + pointer->__classIndex = 24; + + pointer->propertyFromC = 100; + + return pointer; + +} + +classB classB_new() { + + classB instance; + + instance.__classIndex = 25; + + instance.propertyFromC = 111; + + return instance; + +} + +classB * classB_newPointer() { + + struct classB * pointer = malloc( sizeof ( struct classB ) ); + + pointer->__classIndex = 25; + + pointer->propertyFromC = 111; + + return pointer; + +} + diff --git a/application/target/extends.h b/application/target/extends.h new file mode 100644 index 0000000..dc822c0 --- /dev/null +++ b/application/target/extends.h @@ -0,0 +1,107 @@ +#ifndef _extends + +#define _extends + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + + +typedef struct b{ + + unsigned short __classIndex; + + int propertyFromB; + + +} b; + +void b_methodFromB( struct inherit * this ); + +typedef struct a{ + + unsigned short __classIndex; + + int propertyFromA; + + int propertyFromB; + + +} a; + +void a_methodFromA( struct inherit * this ); + +void a_methodFromB( struct inherit * this ); + +typedef struct inherit{ + + unsigned short __classIndex; + + int propertyFromC; + + int propertyFromA; + + int propertyFromB; + + +} inherit; + +void inherit_methodFromC( struct inherit * this ); + +void inherit_methodFromA( struct inherit * this ); + +void inherit_methodFromB( struct inherit * this ); + +typedef struct classA{ + + unsigned short __classIndex; + + int propertyFromC; + + +} classA; + +void classA_methodFromC( struct inherit * this ); + +typedef struct classB{ + + unsigned short __classIndex; + + int propertyFromC; + + +} classB; + +void classB_methodFromC( struct inherit * this ); + +b b_new( ); + +b * b_newPointer( ); + +a a_new( ); + +a * a_newPointer( ); + +inherit inherit_new( ); + +inherit * inherit_newPointer( ); + +classA classA_new( ); + +classA * classA_newPointer( ); + +classB classB_new( ); + +classB * classB_newPointer( ); + +#endif diff --git a/application/target/fileSystem.c b/application/target/fileSystem.c new file mode 100644 index 0000000..32cff03 --- /dev/null +++ b/application/target/fileSystem.c @@ -0,0 +1,263 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + +struct fileSystem * filesystem; + + + +void fileSystem_writeFile( fileSystem * this, char * filepath, char * data ) { + FILE *fp = fopen( filepath, "wb" ); + + if (fp != NULL) + { + fputs( data, fp ); + + fclose( fp ); + } + + } + + +struct array * fileSystem_readDir( fileSystem * this, char * filePath ) { + + DIR * dir; + + struct dirent * entry; + + struct array * files = array_newPointer(); + + if ( ( dir = opendir( filePath ) ) == NULL ){ + + perror("opendir() error"); + + } else { + + while( ( entry = readdir( dir ) ) != NULL ) { + + char * filename = (char *)entry->d_name; + + if ( strcmp( filename, ".." ) != 0 && strcmp( filename, "." ) != 0 ) { + + array_add( files, filename ); + + + + } + } + } + + return files; + + } + + +struct text * fileSystem_readFile( fileSystem * this, char * name, char * mode ) { + + char * readMode; + + if( char_operator_compare( mode , "utf8") ) { + + readMode = "r"; + + } else { + + readMode = "rb"; + + } + + FILE * file = fopen( name, readMode ); + + if ( file == NULL ) { + + fprintf( stderr, "Error: Can't open file '%s'.", name ); + + exit( EXIT_FAILURE ); + + } + + fseek( file, 0, SEEK_END ); + + long length = ftell( file ); + + + + fseek( file, 0, SEEK_SET ); + + char * buffer = malloc( sizeof( char ) * ( length + 1 ) ); + + fread( buffer, sizeof( char ), length, file ); + + fclose( file ); + + if( char_operator_compare( mode , "utf8") ) { + + buffer[ length ] = 0; + + } + + text * output = text_newPointer( "" ); + + output->length = 0; + + text_appendBinary( output, buffer, length ); + + return output; + + } + +char * fileSystem_readBinaryFile( fileSystem * this, char * name, char * mode, int * size ) { + + char * readMode; + + if( char_operator_compare( mode , "utf8") ) { + + readMode = "r"; + + } else { + + readMode = "rb"; + + printf("readmode = rb binary\n\n"); + + } + + FILE * file = fopen( name, readMode ); + + if ( file == NULL ) { + + fprintf( stderr, "Error: Can't open file '%s'.", name ); + + exit( EXIT_FAILURE ); + + } + + fseek( file, 0, SEEK_END ); + + long length = ftell( file ); + + printf("buffer length is '%i' \n\n", length); + + fseek( file, 0, SEEK_SET ); + + char * buffer = malloc( sizeof( char ) * ( length + 1 ) ); + + buffer[ length ] = '\0'; + + fread( buffer, sizeof( char ), length, file ); + + fclose( file ); + + + + + *size = length; + + printf("strlen: %i \n\n", length); + + return buffer; + + } + +int fileSystem_ensureDirectory( fileSystem * this, char * path ) { + + char * pathCopy = char_copy( path ); + + struct array * parts = char_split( pathCopy, "/" ); + + int count = array_length( parts ); + + for ( int i = 1; i < count; ++i ) + { + struct array * tempParts = char_split( pathCopy, "/" ); + + for ( int j = 0; j < count-i-1; ++j ) + { + array_pop( tempParts ); + } + + char * tempPath = array_join( tempParts, "/" ); + + if( fileSystem_exists( this, tempPath ) ) { + + } else { + + fileSystem_makeDirectory( this, tempPath ); + + } + + } + + return 1; + + } + +int fileSystem_makeDirectory( fileSystem * this, char * path ) { + + if ( fileSystem_exists( this, path ) == NULL ) { + + mkdir( path, 0700 ); + + } + + return 1; + + } + +int fileSystem_exists( fileSystem * this, char * path ) { + + if ( access( path, F_OK ) == 0 ) { + + return 1; + + } else { + + return 0; + + } + + } + +fileSystem fileSystem_new() { + + fileSystem instance; + + instance.__classIndex = 11; + + return instance; + +} + +fileSystem * fileSystem_newPointer() { + + struct fileSystem * pointer = malloc( sizeof ( struct fileSystem ) ); + + pointer->__classIndex = 11; + + return pointer; + +} + diff --git a/application/target/fileSystem.h b/application/target/fileSystem.h new file mode 100644 index 0000000..b99bb45 --- /dev/null +++ b/application/target/fileSystem.h @@ -0,0 +1,67 @@ +#ifndef _fileSystem + +#define _fileSystem + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + + +typedef struct fileSystem{ + + unsigned short __classIndex; + + +} fileSystem; + +void fileSystem_writeFile( fileSystem * this, char * filepath, char * data ); + +struct array * fileSystem_readDir( fileSystem * this, char * filePath ); + +struct text * fileSystem_readFile( fileSystem * this, char * name, char * mode ); + +char * fileSystem_readBinaryFile( fileSystem * this, char * name, char * mode, int * size ); + +int fileSystem_ensureDirectory( fileSystem * this, char * path ); + +int fileSystem_makeDirectory( fileSystem * this, char * path ); + +int fileSystem_exists( fileSystem * this, char * path ); + +extern struct fileSystem * filesystem; + +fileSystem fileSystem_new( ); + +fileSystem * fileSystem_newPointer( ); + +#endif diff --git a/application/target/floatArray.c b/application/target/floatArray.c new file mode 100644 index 0000000..911cbb1 --- /dev/null +++ b/application/target/floatArray.c @@ -0,0 +1,197 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + +int floatArray_length( floatArray * this ) { + + return this->total; + + } + + +float floatArray_get( floatArray * this, int index ) { + + if ( index >= 0 && index < this->total ){ + + return this->items[index]; + + } + + return NULL; + + } + + +void floatArray_set( floatArray * this, int index, float item ) { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + +void floatArray_resize( floatArray * this, int capacity ) { + + float * items = realloc( this->items, sizeof( float ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + +void floatArray_addVector2( floatArray * this, struct vector2 * item ) { + + floatArray_add( this, item->x ); + + floatArray_add( this, item->y ); + + } + +void floatArray_addVector3( floatArray * this, struct vector3 * item ) { + + floatArray_add( this, item->x ); + + floatArray_add( this, item->y ); + + floatArray_add( this, item->z ); + + } + +void floatArray_add( floatArray * this, float item ) { + + if ( this->capacity == this->total ){ + + floatArray_resize( this, this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + +void floatArray_delete( floatArray * this, int index ) { + if ( index < 0 || index >= this->total ){ + + return; + + } + + this->items[index] = NULL; + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + this->items[i + 1] = NULL; + + } + + this->total--; + + if ( this->total > 0 && this->total == this->capacity / 4 ){ + + floatArray_resize( this, this->capacity / 2 ); + + } + + } + + +int floatArray_array_push( floatArray * this, float item ) { + + floatArray_add( this, item ); + + return this->total; + + } + +void floatArray_unshift( floatArray * this, float item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + floatArray_resize( this, this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } + +float floatArray_pop( floatArray * this ) { + + int length = this->total; + + int lastIndex = length - 1; + + float lastItem = floatArray_get( this, lastIndex ); + + floatArray_delete( this, lastIndex ); + + return lastItem; + + } + +floatArray floatArray_new() { + + floatArray instance; + + instance.__classIndex = 7; + + instance.capacity = 10; + + instance.total = 0; + + instance.items = malloc( 10000000 ); + + return instance; + +} + +floatArray * floatArray_newPointer() { + + struct floatArray * pointer = malloc( sizeof ( struct floatArray ) ); + + pointer->__classIndex = 7; + + pointer->capacity = 10; + + pointer->total = 0; + + pointer->items = malloc( 10000000 ); + + return pointer; + +} + diff --git a/application/target/floatArray.h b/application/target/floatArray.h new file mode 100644 index 0000000..e78872a --- /dev/null +++ b/application/target/floatArray.h @@ -0,0 +1,67 @@ +#ifndef _floatArray + +#define _floatArray + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + + +typedef struct floatArray{ + + unsigned short __classIndex; + + int capacity; + + int total; + + float * items; + + +} floatArray; + +int floatArray_length( floatArray * this ); + +float floatArray_get( floatArray * this, int index ); + +void floatArray_set( floatArray * this, int index, float item ); + +void floatArray_resize( floatArray * this, int capacity ); + +void floatArray_addVector2( floatArray * this, struct vector2 * item ); + +void floatArray_addVector3( floatArray * this, struct vector3 * item ); + +void floatArray_add( floatArray * this, float item ); + +void floatArray_delete( floatArray * this, int index ); + +int floatArray_array_push( floatArray * this, float item ); + +void floatArray_unshift( floatArray * this, float item ); + +float floatArray_pop( floatArray * this ); + +floatArray floatArray_new( ); + +floatArray * floatArray_newPointer( ); + +#endif diff --git a/application/target/header.c b/application/target/header.c new file mode 100644 index 0000000..552309c --- /dev/null +++ b/application/target/header.c @@ -0,0 +1,27 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + +header header_new() { + + header instance; + + instance.__classIndex = 15; + + return instance; + +} + +header * header_newPointer() { + + struct header * pointer = malloc( sizeof ( struct header ) ); + + pointer->__classIndex = 15; + + return pointer; + +} + diff --git a/application/target/header.h b/application/target/header.h new file mode 100644 index 0000000..9b2139e --- /dev/null +++ b/application/target/header.h @@ -0,0 +1,33 @@ +#ifndef _header + +#define _header + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + + +typedef struct header{ + + unsigned short __classIndex; + + char * name; + + char * value; + + +} header; + +header header_new( ); + +header * header_newPointer( ); + +#endif diff --git a/application/target/headers.c b/application/target/headers.c new file mode 100644 index 0000000..610d016 --- /dev/null +++ b/application/target/headers.c @@ -0,0 +1,190 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + +void headerManager_parse( headerManager * this, char * headerContent ) { + + array * headerRows = char_split( headerContent, "\n"); + + int headerCount = array_length( headerRows ); + + for (int i = 1; i < headerCount; ++i) + { + + char * headerRow = array_get( headerRows, i ); + + array * headerRowParts = char_split( headerRow, ":"); + + int headerRowPartsCount = array_length( headerRowParts ); + + + if( headerRowPartsCount == 2 ) { + + char * headerName = array_get( headerRowParts, 0 ); + + char * headerValue = array_get( headerRowParts, 1 ); + + + + + + headerManager_add( this, headerName, char_removeWhitespace( headerValue ) ); + + } + + } + + printf("\n\n"); + + } + +void headerManager_display( headerManager * this ) { + + struct array * headerRows = this->headers; + + int headerCount = array_length( headerRows ); + + for (int i = 0; i < headerCount; ++i) + { + struct header * headerInstance = array_get( headerRows, i ); + + printf("%-20s %-30s \n", headerInstance->name, headerInstance->value); + + } + + } + +void headerManager_add( headerManager * this, char * name, char * value ) { + + header * headerInstance = header_newPointer(); + + headerInstance->name = name; + + headerInstance->value = value; + + array_add( this->headers, headerInstance ); + + } + +void headerManager_set( headerManager * this, char * name, char * value ) { + + struct header * headerInstance = headerManager_get( this, name ); + + if( headerInstance == NULL ) { + + headerManager_add( this, name, value ); + + } else { + + int headerIndex = headerManager_getHeaderIndex( this, name ); + + array * headers = this->headers; + + + header * headerInstance = array_get( headers, headerIndex ); + + headerInstance->value = value; + + + } + + } + +int headerManager_getHeaderIndex( headerManager * this, char * name ) { + + array * headers = this->headers; + + int count = array_length( headers ); + + for (int i = 0; i < count; ++i) + { + + header * headerInstance = array_get( headers, i ); + + if( char_operator_compare( headerInstance->name , name) ) { + + return i; + + } + + } + + return -1; + + } + +char * headerManager_getValue( headerManager * this, char * name ) { + + array * headers = this->headers; + + int count = array_length( headers ); + + for (int i = 0; i < count; ++i) + { + + header * headerInstance = array_get( headers, i ); + + if( char_operator_compare( headerInstance->name , name) ) { + + return headerInstance->value; + + } + + } + + return NULL; + + } + +header * headerManager_get( headerManager * this, char * name ) { + + array * headers = this->headers; + + int count = array_length( headers ); + + for (int i = 0; i < count; ++i) + { + + header * headerInstance = array_get( headers, i ); + + if( char_operator_compare( headerInstance->name , name) ) { + + return headerInstance; + + } + + } + + return NULL; + + } + +headerManager headerManager_new() { + + headerManager instance; + + instance.__classIndex = 14; + + instance.headers = array_newPointer(); + + return instance; + +} + +headerManager * headerManager_newPointer() { + + struct headerManager * pointer = malloc( sizeof ( struct headerManager ) ); + + pointer->__classIndex = 14; + + pointer->headers = array_newPointer(); + + return pointer; + +} + diff --git a/application/target/headers.h b/application/target/headers.h new file mode 100644 index 0000000..bbfc821 --- /dev/null +++ b/application/target/headers.h @@ -0,0 +1,49 @@ +#ifndef _headers + +#define _headers + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "header.h" + +#include "array.h" + + +typedef struct headerManager{ + + unsigned short __classIndex; + + struct array * headers; + + +} headerManager; + +void headerManager_parse( headerManager * this, char * headerContent ); + +void headerManager_display( headerManager * this ); + +void headerManager_add( headerManager * this, char * name, char * value ); + +void headerManager_set( headerManager * this, char * name, char * value ); + +int headerManager_getHeaderIndex( headerManager * this, char * name ); + +char * headerManager_getValue( headerManager * this, char * name ); + +header * headerManager_get( headerManager * this, char * name ); + +headerManager headerManager_new( ); + +headerManager * headerManager_newPointer( ); + +#endif diff --git a/application/target/http.c b/application/target/http.c new file mode 100644 index 0000000..71d7547 --- /dev/null +++ b/application/target/http.c @@ -0,0 +1,547 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void http_createServer( http * this, void ( * requestCallback )( request * req, text * response ) ) { + + this->requestCallback = requestCallback; + + + if( this->useSSL == 1 ) { + + http_initializeOpenSSL( this ); + + } + + printf("after initializeOpenSSL\n\n"); + + } + +void http_initializeOpenSSL( http * this ) { + + + + + + + + SSL_load_error_strings(); + + OpenSSL_add_ssl_algorithms(); + + SSLeay_add_ssl_algorithms(); + + return; + + } + +int http_listen( http * this, int port ) { + + this->socket = socket( AF_INET, SOCK_STREAM, 0 ); + + int iSetOption = 1; + + setsockopt( this->socket, SOL_SOCKET, SO_REUSEADDR, ( char * ) & iSetOption, sizeof( iSetOption ) ); + + if ( this->socket == -1 ) { + + perror("webserver (socket)"); + + exit( 0 ); + + } else { + + printf("socket created successfully\n"); + + } + + + + this->hostAddress->sin_family = AF_INET; + + this->hostAddress->sin_port = htons( port ); + + this->hostAddress->sin_addr.s_addr = htonl( INADDR_ANY ); + + + + if ( bind( this->socket, ( struct sockaddr * ) this->hostAddress, this->hostAddresslength ) != 0 ) { + + perror("webserver (bind)"); + + exit( 0 ); + + } else { + + printf("socket successfully bound to address\n"); + + } + + + if ( listen( this->socket, SOMAXCONN ) != 0 ) { + + perror("webserver (listen)"); + + exit( 0 ); + + } else { + + printf("server listening for connections\n"); + + } + + + + for (;;) { + + http_acceptConnection( this ); + + } + + + + + printf("exit"); + + + return 0; + + } + +char * http_getExtension( http * this, char * path ) { + + array * parts = char_split( path, "."); + + int count = array_length( parts ); + + return array_get( parts, count - 1 ); + + } + +void http_logRequest( http * this, request * requestInstance ) { + + printf("server address: [%s:%u]\n", requestInstance->address, requestInstance->port ); + + printf("mimeType: %-30s \n", requestInstance->mimeType); + + printf("header: %-30s \n", requestInstance->extension ); + + printf("method: %-30s \n", requestInstance->method ); + + printf("version: %-30s \n\n", requestInstance->version ); + + } + +void http_acceptConnection( http * this ) { + + fileSystem * filesystem = this->filesystem; + + mimeTypes * mimetypes = this->mimetypes; + + text * response = text_newPointer(""); + + + + char buffer[ 4096 ]; + + + struct sockaddr_in client_addr; + + int client_addrlen = sizeof(client_addr); + + + int socketConnection = accept( this->socket, + (struct sockaddr *)this->hostAddress, + ( socklen_t * ) & this->hostAddresslength ); + + + + + + + + + + + + + + + SSL * ssl = NULL; + + if( this->useSSL == 1 ) { + + const SSL_METHOD * method = SSLv23_server_method(); + + this->sslContext = SSL_CTX_new( method ); + + if ( this->sslContext == NULL ) { + + printf("Error loading SSL_CTX_NEW '%s'\n\n", stderr); + + } + + SSL_CTX_set_options( this->sslContext, SSL_OP_SINGLE_DH_USE ); + + int use_cert = SSL_CTX_use_certificate_file( this->sslContext, "/etc/letsencrypt/live/unifyjs.org/fullchain.pem" , SSL_FILETYPE_PEM ); + + int use_prv = SSL_CTX_use_PrivateKey_file( this->sslContext, "/etc/letsencrypt/live/unifyjs.org/privkey.pem", SSL_FILETYPE_PEM ); + + if( use_cert != 1 ) { + + printf( "error: SSL_CTX_use_certificate_file\n\n" ); + + } + + if( use_prv != 1 ) { + + printf( "error: SSL_CTX_use_PrivateKey_file\n\n" ); + + } + + if ( !SSL_CTX_check_private_key(this->sslContext) ) { + + printf("Private key does not match the certificate public key\n"); + + + } + + ssl = SSL_new( this->sslContext ); + + SSL_set_fd( ssl, socketConnection ); + + + int ssl_err = SSL_accept( ssl ); + + + + + + if( ssl_err == 0 ){ + + printf("SSL_accept returned zero\n"); + + } + + + int n; + + if( ssl_err < 0 ) { + + int err; + + if( ( err = SSL_get_error(ssl,n ) ) == SSL_ERROR_WANT_READ) { + + printf("SSL_accept wants more data\n"); + + return ; + + } + + exit(7); + + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } else { + printf("connection accepted\n\n"); + + + int sockn = getsockname( socketConnection, + ( struct sockaddr * ) &client_addr, + ( socklen_t * ) &client_addrlen); + + + if ( sockn == -1 ) { + + perror("webserver (getsockname)"); + + } + + } + + int valread; + + if( this->useSSL == 1 ) { + + valread = SSL_read( ssl, buffer, 4096 - 1 ); + + } else { + + printf("read without ssl\n\n"); + + int valread = read( socketConnection, buffer, 4096 -1 ); + + if ( valread == -1 ) { + + perror("webserver (read)"); + + + + } + + } + + + if ( valread == -1 ) { + + perror("webserver (read)"); + + + } + + + request * requestInstance = request_newPointer(); + + + sscanf( buffer, "%s %s %s", requestInstance->method, requestInstance->url, requestInstance->version ); + + + requestInstance->address = inet_ntoa( client_addr.sin_addr ); + + requestInstance->port = ntohs( client_addr.sin_port ); + + requestInstance->extension = http_getExtension( this, requestInstance->url ); + + requestInstance->mimeType = mimeTypes_getByExtension( mimetypes, requestInstance->extension ); + + this->requestCallback( requestInstance, response ); + + + + + + + int writeResponse; + + if( this->useSSL == 1 ) { + + writeResponse = SSL_write( ssl, response->value, response->length ); + + } else { + + + int writeResponse = write( socketConnection, response->value, response->length ); + + printf("close connection"); + + if ( writeResponse == -1 ) { + + perror("webserver (write)"); + + return; + + } + } + + if ( writeResponse == -1 ) { + + perror("webserver (write)"); + + return; + + } else { + + + + } + + + + + + + + + + + close( socketConnection ); + + + + + + + + + + } + +void http_dump_buffer( http * this, void *buffer, int buffer_size ) { + int i; + + for(i = 0;i < buffer_size;++i){ + + printf( "%c", ( (char *) buffer )[i]); + + } + + } + + + + +void abort( ) { + + +} + +http http_new() { + + http instance; + + instance.__classIndex = 13; + + instance.hostAddress = malloc( sizeof( struct sockaddr_in ) ); + + instance.hostAddresslength = sizeof( struct sockaddr_in ); + + instance.filesystem = fileSystem_newPointer(); + + instance.mimetypes = mimeTypes_newPointer(); + + instance.headers = headerManager_newPointer(); + + instance.useSSL = 1; + + return instance; + +} + +http * http_newPointer() { + + struct http * pointer = malloc( sizeof ( struct http ) ); + + pointer->__classIndex = 13; + + pointer->hostAddress = malloc( sizeof( struct sockaddr_in ) ); + + pointer->hostAddresslength = sizeof( struct sockaddr_in ); + + pointer->filesystem = fileSystem_newPointer(); + + pointer->mimetypes = mimeTypes_newPointer(); + + pointer->headers = headerManager_newPointer(); + + pointer->useSSL = 1; + + return pointer; + +} + diff --git a/application/target/http.h b/application/target/http.h new file mode 100644 index 0000000..675584b --- /dev/null +++ b/application/target/http.h @@ -0,0 +1,91 @@ +#ifndef _http + +#define _http + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include "./mimeTypes.h" + +#include "./text.h" + +#include "./fileSystem.h" + + +typedef struct http{ + + unsigned short __classIndex; + + int socket; + + struct sockaddr_in * hostAddress; + + int hostAddresslength; + + struct fileSystem * filesystem; + + struct mimeTypes * mimetypes; + + struct headerManager * headers; + + int useSSL; + + SSL_CTX * sslContext; + + void ( * requestCallback )( struct request * requestInstance, struct text * response ); + + +} http; + +void http_createServer( http * this, void ( * requestCallback )( request * req, text * response ) ); + +void http_initializeOpenSSL( http * this ); + +int http_listen( http * this, int port ); + +char * http_getExtension( http * this, char * path ); + +void http_logRequest( http * this, request * requestInstance ); + +void http_acceptConnection( http * this ); + +void http_dump_buffer( http * this, void *buffer, int buffer_size ); + +void abort( ); + +http http_new( ); + +http * http_newPointer( ); + +#endif diff --git a/application/target/int.c b/application/target/int.c new file mode 100644 index 0000000..59cad2f --- /dev/null +++ b/application/target/int.c @@ -0,0 +1,21 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + +char * int_toText( int * this ) { + + char * textNumber = malloc( sizeof( char ) * 20 ); + + sprintf( textNumber, "%d", this ); + + return textNumber; + + } + +int int_negative( int * this ) { + + return 12; + + } + diff --git a/application/target/int.h b/application/target/int.h new file mode 100644 index 0000000..1dc2992 --- /dev/null +++ b/application/target/int.h @@ -0,0 +1,24 @@ +#ifndef _int + +#define _int + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + + +char * int_toText( int * this ); + +int int_negative( int * this ); + +#endif diff --git a/application/target/mesh.c b/application/target/mesh.c new file mode 100644 index 0000000..b71cbc1 --- /dev/null +++ b/application/target/mesh.c @@ -0,0 +1,365 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void mesh_createBuffers( mesh * this ) { + + struct unsignedIntegerArray * indices = unsignedIntegerArray_newPointer(); + + struct floatArray * textureCoordinates = floatArray_newPointer(); + + struct floatArray * vertexCoordinates = floatArray_newPointer(); + + struct floatArray * normalCoordinates = floatArray_newPointer(); + + struct unsignedIntegerArray * meshIndices = unsignedIntegerArray_newPointer(); + + + int subdivisionsDepth = 1; + + int subdivisionsWidth = 1; + + float width = 2; + + float depth = 2; + + + int meshCount = 100 * 50; + + int meshStartIndex = 0; + + for (int meshIndex = 0; meshIndex < meshCount; ++meshIndex) + { + + + meshStartIndex = unsignedIntegerArray_length( meshIndices ); + + + + int numVertsAcross = subdivisionsWidth + 1; + + for ( int z = 0; z < subdivisionsDepth; z++ ) { + + for ( int x = 0; x < subdivisionsWidth; x++ ) { + + + unsignedIntegerArray_add( indices, ( z + 0 ) * numVertsAcross + x + meshStartIndex ); + + unsignedIntegerArray_add( indices, ( z + 1 ) * numVertsAcross + x + meshStartIndex ); + + unsignedIntegerArray_add( indices, ( z + 0 ) * numVertsAcross + x + 1 + meshStartIndex ); + + + unsignedIntegerArray_add( indices, ( z + 1 ) * numVertsAcross + x + meshStartIndex ); + + unsignedIntegerArray_add( indices, ( z + 1 ) * numVertsAcross + x + 1 + meshStartIndex ); + + unsignedIntegerArray_add( indices, ( z + 0 ) * numVertsAcross + x + 1 + meshStartIndex ); + + } + + } + + + for ( int z = 0; z <= subdivisionsDepth; z++ ) { + + for ( int x = 0; x <= subdivisionsWidth; x++ ) { + + + float u = ( float ) x; + + float v = ( float ) z; + + + floatArray_add( textureCoordinates, u ); + + floatArray_add( textureCoordinates, ( 1 - v ) ); + + + floatArray_add( vertexCoordinates, width * u - width * 0.5 ); + + floatArray_add( vertexCoordinates, depth * v - depth * 0.5 ); + + floatArray_add( vertexCoordinates, 0 ); + + + floatArray_add( normalCoordinates, 0 ); + + floatArray_add( normalCoordinates, 0 ); + + floatArray_add( normalCoordinates, 1 ); + + + unsignedIntegerArray_add( meshIndices, meshIndex ); + + + } + + } + + + } + + + + + + + + + + + int vertexBufferSize = floatArray_length( vertexCoordinates ) * sizeof( float ); + + + glGenBuffers( 1, &this->vertexbuffer ); + + glBindBuffer( GL_ARRAY_BUFFER, this->vertexbuffer ); + + glBufferData( GL_ARRAY_BUFFER, vertexBufferSize, vertexCoordinates->items, GL_STATIC_DRAW ); + + + + int meshIndexBufferSize = unsignedIntegerArray_length( meshIndices ) * sizeof( unsigned int ); + + + glGenBuffers( 1, &this->meshIndexBuffer ); + + glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, this->meshIndexBuffer ); + + glBufferData( GL_ELEMENT_ARRAY_BUFFER, meshIndexBufferSize, meshIndices->items, GL_STATIC_DRAW ); + + + + int textureCoordinateSize = floatArray_length( textureCoordinates ) * sizeof( float ); + + + glGenBuffers( 1, &this->textureCoordinateBuffer ); + + glBindBuffer( GL_ARRAY_BUFFER, this->textureCoordinateBuffer ); + + glBufferData( GL_ARRAY_BUFFER, textureCoordinateSize, textureCoordinates->items, GL_STATIC_DRAW ); + + + + int indexBufferSize = unsignedIntegerArray_length( indices ) * sizeof( unsigned int ); + + + glGenBuffers( 1, &this->indexBuffer ); + + glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, this->indexBuffer ); + + glBufferData( GL_ELEMENT_ARRAY_BUFFER, indexBufferSize, indices->items, GL_STATIC_DRAW ); + + + + + + + + + + + + GLint compareSize = 0; + + glGetBufferParameteriv( GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &compareSize ); + + if( indexBufferSize != compareSize ) + { + glDeleteBuffers(1, &this->indexBuffer); + + + printf("ERROR: size error"); + return; + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + this->indices = indices; + + this->textureCoordinates = textureCoordinates; + + this->vertexCoordinates = vertexCoordinates; + + this->normalCoordinates = normalCoordinates; + + } + +void mesh_createOrderedTriangleStripQuad( mesh * this ) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +void mesh_createBuffer( mesh * this, GLuint * buffer, int bufferSize, float * bufferData ) { + + + glGenBuffers( 1, buffer ); + + glBindBuffer( GL_ARRAY_BUFFER, this->vertexbuffer ); + glBufferData( GL_ARRAY_BUFFER, bufferSize, bufferData, GL_STATIC_DRAW ); + + + + + + + + + + + + + + + + + + + + + + + } + +mesh mesh_new() { + + mesh instance; + + instance.__classIndex = 18; + + return instance; + +} + +mesh * mesh_newPointer() { + + struct mesh * pointer = malloc( sizeof ( struct mesh ) ); + + pointer->__classIndex = 18; + + return pointer; + +} + diff --git a/application/target/mesh.h b/application/target/mesh.h new file mode 100644 index 0000000..0f35960 --- /dev/null +++ b/application/target/mesh.h @@ -0,0 +1,66 @@ +#ifndef _mesh + +#define _mesh + + +// Macros + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "unsignedIntegerArray.h" + +#include "floatArray.h" + +#include + +#include + +#include + + +typedef struct mesh{ + + unsigned short __classIndex; + + struct unsignedIntegerArray * indices; + + struct floatArray * textureCoordinates; + + struct floatArray * vertexCoordinates; + + struct floatArray * normalCoordinates; + + GLuint indexBuffer; + + GLuint vertexbuffer; + + GLuint textureCoordinateBuffer; + + GLuint meshIndexBuffer; + + GLuint uvBuffer; + + +} mesh; + +void mesh_createBuffers( mesh * this ); + +void mesh_createOrderedTriangleStripQuad( mesh * this ); + +void mesh_createBuffer( mesh * this, GLuint * buffer, int bufferSize, float * bufferData ); + +mesh mesh_new( ); + +mesh * mesh_newPointer( ); + +#endif diff --git a/application/target/mimeTypes.c b/application/target/mimeTypes.c new file mode 100644 index 0000000..7433a69 --- /dev/null +++ b/application/target/mimeTypes.c @@ -0,0 +1,97 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + +void mimeTypes_constructor( mimeTypes * this ) { + + mimeTypes_add( this, "html", "text/html"); + + mimeTypes_add( this, "css", "text/css"); + + mimeTypes_add( this, "ttf", "application/x-font-ttf"); + + mimeTypes_add( this, "png", "image/png"); + + mimeTypes_add( this, "svg", "image/svg+xml"); + + } + +void mimeTypes_add( mimeTypes * this, char * extension, char * mimeType ) { + + struct array * extensions = this->extensions; + + array_add( extensions, extension ); + + + struct array * mimeTypes = this->mimeTypes; + + array_add( mimeTypes, mimeType ); + + } + +char * mimeTypes_getByExtension( mimeTypes * this, char * extension ) { + + struct array * extensions = this->extensions; + + struct array * mimeTypes = this->mimeTypes; + + int count = array_length( extensions ); + + for (int i = 0; i < count; ++i) + { + + char * currentExtension = array_get( extensions, i ); + + if( char_operator_compare( currentExtension , extension) ) { + + char * mimeType = array_get( mimeTypes, i ); + + return mimeType; + + } + + } + + return "no-mimetype"; + + } + +mimeTypes mimeTypes_new() { + + mimeTypes instance; + + instance.__classIndex = 17; + + instance.extensions = array_newPointer(); + + instance.mimeTypes = array_newPointer(); + + mimeTypes_constructor( &instance); + + return instance; + +} + +mimeTypes * mimeTypes_newPointer() { + + struct mimeTypes * pointer = malloc( sizeof ( struct mimeTypes ) ); + + pointer->__classIndex = 17; + + pointer->extensions = array_newPointer(); + + pointer->mimeTypes = array_newPointer(); + + mimeTypes_constructor( pointer ); + + return pointer; + +} + diff --git a/application/target/mimeTypes.h b/application/target/mimeTypes.h new file mode 100644 index 0000000..5c4c608 --- /dev/null +++ b/application/target/mimeTypes.h @@ -0,0 +1,41 @@ +#ifndef _mimeTypes + +#define _mimeTypes + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "array.h" + + +typedef struct mimeTypes{ + + unsigned short __classIndex; + + array * extensions; + + array * mimeTypes; + + +} mimeTypes; + +void mimeTypes_constructor( mimeTypes * this ); + +void mimeTypes_add( mimeTypes * this, char * extension, char * mimeType ); + +char * mimeTypes_getByExtension( mimeTypes * this, char * extension ); + +mimeTypes mimeTypes_new( ); + +mimeTypes * mimeTypes_newPointer( ); + +#endif diff --git a/application/target/opengl.c b/application/target/opengl.c new file mode 100644 index 0000000..2fec12a --- /dev/null +++ b/application/target/opengl.c @@ -0,0 +1,697 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +static int DoubleBufferAttributes[] = { + GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DEPTH_SIZE, 12, + GLX_DOUBLEBUFFER, + None, +}; + + + + + + + + + + + + + + + + + + + + + + + + + + + +void opengl_initialize( opengl * this ) { + + opengl_setupWindow( this ); + + opengl_showVersion( this ); + + opengl_createShaders( this ); + + opengl_createQuad( this ); + + + + opengl_setupTime( this ); + + opengl_setupRenderLoop( this ); + + } + +void opengl_showVersion( opengl * this ) { + + printf("opengl version : %s\n\n", glGetString(GL_VERSION) ); + + } + +void opengl_setupTime( opengl * this ) { + + clock_gettime( CLOCK_REALTIME, &this->startTime ); + + } + +void opengl_setupWindow( opengl * this ) { + + this->mainDisplay = XOpenDisplay( 0 ); + + this->MainScreen = XDefaultScreen( this->mainDisplay ); + + this->RootWindow = XDefaultRootWindow( this->mainDisplay ); + + + int empty; + + int ResultStatus = glXQueryExtension( this->mainDisplay, &empty, &empty ); + + XVisualInfo* VisualInfo = glXChooseVisual( this->mainDisplay, this->MainScreen, DoubleBufferAttributes ); + + GLXContext ShareList = None; + + int IsDirectRendering = True; + + GLXContext OpenGLContext = glXCreateContext( this->mainDisplay, VisualInfo, ShareList, IsDirectRendering ); + + + + int WindowX = 0; + + int WindowY = 0; + + int WindowWidth = 800; + + int WindowHeight = 600; + + int BorderWidth = 0; + + int WindowClass = InputOutput; + + int WindowDepth = VisualInfo->depth; + + + Visual* WindowVisual = VisualInfo->visual; + + int AttributeValueMask = CWBackPixel | CWEventMask | CWColormap; + + + XSetWindowAttributes WindowAttributes = {}; + + WindowAttributes.colormap = XCreateColormap( this->mainDisplay, this->RootWindow, VisualInfo->visual, AllocNone); + + WindowAttributes.background_pixel = 0xffafe9af; + + WindowAttributes.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | PointerMotionMask; + + this->mainWindow = XCreateWindow( this->mainDisplay, this->RootWindow, + WindowX, WindowY, WindowWidth, WindowHeight, + BorderWidth, WindowDepth, WindowClass, WindowVisual, + AttributeValueMask, &WindowAttributes); + + XStoreName( this->mainDisplay, this->mainWindow, "Opengl: Fixed function pipeline" ); + + glXMakeCurrent( this->mainDisplay, this->mainWindow, OpenGLContext ); + + XMapWindow( this->mainDisplay, this->mainWindow ); + + Atom WM_DELETE_WINDOW = XInternAtom( this->mainDisplay, "WM_DELETE_WINDOW", False ); + + if( !XSetWMProtocols( this->mainDisplay, this->mainWindow, &WM_DELETE_WINDOW, 1) ) { + + printf( "Couldn't register WM_DELETE_WINDOW\n" ); + + } + + } + +void opengl_setupRenderLoop( opengl * this ) { + + int IsProgramRunning = 1; + + while( IsProgramRunning ) { + + while( XPending( this->mainDisplay ) ) { + + XEvent GeneralEvent = {}; + + XNextEvent( this->mainDisplay, &GeneralEvent ); + + switch( GeneralEvent.type ) { + + case ClientMessage: + { + + IsProgramRunning = 0; + + } break; + } + + } + + { + + opengl_render( this ); + + } + + } + + } + +void opengl_createShaders( opengl * this ) { + + + shader * currentShader = shader_newPointer(); + + + shader_createFromFile( currentShader, "assets/shaders/color.vertex", "assets/shaders/color.fragment" ); + + vector3 * diffuseColor = vector3_newPointer( 0.0, 1.0, 0.0 ); + + shader_setUniform( currentShader, "diffuse", diffuseColor ); + + vector2 * position = vector2_newPointer( 1.0, 0.0 ); + + shader_setUniform( currentShader, "position", position ); + + this->currentShader = currentShader; + + } + +void opengl_createQuad( opengl * this ) { + + this->quads = mesh_newPointer(); + + mesh_createBuffers( this->quads ); + + + } + +double opengl_clockToMilliseconds( opengl * this, clock_t ticks ) { + + return ( ticks / ( double ) CLOCKS_PER_SEC ); + + } + +void opengl_render( opengl * this ) { + + + + Window qRoot; + + Window qChild; + + unsigned int qMask; + + int childX; + + int childY; + + int mouseX; + + int mouseY; + + int child; + + + + int windowX = 0; + + int windowY = 0; + + int windowWidth = 0; + + int windowHeight = 0; + + + + + XWindowAttributes window; + + + + if( XGetWindowAttributes( this->mainDisplay, this->mainWindow, &window ) ) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + + + + if( XQueryPointer( this->mainDisplay, this->RootWindow, &qRoot, &qChild, &mouseX, &mouseY, &childX, &childY, &qMask ) ) + { + + mouseX -= window.x; + + mouseY -= window.y; + + for(int i = 0; i < sizeof(int) * 8; i++) + { + int mask = 1 << sizeof(int) * 8 - i - 1; + + if(mask & qMask) + { + + } + else + { + + } + + } + + + + if( qMask == Button1MotionMask ) { + + printf("LeftMouse\n"); + + } + + + if( qMask == Button2MotionMask ) { + + printf("Button2MotionMask\n"); + + } + + + if( qMask == Button3MotionMask ) { + + printf("RightMouse\n"); + + } + + if( qMask == Button4MotionMask ) { + + printf("Button2MotionMask\n"); + + } + + + if( qMask == Button5MotionMask ) { + + printf("Button2MotionMask\n"); + + } + + if( qMask == ShiftMask ) { + + printf("Pressed shift\n"); + + } + + if( qMask == ControlMask ) { + + printf("Pressed control\n"); + + } + + + if( qMask == EnterWindowMask ) { + + + + } + + + + XEvent event; + + int keyboardEventCount = XPending( this->mainDisplay ); + + + + while( XPending( this->mainDisplay ) ) { + + + XNextEvent( this->mainDisplay, &event ); + + switch ( event.type ) { + + case KeyPress: + + printf("key has been pressed. %i\n\n", event.xkey.keycode); + + break; + + + case KeyRelease: + + printf("key has been released. %i\n\n", event.xkey.keycode); + + break; + + + + + case Expose: + + break; + + + + default: + + + + + + } + + + + } + + + + + + + + + + + + + } + + + + + + opengl_clearColor( this, 0.0, 1.0, 0.6, 1.0 ); + + opengl_clear( this, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + + + float number = (float)(this->frameCount & 1000) / 1000; + + shader * currentShader = this->currentShader; + + + + + + + vector2 * windowSize = vector2_newPointer( window.width, window.height ); + + vector2 * mouse = vector2_newPointer( mouseX, mouseY ); + + shader_setUniform( currentShader, "window", windowSize ); + + shader_setUniform( currentShader, "mouse", mouse ); + + int itemSize; + + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glEnableVertexAttribArray( 0 ); + + glEnableVertexAttribArray( 1 ); + + glEnableVertexAttribArray( 3 ); + + + + + itemSize = 3; + + glBindBuffer( GL_ARRAY_BUFFER, this->quads->vertexbuffer ); + + glVertexAttribPointer( 0, itemSize, GL_FLOAT, GL_FALSE, 0, ( void * ) 0 ); + + + itemSize = 2; + + glBindBuffer( GL_ARRAY_BUFFER, this->quads->textureCoordinateBuffer ); + + glVertexAttribPointer( 1, itemSize, GL_FLOAT, GL_FALSE, 0, ( void * ) 0 ); + + + itemSize = 1; + + glBindBuffer( GL_ARRAY_BUFFER, this->quads->meshIndexBuffer ); + + glVertexAttribPointer( 2, itemSize, GL_FLOAT, GL_FALSE, 0, ( void * ) 0 ); + + + int numItems = 10000; + + glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, this->quads->indexBuffer ); + + glDrawElements( GL_TRIANGLES, numItems, GL_UNSIGNED_INT, ( void * ) 0 ); + + glDisableVertexAttribArray( 0 ); + + glDisableVertexAttribArray( 1 ); + + + + opengl_end( this ); + + opengl_flush( this ); + + + + } + +void opengl_displayFPS( opengl * this ) { + + struct timespec now; + + clock_gettime( CLOCK_REALTIME, &now ); + + this->frameCount++; + + int elapsedTime = now.tv_sec - this->startTime.tv_sec; + + if( elapsedTime != this->lastTime ) { + + printf("%i fps.\n\n", this->frameCount ); + + this->lastTime = elapsedTime; + + this->frameCount = 0; + + } + + } + +void opengl_vertex2f( opengl * this, float x, float y ) { + + glVertex2f( x, y ); + + } + +void opengl_color3f( opengl * this, float r, float g, float b ) { + + glColor3f( r, g, b ); + + } + +void opengl_clear( opengl * this, GLbitfield mask ) { + + glClear( mask ); + + } + +void opengl_clearColor( opengl * this, float r, float g, float b, float a ) { + + glClearColor( r, g, b, a ); + + } + +void opengl_begin( opengl * this, GLenum mode ) { + + glBegin( mode ); + + } + +void opengl_end( opengl * this ) { + + glEnd(); + + } + +void opengl_flush( opengl * this ) { + + + + + + + + PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT; + PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA; + PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI; + + glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalEXT"); + + if (glXSwapIntervalEXT != NULL) { + + glXSwapIntervalEXT(this->mainDisplay, this->mainWindow, 0); + + } else { + + glXSwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalMESA"); + + + + if ( glXSwapIntervalMESA != NULL ) { + + glXSwapIntervalMESA(0); + + } else { + + glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalSGI"); + + if ( glXSwapIntervalSGI != NULL ) { + glXSwapIntervalSGI(0); + } + + } + } + + glXSwapBuffers( this->mainDisplay, this->mainWindow ); + + + + + + } + +opengl opengl_new() { + + opengl instance; + + instance.__classIndex = 0; + + instance.lastTime = clock(); + + instance.deltaTime = 0; + + instance.frameCount = 0; + + return instance; + +} + +opengl * opengl_newPointer() { + + struct opengl * pointer = malloc( sizeof ( struct opengl ) ); + + pointer->__classIndex = 0; + + pointer->lastTime = clock(); + + pointer->deltaTime = 0; + + pointer->frameCount = 0; + + return pointer; + +} + diff --git a/application/target/opengl.h b/application/target/opengl.h new file mode 100644 index 0000000..f5f3ed7 --- /dev/null +++ b/application/target/opengl.h @@ -0,0 +1,124 @@ +#ifndef _opengl + +#define _opengl + + +// Macros + +#define HEIGHT 480 + + +#define WIDTH 640 + + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include "unsignedIntegerArray.h" + +#include "floatArray.h" + +#include "shader.h" + +#include "mesh.h" + + +typedef struct opengl{ + + unsigned short __classIndex; + + Display * mainDisplay; + + Window mainWindow; + + int MainScreen; + + Window RootWindow; + + int lastTime; + + clock_t deltaTime; + + struct timespec startTime; + + int frameCount; + + GLuint vertexbuffer; + + GLuint indexBuffer; + + struct shader * currentShader; + + struct mesh * quads; + + unsigned char image[HEIGHT][WIDTH]; + + +} opengl; + +void opengl_initialize( opengl * this ); + +void opengl_showVersion( opengl * this ); + +void opengl_setupTime( opengl * this ); + +void opengl_setupWindow( opengl * this ); + +void opengl_setupRenderLoop( opengl * this ); + +void opengl_createShaders( opengl * this ); + +void opengl_createQuad( opengl * this ); + +double opengl_clockToMilliseconds( opengl * this, clock_t ticks ); + +void opengl_render( opengl * this ); + +void opengl_displayFPS( opengl * this ); + +void opengl_vertex2f( opengl * this, float x, float y ); + +void opengl_color3f( opengl * this, float r, float g, float b ); + +void opengl_clear( opengl * this, GLbitfield mask ); + +void opengl_clearColor( opengl * this, float r, float g, float b, float a ); + +void opengl_begin( opengl * this, GLenum mode ); + +void opengl_end( opengl * this ); + +void opengl_flush( opengl * this ); + +static int DoubleBufferAttributes[] ; + +opengl opengl_new( ); + +opengl * opengl_newPointer( ); + +#endif diff --git a/application/target/request.c b/application/target/request.c new file mode 100644 index 0000000..bdb212d --- /dev/null +++ b/application/target/request.c @@ -0,0 +1,116 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + +void request_constructor( request * this ) { + + + } + +void request_free( request * this ) { + + + + + + + + + + + + + + + + + + + + + + free( this ); + + + } + +request request_new() { + + request instance; + + instance.__classIndex = 16; + + instance.connection = malloc( BUFFER_SIZE ); + + instance.address = malloc( BUFFER_SIZE ); + + instance.url = malloc( BUFFER_SIZE ); + + instance.method = malloc( BUFFER_SIZE ); + + instance.version = malloc( BUFFER_SIZE ); + + instance.mimeType = malloc( BUFFER_SIZE ); + + instance.extension = malloc( BUFFER_SIZE ); + + instance.headers = headerManager_newPointer(); + + request_constructor( &instance); + + return instance; + +} + +request * request_newPointer() { + + struct request * pointer = malloc( sizeof ( struct request ) ); + + pointer->__classIndex = 16; + + pointer->connection = malloc( BUFFER_SIZE ); + + pointer->address = malloc( BUFFER_SIZE ); + + pointer->url = malloc( BUFFER_SIZE ); + + pointer->method = malloc( BUFFER_SIZE ); + + pointer->version = malloc( BUFFER_SIZE ); + + pointer->mimeType = malloc( BUFFER_SIZE ); + + pointer->extension = malloc( BUFFER_SIZE ); + + pointer->headers = headerManager_newPointer(); + + request_constructor( pointer ); + + return pointer; + +} + diff --git a/application/target/request.h b/application/target/request.h new file mode 100644 index 0000000..1e36aa9 --- /dev/null +++ b/application/target/request.h @@ -0,0 +1,58 @@ +#ifndef _request + +#define _request + + +// Macros + +#define BUFFER_SIZE 1024 + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "headers.h" + +#include "stdlib.h" + + +typedef struct request{ + + unsigned short __classIndex; + + char * connection; + + char * address; + + int port; + + char * url; + + char * method; + + char * version; + + char * mimeType; + + char * extension; + + struct headerManager * headers; + + +} request; + +void request_constructor( request * this ); + +void request_free( request * this ); + +request request_new( ); + +request * request_newPointer( ); + +#endif diff --git a/application/target/shader.c b/application/target/shader.c new file mode 100644 index 0000000..e35e609 --- /dev/null +++ b/application/target/shader.c @@ -0,0 +1,344 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void shader_checkShaderForErrors( shader * this, GLuint shader ) { + + GLint isCompiled = 0; + + glGetShaderiv( shader, GL_COMPILE_STATUS, &isCompiled ); + + if(isCompiled == GL_FALSE) + { + GLint maxLength = 0; + + glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &maxLength ); + + GLchar errorMessage[ maxLength ]; + + + glGetShaderInfoLog( shader, maxLength, &maxLength, errorMessage ); + + printf("Error: %s\n\n", errorMessage); + + + glDeleteShader( shader ); + + return; + } + + } + +void shader_createFromFile( shader * this, char * vertexShaderPath, char * fragmentShaderPath ) { + + text * vertexShaderSource = fileSystem_readFile( filesystem, vertexShaderPath, "utf8" ); + + text * fragmentShaderSource = fileSystem_readFile( filesystem, fragmentShaderPath, "utf8" ); + + GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); + + glShaderSource( vertexShader, 1, &vertexShaderSource->value, NULL ); + + glCompileShader( vertexShader ); + + shader_checkShaderForErrors( this, vertexShader ); + + + + GLuint fragmentShader = glCreateShader( GL_FRAGMENT_SHADER ); + + glShaderSource( fragmentShader, 1, &fragmentShaderSource->value, NULL ); + + glCompileShader( fragmentShader ); + + shader_checkShaderForErrors( this, fragmentShader ); + + + GLint program = glCreateProgram(); + + glAttachShader( program, fragmentShader ); + + glAttachShader( program, vertexShader ); + + + + glLinkProgram( program ); + + glUseProgram( program ); + + + + + int attributeCount = 0; + + GLsizei bufSize = 64; + + GLsizei length; + + GLint size; + + GLenum type; + + + + glGetProgramiv( program, GL_ACTIVE_ATTRIBUTES, &attributeCount ); + + printf("Active Attributes: %d\n", attributeCount ); + + + for (int i = 0; i < attributeCount; i++) + { + GLenum type; + + + + + attribute attributeInstance = attribute_new(); + + glGetActiveAttrib( program, ( GLuint ) i, bufSize, &length, &size, &type, attributeInstance.name); + + printf("Attribute #%d Type: %u Name: %s\n", i, type, attributeInstance.name); + + GLint attributeLocation = glGetAttribLocation( program, attributeInstance.name ); + + glEnableVertexAttribArray( attributeLocation ); + + + attributeInstance.location = attributeLocation; + + + + attributeInstance.type = type; + + array_add( this->attributes, &attributeInstance ); + + + } + + printf("attributes count: %i\n", array_length( this->attributes )); + + int uniformCount = 0; + + + + glGetProgramiv( program, GL_ACTIVE_UNIFORMS, &uniformCount ); + + printf( "Active Uniforms: %d\n", uniformCount ); + + + + + for (int i = 0; i < uniformCount; i++) + { + + uniform * uniformInstance = uniform_newPointer(); + + GLenum type; + + GLchar name[bufSize]; + + glGetActiveUniform( program, ( GLuint ) i, bufSize, &length, &size, &type, uniformInstance->name ); + + printf( "Uniform #%d Type: %u Name: %s\n", i, type, uniformInstance->name ); + + GLint uniformLocation = glGetUniformLocation( program, uniformInstance->name ); + + uniformInstance->location = uniformLocation; + + uniformInstance->type = type; + + array_add( this->uniforms, uniformInstance ); + + } + + printf("uniforms count: %i\n", array_length( this->uniforms )); + + + } + +struct attribute * shader_getAttributeByName( shader * this, char * attributeName ) { + + int attributeCount = array_length( this->attributes ); + + + + for ( int i = 0; i < attributeCount; ++i ) + { + uniform * currentAttribute = array_get( this->attributes, i ); + + char * currentAttributeName = ( char * ) currentAttribute->name; + + + + if( char_operator_compare( currentAttributeName , attributeName) ) { + + return currentAttribute; + + } + + } + + } + +void shader_setUniform( shader * this, char * name, void * value ) { + + int uniformCount = array_length( this->uniforms ); + + + + for (int i = 0; i < uniformCount; ++i) + { + uniform * currentUniform = array_get( this->uniforms, i ); + + char * uniformName = (char *)currentUniform->name; + + + + if( char_operator_compare( uniformName , name) ) { + + + + switch( currentUniform->type ) { + + + case GL_FLOAT_VEC2: + + vector2 * vector2Value = ( vector2 * ) value; + + + + glUniform2f( currentUniform->location, vector2Value->x, vector2Value->y ); + + break; + + case GL_FLOAT_VEC3: + + vector3 * vector3Value = ( vector3 * ) value; + + + + glUniform3f( currentUniform->location, vector3Value->x, vector3Value->y, vector3Value->z ); + + break; + + } + + } + + + } + + + } + +shader shader_new() { + + shader instance; + + instance.__classIndex = 8; + + instance.uniforms = array_newPointer(); + + instance.attributes = array_newPointer(); + + return instance; + +} + +shader * shader_newPointer() { + + struct shader * pointer = malloc( sizeof ( struct shader ) ); + + pointer->__classIndex = 8; + + pointer->uniforms = array_newPointer(); + + pointer->attributes = array_newPointer(); + + return pointer; + +} + +uniform uniform_new() { + + uniform instance; + + instance.__classIndex = 9; + + return instance; + +} + +uniform * uniform_newPointer() { + + struct uniform * pointer = malloc( sizeof ( struct uniform ) ); + + pointer->__classIndex = 9; + + return pointer; + +} + +attribute attribute_new() { + + attribute instance; + + instance.__classIndex = 10; + + return instance; + +} + +attribute * attribute_newPointer() { + + struct attribute * pointer = malloc( sizeof ( struct attribute ) ); + + pointer->__classIndex = 10; + + return pointer; + +} + diff --git a/application/target/shader.h b/application/target/shader.h new file mode 100644 index 0000000..e0345fc --- /dev/null +++ b/application/target/shader.h @@ -0,0 +1,92 @@ +#ifndef _shader + +#define _shader + + +// Macros + +#define GL_GLEXT_PROTOTYPES + + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "char.h" + +#include "array.h" + +#include "fileSystem.h" + +#include + +#include + +#include + +#include + + +typedef struct shader{ + + unsigned short __classIndex; + + array * uniforms; + + array * attributes; + + +} shader; + +void shader_checkShaderForErrors( shader * this, GLuint shader ); + +void shader_createFromFile( shader * this, char * vertexShaderPath, char * fragmentShaderPath ); + +struct attribute * shader_getAttributeByName( shader * this, char * attributeName ); + +void shader_setUniform( shader * this, char * name, void * value ); + +typedef struct uniform{ + + unsigned short __classIndex; + + char name[64]; + + GLint location; + + GLenum type; + + +} uniform; + +typedef struct attribute{ + + unsigned short __classIndex; + + GLchar name[64]; + + GLint location; + + GLenum type; + + +} attribute; + +shader shader_new( ); + +shader * shader_newPointer( ); + +uniform uniform_new( ); + +uniform * uniform_newPointer( ); + +attribute attribute_new( ); + +attribute * attribute_newPointer( ); + +#endif diff --git a/application/target/sqlite.c b/application/target/sqlite.c new file mode 100644 index 0000000..be3b15c --- /dev/null +++ b/application/target/sqlite.c @@ -0,0 +1,840 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void sqlite_constructor( sqlite * this, char * filePath ) { + this->value = "good"; + + sqlite_connect( this, filePath ); + + } + + +void sqlite_connect( sqlite * this, char * filePath ) { + + printf("\n\ntrying to connect.. %s\n\n", filePath); + + int rc = sqlite3_open( filePath, & this->db ); + + if ( rc != SQLITE_OK ) { + + printf( "Cannot open database: %s\n", sqlite3_errmsg( this->db ) ); + + sqlite3_close( this->db ); + + consoleManager_error( console, ( char * ) sqlite3_errmsg( this->db ) ); + + return; + + } + + rc = sqlite3_prepare_v2( this->db, "SELECT SQLITE_VERSION()", -1, & this->res, 0 ); + + if (rc != SQLITE_OK) { + + consoleManager_error( console, ( char * ) sqlite3_errmsg( this->db ) ); + + sqlite3_close( this->db ); + + return; + + } + + rc = sqlite3_step(this->res); + + + + + + + + + + + + } + +void sqlite_free( sqlite * this ) { + + sqlite3_finalize( this->res ); + + sqlite3_close( this->db ); + + } + +void sqlite_selectModel( sqlite * this, char * className ) { + + this->selectedModel = className; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +void sqlite_createTable( sqlite * this ) { + + char * errorMessage = 0; + + char *sql = "DROP TABLE IF EXISTS user;" + "CREATE TABLE user( id INT, username TEXT, userlevel INT, hash TEXT );"; + + int rc = sqlite3_exec(this->db, sql, 0, 0, &errorMessage); + + if ( rc != SQLITE_OK ) { + + printf( "SQL error: %s\n", errorMessage ); + + sqlite3_free( errorMessage ); + + sqlite3_close(this->db); + + + } + + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void sqlite_addRows( sqlite * this, array * insertArray ) { + + array * copy = insertArray; + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + text * query = text_newPointer( "" ); + + text_append( query, "INSERT INTO " ); + + text_append( query, this->selectedModel ); + + + sqlite3_stmt * result; + + + char * * propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + + + text_append( query, " ( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + + continue; + + } + + if( propertyIndex > 0 ) { + + text_append( query, ", " ); + + } + + text_append( query, propertyName ); + + } + + text_append( query, " ) " ); + + text_append( query, " VALUES ( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + + continue; + + } + + if( propertyIndex > 0 ) { + + text_append( query, ", " ); + + } + + text_append( query, "?" ); + + } + + text_append( query, " ) " ); + + + + sqlite3_prepare_v2( this->db, query->value, -1, &result, 0 ); + + sqlite3_exec(this->db, this->selectedModel, NULL, NULL, 0); + + sqlite3_exec(this->db, "PRAGMA synchronous = OFF", NULL, NULL, 0); + + sqlite3_exec(this->db, "PRAGMA journal_mode = MEMORY", NULL, NULL, 0); + + + int insertItemCount = copy->total; + + char * voidArray = ( char * ) copy->items; + + + + for (int i = 0; i < insertItemCount; ++i) + { + char * pointer = array_get( copy, i ); + + sqlite_updateRow( this, result, propertyCount, propertyNames, propertyOffsets, datatypeIndices, pointer ); + + sqlite3_step( result ); + + sqlite3_reset( result ); + + } + + + + sqlite3_finalize( result ); + + + + } + + + +void sqlite_updateRow( sqlite * this, sqlite3_stmt * result, int propertyCount, char * * propertyNames, int * propertyOffsets, int * datatypeIndices, char * pointer ) { + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + int propertyOffset = propertyOffsets[propertyIndex]; + + int propertyDatatypeIndex = getPropertyDatatypeIndex( datatypeIndices, propertyIndex ); + + + + if( propertyDatatypeIndex == -5 ) { + + int value = *( int * )(pointer + propertyOffset); + + + + sqlite3_bind_int( result, propertyIndex + 1, value ); + + } else if( propertyDatatypeIndex == -3 ) { + + + + uintptr_t * value = ( uintptr_t * ) ( pointer + propertyOffset ); + + + + + + sqlite3_bind_text( result, propertyIndex + 1, (char *) *value, -1, SQLITE_TRANSIENT ); + + } + + } + + + + } + +void sqlite_update( sqlite * this, void * row ) { + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + char ** propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + int propertyIdOfIndex = -1; + + + for ( int i = 0; i < propertyCount; ++i ) + { + char * propertyName = propertyNames[i]; + + + + if( strcmp( propertyName, "id" ) == 0 ) { + + propertyIdOfIndex = i; + + break; + + } + } + + if( propertyIdOfIndex == -1 ) { + + printf("Class '%s' does not have an id field. "); + + } + + int idOffset = propertyOffsets[ propertyIdOfIndex ]; + + char * pointer = row; + + int id = *( pointer + idOffset ); + + text * query = text_newPointer( "" ); + + text_append( query, "UPDATE " ); + + text_append( query, this->selectedModel ); + + text_append( query, " SET " ); + + int activePropertyCount = 0; + + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[propertyIndex]; + + int datatypeIndex = datatypeIndices[propertyIndex]; + + + if( datatypeIndex > 0 ) { + + continue; + + } + + activePropertyCount++; + + if( propertyIndex > 0 ) { + + text_append( query, ", " ); + + } + + text_append( query, propertyName ); + + text_append( query, " = ? " ); + + } + + text_append( query, " where id = ? " ); + + sqlite3_stmt * result; + + sqlite3_prepare_v2( this->db, query->value, -1, &result, 0 ); + + sqlite_updateRow( this, result, propertyCount, propertyNames, propertyOffsets, datatypeIndices, pointer ); + + sqlite3_bind_int( result, activePropertyCount + 1, id ); + + + + sqlite3_step( result ); + + sqlite3_finalize( result ); + + + + } + +void sqlite_addRow( sqlite * this, void * row ) { + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + text * query = text_newPointer( "" ); + + text_append( query, "INSERT INTO " ); + + text_append( query, this->selectedModel ); + + + sqlite3_stmt * result; + + + char * * propertyNames = getPropertiesByClassIndex( classIndex ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + char * pointer = row; + + + text_append( query, " ( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + char * propertyName = propertyNames[ propertyIndex ]; + + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + + continue; + + } + + + if( propertyIndex > 0 ) { + + text_append( query, ", " ); + + } + + text_append( query, propertyName ); + + } + + text_append( query, " ) " ); + + text_append( query, " VALUES ( " ); + + for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) + { + + int datatype = datatypeIndices[ propertyIndex ]; + + if( datatype > 0 ) { + + + continue; + + } + + + if( propertyIndex > 0 ) { + + text_append( query, ", " ); + + } + + text_append( query, "?" ); + + } + + text_append( query, " ) " ); + + + + + + sqlite3_prepare_v2( this->db, query->value, -1, &result, 0 ); + + sqlite_updateRow( this, result, propertyCount, propertyNames, propertyOffsets, datatypeIndices, pointer ); + + sqlite3_step( result ); + + + + sqlite3_finalize( result ); + + + + } + +struct array * sqlite_fetchRows( sqlite * this, char * sql ) { + + sqlite3_stmt * result; + + int rc = sqlite3_prepare_v2( this->db, sql, -1, &result, 0 ); + + if ( rc != SQLITE_OK ) { + + printf("Failed to execute statement: %s\n", sqlite3_errmsg( this->db ) ); + + } + + + + + + + + + int rowIndex = 0; + + + + + int classIndex = getClassIndexByClassName( this->selectedModel ); + + + + + + int propertyIndex = getPropertyIndexByPropertyName( classIndex, "username" ); + + int propertyCount = getPropertyCountByClassIndex( classIndex ); + + char ** propertyNames = getPropertiesByClassIndex( classIndex ); + + int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex ); + + int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex ); + + + char * shortPointer = malloc( sizeof( char * ) * 100000 ); + + void * * voidArray = malloc( sizeof( void * ) * 100000 ); + + int structByteSize; + + getArrayByClassIndex( 1000, voidArray, &structByteSize, classIndex ); + + shortPointer = ( char * ) shortPointer; + + + while ( sqlite3_step( result ) != SQLITE_DONE ) { + + + + int pointerIndex = ( rowIndex * ( structByteSize ) ); + + + + char * pointer = shortPointer + pointerIndex; + + int columnCount = sqlite3_data_count( result ); + + + + for (int i = 0; i < columnCount; ++i) + { + + const char * columnName = sqlite3_column_name( result, i ); + + const int propertyIndex = getPropertyIndexByPropertyName( classIndex, (char *)columnName ); + + int propertyDatatypeIndex = getPropertyDatatypeIndex( datatypeIndices, propertyIndex ); + + int propertyOffset = getPropertyOffsetByPropertyIndex( propertyOffsets, propertyIndex ); + + + + + + + + + + if( propertyDatatypeIndex == -5 ) { + + const int columnValue = sqlite3_column_int( result, i ); + + + *( int * )( pointer + propertyOffset ) = columnValue; + + } else if( propertyDatatypeIndex == -3 ) { + + const char * columnValue = sqlite3_column_text( result, i ); + + char * columnValueCopy = malloc( strlen( columnValue ) ); + + strncpy( columnValueCopy, columnValue, strlen( columnValue ) ); + + + + + + + memcpy( pointer + propertyOffset, &columnValueCopy, 8 ); + + } + + + + } + + + voidArray[rowIndex] = pointer; + + + + rowIndex++; + + } + + struct array * rows = array_newPointer(); + + rows->items = voidArray; + + rows->total = rowIndex; + + return rows; + + } + +sqlite sqlite_new(char * filePath) { + + sqlite instance; + + instance.__classIndex = 27; + + sqlite_constructor( &instance, filePath); + + return instance; + +} + +sqlite * sqlite_newPointer(char * filePath) { + + struct sqlite * pointer = malloc( sizeof ( struct sqlite ) ); + + pointer->__classIndex = 27; + + sqlite_constructor( pointer , filePath); + + return pointer; + +} + diff --git a/application/target/sqlite.h b/application/target/sqlite.h new file mode 100644 index 0000000..74345aa --- /dev/null +++ b/application/target/sqlite.h @@ -0,0 +1,73 @@ +#ifndef _sqlite + +#define _sqlite + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "console.h" + +#include + +#include + +#include + +#include + +#include + +#include + +#include + + +typedef struct sqlite{ + + unsigned short __classIndex; + + sqlite3 * db; + + sqlite3_stmt * res; + + char * value; + + char * selectedModel; + + +} sqlite; + +void sqlite_constructor( sqlite * this, char * filePath ); + +void sqlite_connect( sqlite * this, char * filePath ); + +void sqlite_free( sqlite * this ); + +void sqlite_selectModel( sqlite * this, char * className ); + +void sqlite_createTable( sqlite * this ); + +void sqlite_addRows( sqlite * this, array * insertArray ); + +void sqlite_updateRow( sqlite * this, sqlite3_stmt * result, int propertyCount, char * * propertyNames, int * propertyOffsets, int * datatypeIndices, char * pointer ); + +void sqlite_update( sqlite * this, void * row ); + +void sqlite_addRow( sqlite * this, void * row ); + +struct array * sqlite_fetchRows( sqlite * this, char * sql ); + +sqlite sqlite_new( char * filePath ); + +sqlite * sqlite_newPointer( char * filePath ); + +#endif diff --git a/application/target/street.c b/application/target/street.c new file mode 100644 index 0000000..bb400a1 --- /dev/null +++ b/application/target/street.c @@ -0,0 +1,34 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + +void address_someMethod( address * this ) { + + + } + +address address_new() { + + address instance; + + instance.__classIndex = 19; + + return instance; + +} + +address * address_newPointer() { + + struct address * pointer = malloc( sizeof ( struct address ) ); + + pointer->__classIndex = 19; + + return pointer; + +} + diff --git a/application/target/street.h b/application/target/street.h new file mode 100644 index 0000000..48bef56 --- /dev/null +++ b/application/target/street.h @@ -0,0 +1,35 @@ +#ifndef _street + +#define _street + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + + +typedef struct address{ + + unsigned short __classIndex; + + char * street; + + int number; + + +} address; + +void address_someMethod( address * this ); + +address address_new( ); + +address * address_newPointer( ); + +#endif diff --git a/application/target/text.c b/application/target/text.c new file mode 100644 index 0000000..89e5305 --- /dev/null +++ b/application/target/text.c @@ -0,0 +1,209 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + + +int text_operator_compare( text * this, text * b ) { + + if( strcmp( this->value, b->value ) == 0 ) { + + return 1; + + } else { + + return 0; + + } + + } + +text * text_operator_add( text * this, char * b ) { + + text_append( this, b ); + + return this; + + } + +void text_constructor( text * this, char * value ) { + + this->length = strlen( value ); + + if( this->length > this->capacity ) { + + this->capacity = this->length * 2; + + } + + this->value = malloc( sizeof( char ) * this->capacity ); + + strcpy( this->value, value ); + } + +char text_get( text * this, int index ) { + + return this->value[ index ]; + + } + +void text_resize( text * this, int size ) { + + this->value = realloc( this->value, size ); + + this->capacity = size; + + } + +text * text_append( text * this, char * value ) { + + int originalLength = this->length; + + int newValueLength = strlen( value ); + + this->length += newValueLength; + + if( this->length > this->capacity ) { + + text_resize( this, this->length * 2 ); + + } + + memcpy( this->value + originalLength, value, newValueLength + 1 ); + + return this; + + } + +text * text_appendBinary( text * this, char * value, int size ) { + + int originalLength = this->length; + + int newValueLength = size; + + this->length += newValueLength; + + if( this->length > this->capacity ) { + + text_resize( this, this->length * 2 ); + + } + + memcpy( this->value + originalLength, value, newValueLength + 1 ); + + return this; + + } + + +text * text_appendObject( text * this, text * object ) { + + int originalLength = this->length; + + int newValueLength = object->length; + + this->length += newValueLength; + + if( this->length > this->capacity ) { + + text_resize( this, this->length * 2 ); + + } + + memcpy(this->value + originalLength, object->value, newValueLength + 1); + + return this; + + } + +text * text_concatenate( text * this, char * value ) { + + text * copy = text_newPointer( this->value ); + + strcat( copy->value, value ); + + return copy; + + } + +char * text_toNative( text * this ) { + + return this->value; + + } + +char * text_whiteSpace( text * this, int whiteSpaceCount ) { + + char * output = malloc( 400 ); + + for (int i = 0; i < whiteSpaceCount; ++i) + { + + strcat( output, " " ); + + } + + return output; + + } + +void text_free( text * this ) { + + free( this->value ); + + free( this ); + + } + +text text_new(char * value) { + + text instance; + + instance.__classIndex = 4; + + instance.usevalue = -1; + + instance.capacity = 500; + + text_constructor( &instance, value); + + return instance; + +} + +text * text_newPointer(char * value) { + + struct text * pointer = malloc( sizeof ( struct text ) ); + + pointer->__classIndex = 4; + + pointer->usevalue = -1; + + pointer->capacity = 500; + + text_constructor( pointer , value); + + return pointer; + +} + diff --git a/application/target/text.h b/application/target/text.h new file mode 100644 index 0000000..3d36351 --- /dev/null +++ b/application/target/text.h @@ -0,0 +1,71 @@ +#ifndef _text + +#define _text + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + + +typedef struct text{ + + unsigned short __classIndex; + + char * value; + + int usevalue; + + int length; + + int capacity; + + +} text; + +int text_operator_compare( text * this, text * b ); + +text * text_operator_add( text * this, char * b ); + +void text_constructor( text * this, char * value ); + +char text_get( text * this, int index ); + +void text_resize( text * this, int size ); + +text * text_append( text * this, char * value ); + +text * text_appendBinary( text * this, char * value, int size ); + +text * text_appendObject( text * this, text * object ); + +text * text_concatenate( text * this, char * value ); + +char * text_toNative( text * this ); + +char * text_whiteSpace( text * this, int whiteSpaceCount ); + +void text_free( text * this ); + +text text_new( char * value ); + +text * text_newPointer( char * value ); + +#endif diff --git a/application/target/toolset.c b/application/target/toolset.c new file mode 100644 index 0000000..7403c9a --- /dev/null +++ b/application/target/toolset.c @@ -0,0 +1,47 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + +void toolset_createHorisontalLine( toolset * this ) { + + struct winsize w; + + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + + for (int i = 0; i < w.ws_col; ++i) + { + + printf("-"); + + }; + + printf("\n"); + + } + +toolset toolset_new() { + + toolset instance; + + instance.__classIndex = 20; + + return instance; + +} + +toolset * toolset_newPointer() { + + struct toolset * pointer = malloc( sizeof ( struct toolset ) ); + + pointer->__classIndex = 20; + + return pointer; + +} + diff --git a/application/target/toolset.h b/application/target/toolset.h new file mode 100644 index 0000000..e3748ae --- /dev/null +++ b/application/target/toolset.h @@ -0,0 +1,37 @@ +#ifndef _toolset + +#define _toolset + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + + +typedef struct toolset{ + + unsigned short __classIndex; + + +} toolset; + +void toolset_createHorisontalLine( toolset * this ); + +toolset toolset_new( ); + +toolset * toolset_newPointer( ); + +#endif diff --git a/application/target/triangle.c b/application/target/triangle.c new file mode 100644 index 0000000..d7af204 --- /dev/null +++ b/application/target/triangle.c @@ -0,0 +1,49 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + +void triangle_add( triangle * this, triangle * a ) { + + + } + +triangle triangle_new() { + + triangle instance; + + instance.__classIndex = 28; + + instance.a = vector2_newPointer( 1, 2 ); + + instance.b = vector2_new( 3, 400 ); + + instance.c = vector2_new( 5, 6 ); + + return instance; + +} + +triangle * triangle_newPointer() { + + struct triangle * pointer = malloc( sizeof ( struct triangle ) ); + + pointer->__classIndex = 28; + + pointer->a = vector2_newPointer( 1, 2 ); + + pointer->b = vector2_new( 3, 400 ); + + pointer->c = vector2_new( 5, 6 ); + + return pointer; + +} + diff --git a/application/target/triangle.h b/application/target/triangle.h new file mode 100644 index 0000000..7091b82 --- /dev/null +++ b/application/target/triangle.h @@ -0,0 +1,39 @@ +#ifndef _triangle + +#define _triangle + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + + +typedef struct triangle{ + + unsigned short __classIndex; + + vector2 * a; + + vector2 b; + + vector2 c; + + +} triangle; + +void triangle_add( triangle * this, triangle * a ); + +triangle triangle_new( ); + +triangle * triangle_newPointer( ); + +#endif diff --git a/application/target/unsignedIntegerArray.c b/application/target/unsignedIntegerArray.c new file mode 100644 index 0000000..8987998 --- /dev/null +++ b/application/target/unsignedIntegerArray.c @@ -0,0 +1,197 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + +int unsignedIntegerArray_length( unsignedIntegerArray * this ) { + + return this->total; + + } + + +unsigned float unsignedIntegerArray_get( unsignedIntegerArray * this, int index ) { + + if ( index >= 0 && index < this->total ){ + + return this->items[index]; + + } + + return NULL; + + } + + +void unsignedIntegerArray_set( unsignedIntegerArray * this, int index, unsigned float item ) { + + if ( index >= 0 && index < this->total ){ + + this->items[ index ] = item; + + } + + } + + +void unsignedIntegerArray_resize( unsignedIntegerArray * this, int capacity ) { + + int * items = realloc( this->items, sizeof( int ) * capacity ); + + + this->items = items; + + this->capacity = capacity; + + } + + +void unsignedIntegerArray_addVector2( unsignedIntegerArray * this, struct vector2 * item ) { + + unsignedIntegerArray_add( this, item->x ); + + unsignedIntegerArray_add( this, item->y ); + + } + +void unsignedIntegerArray_addVector3( unsignedIntegerArray * this, struct vector3 * item ) { + + unsignedIntegerArray_add( this, item->x ); + + unsignedIntegerArray_add( this, item->y ); + + unsignedIntegerArray_add( this, item->z ); + + } + +void unsignedIntegerArray_add( unsignedIntegerArray * this, unsigned int item ) { + + if ( this->capacity == this->total ){ + + unsignedIntegerArray_resize( this, this->capacity * 2 ); + + } + + this->items[ this->total++ ] = item; + + } + + +void unsignedIntegerArray_delete( unsignedIntegerArray * this, int index ) { + if ( index < 0 || index >= this->total ){ + + return; + + } + + this->items[index] = 0.0; + + for ( int i = index; i < this->total - 1; i++ ) { + + this->items[i] = this->items[i + 1]; + + this->items[i + 1] = 0.0; + + } + + this->total--; + + if ( this->total > 0 && this->total == this->capacity / 4 ){ + + unsignedIntegerArray_resize( this, this->capacity / 2 ); + + } + + } + + +int unsignedIntegerArray_array_push( unsignedIntegerArray * this, unsigned int item ) { + + unsignedIntegerArray_add( this, item ); + + return this->total; + + } + +void unsignedIntegerArray_unshift( unsignedIntegerArray * this, int item ) { + + int length = this->total; + + this->total++; + + if ( this->capacity == this->total ){ + + unsignedIntegerArray_resize( this, this->capacity * 2 ); + + } + + for ( int i = length - 1; i >= 0; --i ) { + + this->items[ i + 1 ] = this->items[ i ]; + + } + + this->items[ 0 ] = item; + + } + +unsigned int unsignedIntegerArray_pop( unsignedIntegerArray * this ) { + + int length = this->total; + + int lastIndex = length - 1; + + int lastItem = unsignedIntegerArray_get( this, lastIndex ); + + unsignedIntegerArray_delete( this, lastIndex ); + + return lastItem; + + } + +unsignedIntegerArray unsignedIntegerArray_new() { + + unsignedIntegerArray instance; + + instance.__classIndex = 1; + + instance.capacity = 10; + + instance.total = 0; + + instance.items = malloc( 10000000 ); + + return instance; + +} + +unsignedIntegerArray * unsignedIntegerArray_newPointer() { + + struct unsignedIntegerArray * pointer = malloc( sizeof ( struct unsignedIntegerArray ) ); + + pointer->__classIndex = 1; + + pointer->capacity = 10; + + pointer->total = 0; + + pointer->items = malloc( 10000000 ); + + return pointer; + +} + diff --git a/application/target/unsignedIntegerArray.h b/application/target/unsignedIntegerArray.h new file mode 100644 index 0000000..8dacb29 --- /dev/null +++ b/application/target/unsignedIntegerArray.h @@ -0,0 +1,67 @@ +#ifndef _unsignedIntegerArray + +#define _unsignedIntegerArray + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include + +#include + + +typedef struct unsignedIntegerArray{ + + unsigned short __classIndex; + + int capacity; + + int total; + + unsigned int * items; + + +} unsignedIntegerArray; + +int unsignedIntegerArray_length( unsignedIntegerArray * this ); + +unsigned float unsignedIntegerArray_get( unsignedIntegerArray * this, int index ); + +void unsignedIntegerArray_set( unsignedIntegerArray * this, int index, unsigned float item ); + +void unsignedIntegerArray_resize( unsignedIntegerArray * this, int capacity ); + +void unsignedIntegerArray_addVector2( unsignedIntegerArray * this, struct vector2 * item ); + +void unsignedIntegerArray_addVector3( unsignedIntegerArray * this, struct vector3 * item ); + +void unsignedIntegerArray_add( unsignedIntegerArray * this, unsigned int item ); + +void unsignedIntegerArray_delete( unsignedIntegerArray * this, int index ); + +int unsignedIntegerArray_array_push( unsignedIntegerArray * this, unsigned int item ); + +void unsignedIntegerArray_unshift( unsignedIntegerArray * this, int item ); + +unsigned int unsignedIntegerArray_pop( unsignedIntegerArray * this ); + +unsignedIntegerArray unsignedIntegerArray_new( ); + +unsignedIntegerArray * unsignedIntegerArray_newPointer( ); + +#endif diff --git a/application/target/user.c b/application/target/user.c new file mode 100644 index 0000000..0bd3fba --- /dev/null +++ b/application/target/user.c @@ -0,0 +1,51 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + +void user_constructor( user * this ) { + + + + + + } + +user user_new() { + + user instance; + + instance.__classIndex = 29; + + instance.addresses = array_newPointer(); + + user_constructor( &instance); + + return instance; + +} + +user * user_newPointer() { + + struct user * pointer = malloc( sizeof ( struct user ) ); + + pointer->__classIndex = 29; + + pointer->addresses = array_newPointer(); + + user_constructor( pointer ); + + return pointer; + +} + diff --git a/application/target/user.h b/application/target/user.h new file mode 100644 index 0000000..4b9a44b --- /dev/null +++ b/application/target/user.h @@ -0,0 +1,43 @@ +#ifndef _user + +#define _user + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + + +typedef struct user{ + + unsigned short __classIndex; + + char * username; + + int id; + + int userlevel; + + char * hash; + + struct array * addresses; + + +} user; + +void user_constructor( user * this ); + +user user_new( ); + +user * user_newPointer( ); + +#endif diff --git a/application/target/vector2.c b/application/target/vector2.c new file mode 100644 index 0000000..c034494 --- /dev/null +++ b/application/target/vector2.c @@ -0,0 +1,106 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + + + + + + + + + + + + +void vector2_constructor( vector2 * this, float x, float y ) { + + + + this->x = x; + + this->y = y; + + + + + + + } + + + +vector2 * vector2_operator_plus( vector2 * this, vector2 * b ) { + + vector2_add( this, b ); + + return this; + + } + +vector2 * vector2_operator_add( vector2 * this, struct vector2 * b ) { + + + + + + + return b; + } + +void vector2_add( vector2 * this, vector2 * a ) { + + this->x += a->x; + + this->y += a->y; + + } + +void vector2_subtract( vector2 * this, vector2 * a ) { + + this->x -= a->x; + + this->y -= a->y; + + } + +int vector2_length( vector2 * this ) { + + return this->x + this->y; + + } + +vector2 vector2_new(float x, float y) { + + vector2 instance; + + instance.__classIndex = 2; + + vector2_constructor( &instance, x, y); + + return instance; + +} + +vector2 * vector2_newPointer(float x, float y) { + + struct vector2 * pointer = malloc( sizeof ( struct vector2 ) ); + + pointer->__classIndex = 2; + + vector2_constructor( pointer , x, y); + + return pointer; + +} + diff --git a/application/target/vector2.h b/application/target/vector2.h new file mode 100644 index 0000000..76b6280 --- /dev/null +++ b/application/target/vector2.h @@ -0,0 +1,57 @@ +#ifndef _vector2 + +#define _vector2 + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include + +#include + +#include + +#include "time.h" + +#include + +#include "stdio.h" + + +typedef struct vector2{ + + unsigned short __classIndex; + + float x; + + float y; + + +} vector2; + +void vector2_constructor( vector2 * this, float x, float y ); + +vector2 * vector2_operator_plus( vector2 * this, vector2 * b ); + +vector2 * vector2_operator_add( vector2 * this, struct vector2 * b ); + +void vector2_add( vector2 * this, vector2 * a ); + +void vector2_subtract( vector2 * this, vector2 * a ); + +int vector2_length( vector2 * this ); + +vector2 vector2_new( float x, float y ); + +vector2 * vector2_newPointer( float x, float y ); + +#endif diff --git a/application/target/vector3.c b/application/target/vector3.c new file mode 100644 index 0000000..9063804 --- /dev/null +++ b/application/target/vector3.c @@ -0,0 +1,76 @@ +/* + * This file is automaticaly generated, Please dont edit this file! + */ +#include + + + + + + + + + + +void vector3_constructor( vector3 * this, float x, float y, float z ) { + + this->x = x; + + this->y = y; + + this->z = z; + + } + +vector3 * vector3_operator_plus( vector3 * this, vector3 * b ) { + + vector3_add( this, b ); + + return this; + + } + +vector3 * vector3_operator_add( vector3 * this, vector3 * b ) { + + vector3_add( this, b ); + + return this; + + } + + + +void vector3_add( vector3 * this, vector3 * b ) { + + this->x += b->x; + + this->y += b->y; + + this->z += b->z; + + } + +vector3 vector3_new(float x, float y, float z) { + + vector3 instance; + + instance.__classIndex = 3; + + vector3_constructor( &instance, x, y, z); + + return instance; + +} + +vector3 * vector3_newPointer(float x, float y, float z) { + + struct vector3 * pointer = malloc( sizeof ( struct vector3 ) ); + + pointer->__classIndex = 3; + + vector3_constructor( pointer , x, y, z); + + return pointer; + +} + diff --git a/application/target/vector3.h b/application/target/vector3.h new file mode 100644 index 0000000..d50915b --- /dev/null +++ b/application/target/vector3.h @@ -0,0 +1,45 @@ +#ifndef _vector3 + +#define _vector3 + + +// Macros + + + +#include "stdlib.h" + +extern char * __ClassNames[]; + + +// Includes + +#include "application.h" + + +typedef struct vector3{ + + unsigned short __classIndex; + + float x; + + float y; + + float z; + + +} vector3; + +void vector3_constructor( vector3 * this, float x, float y, float z ); + +vector3 * vector3_operator_plus( vector3 * this, vector3 * b ); + +vector3 * vector3_operator_add( vector3 * this, vector3 * b ); + +void vector3_add( vector3 * this, vector3 * b ); + +vector3 vector3_new( float x, float y, float z ); + +vector3 * vector3_newPointer( float x, float y, float z ); + +#endif diff --git a/binaries/1.png b/binaries/1.png new file mode 100644 index 0000000000000000000000000000000000000000..12a69ebeed28fc34fd9a3c36c3080c94da0fb921 GIT binary patch literal 2601 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 nHD2ZUh@xbEUIs>OTfAel`f$6tuD2o0I-uCu@js literal 0 HcmV?d00001 diff --git a/binaries/10.png b/binaries/10.png new file mode 100755 index 0000000000000000000000000000000000000000..36a2b4052139f45581c92b1f2d33f5a72fad3c2f GIT binary patch literal 340426 zcmeFY_fwPa^F16yL4^<$5$PZb3J4;EUPVD)NR!?>NDVasLKOw2BhtG_hX6r(mtI2; zq4ySg3n2s^e9wIUhv$dSOlFeb?)&Us*X}uIH{aD%6oGdc?g9V+;QM!PJ^}zYuYcYI z+$OvJ@@M7=0szVU zu{R$?ho?BrXzh)Uy%N@aSoPEYW&F}m`ww|ey>`-P(4UF9<;!0vO+Sw-vys&i8sYOp zcLx$5(KC#6x{rbz&^^*xkVyirq|y&Nz1~n)S~&5eYPWHHo9NqYM$Fwy)$xEnyeUWh zf1m%0!2dKUzi?5yg+bO5j0fH>JZVEj?fKoaiTop+RC%Ii0jfMza|2c4)Pg{jXKJyaO1xS&sPbHpzaDb?Gu!RY3j$pu zFMWDleJ@>o$49T47V^KK?{k|!zl7)^_>B-SUUY^50>_JvSoOXf1M=#t?i|>O z3{?n1S5Q<-)$Nx7VGj=Hta^ASr7%vV9GI@u{gAT+JW>NopIG{`j zkkR;Ht5grMr;j*VJztqq2oesdX7#1{gVSJpk}}PfzSTr;z)h@QgQ_k|5H`=sQ!x^z zqCo_Qwx$q^ic=e?#A-FmgLPUP<2d;Mnw4M+(F$~M-cpA^lckS&tr_t{WxaUxEC;!F znv~mrh>Sz;pX8cRhx-dZ$!~TQ6K8lD+q3dSj~|AxELZT?&)@l%SCJ>_grQlK{@nvs zUBsRt;`*#f5ZR_EzQO^rmi(w}c0RR^X@ z?9}89?~$D*k>09`>{CQ@Y5G&s2!_a)c4jF@pfK#HgT3%=I8{nr5M@Ga#i@HKL2~2l zaR$VdZDhXuhy^ZaP(S1B(7*%RnY1}2R`SoT*VWi9yLOpPri)5@@ILc@Xu|9rA&)vh zte*GE^Sfe*YX7=-1K+{SPJKqzg9U#7b)KtR3%D0(iu_u!T)ATT28QFY=yghY5aPS_ z`;xvUl1v8Kyz-Bv;xlgJ7xIj=b8}tN9gYkyZAn+jbEjF-HJkcfDKWQ7azv%3MFoA) zK7V#hea;J4Ot6tlVR#Vp4JN_;|M+GvpD=y1IU8|JnRHnT_{Df*eBMKq%fAFIZXNxW zDO$|N*Pn)qTOo3_ub-q#zj=^q!?>?%iMr!^5j~?g)UtMVv2FyeT3jS9y=)SLGtouh zq;UU14p;XshGtdkxBZ^~yJg0)x@4ECMxoe6nF$;#9~#8paZ;^Il0okrWe0GIvUf19 zS2h+&DOS033P{A;0E~k4Qous_P7D%Nk#--37ZkVG5XwYncoEH%1}4Pi9R{>{yLQxh zp#15wbDaEvPgN~Kxlue?{vxnk&b&LmM^x>j;m@kaGD+zUsANHLX{dbKGDl8`K7?7d zEn3`+OK73cr|=?kdx5fLP&`ye19i`-1_^6&pPQ!{4W+QZD$P)zzX*^_Jmx9Upb`Ek zU4rjl1Yxj4MHl5-0@hG)hM`K)e zO-L~1Bt4NdG)AmzTo>F)?vfq;1ElR0AkaPql?rLa5AGHQc zK9yk>-tsn8vp|+v$6Q0zrqUeXs{NF2-bOnszwtF#uDza*FOj)$Af|MYpy{G;iSqXodMTM{q zk?F9dcdN?n@(eZ-pqGY(VNW@7MQ;9Q(rhaEjS>dY46wbEdCzqosR35;W6^|Jn_Jgd zTP*@}US3}2$ok<9kFxXCB!B^SYu1ba@FO+7Ayc(g4P`E`G+|{+T`T1WjFZFcZRc!n zzxhE4 zhmI2pm7ByLkei7qdX9iw zvH!gxHO?u^H(oX>1vvtn2I*Vn3qNm`*DGSZnTL59bo$7F>NJEfOV%9Li1iMd?+GXn zeeD*2?Al6)#lzX6x-)N~Evt&!C~Fg>I6~s;SVn-8G@X)5bY&7#<^(wOfDKcu_1$n-(u n`o}QIVc+VdtVyVG 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