Peoplemon  0.1.0
Peoplemon 3 game source documentation
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
core::map::Map Class Reference

The primary map class that represents a usable map in the game. More...

#include <Map.hpp>

+ Inheritance diagram for core::map::Map:

Public Member Functions

 Map ()
 Creates an empty Map. More...
 
virtual ~Map ()
 Destroy the Map. More...
 
bool loadDev (std::istream &input)
 Loads the map from the given file. Will try to determine if the extension or path need to be added in order to support how map names used to be entered. Loads the json format. More...
 
bool loadProd (bl::serial::binary::InputStream &input)
 Loads the map from the given file. Will try to determine if the extension or path need to be added in order to support how map names used to be entered. Loads the binary format. More...
 
bool save (const std::string &file)
 Saves the map to the given file. The path should be relative to the maps directory and include the .map extension. More...
 
bool saveBundle (bl::serial::binary::OutputStream &output, bl::resource::bundle::FileHandlerContext &ctx) const
 Saves the data from this object to the given bundle and registers dependency files. More...
 
bool enter (system::Systems &systems, std::uint16_t spawnId, const std::string &prevMap, const bl::tmap::Position &prevPlayerPos)
 Initializes runtime data structures and spawns entities into the game. Also runs the on-load script. More...
 
void exit (system::Systems &systems, const std::string &newMap)
 Removes spawned entities and runs the on-unload script. More...
 
void setupCamera (system::Systems &systems)
 Configures the game camera for the player in the map. More...
 
const std::string & name () const
 Returns the name of the map. More...
 
WeatherweatherSystem ()
 Returns a reference to the weather system in this map. More...
 
LightingSystemlightingSystem ()
 Returns a reference to the lighting system in this map. More...
 
const sf::Vector2i & sizeTiles () const
 Returns the size of the map in tiles. More...
 
sf::Vector2f sizePixels () const
 Returns the size of the map in pixels. More...
 
std::uint8_t levelCount () const
 Returns the number of levels in the map. More...
 
void update (float dt)
 Updates internal logic over the elapsed time. More...
 
bool contains (const bl::tmap::Position &position) const
 Returns whether or not the map contains the given position. More...
 
bl::tmap::Position adjacentTile (const bl::tmap::Position &pos, bl::tmap::Direction dir) const
 Returns the adjacent position to the given position when moving in the given direction. Does not take into account collisions. More...
 
bool movePossible (const bl::tmap::Position &position, bl::tmap::Direction dir) const
 Returns whether or not a particular movement is possible. Does not take into account entities blocking the way. More...
 
bool isLedgeHop (const bl::tmap::Position &position, bl::tmap::Direction dir) const
 Test whether the given movement will be a ledge hop or not. More...
 
virtual void observe (const event::EntityMoved &moveEvent) override
 Event listener for moving entities. Used to trigger map events. More...
 
bool interact (bl::ecs::Entity interactor, const bl::tmap::Position &interactPos)
 Lets entities interact with the map itself. This is called by the Interaction system. More...
 
const CatchRegiongetCatchRegion (const bl::tmap::Position &position) const
 Returns the catch region at the given position if the position is on a catch tile. More...
 
bool canFlyFromHere () const
 Returns whether or not the player can fly from this map. More...
 
const bl::tmap::Position * getSpawnPosition (unsigned int spawnId) const
 Returns the position of the given player spawn, or nullptr if not found. More...
 
const std::string & getLocationName (const bl::tmap::Position &pos) const
 Returns the name of the town or route at the given position. More...
 
float getDepthForPosition (unsigned int level, unsigned int y, int layer=-1) const
 Computes the depth to use at the given y position, taking into account the map size, layer count, and layer types. More...
 
float getMinDepth () const
 Returns the maximum depth possible for this map. Maximum is always 0.f. Minimum is negative, so 'higher' positions will have lower depths than deeper positions. More...
 
bl::rc::SceneRef getScene ()
 Returns the scene for this map. More...
 
bl::rc::lgt::Scene2DLighting & getSceneLighting ()
 Returns the scene lighting for this map. Only valid after enter() is called. More...
 
void setupEntityPosition (bl::ecs::Entity entity)
 Performs the final setup of the position components for the given entity. Must already have a bl::tmap::Position and bl::com::Transform2D component. More...
 

Static Public Member Functions

static std::string getMapFile (const std::string &partialFile)
 Returns the full path to the map file from the given partial file. Accounts for missing extension. More...
 
static const std::vector< Town > & FlyMapTowns ()
 Returns the set of towns that can be flown to. More...
 

Protected Member Functions

void clear ()
 
void finishLoad ()
 
void triggerAnimation (const bl::tmap::Position &position)
 
TowngetTown (const glm::i32vec2 &pos)
 
void enterTown (Town *town)
 
void prepareRender ()
 
void cleanupRender ()
 
void setupLevel (unsigned int level)
 
void setupLayer (unsigned int level, unsigned int layer)
 
void setupTile (unsigned int level, unsigned int layer, const sf::Vector2u &pos)
 

Static Protected Member Functions

static void loadFlymapTowns ()
 

Protected Attributes

std::string nameField
 
std::string loadScriptField
 
std::string unloadScriptField
 
std::string playlistField
 
Weather::Type weatherField
 
std::vector< LayerSetlevels
 
std::string tilesetField
 
std::unordered_map< std::uint16_t, Spawnspawns
 
std::vector< CharacterSpawncharacterField
 
std::vector< ItemitemsField
 
std::vector< EventeventsField
 
LightingSystem lighting
 
std::vector< CatchRegioncatchRegionsField
 
bl::ctr::Vector2D< LevelTransitiontransitionField
 
std::vector< Towntowns
 
bl::ctr::Vector2D< std::uint8_t > townTiles
 
system::Systemssystems
 
Town defaultTown
 
TowncurrentTown
 
sf::Vector2i size
 
bl::resource::Ref< Tilesettileset
 
Weather weather
 
std::unique_ptr< bl::script::Script > onEnterScript
 
std::unique_ptr< bl::script::Script > onExitScript
 
bl::ctr::Grid< const Event * > eventRegions
 
bool isWorldMap
 
bl::audio::AudioSystem::Handle playlistHandle
 
bool activated
 
bl::rc::SceneRef scene
 
std::list< RenderLevelrenderLevels
 

Static Protected Attributes

static std::vector< TownflymapTowns
 

Friends

struct bl::serial::SerializableObject< Map >
 

Detailed Description

The primary map class that represents a usable map in the game.

Definition at line 49 of file Map.hpp.

Constructor & Destructor Documentation

◆ Map()

core::map::Map::Map ( )

Creates an empty Map.

Definition at line 21 of file Map.cpp.

◆ ~Map()

core::map::Map::~Map ( )
virtual

Destroy the Map.

Definition at line 27 of file Map.cpp.

Member Function Documentation

◆ adjacentTile()

bl::tmap::Position core::map::Map::adjacentTile ( const bl::tmap::Position &  pos,
bl::tmap::Direction  dir 
) const

Returns the adjacent position to the given position when moving in the given direction. Does not take into account collisions.

Parameters
posThe position that is being moved from
dirThe direction that the movement is going
Returns
bl::tmap::Position The adjacent tile with level transition if any

Definition at line 276 of file Map.cpp.

◆ canFlyFromHere()

bool core::map::Map::canFlyFromHere ( ) const

Returns whether or not the player can fly from this map.

Definition at line 603 of file Map.cpp.

◆ cleanupRender()

void core::map::Map::cleanupRender ( )
protected

Definition at line 779 of file Map.cpp.

◆ clear()

void core::map::Map::clear ( )
protected

Definition at line 523 of file Map.cpp.

◆ contains()

bool core::map::Map::contains ( const bl::tmap::Position &  position) const

Returns whether or not the map contains the given position.

Parameters
positionThe position to check for
Returns
True if the position is within the map, false if not

Definition at line 271 of file Map.cpp.

◆ enter()

bool core::map::Map::enter ( system::Systems systems,
std::uint16_t  spawnId,
const std::string &  prevMap,
const bl::tmap::Position &  prevPlayerPos 
)

Initializes runtime data structures and spawns entities into the game. Also runs the on-load script.

Parameters
systemsThe primary game systems
spawnIdThe spawn to place the player at
prevMapThe name of the map coming from
prevPlayerPosUsed to spawn the player when coming back from a map or loading save
Returns
True on success, false on error

Definition at line 32 of file Map.cpp.

