Skip to content

Commit

Permalink
Merge pull request #19 from KTStephano/v0.9
Browse files Browse the repository at this point in the history
V0.9 -> Master
  • Loading branch information
KTStephano authored Mar 15, 2023
2 parents 3cca1c1 + 06761bf commit 80174f8
Show file tree
Hide file tree
Showing 695 changed files with 6,242 additions and 2,937 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "gl3w"]
path = gl3w
url = https://github.com/skaslev/gl3w.git
[submodule "meshoptimizer"]
path = meshoptimizer
url = https://github.com/zeux/meshoptimizer.git
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if (WIN32)
$ENV{SYSROOT}/lib/cmake/assimp
$ENV{SYSROOT}/lib/cmake/assimp-5.0
$ENV{SYSROOT}/lib/cmake/Catch2
$ENV{SYSROOT}/lib/cmake/meshoptimizer
)
endif ()

Expand Down
25 changes: 24 additions & 1 deletion Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
find_package(OpenGL REQUIRED)

set(ROOT_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../)

include_directories(
${ROOT_DIRECTORY}/gl3w/include
${ROOT_DIRECTORY}
${ROOT_DIRECTORY}/Source/Engine/
${CMAKE_CURRENT_LIST_DIR}
${OPENGL_INCLUDE_DIRS}
${ROOT_DIRECTORY}/assimp/Deploy/include
${ROOT_DIRECTORY}/SDL2/include
)

link_directories(${ROOT_DIRECTORY}/Bin)

include_directories(${CMAKE_CURRENT_LIST_DIR}/Common)
file(GLOB COMMON_SOURCES ${CMAKE_CURRENT_LIST_DIR}/Common/*.cpp)

set(OUTPUT_DIRECTORY ${ROOT_DIRECTORY}/Bin/)

add_subdirectory(ExampleEnv00)
add_subdirectory(ExampleEnv01)
add_subdirectory(ExampleEnv02)
add_subdirectory(ExampleEnv03)
add_subdirectory(ExampleEnv03)
add_subdirectory(ExampleEnv04)
add_subdirectory(ExampleEnv05)
add_subdirectory(ExampleEnv06)
add_subdirectory(ExampleEnv07)
add_subdirectory(ExampleEnv08)
64 changes: 55 additions & 9 deletions Examples/Common/CameraController.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ struct CameraController : public stratus::InputHandler {
for (auto e : input) {
switch (e.type) {
case SDL_MOUSEMOTION:
_camera->modifyAngle(stratus::Degrees(0.0f), stratus::Degrees(-e.motion.xrel), stratus::Degrees(0.0f));
if (_cameraRotateEnabled) {
_camera->modifyAngle(stratus::Degrees(0.0f), stratus::Degrees(-e.motion.xrel), stratus::Degrees(0.0f));
}
//STRATUS_LOG << camera.getRotation() << std::endl;
break;
case SDL_KEYDOWN:
Expand All @@ -49,29 +51,57 @@ struct CameraController : public stratus::InputHandler {
SDL_Scancode key = e.key.keysym.scancode;
switch (key) {
case SDL_SCANCODE_SPACE:
if (!released) {
if (!released && _cameraMoveEnabled) {
_camSpeedDivide = 1.0f;
}
else {
_camSpeedDivide = 0.25f;
}
break;
case SDL_SCANCODE_LSHIFT:
if (!released && _cameraMoveEnabled) {
_camSpeedDivide = 0.125f;
}
else {
_camSpeedDivide = 0.25f;
}
break;
case SDL_SCANCODE_LCTRL:
if (!released && _cameraMoveEnabled) {
_camSpeedDivide = 0.025f;
}
else {
_camSpeedDivide = 0.25f;
}
break;
case SDL_SCANCODE_W:
case SDL_SCANCODE_S:
if (!released) {
if (!released && _cameraMoveEnabled) {
_cameraSpeed.x = key == SDL_SCANCODE_W ? camSpeed : -camSpeed;
} else {
_cameraSpeed.x = 0.0f;
}
break;
case SDL_SCANCODE_A:
case SDL_SCANCODE_D:
if (!released) {
if (!released && _cameraMoveEnabled) {
_cameraSpeed.y = key == SDL_SCANCODE_D ? camSpeed : -camSpeed;
} else {
_cameraSpeed.y = 0.0f;
}
break;
case (SDL_SCANCODE_T): {
if (released) {
_cameraMoveEnabled = !_cameraMoveEnabled;
}
break;
}
case (SDL_SCANCODE_Y): {
if (released) {
_cameraRotateEnabled = !_cameraRotateEnabled;
}
break;
}
// Adds or removes the light following the camera
case SDL_SCANCODE_F:
if (released) {
Expand All @@ -85,6 +115,17 @@ struct CameraController : public stratus::InputHandler {
}
}

break;
case SDL_SCANCODE_V:
if (released) {
STRATUS_LOG << "Camera Position: " << INSTANCE(RendererFrontend)->GetCamera()->getPosition() << std::endl;
}
break;
case SDL_SCANCODE_B:
if (released) {
_drawBoundingBoxes = !_drawBoundingBoxes;
INSTANCE(RendererFrontend)->SetDrawBoundingBoxesEnabled(_drawBoundingBoxes);
}
break;
}
}
Expand All @@ -94,11 +135,13 @@ struct CameraController : public stratus::InputHandler {
// Check mouse state for move up/down
uint32_t buttonState = mouse.mask;
_cameraSpeed.z = 0.0f;
if ((buttonState & SDL_BUTTON_LMASK) != 0) { // left mouse button
_cameraSpeed.z = -camSpeed;
}
else if ((buttonState & SDL_BUTTON_RMASK) != 0) { // right mouse button
_cameraSpeed.z = camSpeed;
if (_cameraMoveEnabled) {
if ((buttonState & SDL_BUTTON_LMASK) != 0) { // left mouse button
_cameraSpeed.z = -camSpeed;
}
else if ((buttonState & SDL_BUTTON_RMASK) != 0) { // right mouse button
_cameraSpeed.z = camSpeed;
}
}

// Final camera speed update
Expand All @@ -112,6 +155,9 @@ struct CameraController : public stratus::InputHandler {
stratus::CameraPtr _camera;
stratus::LightPtr _cameraLight;
bool _cameraLightEnabled = true;
bool _cameraMoveEnabled = true;
bool _cameraRotateEnabled = true;
bool _drawBoundingBoxes = false;
glm::vec3 _cameraSpeed = glm::vec3(0.0f);
float _camSpeedDivide = 0.25f; // For slowing camera down
};
52 changes: 52 additions & 0 deletions Examples/Common/FrameRateController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include "StratusCommon.h"
#include "glm/glm.hpp"
#include "StratusWindow.h"
#include "StratusRendererFrontend.h"
#include "StratusLog.h"
#include "StratusCamera.h"
#include "StratusLight.h"

struct FrameRateController : public stratus::InputHandler {
FrameRateController() {
INSTANCE(RendererFrontend)->SetVsyncEnabled(true);
// 1000 fps is just to get the engine out of the way so SDL can control it with vsync
_frameRates = {1000, 55, 50, 45, 40, 35, 30};
INSTANCE(Engine)->SetMaxFrameRate(_frameRates[0]);
}

// This class is deleted when the Window is deleted so the Renderer has likely already
// been taken offline. The check is for if the camera controller is removed while the engine
// is still running.
virtual ~FrameRateController() {}

void HandleInput(const stratus::MouseState& mouse, const std::vector<SDL_Event>& input, const double deltaSeconds) {
const float camSpeed = 100.0f;

// Handle WASD movement
for (auto e : input) {
switch (e.type) {
case SDL_KEYDOWN:
case SDL_KEYUP: {
bool released = e.type == SDL_KEYUP;
SDL_Scancode key = e.key.keysym.scancode;
switch (key) {
// Why M? Because F is used for flash light and R is recompile :(
case SDL_SCANCODE_M:
if (released) {
_frameRateIndex = (_frameRateIndex + 1) % _frameRates.size();
INSTANCE(Engine)->SetMaxFrameRate(_frameRates[_frameRateIndex]);
STRATUS_LOG << "Max Frame Rate Toggled: " << _frameRates[_frameRateIndex] << std::endl;
break;
}
}
}
}
}
}

private:
size_t _frameRateIndex = 0;
std::vector<uint32_t> _frameRates;
};
51 changes: 42 additions & 9 deletions Examples/Common/LightControllers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static void InitLight(const LightParams& p, stratus::LightPtr& light) {
light->setIntensity(p.intensity);
light->setColor(p.color);
light->SetPosition(p.position);
light->setCastsShadows(p.castsShadows);
}

static void InitCube(const LightParams& p,
Expand All @@ -36,13 +37,13 @@ static void InitCube(const LightParams& p,
auto local = cube->Components().GetComponent<stratus::LocalTransformComponent>().component;
rc->SetMaterialAt(INSTANCE(MaterialManager)->CreateDefault(), 0);
cube->Components().DisableComponent<stratus::LightInteractionComponent>();
local->SetLocalScale(glm::vec3(1.0f));
local->SetLocalScale(glm::vec3(0.25f));
local->SetLocalPosition(p.position);
auto color = light->getColor();
// This prevents the cube from being so bright that the bloom post fx causes it to glow
// to an extreme amount
color = (color / stratus::maxLightColor) * 30.0f;
rc->GetMaterialAt(0)->SetDiffuseColor(color);
color = (color / stratus::maxLightColor) * 100.0f;
rc->GetMaterialAt(0)->SetDiffuseColor(glm::vec4(color, 1.0f));
}

void LightCreator::CreateRandomLightMover(const LightParams& p) {
Expand All @@ -66,34 +67,46 @@ void LightCreator::CreateRandomLightMover(const LightParams& p) {
//INSTANCE(RendererFrontend)->AddDynamicEntity(cube);
}

void LightCreator::CreateStationaryLight(const LightParams& p) {
void LightCreator::CreateStationaryLight(const LightParams& p, const bool spawnCube) {
auto ptr = stratus::Entity::Create();
stratus::LightPtr light(new stratus::PointLight(/* staticLight = */ false));
InitLight(p, light);

stratus::EntityPtr cube = INSTANCE(ResourceManager)->CreateCube();
InitCube(p, light, cube);
stratus::EntityPtr cube;
if (spawnCube) {
cube = INSTANCE(ResourceManager)->CreateCube();
InitCube(p, light, cube);
}

ptr->Components().AttachComponent<LightComponent>(light);
ptr->Components().AttachComponent<LightCubeComponent>(cube);
if (spawnCube) ptr->Components().AttachComponent<LightCubeComponent>(cube);

INSTANCE(EntityManager)->AddEntity(ptr);
INSTANCE(RendererFrontend)->AddLight(light);
INSTANCE(EntityManager)->AddEntity(cube);
if (spawnCube) INSTANCE(EntityManager)->AddEntity(cube);
//INSTANCE(RendererFrontend)->AddDynamicEntity(cube);
}

void LightCreator::CreateVirtualPointLight(const LightParams& p) {
void LightCreator::CreateVirtualPointLight(const LightParams& p, const bool spawnCube) {
auto ptr = stratus::Entity::Create();
stratus::LightPtr light(new stratus::VirtualPointLight());
InitLight(p, light);
((stratus::VirtualPointLight *)light.get())->SetNumShadowSamples(p.numShadowSamples);

stratus::EntityPtr cube;
if (spawnCube) {
cube = INSTANCE(ResourceManager)->CreateCube();
InitCube(p, light, cube);
cube->Components().DisableComponent<stratus::StaticObjectComponent>();
}

STRATUS_LOG << "VPL Radius: " << light->getRadius() << std::endl;

ptr->Components().AttachComponent<LightComponent>(light);
if (spawnCube) ptr->Components().AttachComponent<LightCubeComponent>(cube);
INSTANCE(EntityManager)->AddEntity(ptr);
INSTANCE(RendererFrontend)->AddLight(light);
if (spawnCube) INSTANCE(EntityManager)->AddEntity(cube);
}

struct LightDeleteController : public stratus::InputHandler {
Expand Down Expand Up @@ -127,6 +140,10 @@ struct LightDeleteController : public stratus::InputHandler {
}
break;
}
case SDL_SCANCODE_L: {
printLights = true;
break;
}
}
}
}
Expand All @@ -135,6 +152,7 @@ struct LightDeleteController : public stratus::InputHandler {

std::vector<stratus::EntityPtr> entitiesToRemove;
std::vector<stratus::EntityPtr> entities;
bool printLights = false;
};

