Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	includes/deps/TerreateMath/utils.hpp
#	tests/TCTest.cpp
  • Loading branch information
uPiscium committed Jul 10, 2024
2 parents 8e12011 + aec54ec commit 3039dfb
Show file tree
Hide file tree
Showing 51 changed files with 1,862 additions and 551 deletions.
77 changes: 75 additions & 2 deletions impls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,79 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
message(STATUS "C++ standard : " ${CMAKE_CXX_STANDARD})

set(NONE -1)
set(CRITICAL 0)
set(ERROR 1)
set(WARNING 2)
set(INFO 3)
set(DEBUG 4)
set(TRACE 5)

set(LOGLEVEL
"WARNING"
CACHE STRING "Log level")
set(ERRORLEVEL
"CRITICAL"
CACHE STRING "Error level")
message(STATUS "Log level : " ${LOGLEVEL})
message(STATUS "Error level : " ${ERRORLEVEL})

function(SetLogLevel)
if(${${LOGLEVEL}} GREATER_EQUAL CRITICAL)
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_LOG_CRITICAL=1)
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_LOG_CRITICAL=0)
endif()

if(${${LOGLEVEL}} GREATER_EQUAL ERROR)
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_LOG_ERROR=1)
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_LOG_ERROR=0)
endif()

if(${${LOGLEVEL}} GREATER_EQUAL WARNING)
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_LOG_WARNING=1)
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_LOG_WARNING=0)
endif()

if(${${LOGLEVEL}} GREATER_EQUAL INFO)
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_LOG_INFO=1)
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_LOG_INFO=0)
endif()

if(${${LOGLEVEL}} GREATER_EQUAL DEBUG)
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_LOG_DEBUG=1)
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_LOG_DEBUG=0)
endif()

if(${${LOGLEVEL}} GREATER_EQUAL TRACE)
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_LOG_TRACE=1)
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_LOG_TRACE=0)
endif()

if(${${ERRORLEVEL}} GREATER_EQUAL CRITICAL)
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_THROW_CRITICAL=1)
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_THROW_CRITICAL=0)
endif()

if(${${ERRORLEVEL}} GREATER_EQUAL ERROR)
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_THROW_ERROR=1)
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_THROW_ERROR=0)
endif()

if(${${ERRORLEVEL}} GREATER_EQUAL WARNING)
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_THROW_WARNING=1)
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE TC_THROW_WARNING=0)
endif()
endfunction()