◆ enterTown()

void core::map::Map::enterTown ( Town town)
protected

Definition at line 549 of file Map.cpp.

◆ exit()

void core::map::Map::exit ( system::Systems systems,
const std::string &  newMap 
)

Removes spawned entities and runs the on-unload script.

Parameters
systemsThe primary game systems
newMapThe name of the map going to

Definition at line 136 of file Map.cpp.

◆ finishLoad()

void core::map::Map::finishLoad ( )
protected

Definition at line 215 of file Map.cpp.

◆ FlyMapTowns()

const std::vector< Town > & core::map::Map::FlyMapTowns ( )
static

Returns the set of towns that can be flown to.

Definition at line 587 of file Map.cpp.

◆ getCatchRegion()

const CatchRegion * core::map::Map::getCatchRegion ( const bl::tmap::Position &  position) const

Returns the catch region at the given position if the position is on a catch tile.

Parameters
positionThe position to search
Returns
CatchRegion* The catch region if on a catch tile and a region is there, or nullptr

Definition at line 567 of file Map.cpp.

◆ getDepthForPosition()

float core::map::Map::getDepthForPosition ( unsigned int  level,
unsigned int  y,
int  layer = -1 
) const

Computes the depth to use at the given y position, taking into account the map size, layer count, and layer types.

Parameters
levelThe level of the position to compute the depth for
yThe y coordinate of the position to compute the depth for
layerThe index of the layer to compute the depth for. -1 is for entities
Returns
The depth to use for the given position, both for tiles and entities

Definition at line 741 of file Map.cpp.

◆ getLocationName()

const std::string & core::map::Map::getLocationName ( const bl::tmap::Position &  pos) const

Returns the name of the town or route at the given position.

Parameters
posThe position to check for
Returns
const std::string& The name of the town, route, or map of the position

Definition at line 610 of file Map.cpp.

◆ getMapFile()

std::string core::map::Map::getMapFile ( const std::string &  partialFile)
static

Returns the full path to the map file from the given partial file. Accounts for missing extension.

Parameters
partialFile
Returns
std::string

Definition at line 191 of file Map.cpp.

◆ getMinDepth()

float core::map::Map::getMinDepth ( ) const

Returns the maximum depth possible for this map. Maximum is always 0.f. Minimum is negative, so 'higher' positions will have lower depths than deeper positions.

Definition at line 775 of file Map.cpp.

◆ getScene()

bl::rc::SceneRef core::map::Map::getScene ( )
inline

Returns the scene for this map.

Definition at line 280 of file Map.hpp.

◆ getSceneLighting()

bl::rc::lgt::Scene2DLighting& core::map::Map::getSceneLighting ( )
inline

Returns the scene lighting for this map. Only valid after enter() is called.

Definition at line 285 of file Map.hpp.

◆ getSpawnPosition()

const bl::tmap::Position * core::map::Map::getSpawnPosition ( unsigned int  spawnId) const

Returns the position of the given player spawn, or nullptr if not found.

Parameters
spawnIdId of the spawn to get the position for
Returns
const bl::tmap::Position* Pointer to the position to spawn at. May be nullptr

Definition at line 605 of file Map.cpp.

◆ getTown()

Town * core::map::Map::getTown ( const glm::i32vec2 &  pos)
protected

Definition at line 541 of file Map.cpp.

◆ interact()

bool core::map::Map::interact ( bl::ecs::Entity  interactor,
const bl::tmap::Position &  interactPos 
)

Lets entities interact with the map itself. This is called by the Interaction system.

Parameters
interactorThe entity doing the interact
interactPosThe position being interacted with

Definition at line 454 of file Map.cpp.

◆ isLedgeHop()

bool core::map::Map::isLedgeHop ( const bl::tmap::Position &  position,
bl::tmap::Direction  dir 
) const

Test whether the given movement will be a ledge hop or not.

Parameters
positionThe current position being moved away from
dirThe direction being moved in
Returns
True if the move is a ledge hop, false otherwise

Definition at line 378 of file Map.cpp.

◆ levelCount()

std::uint8_t core::map::Map::levelCount ( ) const

Returns the number of levels in the map.

Definition at line 180 of file Map.cpp.

◆ lightingSystem()

LightingSystem & core::map::Map::lightingSystem ( )

Returns a reference to the lighting system in this map.

Definition at line 184 of file Map.cpp.

◆ loadDev()

bool core::map::Map::loadDev ( std::istream &  input)

Loads the map from the given file. Will try to determine if the extension or path need to be added in order to support how map names used to be entered. Loads the json format.

Parameters
inputStream to load the map from
Returns
True if the map was able to be loaded, false on error

Definition at line 203 of file Map.cpp.

◆ loadFlymapTowns()

void core::map::Map::loadFlymapTowns ( )
staticprotected

Definition at line 592 of file Map.cpp.

◆ loadProd()

bool core::map::Map::loadProd ( bl::serial::binary::InputStream &  input)

Loads the map from the given file. Will try to determine if the extension or path need to be added in order to support how map names used to be entered. Loads the binary format.

Parameters
inputStream to load the map from
Returns
True if the map was able to be loaded, false on error

Definition at line 209 of file Map.cpp.

◆ movePossible()

bool core::map::Map::movePossible ( const bl::tmap::Position &  position,
bl::tmap::Direction  dir 
) const

Returns whether or not a particular movement is possible. Does not take into account entities blocking the way.

Parameters
positionThe position being moved from
dirThe direction to move in
Returns
True if the move is allowed, false if it is not

Definition at line 329 of file Map.cpp.

◆ name()

const std::string & core::map::Map::name ( ) const

Returns the name of the map.

Definition at line 171 of file Map.cpp.

◆ observe()

void core::map::Map::observe ( const event::EntityMoved moveEvent)
overridevirtual

Event listener for moving entities. Used to trigger map events.

Parameters
moveEventThe move event

Definition at line 385 of file Map.cpp.

◆ prepareRender()

void core::map::Map::prepareRender ( )
protected

Definition at line 614 of file Map.cpp.

◆ save()

bool core::map::Map::save ( const std::string &  file)

Saves the map to the given file. The path should be relative to the maps directory and include the .map extension.

Parameters
fileThe file to save to
Returns
True if saved successfully, false on error

Definition at line 229 of file Map.cpp.

◆ saveBundle()

bool core::map::Map::saveBundle ( bl::serial::binary::OutputStream &  output,
bl::resource::bundle::FileHandlerContext &  ctx 
) const

Saves the data from this object to the given bundle and registers dependency files.

Parameters
outputStream to output to
ctxContext to register dependencies with
Returns
True if serialization succeeded, false otherwise

Definition at line 246 of file Map.cpp.

◆ setupCamera()

void core::map::Map::setupCamera ( system::Systems systems)

Configures the game camera for the player in the map.

Parameters
systemsThe main game systems

Definition at line 160 of file Map.cpp.

◆ setupEntityPosition()

void core::map::Map::setupEntityPosition ( bl::ecs::Entity  entity)

Performs the final setup of the position components for the given entity. Must already have a bl::tmap::Position and bl::com::Transform2D component.

Parameters
entityThe entity to initialize

Definition at line 792 of file Map.cpp.

◆ setupLayer()

void core::map::Map::setupLayer ( unsigned int  level,
unsigned int  layer 
)
protected

Definition at line 635 of file Map.cpp.

◆ setupLevel()

void core::map::Map::setupLevel ( unsigned int  level)
protected

Definition at line 624 of file Map.cpp.

◆ setupTile()

void core::map::Map::setupTile ( unsigned int  level,
unsigned int  layer,
const sf::Vector2u &  pos 
)
protected

Definition at line 641 of file Map.cpp.

◆ sizePixels()

sf::Vector2f core::map::Map::sizePixels ( ) const

Returns the size of the map in pixels.

Definition at line 175 of file Map.cpp.

◆ sizeTiles()

const sf::Vector2i & core::map::Map::sizeTiles ( ) const

Returns the size of the map in tiles.

Definition at line 173 of file Map.cpp.

◆ triggerAnimation()

void core::map::Map::triggerAnimation ( const bl::tmap::Position &  position)
protected

Definition at line 439 of file Map.cpp.

◆ update()

void core::map::Map::update ( float  dt)

Updates internal logic over the elapsed time.

Parameters
dtElapsed time in seconds since last update

Definition at line 186 of file Map.cpp.

◆ weatherSystem()

Weather & core::map::Map::weatherSystem ( )

