SuperTuxKart
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ItemManager Class Reference
Inheritance diagram for ItemManager:
Inheritance graph
[legend]

Public Member Functions

 ItemManager ()
 Creates a new instance of the item manager.
 
virtual ~ItemManager ()
 Destructor.
 
virtual ItemplaceItem (ItemState::ItemType type, const Vec3 &xyz, const Vec3 &normal)
 Places a new item on the track/arena.
 
virtual ItemdropNewItem (ItemState::ItemType type, const AbstractKart *parent, const Vec3 *server_xyz=NULL, const Vec3 *normal=NULL)
 Creates a new item at the location of the kart (e.g.
 
void update (int ticks)
 Updates all items, and handles switching items back if the switch time is over.
 
void updateGraphics (float dt)
 Updates the graphics, called once per rendered frame.
 
void checkItemHit (AbstractKart *kart)
 Checks if any item was collected by the given kart.
 
void reset ()
 Resets all items and removes bubble gum that is stuck on the track.
 
virtual void collectedItem (ItemState *item, AbstractKart *kart)
 Set an item as collected.
 
virtual void switchItems ()
 Switches all items: boxes become bananas and vice versa for a certain amount of time (as defined in stk_config.xml).
 
bool randomItemsForArena (const AlignedArray< btTransform > &pos)
 
bool areItemsSwitched ()
 Returns true if the items are switched atm.
 
virtual void setItemConfirmationTime (std::weak_ptr< STKPeer > peer, int ticks)
 Only used in the NetworkItemManager.
 
unsigned int getNumberOfItems () const
 Returns the number of items.
 
const ItemStategetItem (unsigned int n) const
 Returns a pointer to the n-th item.
 
ItemStategetItem (unsigned int n)
 Returns a pointer to the n-th item.
 
bool itemExists (const ItemState *is) const
 
const AllItemTypesgetItemsInQuads (unsigned int n) const
 Returns a reference to the array of all items on the specified quad.
 
ItemgetFirstItemInQuad (unsigned int n) const
 Returns the first item (NULL if none) on the specified quad.
 
unsigned int insertItem (Item *item)
 Inserts the new item into the items management data structures, if possible reusing an existing, unused entry (e.g.
 

Static Public Member Functions

static void loadDefaultItemMeshes ()
 Loads the default item meshes (high- and low-resolution).
 
static void removeTextures ()
 Clean up all textures.
 
static void updateRandomSeed (uint32_t seed_number)
 
static uint32_t getRandomSeed ()
 
static void disableItemCollection ()
 Disable item collection, useful to test client mispreditions or client/server disagreements.
 
static scene::IMesh * getItemModel (ItemState::ItemType type)
 Returns the mesh for a certain item.
 
static scene::IMesh * getItemLowResolutionModel (ItemState::ItemType type)
 Returns the low resolution mesh for a certain item.
 
static std::string getIcon (ItemState::ItemType type)
 Returns the mesh for a certain item.
 
static video::SColorf & getGlowColor (ItemState::ItemType type)
 Returns the glow color for an item.
 

Protected Types

typedef std::vector< ItemState * > AllItemTypes
 The vector of all items of the current track.
 

Protected Member Functions

void deleteItem (ItemState *item)
 Removes an items from the items-in-quad list, from the list of all items, and then frees the item itself.
 
void switchItemsInternal (std::vector< ItemState * > &all_items)
 Switches all items: boxes become bananas and vice versa for a certain amount of time (as defined in stk_config.xml).
 
void setSwitchItems (const std::vector< int > &switch_items)
 Sets which objects is getting switched to what.
 
void insertItemInQuad (Item *item)
 Insert into the appropriate quad list, if there is a quad list (i.e.
 
void deleteItemInQuad (ItemState *item)
 Removes an items from the items-in-quad list only.
 

Protected Attributes

AllItemTypes m_all_items
 
std::vector< ItemState::ItemTypem_switch_to
 What item this item is switched to.
 
int m_switch_ticks
 Remaining time that items should remain switched.
 

Static Private Member Functions

static bool preloadIcon (const std::string &name)
 Preload icon materials to avoid hangs when firstly insert item.
 

Private Attributes

std::vector< AllItemTypes > * m_items_in_quads
 Stores which items are on which quad.
 

Static Private Attributes

static std::vector< video::SColorf > m_glow_color
 Stores the glow color for all items.
 
static bool m_disable_item_collection = false
 Disable item collection (for debugging purposes).
 
static std::mt19937 m_random_engine
 
static uint32_t m_random_seed = 0
 
static std::vector< scene::IMesh * > m_item_mesh
 Stores all item models.
 
static std::vector< scene::IMesh * > m_item_lowres_mesh
 Stores all low-resolution item models.
 
static std::vector< std::string > m_icon
 Stores all item models.
 

Constructor & Destructor Documentation

◆ ItemManager()

ItemManager::ItemManager ( )

Creates a new instance of the item manager.

This is done at startup of each race.

◆ ~ItemManager()

ItemManager::~ItemManager ( )
virtual

Destructor.

Cleans up all items and meshes stored.

Member Function Documentation

◆ checkItemHit()

void ItemManager::checkItemHit ( AbstractKart kart)

Checks if any item was collected by the given kart.

This function calls collectedItem if an item was collected.

Parameters
kartPointer to the kart.

Disable item collection detection for debug purposes.

◆ collectedItem()

void ItemManager::collectedItem ( ItemState item,
AbstractKart kart 
)
virtual

Set an item as collected.

This function is called on the server when an item is collected, or on the client upon receiving information about collected items.

Parameters
itemThe item that was collected.
kartThe kart that collected the item.

Reimplemented in NetworkItemManager.

◆ deleteItem()

void ItemManager::deleteItem ( ItemState item)
protected

Removes an items from the items-in-quad list, from the list of all items, and then frees the item itself.

Parameters
Theitem to delete.

◆ deleteItemInQuad()

void ItemManager::deleteItemInQuad ( ItemState item)
protected

Removes an items from the items-in-quad list only.

Parameters
Theitem to delete.

◆ dropNewItem()

Item * ItemManager::dropNewItem ( ItemState::ItemType  type,
const AbstractKart kart,
const Vec3 server_xyz = NULL,
const Vec3 server_normal = NULL 
)
virtual

Creates a new item at the location of the kart (e.g.

kart drops a bubblegum).

Parameters
typeType of the item.
kartThe kart that drops the new item.
server_xyzCan be used to overwrite the item location.
server_normalThe normal as seen on the server.

Reimplemented in NetworkItemManager.

◆ insertItem()

unsigned int ItemManager::insertItem ( Item item)

Inserts the new item into the items management data structures, if possible reusing an existing, unused entry (e.g.

due to a removed bubble gum). Then the item is also added to the quad-wise list of items.

Parameters
itemThe item to be added.
Returns
Index of the newly added item in the list of all items.

◆ insertItemInQuad()

void ItemManager::insertItemInQuad ( Item item)
protected

Insert into the appropriate quad list, if there is a quad list (i.e.

race mode has a quad graph).

◆ placeItem()

Item * ItemManager::placeItem ( ItemState::ItemType  type,
const Vec3 xyz,
const Vec3 normal 
)
virtual

Places a new item on the track/arena.

It is used for the initial placement of the items - either according to the scene.xml file, or random item placement.

Parameters
typeType of the item.
xyzPosition of the item.
normalThe normal of the terrain to set roll and pitch.

◆ removeTextures()

void ItemManager::removeTextures ( )
static

Clean up all textures.

This is necessary when switching resolution etc.

◆ reset()

void ItemManager::reset ( )

Resets all items and removes bubble gum that is stuck on the track.

This is done when a race is (re)started.

◆ setItemConfirmationTime()

virtual void ItemManager::setItemConfirmationTime ( std::weak_ptr< STKPeer peer,
int  ticks 
)
inlinevirtual

Only used in the NetworkItemManager.

Reimplemented in NetworkItemManager.

◆ setSwitchItems()

void ItemManager::setSwitchItems ( const std::vector< int > &  switch_items)
protected

Sets which objects is getting switched to what.

Parameters
switchA mapping of items types to item types for the mapping. must contain one entry for each item.

◆ switchItems()

void ItemManager::switchItems ( )
virtual

Switches all items: boxes become bananas and vice versa for a certain amount of time (as defined in stk_config.xml).

Reimplemented in NetworkItemManager.

◆ update()

void ItemManager::update ( int  ticks)

Updates all items, and handles switching items back if the switch time is over.

Parameters
ticksNumber of physics time steps - should be 1.

◆ updateGraphics()

void ItemManager::updateGraphics ( float  dt)

Updates the graphics, called once per rendered frame.

Parameters
dtTime based on frame rate.

Member Data Documentation

◆ m_items_in_quads

std::vector< AllItemTypes >* ItemManager::m_items_in_quads
private

Stores which items are on which quad.

m_items_in_quads[#quads] contains all items that are not on a quad. Note that this field is undefined if no Graph exist, e.g. arena without navmesh.

◆ m_switch_ticks

int ItemManager::m_switch_ticks
protected

Remaining time that items should remain switched.

If the value is <0, it indicates that the items are not switched atm.


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