function(CloneTerreateLogger)
message(STATUS "Cloning TerreateLogger...")
set(TERREATE_LOGGER_BUILD_TESTS OFF)
Expand Down Expand Up @@ -70,9 +143,9 @@ function(Build)
font.cpp
gl.cpp
job.cpp
logger.cpp
model.cpp
object.cpp
scene.cpp
screen.cpp
shader.cpp
skeleton.cpp
Expand All @@ -82,7 +155,7 @@ function(Build)
set_target_properties(
${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

setloglevel()
setincludes()
setlibs()
endfunction()
Expand Down
11 changes: 9 additions & 2 deletions impls/TerreateCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ void Clock::Frame(Uint const &fps) {
}
}

void Initialize() {
void Initialize(Bool const &enableConsoleLog) {
if (enableConsoleLog) {
LoggerManager::Register(new ConsoleLogger("TerrcateCore/ConsoleLogger"));
}
LoggerManager::Register(
new FileLogger("TerrcateCore/FileLogger", "build/log.txt"));

if (!glfwInit()) {
TC_THROW("Failed to initialize GLFW");
Logger::Critical("Failed to initialize GLFW");
return;
}

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
Expand Down
11 changes: 6 additions & 5 deletions impls/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace TerreateCore::Animation {
using namespace TerreateCore::Defines;
using namespace TerreateMath::Utils;

void Animation::AddKeyFrame(Transform const &keyFrame, Float const &time) {
mKeyFrames.push_back(keyFrame);
Expand Down Expand Up @@ -45,18 +46,18 @@ Transform Animation::Interpolate(Float const &time) const {
Transform const &k1 = mKeyFrames[index];

Transform result;
result.scale = Math::Lerp(k0.scale, k1.scale, t);
result.position = Math::Lerp(k0.position, k1.position, t);
result.scale = Lerp(k0.scale, k1.scale, t);
result.position = Lerp(k0.position, k1.position, t);
// result.rotation = Math::Lerp(k0.rotation, k1.rotation, t);

return result;
}

mat4 Animation::TransformToMatrix(Transform const &transform) {
mat4 result = Eye<Float>(4);
result = Math::Scale(transform.scale) * result;
result = Math::ToMatrix(transform.rotation) * result;
result = Math::Translate(transform.position) * result;
result = Scale(transform.scale) * result;
result = ToMatrix(transform.rotation) * result;
result = Translate(transform.position) * result;
return result;
}
} // namespace TerreateCore::Animation
66 changes: 64 additions & 2 deletions impls/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,46 @@
namespace TerreateCore::Core {
using namespace TerreateCore::Defines;

Attribute::Attribute(Ulong const &index, Ulong const &comps,
Ulong const &stride, Ulong const &offset)
: mIndex(index), mComps(comps), mStride(stride), mOffset(offset) {
Logger::Trace(LOCATION(Attribute));
Logger::Debug("Attribute is generated.");
}

Ulong const &Attribute::GetIndex() const {
Logger::Trace(LOCATION(Attribute));

return mIndex;
}

Ulong const &Attribute::GetComps() const {
Logger::Trace(LOCATION(Attribute));

return mComps;
}

Ulong const &Attribute::GetStride() const {
Logger::Trace(LOCATION(Attribute));

return mStride;
}

Ulong const &Attribute::GetOffset() const {
Logger::Trace(LOCATION(Attribute));

return mOffset;
}

Vec<Attribute> Attribute::GenerateAttributes(Vec<Ulong> const &comps) {
Logger::Trace(LOCATION(Attribute));

Vec<Attribute> attributes;
Ulong stride = 0;
for (Ulong i = 0; i < comps.size(); ++i) {
stride += comps[i] * sizeof(Float);
}

Ulong offset = 0;
for (Ulong i = 0; i < comps.size(); ++i) {
attributes.push_back(Attribute(i, comps[i], stride, offset));
Expand All @@ -20,6 +54,8 @@ Vec<Attribute> Attribute::GenerateAttributes(Vec<Ulong> const &comps) {
Vec<Attribute> Attribute::GenerateAttributes(Vec<Ulong> const &comps,
Vec<Ulong> const &offsets,
Vec<Ulong> const &strides) {
Logger::Trace(LOCATION(Attribute));

Vec<Attribute> attributes;
for (Ulong i = 0; i < comps.size(); ++i) {
attributes.push_back(Attribute(i, comps[i], strides[i], offsets[i]));
Expand All @@ -28,18 +64,34 @@ Vec<Attribute> Attribute::GenerateAttributes(Vec<Ulong> const &comps,
}

Buffer::Buffer(BufferUsage usage) : mUsage(usage) {
Logger::Trace(LOCATION(Buffer));

glGenVertexArrays(1, &mVAO);
glGenBuffers(1, &mVBO);
glGenBuffers(1, &mIBO);

Logger::Debug("Buffer is generated.");
}

Buffer::~Buffer() {
Logger::Trace(LOCATION(Buffer));

glDeleteVertexArrays(1, &mVAO);
glDeleteBuffers(1, &mVBO);
glDeleteBuffers(1, &mIBO);

Logger::Debug("Buffer is deleted.");
}

BufferUsage const &Buffer::GetUsage() const {
Logger::Trace(LOCATION(Buffer));

return mUsage;
}

void Buffer::LoadVertices(Float const *data, Size const &size) {
Logger::Trace(LOCATION(Buffer));

glBindVertexArray(mVAO);
glBindBuffer(GL_ARRAY_BUFFER, mVBO);
if (mSetVBO) {
Expand All @@ -54,6 +106,8 @@ void Buffer::LoadVertices(Float const *data, Size const &size) {
}

void Buffer::LoadIndices(Uint const *data, Size const &size) {
Logger::Trace(LOCATION(Buffer));

mNumIndices = size / sizeof(Uint);
glBindVertexArray(mVAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIBO);
Expand All @@ -69,6 +123,8 @@ void Buffer::LoadIndices(Uint const *data, Size const &size) {
}

void Buffer::LoadAttributes(Attribute const *attributes, Size const &size) {
Logger::Trace(LOCATION(Buffer));

glBindVertexArray(mVAO);
glBindBuffer(GL_ARRAY_BUFFER, mVBO);

Expand All @@ -84,20 +140,26 @@ void Buffer::LoadAttributes(Attribute const *attributes, Size const &size) {
}

void Buffer::Draw(DrawMode const &drawMode) {
Logger::Trace(LOCATION(Buffer));

glBindVertexArray(mVAO);
if (mNumIndices == 0) {
TC_THROW("No indices loaded.");
Logger::Error("No indices loaded.");
return;
}
glDrawElements((GLenum)drawMode, mNumIndices, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
}

void Buffer::DrawInstances(size_t const &numInstances,
DrawMode const &drawMode) {
Logger::Trace(LOCATION(Buffer));

glBindVertexArray(mVAO);

if (mNumIndices == 0) {
TC_THROW("No indices loaded.");
Logger::Error("No indices loaded.");
return;
}

glDrawElementsInstanced((GLenum)drawMode, mNumIndices, GL_UNSIGNED_INT, 0,
Expand Down
18 changes: 18 additions & 0 deletions impls/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
namespace TerreateCore::Event {
using namespace TerreateCore::Defines;

EventSystem::EventSystem() {
Logger::Trace(LOCATION(EventSystem));
Logger::Debug("EventSystem is generated.");
}

EventSystem::~EventSystem() {
Logger::Trace(LOCATION(EventSystem));
Logger::Debug("EventSystem is deleted.");
}

void EventSystem::Register(Str const &event, EventCallback const &callback) {
Logger::Trace(LOCATION(EventSystem));

if (mCallbacks.find(event) == mCallbacks.end()) {
mCallbacks[event] = Vec<EventCallback>();
}
Expand All @@ -12,6 +24,8 @@ void EventSystem::Register(Str const &event, EventCallback const &callback) {
}

void EventSystem::AddTrigger(Str const &event, EventCallback const &callback) {
Logger::Trace(LOCATION(EventSystem));

if (mTriggers.find(event) == mTriggers.end()) {
mTriggers[event] = Queue<EventCallback>();
}
Expand All @@ -20,6 +34,8 @@ void EventSystem::AddTrigger(Str const &event, EventCallback const &callback) {
}

void EventSystem::ProcessEvents() {
Logger::Trace(LOCATION(EventSystem));

UniqueLock<Mutex> lock(mQueueMutex);
while (!mEventQueue.empty()) {
Str event = mEventQueue.front();
Expand All @@ -41,6 +57,8 @@ void EventSystem::ProcessEvents() {
}

void EventSystem::PublishEvent(Str const &event) {
Logger::Trace(LOCATION(EventSystem));

LockGuard<Mutex> lock(mQueueMutex);
mEventQueue.push(event);
}
Expand Down
Loading

0 comments on commit 3039dfb

Please sign in to comment.