Returns a reference to the weather system in this map.

Definition at line 182 of file Map.cpp.

Friends And Related Function Documentation

◆ bl::serial::SerializableObject< Map >

friend struct bl::serial::SerializableObject< Map >
friend

Definition at line 344 of file Map.hpp.

Member Data Documentation

◆ activated

bool core::map::Map::activated
protected

Definition at line 326 of file Map.hpp.

◆ catchRegionsField

std::vector<CatchRegion> core::map::Map::catchRegionsField
protected

Definition at line 310 of file Map.hpp.

◆ characterField

std::vector<CharacterSpawn> core::map::Map::characterField
protected

Definition at line 306 of file Map.hpp.

◆ currentTown

Town* core::map::Map::currentTown
protected

Definition at line 317 of file Map.hpp.

◆ defaultTown

Town core::map::Map::defaultTown
protected

Definition at line 316 of file Map.hpp.

◆ eventRegions

bl::ctr::Grid<const Event*> core::map::Map::eventRegions
protected

Definition at line 323 of file Map.hpp.

◆ eventsField

std::vector<Event> core::map::Map::eventsField
protected

Definition at line 308 of file Map.hpp.

◆ flymapTowns

std::vector< Town > core::map::Map::flymapTowns
staticprotected

Definition at line 343 of file Map.hpp.

◆ isWorldMap

bool core::map::Map::isWorldMap
protected

Definition at line 324 of file Map.hpp.

◆ itemsField

std::vector<Item> core::map::Map::itemsField
protected

Definition at line 307 of file Map.hpp.

◆ levels

std::vector<LayerSet> core::map::Map::levels
protected

Definition at line 303 of file Map.hpp.

◆ lighting

LightingSystem core::map::Map::lighting
protected

Definition at line 309 of file Map.hpp.

◆ loadScriptField

std::string core::map::Map::loadScriptField
protected

Definition at line 299 of file Map.hpp.

◆ nameField

std::string core::map::Map::nameField
protected

Definition at line 298 of file Map.hpp.

◆ onEnterScript

std::unique_ptr<bl::script::Script> core::map::Map::onEnterScript
protected

Definition at line 321 of file Map.hpp.

◆ onExitScript

std::unique_ptr<bl::script::Script> core::map::Map::onExitScript
protected

Definition at line 322 of file Map.hpp.

◆ playlistField

std::string core::map::Map::playlistField
protected

Definition at line 301 of file Map.hpp.

◆ playlistHandle

bl::audio::AudioSystem::Handle core::map::Map::playlistHandle
protected

Definition at line 325 of file Map.hpp.

◆ renderLevels

std::list<RenderLevel> core::map::Map::renderLevels
protected

Definition at line 329 of file Map.hpp.

◆ scene

bl::rc::SceneRef core::map::Map::scene
protected

Definition at line 328 of file Map.hpp.

◆ size

sf::Vector2i core::map::Map::size
protected

Definition at line 318 of file Map.hpp.

◆ spawns

std::unordered_map<std::uint16_t, Spawn> core::map::Map::spawns
protected

Definition at line 305 of file Map.hpp.

◆ systems

system::Systems* core::map::Map::systems
protected

Definition at line 315 of file Map.hpp.

◆ tileset

bl::resource::Ref<Tileset> core::map::Map::tileset
protected

Definition at line 319 of file Map.hpp.

◆ tilesetField

std::string core::map::Map::tilesetField
protected

Definition at line 304 of file Map.hpp.

◆ towns

std::vector<Town> core::map::Map::towns
protected

Definition at line 312 of file Map.hpp.

◆ townTiles

bl::ctr::Vector2D<std::uint8_t> core::map::Map::townTiles
protected

Definition at line 313 of file Map.hpp.

◆ transitionField

bl::ctr::Vector2D<LevelTransition> core::map::Map::transitionField
protected

Definition at line 311 of file Map.hpp.

◆ unloadScriptField

std::string core::map::Map::unloadScriptField
protected

Definition at line 300 of file Map.hpp.

◆ weather

Weather core::map::Map::weather
protected

Definition at line 320 of file Map.hpp.

◆ weatherField

Weather::Type core::map::Map::weatherField
protected

Definition at line 302 of file Map.hpp.


The documentation for this class was generated from the following files: