Browse Source

Ogre HLMS experimentation

* Cleaned up namings in OgreInitialize.cake
* Added ogre-create-light
* Created OgreHlms.cpp, which is copied from Ogre's Sample
  PbsMaterialsGameState.cpp and modified
* Moved declare-extern-function so I could avoid making a header file
for test file OgreHlms.cpp
* Reorganized where build options are in a few files
pitch-detection
Macoy Madson 2 years ago
parent
commit
40788aaf8e
  1. 18
      Build_Debug.sh
  2. 2
      Dependencies/cakelisp
  3. 58
      src/Ogre.cake
  4. 90
      src/OgreInitialize.cake
  5. 36
      test/src/GamelibMacros.cake
  6. 5
      test/src/Loader.cake
  7. 37
      test/src/NoHotReload.cake
  8. 94
      test/src/OgreHlms.cpp
  9. 56
      test/src/VocalGame.cake

18
Build_Debug.sh

@ -1,8 +1,5 @@
#!/bin/sh
# TODO: Support compiling as a library?
# ./Dependencies/cakelisp/bin/cakelisp src/Ogre.cake || exit $?
echo "\n\nOgre\n\n"
./Dependencies/cakelisp/bin/cakelisp test/src/OgreApp.cake || exit $?
echo "\n\nSDL Ogre\n\n"
@ -17,10 +14,15 @@ echo "\n\nLoader\n\n"
./Dependencies/cakelisp/bin/cakelisp test/src/Loader.cake || exit $?
echo "\n\nVocal Game (no reload)\n\n"
./Dependencies/cakelisp/bin/cakelisp test/src/NoHotReload.cake test/src/VocalGame.cake || exit $?
./Dependencies/cakelisp/bin/cakelisp --execute \
test/src/NoHotReload.cake test/src/VocalGame.cake || exit $?
# echo "\n\nAuto Test\n\n"
# ../cakelisp/bin/cakelisp --verbose-processes src/AutoTest.cake src/SDL.cake src/Tracy.cake
# TESTING
# ./Dependencies/cakelisp/bin/cakelisp --verbose-compile-time-build-objects test/src/SDLOgreApp.cake
# && echo "\n\nRUNTIME\n" && cd test && ./SDLOgreApp
# echo "\n\nVocal Game (no reload)\n\n"
# ../cakelisp/bin/cakelisp \
# test/src/MakeHotReload.cake test/src/VocalGame.cake || exit $?
# TODO: Support compiling as a library?
# ./Dependencies/cakelisp/bin/cakelisp src/Ogre.cake || exit $?

2
Dependencies/cakelisp

@ -1 +1 @@
Subproject commit ec5c500639f1898a49a863782f9e4794e55095bd
Subproject commit 56869ad3d6d7bf315e493b897cd1687947e1aad1

58
src/Ogre.cake

