Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ option(VECTOR_3D_BUILD_EXECUTABLE "Build the executable" ON)
add_subdirectory(include/plog EXCLUDE_FROM_ALL)

add_definitions(-DBOOST_ALL_NO_LIB)
find_package(Boost REQUIRED)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_DEBUG_LIBS OFF)
set(Boost_USE_RELEASE_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED COMPONENTS serialization)

# Vulkan
set(Vulkan_ROOT "$ENV{VULKAN_SDK}")
Expand Down Expand Up @@ -67,7 +72,7 @@ message(STATUS "CHRONO_STATIC = ${CHRONO_STATIC}")
# ENDIF()

SET(ENGINE_INCLUDE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/include/OBJ-Loader-master/Source ${CMAKE_SOURCE_DIR}/src/thirdparty/imgui ${Boost_INCLUDE_DIRS} ${Chrono_INCLUDE_DIR} ${EiGEN3_INCLUDE_DIR} ${CHRONO_INCLUDE_DIRS})
set(vector_3d_LIBS glfw ${GLFW_LIBRARIES} ${OPENGL_LIBRARIES} Vulkan::Vulkan glm::glm plog ${CHRONO_TARGETS} ${WINMM_LIB_PATH} ${CHRONO_LIBRARIES} ${X11_X11_LIB} assimp)
set(vector_3d_LIBS glfw ${GLFW_LIBRARIES} ${OPENGL_LIBRARIES} Vulkan::Vulkan glm::glm plog ${CHRONO_TARGETS} ${WINMM_LIB_PATH} ${CHRONO_LIBRARIES} ${X11_X11_LIB} assimp ${Boost_LIBRARIES})

set(RESOURCES_DIR ${CMAKE_SOURCE_DIR}/resources)

Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ set(vector_3d_core_HEADERS
${CMAKE_SOURCE_DIR}/src/object_ptr.hpp
${CMAKE_SOURCE_DIR}/src/observer_ptr.hpp
${CMAKE_SOURCE_DIR}/src/scene.h
${CMAKE_SOURCE_DIR}/src/serialization.hpp
${CMAKE_SOURCE_DIR}/src/transform.h
${CMAKE_SOURCE_DIR}/src/window.h
)
Expand Down Expand Up @@ -75,14 +76,15 @@ set(vector_3d_editor_FILES
message(STATUS "-- INPUT")

set(vector_3d_input_SOURCES
${CMAKE_SOURCE_DIR}/src/input/KeyboardDevice.cpp
)

set(vector_3d_input_HEADERS
${CMAKE_SOURCE_DIR}/src/input/InputDevice.hpp
${CMAKE_SOURCE_DIR}/src/input/InputKeyCodes.hpp
${CMAKE_SOURCE_DIR}/src/input/InputKeys.hpp
${CMAKE_SOURCE_DIR}/src/input/InputManager.h
${CMAKE_SOURCE_DIR}/src/input/KeyboardDevice.hpp
${CMAKE_SOURCE_DIR}/src/input/KeyboardDevice.h
)

set(vector_3d_input_FILES
Expand Down
30 changes: 29 additions & 1 deletion src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@
#include <boost/stacktrace.hpp>
#include <cassert>
#include <csignal>
#include <fstream>
#include <ostream>
#include <sstream>
#include <string>

#include "backends/imgui_impl_glfw.h"
#include "backends/imgui_impl_opengl3.h"
#include "imgui.h"
#include "input/KeyboardDevice.hpp"
#include "input/KeyboardDevice.h"
#include "physics/Vehicle.h"
#include "physics/VehicleInteractiveController.h"
#include "physics/collider.h"
#include "physics/rigidbody.h"
#include "plog/Severity.h"
#include "rendering/mesh_renderer.h"
#include "rendering/null_graphics_backend.hpp"
#include "serialization.hpp"
#include "transform.h"

// ------------------------------- TEMP ----------------------------------
Expand Down Expand Up @@ -295,6 +297,18 @@ void Engine::mainLoop() {
if (ImGui::InputInt("Target FPS", &targetFPS, 1, 10)) {
m_targetFrameRate = targetFPS;
}
ImGui::Spacing();

if (ImGui::Button("Test save keyboard bindings")) {
m_inputManager.storeDevice(0, "KeyboardConfig.txt");
}
if (ImGui::Button("Test save scene")) {
saveScene("testSceneSave.xml");
}
if (ImGui::Button("Test load scene")) {
loadScene("testSceneSave.xml");
}

ImGui::Spacing();
if (ImGui::CollapsingHeader("Physics")) m_phSystem.renderDebbugGUI();
ImGui::Spacing();
Expand Down Expand Up @@ -345,4 +359,18 @@ void Engine::registerComponents(
}
}

void Engine::saveScene(std::string filename) {
std::ofstream ofs(filename);
boost::archive::text_oarchive oa(ofs);
oa << boost::serialization::make_nvp("scene", m_scene);
}

void Engine::loadScene(std::string filename) {
std::ifstream ifs(filename);
boost::archive::text_iarchive ia(ifs);
Scene* scene;
ia >> boost::serialization::make_nvp("scene", m_scene);
scene->init();
}

} // namespace v3d
3 changes: 3 additions & 0 deletions src/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,8 @@ class Engine {
/// @param componentRegistry
void registerComponents(Scene* scene,
editor::EditorComponentRegistry* componentRegistry);

void saveScene(std::string filename);
void loadScene(std::string filename);
};
} // namespace v3d
10 changes: 10 additions & 0 deletions src/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class RigidBody;

