Skip to content
Merged
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
29 changes: 10 additions & 19 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup MSVC dev environment
uses: ilammy/msvc-dev-cmd@v1

- name: Install ninja-build tool
uses: seanmiddleditch/gha-setup-ninja@v3

- name: Install Vulkan SDK
uses: humbletim/install-vulkan-sdk@81f46b36426f4ccdc1c0e7ab48109f3c98cfdc81
uses: humbletim/install-vulkan-sdk@v1.2
with:
version: 1.3.243.0
version: 1.4.309.0

- name: Configure CMake
run: |
Expand All @@ -37,21 +34,18 @@ jobs:
- name: Test
run: ctest --preset x64-release-tests

# Mac OS
# macOS
macos-build-and-test:
runs-on: macos-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install ninja-build tool
uses: seanmiddleditch/gha-setup-ninja@v3
uses: actions/checkout@v4

- name: Install Vulkan SDK
uses: humbletim/install-vulkan-sdk@81f46b36426f4ccdc1c0e7ab48109f3c98cfdc81
uses: humbletim/install-vulkan-sdk@v1.2
with:
version: 1.3.243.0
version: 1.4.309.0

- name: Configure CMake
run: |
Expand All @@ -72,20 +66,17 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install ninja-build tool
uses: seanmiddleditch/gha-setup-ninja@v3
uses: actions/checkout@v4

- name: Install platform-specific dependencies
run: |
sudo apt update
sudo apt install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev

- name: Install Vulkan SDK
uses: humbletim/install-vulkan-sdk@81f46b36426f4ccdc1c0e7ab48109f3c98cfdc81
uses: humbletim/install-vulkan-sdk@v1.2
with:
version: 1.3.243.0
version: 1.4.309.0

- name: Configure CMake
run: |
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
cmake_minimum_required(VERSION 3.21)

project("Miracle")

