From 77981e45a8bae49bf1f6042f5e3a05ed2462570b Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Thu, 4 Mar 2021 10:31:36 -0600 Subject: [PATCH] Fix the windows version (Fuck that was a trip) --- core/CMakeLists.txt | 6 +++++- core/Node.cpp | 28 ++++++++++++++++++++++------ core/Node.h | 9 +++++++-- core/couch.cpp | 1 - 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 83608b1..b559206 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -65,7 +65,11 @@ target_sources(couchlib PUBLIC Shaders/SkyboxShader.cpp) -add_library(couchlib_luascripting SHARED) +if (WIN32) + add_library(couchlib_luascripting STATIC) +else () + add_library(couchlib_luascripting SHARED) +endif () target_sources(couchlib_luascripting PUBLIC Scripting/Lua.h Scripting/Lua.cpp) diff --git a/core/Node.cpp b/core/Node.cpp index c6208f9..c09c40b 100644 --- a/core/Node.cpp +++ b/core/Node.cpp @@ -24,9 +24,15 @@ #include "Node.h" #include "Util.h" +// Note: Declare theses here, not in the header, otherwise +// Windows DLLs will make two versions of the singleton. +static NodeList freeList(false); +static Node root(false); + NodeList::NodeList() { isPrefabList = true; } + NodeList::NodeList(bool isPrefabList) { this->isPrefabList = isPrefabList; } @@ -45,6 +51,10 @@ void NodeList::Remove(Node *node) { remove(node); } +int NodeList::Length() { + return size(); +} + bool NodeList::IsPrefabList() { return isPrefabList; } @@ -57,6 +67,14 @@ void NodeList::FreeList() { clear(); } +Node::Node() {} +Node::Node(bool isPrefab) { + if (!isPrefab) { + this->isPrefab = false; + children.isPrefabList = false; + } +} + Name Node::GetType() const {return "Node";} bool Node::IsPrefab() { @@ -78,18 +96,18 @@ Node *Node::GetParent() { void Node::QueueFree() { parent->children.Remove(this); - freeList->Append(this); + freeList.Append(this); } void Node::DoFree() { - if (this != root) { + if (this != &root) { throw "Tried to call DoFree from non-root node"; } - freeList->FreeList(); + freeList.FreeList(); } Node *Node::GetRoot() { - return root; + return &root; } Node* Node::Create() { @@ -115,5 +133,3 @@ Node* Node::Instance() { return instance; } -NodeList *Node::freeList = new NodeList(false); -Node *Node::root = {Node().Instance()}; diff --git a/core/Node.h b/core/Node.h index 0f7a2b8..6912fb3 100644 --- a/core/Node.h +++ b/core/Node.h @@ -49,6 +49,11 @@ public: @param node The node to remove */ void Remove(Node *node); + /** + Check how many children this node has + @returns The number of children of this node + */ + int Length(); /** Whether or not this is a list of prefabs @returns true if this is a prefab list, @@ -69,6 +74,8 @@ private: */ class Node { public: + Node(); + Node(bool isPrefab); virtual Name GetType() const; /** @@ -134,8 +141,6 @@ public: private: NodeList children; - static NodeList *freeList; - static Node *root; Node *parent; bool isPrefab = true; friend class NodeList; diff --git a/core/couch.cpp b/core/couch.cpp index cd58989..8ed25f0 100644 --- a/core/couch.cpp +++ b/core/couch.cpp @@ -110,7 +110,6 @@ int main() { double delta = 0.0; while(!glfwWindowShouldClose(window)) { - // Physics update() world->Step(delta);