class Entity : public IEditorGUISelectable {
friend class Scene;
friend class boost::serialization::access;

public:
std::string getName() const { return m_name; }
Expand Down Expand Up @@ -110,6 +111,15 @@ class Entity : public IEditorGUISelectable {
private:
void removeChild(entity_ptr child);
void addChild(entity_ptr child);

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & m_id;
ar & m_name;
ar & m_parent;
ar & m_childs;
ar & m_components;
}
};

} // namespace v3d
32 changes: 32 additions & 0 deletions src/input/InputDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string_view>
#include <unordered_map>

#include "serialization.hpp"
#include "utils/utils.hpp"
#include "window.h"

Expand All @@ -19,6 +20,11 @@ struct InputKey {
constexpr bool operator!=(const InputKey& other) const noexcept {
return code != other.code;
}

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & code;
}
};

struct InputKeyResult {
Expand All @@ -41,6 +47,11 @@ struct InputAction {
constexpr bool operator!=(const InputAction& other) const noexcept {
return code != other.code;
}

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & code;
}
};

struct InputActionHasher {
Expand All @@ -57,9 +68,17 @@ inline constexpr InputAction makeInputActionID(std::string_view name) {
struct InputMap {
InputAction m_action;
InputKey m_key;

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & m_key;
ar & m_action;
}
};

class InputProfile {
friend class boost::serialization::access;

public:
InputProfile() = default;
~InputProfile() = default;
Expand All @@ -74,6 +93,11 @@ class InputProfile {

private:
std::unordered_map<InputAction, InputMap, InputActionHasher> m_mappings;

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & m_mappings;
}
};

enum InputDeviceType {
Expand All @@ -84,6 +108,8 @@ enum InputDeviceType {
};

class InputDevice {
friend class boost::serialization::access;

public:
InputDevice(Window* window, InputProfile profile)
: m_window(window), m_profile(std::move(profile)) {};
Expand All @@ -106,6 +132,12 @@ class InputDevice {
Window* m_window;
InputProfile m_profile;
bool muted = false;

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & m_profile;
ar & m_profile;
}
};

} // namespace input
Expand Down
11 changes: 11 additions & 0 deletions src/input/InputManager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once

#include <fstream>

#include "input/InputDevice.hpp"
#include "input/KeyboardDevice.h"
#include <boost/serialization/unique_ptr.hpp>

namespace v3d {
class Engine;
Expand Down Expand Up @@ -52,5 +56,12 @@ class InputManager {
inline std::size_t getNumDevices() const noexcept {
return m_devices.size();
}

void storeDevice(uint8_t deviceId, std::string filename){
std::ofstream ofs(filename);
boost::archive::text_oarchive oa(ofs);
oa.register_type<v3d::input::KeyboardDevice>();
oa << m_devices[deviceId];
}
};
} // namespace v3d
5 changes: 5 additions & 0 deletions src/input/KeyboardDevice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// #include "input/KeyboardDevice.h"

// #include <boost/serialization/export.hpp>

// BOOST_CLASS_EXPORT_GUID(v3d::input::KeyboardDevice, "input::KeyboardDevice")
10 changes: 10 additions & 0 deletions src/input/KeyboardDevice.hpp → src/input/KeyboardDevice.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#pragma once

#include "input/InputKeys.hpp"
#include <boost/serialization/export.hpp>

namespace v3d {
namespace input {
class KeyboardDevice : public InputDevice {
friend class boost::serialization::access;

public:
KeyboardDevice() : InputDevice(nullptr, InputProfile()) {}
KeyboardDevice(Window* window, InputProfile profile)
: InputDevice(window, profile) {}
void update() override {
Expand Down Expand Up @@ -48,6 +52,12 @@ class KeyboardDevice : public InputDevice {

private:
// std::unordered_map<InputKey, InputKeyState> m_keyStates;

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
// serialize base class information
ar& boost::serialization::base_object<InputDevice>(*this);
}
};
} // namespace input

Expand Down
9 changes: 9 additions & 0 deletions src/object_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
#include <cstddef>
#include <stdexcept>
#include <vector>
#include <boost/serialization/serialization.hpp>

namespace v3d {
class Entity;
class Scene;

template <typename Container, typename T, typename key = boost::uuids::uuid>
class object_ptr {
friend class boost::serialization::access;

public:
object_ptr() : m_vec(nullptr) {}
object_ptr(Container& vec, key index) : m_vec(&vec), m_index(index) {
Expand Down Expand Up @@ -130,6 +133,12 @@ class object_ptr {
private:
Container* m_vec;
key m_index;

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & m_index;
ar & m_vec;
}
};

} // namespace v3d
Loading