LightDeleteController * ConvertHandlerToLightDelete(const stratus::InputHandlerPtr& input) {
Expand All @@ -159,6 +177,21 @@ static bool EntityIsRelevant(const stratus::EntityPtr& entity) {
}

void LightProcess::Process(const double deltaSeconds) {
if (ConvertHandlerToLightDelete(input)->printLights) {
ConvertHandlerToLightDelete(input)->printLights = false;
const auto& lights = ConvertHandlerToLightDelete(input)->entities;
for (const auto& light : lights) {
auto ptr = stratus::GetComponent<LightComponent>(light)->light;
const bool containsCube = stratus::ContainsComponent<LightCubeComponent>(light);
STRATUS_LOG << "LightCreator::CreateStationaryLight(\n"
<< " LightParams(glm::vec3" << ptr->GetPosition() << ", "
<< "glm::vec3" << ptr->getBaseColor() << ", "
<< ptr->getIntensity() << ", "
<< (ptr->castsShadows() ? "true" : "false") << "), \n"
<< " " << (containsCube ? "true" : "false") << "\n);";
}
}

for (stratus::EntityPtr& entity : ConvertHandlerToLightDelete(input)->entitiesToRemove) {
if (entity->Components().ContainsComponent<LightComponent>()) {
INSTANCE(RendererFrontend)->RemoveLight(
Expand Down
14 changes: 9 additions & 5 deletions Examples/Common/LightControllers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@ struct LightParams {
glm::vec3 position;
glm::vec3 color;
float intensity;
bool castsShadows;
uint32_t numShadowSamples; // only valid for Virtual Point Lights (VPLs)

LightParams()
: LightParams(glm::vec3(0.0f), glm::vec3(1.0f), 1.0f) {}

LightParams(const glm::vec3& position, const glm::vec3& color, const float intensity)
: LightParams(position, color, intensity, 3) {}
: LightParams(position, color, intensity, true) {}

LightParams(const glm::vec3& position, const glm::vec3& color, const float intensity, const uint32_t numShadowSamples)
: position(position), color(color), intensity(intensity), numShadowSamples(numShadowSamples) {}
LightParams(const glm::vec3& position, const glm::vec3& color, const float intensity, const bool castsShadows)
: LightParams(position, color, intensity, castsShadows, 3) {}

LightParams(const glm::vec3& position, const glm::vec3& color, const float intensity, const bool castsShadows, const uint32_t numShadowSamples)
: position(position), color(color), intensity(intensity), castsShadows(castsShadows), numShadowSamples(numShadowSamples) {}
};

struct LightCreator {
static void Initialize();
static void Shutdown();
static void CreateRandomLightMover(const LightParams&);
static void CreateStationaryLight(const LightParams&);
static void CreateVirtualPointLight(const LightParams&);
static void CreateStationaryLight(const LightParams&, const bool spawnCube = true);
static void CreateVirtualPointLight(const LightParams&, const bool spawnCube = false);

private:
static std::vector<stratus::EntityProcessHandle> handles;
Expand Down
Loading

0 comments on commit 80174f8

Please sign in to comment.