├── .gitignore ├── .gitmodules ├── CocoaEditor ├── GameViewport.cpp ├── assets │ ├── cocoaLogo.png │ ├── default.ini │ ├── defaultCodeFiles │ │ ├── DefaultScript.cpp │ │ └── DefaultScript.h │ ├── fonts │ │ ├── FRABK.TTF │ │ ├── LICENSE-fontawesome.txt │ │ ├── OpenSans-Regular.ttf │ │ ├── UbuntuMono-Regular.ttf │ │ ├── fontawesome-webfont.ttf │ │ ├── fontawesome-webfont2.ttf │ │ ├── fontawesome-webfont3.ttf │ │ ├── openSans │ │ │ ├── OpenSans-Bold.ttf │ │ │ ├── OpenSans-BoldItalic.ttf │ │ │ ├── OpenSans-ExtraBold.ttf │ │ │ ├── OpenSans-ExtraBoldItalic.ttf │ │ │ ├── OpenSans-Italic.ttf │ │ │ ├── OpenSans-Light.ttf │ │ │ ├── OpenSans-LightItalic.ttf │ │ │ ├── OpenSans-Regular.ttf │ │ │ ├── OpenSans-SemiBold.ttf │ │ │ └── OpenSans-SemiBoldItalic.ttf │ │ └── segoeui.ttf │ ├── images │ │ ├── decorationsAndBlocks.png │ │ ├── gizmos.png │ │ ├── icon.png │ │ └── raw.svg │ ├── jadeLogo.png │ ├── shaders │ │ ├── FontRenderer.glsl │ │ ├── Picking.glsl │ │ ├── SpriteRenderer.glsl │ │ ├── debugLine2D.glsl │ │ └── default.glsl │ ├── styles │ │ ├── Default.json │ │ ├── dark.json │ │ ├── darkv2.json │ │ ├── noctis-viola.json │ │ ├── oceanic.json │ │ └── uranium.json │ └── tmp.jade ├── cpp │ ├── core │ │ ├── CocoaEditorApplication.cpp │ │ ├── ImGuiLayer.cpp │ │ ├── LevelEditorSceneInitializer.cpp │ │ └── LevelEditorSystem.cpp │ ├── editorWindows │ │ ├── AssetWindow.cpp │ │ ├── GameEditorViewport.cpp │ │ ├── GameViewport.cpp │ │ ├── InspectorWindow.cpp │ │ ├── MenuBar.cpp │ │ ├── ProjectWizard.cpp │ │ └── SceneHierarchyWindow.cpp │ ├── gui │ │ └── ImGuiExtended.cpp │ ├── nativeScripting │ │ ├── CodeGenerators.cpp │ │ ├── CppBuild.cpp │ │ ├── ScriptParser.cpp │ │ └── SourceFileWatcher.cpp │ ├── renderer │ │ └── Gizmos.cpp │ └── util │ │ └── Settings.cpp ├── imgui.ini ├── include │ ├── core │ │ ├── CocoaEditorApplication.h │ │ ├── ImGuiLayer.h │ │ ├── LevelEditorSceneInitializer.h │ │ └── LevelEditorSystem.h │ ├── editorWindows │ │ ├── AssetWindow.h │ │ ├── GameEditorViewport.h │ │ ├── GameViewport.h │ │ ├── InspectorWindow.h │ │ ├── MenuBar.h │ │ ├── ProjectWizard.h │ │ └── SceneHierarchyWindow.h │ ├── gui │ │ ├── FontAwesome.h │ │ ├── ImGuiExtended.h │ │ └── ImGuiHeader.h │ ├── nativeScripting │ │ ├── CodeGenerators.h │ │ ├── CppBuild.h │ │ ├── ScriptParser.h │ │ └── SourceFileWatcher.h │ ├── renderer │ │ └── Gizmos.h │ └── util │ │ └── Settings.h └── premake5.lua ├── CocoaEngine ├── Cocoa.h ├── cpp │ └── cocoa │ │ ├── commands │ │ └── CommandHistory.cpp │ │ ├── components │ │ ├── Spritesheet.cpp │ │ ├── Tag.cpp │ │ └── Transform.cpp │ │ ├── core │ │ ├── Application.cpp │ │ ├── AssetManager.cpp │ │ ├── CWindow.cpp │ │ ├── ECS.cpp │ │ ├── Entity.cpp │ │ └── StbTruetypeImpl.cpp │ │ ├── events │ │ ├── Input.cpp │ │ ├── KeyEvent.cpp │ │ ├── MouseEvent.cpp │ │ └── WindowEvent.cpp │ │ ├── file │ │ ├── FileSystemWatcher.cpp │ │ ├── Win32File.cpp │ │ └── Win32FileDialog.cpp │ │ ├── physics2d │ │ ├── ContactListener.cpp │ │ └── Physics2D.cpp │ │ ├── renderer │ │ ├── Camera.cpp │ │ ├── DebugDraw.cpp │ │ ├── Fonts │ │ │ ├── Font.cpp │ │ │ └── FontUtil.cpp │ │ ├── Framebuffer.cpp │ │ ├── Line2D.cpp │ │ ├── RenderBatch.cpp │ │ ├── Shader.cpp │ │ └── Texture.cpp │ │ ├── scenes │ │ └── Scene.cpp │ │ ├── systems │ │ ├── RenderSystem.cpp │ │ ├── ScriptSystem.cpp │ │ └── TransformSystem.cpp │ │ └── util │ │ ├── CMath.cpp │ │ ├── JsonExtended.cpp │ │ └── Settings.cpp ├── include │ ├── cocoa │ │ ├── commands │ │ │ ├── ChangeEnumCommand.h │ │ │ ├── ChangeFloatCommand.h │ │ │ ├── ChangeInt2Command.h │ │ │ ├── ChangeIntCommand.h │ │ │ ├── ChangeUint8Command.h │ │ │ ├── ChangeVec2Command.h │ │ │ ├── ChangeVec3Command.h │ │ │ ├── ChangeVec4Command.h │ │ │ ├── CommandHistory.h │ │ │ └── ICommand.h │ │ ├── components │ │ │ ├── FontRenderer.h │ │ │ ├── NoSerialize.h │ │ │ ├── Script.h │ │ │ ├── Sprite.h │ │ │ ├── SpriteRenderer.h │ │ │ ├── Spritesheet.h │ │ │ ├── Tag.h │ │ │ ├── Transform.h │ │ │ └── TransformStruct.h │ │ ├── core │ │ │ ├── Application.h │ │ │ ├── AssetManager.h │ │ │ ├── Audio.h │ │ │ ├── CWindow.h │ │ │ ├── Core.h │ │ │ ├── Entity.h │ │ │ ├── EntityStruct.h │ │ │ ├── EntryPoint.h │ │ │ └── Handle.h │ │ ├── events │ │ │ ├── Event.h │ │ │ ├── Input.h │ │ │ ├── KeyEvent.h │ │ │ ├── MouseEvent.h │ │ │ └── WindowEvent.h │ │ ├── file │ │ │ ├── File.h │ │ │ ├── FileDialog.h │ │ │ ├── FileSystemWatcher.h │ │ │ └── OutputArchive.h │ │ ├── physics2d │ │ │ ├── ContactListener.h │ │ │ ├── Physics2D.h │ │ │ └── PhysicsComponents.h │ │ ├── renderer │ │ │ ├── Camera.h │ │ │ ├── CameraStruct.h │ │ │ ├── DebugDraw.h │ │ │ ├── DebugShape.h │ │ │ ├── DebugSprite.h │ │ │ ├── Fonts │ │ │ │ ├── DataStructures.h │ │ │ │ ├── Font.h │ │ │ │ └── FontUtil.h │ │ │ ├── Framebuffer.h │ │ │ ├── Line2D.h │ │ │ ├── RenderBatch.h │ │ │ ├── Shader.h │ │ │ └── Texture.h │ │ ├── scenes │ │ │ ├── Scene.h │ │ │ ├── SceneData.h │ │ │ └── SceneInitializer.h │ │ ├── systems │ │ │ ├── RenderSystem.h │ │ │ ├── ScriptSystem.h │ │ │ └── TransformSystem.h │ │ └── util │ │ │ ├── CMath.h │ │ │ ├── JsonExtended.h │ │ │ └── Settings.h │ ├── externalLibs.h │ └── platform │ │ └── windows │ │ └── winMain.h ├── premake5.lua └── vendor │ ├── glad │ ├── include │ │ ├── glad │ │ │ └── glad.h │ │ └── khrplatform.h │ ├── premake5.lua │ └── src │ │ └── glad.c │ └── stb │ ├── stb_image.h │ ├── stb_image_write.h │ └── stb_truetype.h ├── Doxyfile ├── LICENSE ├── README.md ├── build.bat ├── docs ├── README.cpp ├── footer.html └── header.html ├── img └── buildFreetype.png ├── premake5.lua └── vendor └── premake └── premake5.exe /.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | .vscode/* 3 | .vs/* 4 | bin/* 5 | bin-int/* 6 | 7 | **/.vs/* 8 | **/bin/* 9 | **/bin-int/* 10 | **/obj/* 11 | *.sln 12 | *.vcxproj 13 | *.vcxproj.filters 14 | *.vcxproj.user 15 | 16 | CocoaEditor/vendor/libclang/** 17 | 18 | mockups/* -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "CocoaEngine/vendor/GLFW"] 2 | path = CocoaEngine/vendor/GLFW 3 | url = https://github.com/ambrosiogabe/glfw 4 | [submodule "CocoaEngine/vendor/box2DVendor"] 5 | path = CocoaEngine/vendor/box2DVendor 6 | url = https://github.com/ambrosiogabe/box2d 7 | [submodule "CocoaEngine/vendor/nlohmann-json"] 8 | path = CocoaEngine/vendor/nlohmann-json 9 | url = https://github.com/ambrosiogabe/json 10 | [submodule "CocoaEngine/vendor/enttVendor"] 11 | path = CocoaEngine/vendor/enttVendor 12 | url = https://github.com/skypjack/entt 13 | [submodule "CocoaEngine/vendor/glmVendor"] 14 | path = CocoaEngine/vendor/glmVendor 15 | url = https://github.com/g-truc/glm 16 | [submodule "CocoaEngine/vendor/imguiVendor"] 17 | path = CocoaEngine/vendor/imguiVendor 18 | url = https://github.com/ambrosiogabe/imgui 19 | [submodule "CocoaEngine/vendor/freetypeVendor"] 20 | path = CocoaEngine/vendor/freetypeVendor 21 | url = https://github.com/ambrosiogabe/FreetypeFork 22 | [submodule "CocoaEngine/vendor/CppUtils"] 23 | path = CocoaEngine/vendor/CppUtils 24 | url = https://github.com/ambrosiogabe/CppUtils 25 | -------------------------------------------------------------------------------- /CocoaEditor/GameViewport.cpp: -------------------------------------------------------------------------------- 1 | #include "editorWindows/GameViewport.h" -------------------------------------------------------------------------------- /CocoaEditor/assets/cocoaLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/cocoaLogo.png -------------------------------------------------------------------------------- /CocoaEditor/assets/default.ini: -------------------------------------------------------------------------------- 1 | [Window][DockSpace Demo] 2 | Pos=0,0 3 | Size=3840,2035 4 | Collapsed=0 5 | 6 | [Window][Debug##Default] 7 | Pos=60,60 8 | Size=400,400 9 | Collapsed=0 10 | 11 | [Window][Game Viewport] 12 | Pos=1933,40 13 | Size=1180,1448 14 | Collapsed=0 15 | DockId=0x0000000A,0 16 | 17 | [Window][Assets] 18 | Pos=509,1490 19 | Size=2604,545 20 | Collapsed=0 21 | DockId=0x00000007,0 22 | 23 | [Window][ Scene] 24 | Pos=0,40 25 | Size=507,1995 26 | Collapsed=0 27 | DockId=0x00000003,0 28 | 29 | [Window][ Inspector] 30 | Pos=1445,40 31 | Size=475,1006 32 | Collapsed=0 33 | DockId=0x00000005,0 34 | 35 | [Window][Create or Open Project] 36 | Pos=313,62 37 | Size=1920,1080 38 | Collapsed=0 39 | 40 | [Window][Create New Project] 41 | Pos=315,208 42 | Size=1083,522 43 | Collapsed=0 44 | 45 | [Window][Inspector] 46 | Pos=3115,40 47 | Size=725,1995 48 | Collapsed=0 49 | DockId=0x00000002,0 50 | 51 | [Window][Gizmo debug] 52 | Pos=299,57 53 | Size=308,484 54 | Collapsed=0 55 | 56 | [Window][Settings] 57 | Pos=986,400 58 | Size=900,600 59 | Collapsed=0 60 | 61 | [Window][Dear ImGui Demo] 62 | ViewportPos=639,463 63 | ViewportId=0xE927CF2F 64 | Size=1308,1025 65 | Collapsed=0 66 | 67 | [Window][Styles] 68 | ViewportPos=392,544 69 | ViewportId=0xB1F6FFC3 70 | Size=1172,1218 71 | Collapsed=0 72 | 73 | [Window][Dear ImGui Metrics] 74 | Pos=1105,187 75 | Size=604,496 76 | Collapsed=0 77 | 78 | [Window][Game Editor Viewport] 79 | Pos=509,40 80 | Size=1422,1448 81 | Collapsed=0 82 | DockId=0x00000009,0 83 | 84 | [Docking][Data] 85 | DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=0,85 Size=3840,1995 Split=X 86 | DockNode ID=0x00000003 Parent=0x3BC79352 SizeRef=507,1040 Selected=0xA259292F 87 | DockNode ID=0x00000008 Parent=0x3BC79352 SizeRef=3331,1040 Split=X 88 | DockNode ID=0x00000001 Parent=0x00000008 SizeRef=2604,1995 Split=Y 89 | DockNode ID=0x00000004 Parent=0x00000001 SizeRef=3840,754 Split=Y 90 | DockNode ID=0x00000005 Parent=0x00000004 SizeRef=475,1048 Selected=0x57F8A5EA 91 | DockNode ID=0x00000006 Parent=0x00000004 SizeRef=475,945 Split=X Selected=0x6E2C89B8 92 | DockNode ID=0x00000009 Parent=0x00000006 SizeRef=1422,754 CentralNode=1 Selected=0x6E2C89B8 93 | DockNode ID=0x0000000A Parent=0x00000006 SizeRef=1180,754 Selected=0xAE7BB42F 94 | DockNode ID=0x00000007 Parent=0x00000001 SizeRef=3840,284 Selected=0x7E7D78B8 95 | DockNode ID=0x00000002 Parent=0x00000008 SizeRef=725,1995 Selected=0x42A639A8 96 | 97 | -------------------------------------------------------------------------------- /CocoaEditor/assets/defaultCodeFiles/DefaultScript.cpp: -------------------------------------------------------------------------------- 1 | #include "DefaultScript.h" 2 | 3 | namespace Cocoa 4 | { 5 | void DefaultScript::Start() 6 | { 7 | // TODO Get start functions working 8 | 9 | // Place any start logic in here this function is called 10 | // once at the start of the scene's play 11 | } 12 | 13 | void DefaultScript::Update(float dt) 14 | { 15 | // dt is the last frame's length in ms 16 | 17 | // Place any update logic here this function is called 18 | // once every frame 19 | } 20 | } -------------------------------------------------------------------------------- /CocoaEditor/assets/defaultCodeFiles/DefaultScript.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cocoa/core/Core.h" 3 | #include "cocoa/util/Log.h" 4 | #include "cocoa/components/Script.h" 5 | 6 | namespace Cocoa 7 | { 8 | UCLASS(); 9 | class DefaultScript : public Script 10 | { 11 | public: 12 | virtual void Start() override; 13 | virtual void Update(float dt) override; 14 | 15 | public: 16 | UPROPERTY(); 17 | float m_ExampleFloatProperty = 3.14f; 18 | 19 | UPROPERTY(); 20 | int m_ExampleIntProperty = 10; 21 | }; 22 | } -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/FRABK.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/FRABK.TTF -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/LICENSE-fontawesome.txt: -------------------------------------------------------------------------------- 1 | Font Awesome Free License 2 | ------------------------- 3 | 4 | Font Awesome Free is free, open source, and GPL friendly. You can use it for 5 | commercial projects, open source projects, or really almost whatever you want. 6 | Full Font Awesome Free license: https://fontawesome.com/license/free. 7 | 8 | # Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/) 9 | In the Font Awesome Free download, the CC BY 4.0 license applies to all icons 10 | packaged as SVG and JS file types. 11 | 12 | # Fonts: SIL OFL 1.1 License (https://scripts.sil.org/OFL) 13 | In the Font Awesome Free download, the SIL OFL license applies to all icons 14 | packaged as web and desktop font files. 15 | 16 | # Code: MIT License (https://opensource.org/licenses/MIT) 17 | In the Font Awesome Free download, the MIT license applies to all non-font and 18 | non-icon files. 19 | 20 | # Attribution 21 | Attribution is required by MIT, SIL OFL, and CC BY licenses. Downloaded Font 22 | Awesome Free files already contain embedded comments with sufficient 23 | attribution, so you shouldn't need to do anything additional when using these 24 | files normally. 25 | 26 | We've kept attribution comments terse, so we ask that you do not actively work 27 | to remove them from files, especially code. They're a great way for folks to 28 | learn about Font Awesome. 29 | 30 | # Brand Icons 31 | All brand icons are trademarks of their respective owners. The use of these 32 | trademarks does not indicate endorsement of the trademark holder by Font 33 | Awesome, nor vice versa. **Please do not use brand logos for any purpose except 34 | to represent the company, product, or service to which they refer.** 35 | -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/OpenSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/OpenSans-Regular.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/UbuntuMono-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/UbuntuMono-Regular.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/fontawesome-webfont2.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/fontawesome-webfont2.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/fontawesome-webfont3.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/fontawesome-webfont3.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/openSans/OpenSans-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/openSans/OpenSans-Bold.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/openSans/OpenSans-BoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/openSans/OpenSans-BoldItalic.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/openSans/OpenSans-ExtraBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/openSans/OpenSans-ExtraBold.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/openSans/OpenSans-ExtraBoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/openSans/OpenSans-ExtraBoldItalic.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/openSans/OpenSans-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/openSans/OpenSans-Italic.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/openSans/OpenSans-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/openSans/OpenSans-Light.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/openSans/OpenSans-LightItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/openSans/OpenSans-LightItalic.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/openSans/OpenSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/openSans/OpenSans-Regular.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/openSans/OpenSans-SemiBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/openSans/OpenSans-SemiBold.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/openSans/OpenSans-SemiBoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/openSans/OpenSans-SemiBoldItalic.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/fonts/segoeui.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/fonts/segoeui.ttf -------------------------------------------------------------------------------- /CocoaEditor/assets/images/decorationsAndBlocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/images/decorationsAndBlocks.png -------------------------------------------------------------------------------- /CocoaEditor/assets/images/gizmos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/images/gizmos.png -------------------------------------------------------------------------------- /CocoaEditor/assets/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/images/icon.png -------------------------------------------------------------------------------- /CocoaEditor/assets/jadeLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/CocoaEditor/assets/jadeLogo.png -------------------------------------------------------------------------------- /CocoaEditor/assets/shaders/Picking.glsl: -------------------------------------------------------------------------------- 1 | #type vertex 2 | #version 330 3 | 4 | layout (location = 0) in vec3 aPos; 5 | layout (location = 1) in vec4 aColor; 6 | layout (location = 2) in vec2 aTexCoords; 7 | layout (location = 3) in float texID; 8 | layout (location = 4) in uint aEntityID; 9 | 10 | uniform mat4 uView; 11 | uniform mat4 uProjection; 12 | 13 | flat out uint fEntityID; 14 | out vec2 fTexCoords; 15 | out float fTexSlot; 16 | 17 | void main() 18 | { 19 | fEntityID = aEntityID; 20 | fTexCoords = aTexCoords; 21 | fTexSlot = texID; 22 | 23 | gl_Position = uProjection * uView * vec4(aPos, 1.0); 24 | } 25 | 26 | #type fragment 27 | #version 330 28 | 29 | flat in uint fEntityID; 30 | in vec2 fTexCoords; 31 | in float fTexSlot; 32 | 33 | uniform sampler2D uTextures[16]; 34 | 35 | layout(location = 0) out uint FragColor; 36 | 37 | void main() 38 | { 39 | vec4 texColor = vec4(1, 1, 1, 1); 40 | 41 | // Static indexing for linux based machines 42 | switch (int(fTexSlot)) { 43 | case 1: 44 | texColor = texture(uTextures[1], fTexCoords); 45 | break; 46 | case 2: 47 | texColor = texture(uTextures[2], fTexCoords); 48 | break; 49 | case 3: 50 | texColor = texture(uTextures[3], fTexCoords); 51 | break; 52 | case 4: 53 | texColor = texture(uTextures[4], fTexCoords); 54 | break; 55 | case 5: 56 | texColor = texture(uTextures[5], fTexCoords); 57 | break; 58 | case 6: 59 | texColor = texture(uTextures[6], fTexCoords); 60 | break; 61 | case 7: 62 | texColor = texture(uTextures[7], fTexCoords); 63 | break; 64 | case 8: 65 | texColor = texture(uTextures[8], fTexCoords); 66 | break; 67 | case 9: 68 | texColor = texture(uTextures[9], fTexCoords); 69 | break; 70 | case 10: 71 | texColor = texture(uTextures[10], fTexCoords); 72 | break; 73 | case 11: 74 | texColor = texture(uTextures[11], fTexCoords); 75 | break; 76 | case 12: 77 | texColor = texture(uTextures[12], fTexCoords); 78 | break; 79 | case 13: 80 | texColor = texture(uTextures[13], fTexCoords); 81 | break; 82 | case 14: 83 | texColor = texture(uTextures[14], fTexCoords); 84 | break; 85 | case 15: 86 | texColor = texture(uTextures[15], fTexCoords); 87 | break; 88 | } 89 | 90 | if (texColor.a < 0.2) { 91 | FragColor = 32U; 92 | } else { 93 | FragColor = 32U;//fEntityID; 94 | } 95 | } -------------------------------------------------------------------------------- /CocoaEditor/assets/shaders/debugLine2D.glsl: -------------------------------------------------------------------------------- 1 | #type vertex 2 | #version 330 core 3 | layout (location = 0) in vec3 aPos; 4 | layout (location = 1) in vec3 aColor; 5 | 6 | out vec3 fColor; 7 | 8 | uniform mat4 uView; 9 | uniform mat4 uProjection; 10 | 11 | void main() 12 | { 13 | fColor = aColor; 14 | 15 | gl_Position = uProjection * uView * vec4(aPos, 1); 16 | } 17 | 18 | #type fragment 19 | #version 330 core 20 | in vec3 fColor; 21 | 22 | out vec4 color; 23 | 24 | void main() 25 | { 26 | color = vec4(fColor, 1); 27 | } -------------------------------------------------------------------------------- /CocoaEditor/assets/shaders/default.glsl: -------------------------------------------------------------------------------- 1 | #type vertex 2 | #version 330 core 3 | layout (location = 0) in vec3 aPos; 4 | layout (location = 1) in vec3 aColor; 5 | 6 | out vec3 fColor; 7 | 8 | void main() 9 | { 10 | fColor = aColor; 11 | gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0); 12 | } 13 | 14 | #type fragment 15 | #version 330 core 16 | out vec4 FragColor; 17 | 18 | in vec3 fColor; 19 | 20 | void main() 21 | { 22 | FragColor = vec4(fColor, 1.0f); 23 | } -------------------------------------------------------------------------------- /CocoaEditor/assets/styles/Default.json: -------------------------------------------------------------------------------- 1 | { 2 | "Colors": { 3 | "Accent": { 4 | "W": 1.0, 5 | "X": 0.14900000393390656, 6 | "Y": 0.14900000393390656, 7 | "Z": 0.14900000393390656 8 | }, 9 | "AccentDark0": { 10 | "W": 1.0, 11 | "X": 0.10199999809265137, 12 | "Y": 0.10199999809265137, 13 | "Z": 0.10199999809265137 14 | }, 15 | "AccentDark1": { 16 | "W": 1.0, 17 | "X": 0.06300000101327896, 18 | "Y": 0.06300000101327896, 19 | "Z": 0.06300000101327896 20 | }, 21 | "Button": { 22 | "W": 1.0, 23 | "X": 0.8820000290870667, 24 | "Y": 0.8820000290870667, 25 | "Z": 0.8820000290870667 26 | }, 27 | "ButtonHovered": { 28 | "W": 1.0, 29 | "X": 0.7820000052452087, 30 | "Y": 0.7820000052452087, 31 | "Z": 0.7820000052452087 32 | }, 33 | "Font": { 34 | "W": 1.0, 35 | "X": 0.9020000100135803, 36 | "Y": 0.9020000100135803, 37 | "Z": 0.9020000100135803 38 | }, 39 | "FontDisabled": { 40 | "W": 1.0, 41 | "X": 0.36000001430511475, 42 | "Y": 0.36000001430511475, 43 | "Z": 0.36000001430511475 44 | }, 45 | "Header": { 46 | "W": 1.0, 47 | "X": 0.33799999952316284, 48 | "Y": 0.33799999952316284, 49 | "Z": 0.33799999952316284 50 | }, 51 | "HeaderActive": { 52 | "W": 1.0, 53 | "X": 0.3790000081062317, 54 | "Y": 0.3790000081062317, 55 | "Z": 0.3790000081062317 56 | }, 57 | "HeaderHovered": { 58 | "W": 1.0, 59 | "X": 0.2759999930858612, 60 | "Y": 0.2759999930858612, 61 | "Z": 0.2759999930858612 62 | }, 63 | "Highlight": { 64 | "W": 1.0, 65 | "X": 0.14499999582767487, 66 | "Y": 0.5529999732971191, 67 | "Z": 0.3840000033378601 68 | }, 69 | "MainBg": { 70 | "W": 1.0, 71 | "X": 0.20999999344348907, 72 | "Y": 0.20999999344348907, 73 | "Z": 0.20999999344348907 74 | }, 75 | "MainBgDark0": { 76 | "W": 1.0, 77 | "X": 0.1899999976158142, 78 | "Y": 0.1899999976158142, 79 | "Z": 0.1899999976158142 80 | }, 81 | "MainBgDark1": { 82 | "W": 1.0, 83 | "X": 0.14499999582767487, 84 | "Y": 0.14499999582767487, 85 | "Z": 0.14499999582767487 86 | }, 87 | "MainBgDark2": { 88 | "W": 1.0, 89 | "X": 0.09799999743700027, 90 | "Y": 0.09799999743700027, 91 | "Z": 0.09799999743700027 92 | }, 93 | "MainBgLight0": { 94 | "W": 1.0, 95 | "X": 0.40400001406669617, 96 | "Y": 0.40400001406669617, 97 | "Z": 0.40400001406669617 98 | } 99 | }, 100 | "Sizing": { 101 | "FramePadding": { 102 | "X": 20.0, 103 | "Y": 8.0 104 | }, 105 | "FrameRounding": 8.0, 106 | "GrabRounding": 8.0, 107 | "ItemSpacing": { 108 | "X": 20.0, 109 | "Y": 8.0 110 | }, 111 | "ScrollbarRounding": 12.0, 112 | "ScrollbarSize": 17.0, 113 | "TabRounding": 8.0, 114 | "WindowPadding": { 115 | "X": 10.0, 116 | "Y": 10.0 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /CocoaEditor/assets/styles/dark.json: -------------------------------------------------------------------------------- 1 | { 2 | "Colors": { 3 | "Accent": { 4 | "W": 1.0, 5 | "X": 0.14900000393390656, 6 | "Y": 0.14900000393390656, 7 | "Z": 0.14900000393390656 8 | }, 9 | "AccentDark0": { 10 | "W": 1.0, 11 | "X": 0.10199999809265137, 12 | "Y": 0.10199999809265137, 13 | "Z": 0.10199999809265137 14 | }, 15 | "AccentDark1": { 16 | "W": 1.0, 17 | "X": 0.06300000101327896, 18 | "Y": 0.06300000101327896, 19 | "Z": 0.06300000101327896 20 | }, 21 | "Button": { 22 | "W": 1.0, 23 | "X": 0.8820000290870667, 24 | "Y": 0.8820000290870667, 25 | "Z": 0.8820000290870667 26 | }, 27 | "ButtonHovered": { 28 | "W": 1.0, 29 | "X": 0.7820000052452087, 30 | "Y": 0.7820000052452087, 31 | "Z": 0.7820000052452087 32 | }, 33 | "Font": { 34 | "W": 1.0, 35 | "X": 0.9020000100135803, 36 | "Y": 0.9020000100135803, 37 | "Z": 0.9020000100135803 38 | }, 39 | "FontDisabled": { 40 | "W": 1.0, 41 | "X": 0.8389999866485596, 42 | "Y": 0.8389999866485596, 43 | "Z": 0.8389999866485596 44 | }, 45 | "Header": { 46 | "W": 1.0, 47 | "X": 0.33799999952316284, 48 | "Y": 0.33799999952316284, 49 | "Z": 0.33799999952316284 50 | }, 51 | "HeaderActive": { 52 | "W": 1.0, 53 | "X": 0.3790000081062317, 54 | "Y": 0.3790000081062317, 55 | "Z": 0.3790000081062317 56 | }, 57 | "HeaderHovered": { 58 | "W": 1.0, 59 | "X": 0.2759999930858612, 60 | "Y": 0.2759999930858612, 61 | "Z": 0.2759999930858612 62 | }, 63 | "Highlight": { 64 | "W": 1.0, 65 | "X": 0.14499999582767487, 66 | "Y": 0.5529999732971191, 67 | "Z": 0.3840000033378601 68 | }, 69 | "MainBg": { 70 | "W": 1.0, 71 | "X": 0.20999999344348907, 72 | "Y": 0.20999999344348907, 73 | "Z": 0.20999999344348907 74 | }, 75 | "MainBgDark0": { 76 | "W": 1.0, 77 | "X": 0.1899999976158142, 78 | "Y": 0.1899999976158142, 79 | "Z": 0.1899999976158142 80 | }, 81 | "MainBgDark1": { 82 | "W": 1.0, 83 | "X": 0.14499999582767487, 84 | "Y": 0.14499999582767487, 85 | "Z": 0.14499999582767487 86 | }, 87 | "MainBgDark2": { 88 | "W": 1.0, 89 | "X": 0.09799999743700027, 90 | "Y": 0.09799999743700027, 91 | "Z": 0.09799999743700027 92 | }, 93 | "MainBgLight0": { 94 | "W": 1.0, 95 | "X": 0.40400001406669617, 96 | "Y": 0.40400001406669617, 97 | "Z": 0.40400001406669617 98 | } 99 | }, 100 | "Sizing": { 101 | "FramePadding": { 102 | "X": 20.0, 103 | "Y": 8.0 104 | }, 105 | "FrameRounding": 8.0, 106 | "GrabRounding": 8.0, 107 | "ItemSpacing": { 108 | "X": 20.0, 109 | "Y": 8.0 110 | }, 111 | "ScrollbarRounding": 12.0, 112 | "ScrollbarSize": 17.0, 113 | "TabRounding": 8.0, 114 | "WindowPadding": { 115 | "X": 10.0, 116 | "Y": 10.0 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /CocoaEditor/assets/styles/darkv2.json: -------------------------------------------------------------------------------- 1 | { 2 | "Colors": { 3 | "Accent": { 4 | "W": 1.0, 5 | "X": 0.14900000393390656, 6 | "Y": 0.14900000393390656, 7 | "Z": 0.14900000393390656 8 | }, 9 | "AccentDark0": { 10 | "W": 1.0, 11 | "X": 0.10199999809265137, 12 | "Y": 0.10199999809265137, 13 | "Z": 0.10199999809265137 14 | }, 15 | "AccentDark1": { 16 | "W": 1.0, 17 | "X": 0.06300000101327896, 18 | "Y": 0.06300000101327896, 19 | "Z": 0.06300000101327896 20 | }, 21 | "Button": { 22 | "W": 1.0, 23 | "X": 0.8820000290870667, 24 | "Y": 0.8820000290870667, 25 | "Z": 0.8820000290870667 26 | }, 27 | "ButtonHovered": { 28 | "W": 1.0, 29 | "X": 0.7820000052452087, 30 | "Y": 0.7820000052452087, 31 | "Z": 0.7820000052452087 32 | }, 33 | "Font": { 34 | "W": 1.0, 35 | "X": 0.9020000100135803, 36 | "Y": 0.9020000100135803, 37 | "Z": 0.9020000100135803 38 | }, 39 | "FontDisabled": { 40 | "W": 1.0, 41 | "X": 0.5448275804519653, 42 | "Y": 0.5235354900360107, 43 | "Z": 0.5235354900360107 44 | }, 45 | "Highlight": { 46 | "W": 1.0, 47 | "X": 0.12941177189350128, 48 | "Y": 0.14509804546833038, 49 | "Z": 0.16078431904315948 50 | }, 51 | "MainBg": { 52 | "W": 1.0, 53 | "X": 0.20392157137393951, 54 | "Y": 0.22745098173618317, 55 | "Z": 0.250980406999588 56 | }, 57 | "MainBgDark0": { 58 | "W": 1.0, 59 | "X": 0.12941177189350128, 60 | "Y": 0.14509804546833038, 61 | "Z": 0.16078431904315948 62 | }, 63 | "MainBgDark1": { 64 | "W": 1.0, 65 | "X": 0.2862745225429535, 66 | "Y": 0.3137255012989044, 67 | "Z": 0.34117648005485535 68 | }, 69 | "MainBgDark2": { 70 | "W": 1.0, 71 | "X": 0.42352941632270813, 72 | "Y": 0.4588235318660736, 73 | "Z": 0.4901960790157318 74 | }, 75 | "MainBgLight0": { 76 | "W": 1.0, 77 | "X": 0.40400001406669617, 78 | "Y": 0.40400001406669617, 79 | "Z": 0.40400001406669617 80 | } 81 | }, 82 | "Sizing": { 83 | "FramePadding": { 84 | "X": 20.0, 85 | "Y": 8.0 86 | }, 87 | "FrameRounding": 8.0, 88 | "GrabRounding": 8.0, 89 | "ItemSpacing": { 90 | "X": 20.0, 91 | "Y": 8.0 92 | }, 93 | "ScrollbarRounding": 12.0, 94 | "ScrollbarSize": 17.0, 95 | "TabRounding": 8.0, 96 | "WindowPadding": { 97 | "X": 10.0, 98 | "Y": 10.0 99 | } 100 | } 101 | } -------------------------------------------------------------------------------- /CocoaEditor/assets/styles/noctis-viola.json: -------------------------------------------------------------------------------- 1 | { 2 | "Colors": { 3 | "Accent": { 4 | "W": 1.0, 5 | "X": 0.0, 6 | "Y": 0.3049019607843137, 7 | "Z": 0.3088235294117647 8 | }, 9 | "AccentDark0": { 10 | "W": 1.0, 11 | "X": 0.1333333333333333, 12 | "Y": 0.5764705882352941, 13 | "Z": 0.5372549019607843 14 | }, 15 | "AccentDark1": { 16 | "W": 1.0, 17 | "X": 0.1333333333333333, 18 | "Y": 0.5764705882352941, 19 | "Z": 0.5372549019607843 20 | }, 21 | "Button": { 22 | "W": 1.0, 23 | "X": 0.203921568627451, 24 | "Y": 0.654901960784313, 25 | "Z": 0.596078431372549 26 | }, 27 | "ButtonHovered": { 28 | "W": 1.0, 29 | "X": 0.203921568627451, 30 | "Y": 0.754901960784313, 31 | "Z": 0.696078431372549 32 | }, 33 | "Font": { 34 | "W": 1.0, 35 | "X": 0.9020000100135803, 36 | "Y": 0.9020000100135803, 37 | "Z": 0.9020000100135803 38 | }, 39 | "FontDisabled": { 40 | "W": 1.0, 41 | "X": 0.7389999866485596, 42 | "Y": 0.7389999866485596, 43 | "Z": 0.7389999866485596 44 | }, 45 | "Highlight": { 46 | "W": 1.0, 47 | "X": 0.14499999582767487, 48 | "Y": 0.5529999732971191, 49 | "Z": 0.3840000033378601 50 | }, 51 | "MainBg": { 52 | "W": 0.6, 53 | "X": 0.1411764705882353, 54 | "Y": 0.4117647058823529, 55 | "Z": 0.4 56 | }, 57 | "MainBgDark0": { 58 | "W": 0.6, 59 | "X": 0.1411764705882353, 60 | "Y": 0.3117647058823529, 61 | "Z": 0.3117647058823529 62 | }, 63 | "MainBgDark1": { 64 | "W": 0.9, 65 | "X": 0.1411764705882353, 66 | "Y": 0.2117647058823529, 67 | "Z": 0.2117647058823529 68 | }, 69 | "MainBgDark2": { 70 | "W": 0.9, 71 | "X": 0.1411764705882353, 72 | "Y": 0.2117647058823529, 73 | "Z": 0.2117647058823529 74 | }, 75 | "MainBgLight0": { 76 | "W": 0.9, 77 | "X": 0.1411764705882353, 78 | "Y": 0.2117647058823529, 79 | "Z": 0.2117647058823529 80 | } 81 | }, 82 | "Sizing": { 83 | "FramePadding": { 84 | "X": 20.0, 85 | "Y": 8.0 86 | }, 87 | "FrameRounding": 8.0, 88 | "GrabRounding": 8.0, 89 | "ItemSpacing": { 90 | "X": 20.0, 91 | "Y": 8.0 92 | }, 93 | "ScrollbarRounding": 12.0, 94 | "ScrollbarSize": 17.0, 95 | "TabRounding": 8.0, 96 | "WindowPadding": { 97 | "X": 10.0, 98 | "Y": 10.0 99 | } 100 | } 101 | } 102 | 103 | -------------------------------------------------------------------------------- /CocoaEditor/assets/styles/oceanic.json: -------------------------------------------------------------------------------- 1 | { 2 | "Colors": { 3 | "Accent": { 4 | "W": 1.0, 5 | "X": 0.0, 6 | "Y": 0.3049019607843137, 7 | "Z": 0.3088235294117647 8 | }, 9 | "AccentDark0": { 10 | "W": 1.0, 11 | "X": 0.1333333333333333, 12 | "Y": 0.5764705882352941, 13 | "Z": 0.5372549019607843 14 | }, 15 | "AccentDark1": { 16 | "W": 1.0, 17 | "X": 0.1333333333333333, 18 | "Y": 0.5764705882352941, 19 | "Z": 0.5372549019607843 20 | }, 21 | "Button": { 22 | "W": 1.0, 23 | "X": 0.203921568627451, 24 | "Y": 0.654901960784313, 25 | "Z": 0.596078431372549 26 | }, 27 | "ButtonHovered": { 28 | "W": 1.0, 29 | "X": 0.203921568627451, 30 | "Y": 0.754901960784313, 31 | "Z": 0.696078431372549 32 | }, 33 | "Font": { 34 | "W": 1.0, 35 | "X": 0.9020000100135803, 36 | "Y": 0.9020000100135803, 37 | "Z": 0.9020000100135803 38 | }, 39 | "FontDisabled": { 40 | "W": 1.0, 41 | "X": 0.7389999866485596, 42 | "Y": 0.7389999866485596, 43 | "Z": 0.7389999866485596 44 | }, 45 | "Highlight": { 46 | "W": 1.0, 47 | "X": 0.14499999582767487, 48 | "Y": 0.5529999732971191, 49 | "Z": 0.3840000033378601 50 | }, 51 | "MainBg": { 52 | "W": 1.0, 53 | "X": 0.1411764705882353, 54 | "Y": 0.4117647058823529, 55 | "Z": 0.4 56 | }, 57 | "MainBgDark0": { 58 | "W": 1.0, 59 | "X": 0.1411764705882353, 60 | "Y": 0.3117647058823529, 61 | "Z": 0.3117647058823529 62 | }, 63 | "MainBgDark1": { 64 | "W": 1.0, 65 | "X": 0.1411764705882353, 66 | "Y": 0.2117647058823529, 67 | "Z": 0.2117647058823529 68 | }, 69 | "MainBgDark2": { 70 | "W": 1.0, 71 | "X": 0.1411764705882353, 72 | "Y": 0.2117647058823529, 73 | "Z": 0.2117647058823529 74 | }, 75 | "MainBgLight0": { 76 | "W": 1.0, 77 | "X": 0.1411764705882353, 78 | "Y": 0.2117647058823529, 79 | "Z": 0.2117647058823529 80 | } 81 | }, 82 | "Sizing": { 83 | "FramePadding": { 84 | "X": 20.0, 85 | "Y": 8.0 86 | }, 87 | "FrameRounding": 8.0, 88 | "GrabRounding": 8.0, 89 | "ItemSpacing": { 90 | "X": 20.0, 91 | "Y": 8.0 92 | }, 93 | "ScrollbarRounding": 12.0, 94 | "ScrollbarSize": 17.0, 95 | "TabRounding": 8.0, 96 | "WindowPadding": { 97 | "X": 10.0, 98 | "Y": 10.0 99 | } 100 | } 101 | } 102 | 103 | -------------------------------------------------------------------------------- /CocoaEditor/assets/styles/uranium.json: -------------------------------------------------------------------------------- 1 | { 2 | "Colors": { 3 | "Accent": { 4 | "W": 1.0, 5 | "X": 0.34900000393390656, 6 | "Y": 0.64900000393390656, 7 | "Z": 0.39990000393390656 8 | }, 9 | "AccentDark0": { 10 | "W": 1.0, 11 | "X": 0.24900000393390656, 12 | "Y": 0.44900000393390656, 13 | "Z": 0.29990000393390656 14 | }, 15 | "AccentDark1": { 16 | "W": 1.0, 17 | "X": 0.14900000393390656, 18 | "Y": 0.34900000393390656, 19 | "Z": 0.19990000393390656 20 | }, 21 | "Button": { 22 | "W": 1.0, 23 | "X": 0.3820000290870667, 24 | "Y": 0.7820000290870667, 25 | "Z": 0.5820000290870667 26 | }, 27 | "ButtonHovered": { 28 | "W": 1.0, 29 | "X": 0.2820000290870667, 30 | "Y": 0.6820000290870667, 31 | "Z": 0.4820000290870667 32 | }, 33 | "Font": { 34 | "W": 1.0, 35 | "X": 1.0, 36 | "Y": 1.0, 37 | "Z": 1.0 38 | }, 39 | "FontDisabled": { 40 | "W": 1.0, 41 | "X": 0.8389999866485596, 42 | "Y": 0.8389999866485596, 43 | "Z": 0.8389999866485596 44 | }, 45 | "Highlight": { 46 | "W": 1.0, 47 | "X": 0.44499999582767487, 48 | "Y": 0.8529999732971191, 49 | "Z": 0.3840000033378601 50 | }, 51 | "MainBg": { 52 | "W": 0.6, 53 | "X": 0.21199999749660492, 54 | "Y": 0.66199999749660492, 55 | "Z": 0.41199999749660492 56 | }, 57 | "MainBgDark0": { 58 | "W": 0.6, 59 | "X": 0.1899999976158142, 60 | "Y": 0.5199999976158142, 61 | "Z": 0.3199999976158142 62 | }, 63 | "MainBgDark1": { 64 | "W": 0.6, 65 | "X": 0.1899999976158142, 66 | "Y": 0.4199999976158142, 67 | "Z": 0.2199999976158142 68 | }, 69 | "MainBgDark2": { 70 | "W": 0.6, 71 | "X": 0.0899999976158142, 72 | "Y": 0.3199999976158142, 73 | "Z": 0.1199999976158142 74 | }, 75 | "MainBgLight0": { 76 | "W": 0.6, 77 | "X": 0.1899999976158142, 78 | "Y": 0.4199999976158142, 79 | "Z": 0.2199999976158142 80 | } 81 | }, 82 | "Sizing": { 83 | "FramePadding": { 84 | "X": 20.0, 85 | "Y": 8.0 86 | }, 87 | "FrameRounding": 8.0, 88 | "GrabRounding": 8.0, 89 | "ItemSpacing": { 90 | "X": 20.0, 91 | "Y": 8.0 92 | }, 93 | "ScrollbarRounding": 12.0, 94 | "ScrollbarSize": 17.0, 95 | "TabRounding": 8.0, 96 | "WindowPadding": { 97 | "X": 10.0, 98 | "Y": 10.0 99 | } 100 | } 101 | } -------------------------------------------------------------------------------- /CocoaEditor/cpp/core/LevelEditorSceneInitializer.cpp: -------------------------------------------------------------------------------- 1 | #include "core/LevelEditorSceneInitializer.h" 2 | 3 | #include "renderer/Gizmos.h" 4 | #include "editorWindows/InspectorWindow.h" 5 | #include "editorWindows/SceneHierarchyWindow.h" 6 | #include "core/LevelEditorSystem.h" 7 | #include "core/ImGuiLayer.h" 8 | #include "core/CocoaEditorApplication.h" 9 | 10 | #include "cocoa/scenes/Scene.h" 11 | #include "cocoa/systems/ScriptSystem.h" 12 | 13 | namespace Cocoa 14 | { 15 | void LevelEditorSceneInitializer::init(SceneData& scene) 16 | { 17 | LevelEditorSystem::init(scene); 18 | InspectorWindow::clearAllEntities(); 19 | GizmoSystem::init(scene); 20 | } 21 | 22 | void LevelEditorSceneInitializer::start(SceneData& scene) 23 | { 24 | 25 | } 26 | 27 | void LevelEditorSceneInitializer::destroy(SceneData& scene) 28 | { 29 | GizmoSystem::destroy(scene); 30 | LevelEditorSystem::destroy(scene); 31 | } 32 | 33 | void LevelEditorSceneInitializer::save(SceneData& scene) 34 | { 35 | SceneHierarchyWindow::serialize(scene.saveDataJson); 36 | LevelEditorSystem::serialize(scene.saveDataJson); 37 | } 38 | 39 | void LevelEditorSceneInitializer::load(SceneData& scene) 40 | { 41 | SceneHierarchyWindow::deserialize(scene.saveDataJson, scene); 42 | LevelEditorSystem::deserialize(scene.saveDataJson, scene); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /CocoaEditor/cpp/editorWindows/GameEditorViewport.cpp: -------------------------------------------------------------------------------- 1 | #include "editorWindows/GameEditorViewport.h" 2 | #include "nativeScripting/CppBuild.h" 3 | #include "core/LevelEditorSystem.h" 4 | #include "util/Settings.h" 5 | 6 | #include "cocoa/util/Settings.h" 7 | #include "cocoa/scenes/Scene.h" 8 | #include "cocoa/core/Application.h" 9 | #include "cocoa/systems/RenderSystem.h" 10 | 11 | #include 12 | 13 | namespace Cocoa 14 | { 15 | namespace GameEditorViewport 16 | { 17 | // Internal variables 18 | static glm::vec2 m_GameviewPos = glm::vec2(); 19 | static glm::vec2 m_GameviewSize = glm::vec2(); 20 | static glm::vec2 m_GameviewMousePos = glm::vec2(); 21 | static bool m_BlockEvents = false; 22 | 23 | void imgui(SceneData& scene, bool* isWindowHovered) 24 | { 25 | static bool open = true; 26 | ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0, 0, 0, 1)); 27 | ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); 28 | ImGui::Begin("Game Editor Viewport", &open, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_MenuBar); 29 | *isWindowHovered = ImGui::IsWindowHovered(); 30 | 31 | if (ImGui::BeginMenuBar()) 32 | { 33 | static bool isPlaying = false; 34 | static bool compiling = false; 35 | static bool setCompilingFalse = false; 36 | 37 | if (ImGui::BeginMenu("Play", !isPlaying)) 38 | { 39 | if (!isPlaying) 40 | { 41 | std::filesystem::path tmpPath = Settings::General::engineAssetsPath / "tmp.cocoa"; 42 | Scene::save(scene, tmpPath); 43 | Scene::play(scene); 44 | isPlaying = true; 45 | } 46 | ImGui::EndMenu(); 47 | } 48 | else if (ImGui::BeginMenu("Stop", isPlaying)) 49 | { 50 | if (isPlaying) 51 | { 52 | Scene::stop(scene); 53 | std::filesystem::path tmpPath = Settings::General::engineAssetsPath / "tmp.cocoa"; 54 | Scene::freeResources(scene); 55 | Scene::load(scene, tmpPath, false); 56 | isPlaying = false; 57 | } 58 | ImGui::EndMenu(); 59 | } 60 | else if (ImGui::MenuItem("Compile")) 61 | { 62 | std::filesystem::path scriptsPath = Settings::General::workingDirectory / "scripts"; 63 | CppBuild::compile(scriptsPath); 64 | } 65 | ImGui::EndMenuBar(); 66 | } 67 | 68 | ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 1); 69 | ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 1); 70 | 71 | ImVec2 windowSize = ImGui::GetContentRegionAvail() - ImVec2(1, 1); 72 | 73 | // Figure out the largest area that fits this target aspect ratio 74 | float aspectWidth = windowSize.x; 75 | float aspectHeight = (float)aspectWidth / Application::get()->getWindow()->getTargetAspectRatio(); 76 | if (aspectHeight > windowSize.y) 77 | { 78 | // It doesn't fit our height, we must switch to pillarbox 79 | aspectHeight = windowSize.y; 80 | aspectWidth = (float)aspectHeight * Application::get()->getWindow()->getTargetAspectRatio(); 81 | } 82 | 83 | // Center rectangle 84 | float vpX = (windowSize.x / 2.0f) - ((float)aspectWidth / 2.0f); 85 | float vpY = ((float)windowSize.y / 2.0f) - ((float)aspectHeight / 2.0f); 86 | 87 | ImGui::SetCursorPos(ImGui::GetCursorPos() + ImVec2(vpX, vpY)); 88 | 89 | ImVec2 topLeft = ImGui::GetCursorScreenPos(); 90 | m_GameviewPos.x = topLeft.x; 91 | m_GameviewPos.y = topLeft.y + aspectHeight; 92 | Input::setGameViewPos(m_GameviewPos); 93 | m_GameviewSize.x = aspectWidth; 94 | m_GameviewSize.y = aspectHeight; 95 | Input::setGameViewSize(m_GameviewSize); 96 | 97 | ImVec2 mousePos = ImGui::GetMousePos() - ImGui::GetCursorScreenPos() - ImVec2(ImGui::GetScrollX(), ImGui::GetScrollY()); 98 | m_GameviewMousePos.x = mousePos.x; 99 | m_GameviewMousePos.y = mousePos.y; 100 | Input::setGameViewMousePos(m_GameviewMousePos); 101 | 102 | Camera& camera = LevelEditorSystem::getCamera(); 103 | uint32 texId = NFramebuffer::getColorAttachment(camera.framebuffer, 0).graphicsId; 104 | ImGui::Image(reinterpret_cast(texId), ImVec2(aspectWidth, aspectHeight), ImVec2(0, 1), ImVec2(1, 0)); 105 | 106 | ImGui::End(); 107 | ImGui::PopStyleColor(); 108 | ImGui::PopStyleVar(); 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /CocoaEditor/cpp/editorWindows/GameViewport.cpp: -------------------------------------------------------------------------------- 1 | #include "editorWindows/GameViewport.h" 2 | #include "util/Settings.h" 3 | #include "core/LevelEditorSystem.h" 4 | 5 | #include "cocoa/util/Settings.h" 6 | #include "cocoa/scenes/Scene.h" 7 | #include "cocoa/core/Application.h" 8 | #include "cocoa/systems/RenderSystem.h" 9 | #include "cocoa/components/NoSerialize.h" 10 | 11 | #include 12 | 13 | namespace Cocoa 14 | { 15 | namespace GameViewport 16 | { 17 | // Internal variables 18 | static bool m_BlockEvents = false; 19 | 20 | void imgui(SceneData& scene) 21 | { 22 | static bool open = true; 23 | ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0, 0, 0, 1)); 24 | ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); 25 | ImGui::Begin("Game Viewport", &open, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_MenuBar); 26 | 27 | ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 1); 28 | ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 1); 29 | 30 | ImVec2 windowSize = ImGui::GetContentRegionAvail() - ImVec2(1, 1); 31 | 32 | // Figure out the largest area that fits this target aspect ratio 33 | float aspectWidth = windowSize.x; 34 | float aspectHeight = (float)aspectWidth / Application::get()->getWindow()->getTargetAspectRatio(); 35 | if (aspectHeight > windowSize.y) 36 | { 37 | // It doesn't fit our height, we must switch to pillarbox 38 | aspectHeight = windowSize.y; 39 | aspectWidth = (float)aspectHeight * Application::get()->getWindow()->getTargetAspectRatio(); 40 | } 41 | 42 | // Center rectangle 43 | float vpX = (windowSize.x / 2.0f) - ((float)aspectWidth / 2.0f); 44 | float vpY = ((float)windowSize.y / 2.0f) - ((float)aspectHeight / 2.0f); 45 | 46 | ImGui::SetCursorPos(ImGui::GetCursorPos() + ImVec2(vpX, vpY)); 47 | 48 | auto view = scene.registry.view(entt::exclude); 49 | int i = 0; 50 | for (auto& rawEntity : view) 51 | { 52 | Logger::Assert(i == 0, "Game viewport does not support multiple cameras yet."); 53 | const Camera& camera = scene.registry.get(rawEntity); 54 | uint32 texId = NFramebuffer::getColorAttachment(camera.framebuffer, 0).graphicsId; 55 | ImGui::Image(reinterpret_cast(texId), ImVec2(aspectWidth, aspectHeight), ImVec2(0, 1), ImVec2(1, 0)); 56 | i++; 57 | } 58 | 59 | ImGui::End(); 60 | ImGui::PopStyleColor(); 61 | ImGui::PopStyleVar(); 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /CocoaEditor/cpp/editorWindows/ProjectWizard.cpp: -------------------------------------------------------------------------------- 1 | #include "editorWindows/ProjectWizard.h" 2 | #include "gui/ImGuiExtended.h" 3 | #include "gui/FontAwesome.h" 4 | #include "core/CocoaEditorApplication.h" 5 | 6 | #include "cocoa/core/CWindow.h" 7 | #include "cocoa/core/Application.h" 8 | #include "cocoa/file/FileDialog.h" 9 | 10 | namespace Cocoa 11 | { 12 | namespace ProjectWizard 13 | { 14 | // Internal Variables 15 | static Texture mJadeLogo = {}; 16 | static glm::vec2 mIdealSize{ 0, 0 }; 17 | static glm::vec2 mTexturePos{ 0, 0 }; 18 | static glm::vec2 mVersionPos{ 0, 0 }; 19 | static glm::vec2 mCreateProjectButtonPos{ 0, 0 }; 20 | static glm::vec2 mOpenProjectButtonPos{ 0, 0 }; 21 | static glm::vec2 mButtonSize{ 0, 0 }; 22 | static glm::vec2 mPadding{ 10.0f, 20.0f }; 23 | 24 | static bool mCreatingProject = false; 25 | static char mTmpFilename[256]; 26 | static std::filesystem::path mNewProjectPath = ""; 27 | 28 | void init() 29 | { 30 | mTmpFilename[0] = '\0'; 31 | mIdealSize = Application::get()->getWindow()->getMonitorSize() / 2.0f; 32 | 33 | mJadeLogo.magFilter = FilterMode::Linear; 34 | mJadeLogo.minFilter = FilterMode::Linear; 35 | mJadeLogo.wrapS = WrapMode::Repeat; 36 | mJadeLogo.wrapT = WrapMode::Repeat; 37 | TextureUtil::generate(mJadeLogo, "assets/jadeLogo.png"); 38 | 39 | mTexturePos.x = (mIdealSize.x / 2.0f) - (mJadeLogo.width / 2.0f); 40 | mTexturePos.y = mIdealSize.y / 10.0f; 41 | mVersionPos = glm::vec2(-1.0f, -1.0f); 42 | mButtonSize = glm::vec2(mIdealSize.x / 3.0f, mIdealSize.y / 18.0f); 43 | mCreateProjectButtonPos = (mIdealSize / 2.0f) - (mButtonSize / 2.0f); 44 | mOpenProjectButtonPos = mCreateProjectButtonPos + glm::vec2(0.0f, mButtonSize.y) + glm::vec2(0.0f, mPadding.y); 45 | } 46 | 47 | void imgui(SceneData& scene) 48 | { 49 | static bool open = true; 50 | if (mVersionPos.x < 0 && mVersionPos.y < 0) 51 | { 52 | ImVec2 textSize = ImGui::CalcTextSize("Version 1.0 Alpha"); 53 | mVersionPos = (mIdealSize / 2.0f) - glm::vec2(textSize.x / 2.0f, textSize.y / 2.0f); 54 | mVersionPos.y = mTexturePos.y + mJadeLogo.height + textSize.y / 2.0f; 55 | } 56 | 57 | Application::get()->getWindow()->setSize(mIdealSize); 58 | glm::vec2 winPos = Application::get()->getWindow()->getWindowPos(); 59 | ImGui::SetNextWindowPos(ImVec2(winPos.x, winPos.y)); 60 | ImGui::SetNextWindowSize(ImVec2(mIdealSize.x, mIdealSize.y), ImGuiCond_Once); 61 | ImGui::Begin("Create or Open Project", &open, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize); 62 | 63 | ImGui::SetCursorPos(ImVec2(mTexturePos.x, mTexturePos.y)); 64 | ImGui::Image((void*)(mJadeLogo.graphicsId), ImVec2((float)mJadeLogo.width, (float)mJadeLogo.height)); 65 | ImGui::SetCursorPos(ImVec2(mVersionPos.x, mVersionPos.y)); 66 | ImGui::Text("Version 1.0 Alpha"); 67 | 68 | ImGui::SetCursorPos(ImVec2(mCreateProjectButtonPos.x, mCreateProjectButtonPos.y)); 69 | if (CImGui::button(ICON_FA_PLUS " Create Project", mButtonSize)) 70 | { 71 | mCreatingProject = true; 72 | } 73 | 74 | ImGui::SetCursorPos(ImVec2(mOpenProjectButtonPos.x, mOpenProjectButtonPos.y)); 75 | if (CImGui::button(ICON_FA_FOLDER_OPEN " Open Project", mButtonSize) && !mCreatingProject) 76 | { 77 | FileDialogResult res; 78 | if (FileDialog::getOpenFileName("", res, { {"Cocoa Project", "*.cprj"} })) 79 | { 80 | if (!EditorLayer::loadProject(scene, res.filepath)) 81 | { 82 | Logger::Warning("Unable to load project: %s", res.filepath.c_str()); 83 | } 84 | } 85 | } 86 | 87 | ImGui::End(); 88 | 89 | if (mCreatingProject) 90 | { 91 | createProjectImGui(scene, mCreatingProject); 92 | } 93 | } 94 | 95 | 96 | void createProjectImGui(SceneData& scene, bool& windowOpen) 97 | { 98 | ImGui::Begin("Create New Project", &windowOpen); 99 | 100 | ImGui::LabelText("##tmp_projectname", "Project Name:"); 101 | ImGui::InputText("##tmp_filename", mTmpFilename, 256); 102 | ImGui::LabelText("##tmp_projectdir", "Project Directory:"); 103 | ImGui::LabelText("##tmp_showfile", "%s", mNewProjectPath.string().c_str()); 104 | ImGui::SameLine(); 105 | 106 | if (CImGui::button("Choose Directory")) 107 | { 108 | FileDialogResult res; 109 | if (FileDialog::getOpenFolderName(".", res)) 110 | { 111 | mNewProjectPath = res.filepath; 112 | } 113 | } 114 | 115 | if (CImGui::button("Cancel")) 116 | { 117 | windowOpen = false; 118 | } 119 | ImGui::SameLine(); 120 | if (CImGui::button("Create")) 121 | { 122 | if (EditorLayer::createProject(scene, mNewProjectPath, mTmpFilename)) 123 | { 124 | CocoaEditor* e = static_cast(Application::get()); 125 | e->setProjectLoaded(); 126 | windowOpen = false; 127 | } 128 | } 129 | ImGui::End(); 130 | } 131 | } 132 | } -------------------------------------------------------------------------------- /CocoaEditor/cpp/nativeScripting/CppBuild.cpp: -------------------------------------------------------------------------------- 1 | #include "nativeScripting/CppBuild.h" 2 | 3 | #include "cocoa/file/File.h" 4 | 5 | namespace Cocoa 6 | { 7 | namespace CppBuild 8 | { 9 | // Internal variables 10 | static bool buildingCode = false; 11 | static bool compiling = false; 12 | 13 | void build(const std::filesystem::path& projectDirectory) 14 | { 15 | if (!buildingCode && !compiling) 16 | { 17 | buildingCode = true; 18 | const std::filesystem::path pathToBuildScript = projectDirectory.parent_path() / "build.bat"; 19 | std::string cmdArgs = "vs2019"; 20 | Logger::Info("CMD Args: %s", cmdArgs.c_str()); 21 | File::runProgram(pathToBuildScript, cmdArgs); 22 | buildingCode = false; 23 | } 24 | } 25 | 26 | void compile(const std::filesystem::path& projectDirectory) 27 | { 28 | if (!buildingCode && !compiling) 29 | { 30 | compiling = true; 31 | std::filesystem::path pathToBuildScript = projectDirectory.parent_path() / "build.bat"; 32 | std::string cmdArgs = "compile"; 33 | Logger::Info("CMD Args: %s", cmdArgs.c_str()); 34 | File::runProgram(pathToBuildScript, cmdArgs); 35 | compiling = false; 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /CocoaEditor/cpp/util/Settings.cpp: -------------------------------------------------------------------------------- 1 | #include "util/Settings.h" 2 | 3 | namespace Cocoa 4 | { 5 | namespace Settings 6 | { 7 | // TODO: Serialize this stuff on a per project basis or a global basis per user 8 | namespace Editor 9 | { 10 | // Which windows are open (of the windows that can be closed) 11 | bool showDemoWindow = false; 12 | bool showSettingsWindow = false; 13 | bool showStyleSelect = false; 14 | 15 | // Grid stuff 16 | bool snapToGrid = false; 17 | bool drawGrid = false; 18 | glm::vec2 gridSize = { 32.0f, 32.0f }; 19 | glm::vec3 gridColor = { 0.1f, 0.1f, 0.1f }; 20 | float gridStrokeWidth = 1.0f; 21 | 22 | // Selected Style 23 | int selectedStyle = 0; 24 | } 25 | 26 | namespace EditorStyle 27 | { 28 | // Fonts 29 | ImFont* defaultFont = nullptr; 30 | ImFont* largeIconFont = nullptr; 31 | 32 | // Style Colors 33 | glm::vec4 mainBgLight0{ 0.404f, 0.404f ,0.404f, 1.0f }; 34 | glm::vec4 mainBg{ 0.21f, 0.21f, 0.21f, 1.0f }; 35 | glm::vec4 mainBgDark0{ 0.190f, 0.190f, 0.190f, 1.0f }; 36 | glm::vec4 mainBgDark1{ 0.145f, 0.145f, 0.145f, 1.0f }; 37 | glm::vec4 mainBgDark2{ 0.098f, 0.098f, 0.098f, 1.0f }; 38 | 39 | glm::vec4 accent{ 0.149f, 0.149f, 0.149f, 1.0f }; 40 | glm::vec4 accentDark0{ 0.102f, 0.102f, 0.102f, 1.0f }; 41 | glm::vec4 accentDark1{ 0.063f, 0.063f, 0.063f, 1.0f }; 42 | 43 | glm::vec4 button{ 0.882f, 0.882f, 0.882f, 1.0f }; 44 | glm::vec4 buttonHovered{ 0.782f, 0.782f, 0.782f, 1.0f }; 45 | 46 | glm::vec4 header{ 0.338f, 0.338f, 0.338f, 1.0f }; 47 | glm::vec4 headerHovered{ 0.276f, 0.276f, 0.276f, 1.0f }; 48 | glm::vec4 headerActive{ 0.379f, 0.379f, 0.379f, 1.0f }; 49 | 50 | glm::vec4 font{ 0.902f, 0.902f, 0.902f, 1.0f }; 51 | glm::vec4 fontDisabled{ 0.36f, 0.36f, 0.36f, 1.0f }; 52 | glm::vec4 highlightColor{ 0.145f, 0.553f, 0.384f, 1.0f }; 53 | 54 | // Sizing 55 | glm::vec2 windowPadding{ 10, 10 }; 56 | glm::vec2 framePadding{ 20, 8 }; 57 | glm::vec2 itemSpacing{ 20, 8 }; 58 | float scrollbarSize = 17; 59 | float scrollbarRounding = 12; 60 | float frameRounding = 8; 61 | float grabRounding = 8; 62 | float tabRounding = 8; 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /CocoaEditor/imgui.ini: -------------------------------------------------------------------------------- 1 | [Window][DockSpace Demo] 2 | Pos=0,0 3 | Size=1920,1080 4 | Collapsed=0 5 | 6 | [Window][Debug##Default] 7 | Pos=60,60 8 | Size=400,400 9 | Collapsed=0 10 | 11 | [Window][Game Viewport] 12 | Pos=858,40 13 | Size=698,754 14 | Collapsed=0 15 | DockId=0x0000000A,0 16 | 17 | [Window][Assets] 18 | Pos=255,796 19 | Size=1301,284 20 | Collapsed=0 21 | DockId=0x00000007,0 22 | 23 | [Window][ Scene] 24 | Pos=0,40 25 | Size=253,1040 26 | Collapsed=0 27 | DockId=0x00000003,0 28 | 29 | [Window][ Inspector] 30 | Pos=1445,40 31 | Size=475,1006 32 | Collapsed=0 33 | DockId=0x00000005,0 34 | 35 | [Window][Create or Open Project] 36 | Pos=313,62 37 | Size=1920,1080 38 | Collapsed=0 39 | 40 | [Window][Create New Project] 41 | Pos=315,208 42 | Size=1083,522 43 | Collapsed=0 44 | 45 | [Window][Inspector] 46 | Pos=1558,40 47 | Size=362,1040 48 | Collapsed=0 49 | DockId=0x00000002,0 50 | 51 | [Window][Gizmo debug] 52 | Pos=299,57 53 | Size=308,484 54 | Collapsed=0 55 | 56 | [Window][Settings] 57 | Pos=986,400 58 | Size=900,600 59 | Collapsed=0 60 | 61 | [Window][Dear ImGui Demo] 62 | ViewportPos=639,463 63 | ViewportId=0xE927CF2F 64 | Size=1308,1025 65 | Collapsed=0 66 | 67 | [Window][Styles] 68 | ViewportPos=392,544 69 | ViewportId=0xB1F6FFC3 70 | Size=1172,1218 71 | Collapsed=0 72 | 73 | [Window][Dear ImGui Metrics] 74 | Pos=1105,187 75 | Size=604,496 76 | Collapsed=0 77 | 78 | [Window][Game Editor Viewport] 79 | Pos=255,40 80 | Size=601,754 81 | Collapsed=0 82 | DockId=0x00000009,0 83 | 84 | [Docking][Data] 85 | DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=4009,898 Size=1920,1040 Split=X 86 | DockNode ID=0x00000003 Parent=0x3BC79352 SizeRef=507,1040 Selected=0xA259292F 87 | DockNode ID=0x00000008 Parent=0x3BC79352 SizeRef=3331,1040 Split=X 88 | DockNode ID=0x00000001 Parent=0x00000008 SizeRef=2604,1995 Split=Y 89 | DockNode ID=0x00000004 Parent=0x00000001 SizeRef=3840,754 Split=Y 90 | DockNode ID=0x00000005 Parent=0x00000004 SizeRef=475,1048 Selected=0x57F8A5EA 91 | DockNode ID=0x00000006 Parent=0x00000004 SizeRef=475,945 Split=X Selected=0x6E2C89B8 92 | DockNode ID=0x00000009 Parent=0x00000006 SizeRef=601,754 CentralNode=1 Selected=0x6E2C89B8 93 | DockNode ID=0x0000000A Parent=0x00000006 SizeRef=698,754 Selected=0xAE7BB42F 94 | DockNode ID=0x00000007 Parent=0x00000001 SizeRef=3840,284 Selected=0x7E7D78B8 95 | DockNode ID=0x00000002 Parent=0x00000008 SizeRef=725,1995 Selected=0x42A639A8 96 | 97 | -------------------------------------------------------------------------------- /CocoaEditor/include/core/CocoaEditorApplication.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_COCOA_EDITOR_APPLICATION_H 2 | #define COCOA_EDITOR_COCOA_EDITOR_APPLICATION_H 3 | #include "core/LevelEditorSystem.h" 4 | 5 | #include "cocoa/core/Application.h" 6 | #include "cocoa/scenes/SceneData.h" 7 | 8 | namespace Cocoa 9 | { 10 | class SourceFileWatcher; 11 | 12 | namespace EditorLayer 13 | { 14 | void init(); 15 | void onAttach(SceneData& scene); 16 | void onUpdate(SceneData& scene, float dt); 17 | void onRender(SceneData& scene); 18 | void onEvent(SceneData& scene, Event& e); 19 | 20 | bool createProject(SceneData& scene, const std::filesystem::path& projectPath, const char* filename); 21 | bool loadEditorData(SceneData& scene, const std::filesystem::path& path); 22 | bool loadProject(SceneData& scene, const std::filesystem::path& path); 23 | void saveEditorData(); 24 | void saveProject(); 25 | void setProjectLoaded(); 26 | bool isProjectLoaded(); 27 | }; 28 | 29 | class CocoaEditor : public Application 30 | { 31 | public: 32 | ~CocoaEditor() = default; 33 | CocoaEditor(); 34 | 35 | void beginFrame() override; 36 | void endFrame() override; 37 | void init() override; 38 | void shutdown() override; 39 | 40 | static bool isProjectLoaded() 41 | { 42 | return EditorLayer::isProjectLoaded(); 43 | } 44 | 45 | static void setProjectLoaded() 46 | { 47 | EditorLayer::setProjectLoaded(); 48 | } 49 | 50 | void setAppData(AppOnAttachFn attachFn, AppOnUpdateFn updateFn, AppOnRenderFn renderFn, AppOnEventFn eventFn); 51 | }; 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /CocoaEditor/include/core/ImGuiLayer.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_IMGUI_LAYER_H 2 | #define COCOA_EDITOR_IMGUI_LAYER_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | #include "cocoa/scenes/SceneData.h" 7 | #include "cocoa/events/Event.h" 8 | 9 | #include 10 | 11 | namespace Cocoa 12 | { 13 | namespace ImGuiLayer 14 | { 15 | void init(void* window); 16 | void destroy(); 17 | void onEvent(SceneData& scene, Event& e); 18 | void beginFrame(SceneData& scene); 19 | void endFrame(); 20 | 21 | void loadStyle(const std::filesystem::path& filepath); 22 | void applyStyle(); 23 | void exportCurrentStyle(const std::filesystem::path& outputPath); 24 | }; 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /CocoaEditor/include/core/LevelEditorSceneInitializer.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_LEVEL_EDITOR_SCENE_INITIALIZER_H 2 | #define COCOA_EDITOR_LEVEL_EDITOR_SCENE_INITIALIZER_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | #include "cocoa/scenes/SceneInitializer.h" 7 | #include "cocoa/scenes/SceneData.h" 8 | 9 | namespace Cocoa 10 | { 11 | class LevelEditorSceneInitializer : public SceneInitializer 12 | { 13 | public: 14 | LevelEditorSceneInitializer() {} 15 | 16 | void init(SceneData& scene) override; 17 | void start(SceneData& scene) override; 18 | void destroy(SceneData& scene) override; 19 | void save(SceneData& scene) override; 20 | void load(SceneData& scene) override; 21 | }; 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /CocoaEditor/include/core/LevelEditorSystem.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_LEVEL_EDITOR_SYSTEM_H 2 | #define COCOA_EDITOR_LEVEL_EDITOR_SYSTEM_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | #include "cocoa/scenes/Scene.h" 7 | #include "cocoa/scenes/SceneData.h" 8 | 9 | namespace Cocoa 10 | { 11 | namespace LevelEditorSystem 12 | { 13 | void editorUpdate(SceneData& scene, float dt); 14 | void init(SceneData& scene); 15 | void onEvent(SceneData& scene, Event& e); 16 | void destroy(SceneData& scene); 17 | 18 | Camera& getCamera(); 19 | 20 | void serialize(json& j); 21 | void deserialize(const json& j, SceneData& scene); 22 | }; 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /CocoaEditor/include/editorWindows/AssetWindow.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_ASSET_WINDOW_H 2 | #define COCOA_EDITOR_ASSET_WINDOW_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | #include "cocoa/scenes/SceneData.h" 7 | 8 | namespace Cocoa 9 | { 10 | enum class AssetView 11 | { 12 | TextureBrowser, 13 | SceneBrowser, 14 | ScriptBrowser, 15 | FontBrowser, 16 | Length 17 | }; 18 | 19 | namespace AssetWindow 20 | { 21 | void imgui(SceneData& scene); 22 | }; 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /CocoaEditor/include/editorWindows/GameEditorViewport.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_GAME_EDITOR_VIEWPORT_H 2 | #define COCOA_EDITOR_GAME_EDITOR_VIEWPORT_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | #include "cocoa/scenes/SceneData.h" 7 | 8 | namespace Cocoa 9 | { 10 | namespace GameEditorViewport 11 | { 12 | void imgui(SceneData& scene, bool* isWindowHovered); 13 | } 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /CocoaEditor/include/editorWindows/GameViewport.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_GAME_VIEWPORT_H 2 | #define COCOA_EDITOR_GAME_VIEWPORT_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | #include "cocoa/scenes/SceneData.h" 7 | 8 | namespace Cocoa 9 | { 10 | namespace GameViewport 11 | { 12 | void imgui(SceneData& scene); 13 | } 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /CocoaEditor/include/editorWindows/InspectorWindow.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_INSPECTOR_WINDOW_H 2 | #define COCOA_EDITOR_INSPECTOR_WINDOW_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | #include "cocoa/core/Entity.h" 7 | 8 | namespace Cocoa 9 | { 10 | namespace InspectorWindow 11 | { 12 | void imgui(SceneData& scene); 13 | 14 | void addEntity(Entity entity); 15 | 16 | void removeEntity(Entity entity); 17 | 18 | void clearAllEntities(); 19 | 20 | Entity getActiveEntity(); 21 | }; 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /CocoaEditor/include/editorWindows/MenuBar.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_MENU_BAR_H 2 | #define COCOA_EDITOR_MENU_BAR_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | #include "cocoa/scenes/SceneData.h" 7 | 8 | namespace Cocoa 9 | { 10 | namespace MenuBar 11 | { 12 | void imgui(SceneData& scene); 13 | }; 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /CocoaEditor/include/editorWindows/ProjectWizard.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_PROJECT_WIZARD_H 2 | #define COCOA_EDITOR_PROJECT_WIZARD_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | #include "cocoa/scenes/SceneData.h" 7 | 8 | namespace Cocoa 9 | { 10 | namespace ProjectWizard 11 | { 12 | void init(); 13 | void imgui(SceneData& scene); 14 | 15 | void createProjectImGui(SceneData& scene, bool& windowOpen); 16 | }; 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /CocoaEditor/include/editorWindows/SceneHierarchyWindow.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_SCENE_HIERARCHY_WINDOW_H 2 | #define COCOA_EDITOR_SCENE_HIERARCHY_WINDOW_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | #include "cocoa/scenes/SceneData.h" 7 | #include "cocoa/core/EntityStruct.h" 8 | 9 | namespace Cocoa 10 | { 11 | namespace SceneHierarchyWindow 12 | { 13 | void init(); 14 | void destroy(); 15 | 16 | void addNewEntity(Entity entity); 17 | void imgui(SceneData& scene); 18 | void deleteEntity(Entity entity); 19 | 20 | void serialize(json& j); 21 | void deserialize(json& json, SceneData& scene); 22 | }; 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /CocoaEditor/include/gui/ImGuiExtended.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_IMGUI_EXTENDED_H 2 | #define COCOA_EDITOR_IMGUI_EXTENDED_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | #ifdef _COCOA_SCRIPT_DLL 7 | #include "ImGuiHeader.h" 8 | #else 9 | #include "gui/ImGuiHeader.h" 10 | #endif 11 | 12 | #include "cocoa/commands/ICommand.h" 13 | #include "cocoa/renderer/Texture.h" 14 | 15 | #include 16 | 17 | namespace CImGui 18 | { 19 | bool menuButton(const char* label, const glm::vec2& size = { 0, 0 }); 20 | bool button(const char* label, const glm::vec2& size = { 0, 0 }, bool invertTextColor=true); 21 | bool buttonDropdown(const char* label, const char* const items[], int items_size, int& item_pressed); 22 | bool imageButton(const Cocoa::Texture& texture, const glm::vec2& size, int framePadding = -1, 23 | const glm::vec4& bgColor = { 0, 0, 0, 0 }, const glm::vec4& tintColor = { 1, 1, 1, 1 }); 24 | bool inputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, 25 | ImGuiInputTextCallback callback = (ImGuiInputTextCallback)0, void* user_data = (void*)0); 26 | bool checkbox(const char* label, bool* checked); 27 | 28 | bool undoableColorEdit4(const char* label, glm::vec4& color); 29 | bool undoableColorEdit3(const char* label, glm::vec3& color); 30 | bool undoableDragFloat4(const char* label, glm::vec4& vector); 31 | bool undoableDragFloat3(const char* label, glm::vec3& vector); 32 | bool undoableDragFloat2(const char* label, glm::vec2& vector); 33 | bool undoableDragFloat(const char* label, float& val); 34 | bool undoableDragInt2(const char* label, glm::ivec2& val); 35 | bool undoableDragInt(const char* label, int& val); 36 | 37 | void readonlyText(const char* label, const std::string& readonlyTextValue); 38 | 39 | template 40 | bool undoableCombo(T& enumVal, const char* label, const char* const items[], int items_count) 41 | { 42 | int currentItem = static_cast(enumVal); 43 | ImGui::Text(label); 44 | ImGui::SameLine(); 45 | 46 | ImGui::PushStyleColor(ImGuiCol_FrameBg, ImGui::GetStyleColorVec4(ImGuiCol_Button)); 47 | ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered)); 48 | ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive)); 49 | ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextInverted)); 50 | if (!ImGui::BeginCombo((std::string("##") + std::string(label)).c_str(), items[currentItem], ImGuiComboFlags_None)) 51 | { 52 | ImGui::PopStyleColor(4); 53 | return false; 54 | } 55 | ImGui::PopStyleColor(4); 56 | 57 | // Display items 58 | bool valueChanged = false; 59 | for (int i = 0; i < items_count; i++) 60 | { 61 | ImGui::PushID((void*)(intptr_t)i); 62 | const bool item_selected = (i == currentItem); 63 | const char* item_text = items[i]; 64 | if (!item_text) 65 | item_text = "*Unknown item*"; 66 | if (ImGui::Selectable(item_text, item_selected)) 67 | { 68 | valueChanged = true; 69 | currentItem = i; 70 | } 71 | if (item_selected) 72 | ImGui::SetItemDefaultFocus(); 73 | ImGui::PopID(); 74 | } 75 | 76 | ImGui::EndCombo(); 77 | 78 | if (valueChanged) 79 | { 80 | Cocoa::CommandHistory::addCommand(new Cocoa::ChangeEnumCommand(enumVal, static_cast(currentItem))); 81 | Cocoa::CommandHistory::setNoMergeMostRecent(); 82 | } 83 | return valueChanged; 84 | } 85 | 86 | void beginCollapsingHeaderGroup(); 87 | void endCollapsingHeaderGroup(); 88 | ImVec4 from(const glm::vec4& vec4); 89 | ImVec2 from(const glm::vec2& vec2); 90 | 91 | bool beginDragDropTargetCurrentWindow(); 92 | } 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /CocoaEditor/include/gui/ImGuiHeader.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_IMGUI_HEADER_H 2 | #define COCOA_EDITOR_IMGUI_HEADER_H 3 | 4 | // =================================================================== 5 | // ImGUI 6 | // =================================================================== 7 | #pragma warning( push ) 8 | #pragma warning ( disable : 26812 ) 9 | #pragma warning ( disable : 26451 ) 10 | #pragma warning ( disable : 6031 ) 11 | #pragma warning ( disable : 26495 ) 12 | #define IMGUI_DEFINE_MATH_OPERATORS 13 | #include 14 | #include 15 | #include 16 | #pragma warning( pop ) 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /CocoaEditor/include/nativeScripting/CodeGenerators.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_CODE_GENERATORS_H 2 | #define COCOA_EDITOR_CODE_GENERATORS_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | 6 | #include "nativeScripting/ScriptParser.h" 7 | 8 | #include "cocoa/file/File.h" 9 | 10 | #include 11 | 12 | namespace Cocoa 13 | { 14 | namespace CodeGenerators 15 | { 16 | void generateInitFile(const std::vector& classes, const std::filesystem::path& filepath); 17 | 18 | void generatePremakeFile(const std::filesystem::path& filepath); 19 | 20 | void generateBuildFile(const std::filesystem::path& filepath, const std::filesystem::path& premakeFilepath); 21 | } 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /CocoaEditor/include/nativeScripting/CppBuild.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_CPP_BUILD_H 2 | #define COCOA_EDITOR_CPP_BUILD_H 3 | #include 4 | 5 | namespace Cocoa 6 | { 7 | namespace CppBuild 8 | { 9 | void build(const std::filesystem::path& projectDirectory); 10 | 11 | void compile(const std::filesystem::path& projectDirectory); 12 | } 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /CocoaEditor/include/nativeScripting/ScriptParser.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_SCRIPT_PARSER_H 2 | #define COCOA_EDITOR_SCRIPT_PARSER_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | 6 | #include 7 | 8 | namespace Cocoa 9 | { 10 | struct UVariable 11 | { 12 | std::string type; 13 | std::string identifier; 14 | // void* m_Literal; 15 | }; 16 | 17 | struct UClass 18 | { 19 | std::string className; 20 | std::filesystem::path fullFilepath; 21 | std::list variables; 22 | }; 23 | 24 | struct UStruct 25 | { 26 | std::string structName; 27 | const std::filesystem::path& fullFilepath; 28 | std::list variables; 29 | }; 30 | 31 | class ScriptParser 32 | { 33 | public: 34 | std::string generateHeaderFile(); 35 | void debugPrint(); 36 | void parse(); 37 | 38 | bool canGenerateHeaderFile() const { return mStructs.size() != 0 || mClasses.size() != 0; } 39 | std::vector& getClasses() { return mClasses; } 40 | 41 | static std::string getFilenameAsClassName(std::string filename); 42 | 43 | private: 44 | int mCurrentToken; 45 | std::filesystem::path mFullFilepath; 46 | 47 | std::vector mClasses; 48 | std::vector mStructs; 49 | }; 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /CocoaEditor/include/nativeScripting/SourceFileWatcher.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_SOURCE_FILE_WATCHER_H 2 | #define COCOA_EDITOR_SOURCE_FILE_WATCHER_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | 6 | #include "cocoa/file/FileSystemWatcher.h" 7 | 8 | namespace Cocoa 9 | { 10 | class SourceFileWatcher 11 | { 12 | public: 13 | SourceFileWatcher() 14 | : mRootDirectory("") { } 15 | SourceFileWatcher(const std::filesystem::path& path); 16 | ~SourceFileWatcher() { mFileWatcher.stop(); } 17 | 18 | private: 19 | void startFileWatcher(); 20 | 21 | private: 22 | std::filesystem::path mRootDirectory; 23 | FileSystemWatcher mFileWatcher; 24 | }; 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /CocoaEditor/include/renderer/Gizmos.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_GIZMOS_H 2 | #define COCOA_EDITOR_GIZMOS_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | #include "cocoa/components/Transform.h" 7 | #include "cocoa/scenes/SceneData.h" 8 | #include "cocoa/events/Event.h" 9 | 10 | namespace Cocoa 11 | { 12 | // Gizmo Components 13 | enum class GizmoMode 14 | { 15 | None, 16 | Translate, 17 | Rotate, 18 | Scale 19 | }; 20 | 21 | enum class GizmoType 22 | { 23 | None, 24 | Vertical, 25 | Horizontal, 26 | Free 27 | }; 28 | 29 | struct GizmoData 30 | { 31 | glm::vec2 position; 32 | glm::vec3 offset; 33 | glm::vec3 color; 34 | glm::vec2 scale; 35 | glm::vec2 boxBoundsHalfSize; 36 | glm::vec2 boxBoundsOffset; 37 | float rotation; 38 | 39 | GizmoType type; 40 | bool active; 41 | }; 42 | 43 | namespace Gizmo 44 | { 45 | GizmoData createGizmo( 46 | glm::vec3& offset, 47 | float rotation, 48 | GizmoType type, 49 | glm::vec3& color, 50 | glm::vec2& boxBoundsHalfSize, 51 | glm::vec2& boxBoundsOffset = glm::vec2{ 0.0f, 0.0f }, 52 | glm::vec2& scale = glm::vec2{ 1.0f, 1.0f }); 53 | 54 | void render(const GizmoData& data, const Camera& camera, GizmoMode mode); 55 | void gizmoManipulateTranslate(const GizmoData& data, TransformData& transform, const glm::vec3& originalDragClickPos, const glm::vec3& mouseOffset, const Camera& camera); 56 | void gizmoManipulateRotate(const GizmoData& data, TransformData& transform, const glm::vec3& startPos, const glm::vec3& mouseOffset, const Camera& camera); 57 | void gizmoManipulateScale(const GizmoData& data, TransformData& transform, const glm::vec3& originalDragClickPos, const glm::vec3& originalScale, const Camera& camera); 58 | }; 59 | 60 | namespace GizmoSystem 61 | { 62 | void editorUpdate(SceneData& scene, float dt); 63 | void imgui(); 64 | void onEvent(SceneData& scene, Event& e); 65 | void init(SceneData& scene); 66 | void destroy(SceneData& scene); 67 | }; 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /CocoaEditor/include/util/Settings.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_EDITOR_SETTINGS_H 2 | #define COCOA_EDITOR_SETTINGS_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | #include "gui/ImGuiHeader.h" 7 | 8 | namespace Cocoa 9 | { 10 | namespace Settings 11 | { 12 | namespace Editor 13 | { 14 | // Which windows are open (of the windows that can be closed) 15 | extern bool showDemoWindow; 16 | extern bool showSettingsWindow; 17 | extern bool showStyleSelect; 18 | 19 | // Grid stuff 20 | extern bool snapToGrid; 21 | extern bool drawGrid; 22 | extern glm::vec2 gridSize; 23 | extern glm::vec3 gridColor; 24 | extern float gridStrokeWidth; 25 | 26 | // Selected style 27 | extern int selectedStyle; 28 | }; 29 | 30 | namespace EditorStyle 31 | { 32 | // Fonts 33 | extern ImFont* defaultFont; 34 | extern ImFont* largeIconFont; 35 | 36 | // Style Colors 37 | extern glm::vec4 mainBgLight0; 38 | extern glm::vec4 mainBg; 39 | extern glm::vec4 mainBgDark0; 40 | extern glm::vec4 mainBgDark1; 41 | extern glm::vec4 mainBgDark2; 42 | 43 | extern glm::vec4 accent; 44 | extern glm::vec4 accentDark0; 45 | extern glm::vec4 accentDark1; 46 | 47 | extern glm::vec4 button; 48 | extern glm::vec4 buttonHovered; 49 | 50 | extern glm::vec4 header; 51 | extern glm::vec4 headerHovered; 52 | extern glm::vec4 headerActive; 53 | 54 | extern glm::vec4 font; 55 | extern glm::vec4 fontDisabled; 56 | extern glm::vec4 highlightColor; 57 | 58 | // Sizing 59 | extern glm::vec2 windowPadding; 60 | extern glm::vec2 framePadding; 61 | extern glm::vec2 itemSpacing; 62 | extern float scrollbarSize; 63 | extern float scrollbarRounding; 64 | extern float frameRounding; 65 | extern float grabRounding; 66 | extern float tabRounding; 67 | }; 68 | } 69 | } 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /CocoaEditor/premake5.lua: -------------------------------------------------------------------------------- 1 | project "CocoaEditor" 2 | kind "ConsoleApp" 3 | language "C++" 4 | cppdialect "C++17" 5 | staticruntime "off" 6 | 7 | fullOutputDir = "../bin/" .. outputdir .. "/%{prj.name}" 8 | targetdir ("../bin/" .. outputdir .. "/%{prj.name}") 9 | objdir ("../bin-int/" .. outputdir .. "/%{prj.name}") 10 | 11 | files { 12 | "include/**.h", 13 | "cpp/**.cpp", 14 | "tests/**.h", 15 | "tests/**.cpp", 16 | } 17 | 18 | disablewarnings { 19 | "4251", 20 | "4131", 21 | "4267" 22 | } 23 | 24 | libdirs { 25 | fullOutputDir 26 | } 27 | 28 | includedirs { 29 | "../CocoaEngine", 30 | "../CocoaEngine/include", 31 | "../CocoaEngine/vendor", 32 | "../%{prj.name}/include", 33 | "../%{prj.name}/tests", 34 | "../%{IncludeDir.glm}", 35 | "../%{IncludeDir.entt}", 36 | "../%{IncludeDir.Glad}", 37 | "../%{IncludeDir.ImGui}", 38 | "../%{IncludeDir.Box2D}", 39 | "../%{IncludeDir.Json}", 40 | "../%{IncludeDir.GLFW}", 41 | "../%{IncludeDir.Freetype}", 42 | "../%{IncludeDir.Libclang}", 43 | "../%{IncludeDir.CppUtils}" 44 | } 45 | 46 | links { 47 | "CocoaEngine", 48 | "ImGui", 49 | "GLFW", 50 | "opengl32.lib", 51 | "Glad", 52 | "Box2D", 53 | "Freetype" 54 | } 55 | 56 | defines { 57 | "_CRT_SECURE_NO_WARNINGS", 58 | "_GABE_CPP_UTILS_IMPORT_DLL" 59 | } 60 | 61 | filter { "system:windows", "configurations:Debug" } 62 | buildoptions "/MDd" 63 | defines { "COCOA_TEST" } 64 | 65 | filter { "system:windows", "configurations:Release" } 66 | buildoptions "/MD" 67 | 68 | filter "system:windows" 69 | systemversion "latest" 70 | 71 | postbuildcommands { 72 | "xcopy /s /e /q /y /i \"$(SolutionDir)\\%{prj.name}\\assets\" \"$(OutDir)\\assets\" > nul", 73 | "copy /y \"$(SolutionDir)\\vendor\\premake\\premake5.exe\" \"$(OutDir)\\premake5.exe\"", 74 | "copy /y \"$(SolutionDir)\\CocoaEngine\\vendor\\imguiVendor\\bin\\%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}\\ImGui\\ImGui.dll\" \"$(OutDir)\\ImGui.dll\"", 75 | "copy /y \"$(SolutionDir)\\CocoaEngine\\vendor\\imguiVendor\\bin\\%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}\\ImGui\\ImGui.lib\" \"$(OutDir)\\ImGui.lib\"", 76 | "copy /y \"$(SolutionDir)\\CocoaEngine\\vendor\\imguiVendor\\bin\\%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}\\ImGui\\ImGui.pdb\" \"$(OutDir)\\ImGui.pdb\"", 77 | "rmdir /s /q \"$(SolutionDir)\\x64" 78 | } 79 | 80 | defines { 81 | "_COCOA_PLATFORM_WINDOWS" 82 | } 83 | 84 | filter "configurations:Debug" 85 | defines { 86 | "_COCOA_DEBUG", 87 | "_COCOA_ENABLE_ASSERTS" 88 | } 89 | runtime "Debug" 90 | symbols "on" 91 | 92 | 93 | filter "configurations:Release" 94 | defines "_COCOA_RELEASE" 95 | runtime "Release" 96 | optimize "on" 97 | 98 | 99 | filter "configurations:Dist" 100 | defines "_COCOA_DIST" 101 | runtime "Release" 102 | optimize "on" -------------------------------------------------------------------------------- /CocoaEngine/Cocoa.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "cocoa/core/Application.h" 4 | 5 | #include "cocoa/commands/CommandHistory.h" 6 | #include "cocoa/commands/ChangeVec3Command.h" 7 | #include "cocoa/commands/ChangeVec4Command.h" 8 | 9 | #include "cocoa/renderer/DebugDraw.h" 10 | 11 | #include "cocoa/util/Settings.h" 12 | 13 | // ----------------Events----------------------- 14 | #include "cocoa/events/Event.h" 15 | #include "cocoa/events/KeyEvent.h" 16 | #include "cocoa/events/MouseEvent.h" 17 | #include "cocoa/events/WindowEvent.h" 18 | #include "cocoa/events/Input.h" 19 | // --------------------------------------------- 20 | 21 | // ------------Entry Point---------------------- 22 | #include "cocoa/core/EntryPoint.h" 23 | // --------------------------------------------- -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/commands/CommandHistory.cpp: -------------------------------------------------------------------------------- 1 | #include "cocoa/commands/CommandHistory.h" 2 | 3 | namespace Cocoa 4 | { 5 | ICommand* CommandHistory::mCommands[1000] = {}; 6 | int CommandHistory::mCommandSize = 0; 7 | int CommandHistory::mCommandPtr = 0; 8 | 9 | void CommandHistory::addCommand(ICommand* cmd) 10 | { 11 | cmd->execute(); 12 | 13 | if (mCommandPtr < mCommandSize - 1) 14 | { 15 | for (int i = mCommandSize - 1; i > mCommandPtr; i--) 16 | { 17 | delete mCommands[i]; 18 | } 19 | mCommandSize = mCommandPtr + 1; 20 | } 21 | 22 | mCommands[mCommandSize] = cmd; 23 | mCommandSize++; 24 | 25 | if (mCommandSize > 1 && mCommands[mCommandSize - 1]->canMerge() && mCommands[mCommandSize - 2]->canMerge()) 26 | { 27 | if (mCommands[mCommandSize - 1]->mergeWith(mCommands[mCommandSize - 2])) 28 | { 29 | delete mCommands[mCommandSize - 1]; 30 | mCommandSize--; 31 | } 32 | } 33 | 34 | mCommandPtr = mCommandSize - 1; 35 | } 36 | 37 | void CommandHistory::setNoMergeMostRecent() 38 | { 39 | if (mCommandSize - 1 >= 0) 40 | { 41 | mCommands[mCommandSize - 1]->setNoMerge(); 42 | } 43 | } 44 | 45 | void CommandHistory::undo() 46 | { 47 | if (mCommandPtr >= 0) 48 | { 49 | mCommands[mCommandPtr]->undo(); 50 | mCommandPtr--; 51 | } 52 | } 53 | 54 | void CommandHistory::redo() 55 | { 56 | int redoCommand = mCommandPtr + 1; 57 | if (redoCommand < mCommandSize && redoCommand >= 0) 58 | { 59 | mCommands[redoCommand]->execute(); 60 | mCommandPtr++; 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/components/Spritesheet.cpp: -------------------------------------------------------------------------------- 1 | #include "cocoa/components/Spritesheet.h" 2 | #include "cocoa/core/AssetManager.h" 3 | 4 | namespace Cocoa 5 | { 6 | namespace NSpritesheet 7 | { 8 | Spritesheet createSpritesheet(Handle textureHandle, int spriteWidth, int spriteHeight, int numSprites, int spacing) 9 | { 10 | Spritesheet res; 11 | res.textureHandle = textureHandle; 12 | const Texture& texture = AssetManager::getTexture(textureHandle.assetId); 13 | 14 | // NOTE: If you don't reserve the space before hand, when the vector grows it will 15 | // change the pointers it holds 16 | res.sprites.reserve(numSprites); 17 | 18 | int currentX = 0; 19 | int currentY = texture.height - spriteHeight; 20 | for (int i = 0; i < numSprites; i++) 21 | { 22 | float topY = (currentY + spriteHeight) / (float)texture.height; 23 | float rightX = (currentX + spriteWidth) / (float)texture.width; 24 | float leftX = currentX / (float)texture.width; 25 | float bottomY = currentY / (float)texture.height; 26 | 27 | Sprite sprite{ 28 | textureHandle, 29 | { 30 | {rightX, topY}, 31 | {rightX, bottomY}, 32 | {leftX, bottomY}, 33 | {leftX, topY} 34 | } 35 | }; 36 | res.sprites.push_back(sprite); 37 | 38 | currentX += spriteWidth + spacing; 39 | if (currentX >= texture.width) 40 | { 41 | currentX = 0; 42 | currentY -= spriteHeight + spacing; 43 | } 44 | } 45 | 46 | return res; 47 | } 48 | 49 | Sprite getSprite(const Spritesheet& spritesheet, int index) 50 | { 51 | Logger::Assert(index >= 0 && index < spritesheet.sprites.size(), "Index out of bounds exception."); 52 | return spritesheet.sprites[index]; 53 | } 54 | 55 | int size(const Spritesheet& spritesheet) 56 | { 57 | return (int)spritesheet.sprites.size(); 58 | } 59 | }; 60 | } -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/components/Tag.cpp: -------------------------------------------------------------------------------- 1 | #include "cocoa/components/Tag.h" 2 | #include "cocoa/util/JsonExtended.h" 3 | 4 | namespace Cocoa 5 | { 6 | namespace NTag 7 | { 8 | Tag createTag(const char* name, bool isHeapAllocated) 9 | { 10 | Tag res; 11 | res.name = name; 12 | res.size = strlen(name); 13 | res.isHeapAllocated = isHeapAllocated; 14 | return res; 15 | } 16 | 17 | void destroy(Tag& tag) 18 | { 19 | if (tag.isHeapAllocated) 20 | { 21 | FreeMem((void*)tag.name); 22 | tag.size = 0; 23 | tag.name = nullptr; 24 | } 25 | } 26 | 27 | void ImGui() 28 | { 29 | 30 | } 31 | 32 | void serialize(json& j, Entity entity, const Tag& tag) 33 | { 34 | int size = j["Components"].size(); 35 | j["Components"][size] = { 36 | {"Tag", { 37 | {"Entity", NEntity::getId(entity)}, 38 | {"Name", tag.name} 39 | }} 40 | }; 41 | } 42 | void deserialize(const json& j, Entity entity) 43 | { 44 | Tag tag = { "", false, false }; 45 | std::string tagName = j["Tag"]["Name"]; 46 | 47 | int tagNameSize = tagName.length(); 48 | if (tagNameSize > 0) 49 | { 50 | tag.name = (char*)AllocMem(sizeof(char) * (tagNameSize + 1)); 51 | memcpy((void*)tag.name, tagName.c_str(), sizeof(char) * (tagNameSize + 1)); 52 | tag.isHeapAllocated = true; 53 | tag.size = tagNameSize; 54 | } 55 | 56 | NEntity::addComponent(entity, tag); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/components/Transform.cpp: -------------------------------------------------------------------------------- 1 | #include "cocoa/components/Transform.h" 2 | #include "cocoa/util/CMath.h" 3 | 4 | namespace Cocoa 5 | { 6 | namespace Transform 7 | { 8 | // Internal Functions 9 | static TransformData Init(glm::vec3 position, glm::vec3 scale, glm::vec3 eulerRotation, Entity parent = NEntity::createNull()) 10 | { 11 | TransformData data; 12 | data.position = position; 13 | data.scale = scale; 14 | data.eulerRotation = eulerRotation; 15 | data.orientation = glm::toQuat(glm::orientate3(data.eulerRotation)); 16 | data.parent = parent; 17 | data.localPosition = glm::vec3(); 18 | data.localScale = glm::vec3(1, 1, 1); 19 | data.localEulerRotation = glm::vec3(); 20 | 21 | return data; 22 | } 23 | 24 | TransformData createTransform() 25 | { 26 | return Init(glm::vec3(0), glm::vec3(1), glm::vec3(0)); 27 | } 28 | 29 | TransformData createTransform(glm::vec3 position, glm::vec3 scale, glm::vec3 eulerRotation) 30 | { 31 | return Init(position, scale, eulerRotation); 32 | } 33 | 34 | void update(TransformData& data, float dt) 35 | { 36 | if (!NEntity::isNull(data.parent)) 37 | { 38 | // TODO: This logic is probably flawed because it assumes that the parent is updated before the child 39 | const TransformData& parentTransform = NEntity::getComponent(data.parent); 40 | data.position = parentTransform.position + data.localPosition; 41 | data.scale = parentTransform.scale + data.localScale; 42 | data.eulerRotation = parentTransform.eulerRotation + data.localEulerRotation; 43 | } 44 | 45 | data.modelMatrix = glm::translate(glm::mat4(1.0f), data.position); 46 | data.modelMatrix = data.modelMatrix * glm::toMat4(data.orientation); 47 | data.modelMatrix = glm::scale(data.modelMatrix, data.scale); 48 | } 49 | 50 | void serialize(json& j, Entity entity, const TransformData& transform) 51 | { 52 | json position = CMath::serialize("Position", transform.position); 53 | json scale = CMath::serialize("Scale", transform.scale); 54 | json rotation = CMath::serialize("Rotation", transform.eulerRotation); 55 | json localPos = CMath::serialize("LocalPosition", transform.localPosition); 56 | json localScale = CMath::serialize("LocalScale", transform.localScale); 57 | json localRotation = CMath::serialize("LocalRotation", transform.localEulerRotation); 58 | int size = j["Components"].size(); 59 | j["Components"][size] = { 60 | {"Transform", { 61 | {"Entity", NEntity::getId(entity)}, 62 | position, 63 | scale, 64 | rotation, 65 | {"Parent", NEntity::getId(transform.parent)}, 66 | localPos, 67 | localScale, 68 | localRotation 69 | }} 70 | }; 71 | } 72 | 73 | void deserialize(const json& j, Entity entity, Entity parent) 74 | { 75 | TransformData transform = createTransform(); 76 | transform.position = CMath::deserializeVec3(j["Transform"]["Position"]); 77 | transform.scale = CMath::deserializeVec3(j["Transform"]["Scale"]); 78 | transform.eulerRotation = CMath::deserializeVec3(j["Transform"]["Rotation"]); 79 | transform.parent = parent; 80 | transform.localPosition = CMath::deserializeVec3(j["Transform"]["LocalPosition"]); 81 | 82 | if (j["Transform"].contains("LocalScale")) 83 | { 84 | transform.localScale = CMath::deserializeVec3(j["Transform"]["LocalScale"]); 85 | } 86 | 87 | if (j["Transform"].contains("LocalRotation")) 88 | { 89 | transform.localEulerRotation = CMath::deserializeVec3(j["Transform"]["LocalRotation"]); 90 | } 91 | NEntity::addComponent(entity, transform); 92 | } 93 | 94 | void serialize(json& j, const TransformData& transform) 95 | { 96 | json position = CMath::serialize("Position", transform.position); 97 | json scale = CMath::serialize("Scale", transform.scale); 98 | json rotation = CMath::serialize("Rotation", transform.eulerRotation); 99 | json localPos = CMath::serialize("LocalPosition", transform.localPosition); 100 | int size = j["Components"].size(); 101 | j["Transform"] = { 102 | position, 103 | scale, 104 | rotation, 105 | {"Parent", NEntity::getId(transform.parent)}, 106 | localPos 107 | }; 108 | } 109 | 110 | void deserialize(const json& j, TransformData& transform) 111 | { 112 | transform.position = CMath::deserializeVec3(j["Transform"]["Position"]); 113 | transform.scale = CMath::deserializeVec3(j["Transform"]["Scale"]); 114 | transform.eulerRotation = CMath::deserializeVec3(j["Transform"]["Rotation"]); 115 | transform.localPosition = CMath::deserializeVec3(j["Transform"]["LocalPosition"]); 116 | } 117 | } 118 | } -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/core/Application.cpp: -------------------------------------------------------------------------------- 1 | #include "externalLibs.h" 2 | #include "cocoa/core/Core.h" 3 | 4 | #include "cocoa/core/Application.h" 5 | 6 | namespace Cocoa 7 | { 8 | // Stub methods 9 | static void AppOnUpdate(SceneData& scene, float dt) { } 10 | static void AppOnAttach(SceneData& scene) { } 11 | static void AppOnRender(SceneData& scene) { } 12 | static void AppOnEvent(SceneData& scene, Event& e) { } 13 | 14 | Application::Application() 15 | { 16 | mRunning = true; 17 | 18 | Logger::Info("Initializing GLAD functions in DLL."); 19 | mWindow = CWindow::create(1920, 1080, "Test Window"); 20 | sInstance = this; 21 | 22 | mWindow->setEventCallback(std::bind(&Application::onEvent, this, std::placeholders::_1)); 23 | } 24 | 25 | void Application::run() 26 | { 27 | if (!mAppData.appOnAttach) { mAppData.appOnAttach = AppOnAttach; } 28 | if (!mAppData.appOnEvent) { mAppData.appOnEvent = AppOnEvent; } 29 | if (!mAppData.appOnRender) { mAppData.appOnRender = AppOnRender; } 30 | if (!mAppData.appOnUpdate) { mAppData.appOnUpdate = AppOnUpdate; } 31 | 32 | mAppData.appOnAttach(mCurrentScene); 33 | 34 | while (mRunning) 35 | { 36 | float time = (float)glfwGetTime(); 37 | float dt = time - mLastFrameTime; 38 | mLastFrameTime = time; 39 | 40 | beginFrame(); 41 | mAppData.appOnUpdate(mCurrentScene, dt); 42 | mAppData.appOnRender(mCurrentScene); 43 | endFrame(); 44 | 45 | mWindow->onUpdate(); 46 | mWindow->render(); 47 | } 48 | 49 | // TODO: Should this be a thing? (probably, add support at some point...) 50 | //for (Layer* layer : m_Layers) 51 | //{ 52 | // layer->OnDetach(); 53 | //} 54 | 55 | mWindow->destroy(); 56 | } 57 | 58 | bool Application::onWindowClose(WindowCloseEvent& e) 59 | { 60 | mRunning = false; 61 | return true; 62 | } 63 | 64 | void Application::onEvent(Event& e) 65 | { 66 | EventDispatcher dispatcher(e); 67 | dispatcher.dispatch(std::bind(&Application::onWindowClose, this, std::placeholders::_1)); 68 | 69 | mAppData.appOnEvent(mCurrentScene, e); 70 | } 71 | 72 | void Application::stop() 73 | { 74 | mRunning = false; 75 | } 76 | 77 | CWindow* Application::getWindow() const 78 | { 79 | return mWindow; 80 | } 81 | 82 | Application* Application::sInstance = nullptr; 83 | Application* Application::get() 84 | { 85 | if (!sInstance) 86 | { 87 | Logger::Error("Cannot get application. It is nullptr."); 88 | } 89 | return sInstance; 90 | } 91 | } -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/core/Entity.cpp: -------------------------------------------------------------------------------- 1 | #include "cocoa/core/Entity.h" 2 | #include "cocoa/core/Application.h" 3 | #include "cocoa/scenes/Scene.h" 4 | 5 | namespace Cocoa 6 | { 7 | namespace NEntity 8 | { 9 | // Internal Variables 10 | static Entity Null = { entt::null }; 11 | static SceneData* m_Scene = nullptr; 12 | 13 | Entity CreateEntity(SceneData* scene) 14 | { 15 | return Scene::createEntity(*scene); 16 | } 17 | 18 | Entity createEntity(entt::entity raw) 19 | { 20 | return Entity{ raw }; 21 | } 22 | 23 | void setScene(SceneData* scene) 24 | { 25 | m_Scene = scene; 26 | } 27 | 28 | SceneData* getScene() 29 | { 30 | return m_Scene; 31 | } 32 | 33 | Entity createNull() 34 | { 35 | return Null; 36 | } 37 | } 38 | 39 | bool operator==(const Entity& a, const Entity& b) 40 | { 41 | return a.handle == b.handle; 42 | } 43 | 44 | bool operator==(Entity& a, Entity& b) 45 | { 46 | return a.handle == b.handle; 47 | } 48 | 49 | bool operator!=(const Entity& a, const Entity& b) 50 | { 51 | return !(a == b); 52 | } 53 | 54 | bool operator!=(Entity& a, Entity& b) 55 | { 56 | return !(a == b); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/core/StbTruetypeImpl.cpp: -------------------------------------------------------------------------------- 1 | #define STB_TRUETYPE_IMPLEMENTATION 2 | #include "stb/stb_truetype.h" 3 | #undef STB_TRUETYPE_IMPLEMENTATION 4 | 5 | #define STB_IMAGE_WRITE_IMPLEMENTATION 6 | #include "stb/stb_image_write.h" 7 | #undef STB_IMAGE_WRITE_IMPLEMENTATION 8 | 9 | #define STB_IMAGE_IMPLEMENTATION 10 | #include 11 | #undef STB_IMAGE_IMPLEMENTATION 12 | 13 | #define GABE_CPP_UTILS_IMPL 14 | #include 15 | #undef GABE_CPP_UTILS_IMPL -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/events/Input.cpp: -------------------------------------------------------------------------------- 1 | #include "externalLibs.h" 2 | #include "cocoa/core/Core.h" 3 | 4 | #include "cocoa/events/Input.h" 5 | #include "cocoa/core/Application.h" 6 | #include "cocoa/renderer/Camera.h" 7 | #include "cocoa/scenes/Scene.h" 8 | #include "cocoa/scenes/SceneData.h" 9 | 10 | namespace Cocoa 11 | { 12 | bool Input::sInitialized = false; 13 | bool Input::sKeyPressed[349]{ }; 14 | bool Input::sMouseButtonPressed[3]{ }; 15 | float Input::sXPos = 0.0f; 16 | float Input::sYPos = 0.0f; 17 | float Input::sScrollX = 0.0f; 18 | float Input::sScrollY = 0.0f; 19 | glm::vec2 Input::sGameViewPos{ 0, 0 }; 20 | glm::vec2 Input::sGameViewSize{ 0, 0 }; 21 | glm::vec2 Input::sGameViewMousePos{ 0, 0 }; 22 | 23 | void Input::init() 24 | { 25 | Logger::Assert(!sInitialized, "Input already initialized."); 26 | sInitialized = true; 27 | const glm::vec2& windowSize = Application::get()->getWindow()->getSize(); 28 | } 29 | 30 | void Input::keyCallback(int key, int scanCode, int action, int mods) 31 | { 32 | sKeyPressed[key] = (action == COCOA_PRESS || action == COCOA_REPEAT) ? true : false; 33 | } 34 | 35 | bool Input::keyPressed(int keyCode) 36 | { 37 | if (keyCode >= 0 && keyCode < 350) 38 | { 39 | return sKeyPressed[keyCode]; 40 | } 41 | return false; 42 | } 43 | 44 | void Input::mouseButtonCallback(int button, int action, int mods) 45 | { 46 | sMouseButtonPressed[button] = action == COCOA_PRESS ? true : false; 47 | } 48 | 49 | bool Input::mouseButtonPressed(int mouseButton) 50 | { 51 | if (mouseButton >= 0 && mouseButton < 3) 52 | { 53 | return sMouseButtonPressed[mouseButton]; 54 | } 55 | return false; 56 | } 57 | 58 | void Input::cursorCallback(double xPos, double yPos) 59 | { 60 | sXPos = (float)xPos; 61 | sYPos = (float)yPos; 62 | } 63 | 64 | float Input::mouseX() 65 | { 66 | return sXPos; 67 | } 68 | 69 | float Input::mouseY() 70 | { 71 | return sYPos; 72 | } 73 | 74 | float Input::orthoMouseX(const Camera& camera) 75 | { 76 | float currentX = mouseX() - sGameViewPos.x; 77 | currentX = (currentX / sGameViewSize.x) * 2.0f - 1.0f; 78 | glm::vec4 tmp = glm::vec4(currentX, 0.0f, 0.0f, 1.0f); 79 | tmp = camera.inverseView * camera.inverseProjection * tmp; 80 | 81 | return tmp.x; 82 | } 83 | 84 | float Input::orthoMouseY(const Camera& camera) 85 | { 86 | float currentY = sGameViewPos.y - mouseY(); 87 | currentY = (currentY / sGameViewSize.y) * 2.0f - 1.0f; 88 | glm::vec4 tmp = glm::vec4(0.0f, currentY, 0.0f, 1.0f); 89 | tmp = camera.inverseView * camera.inverseProjection * tmp; 90 | 91 | return tmp.y; 92 | } 93 | 94 | glm::vec2 Input::screenToOrtho(const Camera& camera) 95 | { 96 | glm::vec4 tmp{ sGameViewMousePos.x, sGameViewMousePos.y, 0, 1 }; 97 | 98 | tmp.x = (tmp.x / sGameViewSize.x) * 2.0f - 1.0f; 99 | tmp.y = -((tmp.y / sGameViewSize.y) * 2.0f - 1.0f); 100 | tmp = camera.inverseView * camera.inverseProjection * tmp; 101 | 102 | return glm::vec2{ tmp.x, tmp.y }; 103 | } 104 | 105 | glm::vec2 Input::normalizedMousePos() 106 | { 107 | glm::vec4 tmp{ sGameViewMousePos.x, sGameViewSize.y - sGameViewMousePos.y, 0, 1 }; 108 | 109 | tmp.x = (tmp.x / sGameViewSize.x); 110 | tmp.y = (tmp.y / sGameViewSize.y); 111 | 112 | return glm::vec2{ tmp.x, tmp.y }; 113 | } 114 | 115 | void Input::scrollCallback(double xOffset, double yOffset) 116 | { 117 | sScrollX = (float)xOffset; 118 | sScrollY = -(float)yOffset; 119 | } 120 | 121 | float Input::scrollX() 122 | { 123 | return sScrollX; 124 | } 125 | 126 | float Input::scrollY() 127 | { 128 | return sScrollY; 129 | } 130 | 131 | void Input::endFrame() 132 | { 133 | sScrollX = 0; 134 | sScrollY = 0; 135 | } 136 | 137 | glm::vec2 Input::mousePos() 138 | { 139 | return glm::vec2{ sXPos, sYPos }; 140 | } 141 | 142 | void Input::setGameViewPos(const glm::vec2& position) 143 | { 144 | sGameViewPos.x = position.x; 145 | sGameViewPos.y = position.y; 146 | } 147 | 148 | void Input::setGameViewSize(const glm::vec2& size) 149 | { 150 | sGameViewSize.x = size.x; 151 | sGameViewSize.y = size.y; 152 | } 153 | 154 | void Input::setGameViewMousePos(const glm::vec2& mousePos) 155 | { 156 | sGameViewMousePos.x = mousePos.x; 157 | sGameViewMousePos.y = mousePos.y; 158 | } 159 | } -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/events/KeyEvent.cpp: -------------------------------------------------------------------------------- 1 | #include "externalLibs.h" 2 | 3 | #include "cocoa/events/KeyEvent.h" 4 | 5 | namespace Cocoa 6 | { 7 | // ============================================================ 8 | // Base 9 | // ============================================================ 10 | KeyEvent::KeyEvent(int keycode) 11 | : mKeyCode(keycode) 12 | { 13 | } 14 | 15 | int KeyEvent::getKeyCode() const 16 | { 17 | return mKeyCode; 18 | } 19 | 20 | EVENT_CLASS_CATEGORY_IMPL(EventCategoryKeyboard | EventCategoryInput, KeyEvent) 21 | 22 | // ============================================================ 23 | // KeyPressed 24 | // ============================================================ 25 | KeyPressedEvent::KeyPressedEvent(int keycode, int repeatCount) 26 | : KeyEvent(keycode), mRepeatCount(repeatCount) 27 | { 28 | } 29 | 30 | int KeyPressedEvent::getRepeatCount() const 31 | { 32 | return mRepeatCount; 33 | } 34 | 35 | std::string KeyPressedEvent::toString() const 36 | { 37 | std::stringstream ss; 38 | ss << "KeyPressedEvent: " << mKeyCode << "(" << mRepeatCount << ")"; 39 | return ss.str(); 40 | } 41 | 42 | EVENT_CLASS_TYPE_IMPL(KeyPressed, KeyPressedEvent) 43 | 44 | // ============================================================ 45 | // KeyReleased 46 | // ============================================================ 47 | KeyReleasedEvent::KeyReleasedEvent(int keycode) 48 | : KeyEvent(keycode) 49 | { 50 | } 51 | 52 | std::string KeyReleasedEvent::toString() const 53 | { 54 | std::stringstream ss; 55 | ss << "KeyReleasedEvent: " << mKeyCode; 56 | return ss.str(); 57 | } 58 | 59 | EVENT_CLASS_TYPE_IMPL(KeyReleased, KeyReleasedEvent) 60 | 61 | // ============================================================ 62 | // KeyTyped 63 | // ============================================================ 64 | KeyTypedEvent::KeyTypedEvent(int keycode) 65 | : KeyEvent(keycode) 66 | { 67 | } 68 | 69 | std::string KeyTypedEvent::toString() const 70 | { 71 | std::stringstream ss; 72 | ss << "KeyTypedEvent: " << mKeyCode; 73 | return ss.str(); 74 | } 75 | 76 | EVENT_CLASS_TYPE_IMPL(KeyTyped, KeyTypedEvent) 77 | } -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/events/MouseEvent.cpp: -------------------------------------------------------------------------------- 1 | #include "externalLibs.h" 2 | 3 | #include "cocoa/events/MouseEvent.h" 4 | 5 | namespace Cocoa 6 | { 7 | // =============================================================== 8 | // MouseMovedEvent 9 | // =============================================================== 10 | MouseMovedEvent::MouseMovedEvent(float x, float y) 11 | : mMouseX(x), mMouseY(y) 12 | { 13 | } 14 | 15 | float MouseMovedEvent::getX() const 16 | { 17 | return mMouseX; 18 | } 19 | 20 | float MouseMovedEvent::getY() const 21 | { 22 | return mMouseY; 23 | } 24 | 25 | std::string MouseMovedEvent::toString() const 26 | { 27 | std::stringstream ss; 28 | ss << "MouseMovedEvent: " << mMouseX << ", " << mMouseY; 29 | return ss.str(); 30 | } 31 | 32 | EVENT_CLASS_TYPE_IMPL(MouseMoved, MouseMovedEvent) 33 | EVENT_CLASS_CATEGORY_IMPL(EventCategoryMouse | EventCategoryInput, MouseMovedEvent) 34 | 35 | // =============================================================== 36 | // MouseScrolledEvent 37 | // =============================================================== 38 | MouseScrolledEvent::MouseScrolledEvent(float xOffset, float yOffset) 39 | : mXOffset(xOffset), mYOffset(yOffset) 40 | { 41 | } 42 | 43 | float MouseScrolledEvent::getXOffset() const 44 | { 45 | return mXOffset; 46 | } 47 | 48 | float MouseScrolledEvent::getYOffset() const 49 | { 50 | return mYOffset; 51 | } 52 | 53 | std::string MouseScrolledEvent::toString() const 54 | { 55 | std::stringstream ss; 56 | ss << "MouseScrolledEvent: " << mXOffset << ", " << mYOffset; 57 | return ss.str(); 58 | } 59 | 60 | EVENT_CLASS_TYPE_IMPL(MouseScrolled, MouseScrolledEvent) 61 | EVENT_CLASS_CATEGORY_IMPL(EventCategoryMouse | EventCategoryInput, MouseScrolledEvent) 62 | 63 | // =============================================================== 64 | // Base 65 | // =============================================================== 66 | MouseButtonEvent::MouseButtonEvent(int button) 67 | : mButton(button) 68 | { 69 | } 70 | 71 | int MouseButtonEvent::getMouseButton() const 72 | { 73 | return mButton; 74 | } 75 | 76 | EVENT_CLASS_CATEGORY_IMPL(EventCategoryMouse | EventCategoryInput, MouseButtonEvent) 77 | 78 | // =============================================================== 79 | // MouseButtonPressedEvent 80 | // =============================================================== 81 | MouseButtonPressedEvent::MouseButtonPressedEvent(int button) 82 | : MouseButtonEvent(button) 83 | { 84 | } 85 | 86 | std::string MouseButtonPressedEvent::toString() const 87 | { 88 | std::stringstream ss; 89 | ss << "MouseButtonPressedEvent: " << mButton; 90 | return ss.str(); 91 | } 92 | 93 | EVENT_CLASS_TYPE_IMPL(MouseButtonPressed, MouseButtonPressedEvent) 94 | 95 | // =============================================================== 96 | // MouseButtonReleasedEvent 97 | // =============================================================== 98 | MouseButtonReleasedEvent::MouseButtonReleasedEvent(int button) 99 | : MouseButtonEvent(button) 100 | { 101 | } 102 | 103 | std::string MouseButtonReleasedEvent::toString() const 104 | { 105 | std::stringstream ss; 106 | ss << "MouseButtonPressedEvent: " << mButton; 107 | return ss.str(); 108 | } 109 | 110 | EVENT_CLASS_TYPE_IMPL(MouseButtonReleased, MouseButtonReleasedEvent) 111 | } -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/events/WindowEvent.cpp: -------------------------------------------------------------------------------- 1 | #include "externalLibs.h" 2 | 3 | #include "cocoa/events/WindowEvent.h" 4 | 5 | namespace Cocoa 6 | { 7 | WindowResizeEvent::WindowResizeEvent(uint32 width, uint32 height) 8 | : m_Width(width), m_Height(height) 9 | { 10 | } 11 | 12 | uint32 WindowResizeEvent::getWidth() const 13 | { 14 | return m_Width; 15 | } 16 | 17 | uint32 WindowResizeEvent::getHeight() const 18 | { 19 | return m_Height; 20 | } 21 | 22 | std::string WindowResizeEvent::toString() const 23 | { 24 | std::stringstream ss; 25 | ss << "WindowResizeEvent: " << m_Width << ", " << m_Height; 26 | return ss.str(); 27 | } 28 | 29 | EVENT_CLASS_TYPE_IMPL(WindowResize, WindowResizeEvent) 30 | EVENT_CLASS_CATEGORY_IMPL(EventCategoryApplication, WindowResizeEvent) 31 | 32 | WindowCloseEvent::WindowCloseEvent() 33 | { 34 | 35 | } 36 | 37 | EVENT_CLASS_TYPE_IMPL(WindowClose, WindowCloseEvent) 38 | EVENT_CLASS_CATEGORY_IMPL(EventCategoryApplication, WindowCloseEvent) 39 | } -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/physics2d/ContactListener.cpp: -------------------------------------------------------------------------------- 1 | #include "cocoa/physics2d/ContactListener.h" 2 | #include "cocoa/core/Entity.h" 3 | #include "cocoa/systems/ScriptSystem.h" 4 | 5 | namespace Cocoa 6 | { 7 | void ContactListener::BeginContact(b2Contact* contact) 8 | { 9 | entt::entity* rawHandleARef = (entt::entity*)contact->GetFixtureA()->GetBody()->GetUserData(); 10 | entt::entity* rawHandleBRef = (entt::entity*)contact->GetFixtureB()->GetBody()->GetUserData(); 11 | ScriptSystem::notifyBeginContact(NEntity::createEntity(*rawHandleARef), NEntity::createEntity(*rawHandleBRef)); 12 | } 13 | 14 | void ContactListener::EndContact(b2Contact* contact) 15 | { 16 | // TODO: See why this throws nullptr exception on scene stop 17 | void* userDataA = contact->GetFixtureA()->GetBody()->GetUserData(); 18 | void* userDataB = contact->GetFixtureB()->GetBody()->GetUserData(); 19 | if (userDataA && userDataB) 20 | { 21 | entt::entity* rawHandleARef = (entt::entity*)userDataA; 22 | entt::entity* rawHandleBRef = (entt::entity*)userDataB; 23 | ScriptSystem::notifyEndContact(NEntity::createEntity(*rawHandleARef), NEntity::createEntity(*rawHandleBRef)); 24 | } 25 | } 26 | 27 | void ContactListener::PreSolve(b2Contact* contact, const b2Manifold* oldManifold) 28 | { 29 | // TODO: Implement me 30 | } 31 | 32 | void ContactListener::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) 33 | { 34 | // TODO: Implement me 35 | } 36 | } -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/renderer/Fonts/Font.cpp: -------------------------------------------------------------------------------- 1 | #include "cocoa/renderer/fonts/Font.h"" 2 | #include "cocoa/renderer/fonts/FontUtil.h" 3 | #include "cocoa/util/JsonExtended.h" 4 | 5 | #undef CreateFont; 6 | 7 | namespace Cocoa 8 | { 9 | static CharInfo mNullCharacter = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 10 | static Font mNullFontObj; 11 | 12 | Font Font::createFont() 13 | { 14 | Font res; 15 | res.isNull = true; 16 | res.isDefault = false; 17 | return res; 18 | } 19 | 20 | Font Font::createFont(std::filesystem::path& resourcePath, bool isDefault) 21 | { 22 | Font res; 23 | res.isDefault = isDefault; 24 | res.path = resourcePath; 25 | return res; 26 | } 27 | 28 | Font Font::nullFont() 29 | { 30 | return mNullFontObj; 31 | } 32 | 33 | void Font::free() const 34 | { 35 | FreeMem(characterMap); 36 | } 37 | 38 | const CharInfo& Font::getCharacterInfo(int codepoint) const 39 | { 40 | if (codepoint < characterMapSize && codepoint >= 0) 41 | { 42 | return characterMap[codepoint]; 43 | } 44 | else 45 | { 46 | return mNullCharacter; 47 | } 48 | } 49 | 50 | void Font::generateSdf(const std::filesystem::path& fontFile, int fontSize, const std::filesystem::path& outputFile, int glyphRangeStart, int glyphRangeEnd, int padding, int upscaleResolution) 51 | { 52 | glyphRangeStart = glyphRangeStart; 53 | glyphRangeEnd = glyphRangeEnd; 54 | characterMap = (CharInfo*)AllocMem(sizeof(CharInfo) * (glyphRangeEnd - glyphRangeStart)); 55 | characterMapSize = glyphRangeEnd - glyphRangeStart; 56 | FontUtil::createSdfFontTexture(fontFile, fontSize, characterMap, (glyphRangeEnd - glyphRangeStart), outputFile, padding, upscaleResolution, glyphRangeStart); 57 | } 58 | 59 | json Font::serialize() const 60 | { 61 | json res; 62 | res["CharacterMapSize"] = characterMapSize; 63 | for (int i = 0; i < characterMapSize; i++) 64 | { 65 | const CharInfo& charInfo = characterMap[i]; 66 | res["CharacterMap"][std::to_string(i)] = { 67 | {"ux0", charInfo.ux0}, 68 | {"uy0", charInfo.uy0}, 69 | {"ux1", charInfo.ux1}, 70 | {"uy1", charInfo.uy1}, 71 | {"advance", charInfo.advance}, 72 | {"bearingX", charInfo.bearingX}, 73 | {"bearingY", charInfo.bearingY}, 74 | {"chScaleX", charInfo.chScaleX}, 75 | {"chScaleY", charInfo.chScaleY} 76 | }; 77 | } 78 | 79 | res["FontTextureId"] = fontTexture.assetId; 80 | res["GlyphRangeStart"] = glyphRangeStart; 81 | res["GlyphRangeEnd"] = glyphRangeEnd; 82 | res["Filepath"] = path.string(); 83 | return res; 84 | } 85 | 86 | void Font::deserialize(const json& j) 87 | { 88 | JsonExtended::assignIfNotNull(j, "CharacterMapSize", characterMapSize); 89 | 90 | characterMap = (CharInfo*)AllocMem(sizeof(CharInfo) * characterMapSize); 91 | for (int i = 0; i < characterMapSize; i++) 92 | { 93 | float ux0, uy0, ux1, uy1, advance, bearingX, bearingY, chScaleX, chScaleY; 94 | if (j.contains("CharacterMap") && j["CharacterMap"].contains(std::to_string(i))) 95 | { 96 | json subJ = j["CharacterMap"][std::to_string(i)]; 97 | JsonExtended::assignIfNotNull(subJ, "ux0", ux0); 98 | JsonExtended::assignIfNotNull(subJ, "uy0", uy0); 99 | JsonExtended::assignIfNotNull(subJ, "ux1", ux1); 100 | JsonExtended::assignIfNotNull(subJ, "uy1", uy1); 101 | JsonExtended::assignIfNotNull(subJ, "advance", advance); 102 | JsonExtended::assignIfNotNull(subJ, "bearingX", bearingX); 103 | JsonExtended::assignIfNotNull(subJ, "bearingY", bearingY); 104 | JsonExtended::assignIfNotNull(subJ, "chScaleX", chScaleX); 105 | JsonExtended::assignIfNotNull(subJ, "chScaleY", chScaleY); 106 | characterMap[i] = { 107 | ux0, uy0, 108 | ux1, uy1, 109 | advance, 110 | bearingX, bearingY, 111 | chScaleX, chScaleY 112 | }; 113 | } 114 | } 115 | 116 | JsonExtended::assignIfNotNull(j, "FontTextureId", fontTexture.assetId); 117 | JsonExtended::assignIfNotNull(j, "GlyphRangeStart", glyphRangeStart); 118 | JsonExtended::assignIfNotNull(j, "GlyphRangeEnd", glyphRangeEnd); 119 | JsonExtended::assignIfNotNull(j, "Filepath", path); 120 | } 121 | } -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/renderer/Line2D.cpp: -------------------------------------------------------------------------------- 1 | #include "cocoa/renderer/Line2D.h" 2 | #include "cocoa/util/CMath.h" 3 | 4 | namespace Cocoa 5 | { 6 | namespace NLine2D 7 | { 8 | Line2D create(glm::vec2 from, glm::vec2 to, glm::vec3 color, float stroke, int lifetime, bool onTop) 9 | { 10 | Line2D res; 11 | glm::vec2 line = from - to; 12 | glm::vec2 normal = glm::vec2(line.y, -line.x); 13 | normal = glm::normalize(normal); 14 | 15 | float halfStroke = stroke / 2.0f; 16 | res.vertices[0] = to - (normal * halfStroke); 17 | res.vertices[1] = to + (normal * halfStroke); 18 | res.vertices[2] = res.vertices[1] + line; 19 | res.vertices[3] = res.vertices[0] + line; 20 | #if _COCOA_DEBUG 21 | glm::vec2 testVec = res.vertices[1] - res.vertices[0]; 22 | float testLength = glm::length(testVec); 23 | if (!CMath::compare(stroke, testLength, 0.001f)) 24 | { 25 | Logger::Warning("Invalid result when computing line2D position. Stroke width does not match. Stroke %2.3f, Actual Length: %2.3f", stroke, testLength); 26 | } 27 | #endif 28 | 29 | res.onTop = onTop; 30 | res.lifetime = lifetime; 31 | res.color = color; 32 | return res; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/systems/TransformSystem.cpp: -------------------------------------------------------------------------------- 1 | #include "cocoa/systems/TransformSystem.h" 2 | #include "cocoa/components/Transform.h" 3 | #include "cocoa/components/Tag.h" 4 | 5 | namespace Cocoa 6 | { 7 | namespace TransformSystem 8 | { 9 | void update(SceneData& scene, float dt) 10 | { 11 | auto view = scene.registry.view(); 12 | for (entt::entity rawEntity : view) 13 | { 14 | Entity entity = NEntity::createEntity(rawEntity); 15 | TransformData& transform = NEntity::getComponent(entity); 16 | Transform::update(transform, dt); 17 | } 18 | } 19 | 20 | void destroy(SceneData& scene) 21 | { 22 | auto view = scene.registry.view(); 23 | for (entt::entity rawEntity : view) 24 | { 25 | Entity entity = NEntity::createEntity(rawEntity); 26 | Tag& tag = NEntity::getComponent(entity); 27 | NTag::destroy(tag); 28 | } 29 | } 30 | 31 | void deleteEntity(Entity entity) 32 | { 33 | if (NEntity::hasComponent(entity)) 34 | { 35 | Tag& tag = NEntity::getComponent(entity); 36 | NTag::destroy(tag); 37 | } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/util/JsonExtended.cpp: -------------------------------------------------------------------------------- 1 | #include "cocoa/util/JsonExtended.h" 2 | #include "cocoa/util/CMath.h" 3 | 4 | namespace Cocoa 5 | { 6 | void JsonExtended::assignIfNotNull(const json& j, const char* property, glm::vec4& vector) 7 | { 8 | if (j.contains(property)) 9 | { 10 | bool success = true; 11 | glm::vec4 tmp = CMath::deserializeVec4(j[property], success); 12 | if (success) 13 | { 14 | vector = tmp; 15 | } 16 | } 17 | } 18 | 19 | void JsonExtended::assignIfNotNull(const json& j, const char* property, glm::vec3& vector) 20 | { 21 | if (j.contains(property)) 22 | { 23 | bool success = true; 24 | glm::vec3 tmp = CMath::deserializeVec3(j[property], success); 25 | if (success) 26 | { 27 | vector = tmp; 28 | } 29 | } 30 | } 31 | 32 | void JsonExtended::assignIfNotNull(const json& j, const char* property, glm::vec2& vector) 33 | { 34 | if (j.contains(property)) 35 | { 36 | bool success = true; 37 | glm::vec2 tmp = CMath::deserializeVec2(j[property], success); 38 | if (success) 39 | { 40 | vector = tmp; 41 | } 42 | } 43 | } 44 | 45 | void JsonExtended::assignIfNotNull(const json& j, const char* property, uint8& value) 46 | { 47 | if (j.contains(property)) 48 | { 49 | value = j[property]; 50 | } 51 | } 52 | 53 | void JsonExtended::assignIfNotNull(const json& j, const char* property, uint16& value) 54 | { 55 | if (j.contains(property)) 56 | { 57 | value = j[property]; 58 | } 59 | } 60 | 61 | void JsonExtended::assignIfNotNull(const json& j, const char* property, uint32& value) 62 | { 63 | if (j.contains(property)) 64 | { 65 | value = j[property]; 66 | } 67 | } 68 | 69 | void JsonExtended::assignIfNotNull(const json& j, const char* property, int& value) 70 | { 71 | if (j.contains(property)) 72 | { 73 | value = j[property]; 74 | } 75 | } 76 | 77 | void JsonExtended::assignIfNotNull(const json& j, const char* property, float& value) 78 | { 79 | if (j.contains(property)) 80 | { 81 | value = j[property]; 82 | } 83 | } 84 | 85 | void JsonExtended::assignIfNotNull(const json& j, const char* property, bool& value) 86 | { 87 | if (j.contains(property)) 88 | { 89 | value = j[property]; 90 | } 91 | } 92 | 93 | void JsonExtended::assignIfNotNull(const json& j, const char* property, std::filesystem::path& path) 94 | { 95 | if (j.contains(property) && j[property].is_string()) 96 | { 97 | path = std::string(j[property]); 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /CocoaEngine/cpp/cocoa/util/Settings.cpp: -------------------------------------------------------------------------------- 1 | #include "cocoa/util/Settings.h" 2 | 3 | namespace Cocoa 4 | { 5 | namespace Settings 6 | { 7 | namespace General 8 | { 9 | // ======================================================================= 10 | // General Settings 11 | // ======================================================================= 12 | // TODO: This is a bit misleading because none of these defaults are actually ever used. See 'CocoaEditorApplication.cpp' to see how they 13 | // TODO: are overwritten 14 | extern std::filesystem::path imGuiConfigPath = "default.ini"; 15 | extern std::filesystem::path engineAssetsPath = "assets"; 16 | extern std::filesystem::path engineExeDirectory = ""; 17 | extern std::filesystem::path engineSourceDirectory = ""; 18 | extern std::filesystem::path currentScene = "New Scene.cocoa"; 19 | extern std::filesystem::path currentProject = "New Project.cprj"; 20 | extern std::filesystem::path stylesDirectory = "assets/styles"; 21 | extern std::filesystem::path workingDirectory = ""; 22 | extern std::filesystem::path editorSaveData = "EditorSaveData.json"; 23 | extern std::filesystem::path editorStyleData = "EditorStyle.json"; 24 | } 25 | 26 | namespace Physics2D 27 | { 28 | // ======================================================================= 29 | // Physics Settings 30 | // ======================================================================= 31 | extern int Physics2D::positionIterations = 3; 32 | extern int Physics2D::velocityIterations = 8; 33 | extern float Physics2D::timestep = 1.0f / 60.0f; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/commands/ChangeEnumCommand.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_CHANGE_ENUM_COMMAND_H 2 | #define COCOA_ENGINE_CHANGE_ENUM_COMMAND_H 3 | #include "cocoa/commands/ICommand.h" 4 | 5 | namespace Cocoa 6 | { 7 | template 8 | class ChangeEnumCommand final : public ICommand 9 | { 10 | public: 11 | ChangeEnumCommand(T& originalEnum, T newEnum) 12 | : mEnum(originalEnum), mNewEnum(newEnum), mOldEnum(static_cast(0)) 13 | { 14 | } 15 | 16 | void execute() override 17 | { 18 | mOldEnum = mEnum; 19 | mEnum = mNewEnum; 20 | } 21 | 22 | void undo() override 23 | { 24 | mEnum = mOldEnum; 25 | } 26 | 27 | bool mergeWith(ICommand* other) override 28 | { 29 | ChangeEnumCommand* changeEnumCommand = dynamic_cast*>(other); 30 | if (changeEnumCommand != nullptr) 31 | { 32 | if (&changeEnumCommand->mEnum == &this->mEnum) 33 | { 34 | changeEnumCommand->mNewEnum = this->mNewEnum; 35 | return true; 36 | } 37 | } 38 | 39 | return false; 40 | } 41 | 42 | 43 | private: 44 | T& mEnum; 45 | T mNewEnum; 46 | T mOldEnum; 47 | }; 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/commands/ChangeFloatCommand.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_CHANGE_FLOAT_COMMAND_H 2 | #define COCOA_ENGINE_CHANGE_FLOAT_COMMAND_H 3 | #include "cocoa/commands/ICommand.h" 4 | 5 | namespace Cocoa 6 | { 7 | class COCOA ChangeFloatCommand final : public ICommand 8 | { 9 | public: 10 | ChangeFloatCommand(float& originalFloat, float newFloat) 11 | : mFloat(originalFloat), mNewFloat(newFloat), mOldFloat(0) 12 | { 13 | } 14 | 15 | void execute() override 16 | { 17 | mOldFloat = mFloat; 18 | mFloat = mNewFloat; 19 | } 20 | 21 | void undo() override 22 | { 23 | mFloat = mOldFloat; 24 | } 25 | 26 | bool mergeWith(ICommand* other) override 27 | { 28 | ChangeFloatCommand* changeFloatCommand = dynamic_cast(other); 29 | if (changeFloatCommand != nullptr) 30 | { 31 | if (&changeFloatCommand->mFloat == &this->mFloat) 32 | { 33 | changeFloatCommand->mNewFloat = this->mNewFloat; 34 | return true; 35 | } 36 | } 37 | 38 | return false; 39 | } 40 | 41 | 42 | private: 43 | float& mFloat; 44 | float mNewFloat; 45 | float mOldFloat; 46 | }; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/commands/ChangeInt2Command.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_CHANGE_INT_COMMAND_2_H 2 | #define COCOA_ENGINE_CHANGE_INT_COMMAND_2_H 3 | #include "externalLibs.h" 4 | #include "cocoa/commands/ICommand.h" 5 | 6 | namespace Cocoa 7 | { 8 | class COCOA ChangeInt2Command final : public ICommand 9 | { 10 | public: 11 | ChangeInt2Command(glm::ivec2& originalVector, glm::ivec2& newVector) 12 | : mVector(originalVector), mNewVector(newVector), mOldVector(glm::vec2()) 13 | { 14 | } 15 | 16 | void execute() override 17 | { 18 | mOldVector = glm::ivec2(mVector); 19 | mVector.x = mNewVector.x; 20 | mVector.y = mNewVector.y; 21 | } 22 | 23 | void undo() override 24 | { 25 | mVector.x = mOldVector.x; 26 | mVector.y = mOldVector.y; 27 | } 28 | 29 | bool mergeWith(ICommand* other) override 30 | { 31 | ChangeInt2Command* changeInt2Command = dynamic_cast(other); 32 | if (changeInt2Command != nullptr) 33 | { 34 | if (&changeInt2Command->mVector == &this->mVector) 35 | { 36 | changeInt2Command->mNewVector = this->mNewVector; 37 | return true; 38 | } 39 | } 40 | 41 | return false; 42 | } 43 | 44 | 45 | private: 46 | glm::ivec2& mVector; 47 | glm::ivec2 mNewVector; 48 | glm::ivec2 mOldVector; 49 | }; 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/commands/ChangeIntCommand.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_CHANGE_INT_COMMAND_H 2 | #define COCOA_ENGINE_CHANGE_INT_COMMAND_H 3 | #include "cocoa/commands/ICommand.h" 4 | 5 | namespace Cocoa 6 | { 7 | class COCOA ChangeIntCommand final : public ICommand 8 | { 9 | public: 10 | ChangeIntCommand(int& originalInt, const int newInt) 11 | : mInt(originalInt), mNewInt(newInt), mOldInt(0) 12 | { 13 | } 14 | 15 | void execute() override 16 | { 17 | mOldInt = mInt; 18 | mInt = mNewInt; 19 | } 20 | 21 | void undo() override 22 | { 23 | mInt = mOldInt; 24 | } 25 | 26 | bool mergeWith(ICommand* other) override 27 | { 28 | ChangeIntCommand* changeIntCommand = dynamic_cast(other); 29 | if (changeIntCommand != nullptr) 30 | { 31 | if (&changeIntCommand->mInt == &this->mInt) 32 | { 33 | changeIntCommand->mNewInt = this->mNewInt; 34 | return true; 35 | } 36 | } 37 | 38 | return false; 39 | } 40 | 41 | 42 | private: 43 | int& mInt; 44 | int mNewInt; 45 | int mOldInt; 46 | }; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/commands/ChangeUint8Command.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_CHANGE_UINT8_COMMAND_H 2 | #define COCOA_ENGINE_CHANGE_UINT8_COMMAND_H 3 | #include "cocoa/commands/ICommand.h" 4 | 5 | namespace Cocoa 6 | { 7 | class COCOA ChangeUint8Command final : public ICommand 8 | { 9 | public: 10 | ChangeUint8Command(uint8& originalUint8, uint8 newUint8) 11 | : mUint8(originalUint8), mNewUint8(newUint8), mOldUint8(0) 12 | { 13 | } 14 | 15 | void execute() override 16 | { 17 | mOldUint8 = mUint8; 18 | mUint8 = mNewUint8; 19 | } 20 | 21 | void undo() override 22 | { 23 | mUint8 = mOldUint8; 24 | } 25 | 26 | bool mergeWith(ICommand* other) override 27 | { 28 | ChangeUint8Command* changeUint8Command = dynamic_cast(other); 29 | if (changeUint8Command != nullptr) 30 | { 31 | if (&changeUint8Command->mUint8 == &this->mUint8) 32 | { 33 | changeUint8Command->mNewUint8 = this->mNewUint8; 34 | return true; 35 | } 36 | } 37 | 38 | return false; 39 | } 40 | 41 | 42 | private: 43 | uint8& mUint8; 44 | uint8 mNewUint8; 45 | uint8 mOldUint8; 46 | }; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/commands/ChangeVec2Command.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_CHANGE_VEC2_COMMAND_H 2 | #define COCOA_ENGINE_CHANGE_VEC2_COMMAND_H 3 | #include "externalLibs.h" 4 | #include "cocoa/commands/ICommand.h" 5 | 6 | namespace Cocoa 7 | { 8 | class COCOA ChangeVec2Command final : public ICommand 9 | { 10 | public: 11 | ChangeVec2Command(glm::vec2& originalVector, glm::vec2& newVector) 12 | : mVector(originalVector), mNewVector(newVector), mOldVector(glm::vec2()) 13 | { 14 | } 15 | 16 | void execute() override 17 | { 18 | mOldVector = glm::vec2(mVector); 19 | mVector.x = mNewVector.x; 20 | mVector.y = mNewVector.y; 21 | } 22 | 23 | void undo() override 24 | { 25 | mVector.x = mOldVector.x; 26 | mVector.y = mOldVector.y; 27 | } 28 | 29 | bool mergeWith(ICommand* other) override 30 | { 31 | ChangeVec2Command* changeVec2Command = dynamic_cast(other); 32 | if (changeVec2Command != nullptr) 33 | { 34 | if (&changeVec2Command->mVector == &this->mVector) 35 | { 36 | changeVec2Command->mNewVector = this->mNewVector; 37 | return true; 38 | } 39 | } 40 | 41 | return false; 42 | } 43 | 44 | 45 | private: 46 | glm::vec2& mVector; 47 | glm::vec2 mNewVector; 48 | glm::vec2 mOldVector; 49 | }; 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/commands/ChangeVec3Command.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_CHANGE_VEC3_COMMAND_H 2 | #define COCOA_ENGINE_CHANGE_VEC3_COMMAND_H 3 | #include "externalLibs.h" 4 | #include "cocoa/commands/ICommand.h" 5 | 6 | namespace Cocoa 7 | { 8 | class COCOA ChangeVec3Command final : public ICommand 9 | { 10 | public: 11 | ChangeVec3Command(glm::vec3& originalVector, glm::vec3& newVector) 12 | : mVector(originalVector), mNewVector(newVector), mOldVector(glm::vec3()) 13 | { 14 | } 15 | 16 | void execute() override 17 | { 18 | mOldVector = glm::vec3(mVector); 19 | mVector.x = mNewVector.x; 20 | mVector.y = mNewVector.y; 21 | mVector.z = mNewVector.z; 22 | } 23 | 24 | void undo() override 25 | { 26 | mVector.x = mOldVector.x; 27 | mVector.y = mOldVector.y; 28 | mVector.z = mOldVector.z; 29 | } 30 | 31 | bool mergeWith(ICommand* other) override 32 | { 33 | ChangeVec3Command* changeVec3Command = dynamic_cast(other); 34 | if (changeVec3Command != nullptr) 35 | { 36 | if (&changeVec3Command->mVector == &this->mVector) 37 | { 38 | changeVec3Command->mNewVector = this->mNewVector; 39 | return true; 40 | } 41 | } 42 | 43 | return false; 44 | } 45 | 46 | 47 | private: 48 | glm::vec3& mVector; 49 | glm::vec3 mNewVector; 50 | glm::vec3 mOldVector; 51 | }; 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/commands/ChangeVec4Command.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_CHANGE_VEC4_COMMAND_H 2 | #define COCOA_ENGINE_CHANGE_VEC4_COMMAND_H 3 | #include "externalLibs.h" 4 | #include "cocoa/commands/ICommand.h" 5 | 6 | namespace Cocoa 7 | { 8 | class COCOA ChangeVec4Command final : public ICommand 9 | { 10 | public: 11 | ChangeVec4Command(glm::vec4& originalVector, glm::vec4& newVector) 12 | : mVector(originalVector), mNewVector(newVector), mOldVector(glm::vec4()) 13 | { 14 | } 15 | 16 | void execute() override 17 | { 18 | mOldVector = glm::vec4(mVector); 19 | mVector.x = mNewVector.x; 20 | mVector.y = mNewVector.y; 21 | mVector.z = mNewVector.z; 22 | mVector.w = mNewVector.w; 23 | } 24 | 25 | void undo() override 26 | { 27 | mVector.x = mOldVector.x; 28 | mVector.y = mOldVector.y; 29 | mVector.z = mOldVector.z; 30 | mVector.w = mOldVector.w; 31 | } 32 | 33 | bool mergeWith(ICommand* other) override 34 | { 35 | ChangeVec4Command* changeVec4Command = dynamic_cast(other); 36 | if (changeVec4Command != nullptr) 37 | { 38 | if (&changeVec4Command->mVector == &this->mVector) 39 | { 40 | changeVec4Command->mNewVector = this->mNewVector; 41 | return true; 42 | } 43 | } 44 | 45 | return false; 46 | } 47 | 48 | 49 | private: 50 | glm::vec4& mVector; 51 | glm::vec4 mNewVector; 52 | glm::vec4 mOldVector; 53 | }; 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/commands/CommandHistory.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_COMMAND_HISTORY 2 | #define COCOA_ENGINE_COMMAND_HISTORY 3 | #include "cocoa/commands/ICommand.h" 4 | 5 | namespace Cocoa { 6 | class COCOA CommandHistory { 7 | public: 8 | static void addCommand(ICommand* cmd); 9 | static void setNoMergeMostRecent(); 10 | static void undo(); 11 | static void redo(); 12 | 13 | private: 14 | static ICommand* mCommands[1000]; 15 | static int mCommandSize; 16 | static int mCommandPtr; 17 | }; 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/commands/ICommand.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_ICOMMAND_H 2 | #define COCOA_ENGINE_ICOMMAND_H 3 | #include "externalLibs.h" 4 | 5 | #include "cocoa/core/Core.h" 6 | 7 | namespace Cocoa { 8 | class COCOA ICommand { 9 | public: 10 | virtual ~ICommand() {} 11 | virtual void execute() = 0; 12 | virtual void undo() = 0; 13 | virtual bool mergeWith(ICommand* other) = 0; 14 | 15 | void setNoMerge() { mCanMerge = false; } 16 | bool canMerge() const { return mCanMerge; } 17 | 18 | private: 19 | static int64 mId; 20 | 21 | protected: 22 | bool mCanMerge = true; 23 | }; 24 | } 25 | 26 | // These includes are for ease of use from other classes 27 | // If you wish to have all commands simply include ICommand.h 28 | #include "cocoa/commands/CommandHistory.h" 29 | #include "cocoa/commands/ChangeFloatCommand.h" 30 | #include "cocoa/commands/ChangeVec2Command.h" 31 | #include "cocoa/commands/ChangeVec3Command.h" 32 | #include "cocoa/commands/ChangeVec4Command.h" 33 | #include "cocoa/commands/ChangeInt2Command.h" 34 | #include "cocoa/commands/ChangeIntCommand.h" 35 | #include "cocoa/commands/ChangeUint8Command.h" 36 | #include "cocoa/commands/ChangeEnumCommand.h" 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/components/FontRenderer.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_FONT_RENDERER_H 2 | #define COCOA_ENGINE_FONT_RENDERER_H 3 | #include "externalLibs.h" 4 | #include "cocoa/renderer/Fonts/Font.h" 5 | #include "cocoa/core/Handle.h" 6 | 7 | namespace Cocoa 8 | { 9 | struct FontRenderer 10 | { 11 | glm::vec4 color = glm::vec4(1, 1, 1, 1); 12 | int zIndex = 0; 13 | Handle font; 14 | std::string text; 15 | int fontSize; 16 | }; 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/components/NoSerialize.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_NO_SERIALIZE_H 2 | #define COCOA_ENGINE_NO_SERIALIZE_H 3 | 4 | namespace Cocoa 5 | { 6 | struct NoSerialize { uint8 dummy; }; 7 | } 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/components/Script.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_SCRIPT_H 2 | #define COCOA_ENGINE_SCRIPT_H 3 | #include "cocoa/core/Core.h" 4 | #include "cocoa/core/EntityStruct.h" 5 | 6 | namespace Cocoa 7 | { 8 | class Script 9 | { 10 | public: 11 | virtual void start(Entity entity) {} 12 | virtual void editorUpdate(Entity entity, float dt) {} 13 | 14 | virtual void update(Entity entity, float dt) {} 15 | virtual void imGui(Entity entity) {} 16 | 17 | virtual void beginContact(Entity other) {} 18 | virtual void endContact(Entity other) {} 19 | }; 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/components/Sprite.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_SPRITE_H 2 | #define COCOA_ENGINE_SPRITE_H 3 | #include "externalLibs.h" 4 | #include "cocoa/renderer/Texture.h" 5 | #include "cocoa/core/Handle.h" 6 | 7 | namespace Cocoa 8 | { 9 | struct Sprite 10 | { 11 | Handle texture = {}; 12 | glm::vec2 texCoords[4] = { 13 | {1, 1}, 14 | {1, 0}, 15 | {0, 0}, 16 | {0, 1} 17 | }; 18 | }; 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/components/SpriteRenderer.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_SPRITE_RENDERER_H 2 | #define COCOA_ENGINE_SPRITE_RENDERER_H 3 | #include "externalLibs.h" 4 | 5 | #include "cocoa/components/Sprite.h" 6 | 7 | namespace Cocoa 8 | { 9 | struct SpriteRenderer 10 | { 11 | glm::vec4 color = glm::vec4(1, 1, 1, 1); 12 | int zIndex = 0; 13 | Sprite sprite; 14 | }; 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/components/Spritesheet.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_SPRITESHEET_H 2 | #define COCOA_ENGINE_SPRITESHEET_H 3 | #include "externalLibs.h" 4 | #include "cocoa/components/Sprite.h" 5 | 6 | namespace Cocoa 7 | { 8 | struct Spritesheet 9 | { 10 | Handle textureHandle; 11 | std::vector sprites; 12 | }; 13 | 14 | namespace NSpritesheet 15 | { 16 | COCOA Spritesheet createSpritesheet(Handle textureHandle, int spriteWidth, int spriteHeight, int numSprites, int spacing); 17 | 18 | COCOA Sprite getSprite(const Spritesheet& spritesheet, int index); 19 | 20 | COCOA int size(const Spritesheet& spritesheet); 21 | }; 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/components/Tag.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_TAG_H 2 | #define COCOA_ENGINE_TAG_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | #include "cocoa/core/Entity.h" 6 | 7 | namespace Cocoa 8 | { 9 | struct Tag 10 | { 11 | const char* name; 12 | int size; 13 | bool isHeapAllocated; 14 | }; 15 | 16 | namespace NTag 17 | { 18 | COCOA Tag createTag(const char* name, bool isHeapAllocated = false); 19 | COCOA void destroy(Tag& tag); 20 | 21 | COCOA void serialize(json& j, Entity entity, const Tag& transform); 22 | COCOA void deserialize(const json& j, Entity entity); 23 | } 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/components/Transform.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_TRANSFORM_H 2 | #define COCOA_ENGINE_TRANSFORM_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Entity.h" 5 | #include "cocoa/components/TransformStruct.h" 6 | 7 | namespace Cocoa 8 | { 9 | namespace Transform 10 | { 11 | COCOA TransformData createTransform(); 12 | COCOA TransformData createTransform(glm::vec3 position, glm::vec3 scale, glm::vec3 eulerRotation); 13 | 14 | COCOA void update(TransformData& data, float dt); 15 | 16 | COCOA void serialize(json& j, Entity entity, const TransformData& transform); 17 | COCOA void deserialize(const json& j, Entity entity, Entity parent = NEntity::createNull()); 18 | COCOA void serialize(json& j, const TransformData& transform); 19 | COCOA void deserialize(const json& j, TransformData& transform); 20 | } 21 | 22 | namespace TransformSystem 23 | { 24 | COCOA void update(SceneData& scene, float dt); 25 | } 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/components/TransformStruct.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_TRANSFORM_STRUCT_H 2 | #define COCOA_ENGINE_TRANSFORM_STRUCT_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/EntityStruct.h" 5 | 6 | namespace Cocoa 7 | { 8 | struct TransformData 9 | { 10 | glm::vec3 position; 11 | glm::vec3 scale; 12 | glm::vec3 eulerRotation; 13 | glm::quat orientation; 14 | 15 | glm::mat4 modelMatrix; 16 | glm::mat4 inverseModelMatrix; 17 | glm::vec3 localPosition; 18 | glm::vec3 localScale; 19 | glm::vec3 localEulerRotation; 20 | Entity parent; 21 | }; 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/core/Application.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_APPLICATION_H 2 | #define COCOA_ENGINE_APPLICATION_H 3 | #include "externalLibs.h" 4 | 5 | #include "cocoa/core/Core.h" 6 | #include "cocoa/core/CWindow.h" 7 | #include "cocoa/events/Event.h" 8 | #include "cocoa/events/WindowEvent.h" 9 | #include "cocoa/scenes/SceneData.h" 10 | 11 | namespace Cocoa 12 | { 13 | class SceneInitializer; 14 | 15 | typedef void (*AppOnUpdateFn)(SceneData& scene, float dt); 16 | typedef void (*AppOnAttachFn)(SceneData& scene); 17 | typedef void (*AppOnRenderFn)(SceneData& scene); 18 | typedef void (*AppOnEventFn)(SceneData& scene, Event& e); 19 | 20 | /** 21 | * The main application's DLL data 22 | * 23 | * This data is used by the main executable to call the 24 | * main events for the application (update, attach, render, event). 25 | */ 26 | struct ApplicationData 27 | { 28 | AppOnUpdateFn appOnUpdate = nullptr; /**< Callback function to update the app. */ 29 | AppOnAttachFn appOnAttach = nullptr; /**< Callback function to attach the app. */ 30 | AppOnRenderFn appOnRender = nullptr; /**< Callback function to render the app. */ 31 | AppOnEventFn appOnEvent = nullptr; /**< Callback function to forward events to the app. */ 32 | }; 33 | 34 | /** 35 | * The main application class. 36 | * 37 | * This class represents the application and holds is the main entry point for 38 | * the application. It links into the DLL and calls all the callbacks at the appropriate 39 | * times. 40 | */ 41 | class COCOA Application 42 | { 43 | public: 44 | Application(); 45 | virtual ~Application() = default; 46 | 47 | virtual void init() {} 48 | virtual void shutdown() {} 49 | 50 | void run(); 51 | void stop(); 52 | 53 | virtual void onEvent(Event& e); 54 | CWindow* getWindow() const; 55 | 56 | static Application* get(); 57 | 58 | protected: 59 | virtual void beginFrame() {} 60 | virtual void endFrame() {} 61 | 62 | private: 63 | bool onWindowClose(WindowCloseEvent& e); 64 | 65 | static Application* sInstance; 66 | 67 | bool mRunning; 68 | 69 | float mLastFrameTime = 0; 70 | 71 | protected: 72 | SceneData mCurrentScene; 73 | CWindow* mWindow; 74 | ApplicationData mAppData; 75 | }; 76 | 77 | // To be defined in CLIENT 78 | Application* createApplication(); 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/core/AssetManager.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_ASSET_MANAGER_H 2 | #define COCOA_ENGINE_ASSET_MANAGER_H 3 | #include "externalLibs.h" 4 | #include "cocoa/renderer/Fonts/Font.h" 5 | #include "cocoa/renderer/Texture.h" 6 | #include "cocoa/renderer/Shader.h" 7 | 8 | #include 9 | #include 10 | 11 | namespace Cocoa 12 | { 13 | enum class AssetType : char 14 | { 15 | None = 0, 16 | Texture = 1, 17 | Font = 2, 18 | Shader = 3 19 | }; 20 | 21 | namespace AssetManager 22 | { 23 | COCOA Handle loadTextureFromJson(const json& j, bool isDefault = false, int id = -1); 24 | COCOA Handle loadTextureFromFile(Texture& texture, const std::filesystem::path& path, int id = -1); 25 | COCOA Handle getTexture(const std::filesystem::path& path); 26 | COCOA const Texture& getTexture(uint32 resourceId); 27 | 28 | COCOA Handle loadFontFromJson(const std::filesystem::path& path, const json& j, bool isDefault = false, int id = -1); 29 | COCOA Handle loadFontFromTtfFile(const std::filesystem::path& fontFile, int fontSize, const std::filesystem::path& outputFile, int glyphRangeStart, int glyphRangeEnd, int padding, int upscaleResolution); 30 | COCOA Handle getFont(const std::filesystem::path& path); 31 | COCOA const Font& getFont(uint32 resourceId); 32 | 33 | COCOA Handle loadShaderFromFile(const std::filesystem::path& path, bool isDefault = false, int id = -1); 34 | COCOA Handle getShader(const std::filesystem::path& path); 35 | COCOA const Shader& getShader(uint32 resourceId); 36 | 37 | COCOA void loadTexturesFrom(const json& j); 38 | COCOA void loadFontsFrom(const json& j); 39 | COCOA json serialize(); 40 | 41 | COCOA void clear(); 42 | COCOA void init(uint32 scene); 43 | 44 | COCOA const std::vector& getAllTextures(); 45 | COCOA const std::vector& getAllFonts(); 46 | } 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/core/Audio.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_AUDIO_H 2 | #define COCOA_ENGINE_AUDIO_H 3 | #include "cocoa/core/AssetManager.h" 4 | 5 | namespace Cocoa 6 | { 7 | class COCOA Audio 8 | { 9 | 10 | }; 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/core/CWindow.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_CWINDOW_H 2 | #define COCOA_ENGINE_CWINDOW_H 3 | #include "externalLibs.h" 4 | 5 | #include "cocoa/core/Core.h" 6 | #include "cocoa/events/Event.h" 7 | 8 | namespace Cocoa 9 | { 10 | class COCOA CWindow 11 | { 12 | public: 13 | using EventCallbackFn = std::function; 14 | 15 | CWindow(uint32 width, uint32 height, const std::string& name); 16 | 17 | void init(uint32 width, uint32 height, const std::string& name); 18 | void onUpdate(); 19 | 20 | // Window Attributes 21 | void setVSync(bool enabled); 22 | bool isVSync() const; 23 | 24 | void* getNativeWindow() const; 25 | 26 | static CWindow* create(uint32 width, uint32 height, const std::string& name); 27 | 28 | bool isRunning(); 29 | void setEventCallback(const EventCallbackFn& callback); 30 | glm::vec2 getWindowPos(); 31 | 32 | void setWidth(const int newWidth) { mSize.x = (float)newWidth; } 33 | void setHeight(const int newHeight) { mSize.y = (float)newHeight; } 34 | void setSize(const glm::vec2& size); 35 | void setTitle(const char* newTitle); 36 | glm::vec2 getMonitorSize(); 37 | int getWidth() const { return (int)mSize.x; } 38 | int getHeight() const { return (int)mSize.y; } 39 | const glm::vec2& getSize() const { return mSize; } 40 | 41 | float getTargetAspectRatio() const { return mTargetAspectRatio; } 42 | void render(); 43 | 44 | void destroy(); 45 | 46 | private: 47 | CWindow() = default; 48 | 49 | private: 50 | void* mWindowHandle = nullptr; 51 | 52 | EventCallbackFn mEventCallback = nullptr; 53 | bool mVSync = false; 54 | bool mRunning = true; 55 | glm::vec2 mSize{ 1920, 1080 }; 56 | float mTargetAspectRatio = 3840.0f / 2160.0f; 57 | }; 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/core/Entity.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_ENTITY_H 2 | #define COCOA_ENGINE_ENTITY_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | 6 | #include "cocoa/scenes/SceneData.h" 7 | #include "cocoa/core/EntityStruct.h" 8 | 9 | namespace Cocoa 10 | { 11 | namespace NEntity 12 | { 13 | COCOA Entity createEntity(entt::entity raw); 14 | COCOA void setScene(SceneData* scene); 15 | COCOA SceneData* getScene(); 16 | COCOA Entity createNull(); 17 | 18 | template 19 | void registerComponentType() 20 | { 21 | SceneData* scene = getScene(); 22 | scene->registry.prepare(); 23 | } 24 | 25 | template 26 | void clear() 27 | { 28 | SceneData* scene = getScene(); 29 | scene->registry.clear(); 30 | } 31 | 32 | template 33 | bool hasComponent(Entity entity) 34 | { 35 | SceneData* scene = getScene(); 36 | return scene->registry.has(entity.handle); 37 | } 38 | 39 | template 40 | T& addComponent(Entity entity, Args&&... args) 41 | { 42 | Logger::Assert(!hasComponent(entity), "Entity already has component."); 43 | SceneData* scene = getScene(); 44 | return scene->registry.emplace(entity.handle, std::forward(args)...); 45 | } 46 | 47 | template 48 | T& getComponent(Entity entity) 49 | { 50 | Logger::Assert(hasComponent(entity), "Entity does not have component."); 51 | SceneData* scene = getScene(); 52 | return scene->registry.get(entity.handle); 53 | } 54 | 55 | template 56 | void removeComponent(Entity entity) 57 | { 58 | Logger::Assert(hasComponent(entity), "Entity does not have component."); 59 | SceneData* scene = getScene(); 60 | scene->registry.remove(entity.handle); 61 | } 62 | 63 | inline bool isNull(Entity entity) 64 | { 65 | return entity.handle == entt::null; 66 | } 67 | 68 | inline uint32 getId(Entity entity) 69 | { 70 | return (uint32)(entt::to_integral(entity.handle)); 71 | } 72 | 73 | template 74 | Entity fromComponent(const T& component) 75 | { 76 | SceneData* scene = getScene(); 77 | size_t offset = &component - scene->registry.raw(); 78 | Logger::Assert(offset < scene->registry.size(), "Tried to get nonexistent entity."); 79 | return Entity{*(scene->registry.data() + offset)}; 80 | } 81 | } 82 | 83 | COCOA bool operator==(const Entity& a, const Entity& b); 84 | COCOA bool operator==(Entity& a, Entity& other); 85 | COCOA bool operator!=(const Entity& a, const Entity& b); 86 | COCOA bool operator!=(Entity& a, Entity& b); 87 | } 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/core/EntityStruct.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_ENTITY_STRUCT_H 2 | #define COCOA_ENGINE_ENTITY_STRUCT_H 3 | #include "externalLibs.h" 4 | 5 | namespace Cocoa 6 | { 7 | struct Entity 8 | { 9 | entt::entity handle; 10 | }; 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/core/EntryPoint.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_ENTRY_POINT_H 2 | #define COCOA_ENGINE_ENTRY_POINT_H 3 | 4 | #ifdef _WIN32 5 | #include "platform/windows/winMain.h" 6 | #endif 7 | 8 | #endif -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/core/Handle.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_HANDLE_H 2 | #define COCOA_ENGINE_HANDLE_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | namespace Cocoa 7 | { 8 | namespace NHandle 9 | { 10 | const uint32 NULL_ID = UINT32_MAX; 11 | } 12 | 13 | template 14 | struct Handle 15 | { 16 | uint32 assetId; 17 | 18 | bool operator==(Handle other) const 19 | { 20 | return assetId == other.assetId; 21 | } 22 | 23 | bool operator!=(Handle other) const 24 | { 25 | return !(*this == other); 26 | } 27 | 28 | operator bool() const 29 | { 30 | return !isNull(); 31 | } 32 | 33 | bool isNull() const 34 | { 35 | return assetId == NHandle::NULL_ID; 36 | } 37 | }; 38 | 39 | namespace NHandle 40 | { 41 | template 42 | Handle createHandle() 43 | { 44 | return Handle { 45 | NULL_ID 46 | }; 47 | } 48 | 49 | template 50 | Handle createHandle(uint32 id) 51 | { 52 | return Handle { 53 | id 54 | }; 55 | } 56 | } 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/events/Event.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_EVENT_H 2 | #define COCOA_ENGINE_EVENT_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | 6 | #pragma warning( push ) 7 | #pragma warning ( disable : 26812 ) 8 | 9 | namespace Cocoa 10 | { 11 | 12 | // ================================================================ 13 | // Event enums 14 | // We have to declare the first enum as a class, otherwise we get 15 | // a name clashing error for None = 0 16 | // ================================================================ 17 | enum class EventType 18 | { 19 | None = 0, 20 | WindowClose, WindowResize, WindowFocus, WindowLostFocus, WindowMoved, 21 | KeyPressed, KeyReleased, KeyTyped, 22 | MouseButtonPressed, MouseButtonReleased, MouseMoved, MouseScrolled 23 | }; 24 | 25 | enum EventCategory 26 | { 27 | None = 0, 28 | EventCategoryApplication = 0x00000001, 29 | EventCategoryInput = 0x00000010, 30 | EventCategoryKeyboard = 0x00000100, 31 | EventCategoryMouse = 0x00001000, 32 | EventCategoryMouseButton = 0x00010000 33 | }; 34 | 35 | // ================================================================ 36 | // Event helper macros 37 | // ================================================================ 38 | #define EVENT_CLASS_TYPE_HEADER(type) static EventType getStaticType(); \ 39 | virtual EventType getType() const override; \ 40 | virtual const char* getName() const override; 41 | 42 | #define EVENT_CLASS_TYPE_IMPL(type, clazz) EventType clazz::getStaticType() { return EventType::##type; } \ 43 | EventType clazz::getType() const { return getStaticType(); } \ 44 | const char* clazz::getName() const { return #type; } 45 | 46 | #define EVENT_CLASS_CATEGORY_HEADER(category) int getCategoryFlags() const; 47 | #define EVENT_CLASS_CATEGORY_IMPL(category, clazz) int clazz::getCategoryFlags() const { return category; } 48 | 49 | // ================================================================ 50 | // Event Base Class 51 | // ================================================================ 52 | class COCOA Event 53 | { 54 | friend class EventDispatcher; 55 | 56 | public: 57 | virtual EventType getType() const = 0; 58 | virtual const char* getName() const = 0; 59 | virtual int getCategoryFlags() const = 0; 60 | virtual std::string toString() const { return getName(); } 61 | 62 | bool isInCategory(EventCategory category) const { return getCategoryFlags() & category; } 63 | 64 | bool handled = false; 65 | }; 66 | 67 | // ================================================================ 68 | // Event dispatcher 69 | // ================================================================ 70 | class COCOA EventDispatcher 71 | { 72 | template 73 | using EventFn = std::function; 74 | 75 | public: 76 | EventDispatcher(Event& e) 77 | : mEvent(e) 78 | { 79 | } 80 | 81 | template 82 | bool dispatch(EventFn function) 83 | { 84 | if (mEvent.getType() == T::getStaticType()) 85 | { 86 | mEvent.handled = function(*(T*)&mEvent); 87 | return true; 88 | } 89 | 90 | return false; 91 | } 92 | 93 | private: 94 | Event& mEvent; 95 | }; 96 | 97 | inline std::ostream& operator<<(std::ostream& os, const Event& e) 98 | { 99 | return os << e.toString(); 100 | } 101 | } 102 | 103 | // For convenience other classes only need to include this header 104 | #include "cocoa/events/WindowEvent.h" 105 | #include "cocoa/events/KeyEvent.h" 106 | #include "cocoa/events/MouseEvent.h" 107 | #include "cocoa/events/Input.h" 108 | 109 | #pragma warning(pop) 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/events/Input.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_INPUT_H 2 | #define COCOA_ENGINE_INPUT_H 3 | #include "externalLibs.h" 4 | #include "cocoa/scenes/SceneData.h" 5 | #include "cocoa/renderer/Camera.h" 6 | 7 | namespace Cocoa 8 | { 9 | class COCOA Input 10 | { 11 | public: 12 | static void init(); 13 | 14 | static void keyCallback(int key, int scanCode, int action, int mods); 15 | static void cursorCallback(double xPos, double yPos); 16 | static void mouseButtonCallback(int button, int action, int mods); 17 | static void scrollCallback(double xOffset, double yOffset); 18 | 19 | static bool keyPressed(int keyCode); 20 | static bool mouseButtonPressed(int mouseButton); 21 | static float mouseX(); 22 | static float mouseY(); 23 | static float scrollX(); 24 | static float scrollY(); 25 | static void endFrame(); 26 | static glm::vec2 mousePos(); 27 | 28 | static float orthoMouseX(const Camera& camera); 29 | static float orthoMouseY(const Camera& camera); 30 | static glm::vec2 screenToOrtho(const Camera& camera); 31 | static glm::vec2 normalizedMousePos(); 32 | 33 | static void setGameViewPos(const glm::vec2& position); 34 | static void setGameViewSize(const glm::vec2& size); 35 | static void setGameViewMousePos(const glm::vec2& mousePos); 36 | 37 | private: 38 | Input() = default; 39 | 40 | private: 41 | static bool sInitialized; 42 | 43 | static bool sKeyPressed[349]; 44 | static bool sMouseButtonPressed[3]; 45 | static float sXPos; 46 | static float sYPos; 47 | static float sScrollX; 48 | static float sScrollY; 49 | 50 | static glm::vec2 sGameViewPos; 51 | static glm::vec2 sGameViewSize; 52 | static glm::vec2 sGameViewMousePos; 53 | 54 | static SceneData* sScene; 55 | }; 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/events/KeyEvent.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_KEY_EVENT_H 2 | #define COCOA_ENGINE_KEY_EVENT_H 3 | 4 | #include "cocoa/events/Event.h" 5 | 6 | namespace Cocoa 7 | { 8 | // ============================================================ 9 | // Base 10 | // ============================================================ 11 | class COCOA KeyEvent : public Event 12 | { 13 | public: 14 | // TODO: Make this inline somehow 15 | int getKeyCode() const; 16 | 17 | EVENT_CLASS_CATEGORY_HEADER(EventCategoryKeyboard | EventCategoryInput) 18 | 19 | protected: 20 | // Abstract class, should not be instantiated 21 | KeyEvent(int keycode); 22 | 23 | int mKeyCode; 24 | }; 25 | 26 | // ============================================================ 27 | // KeyPressed 28 | // ============================================================ 29 | class COCOA KeyPressedEvent : public KeyEvent 30 | { 31 | public: 32 | KeyPressedEvent(int keycode, int repeatCount); 33 | 34 | inline int getRepeatCount() const; 35 | 36 | std::string toString() const override; 37 | 38 | EVENT_CLASS_TYPE_HEADER(KeyPressed) 39 | 40 | private: 41 | int mRepeatCount; 42 | }; 43 | 44 | // ============================================================ 45 | // KeyReleased 46 | // ============================================================ 47 | class COCOA KeyReleasedEvent : public KeyEvent 48 | { 49 | public: 50 | KeyReleasedEvent(int keycode); 51 | 52 | std::string toString() const override; 53 | 54 | EVENT_CLASS_TYPE_HEADER(KeyReleased); 55 | }; 56 | 57 | // ============================================================ 58 | // KeyTyped 59 | // ============================================================ 60 | class COCOA KeyTypedEvent : public KeyEvent 61 | { 62 | KeyTypedEvent(int keycode); 63 | 64 | std::string toString() const override; 65 | 66 | EVENT_CLASS_TYPE_HEADER(KeyTyped); 67 | }; 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/events/MouseEvent.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_MOUSE_EVENT_H 2 | #define COCOA_ENGINE_MOUSE_EVENT_H 3 | 4 | #include "cocoa/events/Event.h" 5 | 6 | namespace Cocoa 7 | { 8 | // =============================================================== 9 | // MouseMovedEvent 10 | // =============================================================== 11 | class COCOA MouseMovedEvent : public Event 12 | { 13 | public: 14 | MouseMovedEvent(float x, float y); 15 | 16 | inline float getX() const; 17 | inline float getY() const; 18 | 19 | std::string toString() const override; 20 | 21 | EVENT_CLASS_TYPE_HEADER(MouseMoved) 22 | EVENT_CLASS_CATEGORY_HEADER(EventCategoryInput | EventCategoryMouse) 23 | 24 | private: 25 | float mMouseX; 26 | float mMouseY; 27 | }; 28 | 29 | // =============================================================== 30 | // MouseScrolledEvent 31 | // =============================================================== 32 | class COCOA MouseScrolledEvent : public Event 33 | { 34 | public: 35 | MouseScrolledEvent(float xOffset, float yOffset); 36 | 37 | // TODO: Make these inline somehow 38 | float getXOffset() const; 39 | float getYOffset() const; 40 | 41 | std::string toString() const override; 42 | 43 | EVENT_CLASS_TYPE_HEADER(MouseScrolled) 44 | EVENT_CLASS_CATEGORY_HEADER(EventCategoryMouse | EventCategoryInput) 45 | 46 | private: 47 | float mXOffset; 48 | float mYOffset; 49 | }; 50 | 51 | // =============================================================== 52 | // Base 53 | // =============================================================== 54 | class COCOA MouseButtonEvent : public Event 55 | { 56 | public: 57 | // TODO: Make this inline somehow 58 | int getMouseButton() const; 59 | 60 | EVENT_CLASS_CATEGORY_HEADER(EventCategoryInput | EventCategoryMouse) 61 | 62 | protected: 63 | MouseButtonEvent(int button); 64 | 65 | int mButton; 66 | }; 67 | 68 | // =============================================================== 69 | // MouseButtonPressedEvent 70 | // =============================================================== 71 | class COCOA MouseButtonPressedEvent : public MouseButtonEvent 72 | { 73 | public: 74 | MouseButtonPressedEvent(int button); 75 | 76 | std::string toString() const override; 77 | 78 | EVENT_CLASS_TYPE_HEADER(MouseButtonPressed) 79 | }; 80 | 81 | // =============================================================== 82 | // MouseButtonReleasedEvent 83 | // =============================================================== 84 | class COCOA MouseButtonReleasedEvent : public MouseButtonEvent 85 | { 86 | public: 87 | MouseButtonReleasedEvent(int button); 88 | 89 | std::string toString() const override; 90 | 91 | EVENT_CLASS_TYPE_HEADER(MouseButtonReleased) 92 | }; 93 | } 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/events/WindowEvent.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_WINDOW_EVENT_H 2 | #define COCOA_ENGINE_WINDOW_EVENT_H 3 | 4 | #include "cocoa/core/Core.h" 5 | #include "cocoa/events/Event.h" 6 | 7 | namespace Cocoa 8 | { 9 | class COCOA WindowResizeEvent : public Event 10 | { 11 | public: 12 | WindowResizeEvent(uint32 width, uint32 height); 13 | 14 | // TODO: Make these inline somehow 15 | uint32 getWidth() const; 16 | uint32 getHeight() const; 17 | 18 | std::string toString() const override; 19 | 20 | EVENT_CLASS_TYPE_HEADER(WindowResize) 21 | EVENT_CLASS_CATEGORY_HEADER(EventCategoryApplication) 22 | 23 | private: 24 | uint32 m_Width; 25 | uint32 m_Height; 26 | }; 27 | 28 | class COCOA WindowCloseEvent : public Event 29 | { 30 | public: 31 | WindowCloseEvent(); 32 | 33 | EVENT_CLASS_TYPE_HEADER(WindowClose) 34 | EVENT_CLASS_CATEGORY_HEADER(EventCategoryApplication) 35 | }; 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/file/File.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_FILE_H 2 | #define COCOA_ENGINE_FILE_H 3 | #include "externalLibs.h" 4 | 5 | #include 6 | 7 | namespace Cocoa 8 | { 9 | struct FileHandle 10 | { 11 | std::string filename = ""; 12 | char* data = nullptr; 13 | uint32 size = 0; 14 | bool open = false; 15 | }; 16 | 17 | namespace File 18 | { 19 | COCOA FileHandle* openFile(const std::filesystem::path& filename); 20 | COCOA void closeFile(FileHandle* file); 21 | COCOA bool writeFile(const char* data, const std::filesystem::path& filename); 22 | COCOA bool createFile(const std::filesystem::path& filename, const char* extToAppend = ""); 23 | COCOA bool deleteFile(const std::filesystem::path& filename); 24 | COCOA bool copyFile(const std::filesystem::path& fileToCopy, const std::filesystem::path& newFileLocation, const char* newFilename = ""); 25 | COCOA std::filesystem::path getCwd(); 26 | COCOA std::filesystem::path getSpecialAppFolder(); 27 | COCOA std::filesystem::path getExecutableDirectory(); 28 | COCOA std::vector getFilesInDir(const std::filesystem::path& directory); 29 | COCOA std::vector getFoldersInDir(const std::filesystem::path& directory); 30 | COCOA void createDirIfNotExists(const std::filesystem::path& directory); 31 | COCOA bool isFile(const std::filesystem::path& filepath); 32 | COCOA bool isHidden(const std::filesystem::path& filepath); 33 | COCOA bool isDirectory(const std::filesystem::path& directory); 34 | COCOA std::filesystem::path getAbsolutePath(const std::filesystem::path& path); 35 | 36 | COCOA bool runProgram(const std::filesystem::path& pathToExe, const char* cmdArgs = ""); 37 | COCOA bool runProgram(const std::filesystem::path& pathToExe, const std::string& cmdArgs = ""); 38 | }; 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/file/FileDialog.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_FILE_DIALOG_H 2 | #define COCOA_ENGINE_FILE_DIALOG_H 3 | #include "externalLibs.h" 4 | 5 | namespace Cocoa 6 | { 7 | struct FileDialogResult 8 | { 9 | std::string filepath; 10 | const char* filename; 11 | const char* extension; 12 | }; 13 | 14 | namespace FileDialog 15 | { 16 | COCOA bool getOpenFileName( 17 | const std::string& initialPath, 18 | FileDialogResult& result, 19 | std::vector> extensionFilters = { {"All Files", "*.*"} }); 20 | 21 | COCOA bool getOpenFolderName( 22 | const std::string& initialPath, 23 | FileDialogResult& result); 24 | 25 | COCOA bool getSaveFileName( 26 | const std::string& initialPath, 27 | FileDialogResult& result, 28 | std::vector> extensionFilters = { {"All Files", "*.*"} }, 29 | std::string extToAppend = ""); 30 | 31 | COCOA void displayMessageBox(const std::string& title, const std::string& message); 32 | }; 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/file/FileSystemWatcher.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_FILE_SYSTEM_WATCHER_H 2 | #define COCOA_ENGINE_FILE_SYSTEM_WATCHER_H 3 | 4 | #include "externalLibs.h" 5 | #include "cocoa/core/Core.h" 6 | 7 | #include 8 | 9 | #include 10 | #ifdef _WIN32 11 | #include 12 | #endif 13 | 14 | #undef CopyFile 15 | #undef DeleteFile 16 | #undef CreateFile 17 | 18 | namespace Cocoa 19 | { 20 | enum NotifyFilters 21 | { 22 | FileName = 1, 23 | DirectoryName = 2, 24 | Attributes = 4, 25 | Size = 8, 26 | LastWrite = 16, 27 | LastAccess = 32, 28 | CreationTime = 64, 29 | Security = 256 30 | }; 31 | 32 | class COCOA FileSystemWatcher 33 | { 34 | public: 35 | FileSystemWatcher(); 36 | ~FileSystemWatcher() { stop(); } 37 | void start(); 38 | void stop(); 39 | 40 | public: 41 | typedef void (*OnChanged)(const std::filesystem::path& file); 42 | typedef void (*OnRenamed)(const std::filesystem::path& file); 43 | typedef void (*OnDeleted)(const std::filesystem::path& file); 44 | typedef void (*OnCreated)(const std::filesystem::path& file); 45 | 46 | OnChanged onChanged = nullptr; 47 | OnRenamed onRenamed = nullptr; 48 | OnDeleted onDeleted = nullptr; 49 | OnCreated onCreated = nullptr; 50 | 51 | int notifyFilters = 0; 52 | bool includeSubdirectories = false; 53 | std::string filter = ""; 54 | std::filesystem::path path = {}; 55 | 56 | private: 57 | void startThread(); 58 | 59 | private: 60 | bool mEnableRaisingEvents = true; 61 | std::thread mThread; 62 | 63 | #ifdef _WIN32 64 | HANDLE mHStopEvent; 65 | #endif 66 | }; 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/file/OutputArchive.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_OUTPUT_ARCHIVE_H 2 | #define COCOA_ENGINE_OUTPUT_ARCHIVE_H 3 | #include "externalLibs.h" 4 | 5 | #include "cocoa/components/Transform.h" 6 | #include "cocoa/components/Tag.h" 7 | #include "cocoa/systems/RenderSystem.h" 8 | #include "cocoa/physics2d/Physics2D.h" 9 | 10 | #include 11 | #include 12 | 13 | namespace Cocoa 14 | { 15 | class COCOA OutputArchive 16 | { 17 | public: 18 | OutputArchive(json& j) 19 | : mJson(j) {} 20 | 21 | void operator()(entt::entity entity) const 22 | { 23 | //Logger::Info("Archiving entity: %d", entt::to_integral(entity)); 24 | } 25 | 26 | void operator()(std::underlying_type_t underlyingType) const 27 | { 28 | //Logger::Info("Archiving underlying type entity: %d", underlyingType); 29 | } 30 | 31 | template 32 | void operator()(entt::entity entity, const T& component) 33 | { 34 | entt::type_info info = entt::type_id(); 35 | 36 | if (info.seq() == entt::type_id().seq()) 37 | { 38 | const TransformData* transform = reinterpret_cast(&component); 39 | Transform::serialize(mJson, NEntity::createEntity(entity), *transform); 40 | } 41 | else if (info.seq() == entt::type_id().seq()) 42 | { 43 | const SpriteRenderer* renderer = reinterpret_cast(&component); 44 | RenderSystem::serialize(mJson, NEntity::createEntity(entity), *renderer); 45 | } 46 | else if (info.seq() == entt::type_id().seq()) 47 | { 48 | const FontRenderer* fontRenderer = reinterpret_cast(&component); 49 | RenderSystem::serialize(mJson, NEntity::createEntity(entity), *fontRenderer); 50 | } 51 | else if (info.seq() == entt::type_id().seq()) 52 | { 53 | const Box2D* box2D = reinterpret_cast(&component); 54 | Physics2D::serialize(mJson, NEntity::createEntity(entity), *box2D); 55 | } 56 | else if (info.seq() == entt::type_id().seq()) 57 | { 58 | const Rigidbody2D* rb = reinterpret_cast(&component); 59 | Physics2D::serialize(mJson, NEntity::createEntity(entity), *rb); 60 | } 61 | else if (info.seq() == entt::type_id().seq()) 62 | { 63 | const AABB* box = reinterpret_cast(&component); 64 | Physics2D::serialize(mJson, NEntity::createEntity(entity), *box); 65 | } 66 | else if (info.seq() == entt::type_id().seq()) 67 | { 68 | const Tag* tag = reinterpret_cast(&component); 69 | NTag::serialize(mJson, NEntity::createEntity(entity), *tag); 70 | } 71 | else 72 | { 73 | //Logger::Info("Archiving entity: %d DEFAULT", entt::to_integral(entity)); 74 | } 75 | } 76 | 77 | private: 78 | json& mJson; 79 | }; 80 | } 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/physics2d/ContactListener.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_CONTACT_LISTENER_H 2 | #define COCOA_ENGINE_CONTACT_LISTENER_H 3 | #include "externalLibs.h" 4 | 5 | namespace Cocoa 6 | { 7 | class ContactListener final : public b2ContactListener 8 | { 9 | public: 10 | void BeginContact(b2Contact* contact) override; 11 | 12 | void EndContact(b2Contact* contact) override; 13 | 14 | void PreSolve(b2Contact* contact, const b2Manifold* oldManifold) override; 15 | 16 | void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) override; 17 | }; 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/physics2d/Physics2D.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_PHYSICS_2D_H 2 | #define COCOA_ENGINE_PHYSICS_2D_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | 6 | #include "cocoa/physics2d/PhysicsComponents.h" 7 | #include "cocoa/core/Entity.h" 8 | #include "cocoa/scenes/SceneData.h" 9 | 10 | namespace Cocoa 11 | { 12 | namespace Physics2D 13 | { 14 | COCOA void init(const glm::vec2& gravity); 15 | COCOA void destroy(SceneData& scene); 16 | 17 | COCOA bool pointInBox(const glm::vec2& point, const glm::vec2& halfSize, const glm::vec2& position, float rotationDegrees); 18 | 19 | COCOA void addEntity(Entity entity); 20 | COCOA void deleteEntity(Entity entity); 21 | COCOA void update(SceneData& scene, float dt); 22 | 23 | COCOA void applyForceToCenter(const Rigidbody2D& rigidbody, const glm::vec2& force); 24 | COCOA void applyForce(const Rigidbody2D& rigidbody, const glm::vec2& force, const glm::vec2& point); 25 | COCOA void applyLinearImpulseToCenter(const Rigidbody2D& rigidbody, const glm::vec2& impulse); 26 | COCOA void applyLinearImpulse(const Rigidbody2D& rigidbody, const glm::vec2& impulse, const glm::vec2& point); 27 | 28 | // ---------------------------------------------------------------------------- 29 | // Serialization 30 | // ---------------------------------------------------------------------------- 31 | COCOA void serialize(json& j, Entity entity, const AABB& box); 32 | COCOA void deserializeAabb(const json& j, Entity entity); 33 | COCOA void serialize(json& j, Entity entity, const Box2D& box); 34 | COCOA void deserializeBox2D(const json& j, Entity entity); 35 | COCOA void serialize(json& j, Entity entity, const Rigidbody2D& rigidbody); 36 | COCOA void deserializeRigidbody2D(const json& j, Entity entity); 37 | }; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/physics2d/PhysicsComponents.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_PHYSICS_COMPONENTS_H 2 | #define COCOA_ENGINE_PHYSICS_COMPONENTS_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | #include "cocoa/core/Entity.h" 6 | 7 | namespace Cocoa 8 | { 9 | enum class BodyType2D : uint8 10 | { 11 | Dynamic = 0, 12 | Kinematic = 1, 13 | Static = 2 14 | }; 15 | 16 | struct Box2D 17 | { 18 | glm::vec2 size = glm::vec2(1.0f, 1.0f); 19 | glm::vec2 halfSize = glm::vec2(0.5f, 0.5f); 20 | glm::vec2 offset = glm::vec2(); 21 | }; 22 | 23 | struct AABB 24 | { 25 | glm::vec2 size = glm::vec2(1.0f, 1.0f); 26 | glm::vec2 halfSize = glm::vec2(0.5f, 0.5f); 27 | glm::vec2 offset = glm::vec2(); 28 | }; 29 | 30 | struct Circle 31 | { 32 | float radius = 1.0f; 33 | float inertiaTensor = 0.0f; 34 | }; 35 | 36 | struct Ray2D 37 | { 38 | glm::vec2 origin = glm::vec2(); 39 | glm::vec2 direction = glm::vec2(); 40 | float maxDistance = 0.0f; 41 | Entity ignore = NEntity::createNull(); 42 | }; 43 | 44 | struct Rigidbody2D 45 | { 46 | glm::vec2 velocity = glm::vec2(); 47 | float angularDamping = 0.0f; 48 | float linearDamping = 0.5f; 49 | float mass = 0.0f; 50 | BodyType2D bodyType = BodyType2D::Dynamic; 51 | 52 | bool fixedRotation = false; 53 | bool continuousCollision = false; 54 | 55 | void* rawRigidbody = nullptr; 56 | }; 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/renderer/Camera.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_CAMERA_H 2 | #define COCOA_ENGINE_CAMERA_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | 6 | #include "cocoa/components/Transform.h" 7 | #include "cocoa/renderer/CameraStruct.h" 8 | #include "cocoa/renderer/Framebuffer.h" 9 | 10 | namespace Cocoa 11 | { 12 | namespace NCamera 13 | { 14 | COCOA Camera createCamera(); 15 | COCOA Camera createCamera(Framebuffer framebuffer); 16 | 17 | COCOA void adjustPerspective(Camera& camera); 18 | COCOA void calculateViewMatrix(Entity entity, Camera& camera); 19 | COCOA void calculateOrthoViewMatrix(Entity entity, Camera& camera); 20 | 21 | COCOA void clearColorRgb(const Camera& camera, int attachment, glm::vec3 color); 22 | COCOA void clearColorUint32(Camera& camera, int attachment, uint32 color); 23 | 24 | COCOA glm::vec2 screenToOrtho(const Camera& camera); 25 | 26 | COCOA void serialize(json* j, Entity entity, const Camera& camera); 27 | COCOA void deserialize(const json& j, Entity entity); 28 | }; 29 | 30 | namespace CameraSystem 31 | { 32 | COCOA void update(SceneData& scene, float dt); 33 | COCOA void destroy(SceneData& scene); 34 | COCOA void deleteEntity(Entity entity); 35 | } 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/renderer/CameraStruct.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_CAMERA_STRUCT_H 2 | #define COCOA_ENGINE_CAMERA_STRUCT_H 3 | #include "externalLibs.h" 4 | #include "cocoa/renderer/Framebuffer.h" 5 | 6 | namespace Cocoa 7 | { 8 | struct Camera 9 | { 10 | // Projection/View matrices for ortho and perspective 11 | glm::mat4 viewMatrix; 12 | glm::mat4 inverseView; 13 | glm::mat4 projectionMatrix; 14 | glm::mat4 inverseProjection; 15 | 16 | glm::vec3 clearColor; 17 | glm::vec2 projectionSize; 18 | float projectionNearPlane; 19 | float projectionFarPlane; 20 | Framebuffer framebuffer; 21 | 22 | float fov = 45.0f; 23 | float aspect = 1920.0f / 1080.0f; 24 | float zoom = 1.0f; 25 | }; 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/renderer/DebugDraw.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_CAMERA_DEBUG_H 2 | #define COCOA_ENGINE_CAMERA_DEBUG_H 3 | #include "externalLibs.h" 4 | 5 | #include "cocoa/core/Handle.h" 6 | #include "cocoa/renderer/Texture.h" 7 | #include "cocoa/renderer/Camera.h" 8 | 9 | namespace Cocoa 10 | { 11 | namespace DebugDraw 12 | { 13 | COCOA void init(); 14 | COCOA void destroy(); 15 | 16 | COCOA void beginFrame(); 17 | COCOA void drawBottomBatches(const Camera& camera); 18 | COCOA void drawTopBatches(const Camera& camera); 19 | COCOA void addDebugObjectsToBatches(); 20 | COCOA void clearAllBatches(); 21 | 22 | COCOA void addLine2D( 23 | glm::vec2& from, 24 | glm::vec2& to, 25 | float strokeWidth = 1.2f, 26 | glm::vec3 color = { 0.0f, 1.0f, 0.0f }, 27 | int lifetime = 1, 28 | bool onTop = true 29 | ); 30 | 31 | COCOA void addBox2D( 32 | glm::vec2& center, 33 | glm::vec2& dimensions, 34 | float rotation = 0.0f, 35 | float strokeWidth = 0.01f, 36 | glm::vec3 color = { 0.0f, 1.0f, 0.0f }, 37 | int lifetime = 1, 38 | bool onTop = true 39 | ); 40 | 41 | COCOA void addFilledBox( 42 | const glm::vec2& center, 43 | const glm::vec2& dimensions, 44 | float rotation = 0.0f, 45 | const glm::vec3 color = { 0.0f, 1.0f, 0.0f }, 46 | int lifetime = 1, 47 | bool onTop = true 48 | ); 49 | 50 | COCOA void addSprite( 51 | Handle spriteTexture, 52 | glm::vec2 size, 53 | glm::vec2 position, 54 | glm::vec3 tint = { 1.0f, 1.0f, 1.0f }, 55 | glm::vec2 texCoordMin = { 0.0f, 1.0f }, 56 | glm::vec2 texCoordMax = { 1.0f, 0.0f }, 57 | float rotation = 0.0f, 58 | int lifetime = 1, 59 | bool onTop = true 60 | ); 61 | 62 | COCOA void addShape( 63 | const glm::vec2* vertices, 64 | int numVertices, 65 | int numElements, 66 | const glm::vec3& color, 67 | const glm::vec2& position, 68 | const glm::vec2& scale = { 1.0f, 1.0f }, 69 | float rotation = 0.0f, 70 | int lifetime = 1, 71 | bool onTop = true 72 | ); 73 | }; 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/renderer/DebugShape.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_DEBUG_SHAPE_H 2 | #define COCOA_ENGINE_DEBUG_SHAPE_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | 6 | namespace Cocoa 7 | { 8 | struct DebugShape 9 | { 10 | glm::vec2* vertices; 11 | int numVertices; 12 | int numElements; 13 | glm::vec3 color; 14 | glm::vec2 position; 15 | float rotation; 16 | int lifetime; 17 | bool onTop; 18 | }; 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/renderer/DebugSprite.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_DEBUG_SPRITE_H 2 | #define COCOA_ENGINE_DEBUG_SPRITE_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | 6 | #include "cocoa/core/Handle.h" 7 | #include "cocoa/renderer/Texture.h" 8 | 9 | namespace Cocoa 10 | { 11 | struct DebugSprite 12 | { 13 | Handle spriteTexture; 14 | glm::vec2 size; 15 | glm::vec2 position; 16 | glm::vec3 tint; 17 | glm::vec2 texCoordMin; 18 | glm::vec2 texCoordMax; 19 | float rotation; 20 | int lifetime; 21 | bool onTop; 22 | }; 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/renderer/Fonts/DataStructures.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_FONTS_DATA_STRUCTURES_H 2 | #define COCOA_ENGINE_FONTS_DATA_STRUCTURES_H 3 | 4 | namespace Cocoa 5 | { 6 | struct CharInfo 7 | { 8 | float ux0, uy0; 9 | float ux1, uy1; 10 | float advance; 11 | float bearingX, bearingY; 12 | float chScaleX, chScaleY; 13 | }; 14 | 15 | struct SdfBitmapContainer 16 | { 17 | int width, height; 18 | int xOff, yOff; 19 | float advance; 20 | float bearingX, bearingY; 21 | float chScaleX, chScaleY; 22 | unsigned char* bitmap; 23 | }; 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/renderer/Fonts/Font.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_FONT_H 2 | #define COCOA_ENGINE_FONT_H 3 | #include "cocoa/renderer/fonts/DataStructures.h" 4 | #include "cocoa/core/Handle.h" 5 | #include "cocoa/renderer/Texture.h" 6 | 7 | #include 8 | 9 | #undef CreateFont 10 | 11 | // TODO: I haven't tested changing this to a namespace 12 | // TODO: Test me thoroughly!!! 13 | namespace Cocoa 14 | { 15 | struct Font 16 | { 17 | std::filesystem::path path; 18 | Handle fontTexture; 19 | CharInfo* characterMap; 20 | int characterMapSize; 21 | int glyphRangeStart; 22 | int glyphRangeEnd; 23 | bool isDefault; 24 | bool isNull; 25 | 26 | COCOA static Font createFont(std::filesystem::path& resourcePath, bool isDefault = false); 27 | COCOA static Font createFont(); 28 | COCOA static Font nullFont(); 29 | 30 | COCOA const CharInfo& getCharacterInfo(int codepoint) const; 31 | COCOA void generateSdf(const std::filesystem::path& fontFile, int fontSize, const std::filesystem::path& outputFile, int glyphRangeStart = 0, int glyphRangeEnd = 'z' + 1, int padding = 5, int upscaleResolution = 4096); 32 | COCOA void free() const; 33 | 34 | COCOA json serialize() const; 35 | COCOA void deserialize(const json& j); 36 | }; 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/renderer/Fonts/FontUtil.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_FONT_UTIL_H 2 | #define COCOA_ENGINE_FONT_UTIL_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | 6 | #include "DataStructures.h" 7 | 8 | #include 9 | 10 | #include 11 | #include FT_FREETYPE_H 12 | 13 | namespace Cocoa 14 | { 15 | namespace FontUtil 16 | { 17 | COCOA int getPixel(int x, int y, uint8* bitmap, int width, int height); 18 | 19 | COCOA float findNearestPixel(int pixX, int pixY, uint8* bitmap, int width, int height, int spread); 20 | 21 | COCOA SdfBitmapContainer generateSdfCodepointBitmap(int codepoint, FT_Face font, int fontSize, int padding = 5, int upscaleResolution = 4096, bool flipVertically = false); 22 | 23 | COCOA void createSdfFontTexture(const std::filesystem::path& fontFile, int fontSize, CharInfo* characterMap, int characterMapSize, const std::filesystem::path& outputFile, 24 | int padding = 5, int upscaleResolution = 4096, int glyphOffset = 0); 25 | } 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/renderer/Framebuffer.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_FRAMEBUFFER_H 2 | #define COCOA_ENGINE_FRAMEBUFFER_H 3 | #include "cocoa/renderer/Texture.h" 4 | #include "cocoa/core/Handle.h" 5 | 6 | namespace Cocoa 7 | { 8 | struct Framebuffer 9 | { 10 | uint32 fbo = (uint32)-1; 11 | int32 width = 0; 12 | int32 height = 0; 13 | 14 | // Depth/Stencil attachment (optional) 15 | uint32 rbo = (uint32)-1; 16 | ByteFormat depthStencilFormat = ByteFormat::None; 17 | bool includeDepthStencil = true; 18 | 19 | // Color attachments 20 | std::vector colorAttachments; // TODO: All color attachments will be resized to match the framebuffer size (perhaps this should be changed in the future...?) 21 | }; 22 | 23 | namespace NFramebuffer 24 | { 25 | COCOA void destroy(Framebuffer& framebuffer, bool clearColorAttachmentSpecs = true); 26 | COCOA void generate(Framebuffer& framebuffer); 27 | COCOA void regenerate(Framebuffer& framebuffer); 28 | 29 | COCOA const Texture& getColorAttachment(const Framebuffer& framebuffer, int index); 30 | COCOA void addColorAttachment(Framebuffer& framebuffer, const Texture& textureSpec); // TODO: The order the attachments are added will be the index they get (change this in the future too...?) 31 | COCOA void clearColorAttachmentRgb(const Framebuffer& framebuffer, int colorAttachment, glm::vec3 clearColor); 32 | COCOA void clearColorAttachmentUint32(const Framebuffer& framebuffer, int colorAttachment, uint32 clearColor); 33 | COCOA uint32 readPixelUint32(const Framebuffer& framebuffer, int colorAttachment, int x, int y); 34 | 35 | COCOA void bind(const Framebuffer& framebuffer); 36 | COCOA void unbind(const Framebuffer& framebuffer); 37 | 38 | COCOA json serialize(const Framebuffer& framebuffer); 39 | COCOA Framebuffer deserialize(const json& j); 40 | }; 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/renderer/Line2D.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_LINE_2D_H 2 | #define COCOA_ENGINE_LINE_2D_H 3 | #include "externalLibs.h" 4 | 5 | #include "cocoa/core/Core.h" 6 | 7 | namespace Cocoa 8 | { 9 | struct Line2D 10 | { 11 | glm::vec3 color; 12 | glm::vec2 vertices[4]; 13 | float stroke; 14 | int lifetime; 15 | bool onTop; 16 | }; 17 | 18 | namespace NLine2D 19 | { 20 | COCOA Line2D create(glm::vec2 from, glm::vec2 to, glm::vec3 color, float stroke, int lifetime, bool onTop); 21 | } 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/renderer/RenderBatch.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_RENDERER_2D_H 2 | #define COCOA_ENGINE_RENDERER_2D_H 3 | #include "externalLibs.h" 4 | 5 | #include "cocoa/components/Transform.h" 6 | #include "cocoa/components/SpriteRenderer.h" 7 | #include "cocoa/components/FontRenderer.h" 8 | #include "cocoa/core/Handle.h" 9 | #include "cocoa/renderer/Texture.h" 10 | #include "cocoa/renderer/Shader.h" 11 | 12 | namespace Cocoa 13 | { 14 | namespace RenderBatch 15 | { 16 | const int TEXTURE_SIZE = 16; 17 | } 18 | 19 | struct Vertex 20 | { 21 | glm::vec3 position; 22 | glm::vec4 color; 23 | glm::vec2 texCoords; 24 | float texId; 25 | uint32 entityId; 26 | }; 27 | 28 | struct RenderBatchData 29 | { 30 | Handle batchShader; 31 | Vertex* vertexBufferBase; 32 | Vertex* vertexStackPointer; 33 | uint32* indices; 34 | Handle textures[RenderBatch::TEXTURE_SIZE]; 35 | 36 | uint32 vao, vbo, ebo; 37 | int16 zIndex; 38 | uint16 numUsedElements; 39 | uint16 numTextures; 40 | 41 | int maxBatchSize; 42 | bool batchOnTop; 43 | }; 44 | 45 | namespace RenderBatch 46 | { 47 | COCOA RenderBatchData createRenderBatch(int maxBatchSize, int zIndex, Handle shader, bool batchOnTop=false); 48 | COCOA void free(RenderBatchData& data); 49 | 50 | COCOA void clear(RenderBatchData& data); 51 | COCOA void start(RenderBatchData& data); 52 | COCOA void add(RenderBatchData& data, const TransformData& transform, const SpriteRenderer& spr); 53 | COCOA void add(RenderBatchData& data, const TransformData& transform, const FontRenderer& fontRenderer); 54 | COCOA void add(RenderBatchData& data, const glm::vec2* vertices, const glm::vec3& color, const glm::vec2& position={0.0f, 0.0f}, int numVertices=4, int numElements=6); 55 | 56 | COCOA void add( 57 | RenderBatchData& data, 58 | Handle textureHandle, 59 | const glm::vec3& position, 60 | const glm::vec3& scale, 61 | const glm::vec3& color, 62 | const glm::vec2& texCoordMin, 63 | const glm::vec2& texCoordMax, 64 | float rotation); 65 | 66 | COCOA void render(RenderBatchData& data); 67 | 68 | COCOA bool hasRoom(const RenderBatchData& data, int numVertices=4); 69 | COCOA bool hasRoom(const RenderBatchData& data, const FontRenderer& fontRenderer); 70 | COCOA bool hasTextureRoom(const RenderBatchData& data); 71 | 72 | COCOA bool compare(const RenderBatchData& b1, const RenderBatchData& b2); 73 | 74 | COCOA bool hasTexture(const RenderBatchData& data, Handle resourceId); 75 | }; 76 | } 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/renderer/Shader.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_SHADER_H 2 | #define COCOA_ENGINE_SHADER_H 3 | #include "externalLibs.h" 4 | 5 | #include 6 | 7 | typedef unsigned int GLuint; 8 | 9 | namespace Cocoa 10 | { 11 | struct Shader 12 | { 13 | uint32 programId; 14 | int startIndex; // This is the start index in the global shader variables vector 15 | bool isDefault; 16 | std::filesystem::path filepath; 17 | }; 18 | 19 | namespace NShader 20 | { 21 | COCOA Shader createShader(); 22 | COCOA Shader createShader(const std::filesystem::path& resourceName, bool isDefault=false); 23 | 24 | COCOA Shader compile(const std::filesystem::path& filepath, bool isDefault=false); 25 | COCOA void bind(const Shader& shader); 26 | COCOA void unbind(const Shader& shader); 27 | COCOA void destroy(Shader& shader); 28 | 29 | COCOA void uploadVec4(const Shader& shader, const char* varName, const glm::vec4& vec4); 30 | COCOA void uploadVec3(const Shader& shader, const char* varName, const glm::vec3& vec3); 31 | COCOA void uploadVec2(const Shader& shader, const char* varName, const glm::vec2& vec2); 32 | COCOA void uploadFloat(const Shader& shader, const char* varName, float value); 33 | COCOA void uploadInt(const Shader& shader, const char* varName, int value); 34 | COCOA void uploadIntArray(const Shader& shader, const char* varName, int size, const int* array); 35 | COCOA void uploadUInt(const Shader& shader, const char* varName, uint32 value); 36 | 37 | COCOA void uploadMat4(const Shader& shader, const char* varName, const glm::mat4& mat4); 38 | COCOA void uploadMat3(const Shader& shader, const char* varName, const glm::mat3& mat3); 39 | 40 | COCOA bool isNull(const Shader& shader); 41 | COCOA void clearAllShaderVariables(); 42 | }; 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/renderer/Texture.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_TEXTURE_H 2 | #define COCOA_ENGINE_TEXTURE_H 3 | #include "cocoa/core/Core.h" 4 | 5 | #include 6 | 7 | namespace Cocoa 8 | { 9 | enum class FilterMode 10 | { 11 | None=0, 12 | Linear, 13 | Nearest 14 | }; 15 | 16 | enum class WrapMode 17 | { 18 | None=0, 19 | Repeat 20 | }; 21 | 22 | enum class ByteFormat 23 | { 24 | None=0, 25 | RGBA, 26 | RGBA8, 27 | 28 | RGB, 29 | RGB8, 30 | 31 | R32UI, 32 | RED_INTEGER, 33 | 34 | // Depth/Stencil formats 35 | DEPTH24_STENCIL8 36 | }; 37 | 38 | struct COCOA Texture 39 | { 40 | uint32 graphicsId; 41 | int32 width; 42 | int32 height; 43 | 44 | // Texture attributes 45 | FilterMode magFilter; 46 | FilterMode minFilter; 47 | WrapMode wrapS; 48 | WrapMode wrapT; 49 | ByteFormat internalFormat; 50 | ByteFormat externalFormat; 51 | 52 | std::filesystem::path path; 53 | bool isDefault; 54 | }; 55 | 56 | namespace TextureUtil 57 | { 58 | // Namespace variables 59 | // NOTE: To make sure this variable is visible to other translation units, declare it as extern 60 | COCOA extern const Texture NULL_TEXTURE; 61 | 62 | // Namespace functions 63 | COCOA void bind(const Texture& texture); 64 | COCOA void unbind(const Texture& texture); 65 | COCOA void destroy(Texture& texture); 66 | 67 | // Loads a texture using stb library and generates a texutre using the filter/wrap modes and automatically detects 68 | // internal/external format, width, height, and alpha channel 69 | COCOA void generate(Texture& texture, const std::filesystem::path& filepath); 70 | 71 | // Allocates memory space on the GPU according to the texture specifications listed here 72 | COCOA void generate(Texture& texture); 73 | 74 | COCOA bool isNull(const Texture& texture); 75 | 76 | COCOA uint32 toGl(ByteFormat format); 77 | COCOA uint32 toGl(WrapMode wrapMode); 78 | COCOA uint32 toGl(FilterMode filterMode); 79 | COCOA uint32 toGlDataType(ByteFormat format); 80 | COCOA bool byteFormatIsInt(ByteFormat format); 81 | COCOA bool byteFormatIsRgb(ByteFormat format); 82 | 83 | COCOA json serialize(const Texture& texture); 84 | COCOA Texture deserialize(const json& j); 85 | 86 | COCOA Texture create(); 87 | }; 88 | } 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/scenes/Scene.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_SCENE_H 2 | #define COCOA_ENGINE_SCENE_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | 6 | #include "cocoa/events/Event.h" 7 | #include "cocoa/scenes/SceneData.h" 8 | 9 | #include 10 | 11 | namespace Cocoa 12 | { 13 | namespace Scene 14 | { 15 | COCOA SceneData create(SceneInitializer* sceneInitializer); 16 | 17 | COCOA void init(SceneData& data); 18 | COCOA void start(SceneData& data); 19 | COCOA void update(SceneData& data, float dt); 20 | COCOA void editorUpdate(SceneData& data, float dt); 21 | COCOA void onEvent(SceneData& data, const Event& e); 22 | COCOA void render(SceneData& data); 23 | COCOA void freeResources(SceneData& data); 24 | 25 | COCOA void play(SceneData& data); 26 | COCOA void stop(SceneData& data); 27 | COCOA void save(SceneData& data, const std::filesystem::path& filename); 28 | COCOA void load(SceneData& data, const std::filesystem::path& filename, bool setAsCurrentScene = true); 29 | COCOA void loadScriptsOnly(SceneData& data, const std::filesystem::path& filename); 30 | 31 | COCOA void serializeEntity(json* j, Entity entity); 32 | COCOA void deserializeEntities(const json& j, SceneData& scene); 33 | COCOA Entity createEntity(SceneData& data); 34 | COCOA Entity duplicateEntity(SceneData& data, Entity entity); 35 | COCOA Entity getEntity(SceneData& data, uint32 id); 36 | COCOA bool isValid(SceneData& scene, uint32 entityId); 37 | COCOA bool isValid(SceneData& scene, Entity entity); 38 | COCOA void deleteEntity(SceneData& data, Entity entity); 39 | }; 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/scenes/SceneData.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_SCENE_DATA_H 2 | #define COCOA_ENGINE_SCENE_DATA_H 3 | #include "cocoa/renderer/Shader.h" 4 | 5 | namespace Cocoa 6 | { 7 | class SceneInitializer; 8 | struct SceneData 9 | { 10 | bool isPlaying; 11 | entt::registry registry; 12 | json saveDataJson; 13 | 14 | SceneInitializer* currentSceneInitializer = nullptr; 15 | }; 16 | } 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/scenes/SceneInitializer.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_SCENE_INITIALIZER_H 2 | #define COCOA_ENGINE_SCENE_INITIALIZER_H 3 | #include "cocoa/core/Core.h" 4 | #include "externalLibs.h" 5 | 6 | #include "cocoa/scenes/SceneData.h" 7 | 8 | namespace Cocoa 9 | { 10 | class COCOA SceneInitializer 11 | { 12 | public: 13 | SceneInitializer() {} 14 | 15 | virtual void init(SceneData& scene) = 0; 16 | virtual void start(SceneData& scene) = 0; 17 | virtual void destroy(SceneData& scene) = 0; 18 | virtual void save(SceneData& scene) = 0; 19 | virtual void load(SceneData& scene) = 0; 20 | }; 21 | } 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/systems/RenderSystem.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_RENDER_SYSTEM_H 2 | #define COCOA_ENGINE_RENDER_SYSTEM_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | 6 | #include "cocoa/components/SpriteRenderer.h" 7 | #include "cocoa/components/FontRenderer.h" 8 | #include "cocoa/components/Transform.h" 9 | #include "cocoa/scenes/SceneData.h" 10 | 11 | namespace Cocoa 12 | { 13 | namespace RenderSystem 14 | { 15 | COCOA void init(); 16 | COCOA void destroy(); 17 | 18 | COCOA void addEntity(const TransformData& transform, const FontRenderer& fontRenderer); 19 | COCOA void addEntity(const TransformData& transform, const SpriteRenderer& spr); 20 | COCOA void render(const SceneData& scene); 21 | 22 | COCOA void serialize(json& j, Entity entity, const SpriteRenderer& spriteRenderer); 23 | COCOA void deserializeSpriteRenderer(const json& json, Entity entity); 24 | COCOA void serialize(json& j, Entity entity, const FontRenderer& fontRenderer); 25 | COCOA void deserializeFontRenderer(const json& json, Entity entity); 26 | }; 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/systems/ScriptSystem.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_SCRIPT_SYSTEM_H 2 | #define COCOA_ENGINE_SCRIPT_SYSTEM_H 3 | #include "externalLibs.h" 4 | #include "cocoa/core/Core.h" 5 | 6 | #include "cocoa/scenes/Scene.h" 7 | #include "cocoa/scenes/SceneData.h" 8 | 9 | namespace Cocoa 10 | { 11 | typedef void (*AddComponentFn)(entt::registry&, std::string, entt::entity); 12 | typedef void (*UpdateScriptFn)(entt::registry&, float); 13 | typedef void (*EditorUpdateScriptFn)(entt::registry&, float); 14 | typedef void (*SaveScriptsFn)(entt::registry&, json&, SceneData*); 15 | typedef void (*LoadScriptFn)(entt::registry&, const json&, Entity); 16 | typedef void (*InitScriptsFn)(SceneData*); 17 | typedef void (*InitImGuiFn)(void*); 18 | typedef void (*ImGuiFn)(entt::registry&, Entity); 19 | typedef void (*DeleteScriptsFn)(); 20 | typedef void (*NotifyBeginContactFn)(Entity, Entity); 21 | typedef void (*NotifyEndContactFn)(Entity, Entity); 22 | 23 | namespace ScriptSystem 24 | { 25 | COCOA void init(SceneData& scene); 26 | COCOA void update(SceneData& scene, float dt); 27 | COCOA void editorUpdate(SceneData& scene, float dt); 28 | 29 | COCOA void imGui(SceneData& scene, Entity entity); 30 | COCOA void initImGui(void* context); 31 | 32 | COCOA void notifyBeginContact(Entity entityA, Entity entityB); 33 | COCOA void notifyEndContact(Entity entityA, Entity entityB); 34 | 35 | COCOA void reload(SceneData& scene, bool deleteScriptComponents = false); 36 | COCOA void saveScripts(SceneData& scene, json& j); 37 | COCOA void deserialize(SceneData& scene, const json& j, Entity entity); 38 | 39 | COCOA bool freeScriptLibrary(SceneData& scene, bool deleteScriptComponents = false); 40 | COCOA void addComponentFromString(std::string className, entt::entity entity, entt::registry& registry); 41 | }; 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/systems/TransformSystem.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_TRANSFORM_SYSTEM_H 2 | #define COCOA_ENGINE_TRANSFORM_SYSTEM_H 3 | #include "externalLibs.h" 4 | #include "cocoa/scenes/SceneData.h" 5 | 6 | #include "cocoa/core/EntityStruct.h" 7 | 8 | namespace Cocoa 9 | { 10 | namespace TransformSystem 11 | { 12 | COCOA void update(SceneData& scene, float dt); 13 | COCOA void destroy(SceneData& scene); 14 | COCOA void deleteEntity(Entity entity); 15 | } 16 | } 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/util/CMath.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_CMATH_H 2 | #define COCOA_ENGINE_CMATH_H 3 | #include "externalLibs.h" 4 | 5 | // TODO: Find who's leaking min, max macros... 6 | #ifdef min 7 | #undef min 8 | #endif 9 | #ifdef max 10 | #undef max 11 | #endif 12 | 13 | namespace Cocoa 14 | { 15 | namespace CMath 16 | { 17 | // Float Comparison functions, using custom epsilon 18 | COCOA bool compare(float x, float y, float epsilon = std::numeric_limits::min()); 19 | COCOA bool compare(const glm::vec3& vec1, const glm::vec3& vec2, float epsilon = std::numeric_limits::min()); 20 | COCOA bool compare(const glm::vec2& vec1, const glm::vec2& vec2, float epsilon = std::numeric_limits::min()); 21 | COCOA bool compare(const glm::vec4& vec1, const glm::vec4& vec2, float epsilon = std::numeric_limits::min()); 22 | 23 | // Vector conversions 24 | COCOA glm::vec2 vector2From3(const glm::vec3& vec); 25 | COCOA glm::vec3 vector3From2(const glm::vec2& vec); 26 | 27 | // Math functions 28 | COCOA void rotate(glm::vec2& vec, float angleDeg, const glm::vec2& origin); 29 | COCOA void rotate(glm::vec3& vec, float angleDeg, const glm::vec3& origin); 30 | 31 | COCOA float toRadians(float degrees); 32 | COCOA float toDegrees(float radians); 33 | 34 | // Serialize math components 35 | COCOA json serialize(const std::string& name, const glm::vec4& vec); 36 | COCOA json serialize(const glm::vec4& vec); 37 | COCOA glm::vec4 deserializeVec4(const json& json); 38 | COCOA glm::vec4 deserializeVec4(const json& json, bool& success); 39 | COCOA json serialize(const std::string& name, const glm::vec3& vec); 40 | COCOA json serialize(const glm::vec3& vec); 41 | COCOA glm::vec3 deserializeVec3(const json& json); 42 | COCOA glm::vec3 deserializeVec3(const json& json, bool& success); 43 | COCOA json serialize(const std::string& name, const glm::vec2& vec); 44 | COCOA json serialize(const glm::vec2& vec); 45 | COCOA glm::vec2 deserializeVec2(const json& json); 46 | COCOA glm::vec2 deserializeVec2(const json& json, bool& success); 47 | 48 | // Map Ranges 49 | COCOA float mapRange(float val, float inMin, float inMax, float outMin, float outMax); 50 | 51 | // Max, Min impls 52 | COCOA int max(int a, int b); 53 | COCOA int min(int a, int b); 54 | COCOA float saturate(float val); 55 | 56 | // Hash Strings 57 | COCOA uint32 hashString(const char* str); 58 | } 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/util/JsonExtended.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_JSON_EXTENDED_H 2 | #define COCOA_ENGINE_JSON_EXTENDED_H 3 | #include "externalLibs.h" 4 | 5 | #include 6 | 7 | namespace Cocoa 8 | { 9 | namespace JsonExtended 10 | { 11 | COCOA void assignIfNotNull(const json& j, const char* property, uint8& val); 12 | COCOA void assignIfNotNull(const json& j, const char* property, uint16& val); 13 | COCOA void assignIfNotNull(const json& j, const char* property, uint32& val); 14 | COCOA void assignIfNotNull(const json& j, const char* property, int& val); 15 | COCOA void assignIfNotNull(const json& j, const char* property, float& val); 16 | COCOA void assignIfNotNull(const json& j, const char* property, bool& val); 17 | COCOA void assignIfNotNull(const json& j, const char* property, glm::vec2& vec); 18 | COCOA void assignIfNotNull(const json& j, const char* property, glm::vec3& vector); 19 | COCOA void assignIfNotNull(const json& j, const char* property, glm::vec4& vector); 20 | COCOA void assignIfNotNull(const json& j, const char* property, std::filesystem::path& path); 21 | 22 | template 23 | void assignEnumIfNotNull(const json& j, const char* property, T& enumValue) 24 | { 25 | if (j.contains(property) && j[property].is_number_integer()) 26 | { 27 | int enumAsInt = (int)j[property]; 28 | enumValue = (T)enumAsInt; 29 | } 30 | } 31 | } 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /CocoaEngine/include/cocoa/util/Settings.h: -------------------------------------------------------------------------------- 1 | #ifndef COCOA_ENGINE_SETTINGS_H 2 | #define COCOA_ENGINE_SETTINGS_H 3 | #include "externalLibs.h" 4 | 5 | #include 6 | 7 | namespace Cocoa 8 | { 9 | namespace Settings 10 | { 11 | namespace General 12 | { 13 | extern COCOA std::filesystem::path imGuiConfigPath; 14 | extern COCOA std::filesystem::path engineAssetsPath; 15 | extern COCOA std::filesystem::path engineExeDirectory; 16 | extern COCOA std::filesystem::path engineSourceDirectory; 17 | extern COCOA std::filesystem::path workingDirectory; 18 | extern COCOA std::filesystem::path currentProject; 19 | extern COCOA std::filesystem::path stylesDirectory; 20 | extern COCOA std::filesystem::path currentScene; 21 | extern COCOA std::filesystem::path editorSaveData; 22 | extern COCOA std::filesystem::path editorStyleData; 23 | extern COCOA std::filesystem::path editorStyle; 24 | }; 25 | 26 | namespace Physics2D 27 | { 28 | extern COCOA int velocityIterations; 29 | extern COCOA int positionIterations; 30 | extern COCOA float timestep; 31 | }; 32 | } 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /CocoaEngine/include/externalLibs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // =================================================================== 4 | // Json Library 5 | // =================================================================== 6 | #include 7 | using json = nlohmann::json; 8 | 9 | // =================================================================== 10 | // GLM 11 | // =================================================================== 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | // =================================================================== 24 | // Box2D 25 | // =================================================================== 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | // =================================================================== 34 | // Entt 35 | // =================================================================== 36 | #define ENTT_STANDARD_CPP 37 | #include 38 | 39 | // =================================================================== 40 | // Std Library 41 | // =================================================================== 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | 55 | // STB 56 | #include 57 | 58 | // Make sure to include windows before glfw 59 | #ifdef _WIN32 60 | #include 61 | #undef DeleteFile 62 | #undef CopyFile 63 | #undef CreateFile 64 | #undef GetSaveFileName 65 | #undef GetOpenFileName 66 | #endif 67 | 68 | // =================================================================== 69 | // GLFW & GLAD 70 | // =================================================================== 71 | #include 72 | #include 73 | 74 | // =================================================================== 75 | // Cpp Utils 76 | // =================================================================== 77 | #include 78 | using namespace CppUtils; 79 | 80 | // Some core defines and stuff 81 | #include "cocoa/core/Core.h" -------------------------------------------------------------------------------- /CocoaEngine/include/platform/windows/winMain.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "cocoa/core/Application.h" 4 | 5 | extern Cocoa::Application* Cocoa::createApplication(); 6 | 7 | int main() 8 | { 9 | using namespace Cocoa; 10 | 11 | Application* application = createApplication(); 12 | 13 | application->init(); 14 | 15 | application->run(); 16 | 17 | application->shutdown(); 18 | 19 | delete application; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /CocoaEngine/premake5.lua: -------------------------------------------------------------------------------- 1 | project "CocoaEngine" 2 | kind "SharedLib" 3 | language "C++" 4 | cppdialect "C++17" 5 | staticruntime "off" 6 | 7 | targetdir ("../bin/" .. outputdir .. "/%{prj.name}") 8 | objdir ("../bin-int/" .. outputdir .. "/%{prj.name}") 9 | 10 | files { 11 | "Cocoa.h", 12 | "cpp/**.cpp", 13 | "include/**.h", 14 | "../%{prj.name}/vendor/glmVendor/glm/**.hpp", 15 | "../%{prj.name}/vendor/glmVendor/glm/**.inl", 16 | "../%{prj.name}/vendor/nlohmann-json/single_include/**.hpp", 17 | } 18 | 19 | disablewarnings { 20 | "4251", 21 | "4131", 22 | "4267" 23 | } 24 | 25 | defines { 26 | "_CRT_SECURE_NO_WARNINGS", 27 | "NOMINMAX", 28 | "_COCOA_DLL", 29 | "GLFW_DLL", 30 | "_GABE_CPP_UTILS_EXPORT_DLL" 31 | } 32 | 33 | includedirs { 34 | "../%{prj.name}/include", 35 | "../%{prj.name}/vendor", 36 | "../%{IncludeDir.GLFW}", 37 | "../%{IncludeDir.Glad}", 38 | "../%{IncludeDir.Box2D}", 39 | "../%{IncludeDir.glm}", 40 | "../%{IncludeDir.stb}", 41 | "../%{IncludeDir.entt}", 42 | "../%{IncludeDir.Json}", 43 | "../%{IncludeDir.Freetype}", 44 | "../%{IncludeDir.CppUtils}" 45 | } 46 | 47 | links { 48 | "GLFW", 49 | "opengl32.lib", 50 | "Glad", 51 | "Box2D", 52 | "Freetype" 53 | } 54 | 55 | filter { "system:windows", "configurations:Debug" } 56 | buildoptions "/MDd" 57 | 58 | filter { "system:windows", "configurations:Release" } 59 | buildoptions "/MD" 60 | 61 | filter "system:windows" 62 | systemversion "latest" 63 | 64 | defines { 65 | "GLFW_INCLUDE_NONE", 66 | "JSON_MultipleHeaders" 67 | } 68 | 69 | postbuildcommands { 70 | "if not exist \"$(OutDir)..\\CocoaEditor\" mkdir \"$(OutDir)..\\CocoaEditor\"", 71 | "copy /y \"$(OutDir)CocoaEngine.dll\" \"$(OutDir)..\\CocoaEditor\\CocoaEngine.dll\"", 72 | "copy /y \"$(SolutionDir)CocoaEngine\\vendor\\GLFW\\bin\\%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}\\GLFW\\GLFW.dll\" \"$(OutDir)..\\CocoaEditor\\GLFW.dll\"" 73 | } 74 | 75 | filter "configurations:Debug" 76 | defines { 77 | "_COCOA_DEBUG", 78 | "_COCOA_ENABLE_ASSERTS" 79 | } 80 | runtime "Debug" 81 | symbols "on" 82 | 83 | 84 | filter "configurations:Release" 85 | defines "_COCOA_RELEASE" 86 | runtime "Release" 87 | optimize "on" 88 | 89 | 90 | filter "configurations:Dist" 91 | defines "_COCOA_DIST" 92 | runtime "Release" 93 | optimize "on" 94 | -------------------------------------------------------------------------------- /CocoaEngine/vendor/glad/premake5.lua: -------------------------------------------------------------------------------- 1 | project "Glad" 2 | kind "StaticLib" 3 | language "C" 4 | staticruntime "off" 5 | 6 | targetdir ("bin/" .. outputdir .. "/%{prj.name}") 7 | objdir ("bin-int/" .. outputdir .. "/%{prj.name}") 8 | 9 | files { 10 | "include/glad/glad.h", 11 | "include/KHR/khrplatform.h", 12 | "src/glad.c" 13 | } 14 | 15 | includedirs { 16 | "include" 17 | } 18 | 19 | filter { "system:windows", "configurations:Debug" } 20 | buildoptions "/MDd" 21 | 22 | filter { "system:windows", "configurations:Release" } 23 | buildoptions "/MD" 24 | 25 | filter "system:windows" 26 | systemversion "latest" 27 | 28 | filter "configurations:Debug" 29 | runtime "Debug" 30 | symbols "on" 31 | 32 | filter "configurations:Release" 33 | runtime "Release" 34 | optimize "on" 35 | -------------------------------------------------------------------------------- /Doxyfile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------- 2 | # Project related configuration options 3 | #--------------------------------------------------------------------------- 4 | 5 | DOXYFILE_ENCODING = UTF-8 6 | PROJECT_NAME = "Cocoa Engine" 7 | PROJECT_NUMBER = 1.0 8 | PROJECT_BRIEF = 2D Lite Game Engine 9 | 10 | PROJECT_LOGO = 11 | OUTPUT_DIRECTORY = ../CocoaEngineDocs/docs 12 | CREATE_SUBDIRS = NO 13 | 14 | GENERATE_TREEVIEW = YES 15 | HTML_HEADER = docs/header.html 16 | HTML_FOOTER = docs/footer.html 17 | 18 | ALLOW_UNICODE_NAMES = NO 19 | OUTPUT_LANGUAGE = English 20 | OUTPUT_TEXT_DIRECTION = None 21 | BRIEF_MEMBER_DESC = YES 22 | REPEAT_BRIEF = YES 23 | 24 | ABBREVIATE_BRIEF = "The $name class" \ 25 | "The $name widget" \ 26 | "The $name file" \ 27 | is \ 28 | provides \ 29 | specifies \ 30 | contains \ 31 | represents \ 32 | a \ 33 | an \ 34 | the 35 | 36 | ALWAYS_DETAILED_SEC = NO 37 | INLINE_INHERITED_MEMB = NO 38 | FULL_PATH_NAMES = YES 39 | SHORT_NAMES = NO 40 | JAVADOC_AUTOBRIEF = YES 41 | 42 | OPTIMIZE_OUTPUT_FOR_C = YES 43 | MARKDOWN_SUPPORT = YES 44 | TOC_INCLUDE_HEADINGS = 5 45 | AUTOLINK_SUPPORT = YES 46 | 47 | INPUT = CocoaEngine/ docs/README.cpp 48 | EXCLUDE_PATTERNS = */bin/* */bin-int/* */vendor/* 49 | RECURSIVE = YES 50 | 51 | EXTRACT_ALL = YES -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Gabriel Ambrosio 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Disclaimer 2 | 3 | This project is quite broken right now. You can explore it, and it should compile and run ok for the most part, but it's pretty broken and I'm not planning on working on it for awhile. 4 | 5 | # Cocoa Engine 6 | Welcome to Cocoa Engine, this is a 2D game engine independently developed by me, Gabe Ambrosio (AKA GamesWithGabe). The engine is currently in development, for the most recent stable build please follow the following steps on the *master* branch. 7 | 8 | ## Quickstart 9 | In order to run this, you'll have to run a few commands. First, open up a powershell window in a directory you would like to contain the engine source code. (The engine currently only supports Windows, so this will not work on Linux *yet*). 10 | 11 | Next run these commands: 12 | ``` 13 | git clone --recursive https://github.com/ambrosiogabe/Cocoa 14 | cd Cocoa 15 | build.bat vs2019 16 | ``` 17 | 18 | These commands will clone the repository into your directory, update the submodules (this step takes awhile because of all the code). 19 | 20 | Next, build freetype by doing: 21 | 22 | ``` 23 | cd CocoaEngine\vendor\freetypeVendor 24 | mkdir freetype2.compiled 25 | cd freetype2.compiled 26 | cmake .. 27 | ``` 28 | 29 | You'll also have to build it in the VS solution file. 30 | 31 | After that, simply double click the VisualStudio solution file that was (hopefully) generated, and then once it opens press F5 to run. This will compile *almost* all the projects, unfortunately I can't get FreeType to build in order ***yet***. So, for now, the build will fail the first time, then just right-click the ```freetype``` project in the right-hand panel in visual studio and click ```build```. 32 | 33 |
34 | How To Build FreeType VS2019 35 | 36 | ![BuildFreetype.png](img/buildFreetype.png) 37 | 38 |
39 | 40 | If all this works properly, you should be able to press F5 once again and then be presented with a window saying to create a project or open a Cocoa project. 41 | 42 | ***NOTE***: This only works with VisualStudio 2019 right now, I will add support for more versions and more editor hopefully in the near future. 43 | 44 | ## Feature Requests 45 | 46 | If you are using this and happen to have any features you would like to request, please submit an issue at: https://github.com/ambrosiogabe/Cocoa/issues . Prefix the title with FEATURE REQUEST, and provide as much information as possible. 47 | 48 | ## Bug Reporting 49 | 50 | This engine is still very much in development, there are no official releases yet, however bug reporting is still very helpful so I can keep track of everything. If you encounter any bugs please report them at the issues tab of the repository at: https://github.com/ambrosiogabe/Cocoa/issues . 51 | 52 | Follow this template when reporting the bug: 53 | 54 | ```markdown 55 | ## Describe the bug 56 | A clear and concise description of what the bug is. 57 | 58 | ## To Reproduce 59 | Steps to reproduce the behavior: 60 | 61 | 1. Go to '...' 62 | 2. Click on '....' 63 | 3. Scroll down to '....' 64 | 4. See error 65 | 66 | ## Expected behavior 67 | A clear and concise description of what you expected to happen. 68 | 69 | ## Screenshots 70 | If applicable, add screenshots to help explain your problem. 71 | 72 | ## Desktop (please complete the following information): 73 | OS: [e.g. Windows 10, Linux, MacOS] 74 | 75 | ## Additional context 76 | Add any other context about the problem here. 77 | ``` 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | IF "%~1" == "" GOTO PrintHelp 4 | IF "%~1" == "compile" GOTO Compile 5 | 6 | REM Build Freetype library using cmake 7 | IF EXIST CocoaEngine\vendor\freetypeVendor\freetype2.compiled GOTO GenerateProject 8 | mkdir CocoaEngine\vendor\freetypeVendor\freetype2.compiled 9 | pushd CocoaEngine\vendor\freetypeVendor\freetype2.compiled 10 | cmake ..\ 11 | popd 12 | REM CMake generates this folder for some reason, I'm just going to remove it... 13 | rmdir .\x64 14 | 15 | :GenerateProject 16 | REM Build the project files 17 | vendor\premake\premake5.exe %1 18 | GOTO Done 19 | 20 | :PrintHelp 21 | 22 | echo. 23 | echo Enter 'build.bat action' where action is one of the following: 24 | echo. 25 | echo compile Generate project files, then compile using project files 26 | echo clean Remove all binaries and intermediate binaries and project files. 27 | echo codelite Generate CodeLite project files 28 | echo gmake Generate GNU makefiles for Linux 29 | echo vs2005 Generate Visual Studio 2005 project files 30 | echo vs2008 Generate Visual Studio 2008 project files 31 | echo vs2010 Generate Visual Studio 2010 project files 32 | echo vs2012 Generate Visual Studio 2012 project files 33 | echo vs2013 Generate Visual Studio 2013 project files 34 | echo vs2015 Generate Visual Studio 2015 project files 35 | echo vs2017 Generate Visual Studio 2017 project files 36 | echo vs2019 Generate Visual Studio 2019 project files 37 | echo xcode4 Generate Apple Xcode 4 project files 38 | GOTO Done 39 | 40 | :Compile 41 | 42 | vendor\premake5.exe vs2019 43 | 44 | if not defined DevEnvDir ( 45 | call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat" 46 | ) 47 | 48 | set solutionFile="CocoaEngine.sln" 49 | msbuild /t:Build /p:Configuration=Debug /p:Platform=x64 %solutionFile% 50 | 51 | :Done -------------------------------------------------------------------------------- /docs/README.cpp: -------------------------------------------------------------------------------- 1 | 2 | /*! \mainpage Cocoa Engine Documentation 3 | * 4 | * \section intro_sec Introduction 5 | * 6 | * Welcome to Cocoa Engine Documentation. This file is a work in progress... 7 | * 8 | * \section install_sec Installation 9 | * 10 | * \subsection step1 Step 1: Opening the box 11 | * 12 | * etc... 13 | */ -------------------------------------------------------------------------------- /docs/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /docs/header.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | $projectname: $title 13 | 14 | 15 | $title 16 | 17 | 18 | 19 | 20 | $treeview 21 | $search 22 | $mathjax 23 | 24 | 25 | 26 | 27 | $extrastylesheet 28 | 29 | 30 | 31 |
32 | 33 | 34 | 35 |
36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 63 | 64 | 65 | 66 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 |
44 |
45 |
47 | $projectname 48 |
49 |  $projectnumber 50 | 51 |
52 | 53 |
$projectbrief
54 |
55 | 59 |

