GameLib is a collection of libraries for creating applications in Cakelisp.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.9 KiB

(set-cakelisp-option cakelisp-src-dir "Dependencies/cakelisp/src")
(add-cakelisp-search-directory "Dependencies/cakelisp/runtime")
(import "ComptimeHelpers.cake" "Dependencies.cake" "BuildTools.cake")
(c-import &with-decls "Tracy.hpp" "TracyC.h")
(defmacro scope-timed (scope-label string &rest body any)
(tokenize-push output
(ZoneScopedN (token-splice scope-label))
(token-splice-rest body tokens)))
(return true))
;; TODO: Move into Profiler.cake?
(defmacro time-this-scope (varname symbol &optional name string)
(if name
(tokenize-push output (ZoneNamedN (token-splice varname name) 1))
;; Doesn't work. Why not?
(tokenize-push output (ZoneNamed (token-splice varname) 1)))
(return true))
;; This needed to be a generator to output "FrameMark;" with no parens.
(defgenerator profiler-mark-frame (&optional name (arg-index string))
(if (!= -1 name)
(var define-statement (const ([] CStatementOperation))
(array KeywordNoSpace "FrameMarkNamed" -1)
(array OpenParen null -1)
(array Expression null 1)
(array CloseParen null -1)
(array SmartEndStatement null -1)))
(return (c-statement-out define-statement)))
(var define-statement (const ([] CStatementOperation))
(array KeywordNoSpace "FrameMark" -1)
(array SmartEndStatement null -1)))
(return (c-statement-out define-statement))))
(return true))
(defmacro timing-zone-start (varname symbol name string)
(tokenize-push output (TracyCZoneN (token-splice varname name) 1))
(return true))
(defmacro timing-zone-stop (varname symbol)
(tokenize-push output (TracyCZoneEnd (token-splice varname)))
(return true))
;; Testing
;; TODO: Linux only
(c-import "unistd.h")
(defun test--tracy-main (&return int)
(ZoneScopedN "main")
(fprintf stderr "Waiting for profiler to connect...\n")
(while (not (call-on IsConnected (call (in tracy GetProfiler))))
(ZoneScopedN "wait for profiler")
(sleep 1))
(var i int 0)
(var num-times (const int) 10)
(while (< i num-times)
(ZoneScopedN "hot loop")
(fprintf stderr "hot loop %d / %d\n" i num-times)
(sleep 1)
(incr i))
(return 0))))
;; Building
;; Note that Tracy does not need to be built for the final executable. It's an external tool
(defun-comptime build-tracy-profiler (manager (& ModuleManager) module (* Module) &return bool)
(comptime-error "Tracy build needs to be ported to Windows. See manual at"))
(when (fileExists "Dependencies/tracy/profiler/build/unix/Tracy-release")
(return true))
("make" "-j4" :in-directory "Dependencies/tracy/profiler/build/unix")
(Log "error: failed to build Tracy profiler. Check the manual at
If this was a build after an update, delete the Dependencies/tracy/profiler/build/unix/obj/ directory
and try again")
(return false))
;; Final check
(when (fileExists "Dependencies/tracy/profiler/build/unix/Tracy-release")
(return true))))
(Log "error: did not build Tracy profiler. Is this platform unsupported? Was Tracy built in an
unexpected location?")
(return false))
(add-dependency-git-submodule clone-tracy "" "Dependencies/tracy")
(add-compile-time-hook-module pre-build build-tracy-profiler)
(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")
(add-library-dependency "pthread" "dl")))
(add-build-config-label "Profile")