Compare commits
9 Commits
cff7164d27
...
2ef222b7ba
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ef222b7ba | ||
|
|
1c40d98812 | ||
|
|
85241b4aa5 | ||
|
|
a5dc639958 | ||
|
|
1b4a891a58 | ||
|
|
6c71bd46af | ||
|
|
b593b7e083 | ||
|
|
a927b96a99 | ||
|
|
126862748e |
11
README.md
11
README.md
@ -1,5 +1,7 @@
|
|||||||
# NBEngine
|
# NBEngine
|
||||||
|
|
||||||
|
My own GUI (and related stuff needed for GUI programs) engine. I suck at coding. Do not judge.
|
||||||
|
|
||||||
## Current Implemented Libraries
|
## Current Implemented Libraries
|
||||||
|
|
||||||
These are subject to (hopefully) grow in size as more stuff gets added.
|
These are subject to (hopefully) grow in size as more stuff gets added.
|
||||||
@ -9,12 +11,11 @@ These are subject to (hopefully) grow in size as more stuff gets added.
|
|||||||
|
|
||||||
## Dependencies and Foundations
|
## Dependencies and Foundations
|
||||||
|
|
||||||
For Code:
|
While the engine is intended to be a close-to-ground-up project, there's no point in reinventing the spokes that
|
||||||
|
make up a wheel. This project utilizes and depends on (expected to change and grow):
|
||||||
|
|
||||||
* GLFW
|
* GLFW
|
||||||
* Glad
|
* Glad
|
||||||
|
|
||||||
For Repo:
|
Additionally, it's important to note that right now this project is on Windows only. I wanna work on this in Linux soon
|
||||||
|
("soon" whatever that means. Maybe in like 5 years).
|
||||||
* gTest
|
|
||||||
* doxygen
|
|
||||||
|
|||||||
@ -6,11 +6,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
#include "Logger.hpp"
|
|
||||||
#include "StringUtils.hpp"
|
|
||||||
#include "TypeTraits.hpp"
|
#include "TypeTraits.hpp"
|
||||||
|
#include <unordered_map>
|
||||||
|
#include "StringUtils.hpp"
|
||||||
|
|
||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
@ -275,38 +273,8 @@ public:
|
|||||||
static const std::string type;
|
static const std::string type;
|
||||||
static const ErrorCodeMap ErrorMessages;
|
static const ErrorCodeMap ErrorMessages;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace nb
|
} // namespace nb
|
||||||
|
|
||||||
#ifdef _NB_AUTOLOG
|
|
||||||
#ifdef _NB_CODE_ERROR_LOCATIONS
|
|
||||||
#ifndef LOG
|
|
||||||
#define LOG(args...) nb::logger.log(args, __FILE__, __LINE__)
|
|
||||||
#endif // LOG
|
|
||||||
#ifndef WARN
|
|
||||||
#define WARN(args...) nb::logger.warn(args, __FILE__, __LINE__)
|
|
||||||
#endif // WARN
|
|
||||||
#ifndef ERROR
|
|
||||||
#define ERROR(args...) nb::logger.error(args, __FILE__, __LINE__)
|
|
||||||
#endif // ERROR
|
|
||||||
#else
|
|
||||||
#ifndef LOG
|
|
||||||
#define LOG(args...) nb::logger.log(args)
|
|
||||||
#endif // LOG
|
|
||||||
#ifndef WARN
|
|
||||||
#define WARN(args...) nb::logger.warn(args)
|
|
||||||
#endif // WARN
|
|
||||||
#ifndef ERROR
|
|
||||||
#define ERROR(args...) nb::logger.error(args)
|
|
||||||
#endif // ERROR
|
|
||||||
#endif // _NB_CODE_ERROR_LOCATIONS
|
|
||||||
#endif // _NB_AUTOLOG
|
|
||||||
|
|
||||||
#ifndef THROW
|
|
||||||
#ifdef _NB_AUTOLOG
|
|
||||||
#define THROW(args...) ERROR(args); throw args
|
|
||||||
#else
|
|
||||||
#define THROW(args...) throw args
|
|
||||||
#endif // _NB_CODE_ERROR_LOCATIONS
|
|
||||||
#endif // THROW
|
|
||||||
|
|
||||||
#endif // _NB_ERROR
|
#endif // _NB_ERROR
|
||||||
@ -9,15 +9,13 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "DataSink.hpp"
|
#include "DataSink.hpp"
|
||||||
|
#include "Errors.hpp"
|
||||||
#include "Processes.hpp"
|
#include "Processes.hpp"
|
||||||
#include "ThreadSafeQueue.hpp"
|
#include "ThreadSafeQueue.hpp"
|
||||||
#include "TypeTraits.hpp"
|
#include "TypeTraits.hpp"
|
||||||
|
|
||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
class ErrorBase;
|
|
||||||
|
|
||||||
typedef std::chrono::time_point<
|
typedef std::chrono::time_point<
|
||||||
std::chrono::system_clock,
|
std::chrono::system_clock,
|
||||||
std::chrono::nanoseconds
|
std::chrono::nanoseconds
|
||||||
@ -133,10 +131,7 @@ public:
|
|||||||
U val,
|
U val,
|
||||||
std::string file="",
|
std::string file="",
|
||||||
unsigned int line=0
|
unsigned int line=0
|
||||||
) {
|
) { static_cast<LoggerType*>(this)->log(val, 0xFF, file, line); }
|
||||||
static_cast<LoggerType*>(this)->log(val, 0xFF, file, line);
|
|
||||||
static_cast<LoggerType*>(this)->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<std::ostream*> _ostream;
|
std::vector<std::ostream*> _ostream;
|
||||||
@ -172,6 +167,103 @@ extern DefaultDebugLogger logger;
|
|||||||
|
|
||||||
// Taking Charge of Adult ADHD by Russell Barkley
|
// Taking Charge of Adult ADHD by Russell Barkley
|
||||||
|
|
||||||
|
/* template <typename T=NoneType>
|
||||||
|
struct NB_DEFAULT_LOGGER_THROW;
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct NB_DEFAULT_LOGGER_THROW<NoneType> {
|
||||||
|
template <typename T>
|
||||||
|
NB_DEFAULT_LOGGER_THROW(T arg) {
|
||||||
|
#ifdef _NB_AUTOLOG
|
||||||
|
logger.error(arg);
|
||||||
|
#endif // _NB_AUTLOG
|
||||||
|
throw arg;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct NB_DEFAULT_LOGGER_THROW {
|
||||||
|
template <typename... Args>
|
||||||
|
NB_DEFAULT_LOGGER_THROW(Args&&... args) {
|
||||||
|
std::shared_ptr<T> error_ptr;
|
||||||
|
#ifdef _NB_AUTOLOG
|
||||||
|
#ifdef _NB_CODE_ERROR_LOCATIONS
|
||||||
|
error_ptr = std::make_shared<T>(args..., __LINE__, __FILE__);
|
||||||
|
#else
|
||||||
|
error_ptr = std::make_shared<T>(args...);
|
||||||
|
#endif // _NB_CODE_ERROR_LOCATIONS
|
||||||
|
logger.error(*error_ptr);
|
||||||
|
#endif // _NB_AUTLOG
|
||||||
|
throw *error_ptr;
|
||||||
|
}
|
||||||
|
}; */
|
||||||
|
|
||||||
|
/* template <typename Arg1=NoneType, typename...Args>
|
||||||
|
void NB_DEFAULT_LOGGER_THROW(Args&& ... args) {
|
||||||
|
std::shared_ptr<Arg1> error_ptr;
|
||||||
|
#ifdef _NB_AUTOLOG
|
||||||
|
#ifdef _NB_CODE_ERROR_LOCATIONS
|
||||||
|
error_ptr = std::make_shared<Arg1>(args..., __LINE__, __FILE__);
|
||||||
|
#else
|
||||||
|
error_ptr = std::make_shared<Arg1>(args...);
|
||||||
|
#endif // _NB_CODE_ERROR_LOCATIONS
|
||||||
|
logger.error(*error_ptr);
|
||||||
|
#endif // _NB_AUTLOG
|
||||||
|
throw *error_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Arg>
|
||||||
|
void NB_DEFAULT_LOGGER_THROW<NoneType>(const Arg& arg) {
|
||||||
|
#ifdef _NB_AUTOLOG
|
||||||
|
logger.error(arg);
|
||||||
|
#endif // _NB_AUTLOG
|
||||||
|
throw arg;
|
||||||
|
} */
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void NB_DEFAULT_LOGGER_THROW(const T& err, std::string file="", unsigned int line = 0) {
|
||||||
|
#ifdef _NB_AUTOLOG
|
||||||
|
if (file.empty()) {
|
||||||
|
logger.error(err);
|
||||||
|
} else {
|
||||||
|
logger.error(err, file, line);
|
||||||
|
}
|
||||||
|
#endif // _NB_AUTLOG
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace nb
|
} // namespace nb
|
||||||
|
|
||||||
|
#ifdef _NB_AUTOLOG
|
||||||
|
#ifdef _NB_CODE_ERROR_LOCATIONS
|
||||||
|
#ifndef LOG
|
||||||
|
#define LOG(args...) nb::logger.log(args, __FILE__, __LINE__)
|
||||||
|
#endif // LOG
|
||||||
|
#ifndef WARN
|
||||||
|
#define WARN(args...) nb::logger.warn(args, __FILE__, __LINE__)
|
||||||
|
#endif // WARN
|
||||||
|
#ifndef ERROR
|
||||||
|
#define ERROR(args...) nb::logger.error(args, __FILE__, __LINE__)
|
||||||
|
#endif // ERROR
|
||||||
|
#else
|
||||||
|
#ifndef LOG
|
||||||
|
#define LOG(args...) nb::logger.log(args)
|
||||||
|
#endif // LOG
|
||||||
|
#ifndef WARN
|
||||||
|
#define WARN(args...) nb::logger.warn(args)
|
||||||
|
#endif // WARN
|
||||||
|
#ifndef ERROR
|
||||||
|
#define ERROR(args...) nb::logger.error(args)
|
||||||
|
#endif // ERROR
|
||||||
|
#endif // _NB_CODE_ERROR_LOCATIONS
|
||||||
|
#endif // _NB_AUTOLOG
|
||||||
|
|
||||||
|
#ifndef THROW
|
||||||
|
#ifdef _NB_AUTOLOG
|
||||||
|
#define THROW(args...) ERROR(args); throw args
|
||||||
|
#else
|
||||||
|
#define THROW(args...) throw args
|
||||||
|
#endif // _NB_CODE_ERROR_LOCATIONS
|
||||||
|
#endif // THROW
|
||||||
|
|
||||||
#endif // _NB_LOGGER
|
#endif // _NB_LOGGER
|
||||||
@ -7,8 +7,6 @@
|
|||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
uint64_t GetPID();
|
uint64_t GetPID();
|
||||||
uint64_t getTID();
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace nb
|
} // namespace nb
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef _NB_STRING_UTILS
|
#ifndef _NB_CORE_TYPES
|
||||||
#define _NB_STRING_UTILS
|
#define _NB_CORE_TYPES
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -76,4 +76,4 @@ std::string indent_strblock(
|
|||||||
);
|
);
|
||||||
|
|
||||||
} // namespace nb
|
} // namespace nb
|
||||||
#endif // _NB_STRING_UTILS
|
#endif // _NB_CORE_TYPES
|
||||||
@ -2,79 +2,23 @@
|
|||||||
#ifndef _NB_CORE_TYPES
|
#ifndef _NB_CORE_TYPES
|
||||||
#define _NB_CORE_TYPES
|
#define _NB_CORE_TYPES
|
||||||
|
|
||||||
#include <mutex>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "Errors.hpp"
|
|
||||||
|
|
||||||
namespace nb {
|
namespace nb {
|
||||||
|
|
||||||
using ByteVector = std::vector<uint8_t>;
|
/* template<typename T>
|
||||||
|
T swap_endian(const T& val) {
|
||||||
|
T ret;
|
||||||
|
const int size = sizeof(T);
|
||||||
|
auto retLoc = static_cast<void*>(&ret);
|
||||||
|
auto valLoc = static_cast<const void*>(&val);
|
||||||
|
|
||||||
class ObjectManagerError : public Error<ObjectManagerError> {
|
for (int i = 0; i < size; ++i) {
|
||||||
using Base = Error<ObjectManagerError>;
|
memcpy(retLoc+i, valLoc+(size-i-1), 1);
|
||||||
|
|
||||||
public:
|
|
||||||
using Base::Base;
|
|
||||||
|
|
||||||
enum Codes : unsigned int {
|
|
||||||
UNDEFINED, NO_MANAGER, MANAGER_MISMATCH, LOCK_OVERFLOW, BAD_THREAD
|
|
||||||
};
|
|
||||||
|
|
||||||
static const std::string type;
|
|
||||||
static const ErrorCodeMap ErrorMessages;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
class ThreadsafeObjectLock;
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
class ThreadsafeObject {
|
|
||||||
using Codes = ObjectManagerError::Codes;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ThreadsafeObject(T&& obj)
|
|
||||||
: _obj(std::make_shared<T>(obj)) {}
|
|
||||||
|
|
||||||
ThreadsafeObjectLock<T> lock() {
|
|
||||||
return ThreadsafeObjectLock<T>(this);
|
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
|
} */
|
||||||
|
|
||||||
friend ThreadsafeObjectLock<T>;
|
|
||||||
|
|
||||||
protected:
|
// using ByteVector = std::vector<uint8_t>;
|
||||||
std::shared_ptr<T> _obj;
|
|
||||||
mutable std::recursive_mutex _mutex;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
class ThreadsafeObjectLock {
|
|
||||||
public:
|
|
||||||
ThreadsafeObjectLock(const ThreadsafeObjectLock&) = delete;
|
|
||||||
ThreadsafeObjectLock operator=(const ThreadsafeObjectLock&) = delete;
|
|
||||||
~ThreadsafeObjectLock() {
|
|
||||||
_manager->_mutex.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
T* operator->() {
|
|
||||||
return _manager->_obj.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
friend ThreadsafeObject<T>;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
ThreadsafeObjectLock(
|
|
||||||
ThreadsafeObject<T>* const manager_
|
|
||||||
) : _manager(manager_) {
|
|
||||||
if (!_manager) {
|
|
||||||
using Codes = ObjectManagerError::Codes;
|
|
||||||
THROW(ObjectManagerError(Codes::NO_MANAGER));
|
|
||||||
}
|
|
||||||
_manager->_mutex.lock();
|
|
||||||
}
|
|
||||||
ThreadsafeObject<T>* const _manager;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace nb
|
} // namespace nb
|
||||||
#endif // _NB_CORE_TYPES
|
#endif // _NB_CORE_TYPES
|
||||||
@ -33,6 +33,8 @@ static bool RUN_LOGGER(nb::DefaultDebugLogger& log) {
|
|||||||
return log.run();
|
return log.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const bool LOGGER_RUNNING = RUN_LOGGER(logger);
|
static const bool LOGGER_RUNNING = RUN_LOGGER(logger);
|
||||||
|
|
||||||
} // namespace nb
|
} // namespace nb
|
||||||
@ -15,14 +15,7 @@ uint64_t GetPID() {
|
|||||||
return GetCurrentProcessId();
|
return GetCurrentProcessId();
|
||||||
}
|
}
|
||||||
#endif // _NB_TARGET_WINDOWS
|
#endif // _NB_TARGET_WINDOWS
|
||||||
#ifdef _NB_TARGET_LINUX
|
|
||||||
#endif // _NB_TARGET_LINUX
|
|
||||||
|
|
||||||
#ifdef _NB_TARGET_WINDOWS
|
|
||||||
uint64_t GetTID() {
|
|
||||||
return GetCurrentThreadId();
|
|
||||||
}
|
|
||||||
#endif // _NB_TARGET_WINDOWS
|
|
||||||
#ifdef _NB_TARGET_LINUX
|
#ifdef _NB_TARGET_LINUX
|
||||||
#endif // _NB_TARGET_LINUX
|
#endif // _NB_TARGET_LINUX
|
||||||
|
|
||||||
|
|||||||
@ -1,27 +1 @@
|
|||||||
#include "Utils.hpp"
|
|
||||||
|
|
||||||
namespace nb {
|
|
||||||
|
|
||||||
using ObjectManagerCodes = ObjectManagerError::Codes;
|
|
||||||
const std::string ObjectManagerError::type = "nb::ObjectManagerError";
|
|
||||||
const ErrorCodeMap ObjectManagerError::ErrorMessages({
|
|
||||||
{ObjectManagerCodes::UNDEFINED, "Error"},
|
|
||||||
{
|
|
||||||
ObjectManagerCodes::NO_MANAGER,
|
|
||||||
"Attempting to create object lock without lock manager"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ObjectManagerCodes::MANAGER_MISMATCH,
|
|
||||||
"Attempting to delete object lock from mismatched lock manager"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ObjectManagerCodes::LOCK_OVERFLOW,
|
|
||||||
"Too many object locks allocated"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ObjectManagerCodes::BAD_THREAD,
|
|
||||||
"Attempting operation from a bad thread"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}; // namespace nb
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user