Toggle Dark Mode

60 |
61 | 62 |
67 |
$projectbrief
68 |
$searchbox
79 |
80 | 81 | -------------------------------------------------------------------------------- /img/buildFreetype.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/img/buildFreetype.png -------------------------------------------------------------------------------- /premake5.lua: -------------------------------------------------------------------------------- 1 | workspace "CocoaEngine" 2 | architecture "x64" 3 | 4 | configurations { 5 | "Debug", 6 | "Release", 7 | "Dist" 8 | } 9 | 10 | startproject "CocoaEditor" 11 | 12 | -- This is a helper variable, to concatenate the sys-arch 13 | outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}" 14 | 15 | IncludeDir = {} 16 | IncludeDir["GLFW"] = "CocoaEngine/vendor/GLFW/include" 17 | IncludeDir["Glad"] = "CocoaEngine/vendor/glad/include" 18 | IncludeDir["ImGui"] = "CocoaEngine/vendor/imguiVendor" 19 | IncludeDir["glm"] = "CocoaEngine/vendor/glmVendor" 20 | IncludeDir["stb"] = "CocoaEngine/vendor/stb" 21 | IncludeDir["entt"] = "CocoaEngine/vendor/enttVendor/src" 22 | IncludeDir["Box2D"] = "CocoaEngine/vendor/box2DVendor/include" 23 | IncludeDir["Json"] = "CocoaEngine/vendor/nlohmann-json/single_include" 24 | IncludeDir["Freetype"] = "CocoaEngine/vendor/freetypeVendor/include" 25 | IncludeDir["Libclang"] = "CocoaEditor/vendor/libclang/include" 26 | IncludeDir["CppUtils"] = "CocoaEngine/vendor/CppUtils/SingleInclude" 27 | 28 | include "CocoaEngine" 29 | include "CocoaEditor" 30 | 31 | include "CocoaEngine/vendor/GLFW" 32 | include "CocoaEngine/vendor/glad" 33 | include "CocoaEngine/vendor/imguiVendor" 34 | include "CocoaEngine/vendor/box2DVendor" 35 | 36 | externalproject "Freetype" 37 | location "CocoaEngine/vendor/freetypeVendor/freetype2.compiled" 38 | uuid "55FB27B1-C655-3244-9BAA-DDACB0BD93F7" 39 | kind "SharedLib" 40 | language "C" 41 | -------------------------------------------------------------------------------- /vendor/premake/premake5.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/Cocoa/c66539149c9963e354daba9dfd4ec444ca135b48/vendor/premake/premake5.exe --------------------------------------------------------------------------------