Skip to content

Commit

Permalink
Move Transition effect to seperate class
Browse files Browse the repository at this point in the history
  • Loading branch information
copyrat90 committed May 20, 2021
1 parent e4e5200 commit 1c24c4f
Show file tree
Hide file tree
Showing 15 changed files with 521 additions and 178 deletions.
2 changes: 1 addition & 1 deletion include/Constants.h → include/constant.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <bn_color.h>

namespace sym::constants
namespace sym::constant
{
constexpr bn::color TRANSPARENT_BG_COLOR(4, 4, 6);
}
110 changes: 110 additions & 0 deletions include/effect_Transition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#pragma once

#include <bn_bgs_mosaic_actions.h>
#include <bn_blending_actions.h>
#include <bn_optional.h>
#include <bn_sprites_mosaic_actions.h>

namespace sym::effect
{

/**
* @brief Simple end-to-end transition
* Manages all the actions including transparency, fade, intensity, and mosaic.
*
*/
class Transition
{
public:
/**
* @brief Transition Type.
* Keep in mind that FADE and other blendings cannot be enabled at the same time.
*
*/
enum class Types
{
TRANSPARENCY = 1,
FADE = 2,
INTENSITY = 4,
SPRITE_MOSAIC = 8,
BG_MOSAIC = 16
};
enum class Direction
{
IN,
OUT
};
enum class State
{
NOT_READY,
ONGOING,
DONE
};

Transition(Types types, Direction direction, int updateCount);

~Transition();

/**
* @brief Allocates transition actions & sets state to ONGOING.
* You must call this function before using Transition.
*
* Calling Init() of the second transition object after calling Destroy() of the first transition object,
* you can prevent having FADE and other blendings at the same time,
* while keeping both Transition objects alive.
*
*/
void Init();

/**
* @brief Updates transition actions.
* you must check Done() first.
* Because updating the finished action will break the game.
* When transition is done, this function automatically calls Destroy() and sets state to DONE.
*
*/
void Update();

/**
* @brief Disposes transition actions.
* This function is automatically called when the transition is done.
* Keep in mind that you have to manually reset the blending alpha.
*
*/
void Destroy();

/**
* @brief Get the State object
*
* @return current state
*/
State GetState() const
{
return state_;
}

private:
const Types types_;
const Direction direction_;
int updateCountDown_;

State state_ = State::NOT_READY;

bn::optional<bn::blending_transparency_alpha_to_action> transparencyAction_;
bn::optional<bn::blending_fade_alpha_to_action> fadeAction_;
bn::optional<bn::blending_intensity_alpha_to_action> intensityAction_;
bn::optional<bn::sprites_mosaic_stretch_to_action> spriteMosaicAction_;
bn::optional<bn::bgs_mosaic_stretch_to_action> bgMosaicAction_;
};

inline Transition::Types operator|(Transition::Types t1, Transition::Types t2)
{
return static_cast<Transition::Types>(static_cast<int>(t1) | static_cast<int>(t2));
}

inline Transition::Types operator&(Transition::Types t1, Transition::Types t2)
{
return static_cast<Transition::Types>(static_cast<int>(t1) & static_cast<int>(t2));
}

} // namespace sym::effect
20 changes: 20 additions & 0 deletions include/global.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <bn_sprite_text_generator.h>

namespace sym::global
{

struct TextGen
{
bn::sprite_text_generator* hangeul;
bn::sprite_text_generator* latin;

TextGen(bn::sprite_text_generator* hg, bn::sprite_text_generator* lt) : hangeul(hg), latin(lt)
{
}
};

extern TextGen* textGenPtr_g;

} // namespace sym::global
4 changes: 2 additions & 2 deletions include/KeypadHelper.h → include/helper_keypad.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <bn_keypad.h>

