Skip to content

Commit

Permalink
Merge branch 'dev' into object-transportation-project-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
brenocq committed Jan 19, 2025
2 parents 42f179d + 0507d6f commit d8ab3a1
Show file tree
Hide file tree
Showing 291 changed files with 12,189 additions and 5,189 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install cmake xorg-dev curl
sudo apt-get install cmake xorg-dev curl
- name: Build
run: ./build.sh --jobs 2 --compiler ${{ matrix.config.compiler }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/updateReadmeButtons.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Update readme buttons

on:
on:
project_card:
types: [created, deleted, moved]
project:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
}

steps:
- uses: mymindstorm/setup-emsdk@v9
- uses: mymindstorm/setup-emsdk@v13

- name: Checkout atta
uses: actions/checkout@v2

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ tags
imgui.ini

# Debugging/Profile
.cache/
perf.*
.gdb_history
profile/
compile_commands.json
19 changes: 10 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.14)

project(atta VERSION 0.4.0 LANGUAGES CXX C)
project(atta VERSION 0.3.2 LANGUAGES CXX C)

OPTION(ATTA_BUILD_TESTS
"Set to ON to build also the test executables"
Expand All @@ -11,17 +11,18 @@ OPTION(ATTA_WEB_BUILD_MODULE
OPTION(ATTA_BUILD_DOCS
"Build the documentation"
OFF)
option(ATTA_STATIC_PROJECT_FILE
"Project to be linked statically to atta"
option(ATTA_STATIC_PROJECT_FILE
"Project to be linked statically to atta"
"")
option(ATTA_PROFILE
"Set to ON to enable code profiling"
option(ATTA_PROFILE
"Set to ON to enable code profiling"
ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(ATTA_VERSION_SAFE atta-${CMAKE_PROJECT_VERSION})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/atta/cmakeConfig.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/atta/cmakeConfig.h)

Expand Down Expand Up @@ -82,7 +83,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Emscripten)#----- Web build
set(ATTA_BUILD_TESTS OFF CACHE INTERNAL "" FORCE)

# Configure emscripten link flags
set(EMSCRIPTEN_LINK_PROPERTIES "-s USE_WEBGL2=1 -s USE_GLFW=3")
set(EMSCRIPTEN_LINK_PROPERTIES "-s USE_WEBGL2=1 -s USE_GLFW=3 -s GL_ENABLE_GET_PROC_ADDRESS")
set(EMSCRIPTEN_LINK_PROPERTIES "${EMSCRIPTEN_LINK_PROPERTIES} -s ALLOW_MEMORY_GROWTH=1 -s FORCE_FILESYSTEM=1")
set(EMSCRIPTEN_LINK_PROPERTIES "${EMSCRIPTEN_LINK_PROPERTIES} -s NO_DISABLE_EXCEPTION_CATCHING -s EXIT_RUNTIME=1")
set(EMSCRIPTEN_LINK_PROPERTIES "${EMSCRIPTEN_LINK_PROPERTIES} --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/resources@/resources/")
Expand Down Expand Up @@ -123,7 +124,7 @@ if(CMAKE_BUILD_TYPE MATCHES Debug)
list(APPEND ATTA_OPTIONS -Wno-unused-parameter)
# Script C linkage
list(APPEND ATTA_OPTIONS -Wno-return-type-c-linkage)
# Math anonymous union
# Math anonymous union
#list(APPEND ATTA_OPTIONS -Wno-nested-anon-types -Wno-gnu-anonymous-struct)
# Glad opengl definitions
#list(APPEND ATTA_OPTIONS -Wno-macro-redefined)
Expand Down Expand Up @@ -218,7 +219,7 @@ if(ATTA_STATIC_PROJECT)
endif()

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/src/atta/script/scripts.h.in"
"${CMAKE_CURRENT_SOURCE_DIR}/src/atta/script/scripts.h.in"
"${CMAKE_CURRENT_SOURCE_DIR}/src/atta/script/scripts.h"
)

Expand All @@ -236,7 +237,7 @@ if(NOT (ATTA_SYSTEM_NAME MATCHES "Web") AND NOT ATTA_STATIC_PROJECT_FILE)
########## Install files ##########

# Install atta executable
install(TARGETS atta
install(TARGETS atta
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PRIVATE_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${ATTA_VERSION_SAFE}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${ATTA_VERSION_SAFE}
Expand Down
1 change: 1 addition & 0 deletions src/atta/atta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ void Atta::loop() {

file::update();
graphics::update();
resource::update();
}

void Atta::step() {
Expand Down
2 changes: 2 additions & 0 deletions src/atta/cmakeConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

#ifdef ATTA_OS_WEB
#define ATTA_DIR "/"
#define ATTA_BUILD_DIR "/"
#else
#define ATTA_DIR "@CMAKE_SOURCE_DIR@"
#define ATTA_BUILD_DIR "@CMAKE_BINARY_DIR@"
#endif

#define ATTA_VERSION "@CMAKE_PROJECT_VERSION@"
Expand Down
1 change: 1 addition & 0 deletions src/atta/component/components/cameraSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const uint8_t* CameraSensor::getImage() {
if (cameraInfo.component == this)
return cameraInfo.data.data();
ASSERT(false, "(component::CameraSensor) Could not get camera frame from sensor::Manager.");
return nullptr;
}

} // namespace atta::component
57 changes: 42 additions & 15 deletions src/atta/component/components/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

namespace atta::component {

void renderComboImage(std::string attribute, StringId& image) {
bool isImage = (image != resource::Material::emptyImage);
bool renderComboImage(std::string attribute, StringId& image) {
bool isImage = (image != StringId());
bool updated = false;
std::string imguiId = attribute;
if (isImage) {
std::string selectedName = image.getString();
Expand All @@ -24,17 +25,22 @@ void renderComboImage(std::string attribute, StringId& image) {
if (imageStr == "")
imageStr = "##";
const bool selected = (rImage == image);
if (ImGui::Selectable(imageStr.c_str(), selected))
if (ImGui::Selectable(imageStr.c_str(), selected)) {
image = rImage;
updated = true;
}
if (selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
}

if (ImGui::Checkbox(("Is image##IsImage" + imguiId).c_str(), &isImage))
image = isImage ? "textures/white.jpg"_sid : resource::Material::emptyImage;
if (ImGui::Checkbox(("Is image##IsImage" + imguiId).c_str(), &isImage)) {
image = isImage ? "textures/white.png"_sid : StringId();
updated = true;
}
return updated;
}

void materialRenderImGui(void* data, std::string imguiId) {
Expand Down Expand Up @@ -132,29 +138,50 @@ void materialRenderImGui(void* data, std::string imguiId) {
//---------- Edit ----------//
ImGui::Text("Color");
if (!m->colorIsImage()) {
ImGui::SliderFloat("R##ColorR", &m->color.x, 0.0f, 1.0f);
ImGui::SliderFloat("G##ColorG", &m->color.y, 0.0f, 1.0f);
ImGui::SliderFloat("B##ColorB", &m->color.z, 0.0f, 1.0f);
vec3 color = m->getColor();
bool updated = false;
if (ImGui::SliderFloat("R##ColorR", &color.x, 0.0f, 1.0f))
updated = true;
if (ImGui::SliderFloat("G##ColorG", &color.y, 0.0f, 1.0f))
updated = true;
if (ImGui::SliderFloat("B##ColorB", &color.z, 0.0f, 1.0f))
updated = true;
if (updated)
m->setColor(color);
}
renderComboImage("Color", m->colorImage);
StringId colorImage = m->getColorImage();
if (renderComboImage("Color", colorImage))
m->setColorImage(colorImage);

ImGui::Text("Roughness");
if (!m->roughnessIsImage()) {
ImGui::SliderFloat("##Roughness", &m->roughness, 0.0f, 1.0f);
float roughness = m->getRoughness();
if (ImGui::SliderFloat("##Roughness", &roughness, 0.0f, 1.0f))
m->setRoughness(roughness);
}
renderComboImage("Roughness", m->roughnessImage);
StringId roughnessImage = m->getRoughnessImage();
if (renderComboImage("Roughness", roughnessImage))
m->setRoughnessImage(roughnessImage);

ImGui::Text("Metallic");
if (!m->metallicIsImage()) {
ImGui::SliderFloat("##Metallic", &m->metallic, 0.0f, 1.0f);
float metallic = m->getMetallic();
if (ImGui::SliderFloat("##Metallic", &metallic, 0.0f, 1.0f))
m->setMetallic(metallic);
}
renderComboImage("Metallic", m->metallicImage);
StringId metallicImage = m->getMetallicImage();
if (renderComboImage("Metallic", metallicImage))
m->setMetallicImage(metallicImage);

ImGui::Text("AO");
if (!m->aoIsImage()) {
ImGui::SliderFloat("##AO", &m->ao, 0.0f, 1.0f);
float ao = m->getAo();
if (ImGui::SliderFloat("##AO", &ao, 0.0f, 1.0f))
m->setAo(ao);
}
renderComboImage("AO", m->aoImage);
StringId aoImage = m->getAoImage();
if (renderComboImage("AO", aoImage))
m->setAoImage(aoImage);
}

template <>
Expand Down
5 changes: 3 additions & 2 deletions src/atta/component/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ void Manager::createDefaultImpl() {
cube.add<Name>()->set("Cube");
cube.add<Mesh>()->set("meshes/cube.obj");

resource::Material* rmt = resource::create<resource::Material>("Material", resource::Material::CreateInfo{});
rmt->color = {0.5, 0.5, 0.5};
resource::Material::CreateInfo mInfo{};
mInfo.color = {0.5, 0.5, 0.5};
resource::Material* rmt = resource::create<resource::Material>("Material", mInfo);
cube.add<Material>()->set(rmt);

// Light entity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
//--------------------------------------------------
// Atta Event Module
// materialLoad.h
// materialCreate.h
// Date: 2022-08-13
// By Breno Cunha Queiroz
//--------------------------------------------------
#ifndef ATTA_EVENT_EVENTS_MATERIAL_LOAD_H
#define ATTA_EVENT_EVENTS_MATERIAL_LOAD_H
#ifndef ATTA_EVENT_EVENTS_MATERIAL_CREATE_H
#define ATTA_EVENT_EVENTS_MATERIAL_CREATE_H
#include <atta/event/event.h>

namespace atta::event {

class MaterialLoad : public EventTyped<SID("MaterialLoad")> {
class MaterialCreate : public EventTyped<SID("MaterialCreate")> {
public:
MaterialLoad(StringId sid_) : sid(sid_) {}
MaterialCreate(StringId sid_) : sid(sid_) {}

const StringId sid;
};

} // namespace atta::event

#endif // ATTA_EVENT_EVENTS_MATERIAL_LOAD_H
#endif // ATTA_EVENT_EVENTS_MATERIAL_CREATE_H
22 changes: 22 additions & 0 deletions src/atta/event/events/materialDestroy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//--------------------------------------------------
// Atta Event Module
// materialDestroy.h
// Date: 2022-08-13
// By Breno Cunha Queiroz
//--------------------------------------------------
#ifndef ATTA_EVENT_EVENTS_MATERIAL_DESTROY_H
#define ATTA_EVENT_EVENTS_MATERIAL_DESTROY_H
#include <atta/event/event.h>

namespace atta::event {

class MaterialDestroy : public EventTyped<SID("MaterialDestroy")> {
public:
MaterialDestroy(StringId sid_) : sid(sid_) {}

const StringId sid;
};

} // namespace atta::event

#endif // ATTA_EVENT_EVENTS_MATERIAL_DESTROY_H
22 changes: 22 additions & 0 deletions src/atta/event/events/materialUpdate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//--------------------------------------------------
// Atta Event Module
// materialUpdate.h
// Date: 2022-08-13
// By Breno Cunha Queiroz
//--------------------------------------------------
#ifndef ATTA_EVENT_EVENTS_MATERIAL_UPDATE_H
#define ATTA_EVENT_EVENTS_MATERIAL_UPDATE_H
#include <atta/event/event.h>

namespace atta::event {

class MaterialUpdate : public EventTyped<SID("MaterialUpdate")> {
public:
MaterialUpdate(StringId sid_) : sid(sid_) {}

const StringId sid;
};

} // namespace atta::event

#endif // ATTA_EVENT_EVENTS_MATERIAL_UPDATE_H
22 changes: 22 additions & 0 deletions src/atta/event/events/meshDestroy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//--------------------------------------------------
// Atta Event Module
// meshDestroy.h
// Date: 2024-01-05
// By Breno Cunha Queiroz
//--------------------------------------------------
#ifndef ATTA_EVENT_EVENTS_MESH_DESTROY_H
#define ATTA_EVENT_EVENTS_MESH_DESTROY_H
#include <atta/event/event.h>

namespace atta::event {

class MeshDestroy : public EventTyped<SID("MeshDestroy")> {
public:
MeshDestroy(StringId sid_) : sid(sid_) {}

const StringId sid;
};

} // namespace atta::event

#endif // ATTA_EVENT_EVENTS_MESH_DESTROY_H
22 changes: 22 additions & 0 deletions src/atta/event/events/meshUpdate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//--------------------------------------------------
// Atta Event Module
// meshUpdate.h
// Date: 2023-12-30
// By Breno Cunha Queiroz
//--------------------------------------------------
#ifndef ATTA_EVENT_EVENTS_MESH_UPDATE_H
#define ATTA_EVENT_EVENTS_MESH_UPDATE_H
#include <atta/event/event.h>

namespace atta::event {

class MeshUpdate : public EventTyped<SID("MeshUpdate")> {
public:
MeshUpdate(StringId sid_) : sid(sid_) {}

const StringId sid;
};

} // namespace atta::event

#endif // ATTA_EVENT_EVENTS_MESH_UPDATE_H
17 changes: 11 additions & 6 deletions src/atta/event/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
namespace atta::event {

using Callback = std::function<void(Event&)>;
#define BIND_EVENT_FUNC(x) std::bind(&x, this, std::placeholders::_1)
#define BIND_EVENT_FUNC(x) (void*)this, std::bind(&x, this, std::placeholders::_1)

// static void subscribe(Event::Type type, Callback&& callback) { getInstance().subscribeImpl(type, std::move(callback)); }
template <typename E>
void subscribe(Callback&& callback);
// static void subscribe(Event::Type type, Callback&& callback) { getInstance()._observers[type].push_back(callback); }
void subscribe(void* source, Callback&& callback);
template <typename E>
void unsubscribe(void* source, Callback&& callback);
void publish(Event& event);
void clear();

Expand All @@ -28,8 +28,13 @@ void clear();
namespace atta::event {

template <typename E>
void subscribe(Callback&& callback) {
Manager::getInstance().subscribeImpl(E::type, std::move(callback));
void subscribe(void* source, Callback&& callback) {
Manager::getInstance().subscribeImpl(E::type, source, std::move(callback));
}

template <typename E>
void unsubscribe(void* source, Callback&& callback) {
Manager::getInstance().unsubscribeImpl(E::type, source, std::move(callback));
}

} // namespace atta::event
Expand Down
Loading

0 comments on commit d8ab3a1

Please sign in to comment.