Skip to content

Commit

Permalink
Resolve first-frame visual artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
justindriggers committed Jan 19, 2024
1 parent 29a7c86 commit 2bc50f0
Show file tree
Hide file tree
Showing 21 changed files with 146 additions and 85 deletions.
1 change: 1 addition & 0 deletions linguine/include/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "LifecycleManager.h"
#include "Logger.h"
#include "Scene.h"
#include "TimeManager.h"
#include "audio/AudioManager.h"
#include "entity/EntityManagerFactory.h"
Expand Down
15 changes: 13 additions & 2 deletions linguine/include/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@

#include "System.h"

#include "ServiceLocator.h"
#import "entity/EntityManagerFactory.h"

namespace linguine {

class Scene {
public:
explicit Scene(std::unique_ptr<EntityManager> entityManager)
: _entityManager(std::move(entityManager)) {}
explicit Scene(ServiceLocator& serviceLocator)
: _serviceLocator(serviceLocator),
_entityManager(serviceLocator.get<EntityManagerFactory>().create()) {}

virtual ~Scene() = default;

virtual void init() = 0;

void update(float deltaTime) {
for (const auto& system : _systems) {
system->update(deltaTime);
Expand All @@ -26,6 +32,10 @@ class Scene {
}

protected:
template<typename T> inline T& get() {
return _serviceLocator.get<T>();
}

inline EntityManager& getEntityManager() {
return *_entityManager;
}
Expand All @@ -39,6 +49,7 @@ class Scene {
}

private:
ServiceLocator& _serviceLocator;
std::unique_ptr<EntityManager> _entityManager;
std::vector<std::unique_ptr<System>> _systems;
};
Expand Down
4 changes: 2 additions & 2 deletions linguine/include/SceneManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#include <memory>

#include "Scene.h"

namespace linguine {

class Scene;

class SceneManager {
public:
virtual void load(std::unique_ptr<Scene> scene) = 0;
Expand Down
5 changes: 5 additions & 0 deletions linguine/include/ServiceLocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class ServiceLocator {
return getSceneManager();
}

template<>
inline ServiceLocator& get<ServiceLocator>() {
return *this;
}

template<>
inline TimeManager& get<TimeManager>() {
return getTimeManager();
Expand Down
4 changes: 2 additions & 2 deletions linguine/include/TimeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TimeManager {
inline void reset() {
_lastTickTime = currentTime();
_currentTickTime = _lastTickTime;
_accumulator = 0.0f;
_accumulator = _fixedDeltaTime;
}

inline float tick() {
Expand Down Expand Up @@ -75,7 +75,7 @@ class TimeManager {
private:
constexpr static float _fixedDeltaTime = 0.02f;

float _accumulator = 0.0f;
float _accumulator = _fixedDeltaTime;
float _timeScale = 1.0f;

time_t _startTime;
Expand Down
3 changes: 3 additions & 0 deletions linguine/src/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Engine::Engine(
_audioManager->setMusicEnabled(_saveManager->isMusicEnabled());
_audioManager->setSoundEffectsEnabled(_saveManager->isSoundEffectsEnabled());
_currentScene = std::make_unique<TitleScene>(*this);
_currentScene->init();
}

void Engine::run() {
Expand Down Expand Up @@ -56,6 +57,8 @@ void Engine::tick() {

_renderer->reset();
_timeManager->reset();

_currentScene->init();
}
}

Expand Down
1 change: 1 addition & 0 deletions linguine/src/components/Attachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace linguine {
struct Attachment {
uint64_t parentId{};
glm::vec2 offset = { 0.0f, 0.0f };
bool useFixedUpdate = true;
};

} // namespace lingiune
1 change: 1 addition & 0 deletions linguine/src/components/Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct Button {
glm::vec2 minSize = glm::vec2(1.0f);
glm::vec3 color = Palette::Primary;
glm::vec3 activeColor = Palette::PrimaryAccent;
bool visible = true;

std::string text;
glm::vec3 textColor = glm::vec3(1.0f);
Expand Down
30 changes: 15 additions & 15 deletions linguine/src/scenes/GameOverScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@

namespace linguine {

GameOverScene::GameOverScene(ServiceLocator& serviceLocator, int32_t points)
: Scene(serviceLocator.get<EntityManagerFactory>().create()) {
registerSystem(std::make_unique<FpsSystem>(getEntityManager(), serviceLocator.get<Logger>()));
registerSystem(std::make_unique<GestureRecognitionSystem>(getEntityManager(), serviceLocator.get<InputManager>(), serviceLocator.get<Renderer>(), serviceLocator.get<TimeManager>()));
registerSystem(std::make_unique<PhysicsInterpolationSystem>(getEntityManager(), serviceLocator.get<TimeManager>()));
registerSystem(std::make_unique<ButtonSystem>(getEntityManager(), serviceLocator.get<Renderer>(), serviceLocator.get<AudioManager>()));
void GameOverScene::init() {
registerSystem(std::make_unique<FpsSystem>(getEntityManager(), get<Logger>()));
registerSystem(std::make_unique<GestureRecognitionSystem>(getEntityManager(), get<InputManager>(), get<Renderer>(), get<TimeManager>()));
registerSystem(std::make_unique<PhysicsInterpolationSystem>(getEntityManager(), get<TimeManager>()));
registerSystem(std::make_unique<ButtonSystem>(getEntityManager(), get<Renderer>(), get<AudioManager>()));
registerSystem(std::make_unique<ToastSystem>(getEntityManager()));
registerSystem(std::make_unique<ShakeSystem>(getEntityManager(), serviceLocator.get<SaveManager>()));
registerSystem(std::make_unique<ShakeSystem>(getEntityManager(), get<SaveManager>()));

registerSystem(std::make_unique<LevelTrackingSystem>(getEntityManager(), serviceLocator.get<AudioManager>(), _upgradeDatabase));
registerSystem(std::make_unique<LevelTrackingSystem>(getEntityManager(), get<AudioManager>(), _upgradeDatabase));

registerSystem(std::make_unique<TransformationSystem>(getEntityManager()));
registerSystem(std::make_unique<CameraSystem>(getEntityManager(), serviceLocator.get<Renderer>()));
registerSystem(std::make_unique<CameraSystem>(getEntityManager(), get<Renderer>()));

auto& renderer = serviceLocator.get<Renderer>();
auto& sceneManager = serviceLocator.get<SceneManager>();
auto& saveManager = serviceLocator.get<SaveManager>();
auto& renderer = get<Renderer>();
auto& sceneManager = get<SceneManager>();
auto& saveManager = get<SaveManager>();
auto& serviceLocator = get<ServiceLocator>();

{
auto uiCameraEntity = createEntity();
Expand Down Expand Up @@ -101,9 +101,9 @@ GameOverScene::GameOverScene(ServiceLocator& serviceLocator, int32_t points)

{
auto progressBarEntity = createEntity();
progressBarEntity->add<LevelTracker>(saveManager.getPoints(), saveManager.getPoints() + points);
progressBarEntity->add<LevelTracker>(saveManager.getPoints(), saveManager.getPoints() + _points);

saveManager.addPoints(points);
saveManager.addPoints(_points);

auto transform = progressBarEntity->add<Transform>();
transform->scale = { 192.0f, 12.0f, 1.0f };
Expand Down Expand Up @@ -200,7 +200,7 @@ GameOverScene::GameOverScene(ServiceLocator& serviceLocator, int32_t points)
text->renderable->setEnabled(false);
}

auto& audioManager = serviceLocator.get<AudioManager>();
auto& audioManager = get<AudioManager>();
audioManager.play(SongType::GameOver, Mode::Once);
}

Expand Down
6 changes: 5 additions & 1 deletion linguine/src/scenes/GameOverScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ namespace linguine {

class GameOverScene : public Scene {
public:
GameOverScene(ServiceLocator& serviceLocator, int32_t points);
GameOverScene(ServiceLocator& serviceLocator, int32_t points)
: Scene(serviceLocator), _points(points) {}

void init() override;

private:
int32_t _points;
UpgradeDatabase _upgradeDatabase;
};

Expand Down
30 changes: 14 additions & 16 deletions linguine/src/scenes/InfiniteRunnerScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,36 @@

namespace linguine {

InfiniteRunnerScene::InfiniteRunnerScene(ServiceLocator& serviceLocator)
: Scene(serviceLocator.get<EntityManagerFactory>().create()),
_spellDatabase(std::make_unique<SpellDatabase>(serviceLocator, getEntityManager())) {
registerSystem(std::make_unique<FpsSystem>(getEntityManager(), serviceLocator.get<Logger>()));
registerSystem(std::make_unique<GestureRecognitionSystem>(getEntityManager(), serviceLocator.get<InputManager>(), serviceLocator.get<Renderer>(), serviceLocator.get<TimeManager>()));
registerSystem(std::make_unique<PlayerControllerSystem>(getEntityManager(), serviceLocator.get<InputManager>(), serviceLocator.get<AudioManager>()));
void InfiniteRunnerScene::init() {
registerSystem(std::make_unique<FpsSystem>(getEntityManager(), get<Logger>()));
registerSystem(std::make_unique<GestureRecognitionSystem>(getEntityManager(), get<InputManager>(), get<Renderer>(), get<TimeManager>()));
registerSystem(std::make_unique<PlayerControllerSystem>(getEntityManager(), get<InputManager>(), get<AudioManager>()));
registerSystem(std::make_unique<VelocitySystem>(getEntityManager()));
registerSystem(std::make_unique<CameraFollowSystem>(getEntityManager()));
registerSystem(std::make_unique<AttachmentSystem>(getEntityManager()));
registerSystem(std::make_unique<PhysicsInterpolationSystem>(getEntityManager(), serviceLocator.get<TimeManager>()));
registerSystem(std::make_unique<PhysicsInterpolationSystem>(getEntityManager(), get<TimeManager>()));
registerSystem(std::make_unique<CollisionSystem>(getEntityManager()));
registerSystem(std::make_unique<EffectSystem>(getEntityManager(), *_spellDatabase));
registerSystem(std::make_unique<HudSystem>(getEntityManager(), serviceLocator.get<Renderer>()));
registerSystem(std::make_unique<HudSystem>(getEntityManager(), get<Renderer>()));
registerSystem(std::make_unique<HealthProgressSystem>(getEntityManager()));
registerSystem(std::make_unique<LivenessSystem>(getEntityManager(), serviceLocator.get<Renderer>(), serviceLocator.get<AudioManager>(), serviceLocator.get<SaveManager>(), serviceLocator));
registerSystem(std::make_unique<LivenessSystem>(getEntityManager(), get<Renderer>(), get<AudioManager>(), get<SaveManager>(), get<ServiceLocator>()));
registerSystem(std::make_unique<CooldownProgressSystem>(getEntityManager()));
registerSystem(std::make_unique<CastSystem>(getEntityManager()));
registerSystem(std::make_unique<ParticleSystem>(getEntityManager()));
registerSystem(std::make_unique<FireSystem>(getEntityManager()));
registerSystem(std::make_unique<ToastSystem>(getEntityManager()));
registerSystem(std::make_unique<ShakeSystem>(getEntityManager(), serviceLocator.get<SaveManager>()));
registerSystem(std::make_unique<ShakeSystem>(getEntityManager(), get<SaveManager>()));

// Scene-specific
registerSystem(std::make_unique<SpawnSystem>(getEntityManager(), serviceLocator.get<Renderer>()));
registerSystem(std::make_unique<ScoringSystem>(getEntityManager(), *_spellDatabase, serviceLocator.get<Renderer>(), serviceLocator.get<AudioManager>()));
registerSystem(std::make_unique<SpawnSystem>(getEntityManager(), get<Renderer>()));
registerSystem(std::make_unique<ScoringSystem>(getEntityManager(), *_spellDatabase, get<Renderer>(), get<AudioManager>()));
registerSystem(std::make_unique<TutorialSystem>(getEntityManager()));

registerSystem(std::make_unique<TransformationSystem>(getEntityManager()));
registerSystem(std::make_unique<CameraSystem>(getEntityManager(), serviceLocator.get<Renderer>()));
registerSystem(std::make_unique<CameraSystem>(getEntityManager(), get<Renderer>()));

auto& renderer = serviceLocator.get<Renderer>();
auto& saveManager = serviceLocator.get<SaveManager>();
auto& renderer = get<Renderer>();
auto& saveManager = get<SaveManager>();

if (saveManager.isNewPlayer()) {
auto tutorialEntity = createEntity();
Expand Down Expand Up @@ -470,7 +468,7 @@ InfiniteRunnerScene::InfiniteRunnerScene(ServiceLocator& serviceLocator)
text->renderable->setEnabled(false);
}

auto& audioManager = serviceLocator.get<AudioManager>();
auto& audioManager = get<AudioManager>();
audioManager.play(SongType::Theme, Mode::Repeat);
}

Expand Down
6 changes: 5 additions & 1 deletion linguine/src/scenes/InfiniteRunnerScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ namespace linguine {

class InfiniteRunnerScene : public Scene {
public:
explicit InfiniteRunnerScene(ServiceLocator& serviceLocator);
explicit InfiniteRunnerScene(ServiceLocator& serviceLocator)
: Scene(serviceLocator),
_spellDatabase(std::make_unique<SpellDatabase>(serviceLocator, getEntityManager())) {}

void init() override;

private:
std::random_device _random;
Expand Down
20 changes: 10 additions & 10 deletions linguine/src/scenes/OptionsScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@

namespace linguine {

OptionsScene::OptionsScene(ServiceLocator& serviceLocator)
: Scene(serviceLocator.get<EntityManagerFactory>().create()) {
registerSystem(std::make_unique<FpsSystem>(getEntityManager(), serviceLocator.get<Logger>()));
registerSystem(std::make_unique<GestureRecognitionSystem>(getEntityManager(), serviceLocator.get<InputManager>(), serviceLocator.get<Renderer>(), serviceLocator.get<TimeManager>()));
void OptionsScene::init() {
registerSystem(std::make_unique<FpsSystem>(getEntityManager(), get<Logger>()));
registerSystem(std::make_unique<GestureRecognitionSystem>(getEntityManager(), get<InputManager>(), get<Renderer>(), get<TimeManager>()));
registerSystem(std::make_unique<ToggleSystem>(getEntityManager()));
registerSystem(std::make_unique<ButtonSystem>(getEntityManager(), serviceLocator.get<Renderer>(), serviceLocator.get<AudioManager>()));
registerSystem(std::make_unique<ButtonSystem>(getEntityManager(), get<Renderer>(), get<AudioManager>()));

registerSystem(std::make_unique<TransformationSystem>(getEntityManager()));
registerSystem(std::make_unique<CameraSystem>(getEntityManager(), serviceLocator.get<Renderer>()));
registerSystem(std::make_unique<CameraSystem>(getEntityManager(), get<Renderer>()));

auto& audioManager = serviceLocator.get<AudioManager>();
auto& renderer = serviceLocator.get<Renderer>();
auto& saveManager = serviceLocator.get<SaveManager>();
auto& sceneManager = serviceLocator.get<SceneManager>();
auto& audioManager = get<AudioManager>();
auto& renderer = get<Renderer>();
auto& saveManager = get<SaveManager>();
auto& sceneManager = get<SceneManager>();
auto& serviceLocator = get<ServiceLocator>();

{
auto uiCameraEntity = createEntity();
Expand Down
5 changes: 4 additions & 1 deletion linguine/src/scenes/OptionsScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ namespace linguine {

class OptionsScene : public Scene {
public:
explicit OptionsScene(ServiceLocator& serviceLocator);
explicit OptionsScene(ServiceLocator& serviceLocator)
: Scene(serviceLocator) {}

void init() override;
};

} // namespace linguine
36 changes: 16 additions & 20 deletions linguine/src/scenes/TitleScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,30 @@

namespace linguine {

TitleScene::TitleScene(ServiceLocator &serviceLocator)
: Scene(serviceLocator.get<EntityManagerFactory>().create()) {
registerSystem(std::make_unique<FpsSystem>(getEntityManager(), serviceLocator.get<Logger>()));
registerSystem(std::make_unique<GestureRecognitionSystem>(getEntityManager(), serviceLocator.get<InputManager>(), serviceLocator.get<Renderer>(), serviceLocator.get<TimeManager>()));
void TitleScene::init() {
registerSystem(std::make_unique<FpsSystem>(getEntityManager(), get<Logger>()));
registerSystem(std::make_unique<GestureRecognitionSystem>(getEntityManager(), get<InputManager>(), get<Renderer>(), get<TimeManager>()));
registerSystem(std::make_unique<VelocitySystem>(getEntityManager()));
registerSystem(std::make_unique<CameraFollowSystem>(getEntityManager()));
registerSystem(std::make_unique<ButtonSystem>(getEntityManager(), serviceLocator.get<Renderer>(), serviceLocator.get<AudioManager>()));
registerSystem(std::make_unique<DialogSystem>(getEntityManager()));
registerSystem(std::make_unique<ButtonSystem>(getEntityManager(), get<Renderer>(), get<AudioManager>()));
registerSystem(std::make_unique<FooterSystem>(getEntityManager(), get<Renderer>()));
registerSystem(std::make_unique<AttachmentSystem>(getEntityManager()));
registerSystem(std::make_unique<PhysicsInterpolationSystem>(getEntityManager(), serviceLocator.get<TimeManager>()));
registerSystem(std::make_unique<PhysicsInterpolationSystem>(getEntityManager(), get<TimeManager>()));
registerSystem(std::make_unique<CollisionSystem>(getEntityManager()));
registerSystem(std::make_unique<ParticleSystem>(getEntityManager()));
registerSystem(std::make_unique<FireSystem>(getEntityManager()));

registerSystem(std::make_unique<SpawnSystem>(getEntityManager(), serviceLocator.get<Renderer>()));
registerSystem(std::make_unique<DialogSystem>(getEntityManager()));
registerSystem(std::make_unique<FooterSystem>(getEntityManager(), serviceLocator.get<Renderer>()));
registerSystem(std::make_unique<SpawnSystem>(getEntityManager(), get<Renderer>()));

registerSystem(std::make_unique<TransformationSystem>(getEntityManager()));
registerSystem(std::make_unique<CameraSystem>(getEntityManager(), serviceLocator.get<Renderer>()));
registerSystem(std::make_unique<CameraSystem>(getEntityManager(), get<Renderer>()));

auto& audioManager = serviceLocator.get<AudioManager>();
auto& renderer = serviceLocator.get<Renderer>();
auto& sceneManager = serviceLocator.get<SceneManager>();
auto& saveManager = serviceLocator.get<SaveManager>();
auto& audioManager = get<AudioManager>();
auto& renderer = get<Renderer>();
auto& sceneManager = get<SceneManager>();
auto& saveManager = get<SaveManager>();
auto& serviceLocator = get<ServiceLocator>();

{
auto cameraEntity = createEntity();
Expand Down Expand Up @@ -522,8 +522,6 @@ TitleScene::TitleScene(ServiceLocator &serviceLocator)
transform->position = { 0.0f, 0.0f, 10.0f };
transform->scale = { 240.0f, 48.0f, 1.0f };

footerPanelEntity->add<PhysicalState>(transform->position, 0.0f);

auto drawable = footerPanelEntity->add<Drawable>();
drawable->feature = new ColoredFeature();
drawable->feature->color = Palette::SecondaryAccent;
Expand All @@ -539,11 +537,10 @@ TitleScene::TitleScene(ServiceLocator &serviceLocator)
footerTextTransform->position = { 0.0f, 0.0f, 5.0f };
footerTextTransform->scale = { 8.0f, 8.0f, 1.0f };

footerTextEntity->add<PhysicalState>(footerTextTransform->position, 0.0f);

auto attachment = footerTextEntity->add<Attachment>();
attachment->parentId = footerPanelEntity->getId();
attachment->offset = { -56.0f, 8.0f };
attachment->useFixedUpdate = false;

auto text = footerTextEntity->add<Text>();
text->feature = new TextFeature();
Expand All @@ -561,11 +558,10 @@ TitleScene::TitleScene(ServiceLocator &serviceLocator)
footerTextTransform->position = { 0.0f, 0.0f, 5.0f };
footerTextTransform->scale = { 5.0f, 5.0f, 1.0f };

footerTextEntity->add<PhysicalState>(footerTextTransform->position, 0.0f);

auto attachment = footerTextEntity->add<Attachment>();
attachment->parentId = footerPanelEntity->getId();
attachment->offset = { -72.5f, -8.0f };
attachment->useFixedUpdate = false;

auto text = footerTextEntity->add<Text>();
text->feature = new TextFeature();
Expand Down

0 comments on commit 2bc50f0

Please sign in to comment.