From e2a358ffd17d8246484391627b4c406d932f9bef Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 16 Jan 2023 14:08:28 -0500 Subject: [PATCH] Basic window class --- include/blt/std/binary_tree.h | 50 ++++++----------------------------- include/blt/std/map.h | 15 +++++++++++ include/blt/window/window.h | 36 +++++++++++++++++++++++++ src/blt/std/system.cpp | 3 ++- 4 files changed, 61 insertions(+), 43 deletions(-) create mode 100644 include/blt/std/map.h create mode 100644 include/blt/window/window.h diff --git a/include/blt/std/binary_tree.h b/include/blt/std/binary_tree.h index 07801a7..a485000 100644 --- a/include/blt/std/binary_tree.h +++ b/include/blt/std/binary_tree.h @@ -160,6 +160,7 @@ namespace blt { if (parent == nullptr) { m_root = nullptr; } else { + // remove references to the nodes, we will add them later. We have a copy of the pointers which will be deleted. if (parent->right == elementNode) parent->right = nullptr; else if (parent->left == elementNode) @@ -167,6 +168,7 @@ namespace blt { else throw binary_search_tree_error("Parent node doesn't own child!\n"); } + // re-add all nodes to the tree, this is a terrible way of doing this, TODO. for (auto* node : traverseNodes) { if (node != elementNode) { if (parent == nullptr) { @@ -176,43 +178,6 @@ namespace blt { delete(node); } } - /*BST_node* inOrderSuccessor = elementNode->right; - BST_node* inOrderSuccessorParent = nullptr; - while (true){ - // go all the way to the left subtree - while (inOrderSuccessor->left != nullptr) { - inOrderSuccessorParent = inOrderSuccessor; - inOrderSuccessor = inOrderSuccessor->left; - } - if (inOrderSuccessor->right != nullptr) { - inOrderSuccessorParent = inOrderSuccessor; - inOrderSuccessor = inOrderSuccessor->right; - } else - break; - } - - if (parent != nullptr) { - if (parent->right == elementNode) - parent->right = inOrderSuccessor; - else if (parent->left == elementNode) - parent->left = inOrderSuccessor; - else - throw binary_search_tree_error("Parent node doesn't own child!\n"); - } else - m_root = inOrderSuccessor; - // reconstruct the node's children - inOrderSuccessor->left = elementNode->left; - inOrderSuccessor->right = elementNode->right; - // delete the parent's reference to the moved node - if (inOrderSuccessorParent != nullptr) { - if (inOrderSuccessorParent->left == inOrderSuccessor) - inOrderSuccessorParent->left = nullptr; - else if (inOrderSuccessorParent->right == inOrderSuccessor) - inOrderSuccessorParent->right = nullptr; - else - throw binary_search_tree_error("Parent does not contain child!\n"); - } - rebalance(parent);*/ } else { auto replacementNode = elementNode->left != nullptr ? elementNode->left : elementNode->right; if (parent == nullptr) @@ -233,9 +198,8 @@ namespace blt { return inOrderTraverse(m_root); } - inline BST_node* debug() { - return m_root; - } + inline BST_node* findMin(){return findMin(m_root);} + inline BST_node* findMax(){return findMax(m_root);} ~node_binary_search_tree() { auto inOrder = inOrderTraverse(); @@ -245,14 +209,16 @@ namespace blt { }; template - class flat_binary_search_tree { + class heap { private: - + //TODO }; template using node_BST = node_binary_search_tree; template + using flat_binary_search_tree = heap; + template using flat_BST = flat_binary_search_tree; } diff --git a/include/blt/std/map.h b/include/blt/std/map.h new file mode 100644 index 0000000..5f96993 --- /dev/null +++ b/include/blt/std/map.h @@ -0,0 +1,15 @@ +/* + * Created by Brett on 13/01/23. + * Licensed under GNU General Public License V3.0 + * See LICENSE file for license detail + */ + +#ifndef BLT_TESTS_MAP_H +#define BLT_TESTS_MAP_H + +template> +class hashmap { + +}; + +#endif //BLT_TESTS_MAP_H diff --git a/include/blt/window/window.h b/include/blt/window/window.h new file mode 100644 index 0000000..ebc1f50 --- /dev/null +++ b/include/blt/window/window.h @@ -0,0 +1,36 @@ +/* + * Created by Brett on 16/01/23. + * Licensed under GNU General Public License V3.0 + * See LICENSE file for license detail + */ + +#ifndef BLT_WINDOW_H +#define BLT_WINDOW_H + +#include + +namespace blt { + +class window { + public: + window() = default; + virtual void createWindow() = 0; + virtual void destroyWindow() = 0; + virtual ~window() = 0; + + virtual bool setResizeable(bool resizeEnabled) = 0; + virtual bool setWindowSize(int width, int height) = 0; + virtual int getWidth() = 0; + virtual int getHeight() = 0; + + virtual bool isKeyDown(int key) = 0; + virtual bool isMouseDown(int button) = 0; + // Function signature is window pointer to this, key press, pressed/released (true/false) + virtual void registerKeyListener(std::function listener) = 0; + // Function signature is window pointer to this, mouse button press, pressed/released (true/false) + virtual void registerMouseListener(std::function listener) = 0; +}; + +} + +#endif \ No newline at end of file diff --git a/src/blt/std/system.cpp b/src/blt/std/system.cpp index 692089f..bbd8791 100644 --- a/src/blt/std/system.cpp +++ b/src/blt/std/system.cpp @@ -4,4 +4,5 @@ * See LICENSE file for license detail */ #include -#include \ No newline at end of file +#include +#include \ No newline at end of file