GameLib is my library for making games
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.

162 lines
6.8 KiB

(set-cakelisp-option cakelisp-src-dir "Dependencies/cakelisp/src")
(import &comptime-only "Macros.cake")
(c-import "<stdio.h>"
;; Ogre dependencies
;; Not ported over to Cakelisp yet
;; TODO: convert these functions to cakelisp eventually
(defun ogre-initialize (&return bool)
(return (OgreInitialize)))
(defun ogre-initialize-sdl (&return bool)
(return (OgreInitializeSDL)))
(defun ogre-shutdown ()
;; 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)))
;; 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)))
;; I'd be happy if this goes away in the "real" language, but it seems necessary for C++ interop
(namespace Ogre
(class Item)
(class SceneNode)))
;; The client of this API should not need access the internals of this structure
(defstruct mesh-handle
mesh-item (* (in Ogre Item)))
(defstruct scene-node
node (* (in Ogre SceneNode)))
(defun ogre-load-mesh (name (* (const char)) &return mesh-handle)
(var scene-manager (* (in Ogre SceneManager)) (ogreGetSceneManager))
;; 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.
(var mesh-v1 Ogre::v1::MeshPtr
(on-call (call (in Ogre v1 MeshManager getSingleton)) load
name Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME
Ogre::v1::HardwareBuffer::HBU_STATIC Ogre::v1::HardwareBuffer::HBU_STATIC))
(var half-position bool true)
(var half-UVs bool true)
(var use-Q-tangents bool true)
;; Create a v2 mesh to import to, with a different name (arbitrary).
(var mesh-name-v2 (const Ogre::String) (+ name (Ogre::String " Imported")))
;; Import the v1 mesh to v2
(var v2Mesh Ogre::MeshPtr
(on-call (call (in Ogre MeshManager getSingleton)) createByImportingV1
mesh-name-v2 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME
(on-call mesh-v1 get)
half-position half-UVs use-Q-tangents))
;; We don't need the v1 mesh. Free CPU memory, get it out of the GPU.
;; Leave it loaded if you want to use athene with v1 Entity.
(on-call-ptr mesh-v1 unload)
;; Create an Item with the model we just imported.
;; Notice we use the name of the imported model. We could also use the overload
;; with the mesh pointer:
;; item = scene-manager->createItem( v2Mesh, Ogre::SCENE_DYNAMIC );
(var item (* Ogre::Item) (on-call-ptr scene-manager createItem
mesh-name-v2 Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME
(var mesh-handle mesh-handle (array item))
(return mesh-handle))
(defun ogre-node-from-item (mesh-handle mesh-handle &return scene-node)
(var new-scene-node scene-node (array nullptr))
(var scene-manager (* (in Ogre SceneManager)) (ogreGetSceneManager))
(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
;; Ogre::SceneNode* sceneNode = root-scene-node->createChildSceneNode(Ogre::SCENE_DYNAMIC);
(var scene-node (* Ogre::SceneNode)
(type-cast (on-call-ptr root-scene-node createChild) (* Ogre::SceneNode)))
(when scene-node
(on-call-ptr scene-node attachObject (field mesh-handle mesh-item))
(set (field new-scene-node node) scene-node)))
(return new-scene-node))
(defun ogre-node-set-position (node (* scene-node) x float y float z float)
(on-call-ptr (path node > node) setPosition x y z))
;; Building
;; TODO: Relative vs. absolute paths
(import &comptime-only "../Dependencies/cakelisp/runtime/Macros.cake")
(add-cpp-build-dependency "OgreInitialize.cpp")
(set-module-option build-time-compiler "/usr/bin/clang++")
;; Include cakelisp source for DynamicLoader.hpp
(set-module-option build-time-compile-arguments
"-std=c++11" "-Wall" "-Wextra" "-Wno-unused-parameter"
"-g" "-c" 'source-input "-o" 'object-output "-fPIC"
;; Ogre options
;; TODO: Automatically build Ogre if it isn't built yet, and copy necessary files
;; (defun-comptime ogre-pre-build-hook ()
;; (unless (fileExists "Dependencies/ogre-next/build/Debug/lib")
;; (printf "error: Ogre is not built yet. Please run ./\n")
;; (return false))
;; (return true))
;; (add-compile-time-hook-module pre-build ogre-pre-build-hook)
(defun-comptime ogre-link-hook (manager (& ModuleManager)
linkCommand (& ProcessCommand)
linkTimeInputs (* ProcessCommandInput) numLinkTimeInputs int
&return bool)
;; TODO: Expose this option somehow?
(var is-debug-build bool true)
(printf "OgreCore: Adding %s link arguments\n" (? is-debug-build "debug" "release"))
(if is-debug-build
(command-add-string-argument "-LDependencies/ogre-next/build/Debug/lib")
(command-add-string-argument "-lOgreHlmsPbs_d")
(command-add-string-argument "-lOgreHlmsUnlit_d")
(command-add-string-argument "-lOgreMain_d")
(command-add-string-argument "-lOgreOverlay_d")
(command-add-string-argument "-Wl,-rpath,.:../Dependencies/ogre-next/build/Debug/lib"))
(command-add-string-argument "-LDependencies/ogre-next/build/Release/lib")
(command-add-string-argument "-lOgreHlmsPbs")
(command-add-string-argument "-lOgreHlmsUnlit")
(command-add-string-argument "-lOgreMain")
(command-add-string-argument "-lOgreOverlay")
(command-add-string-argument "-Wl,-rpath,.:../Dependencies/ogre-next/build/Release/lib")))
(return true))
(add-compile-time-hook pre-link ogre-link-hook)