- Began outlining tokenizer.h and priority_queue.h

- Began outlining sdl implementation
- Added some helper definitions to various classes
- Added contains to string.h and wstring.h
This commit is contained in:
2025-09-13 20:33:46 -04:00
parent 3565bbbc52
commit f2a45aa913
16 changed files with 331 additions and 16 deletions

View File

@@ -0,0 +1,66 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
///
/// \file priority_queue.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_CONTAINERS_PRIORITY_QUEUE_H
#define FENNEC_CONTAINERS_PRIORITY_QUEUE_H
#include <fennec/containers/object_pool.h>
#include <fennec/lang/compare.h>
#include <fennec/lang/types.h>
#include <fennec/memory/allocator.h>
namespace fennec
{
template<typename ValueT, class CompareT = less<ValueT>, class AllocT = allocator<ValueT>>
struct priority_queue {
public:
using value_t = ValueT;
using compare_t = CompareT;
using alloc_t = AllocT;
private:
struct node {
size_t parent, child;
size_t left, right;
int degree;
value_t key;
};
using table_t = object_pool<node>;
public:
table_t _table;
};
}
#endif // FENNEC_CONTAINERS_PRIORITY_QUEUE_H

View File

@@ -0,0 +1,96 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
///
/// \file tokenizer.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_LANGPROC_FORMAT_TOKENIZER_H
#define FENNEC_LANGPROC_FORMAT_TOKENIZER_H
#include <fennec/containers/list.h>
#include <fennec/langproc/strings/string.h>
//
// escape sequences are tricky, sometimes they must be separated by white space,
// other times they don't. Requiring a list of all possible escape sequences is unrealistic.
// We need to allow the user of this struct to specify rules for escape sequences. Here are some basic rules:
//
// An escape sequence is marked by an escape character, e.g. %, \, {{
// Multiple escape characters may be used in a single tokenizer and will have different rules
// Escape characters may also be operators, brackets, or quotes
// Escape sequences may contain operators, brackets, or quotes
//
// Here are a few examples of escape sequences from various formats and languages
// C: \\, \n, \0, \u200b
// PrintF: %s, %2.2f
// Python FMT: {{, }}
// SPSS: ''
//
namespace fennec
{
struct escape_sequence {
virtual size_t operator[](const std::string& str, size_t i) = 0;
};
struct tokenizer {
using escseq = escape_sequence*;
using escmap = map<char, escape_sequence*>;
string delimiter; // markers that separate tokens
string operators; // operators are treated as individual tokens
string brackets; // characters that mark brackets
string quotes; // characters that mark a string sequence, entire string sequence is treated as one token
escmap escapes; // characters that mark the start of an escape sequence and validate them
enum token_ : uint8_t {
token_string = 0,
token_newline = 1,
token_escaped = 2,
token_operator = 3,
token_bracket = 4,
token_quoted = 5,
};
using token = pair<string, uint8_t>;
private:
list<token> operator()(const string& line) {
list<token> res;
for (size_t i = 0; i < )
return res;
}
private:
};
}
#endif // FENNEC_LANGPROC_FORMAT_TOKENIZER_H

View File

