Browse Source

Fix Image.cake and Raylib.cake conflicting

* Use raylib's stb_image.h and implementation if Raylib is
imported. This prevents multiple definitions and ensures the API
matches (because already, I'm on a different version of stb_image.h as
raylib).
* Make raylib support image formats I care about. Note that there's a
bug in raylib right now which is addressed by:
https://github.com/raysan5/raylib/pull/2318
* Reduce number of "hot loop" to speed up testing
master
Macoy Madson 2 years ago
parent
commit
b8c39e38bc
  1. 29
      src/Image.cake
  2. 9
      src/Raylib.cake
  3. 2
      src/Tracy.cake
  4. 8
      test/src/GameLibTests.cake

29
src/Image.cake

@ -1,13 +1,32 @@
;; Image
;; Interface for loading images of various formats
;; Currently, stb_image.h does all the heavy lifting
(export-and-evaluate (add-c-search-directory-module "Dependencies/stb"))
(import "STB.cake")
(export-and-evaluate
(comptime-cond
('STBImageDefinedInRaylib
(add-c-search-directory-module "Dependencies"))
(true
(add-c-search-directory-module "Dependencies/stb"))))
(import "STB.cake") ;; Download STB if necessary
(c-preprocessor-define STB_IMAGE_IMPLEMENTATION)
;; If another dependency includes stb_image (it's quite popular), then we don't need to add the
;; implementations here (and cause multiple definitions)
(comptime-cond
('STBImageDefinedInRaylib)
(true
(c-preprocessor-define STB_IMAGE_IMPLEMENTATION)))
(c-preprocessor-define STBI_FAILURE_USERMSG)
(c-import &with-decls "stb_image.h"
&with-defs "stb_image.h")
;; This is an annoying hack: Raylib uses a different version of stb, so if we import Raylib.cake
;; and Image.cake (must be in that order!), we need to use Raylib's version, because I don't want
;; to modify raylib.
(comptime-cond
('STBImageDefinedInRaylib
;; I don't want to expose raylib/src/external because it breaks other modules in GameLib
(c-import &with-decls "raylib/src/external/stb_image.h"
&with-defs "raylib/src/external/stb_image.h"))
(true
(c-import &with-decls "stb_image.h"
&with-defs "stb_image.h")))
(comptime-cond
('auto-test

9
src/Raylib.cake

@ -2,6 +2,8 @@
(add-cakelisp-search-directory "Dependencies/cakelisp/runtime")
(import "CHelpers.cake" "BuildTools.cake" "Dependencies.cake")
(comptime-define-symbol 'STBImageDefinedInRaylib)
(export-and-evaluate
(add-c-search-directory-module "Dependencies/raylib/src")
(c-import "raylib.h"))
@ -36,7 +38,12 @@
(makeDirectory raylib-output-dir)
(run-process-sequential-or
("cmake" "../../Dependencies/raylib" :in-directory raylib-output-dir)
("cmake"
;; Enable file formats raylib normally disables, because if raylib defines stb image, we use
;; the same definitions.
"-DCUSTOMIZE_BUILD=ON" "-DSUPPORT_FILEFORMAT_JPG=ON"
"-DSUPPORT_FILEFORMAT_BMP=ON" "-DSUPPORT_FILEFORMAT_TGA=ON"
"../../Dependencies/raylib" :in-directory raylib-output-dir)
(Log "failed at Raylib configure step. This requires a sh/bash-style shell to execute.")
(return false))

2
src/Tracy.cake

@ -66,7 +66,7 @@
(sleep 1))
(var i int 0)
(var num-times (const int) 10)
(var num-times (const int) 2)
(while (< i num-times)
(ZoneScopedN "hot loop")
(fprintf stderr "hot loop %d / %d\n" i num-times)

8
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)
@ -69,7 +69,9 @@
"../src/AutoTest.cake" "../src/SDL.cake" "../src/Math.cake"
"../src/Aubio.cake" "../src/ImGui.cake" "../src/Dictionary.cake"
"../src/DynamicArray.cake" "../src/Introspection.cake" "../src/OpenGL.cake"
"../src/Tracy.cake" "../src/TaskSystem.cake" "../src/Image.cake"
"../src/Tracy.cake" "../src/TaskSystem.cake"
;; Note that Raylib must come first so Image knows not to redefine stb_image implementation
"../src/Raylib.cake" "../src/Image.cake"
"../src/DataBundle.cake" "../src/TinyCCompiler.cake" "../src/FreeType.cake"
"../src/ImGuiAutoColor.cake"
"../src/ProfilerAutoInstrument.cake"))

Loading…
Cancel
Save