-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rendering): add splitscreen plugin
- Loading branch information
1 parent
2460cc5
commit f96bd25
Showing
9 changed files
with
270 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/// @file | ||
/// @brief Component @ref cubos::engine::Viewport. | ||
/// @ingroup renderer-plugin | ||
|
||
#pragma once | ||
|
||
#include <glm/vec2.hpp> | ||
|
||
#include <cubos/core/reflection/reflect.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @brief Component which defines parameters of a viewport, the actual screen space | ||
/// that will be used by the camera it is attached to. Useful for having multiple camera views | ||
/// shown on screen. | ||
/// @note Should be used with @ref LocalToWorld. | ||
/// @ingroup renderer-plugin | ||
struct Viewport | ||
{ | ||
CUBOS_REFLECT; | ||
|
||
glm::ivec2 position{0.0F, 0.0F}; //< Top left position of the viewport in pixels | ||
glm::ivec2 size{0.0F, 0.0F}; //< Size of the viewport in pixels | ||
}; | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/// @dir | ||
/// @brief @ref splitscreen-plugin plugin directory. | ||
|
||
/// @file | ||
/// @brief Plugin entry point. | ||
/// @ingroup splitscreen-plugin | ||
|
||
#pragma once | ||
|
||
#include <cubos/engine/cubos.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @defgroup splitscreen-plugin Splitscreen | ||
/// @ingroup engine | ||
/// @brief Adds viewport to all active cameras to achieve a splitscreen layout. | ||
/// | ||
/// ## Dependencies | ||
/// - @ref renderer-plugin | ||
|
||
/// @brief Plugin entry function. | ||
/// @param cubos @b CUBOS. main class | ||
/// @ingroup splitscreen-plugin | ||
void splitscreenPlugin(Cubos& cubos); | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,77 @@ | ||
#include <cubos/engine/renderer/directional_light.hpp> | ||
#include <cubos/engine/renderer/plugin.hpp> | ||
#include <cubos/engine/settings/settings.hpp> | ||
#include <cubos/engine/transform/plugin.hpp> | ||
#include <cubos/engine/voxels/plugin.hpp> | ||
|
||
using namespace cubos::engine; | ||
|
||
/// [Get handles to assets] | ||
static const Asset<VoxelGrid> CarAsset = AnyAsset("059c16e7-a439-44c7-9bdc-6e069dba0c75"); | ||
static const Asset<VoxelPalette> PaletteAsset = AnyAsset("1aa5e234-28cb-4386-99b4-39386b0fc215"); | ||
/// [Get handles to assets] | ||
|
||
static void settingsSystem(Write<Settings> settings) | ||
{ | ||
settings->setString("assets.io.path", SAMPLE_ASSETS_FOLDER); | ||
} | ||
|
||
/// [Load and set palette] | ||
static void setPaletteSystem(Read<Assets> assets, Write<Renderer> renderer) | ||
{ | ||
// Read the palette's data and pass it to the renderer. | ||
auto palette = assets->read(PaletteAsset); | ||
(*renderer)->setPalette(*palette); | ||
} | ||
/// [Load and set palette] | ||
|
||
static void spawnCameraSystem(Commands cmds, Write<ActiveCameras> activeCameras) | ||
{ | ||
// Spawn the camera entity. | ||
activeCameras->entities[0] = | ||
cmds.create() | ||
.add(Camera{.fovY = 60.0F, .zNear = 0.1F, .zFar = 1000.0F}) | ||
.add(Position{{50.0F, 50.0F, 50.0F}}) | ||
.add(Rotation{glm::quatLookAt(glm::normalize(glm::vec3{-1.0F, -1.0F, -1.0F}), glm::vec3{0.0F, 1.0F, 0.0F})}) | ||
.entity(); | ||
} | ||
|
||
static void spawnLightSystem(Commands cmds) | ||
{ | ||
// Spawn the sun. | ||
cmds.create() | ||
.add(DirectionalLight{glm::vec3(1.0F), 1.0F}) | ||
.add(Rotation{glm::quat(glm::vec3(glm::radians(45.0F), glm::radians(45.0F), 0))}); | ||
} | ||
|
||
/// [Spawn car system] | ||
static void spawnCarSystem(Commands cmds, Read<Assets> assets) | ||
{ | ||
// Calculate the necessary offset to center the model on (0, 0, 0). | ||
auto car = assets->read(CarAsset); | ||
glm::vec3 offset = glm::vec3(car->size().x, 0.0F, car->size().z) / -2.0F; | ||
|
||
// Create the car entity | ||
cmds.create().add(RenderableGrid{CarAsset, offset}).add(LocalToWorld{}); | ||
} | ||
/// [Spawn car system] | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
Cubos cubos{argc, argv}; | ||
|
||
cubos.addPlugin(rendererPlugin); | ||
/// [Adding the plugin] | ||
cubos.addPlugin(voxelsPlugin); | ||
/// [Adding the plugin] | ||
|
||
cubos.startupSystem(settingsSystem).tagged("cubos.settings"); | ||
cubos.startupSystem(spawnCameraSystem); | ||
cubos.startupSystem(spawnLightSystem); | ||
/// [Adding systems] | ||
cubos.startupSystem(setPaletteSystem).after("cubos.renderer.init"); | ||
cubos.startupSystem(spawnCarSystem).tagged("cubos.assets"); | ||
/// [Adding systems] | ||
|
||
cubos.run(); | ||
#include <cubos/engine/renderer/directional_light.hpp> | ||
#include <cubos/engine/renderer/plugin.hpp> | ||
#include <cubos/engine/settings/settings.hpp> | ||
#include <cubos/engine/transform/plugin.hpp> | ||
#include <cubos/engine/voxels/plugin.hpp> | ||
|
||
using namespace cubos::engine; | ||
|
||
/// [Get handles to assets] | ||
static const Asset<VoxelGrid> CarAsset = AnyAsset("059c16e7-a439-44c7-9bdc-6e069dba0c75"); | ||
static const Asset<VoxelPalette> PaletteAsset = AnyAsset("1aa5e234-28cb-4386-99b4-39386b0fc215"); | ||
/// [Get handles to assets] | ||
|
||
static void settingsSystem(Write<Settings> settings) | ||
{ | ||
settings->setString("assets.io.path", SAMPLE_ASSETS_FOLDER); | ||
} | ||
|
||
/// [Load and set palette] | ||
static void setPaletteSystem(Read<Assets> assets, Write<Renderer> renderer) | ||
{ | ||
// Read the palette's data and pass it to the renderer. | ||
auto palette = assets->read(PaletteAsset); | ||
(*renderer)->setPalette(*palette); | ||
} | ||
/// [Load and set palette] | ||
|
||
static void spawnCameraSystem(Commands cmds, Write<ActiveCameras> activeCameras) | ||
{ | ||
// Spawn the camera entity. | ||
activeCameras->entities[0] = | ||
cmds.create() | ||
.add(Camera{.fovY = 60.0F, .zNear = 0.1F, .zFar = 1000.0F}) | ||
.add(Position{{50.0F, 50.0F, 50.0F}}) | ||
.add(Rotation{glm::quatLookAt(glm::normalize(glm::vec3{-1.0F, -1.0F, -1.0F}), glm::vec3{0.0F, 1.0F, 0.0F})}) | ||
.entity(); | ||
} | ||
|
||
static void spawnLightSystem(Commands cmds) | ||
{ | ||
// Spawn the sun. | ||
cmds.create() | ||
.add(DirectionalLight{glm::vec3(1.0F), 1.0F}) | ||
.add(Rotation{glm::quat(glm::vec3(glm::radians(45.0F), glm::radians(45.0F), 0))}); | ||
} | ||
|
||
/// [Spawn car system] | ||
static void spawnCarSystem(Commands cmds, Read<Assets> assets) | ||
{ | ||
// Calculate the necessary offset to center the model on (0, 0, 0). | ||
auto car = assets->read(CarAsset); | ||
glm::vec3 offset = glm::vec3(car->size().x, 0.0F, car->size().z) / -2.0F; | ||
|
||
// Create the car entity | ||
cmds.create().add(RenderableGrid{CarAsset, offset}).add(LocalToWorld{}); | ||
} | ||
/// [Spawn car system] | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
Cubos cubos{argc, argv}; | ||
|
||
cubos.addPlugin(rendererPlugin); | ||
/// [Adding the plugin] | ||
cubos.addPlugin(voxelsPlugin); | ||
/// [Adding the plugin] | ||
|
||
cubos.startupSystem(settingsSystem).tagged("cubos.settings"); | ||
cubos.startupSystem(spawnCameraSystem); | ||
cubos.startupSystem(spawnLightSystem); | ||
/// [Adding systems] | ||
cubos.startupSystem(setPaletteSystem).after("cubos.renderer.init"); | ||
cubos.startupSystem(spawnCarSystem).tagged("cubos.assets"); | ||
/// [Adding systems] | ||
|
||
cubos.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <cubos/core/ecs/component/reflection.hpp> | ||
#include <cubos/core/reflection/external/glm.hpp> | ||
|
||
#include <cubos/engine/renderer/viewport.hpp> | ||
|
||
CUBOS_REFLECT_IMPL(cubos::engine::Viewport) | ||
{ | ||
return core::ecs::ComponentTypeBuilder<Viewport>("cubos::engine::Viewport") | ||
.withField("position", &Viewport::position) | ||
.withField("size", &Viewport::size) | ||
.build(); | ||
} |
Oops, something went wrong.