@@ -58,6 +58,7 @@ struct cstring
{
public:
static constexpr size_t npos = -1;
using char_t = char;
// Constructors ========================================================================================================

View File

@@ -47,6 +47,7 @@ struct _string
{
public:
static constexpr size_t npos = -1;
using char_t = char;
using alloc_t = allocation<char, AllocT>;
@@ -197,7 +198,7 @@ public:
if (i >= size()) { // bounds check
return -1;
}
n = fennec::min(n, fennec::max(_str, str.size()) + 1);
n = fennec::min(n, fennec::max(size(), str.size()) + 1);
return ::strncmp(_str + i, str, n);
}
@@ -216,10 +217,23 @@ public:
return ::strncmp(_str + i, str.data(), n);
}
constexpr bool operator==(const cstring& str) const {
return compare(str) == 0;
}
constexpr bool operator==(const _string& str) const {
return compare(str) == 0;
}
///
/// \brief Check if the string contains a character
/// \param c
/// \param i
/// \return
constexpr bool contains(char c, size_t i = 0) const {
return find(c, i) != size();
}
///
/// \brief Finds the index of the first occurrence of `c` in the string
/// \param c the character to find
@@ -242,7 +256,7 @@ public:
return size();
}
const char* loc = ::strstr(_str, str);
const char* loc = ::strstr(_str, str._str);
return loc ? loc - _str : size();
}
@@ -325,7 +339,7 @@ public:
/// \param n the number of characters
/// \return
constexpr _string substring(size_t i, size_t n = npos) const {
if (i >= size()) {
if (i >= size() || n == 0) {
return _string("");
}
n = fennec::min(n, size() - i);
@@ -420,6 +434,25 @@ public:
}
// Iteration ===========================================================================================================
constexpr char* begin() {
return _str.data();
}
constexpr const char* begin() const {
return _str.data();
}
constexpr char* end() {
return _str.data() + _str.capacity();
}
constexpr const char* end() const {
return _str.data() + _str.capacity();
}
private:
alloc_t _str;
};

View File