@ -19,25 +19,25 @@
;; Use Ogre's GLX window
;; TODO: convert these functions to cakelisp eventually
(defun ogre-initialize (&return bool)
(return (OgreInitialize false)))
(return (ogre-initialize-internal false)))
;; Use an already-created SDL window
;; Note that this will probably break rendering via SDL, i.e. you need to use OpenGL instead
;; This makes sense because SDL was only for input, audio etc., not graphics, in our case
(defun ogre-initialize-sdl (&return bool)
(return (OgreInitialize true)))
(return (ogre-initialize-internal true)))
(defun ogre-shutdown ()
(OgreShutdown))
(ogre-shutdown-internal))
;; If false is returned, you should break from the main loop (the window has been closed)
(defun ogre-handle-window-events (&return bool)
(call (in Ogre WindowEventUtilities messagePump))
(return (not g_ogreWindowShouldQuit)))
(return (not g-ogre-window-should-quit)))
;; If false is returned, you should break from the main loop (an error has occurred)
(defun ogre-render-frame (&return bool)
(return (on-call-ptr g_ogreRoot renderOneFrame)))
(return (on-call-ptr g-ogre-root renderOneFrame)))
;; I'd be happy if this goes away in the "real" language, but it seems necessary for C++ interop
(forward-declare
@ -53,7 +53,7 @@
node (* (in Ogre SceneNode)))
(defun ogre-load-mesh (name (* (const char)) &return mesh-handle)
(var scene-manager (* (in Ogre SceneManager)) (ogreGetSceneManager))
(var scene-manager (* (in Ogre SceneManager)) (ogre-get-scene-manager))
;; Load the v1 mesh. Notice the v1 namespace
;; Also notice the HBU_STATIC flag; since the HBU_WRITE_ONLY
;; bit would prohibit us from reading the data for importing.
@ -92,7 +92,7 @@
(defun ogre-node-from-item (mesh-handle mesh-handle &return scene-node)
(var new-scene-node scene-node (array null))
(var scene-manager (* (in Ogre SceneManager)) (ogreGetSceneManager))
(var scene-manager (* (in Ogre SceneManager)) (ogre-get-scene-manager))
(var root-scene-node (* Ogre::SceneNode) (on-call-ptr scene-manager getRootSceneNode))
(when root-scene-node
;; WTF - this should work, but it's almost like the root scene node's vtable is wrong
@ -107,22 +107,48 @@
(defun ogre-node-set-position (node (* scene-node) x float y float z float)
(on-call-ptr (path node > node) setPosition x y z))
(defun ogre-create-light (&return scene-node)
(var new-light-node scene-node (array null))
(var scene-manager (* (in Ogre SceneManager)) (ogre-get-scene-manager))
(var root-scene-node (* Ogre::SceneNode) (on-call-ptr scene-manager getRootSceneNode))
(when root-scene-node
(var light (* (in Ogre Light)) (on-call-ptr scene-manager createLight))
(var light-node (* (in Ogre SceneNode))
;; Required cast for VTable weirdness (See "WTF" comment)
(type-cast (on-call-ptr root-scene-node createChild) (* Ogre::SceneNode)))
(set (field new-light-node node) light-node)
(on-call-ptr light-node attachObject light)
(on-call-ptr light setPowerScale 1.0f)
(on-call-ptr light setType (in Ogre Light LT_DIRECTIONAL))
(on-call-ptr light setDirection (on-call (call (in Ogre Vector3) -1 -1 -1) normalisedCopy))
(on-call-ptr scene-manager setAmbientLight
(* (call (in Ogre ColourValue) 0.3f 0.5f 0.7f) 0.1f 0.75f)
(* (call (in Ogre ColourValue) 0.6f 0.45f 0.3f) 0.065f 0.75f)
(+ (negate (on-call-ptr light getDirection)) (* (in Ogre Vector3 UNIT_Y) 0.2f))))
(return new-light-node))
;; e.g. (negate 1) outputs (-1)
(defgenerator negate (to-negate (index any))
(var negate-statement (const ([] CStatementOperation))
(array
(array OpenParen null -1)
(array Keyword "-" -1)
(array Expression null 1)
(array CloseParen null -1)))
(return (CStatementOutput environment context tokens startTokenIndex
negate-statement (array-size negate-statement)
output)))
;;
;; Building
;;
(add-build-options "-DOGRE_DEBUG_MODE=1")
(add-c-search-directory module
"Dependencies/ogre-next/OgreMain/include"
"Dependencies/ogre-next/Components/Hlms/Common/include"
"Dependencies/ogre-next/Components/Hlms/Pbs/include"
"Dependencies/ogre-next/Components/Hlms/Unlit/include"
"Dependencies/ogre-next/build/Debug/include"
"Dependencies/ogre-next/Components/Overlay/include")
(use-ogre-build-options)
;; TODO: Automatically build Ogre if it isn't built yet
;; TODO: Copy necessary files (Hlms materials etc.) so self-test/user exes can run
;; (defun-comptime ogre-pre-build-hook ()
;; (defun-comptime ogre-pre-build-hook (&return bool)
;; (unless (fileExists "Dependencies/ogre-next/build/Debug/lib")
;; (printf "error: Ogre is not built yet. Please run ./BuildDependencies_Debug.sh\n")
;; (return false))

90
src/OgreInitialize.cake

@ -1,14 +1,5 @@
(import &comptime-only "Macros.cake")
(add-build-options "-DOGRE_DEBUG_MODE=1")
(add-c-search-directory module
"Dependencies/ogre-next/OgreMain/include"
"Dependencies/ogre-next/Components/Hlms/Common/include"
"Dependencies/ogre-next/Components/Hlms/Pbs/include"
"Dependencies/ogre-next/Components/Hlms/Unlit/include"
"Dependencies/ogre-next/build/Debug/include"
"Dependencies/ogre-next/Components/Overlay/include")
;; #pragma GCC diagnostic push
;; #pragma GCC diagnostic ignored "-Woverloaded-virtual"
(c-import
@ -37,12 +28,12 @@
(class Root)
(class SceneManager)))
(global-var g_ogreRoot (* (in Ogre Root)) null)
(var g_sceneManager (* (in Ogre SceneManager)) null)
(var g_window (* (in Ogre Window)) null)
(global-var g-ogre-root (* (in Ogre Root)) null)
(var g-scene-manager (* (in Ogre SceneManager)) null)
(var g-ogre-window (* (in Ogre Window)) null)
(var g_graphicsIntialized bool false)
(global-var g_ogreWindowShouldQuit bool false)
(var g-graphics-intialized bool false)
(global-var g-ogre-window-should-quit bool false)
;; TODO: Add advanced class definition
;; class MyWindowEventListener : public Ogre::WindowEventListener
@ -50,7 +41,7 @@
;; public:
;; virtual void windowClosed(Ogre::Window* window)
;; {
;; g_ogreWindowShouldQuit = true;
;; g-ogre-window-should-quit = true;
;; }
;; };
@ -140,7 +131,7 @@
(on-call-ptr hlmsPbs setTextureBufferDefaultSize (* 512 1024))
(on-call-ptr hlmsUnlit setTextureBufferDefaultSize (* 512 1024)))))
(defun OgreInitialize (useCurrentWindow bool &return bool)
(defun ogre-initialize-internal (useCurrentWindow bool &return bool)
(var pluginsFolder (const (in Ogre String)) "./data/")
(var writeAccessFolder (const (in Ogre String)) "./output/")
@ -153,18 +144,18 @@
;; #endif
;; #endif
(set g_ogreRoot (ogre-new (call (in Ogre Root) (+ pluginsFolder pluginsFile)
(set g-ogre-root (ogre-new (call (in Ogre Root) (+ pluginsFolder pluginsFile)
(+ writeAccessFolder "ogre.cfg")
(+ writeAccessFolder "Ogre.log"))))
;; This allows the user to configure the graphics. It's damn annoying during dev though
;; TODO: Make this return false and quit the app
;; if (!g_ogreRoot->showConfigDialog())
;; if (!g-ogre-root->showConfigDialog())
;; return false;
;; Initialize Root
(var renderSystem (* (in Ogre RenderSystem))
(on-call-ptr g_ogreRoot getRenderSystemByName "OpenGL 3+ Rendering Subsystem"))
(on-call-ptr g-ogre-root getRenderSystemByName "OpenGL 3+ Rendering Subsystem"))
(unless renderSystem
(printf "Render system not found!\n")
(return false))
@ -174,8 +165,8 @@
;; renderSystem->setConfigOption("VSync", "Yes");
(on-call-ptr renderSystem setConfigOption "Video Mode" "1920 x 1080")
(on-call-ptr renderSystem setConfigOption "sRGB Gamma Conversion" "Yes")
(on-call-ptr g_ogreRoot setRenderSystem renderSystem)
(set g_window (on-call-ptr g_ogreRoot initialise
(on-call-ptr g-ogre-root setRenderSystem renderSystem)
(set g-ogre-window (on-call-ptr g-ogre-root initialise
(not useCurrentWindow) ;; autoCreateWindow
"GameLib"))
@ -189,7 +180,7 @@
(set (at "currentGLContext" windowSettings) (call (type (in Ogre String)) "True"))
(var winWidth int 1920)
(var winHeight int 1080)
(set g_window (on-call-ptr g_ogreRoot createRenderWindow "GameLib" winWidth winHeight
(set g-ogre-window (on-call-ptr g-ogre-root createRenderWindow "GameLib" winWidth winHeight
false ;; Fullscreen
(addr windowSettings)))
;; renderWindow->setVisible(true);
@ -199,11 +190,11 @@
;; Create SceneManager
(var numThreads (const size_t) 1u)
(set g_sceneManager (on-call-ptr g_ogreRoot createSceneManager
(set g-scene-manager (on-call-ptr g-ogre-root createSceneManager
(in Ogre ST_GENERIC) numThreads "SceneManager"))
;; Create & setup camera
(var camera (* (in Ogre Camera)) (on-call-ptr g_sceneManager createCamera "Main Camera"))
(var camera (* (in Ogre Camera)) (on-call-ptr g-scene-manager createCamera "Main Camera"))
;; Position it at 500 in Z direction
(on-call-ptr camera setPosition (call (type (in Ogre Vector3)) 0 5 15))
@ -215,7 +206,7 @@
;; Setup a basic compositor with a blue clear colour
(var compositorManager (* (in Ogre CompositorManager2))
(on-call-ptr g_ogreRoot getCompositorManager2))
(on-call-ptr g-ogre-root getCompositorManager2))
(var workspaceName (const (in Ogre String)) "Main Workspace")
;; const IdString definitionNameId = workspaceName;
;; TODO: This needs initializer parameters
@ -223,7 +214,7 @@
(on-call-ptr compositorManager createBasicWorkspaceDef
workspaceName backgroundColour (call (in Ogre IdString)))
(on-call-ptr compositorManager addWorkspace
g_sceneManager (on-call-ptr g_window getTexture) camera workspaceName true)
g-scene-manager (on-call-ptr g-ogre-window getTexture) camera workspaceName true)
(var resource-group-manager (& (in Ogre ResourceGroupManager))
(call (in Ogre ResourceGroupManager getSingleton)))
@ -241,19 +232,19 @@
(on-call resource-group-manager loadResourceGroup "Materials"))
;; (call (in Ogre WindowEventUtilities addWindowEventListener)
;; g_window (addr g_myWindowEventListener))
;; g-ogre-window (addr g_myWindowEventListener))
(set g_graphicsIntialized true)
(set g-graphics-intialized true)
(return true))
(defun OgreShutdown ()
(defun ogre-shutdown-internal ()
;; (call (in Ogre WindowEventUtilities removeWindowEventListener)
;; g_window (addr g_myWindowEventListener))
(OGRE_DELETE g_ogreRoot)
(set g_ogreRoot null))
;; g-ogre-window (addr g_myWindowEventListener))
(OGRE_DELETE g-ogre-root)
(set g-ogre-root null))
(defun ogreGetSceneManager (&return (* (in Ogre SceneManager)))
(return g_sceneManager))
(defun ogre-get-scene-manager (&return (* (in Ogre SceneManager)))
(return g-scene-manager))
(defgenerator ogre-new (expression-index (index any))
(addStringOutput (field output source) "OGRE_NEW" StringOutMod_SpaceAfter
@ -271,16 +262,39 @@
;; (var-construct name type constructor-arguments)
;; Output
;; type name(constructor-arguments);
(defgenerator var-construct ()
(defgenerator var-construct (name (index symbol) type (index any)
&rest constructor-arguments (index any))
;; TODO: Make version of this that uses the absolute token index rather than re-getting the args
;; Right now, we're not really getting the benefits of using generator arguments
(var constructor-var-statement (const ([] CStatementOperation))
(array
(array TypeNoArray null 2)
(array TypeNoArray null 2) ;; type
(array Keyword " " -1)
(array Expression null 1)
(array Expression null 1) ;; name
(array OpenParen null -1)
(array ExpressionList null 3)
(array ExpressionList null 3) ;; constructor-arguments
(array CloseParen null -1)
(array SmartEndStatement null -1)))
(return (CStatementOutput environment context tokens startTokenIndex
constructor-var-statement (array-size constructor-var-statement)
output)))
;;
;; Building
;;
(defmacro use-ogre-build-options ()
(tokenize-push output
(add-build-options "-DOGRE_DEBUG_MODE=1"
;; Ignore an annoyingly long error in Ogre's code
"-Wno-gnu-inline-cpp-without-extern")
(add-c-search-directory module
"Dependencies/ogre-next/OgreMain/include"
"Dependencies/ogre-next/Components/Hlms/Common/include"
"Dependencies/ogre-next/Components/Hlms/Pbs/include"
"Dependencies/ogre-next/Components/Hlms/Unlit/include"
"Dependencies/ogre-next/build/Debug/include"
"Dependencies/ogre-next/Components/Overlay/include"))
(return true))
(use-ogre-build-options)

36
test/src/GamelibMacros.cake

@ -0,0 +1,36 @@
(skip-build)
;; Given
;; (declare-extern-function my-func (i int &return bool))
;; Output
;; bool myFunc(int i);
;; This is useful for forward declarations of functions or declaring functions linked dynamically
(defgenerator declare-extern-function (name-token (ref symbol) signature-index (index array))
(quick-token-at signature-token signature-index)
(var return-type-start int -1)
(var arguments (<> std::vector FunctionArgumentTokens))
(unless (parseFunctionSignature tokens signature-index arguments return-type-start)
(return false))
(var end-signature-index int (FindCloseParenTokenIndex tokens signature-index))
(unless (outputFunctionReturnType tokens output return-type-start startTokenIndex
end-signature-index
true ;; Output to source
false) ;; Output to header
(return false))
(addStringOutput (path output . source) (field name-token contents)
StringOutMod_ConvertFunctionName
(addr name-token))
(addLangTokenOutput (field output source) StringOutMod_OpenParen (addr signature-token))
(unless (outputFunctionArguments tokens output arguments
true ;; Output to source
false) ;; Output to header
(return false))
(addLangTokenOutput (field output source) StringOutMod_CloseParen (addr signature-token))
(addLangTokenOutput (field output source) StringOutMod_EndStatement (addr signature-token))
(return true))

5
test/src/Loader.cake

@ -26,8 +26,6 @@
(c-import "stdio.h")
(defun main (&return int)
(printf "Hello Hot-reloading!\n")
(def-function-signature reload-entry-point-signature (&return bool))
(var hot-reload-entry-point-func reload-entry-point-signature null)
(register-function-pointer (type-cast (addr hot-reload-entry-point-func) (* (* void)))
@ -35,7 +33,7 @@
"reloadableEntryPoint")
(unless (do-hot-reload)
(printf "error: failed to hot-reload\n")
(printf "error: failed to load\n")
(return 1))
(while (hot-reload-entry-point-func)
@ -44,7 +42,6 @@
(return 1)))
(return 0))
;;
;; Libraries
;;

37
test/src/NoHotReload.cake

@ -1,3 +1,5 @@
(import &comptime-only "GamelibMacros.cake")
(declare-extern-function
reloadableEntryPoint (&return bool))
@ -5,38 +7,3 @@
(defun main (&return int)
(while (reloadableEntryPoint) (printf "Reloaded, but not really\n"))
(return 0))
;; Given
;; (declare-extern-function my-func (i int &return bool))
;; Output
;; bool myFunc(int i);
;; This is useful for forward declarations of functions or declaring functions linked dynamically
(defgenerator declare-extern-function (name-token (ref symbol) signature-index (index array))
(quick-token-at signature-token signature-index)
(var return-type-start int -1)
(var arguments (<> std::vector FunctionArgumentTokens))
(unless (parseFunctionSignature tokens signature-index arguments return-type-start)
(return false))
(var end-signature-index int (FindCloseParenTokenIndex tokens signature-index))
(unless (outputFunctionReturnType tokens output return-type-start startTokenIndex
end-signature-index
true ;; Output to source
false) ;; Output to header
(return false))
(addStringOutput (path output . source) (field name-token contents)
StringOutMod_ConvertFunctionName
(addr name-token))
(addLangTokenOutput (field output source) StringOutMod_OpenParen (addr signature-token))
(unless (outputFunctionArguments tokens output arguments
true ;; Output to source
false) ;; Output to header
(return false))
(addLangTokenOutput (field output source) StringOutMod_CloseParen (addr signature-token))
(addLangTokenOutput (field output source) StringOutMod_EndStatement (addr signature-token))
(return true))

94
test/src/OgreHlms.cpp

@ -0,0 +1,94 @@
#include "OgreHlmsManager.h"
#include "OgreHlmsPbs.h"
#include "OgreHlmsPbsDatablock.h"
#include "OgreHlmsSamplerblock.h"
#include "OgreItem.h"
#include "OgreMesh2.h"
#include "OgreMeshManager.h"
#include "OgreMeshManager2.h"
#include "OgreRoot.h"
#include "OgreSceneManager.h"
#include "OgreTextureFilters.h"
#include "OgreTextureGpuManager.h"
// For testing only. Copied from Ogre samples, and modified.
void ogreCreatePbsSpheres(Ogre::Root* root, Ogre::SceneManager* sceneManager)
{
int numSpheres = 0;
Ogre::HlmsManager* hlmsManager = root->getHlmsManager();
assert(dynamic_cast<Ogre::HlmsPbs*>(hlmsManager->getHlms(Ogre::HLMS_PBS)));
Ogre::HlmsPbs* hlmsPbs = static_cast<Ogre::HlmsPbs*>(hlmsManager->getHlms(Ogre::HLMS_PBS));
const int numX = 8;
const int numZ = 8;
const float armsLength = 1.0f;
const float startX = (numX - 1) / 2.0f;
const float startZ = (numZ - 1) / 2.0f;
Ogre::TextureGpuManager* textureMgr = root->getRenderSystem()->getTextureGpuManager();
Ogre::SceneNode* rootSceneNode = sceneManager->getRootSceneNode();
// Convert the sphere mesh (doesn't work due to material)
// const Ogre::String meshNameV2 = ("sphere.mesh" + Ogre::String(" Imported"));
// {
// Ogre::v1::MeshPtr meshV1 = Ogre::v1::MeshManager::getSingleton().load(
// "sphere.mesh", Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
// Ogre::v1::HardwareBuffer::HBU_STATIC, Ogre::v1::HardwareBuffer::HBU_STATIC);
// bool halfPosition = true;
// bool halfUVs = true;
// bool useQTangents = true;
// Ogre::MeshPtr v2Mesh = Ogre::MeshManager::getSingleton().createByImportingV1(
// meshNameV2, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, meshV1.get(),
// halfPosition, halfUVs, useQTangents);
// meshV1->unload();
// }
for (int x = 0; x < numX; ++x)
{
for (int z = 0; z < numZ; ++z)
{
Ogre::String datablockName = "Test" + Ogre::StringConverter::toString(numSpheres++);
Ogre::HlmsPbsDatablock* datablock = static_cast<Ogre::HlmsPbsDatablock*>(
hlmsPbs->createDatablock(datablockName, datablockName, Ogre::HlmsMacroblock(),
Ogre::HlmsBlendblock(), Ogre::HlmsParamVec()));
Ogre::TextureGpu* texture = textureMgr->createOrRetrieveTexture(
"SaintPetersBasilica.dds", Ogre::GpuPageOutStrategy::Discard,
Ogre::TextureFlags::PrefersLoadingFromFileAsSRGB, Ogre::TextureTypes::TypeCube,
Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
Ogre::TextureFilter::TypeGenerateDefaultMipmaps);
datablock->setTexture(Ogre::PBSM_REFLECTION, texture);
datablock->setDiffuse(Ogre::Vector3(0.0f, 1.0f, 0.0f));
datablock->setRoughness(std::max(0.02f, x / std::max(1.0f, (float)(numX - 1))));
datablock->setFresnel(Ogre::Vector3(z / std::max(1.0f, (float)(numZ - 1))), false);
// Ogre::Item* item = nullptr;
// {
// item = sceneManager->createItem(
// meshNameV2, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
// Ogre::SCENE_DYNAMIC);
// }
// TODO this is a hack that relies on ogre-load-mesh being called some time before this
// This is because "sphere.mesh" is an old-style mesh which I need a convertor for or something
Ogre::Item* item = sceneManager->createItem(
"Suzanne.mesh Imported", Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
Ogre::SCENE_DYNAMIC);
item->setDatablock(datablock);
item->setVisibilityFlags(0x000000002);
Ogre::SceneNode* sceneNode = ((Ogre::SceneNode*)rootSceneNode->createChild());
if (!sceneNode)
return;
sceneNode->setPosition(
Ogre::Vector3(armsLength * x - startX, -3.0f, armsLength * z - startZ));
sceneNode->attachObject(item);
}
}
}

56
test/src/VocalGame.cake

@ -1,16 +1,12 @@
(set-cakelisp-option executable-output "test/VocalGame")
(import &comptime-only "Options.cake" "Macros.cake")
(import &comptime-only "Options.cake" "Macros.cake" "GamelibMacros.cake")
(import "Ogre.cake" "SDL.cake")
(import "Ogre.cake" "OgreInitialize.cake" "SDL.cake")
;; TODO: Should this happen automatically, because import automatically adds current working dir?
;; Should it add working dir?
(add-c-search-directory module ".")
(c-import "SDL.h" "SDL_syswm.h" "SDL_timer.h"
"<math.h>" "<stdio.h>" "<string.h>")
;; TODO: Somehow inherit this from SDL.cake?
(module-use-sdl-build-options)
;; These are read and written to from different threads (currently, without locking)
(var audio-is-recording bool false)
@ -284,23 +280,20 @@
(var monkey-mesh mesh-handle)
(var monkey-node scene-node)
(var g-light-node scene-node)
(var reload-sentinel int 2)
;; TODO: Automatically make entry point
(defun reloadableEntryPoint (&return bool)
(var result int (app-main))
(cond ((= 0 result)
(return false))
((= 1 result)
(return false))
((= reload-sentinel result)
(return true)))
(return false))
(var initialized bool false)
(defun app-main (&return int)
(forward-declare (namespace Ogre
(class Root)
(class SceneManager)))
(declare-extern-function
ogreCreatePbsSpheres (root (* (in Ogre Root))
scene-manager (* (in Ogre SceneManager))))
(defun-local app-main (&return int)
(unless initialized
;; (defun main (&return int)
(unless (sdl-initialize (addr g-window))
@ -316,6 +309,11 @@
(set monkey-mesh (ogre-load-mesh "Suzanne.mesh"))
(set monkey-node (ogre-node-from-item monkey-mesh))
(set g-light-node (ogre-create-light))
(when g-ogre-root
(ogreCreatePbsSpheres g-ogre-root (ogre-get-scene-manager)))
(set initialized true))
;; Audio needs to be re-initialized due to reload removing callbacks
@ -508,3 +506,25 @@
(when exit-reason
(printf "Exit reason: %s\n" exit-reason))
(return 0))
;; TODO: Automatically make entry point
(defun reloadableEntryPoint (&return bool)
(var result int (app-main))
(cond ((= 0 result)
(return false))
((= 1 result)
(return false))
((= reload-sentinel result)
(return true)))
(return false))
;;
;; Building
;;
(set-cakelisp-option executable-output "test/VocalGame")
;; 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")

Loading…
Cancel
Save