Browse Source

Convert GameLib to use new export feature

* Re-organize ImGui module
master
Macoy Madson 1 month ago
parent
commit
c175669db9
  1. 242
      src/ImGui.cake
  2. 2
      src/OpenGL.cake
  3. 3
      src/ProfilerAutoInstrument.cake
  4. 4
      src/ProfilerNull.cake
  5. 17
      src/SDL.cake
  6. 14
      src/Tracy.cake
  7. 4
      test/src/GameLibTests.cake
  8. 3
      test/src/Loader.cake
  9. 2
      test/src/SDLOgreApp.cake
  10. 5
      test/src/VocalGame.cake

242
src/ImGui.cake

@ -1,18 +1,7 @@
(import &comptime-only "Dependencies.cake" "CHelpers.cake")
;; (c-import &with-decls "imgui.h")
(c-import "imgui.h")
(add-c-search-directory-module "Dependencies/imgui")
(add-cpp-build-dependency "imgui.cpp"
"imgui_draw.cpp"
"imgui_tables.cpp"
"imgui_widgets.cpp")
(add-dependency-git-submodule clone-imgui "https://github.com/ocornut/imgui"
"Dependencies/imgui"
"docking")
(defmacro imgui-call (function symbol &rest &optional arguments any)
(if arguments
(tokenize-push output
@ -21,116 +10,6 @@
(call (in ImGui (token-splice function)))))
(return true))
(defun imgui-set-style-red-dark ()
;; copied and modified from https://github.com/ocornut/imgui/issues/707
(var colors (* ImVec4) (field (imgui-call GetStyle) Colors))
(set (at ImGuiCol_Text colors) (ImVec4 0.75f 0.75f 0.75f 1.00f))
(set (at ImGuiCol_TextDisabled colors) (ImVec4 0.35f 0.35f 0.35f 1.00f))
(set (at ImGuiCol_WindowBg colors) (ImVec4 0.00f 0.00f 0.00f 0.94f))
(set (at ImGuiCol_ChildBg colors) (ImVec4 0.00f 0.00f 0.00f 0.00f))
(set (at ImGuiCol_PopupBg colors) (ImVec4 0.08f 0.08f 0.08f 0.94f))
(set (at ImGuiCol_Border colors) (ImVec4 0.00f 0.00f 0.00f 0.50f))
(set (at ImGuiCol_BorderShadow colors) (ImVec4 0.00f 0.00f 0.00f 0.00f))
(set (at ImGuiCol_FrameBg colors) (ImVec4 0.25f 0.25f 0.25f 0.54f))
(set (at ImGuiCol_FrameBgHovered colors) (ImVec4 0.37f 0.14f 0.14f 0.67f))
(set (at ImGuiCol_FrameBgActive colors) (ImVec4 0.39f 0.20f 0.20f 0.67f))
(set (at ImGuiCol_TitleBg colors) (ImVec4 0.04f 0.04f 0.04f 1.00f))
(set (at ImGuiCol_TitleBgActive colors) (ImVec4 0.48f 0.16f 0.16f 1.00f))
(set (at ImGuiCol_TitleBgCollapsed colors) (ImVec4 0.48f 0.16f 0.16f 1.00f))
(set (at ImGuiCol_MenuBarBg colors) (ImVec4 0.14f 0.14f 0.14f 1.00f))
(set (at ImGuiCol_ScrollbarBg colors) (ImVec4 0.02f 0.02f 0.02f 0.53f))
(set (at ImGuiCol_ScrollbarGrab colors) (ImVec4 0.31f 0.31f 0.31f 1.00f))
(set (at ImGuiCol_ScrollbarGrabHovered colors) (ImVec4 0.41f 0.41f 0.41f 1.00f))
(set (at ImGuiCol_ScrollbarGrabActive colors) (ImVec4 0.51f 0.51f 0.51f 1.00f))
(set (at ImGuiCol_CheckMark colors) (ImVec4 0.56f 0.10f 0.10f 1.00f))
(set (at ImGuiCol_SliderGrab colors) (ImVec4 1.00f 0.19f 0.19f 0.40f))
(set (at ImGuiCol_SliderGrabActive colors) (ImVec4 0.89f 0.00f 0.19f 1.00f))
(set (at ImGuiCol_Button colors) (ImVec4 1.00f 0.19f 0.19f 0.40f))
(set (at ImGuiCol_ButtonHovered colors) (ImVec4 0.80f 0.17f 0.00f 1.00f))
(set (at ImGuiCol_ButtonActive colors) (ImVec4 0.89f 0.00f 0.19f 1.00f))
(set (at ImGuiCol_Header colors) (ImVec4 0.33f 0.35f 0.36f 0.53f))
(set (at ImGuiCol_HeaderHovered colors) (ImVec4 0.76f 0.28f 0.44f 0.67f))
(set (at ImGuiCol_HeaderActive colors) (ImVec4 0.47f 0.47f 0.47f 0.67f))
(set (at ImGuiCol_Separator colors) (ImVec4 0.32f 0.32f 0.32f 1.00f))
(set (at ImGuiCol_SeparatorHovered colors) (ImVec4 0.32f 0.32f 0.32f 1.00f))
(set (at ImGuiCol_SeparatorActive colors) (ImVec4 0.32f 0.32f 0.32f 1.00f))
(set (at ImGuiCol_ResizeGrip colors) (ImVec4 1.00f 1.00f 1.00f 0.85f))
(set (at ImGuiCol_ResizeGripHovered colors) (ImVec4 1.00f 1.00f 1.00f 0.60f))
(set (at ImGuiCol_ResizeGripActive colors) (ImVec4 1.00f 1.00f 1.00f 0.90f))
(set (at ImGuiCol_Tab colors) (ImVec4 0.07f 0.07f 0.07f 0.51f))
(set (at ImGuiCol_TabHovered colors) (ImVec4 0.86f 0.23f 0.43f 0.67f))
(set (at ImGuiCol_TabActive colors) (ImVec4 0.19f 0.19f 0.19f 0.57f))
(set (at ImGuiCol_TabUnfocused colors) (ImVec4 0.05f 0.05f 0.05f 0.90f))
(set (at ImGuiCol_TabUnfocusedActive colors) (ImVec4 0.13f 0.13f 0.13f 0.74f))
(set (at ImGuiCol_DockingPreview colors) (ImVec4 0.47f 0.47f 0.47f 0.47f))
(set (at ImGuiCol_DockingEmptyBg colors) (ImVec4 0.20f 0.20f 0.20f 1.00f))
(set (at ImGuiCol_PlotLines colors) (ImVec4 0.61f 0.61f 0.61f 1.00f))
(set (at ImGuiCol_PlotLinesHovered colors) (ImVec4 1.00f 0.43f 0.35f 1.00f))
(set (at ImGuiCol_PlotHistogram colors) (ImVec4 0.90f 0.70f 0.00f 1.00f))
(set (at ImGuiCol_PlotHistogramHovered colors) (ImVec4 1.00f 0.60f 0.00f 1.00f))
(set (at ImGuiCol_TableHeaderBg colors) (ImVec4 0.19f 0.19f 0.20f 1.00f))
(set (at ImGuiCol_TableBorderStrong colors) (ImVec4 0.31f 0.31f 0.35f 1.00f))
(set (at ImGuiCol_TableBorderLight colors) (ImVec4 0.23f 0.23f 0.25f 1.00f))
(set (at ImGuiCol_TableRowBg colors) (ImVec4 0.00f 0.00f 0.00f 0.00f))
(set (at ImGuiCol_TableRowBgAlt colors) (ImVec4 1.00f 1.00f 1.00f 0.07f))
(set (at ImGuiCol_TextSelectedBg colors) (ImVec4 0.26f 0.59f 0.98f 0.35f))
(set (at ImGuiCol_DragDropTarget colors) (ImVec4 1.00f 1.00f 0.00f 0.90f))
(set (at ImGuiCol_NavHighlight colors) (ImVec4 0.26f 0.59f 0.98f 1.00f))
(set (at ImGuiCol_NavWindowingHighlight colors) (ImVec4 1.00f 1.00f 1.00f 0.70f))
(set (at ImGuiCol_NavWindowingDimBg colors) (ImVec4 0.80f 0.80f 0.80f 0.20f))
(set (at ImGuiCol_ModalWindowDimBg colors) (ImVec4 0.80f 0.80f 0.80f 0.35f)))
(comptime-cond
('auto-test
(imgui-use-sdl-gl3)
(c-import "<cstdio>")
(make-imgui-sdl-gl3-application ;; If you want your own entry point, check this macro's body
test--imgui-main
"GameLib ImGui test"
(scope (fprintf stderr "Initializing\n")) ;; Initialization
(scope ;; Once per frame
(imgui-call ShowDemoWindow))
(scope (fprintf stderr "Shut down\n"))))) ;; Shutdown
;; Different loaders are available. Loader selection is done via macro to allow that flexibility
(defmacro imgui-use-sdl-gl3 ()
(tokenize-push output
(import "OpenGL.cake")
(import "SDL.cake")
(c-import "SDL.h"
"imgui_impl_sdl.h" ;; Platform (inputs etc.)
"imgui_impl_opengl3.h") ;; Rendering
;; From ImGuiSDLOpenGL.cpp
(declare-extern-function ImGuiSDLOpenGL_SetAttributes (glsl-version (* (* (const char)))))
(declare-extern-function ImGuiSDLOpenGL_InitializeGLLoader (&return bool))
(declare-extern-function ImGuiSDLOpenGL_ClearWindow (io (* ImGuiIO) clear-color ImVec4))
;; TODO This is a hack: add build output dir as search directory. Should be built in?
(defun-comptime add-search-build-directory (manager (& ModuleManager) module (* Module)
&return bool)
(call-on push_back (path module > cSearchDirectories)
(call-on c_str (field manager buildOutputDir)))
(return true))
(add-compile-time-hook-module pre-build add-search-build-directory)
(add-c-search-directory-module
"Dependencies/gamelib/src"
"Dependencies/imgui"
"Dependencies/imgui/backends")
(add-cpp-build-dependency "imgui_demo.cpp" "imgui_impl_sdl.cpp"
"ImGuiSDLOpenGL.cpp" "imgui_impl_opengl3.cpp")
(comptime-cond
('Unix
(add-library-dependency "GL" "dl"))
('Windows
(add-linker-options "opengl32.lib")))
(module-use-sdl-build-options))
(return true))
;; When you just don't care about the details and want a ImGui window
(defmacro make-imgui-sdl-gl3-application (entry-point-name symbol
window-name string
@ -269,3 +148,124 @@
(sdl-shutdown window)
(return 0)))
(return true))
(defun imgui-set-style-red-dark ()
;; copied and modified from https://github.com/ocornut/imgui/issues/707
(var colors (* ImVec4) (field (imgui-call GetStyle) Colors))
(set (at ImGuiCol_Text colors) (ImVec4 0.75f 0.75f 0.75f 1.00f))
(set (at ImGuiCol_TextDisabled colors) (ImVec4 0.35f 0.35f 0.35f 1.00f))
(set (at ImGuiCol_WindowBg colors) (ImVec4 0.00f 0.00f 0.00f 0.94f))
(set (at ImGuiCol_ChildBg colors) (ImVec4 0.00f 0.00f 0.00f 0.00f))
(set (at ImGuiCol_PopupBg colors) (ImVec4 0.08f 0.08f 0.08f 0.94f))
(set (at ImGuiCol_Border colors) (ImVec4 0.00f 0.00f 0.00f 0.50f))
(set (at ImGuiCol_BorderShadow colors) (ImVec4 0.00f 0.00f 0.00f 0.00f))
(set (at ImGuiCol_FrameBg colors) (ImVec4 0.25f 0.25f 0.25f 0.54f))
(set (at ImGuiCol_FrameBgHovered colors) (ImVec4 0.37f 0.14f 0.14f 0.67f))
(set (at ImGuiCol_FrameBgActive colors) (ImVec4 0.39f 0.20f 0.20f 0.67f))
(set (at ImGuiCol_TitleBg colors) (ImVec4 0.04f 0.04f 0.04f 1.00f))
(set (at ImGuiCol_TitleBgActive colors) (ImVec4 0.48f 0.16f 0.16f 1.00f))
(set (at ImGuiCol_TitleBgCollapsed colors) (ImVec4 0.48f 0.16f 0.16f 1.00f))
(set (at ImGuiCol_MenuBarBg colors) (ImVec4 0.14f 0.14f 0.14f 1.00f))
(set (at ImGuiCol_ScrollbarBg colors) (ImVec4 0.02f 0.02f 0.02f 0.53f))
(set (at ImGuiCol_ScrollbarGrab colors) (ImVec4 0.31f 0.31f 0.31f 1.00f))
(set (at ImGuiCol_ScrollbarGrabHovered colors) (ImVec4 0.41f 0.41f 0.41f 1.00f))
(set (at ImGuiCol_ScrollbarGrabActive colors) (ImVec4 0.51f 0.51f 0.51f 1.00f))
(set (at ImGuiCol_CheckMark colors) (ImVec4 0.56f 0.10f 0.10f 1.00f))
(set (at ImGuiCol_SliderGrab colors) (ImVec4 1.00f 0.19f 0.19f 0.40f))
(set (at ImGuiCol_SliderGrabActive colors) (ImVec4 0.89f 0.00f 0.19f 1.00f))
(set (at ImGuiCol_Button colors) (ImVec4 1.00f 0.19f 0.19f 0.40f))
(set (at ImGuiCol_ButtonHovered colors) (ImVec4 0.80f 0.17f 0.00f 1.00f))
(set (at ImGuiCol_ButtonActive colors) (ImVec4 0.89f 0.00f 0.19f 1.00f))
(set (at ImGuiCol_Header colors) (ImVec4 0.33f 0.35f 0.36f 0.53f))
(set (at ImGuiCol_HeaderHovered colors) (ImVec4 0.76f 0.28f 0.44f 0.67f))
(set (at ImGuiCol_HeaderActive colors) (ImVec4 0.47f 0.47f 0.47f 0.67f))
(set (at ImGuiCol_Separator colors) (ImVec4 0.32f 0.32f 0.32f 1.00f))
(set (at ImGuiCol_SeparatorHovered colors) (ImVec4 0.32f 0.32f 0.32f 1.00f))
(set (at ImGuiCol_SeparatorActive colors) (ImVec4 0.32f 0.32f 0.32f 1.00f))
(set (at ImGuiCol_ResizeGrip colors) (ImVec4 1.00f 1.00f 1.00f 0.85f))
(set (at ImGuiCol_ResizeGripHovered colors) (ImVec4 1.00f 1.00f 1.00f 0.60f))
(set (at ImGuiCol_ResizeGripActive colors) (ImVec4 1.00f 1.00f 1.00f 0.90f))
(set (at ImGuiCol_Tab colors) (ImVec4 0.07f 0.07f 0.07f 0.51f))
(set (at ImGuiCol_TabHovered colors) (ImVec4 0.86f 0.23f 0.43f 0.67f))
(set (at ImGuiCol_TabActive colors) (ImVec4 0.19f 0.19f 0.19f 0.57f))
(set (at ImGuiCol_TabUnfocused colors) (ImVec4 0.05f 0.05f 0.05f 0.90f))
(set (at ImGuiCol_TabUnfocusedActive colors) (ImVec4 0.13f 0.13f 0.13f 0.74f))
(set (at ImGuiCol_DockingPreview colors) (ImVec4 0.47f 0.47f 0.47f 0.47f))
(set (at ImGuiCol_DockingEmptyBg colors) (ImVec4 0.20f 0.20f 0.20f 1.00f))
(set (at ImGuiCol_PlotLines colors) (ImVec4 0.61f 0.61f 0.61f 1.00f))
(set (at ImGuiCol_PlotLinesHovered colors) (ImVec4 1.00f 0.43f 0.35f 1.00f))
(set (at ImGuiCol_PlotHistogram colors) (ImVec4 0.90f 0.70f 0.00f 1.00f))
(set (at ImGuiCol_PlotHistogramHovered colors) (ImVec4 1.00f 0.60f 0.00f 1.00f))
(set (at ImGuiCol_TableHeaderBg colors) (ImVec4 0.19f 0.19f 0.20f 1.00f))
(set (at ImGuiCol_TableBorderStrong colors) (ImVec4 0.31f 0.31f 0.35f 1.00f))
(set (at ImGuiCol_TableBorderLight colors) (ImVec4 0.23f 0.23f 0.25f 1.00f))
(set (at ImGuiCol_TableRowBg colors) (ImVec4 0.00f 0.00f 0.00f 0.00f))
(set (at ImGuiCol_TableRowBgAlt colors) (ImVec4 1.00f 1.00f 1.00f 0.07f))
(set (at ImGuiCol_TextSelectedBg colors) (ImVec4 0.26f 0.59f 0.98f 0.35f))
(set (at ImGuiCol_DragDropTarget colors) (ImVec4 1.00f 1.00f 0.00f 0.90f))
(set (at ImGuiCol_NavHighlight colors) (ImVec4 0.26f 0.59f 0.98f 1.00f))
(set (at ImGuiCol_NavWindowingHighlight colors) (ImVec4 1.00f 1.00f 1.00f 0.70f))
(set (at ImGuiCol_NavWindowingDimBg colors) (ImVec4 0.80f 0.80f 0.80f 0.20f))
(set (at ImGuiCol_ModalWindowDimBg colors) (ImVec4 0.80f 0.80f 0.80f 0.35f)))
;;
;; Building
;;
(add-dependency-git-submodule clone-imgui "https://github.com/ocornut/imgui"
"Dependencies/imgui"
"docking")
(export-and-evaluate
;; Different loaders are available. Loader selection could be done via macro to allow that flexibility
(import "OpenGL.cake")
(import "SDL.cake")
(c-import "SDL.h"
"imgui_impl_sdl.h" ;; Platform (inputs etc.)
"imgui_impl_opengl3.h") ;; Rendering
;; From ImGuiSDLOpenGL.cpp
(declare-extern-function ImGuiSDLOpenGL_SetAttributes (glsl-version (* (* (const char)))))
(declare-extern-function ImGuiSDLOpenGL_InitializeGLLoader (&return bool))
(declare-extern-function ImGuiSDLOpenGL_ClearWindow (io (* ImGuiIO) clear-color ImVec4))
;; TODO This is a hack: add build output dir as search directory. Should be built in?
(defun-comptime add-search-build-directory (manager (& ModuleManager) module (* Module)
&return bool)
(call-on push_back (path module > cSearchDirectories)
(call-on c_str (field manager buildOutputDir)))
(return true))
(add-compile-time-hook-module pre-build add-search-build-directory)
(add-c-search-directory-module
"Dependencies/gamelib/src"
"Dependencies/imgui"
"Dependencies/imgui/backends")
(add-cpp-build-dependency "imgui_impl_sdl.cpp" "ImGuiSDLOpenGL.cpp" "imgui_impl_opengl3.cpp")
(comptime-cond
('Unix
(add-library-dependency "GL" "dl"))
('Windows
(add-linker-options "opengl32.lib"))))
(add-cpp-build-dependency "imgui.cpp"
"imgui_demo.cpp"
"imgui_draw.cpp"
"imgui_tables.cpp"
"imgui_widgets.cpp")
;;
;; Testing
;;
(comptime-cond
('auto-test
(c-import "<stdio.h>")
(make-imgui-sdl-gl3-application ;; If you want your own entry point, check this macro's body
test--imgui-main
"GameLib ImGui test"
(scope (fprintf stderr "Initializing\n")) ;; Initialization
(scope ;; Once per frame
(imgui-call ShowDemoWindow))
(scope (fprintf stderr "Shut down\n"))))) ;; Shutdown