@@ -60,6 +60,7 @@ struct wcstring
{
public:
static constexpr size_t npos = -1;
using char_t = wchar_t;
// Constructors ========================================================================================================

View File

@@ -47,6 +47,7 @@ struct _wstring
{
public:
static constexpr size_t npos = -1;
using char_t = wchar_t;
using alloc_t = allocation<wchar_t, AllocT>;
@@ -216,10 +217,23 @@ public:
return ::wcsncmp(_str + i, str.data(), n);
}
constexpr bool operator==(const wcstring& str) const {
return compare(str) == 0;
}
constexpr bool operator==(const _wstring& str) const {
return compare(str) == 0;
}
///
/// \brief Check if the string contains a character
/// \param c
/// \param i
/// \return
constexpr bool contains(char c, size_t i = 0) const {
return find(c, i) != size();
}
///
/// \brief Finds the index of the first occurrence of `c` in the string
/// \param c the wchar_tacter to find

View File

@@ -306,8 +306,8 @@ public:
// Quaternion Quaternion Arithmetic Operators ==========================================================================
constexpr friend quaternion operator+(const quaternion& lhs, const quaternion& rhs) {
return quaternion(
constexpr friend quat_t operator+(const quat_t& lhs, const quat_t& rhs) {
return quat_t(
lhs.w + rhs.w,
lhs.x + rhs.x,
lhs.y + rhs.y,
@@ -315,8 +315,8 @@ public:
);
}
constexpr friend quaternion operator-(const quaternion& lhs, const quaternion& rhs) {
return quaternion(
constexpr friend quat_t operator-(const quat_t& lhs, const quat_t& rhs) {
return quat_t(
lhs.w - rhs.w,
lhs.x - rhs.x,
lhs.y - rhs.y,
@@ -324,8 +324,8 @@ public:
);
}
constexpr friend quaternion operator*(const quaternion& lhs, const quaternion& rhs) {
return quaternion(
constexpr friend quat_t operator*(const quat_t& lhs, const quat_t& rhs) {
return quat_t(
lhs.w*rhs.w - lhs.x*rhs.x - lhs.y*rhs.y - lhs.z * rhs.z,
lhs.w*rhs.x + lhs.x*rhs.w + lhs.y*rhs.z - lhs.z * rhs.y,
lhs.w*rhs.y - lhs.x*rhs.z + lhs.y*rhs.w + lhs.z * rhs.x,
@@ -336,7 +336,7 @@ public:
// Quaternion Quaternion Arithmetic Assignment Operators ===============================================================
constexpr friend quaternion& operator+=(quaternion& lhs, const quaternion& rhs) {
constexpr friend quat_t& operator+=(quat_t& lhs, const quat_t& rhs) {
lhs.w += rhs.w;
lhs.x += rhs.x;
lhs.y += rhs.y;
@@ -344,7 +344,7 @@ public:
return lhs;
}
constexpr friend quaternion& operator-=(quaternion& lhs, const quaternion& rhs) {
constexpr friend quat_t& operator-=(quat_t& lhs, const quat_t& rhs) {
lhs.w -= rhs.w;
lhs.x -= rhs.x;
lhs.y -= rhs.y;
@@ -352,7 +352,7 @@ public:
return lhs;
}
constexpr friend quaternion& operator*=(quaternion& lhs, const quaternion& rhs) {
constexpr friend quat_t& operator*=(quat_t& lhs, const quat_t& rhs) {
return lhs = lhs * rhs;
}

View File

@@ -280,7 +280,7 @@ public:
/// \details This simply acts as a proxy for allocating memory. It does not call any constructors or
/// initialize any values as if they were the provided data type. Any operations present work
/// only on individual bytes.
template<typename T, class AllocT>
template<typename T, class AllocT = allocator<T>>
struct allocation
{
public:

View File

@@ -33,6 +33,7 @@
#include <fennec/lang/types.h>
#include <fennec/langproc/strings/string.h>
#include <fennec/renderers/interface/gfxcontext.h>
namespace fennec
{
@@ -115,22 +116,29 @@ public:
// Modifiers ===========================================================================================================
virtual void resize(size_t, size_t) = 0;
virtual void position(size_t, size_t) = 0;
virtual void set_fullscreen(bool) = 0;
virtual void set_borderless(bool) = 0;
virtual void grab_mouse(bool) = 0;
virtual void grab_keyboard(bool) = 0;
virtual void set_title(const cstring&) = 0;
virtual void set_title(const string&) = 0;
virtual void vsync(int8_t) = 0;
virtual void set_progress(bool, float) = 0;
virtual void vsync(int8_t) = 0;
// Graphics ============================================================================================================
virtual void begin_frame() = 0;
virtual void end_frame() = 0;
protected:
window* _parent;
window* _parent;
gfxcontext* _context;
config _config;
window(window* parent, const config& cfg)

View File

@@ -38,7 +38,25 @@ namespace fennec
class sdlwindow : public window {
public:
sdlwindow(window* parent, const config& cfg);
bool running() override;
void set_fullscreen(bool) override;
void set_borderless(bool) override;
void grab_mouse(bool) override;
void grab_keyboard(bool) override;
void set_title(const cstring&) override;
void set_title(const string&) override;
void set_progress(bool, float) override;
void vsync(int8_t) override;
void begin_frame() override;
void end_frame() override;
private:

View File

@@ -37,6 +37,7 @@ namespace fennec
class gfxpass; // Overarching rendering scheme
class gfxcontext; // Globals for an API's context
class gfxresourcepool; // Handles resource creation, allocation, and mapping
class gfxpass; // A pass of the renderer, holds a set of subpasses with one coherent objective
class gfxsubpass; // A subpass of the renderer, implements, for example, the steps of composing and lighting a deferred renderer
class gfxpipeline; // A user-defined pipeline, e.g. the Vulkan pipeline needed to render the G-Buffer

View File

@@ -39,17 +39,22 @@ namespace fennec
{
///
/// \brief Defines a renderer interface to implement different graphics APIs, e.g. OpenGL Vulkan
/// \brief Defines an interface that holds a series of passes with one coherent objective
/// \details This represents the overarching renderer, and not any platform specific behaviour.
/// I.E. This acts as a proxy for creating API objects, but the behaviour of those objects
/// is defined elsewhere.
class gfxpass {
public:
gfxsubpass* add_subpass();
private:
};
class gfxsubpass {
};
}
#endif // FENNEC_PLATFORM_INTERFACE_GFXCONTEXT_H