Compare commits
11 Commits
2ef222b7ba
...
cff7164d27
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cff7164d27 | ||
|
|
13ef940b2d | ||
|
|
58121bdf28 | ||
|
|
0f62aecfa3 | ||
|
|
40cf079e9d | ||
|
|
fb695798e7 | ||
|
|
e1c456bfe4 | ||
|
|
e23e062e58 | ||
|
|
fd7d36e4be | ||
|
|
0b473c0f8a | ||
|
|
d448b6724a |
11
README.md
11
README.md
@ -1,7 +1,5 @@
|
||||
# NBEngine
|
||||
|
||||
My own GUI (and related stuff needed for GUI programs) engine. I suck at coding. Do not judge.
|
||||
|
||||
## Current Implemented Libraries
|
||||
|
||||
These are subject to (hopefully) grow in size as more stuff gets added.
|
||||
@ -11,11 +9,12 @@ These are subject to (hopefully) grow in size as more stuff gets added.
|
||||
|
||||
## Dependencies and Foundations
|
||||
|
||||
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):
|
||||
For Code:
|
||||
|
||||
* GLFW
|
||||
* Glad
|
||||
|
||||
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).
|
||||
For Repo:
|
||||
|
||||
* gTest
|
||||
* doxygen
|
||||
@ -6,9 +6,11 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include "TypeTraits.hpp"
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Logger.hpp"
|
||||
#include "StringUtils.hpp"
|
||||
#include "TypeTraits.hpp"
|
||||
|
||||
namespace nb {
|
||||
|
||||
@ -273,8 +275,38 @@ public:
|
||||
static const std::string type;
|
||||
static const ErrorCodeMap ErrorMessages;
|
||||
};
|
||||
|
||||
|
||||
} // 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
|
||||
@ -9,13 +9,15 @@
|
||||
#include <vector>
|
||||
|
||||
#include "DataSink.hpp"
|
||||
#include "Errors.hpp"
|
||||
#include "Processes.hpp"
|
||||
#include "ThreadSafeQueue.hpp"
|
||||
#include "TypeTraits.hpp"
|
||||
|
||||
namespace nb {
|
||||
|
||||
template <typename T>
|
||||
class ErrorBase;
|
||||
|
||||
typedef std::chrono::time_point<
|
||||
std::chrono::system_clock,
|
||||
std::chrono::nanoseconds
|
||||
@ -131,7 +133,10 @@ public:
|
||||
U val,
|
||||
std::string file="",
|
||||
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:
|
||||
std::vector<std::ostream*> _ostream;
|
||||
@ -167,103 +172,6 @@ extern DefaultDebugLogger logger;
|
||||
|
||||
// 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
|
||||
|
||||
#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
|
||||
@ -7,6 +7,8 @@
|
||||
namespace nb {
|
||||
|
||||
uint64_t GetPID();
|
||||
uint64_t getTID();
|
||||
|
||||
|
||||
} // namespace nb
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#ifndef _NB_CORE_TYPES
|
||||
#define _NB_CORE_TYPES
|
||||
#ifndef _NB_STRING_UTILS
|
||||
#define _NB_STRING_UTILS
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@ -76,4 +76,4 @@ std::string indent_strblock(
|
||||
);
|
||||
|
||||
} // namespace nb
|
||||
#endif // _NB_CORE_TYPES
|
||||
#endif // _NB_STRING_UTILS
|
||||
@ -2,23 +2,79 @@
|
||||
#ifndef _NB_CORE_TYPES
|
||||
#define _NB_CORE_TYPES
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include "Errors.hpp"
|
||||
|
||||
namespace nb {
|
||||
|
||||
/* 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);
|
||||
using ByteVector = std::vector<uint8_t>;
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
memcpy(retLoc+i, valLoc+(size-i-1), 1);
|
||||
class ObjectManagerError : public Error<ObjectManagerError> {
|
||||
using Base = Error<ObjectManagerError>;
|
||||
|
||||
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>;
|
||||
|
||||
// using ByteVector = std::vector<uint8_t>;
|
||||
protected:
|
||||
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
|
||||
#endif // _NB_CORE_TYPES
|
||||
@ -33,8 +33,6 @@ static bool RUN_LOGGER(nb::DefaultDebugLogger& log) {
|
||||
return log.run();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static const bool LOGGER_RUNNING = RUN_LOGGER(logger);
|
||||
|
||||
} // namespace nb
|
||||
@ -15,7 +15,14 @@ uint64_t GetPID() {
|
||||
return GetCurrentProcessId();
|
||||
}
|
||||
#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
|
||||
#endif // _NB_TARGET_LINUX
|
||||
|
||||
|
||||
@ -1 +1,27 @@
|
||||
#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