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
(scope
(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)
(scope
(var define-statement (const ([] CStatementOperation))
(array
(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)))
(scope
(var define-statement (const ([] CStatementOperation))
(array
(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
;;
(comptime-cond
('auto-test
;; 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) 2)
(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-cond
('Windows
(comptime-error "Tracy build needs to be ported to Windows. See manual at
https://github.com/wolfpld/tracy"))
('Unix
(when (fileExists "Dependencies/tracy/profiler/build/unix/Tracy-release")
(return true))
(run-process-sequential-or
("make" "-j4" :in-directory "Dependencies/tracy/profiler/build/unix")
(Log "error: failed to build Tracy profiler. Check the manual at https://github.com/wolfpld/tracy.
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 "https://github.com/wolfpld/tracy" "Dependencies/tracy")
(add-compile-time-hook-module pre-build build-tracy-profiler)
(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")
(comptime-cond
('Unix
(add-library-dependency "pthread" "dl")))
(add-build-config-label "Profile")