Expand All @@ -19,4 +19,5 @@ add_subdirectory("Miracle")
# Demo targets
if(MIRACLE_BUILD_DEMO_TARGETS)
add_subdirectory("Demos/Demo1")
add_subdirectory("Demos/Demo2")
endif()
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"VCPKG_TARGET_TRIPLET": "x64-osx"
"VCPKG_TARGET_TRIPLET": "arm64-osx"
},
"condition": {
"type": "equals",
Expand Down
147 changes: 47 additions & 100 deletions Demos/Demo1/Demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ static void updateTitle() {
Window::setTitle(
UnicodeConverter::toUtf8(
std::format(
"{} - FPS: {} - UPS: {} - Entity count: {}",
"{} - Depth test: {} - FPS: {} - UPS: {} - Entity count: {}",
CurrentApp::getName(),
Renderer::isUsingDepthTesting() ? "enabled" : "disabled",
PerformanceCounters::getFps(),
PerformanceCounters::getUps(),
CurrentScene::getEntityCount()
Expand All @@ -18,80 +19,6 @@ static void updateTitle() {
);
}

class ProjectileBehavior : public BehaviorBase {
private:
Vector3 m_velocity;

public:
ProjectileBehavior(
const EntityContext& context,
float movementSpeed
) : BehaviorBase(context),
m_velocity(Vector3s::up * movementSpeed)
{}

virtual void act() override {
auto& transform = m_context.getTransform();

transform.translate(m_velocity * DeltaTime::get());

if (transform.getTranslation().getLength() > 10.0f) {
m_context.destroyEntity();
}
}
};

class PlayerBehavior : public BehaviorBase {
private:
float m_movementSpeed;
Degrees m_turnSpeed;

public:
PlayerBehavior(
const EntityContext& context,
float movementSpeed,
Degrees turnSpeed
) : BehaviorBase(context),
m_movementSpeed(movementSpeed),
m_turnSpeed(turnSpeed)
{}

virtual void act() override {
auto velocity = Vector3{
.x = static_cast<float>(Keyboard::isKeyHeld(KeyboardKey::keyD) - Keyboard::isKeyHeld(KeyboardKey::keyA)),
.y = static_cast<float>(Keyboard::isKeyHeld(KeyboardKey::keyW) - Keyboard::isKeyHeld(KeyboardKey::keyS))
};

float rotation = Keyboard::isKeyHeld(KeyboardKey::keyQ) - Keyboard::isKeyHeld(KeyboardKey::keyE);

auto& transform = m_context.getTransform();

transform.rotate(Quaternion::createRotation(Vector3s::forward, rotation * m_turnSpeed * DeltaTime::get()));
transform.translate(velocity.toNormalized() * m_movementSpeed * DeltaTime::get());

if (Keyboard::isKeyPressed(KeyboardKey::keySpace)) {
CurrentScene::createEntity(
EntityConfig{
.transformConfig = TransformConfig{
.translation = transform.getTranslation(),
.rotation = transform.getRotation(),
.scale = Vector3{ .x = 0.5f, .y = 0.5f, .z = 1.0f }
},
.appearanceConfig = AppearanceConfig{
.meshIndex = 1,
.color = ColorRgbs::magenta
},
.behaviorFactory = BehaviorFactory::createFactoryFor<ProjectileBehavior>(3.0f)
}
);
}

if (Keyboard::isKeyPressed(KeyboardKey::keyDelete)) {
m_context.destroyEntity();
}
}
};

class CameraBehavior : public BehaviorBase {
private:
float m_movementSpeed;
Expand Down Expand Up @@ -129,14 +56,18 @@ int main() {
AppConfig{
.windowConfig = WindowConfig{
.size = WindowSize{
.width = 800,
.width = 800,
.height = 600
},
.resizable = true
},
.rendererConfig = RendererConfig{
.meshes = std::vector<Mesh>{
{
.swapchainConfig = SwapchainConfig{
.useVsync = true
},
.useDepthTesting = true,
.meshes = std::vector{
Mesh{
.vertices = std::vector{
Vertex{ .position = Vector3{ .x = -0.5f, .y = -0.5f, .z = 0.0f } },
Vertex{ .position = Vector3{ .x = 0.5f, .y = -0.5f, .z = 0.0f } },
Expand All @@ -147,34 +78,52 @@ int main() {
Face{ .indices = { 0, 1, 2 } },
Face{ .indices = { 0, 2, 3 } }
}
},
{
.vertices = std::vector{
Vertex{ .position = Vector3{ .x = -0.5f, .y = -0.5f, .z = 0.0f } },
Vertex{ .position = Vector3{ .x = 0.5f, .y = -0.5f, .z = 0.0f } },
Vertex{ .position = Vector3{ .x = 0.0f, .y = 0.5f, .z = 0.0f } }
},
.faces = std::vector{
Face{ .indices = { 0, 1, 2 } }
}
}
}
},
.sceneConfig = SceneConfig{
.entityConfigs = std::vector<EntityConfig>{
{
.entityConfigs = std::vector{
EntityConfig{
.transformConfig = TransformConfig{
.translation = Vector3{ 0.0f, 0.0f, -1.0f }
},
.cameraConfig = PerspectiveCameraConfig{},
.behaviorFactory = BehaviorFactory::createFactoryFor<CameraBehavior>(1.0f, 120.0_deg)
.cameraConfig = PerspectiveCameraConfig{
.fieldOfView = 80.0_deg
},
.behaviorFactory = BehaviorFactory::createFactoryFor<CameraBehavior>(2.0f, 120.0_deg)
},
EntityConfig{
.appearanceConfig = AppearanceConfig{
.meshIndex = 0,
.color = ColorRgb::createFromNonlinearSrgbColorCode(0xFF7700)
}
},
{
EntityConfig{
.transformConfig = TransformConfig{
.translation = Vector3{
.x = -1.0f,
.z = 1.0f
}
},
.appearanceConfig = AppearanceConfig{
.meshIndex = 0,
.color = ColorRgbs::green
.color = ColorRgbs::magenta
}
},
EntityConfig{
.transformConfig = TransformConfig{
.translation = Vector3{
.x = -0.5f,
.y = -0.5f,
.z = 0.5f
},
.rotation = Quaternion::createRotation(Vector3s::right, 90.0_deg),
.scale = Vector3{ .x = 1.0f, .y = 1.0f, .z = 1.0f } * 6.0f
},
.behaviorFactory = BehaviorFactory::createFactoryFor<PlayerBehavior>(10.0f, 270.0_deg)
.appearanceConfig = AppearanceConfig{
.meshIndex = 0,
.color = ColorRgbs::green
}
}
},
.entityCreatedCallback = [](EntityId) { updateTitle(); },
Expand All @@ -198,16 +147,14 @@ int main() {
}

if (Keyboard::isKeyPressed(KeyboardKey::keyF3)) {
Renderer::setVsyncAndTripleBuffering(
!Renderer::isUsingVsync(),
!Renderer::isUsingTripleBuffering()
);
Renderer::setDepthTesting(!Renderer::isUsingDepthTesting());
updateTitle();
}
}
}
);

int exitCode = app.run();

return exitCode;
}
14 changes: 14 additions & 0 deletions Demos/Demo2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Target definition
add_executable(Demo2 "Demo.cpp")

# Target properties
set_target_properties(
Demo2
PROPERTIES
CXX_STANDARD 20
CXX_STANDARD_REQUIRED true
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)

# Linking
target_link_libraries(Demo2 PRIVATE Miracle)
Loading