namespace sym::helper
namespace sym::helper::keypad
{

bn::keypad::key_type operator|(bn::keypad::key_type a, bn::keypad::key_type b);

} // namespace sym::helper
} // namespace sym::helper::keypad
8 changes: 4 additions & 4 deletions include/Scene.h → include/scene_Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#include <bn_optional.h>

namespace sym
namespace sym::scene
{

enum class SceneType
enum class Type
{
SPLASH,
TITLE,
Expand All @@ -17,10 +17,10 @@ class Scene
{
public:
virtual ~Scene() = default;
[[nodiscard]] virtual bn::optional<SceneType> Update() = 0;
[[nodiscard]] virtual bn::optional<Type> Update() = 0;

protected:
Scene() = default;
};

} // namespace sym
} // namespace sym::scene
45 changes: 11 additions & 34 deletions include/SplashScene.h → include/scene_Splash.h
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
#pragma once

#include "Scene.h"
#include "scene_Scene.h"

#include <bn_array.h>
#include <bn_blending_actions.h>
#include <bn_keypad.h>
#include <bn_regular_bg_ptr.h>

namespace sym
#include "effect_Transition.h"

namespace sym::scene
{

class SplashScene final : public Scene
class Splash final : public Scene
{
public:
SplashScene();
~SplashScene() = default;
[[nodiscard]] bn::optional<SceneType> Update() final;
Splash();
~Splash();
[[nodiscard]] bn::optional<Type> Update() final;

private:
bn::array<bn::regular_bg_ptr, 2> bgs_;
bn::optional<bn::blending_transparency_alpha_to_action> transparentAction_;
effect::Transition fadeIn_;
effect::Transition fadeOut_;

static constexpr int BG_SWAP_UPDATE_COUNT = 30;
static constexpr int FADE_OUT_START_COUNT = 8;
static constexpr int FADE_IN_UPDATE_COUNT = 60;
static constexpr int FADE_OUT_UPDATE_COUNT = 60;

enum class SplashState
{
FADE_IN,
PRESENT,
FADE_OUT,
DONE
};
SplashState state_ = SplashState::FADE_IN;
int fadeOutStartCounter_ = FADE_OUT_START_COUNT;
int bgSwapUpdateCounter_ = BG_SWAP_UPDATE_COUNT;
bool isShowingFirstBg_ = false;
Expand All @@ -43,24 +38,6 @@ class SplashScene final : public Scene
void SwapBg_();

void FetchPressAnyOfTheseKeys_(bn::keypad::key_type theseKeys);

/**
* @brief Update when state_ is SplashState::FADE_IN
*
*/
void UpdateFadeIn_();

/**
* @brief Update when state_ is SplashState::FADE_OUT
*
*/
void UpdateFadeOut_();

/**
* @brief Update when state_ is SplashState::PRESENT
*
*/
void UpdatePresent_();
};

} // namespace sym
} // namespace sym::scene
34 changes: 34 additions & 0 deletions include/scene_Title.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include "scene_Scene.h"

#include <bn_array.h>
#include <bn_optional.h>
#include <bn_regular_bg_ptr.h>
#include <bn_sprite_ptr.h>

#include "effect_Transition.h"

namespace sym::scene
{

class Title final : public Scene
{
public:
Title();
~Title() = default;
[[nodiscard]] bn::optional<Type> Update() final;

private:
bn::array<bn::sprite_ptr, 2> cursor_;
bn::regular_bg_ptr bg_;
effect::Transition fadeIn_;
effect::Transition fadeOut_;

static constexpr int CURSOR_HORIZONTAL_OFFSET = 30;
static constexpr int BUTTON_WIDTH = 20;
static constexpr int FADE_IN_UPDATE_COUNT = 30;
static constexpr int FADE_OUT_UPDATE_COUNT = 30;
};

} // namespace sym::scene
11 changes: 0 additions & 11 deletions src/KeypadHelper.cpp

This file was deleted.

Loading

0 comments on commit 1c24c4f

Please sign in to comment.