Skip to content
Snippets Groups Projects
Commit d34b716d authored by Jonathan Kunstwald's avatar Jonathan Kunstwald
Browse files

Code cleanup II

parent c7b44d29
No related branches found
No related tags found
No related merge requests found
......@@ -60,8 +60,6 @@ void FlockApp::startupGameCore()
mParticleSystem = std::make_unique<ParticleSystem>();
mParticleSystem->init();
mGameEvents = std::make_unique<GameEvents>();
}
void FlockApp::loadLevel()
......@@ -115,6 +113,7 @@ void FlockApp::startupGameLogic()
{
loadLevel();
mGameEvents = std::make_unique<GameEvents>();
mSwarm = std::make_unique<Swarm>(&mRegistry);
mHive = std::make_unique<Hive>(&mRegistry, &mPhysicsEngine, mInstancingManager, mGameEvents.get(), mMeshMonkey,
mMeshIcosphere, mMeshTerrorSquid);
......@@ -137,6 +136,7 @@ void FlockApp::teardownGameLogic()
mPlayerController.reset();
mHive.reset();
mSwarm.reset();
mGameEvents.reset();
}
void FlockApp::drawOpaqueGeometry(Program::UsedProgram &shader, const CameraData &camData, bool zPreOnly)
......@@ -204,11 +204,8 @@ void FlockApp::internalUpdate(float dt, float realDt)
{
int axesCount;
auto axisVals = glfwGetJoystickAxes(0, &axesCount);
int buttonCount;
auto buttonVals = glfwGetJoystickButtons(0, &buttonCount);
static float const deadzone = 0.25f;
static float const gamepadCamSensitivity = 0.02f;
float correctedAxes[6];
for (auto i = 0u; i < 6; ++i)
......
......@@ -6,7 +6,7 @@ namespace flock
{
struct SwarmlingC
{
glm::vec3 position;
glm::vec3 position = glm::vec3(0);
glm::vec3 velocity = glm::vec3(0);
glm::vec3 acceleration = glm::vec3(0);
};
......
......@@ -21,32 +21,32 @@ constexpr inline unsigned packColor(glm::vec3 const& color) noexcept
/// Hermite interpolation, equivalent to glsl smoothstep()
constexpr inline float smoothstep(float edge0, float edge1, float x) noexcept
{
float t = std::clamp((x - edge0) / (edge1 - edge0), 0.f, 1.f);
float const t = std::clamp((x - edge0) / (edge1 - edge0), 0.f, 1.f);
return t * t * (3.f - 2.f * t);
}
/// Returns a random direction vector, normalized
inline glm::vec3 getRandomDirection(std::mt19937& rng)
inline glm::vec3 getRandomDirection(std::mt19937& rng) noexcept
{
static const std::uniform_real_distribution<float> thetaRange(0.0f, 6.28318530717f);
static const std::uniform_real_distribution<float> oneRange(0, 1);
float theta = thetaRange(rng);
float r = sqrt(oneRange(rng));
float z = sqrt(1.0f - r * r) * (oneRange(rng) > 0.5f ? -1.0f : 1.0f);
float const theta = thetaRange(rng);
float const r = sqrt(oneRange(rng));
float const z = sqrt(1.0f - r * r) * (oneRange(rng) > 0.5f ? -1.0f : 1.0f);
return glm::vec3(r * cos(theta), r * sin(theta), z);
}
inline glm::vec2 getRandomDirection2D(std::mt19937& rng)
inline glm::vec2 getRandomDirection2D(std::mt19937& rng) noexcept
{
static const std::uniform_real_distribution<float> oneRange(0, 1);
const auto rads = oneRange(rng) * FLOCK_PI * 2;
auto const rads = oneRange(rng) * FLOCK_PI * 2;
return glm::vec2(cos(rads), sin(rads));
}
/// Normalize that does not crash when given a zero vector
inline glm::vec3 safeNormalize(glm::vec3 const& v)
inline glm::vec3 safeNormalize(glm::vec3 const& v) noexcept
{
auto const lengthSq = glm::length2(v);
if (lengthSq == 0.f)
......@@ -57,7 +57,7 @@ inline glm::vec3 safeNormalize(glm::vec3 const& v)
}
}
inline glm::vec3 safeNormalize(glm::vec3 const& v, float lengthSq)
inline glm::vec3 safeNormalize(glm::vec3 const& v, float lengthSq) noexcept
{
if (lengthSq == 0.f)
return v;
......@@ -69,14 +69,14 @@ inline glm::vec3 safeNormalize(glm::vec3 const& v, float lengthSq)
/// Smoothed lerp, framerate-correct
template <typename T>
inline T smoothLerp(T a, T b, float smoothing, float dt)
inline T smoothLerp(T a, T b, float smoothing, float dt) noexcept
{
return glm::lerp(a, b, 1 - std::pow(smoothing, dt));
}
/// Exponential decay, framerate-correct damp / lerp
template <typename T>
inline T exponentialDecayLerp(T a, T b, float lambda, float dt)
inline T exponentialDecayLerp(T a, T b, float lambda, float dt) noexcept
{
return glm::lerp(a, b, 1 - std::exp(-lambda * dt));
}
......
......@@ -8,11 +8,11 @@ template <int N>
struct Ring
{
private:
uint32_t mPosition : 30;
uint32_t mFullCircle : 1;
uint32_t mPosition = 0;
bool mFullCircle = false;
public:
Ring() : mPosition(0), mFullCircle(0) {}
Ring() = default;
void advance()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment