utils

Located within /builds/insightgit/Morpheus/include/morpheus/utils.hpp

A file consisting mostly of helper functions constructing the appropriate implementations of Morpheus classes for code portability across the DS and the GBA.

namespace morpheus
namespace utils

Functions

static morpheus::core::gfx::AnimationFrame *construct_appropriate_animation_frame(core::gfx::SpriteBase *sprite_base, core::gfx::AnimationFrame *from_animation_frame = nullptr)

Constructs the appropriate morpheus::core::gfx::AnimationFrame for the current platform.

Parameters
  • sprite_base – The sprite for the AnimationFrame

  • from_animation_frame – The optional from_animation_frame argument for the AnimationFrame

Returns

The appropriate AnimationFrame

static morpheus::core::MainLoop *construct_appropriate_main_loop(morpheus::core::GbaSaveType gba_save_type = morpheus::core::GbaSaveType::SRAM_32KB)

Constructs the appropriate morpheus::core::MainLoop for the current platform.

Parameters

gba_save_type – The appropriate GbaSaveType used if this function constructs a GbaMainLoop

Returns

The appropriate MainLoop

static morpheus::core::audio::MaxModMusic *construct_appropriate_max_mod_music(int sound_bank_ref_num, void *sound_bank = nullptr, unsigned char num_of_channels = -1)

Constructs the appropriate morpheus::core::audio::MaxModMusic for the current platform.

Parameters
  • sound_bank_ref_num – The sound bank reference number argument of MaxModMusic

  • sound_bank – The sound bank pointer argument of MaxModMusic

  • num_of_channels – The number of audio channels to use if constructing a GbaMaxModMusic

Returns

The appropriate MaxModMusic object

static morpheus::core::audio::MaxModSfx *construct_appropriate_max_mod_sfx(int sound_bank_ref_num, void *sound_bank = nullptr, int num_of_channels = -1)

Constructs the appropriate morpheus::core::audio::MaxModSfx for the current platform.

Parameters
  • sound_bank_ref_num – The sound bank reference number argument of MaxModSfx

  • sound_bank – The sound bank pointer argument of MaxModSfx

  • num_of_channels – The number of audio channels to use if constructing a GbaMaxModSfx

Returns

The appropriate MaxModSfx object

static morpheus::core::gfx::SpriteBase *construct_appropriate_sprite_4bpp(bool affine, morpheus::core::gfx::BlendingController *blending_controller, morpheus::core::gfx::MosaicController *mosaic_controller, bool nds_use_sub_display = false)

Constructs the appropriate 4bpp morpheus::core::gfx::SpriteBase for the current platform.

Parameters
  • affine – The affine argument of SpriteBase

  • blending_controller – The blending controller argument of SpriteBase

  • mosaic_controller – The mosaic controller argument of SpriteBase

  • nds_use_sub_display – If constructing a 4bpp sprite for the DS, should this sprite be displayed on the bottom sub display (true) or the top main display (false)

Returns

The appropriate 4bpp SpriteBase object

static morpheus::core::gfx::SpriteBase *construct_appropriate_sprite_8bpp(bool affine, morpheus::core::gfx::BlendingController *blending_controller, morpheus::core::gfx::MosaicController *mosaic_controller, bool nds_use_sub_display = false, bool nds_use_extended_palettes = false)

Constructs the appropriate 8bpp morpheus::core::gfx::SpriteBase for the current platform.

Parameters
  • affine – The affine argument of SpriteBase

  • blending_controller – The blending controller argument of SpriteBase

  • mosaic_controller – The mosaic controller argument of SpriteBase

  • nds_use_sub_display – If constructing an 8bpp sprite for the DS, should this sprite be displayed on the bottom sub display (true) or the top main display (false)

  • nds_use_sub_display – If constructing an 8bpp sprite for the DS, should extended palette mode be enabled or disabled

Returns

The appropriate 4bpp SpriteBase object

static morpheus::core::gfx::TextBase *construct_appropriate_text(bool affine, unsigned int background_num, unsigned int cbb, unsigned int sbb, morpheus::core::MainLoop *main_loop, bool nds_use_sub_display = false)

Constructs the appropriate morpheus::core::gfx::TextBase for the current platform.

Parameters
  • affine – The affine argument of TextBase

  • background_num – The background number argument of TextBase

  • cbb – The tile offset number argument of TextBase

  • sbb – The tilemap offset number argument of TextBase

  • main_loop – The main loop pointer argument of TextBase

  • nds_use_sub_display – If constructing a TextBase for the DS, should the text be displayed on the bottom sub display (true) or the top main display (false)

Returns

The appropriate TextBase object

static morpheus::core::gfx::TiledBackgroundBase *construct_appropriate_tiled_background_4bpp(bool affine, unsigned int background_num, morpheus::core::gfx::BlendingController *blending_controller, morpheus::core::gfx::MosaicController *mosaic_controller, morpheus::core::MainLoop *main_loop, unsigned int cbb_num, unsigned int sbb_num, bool nds_use_sub_display = false)

Constructs the appropriate 4bpp morpheus::core::gfx::TiledBackgroundBase for the current platform.

Parameters
  • affine – The affine argument of TiledBackgroundBase

  • background_num – The background number argument of TiledBackgroundBase

  • blending_controller – The blending controller argument of TiledBackgroundBase

  • mosaic_controller – The mosaic controller argument of TiledBackgroundBase

  • main_loop – The main loop pointer argument of TiledBackgroundBase

  • cbb_num – The tile offset number argument of TiledBackgroundBase

  • sbb_num – The tilemap offset number argument of TiledBackgroundBase

  • nds_use_sub_display – If constructing a TiledBackgroundBase for the DS, should the background be displayed on the bottom sub display (true) or the top main display (false)

Returns

The appropriate 4bpp TiledBackgroundBase

static morpheus::core::gfx::TiledBackgroundBase *construct_appropriate_tiled_background_8bpp(bool affine, unsigned int background_num, morpheus::core::gfx::BlendingController *blending_controller, morpheus::core::gfx::MosaicController *mosaic_controller, morpheus::core::MainLoop *main_loop, unsigned int cbb_num, unsigned int sbb_num, bool nds_use_sub_display = false)

Constructs the appropriate 8bpp morpheus::core::gfx::TiledBackgroundBase for the current platform.

Parameters
  • affine – The affine argument of TiledBackgroundBase

  • background_num – The background number argument of TiledBackgroundBase

  • blending_controller – The blending controller argument of TiledBackgroundBase

  • mosaic_controller – The mosaic controller argument of TiledBackgroundBase

  • main_loop – The main loop pointer argument of TiledBackgroundBase

  • cbb_num – The tile offset number argument of TiledBackgroundBase

  • sbb_num – The tilemap offset number argument of TiledBackgroundBase

  • nds_use_sub_display – If constructing a TiledBackgroundBase for the DS, should the background be displayed on the bottom sub display (true) or the top main display (false)

Returns

The appropriate 8bpp TiledBackgroundBase

static morpheus::core::gfx::Window *construct_appropriate_window(const core::gfx::WindowType window_type, const std::shared_ptr<core::MainLoop> main_loop, const bool nds_use_sub_display = false)

Constructs the appropriate morpheus::core::gfx::Window for the current platform.

Parameters
  • window_type – The window type argument of Window

  • main_loop – The main loop pointer argument of Window

  • nds_use_sub_display – If constructing a Window for the DS, should the window be on the bottom sub display (true) or the top main display (false)

Returns

The appropriate Window object

static morpheus::core::gfx::StreamingBackgroundBase *construct_appropriate_streaming_background_base(morpheus::core::gfx::TiledBackgroundBase *background_to_use, morpheus::core::gfx::Vector2 map_tile_update_threshold = morpheus::core::gfx::Vector2(0, 0), const morpheus::core::gfx::Vector2 &player_position = morpheus::core::gfx::Vector2(0, 0), bool enable_wrapping = false)

Constructs a morpheus::core::gfx::StreamingBackgroundBase with sensible defaults for the current platform.

Parameters
  • background_to_use – The TiledBackgroundBase argument of StreamingBackgroundBase

  • map_tile_update_threshold – The tilemap update threshold argument of StreamingBackgroundBase

  • player_position – The player position argument of StreamingBackgroundBase

  • enable_wrapping – The enable wrapping argument of StreamingBackgroundBase

Returns

The StreamingBackgroundBase with sensible platform defaults

class BackgroundTestControls : public morpheus::core::ControlReciever
#include <utils.hpp>

A helper class for testing background scrolling with the directional pad.

Public Functions

inline BackgroundTestControls(std::shared_ptr<morpheus::core::gfx::TiledBackgroundBase> background)

Constructs a BackgroundTestControls object with a given smart pointer to a TiledBackgroundBase.

Parameters

background – A smart pointer to the TiledBackgroundBase this class will control

inline virtual void input(morpheus::core::InputEvent input_event) override

Recieve a InputEvent for processing within this ControlReciever.

Parameters

input_event – The InputEvent to be recieved by this ControlReciever

inline virtual void update(unsigned char cycle_time) override

Updates this ControlReciever’s internal state. This should be called no more than once per VBlank.

Parameters

cycle_time – The current frame number (0-59) after a VBlank

inline void change_background(const std::shared_ptr<morpheus::core::gfx::TiledBackgroundBase> new_background)

Changes the current smart pointer to the TiledBackgroundBase that this class will control.

Parameters

new_background – The smart pointer that this class will control

Protected Functions

inline void scroll_background(morpheus::core::InputEvent input_event)

Scrolls the background according to InputEvents feeded by input()

Parameters

input_event – The InputEvent from input() to react to

Private Members

std::shared_ptr<morpheus::core::gfx::TiledBackgroundBase> m_background