2
src/OpenGL.cake

@ -159,8 +159,6 @@ void main()\n
;; Building
;;
(module-use-sdl-build-options)
(comptime-cond
('Unix
(add-library-dependency "GL" "dl"))

3
src/ProfilerAutoInstrument.cake

@ -100,8 +100,7 @@
(call-on find modules-with-import (field definition-to-replace source-file))))
(tokenize-push (deref new-definition)
;; TODO: Allow the client to define which profiler to use
(import "Tracy.cake")
(module-use-tracy-build-options))
(import "Tracy.cake"))
(set (at (field definition-to-replace source-file) modules-with-import) 1))
(tokenize-push (deref new-definition)

4
src/ProfilerNull.cake

@ -12,8 +12,4 @@
(defmacro timing-zone-stop (varname symbol)
(return true))
;; TODO Remove the need to specify this in every module anyways
(defmacro module-use-tracy-build-options ()
(return true))
(var-global unused int 0)

17
src/SDL.cake

@ -319,17 +319,12 @@ Note that you can also build SDL manually. This can be useful if you are porting
(add-dependency-git-submodule clone-sdl2 "https://github.com/libsdl-org/SDL" "Dependencies/SDL")
(add-compile-time-hook-module pre-build build-sdl)
;; For now, an easy way to build files which include SDL headers
(defmacro module-use-sdl-build-options ()
(tokenize-push output
(comptime-cond
('Windows
(add-c-search-directory-module "Dependencies/SDL/include"))
('Unix
(add-c-search-directory-module "Dependencies/SDL/buildSDLBuild/include/SDL2"))))
(return true))
(module-use-sdl-build-options)
(export-and-evaluate
(comptime-cond
('Windows
(add-c-search-directory-module "Dependencies/SDL/include"))
('Unix
(add-c-search-directory-module "Dependencies/SDL/buildSDLBuild/include/SDL2"))))
;; TODO: Add debug version
(comptime-cond

14
src/Tracy.cake

@ -106,16 +106,10 @@
(add-dependency-git-submodule clone-tracy "https://github.com/wolfpld/tracy" "Dependencies/tracy")
(add-compile-time-hook-module pre-build build-tracy-profiler)
;; TODO: Any file which includes Tracy needs these
;; For now, an easy way to build files which include necessary headers
(defmacro module-use-tracy-build-options ()
(tokenize-push output
(add-build-options "-DTRACY_ENABLE")
;; (add-build-options "-DTRACY_CALLSTACK=10") ;; TODO: Causes exit code 134, failing in tracy alloc
(add-c-search-directory-module "Dependencies/tracy"))
(return true))
(module-use-tracy-build-options)
(export-and-evaluate
(add-build-options "-DTRACY_ENABLE")
;; (add-build-options "-DTRACY_CALLSTACK=10") ;; TODO: Causes exit code 134, failing in tracy alloc
(add-c-search-directory-module "Dependencies/tracy"))
(add-c-search-directory-module "Dependencies/tracy")
(add-cpp-build-dependency "TracyClient.cpp")

4
test/src/GameLibTests.cake

@ -37,8 +37,8 @@
(true
"src/Config_Linux.cake")))
(var test-minimal bool true)
;; (var test-minimal bool false)
;; (var test-minimal bool true)
(var test-minimal bool false)
;; (var test-opengl-only bool true)
(var test-opengl-only bool false)

3
test/src/Loader.cake

@ -12,8 +12,7 @@
;; TODO: Tracy gets confused when the reloaded lib has its own version of Tracy
(ignore
(add-cakelisp-search-directory "src")
(import "Tracy.cake")
(module-use-tracy-build-options))
(import "Tracy.cake"))
;; We only want the shared libraries these use
;; (import "src/Ogre.cake"

2
test/src/SDLOgreApp.cake

@ -8,8 +8,6 @@
(add-c-search-directory-module ".")
(c-import "SDL.h" "SDL_syswm.h" "SDL_timer.h")
;; TODO: Somehow inherit this from SDL.cake?
(module-use-sdl-build-options)
(defun main (&return int)
(var window (* SDL_Window) null)

5
test/src/VocalGame.cake

@ -685,12 +685,7 @@
;; Building
;;
;; TODO: Somehow inherit this from SDL.cake?
(module-use-sdl-build-options)
(use-ogre-build-options) ;; Only needed for the dependency
(add-cpp-build-dependency "OgreHlms.cpp")
(module-use-tracy-build-options)
(import &comptime-only "Dependencies.cake")

Loading…
Cancel
Save