427 lines
12 KiB
C++
427 lines
12 KiB
C++
// Copyright (c) 2011-2024 Squall Line Software, LLC
|
|
// Distributed under the terms of the MIT License
|
|
// See accompanying LICENSE.txt file or
|
|
// http://www.opensource.org/licenses/mit-license.php
|
|
|
|
#ifndef DISORDER_ENTITY_APPEARANCE_HPP
|
|
#define DISORDER_ENTITY_APPEARANCE_HPP
|
|
|
|
#include <disorder/dso_api.hpp>
|
|
|
|
#include <disorder/siso/ref_010_bit_fields.hpp>
|
|
|
|
#include <cstdint>
|
|
|
|
namespace disorder
|
|
{
|
|
|
|
namespace entity
|
|
{
|
|
|
|
class Entity;
|
|
|
|
/**
|
|
* The Appearance class provides a more convenient mechanism for dealing with
|
|
* the appearance bits of an entity than dealing with the SISO generated
|
|
* bit fields directly.
|
|
*/
|
|
class DISORDER_DSO_PUBLIC Appearance
|
|
{
|
|
public:
|
|
/// the underlying rudimentary type of an appearance bit field
|
|
using Bits = uint32_t;
|
|
|
|
/// bit mask for the frozen bit within the appearance bits where 1 means
|
|
/// frozen and 0 means not frozen. This bit applies to all entity types.
|
|
static const Bits FROZEN_BIT_MASK;
|
|
|
|
/// bit mask for the deactivated bit within the appearance bits where 1
|
|
/// means deactivated and 0 means active. This bit applies to all entity
|
|
/// types.
|
|
static const Bits DEACTIVATED_BIT_MASK;
|
|
|
|
/// a good default value for a happy entity appearance (not deactivated or
|
|
/// frozen)
|
|
static const Bits DEFAULT;
|
|
|
|
/**
|
|
* BitFieldTracker is an extension of a templatized SISO bit field tracker
|
|
* that updates the actual appearance in an Entity with changes to the
|
|
* appearance made during the lifetime of this instance.
|
|
*/
|
|
template<typename SISOBitFieldTracker>
|
|
class BitFieldTracker: public SISOBitFieldTracker
|
|
{
|
|
public:
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @param entity pointer to the associated Entity or nullptr to not
|
|
* associate with an Entity
|
|
*/
|
|
BitFieldTracker(Entity* entity = nullptr):
|
|
entity_(entity)
|
|
{
|
|
this->bit_field_.all = entity_appearance(entity);
|
|
}
|
|
|
|
private:
|
|
/**
|
|
* pointer to the entity this instance is associated with. This field
|
|
* can be nullptr, in which case this appearance bit field is not
|
|
* associated with an entity.
|
|
*/
|
|
Entity* entity_;
|
|
|
|
void handle_change() override
|
|
{
|
|
entity_appearance(entity_, this->bit_field_.all);
|
|
}
|
|
};
|
|
|
|
/// shorthand for a land platform appearance bit field
|
|
using LandPlatform = BitFieldTracker<siso::tracker::LandPlatformAppearance>;
|
|
|
|
/// shorthand for a air platform appearance bit field
|
|
using AirPlatform = BitFieldTracker<siso::tracker::AirPlatformAppearance>;
|
|
|
|
/// shorthand for a surface platform appearance bit field
|
|
using SurfacePlatform =
|
|
BitFieldTracker<siso::tracker::SurfacePlatformAppearance>;
|
|
|
|
/// shorthand for a subsurface platform appearance bit field
|
|
using SubsurfacePlatform =
|
|
BitFieldTracker<siso::tracker::SubsurfacePlatformAppearance>;
|
|
|
|
/// shorthand for a space platform appearance bit field
|
|
using SpacePlatform =
|
|
BitFieldTracker<siso::tracker::SpacePlatformAppearance>;
|
|
|
|
/// shorthand for a munition appearance bit field
|
|
using Munition = BitFieldTracker<siso::tracker::MunitionAppearance>;
|
|
|
|
/// shorthand for a life form appearance bit field
|
|
using LifeForm = BitFieldTracker<siso::tracker::LifeFormAppearance>;
|
|
|
|
/// shorthand for an environmental appearance bit field
|
|
using Environmental =
|
|
BitFieldTracker<siso::tracker::EnvironmentalAppearance>;
|
|
|
|
/// shorthand for a cultural feature appearance bit field
|
|
using CulturalFeature =
|
|
BitFieldTracker<siso::tracker::CulturalFeatureAppearance>;
|
|
|
|
/// shorthand for a supply appearance bit field
|
|
using Supply = BitFieldTracker<siso::tracker::SupplyAppearance>;
|
|
|
|
/// shorthand for a radio appearance bit field
|
|
using Radio = BitFieldTracker<siso::tracker::RadioAppearance>;
|
|
|
|
/// shorthand for an expendable appearance bit field
|
|
using Expendable = BitFieldTracker<siso::tracker::ExpendableAppearance>;
|
|
|
|
/// shorthand for a sensor appearance bit field
|
|
using Sensor = BitFieldTracker<siso::tracker::SensorEmitterAppearance>;
|
|
|
|
/// shorthand for an emitter appearance bit field
|
|
using Emitter = BitFieldTracker<siso::tracker::SensorEmitterAppearance>;
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @param entity pointer to the entity this instance is associated with
|
|
* or nullptr to indicate that this instance is not
|
|
* associated with an entity
|
|
* @param bits reference to the actual entity appearance bits
|
|
*/
|
|
Appearance(Entity* entity, Bits& bits);
|
|
|
|
/**
|
|
* Constructor for creating a read-only instance of this class.
|
|
*
|
|
* @param entity pointer to the entity this instance is associated with
|
|
* or nullptr to indicate that this instance is not
|
|
* associated with an entity
|
|
* @param bits reference to the actual entity appearance bits
|
|
*/
|
|
Appearance(const Entity* entity, const Bits& bits);
|
|
|
|
/**
|
|
* This method returns a constant representation of the appearance
|
|
* bits for a land platform.
|
|
*
|
|
* @return constant land platform appearance
|
|
*/
|
|
const siso::LandPlatformAppearance& land_platform() const;
|
|
|
|
/**
|
|
* This method returns a manipulatable representation of the
|
|
* appearance bits for a land platform.
|
|
*
|
|
* @return manipulatable land platform appearance
|
|
*/
|
|
LandPlatform land_platform();
|
|
|
|
/**
|
|
* This method returns a constant representation of the appearance
|
|
* bits for a air platform.
|
|
*
|
|
* @return constant air platform appearance
|
|
*/
|
|
const siso::AirPlatformAppearance& air_platform() const;
|
|
|
|
/**
|
|
* This method returns a manipulatable representation of the
|
|
* appearance bits for a air platform.
|
|
*
|
|
* @return manipulatable air platform appearance
|
|
*/
|
|
AirPlatform air_platform();
|
|
|
|
/**
|
|
* This method returns a constant representation of the appearance
|
|
* bits for a surface platform.
|
|
*
|
|
* @return constant surface platform appearance
|
|
*/
|
|
const siso::SurfacePlatformAppearance& surface_platform() const;
|
|
|
|
/**
|
|
* This method returns a manipulatable representation of the
|
|
* appearance bits for a surface platform.
|
|
*
|
|
* @return manipulatable surface platform appearance
|
|
*/
|
|
SurfacePlatform surface_platform();
|
|
|
|
/**
|
|
* This method returns a constant representation of the appearance
|
|
* bits for a subsurface platform.
|
|
*
|
|
* @return constant subsurface platform appearance
|
|
*/
|
|
const siso::SubsurfacePlatformAppearance& subsurface_platform() const;
|
|
|
|
/**
|
|
* This method returns a manipulatable representation of the
|
|
* appearance bits for a subsurface platform.
|
|
*
|
|
* @return manipulatable subsurface platform appearance
|
|
*/
|
|
SubsurfacePlatform subsurface_platform();
|
|
|
|
/**
|
|
* This method returns a constant representation of the appearance
|
|
* bits for a space platform.
|
|
*
|
|
* @return constant space platform appearance
|
|
*/
|
|
const siso::SpacePlatformAppearance& space_platform() const;
|
|
|
|
/**
|
|
* This method returns a manipulatable representation of the
|
|
* appearance bits for a space platform.
|
|
*
|
|
* @return manipulatable space platform appearance
|
|
*/
|
|
SpacePlatform space_platform();
|
|
|
|
/**
|
|
* This method returns a constant representation of the appearance bits
|
|
* for a munition.
|
|
*
|
|
* @return constant munition appearance
|
|
*/
|
|
const siso::MunitionAppearance& munition() const;
|
|
|
|
/**
|
|
* This method returns a manipulatable representation of the appearance
|
|
* bits for a munition.
|
|
*
|
|
* @return manipulatable munition appearance
|
|
*/
|
|
Munition munition();
|
|
|
|
/**
|
|
* This method returns a constant representation of the appearance bits
|
|
* for a life form.
|
|
*
|
|
* @return constant life form appearance
|
|
*/
|
|
const siso::LifeFormAppearance& life_form() const;
|
|
|
|
/**
|
|
* This method returns a manipulatable representation of the appearance
|
|
* bits for a life form.
|
|
*
|
|
* @return manipulatable life form appearance
|
|
*/
|
|
LifeForm life_form();
|
|
|
|
/**
|
|
* This method returns a constant representation of the appearance bits
|
|
* for an environmental.
|
|
*
|
|
* @return constant environmental appearance
|
|
*/
|
|
const siso::EnvironmentalAppearance& environmental() const;
|
|
|
|
/**
|
|
* This method returns a manipulatable representation of the appearance
|
|
* bits for an environmental.
|
|
*
|
|
* @return manipulatable environmental appearance
|
|
*/
|
|
Environmental environmental();
|
|
|
|
/**
|
|
* This method returns a constant representation of the appearance bits
|
|
* for a cultural feature.
|
|
*
|
|
* @return constant cultural feature appearance
|
|
*/
|
|
const siso::CulturalFeatureAppearance& cultural_feature() const;
|
|
|
|
/**
|
|
* This method returns a manipulatable representation of the appearance
|
|
* bits for a cultural feature.
|
|
*
|
|
* @return manipulatable cultural feature appearance
|
|
*/
|
|
CulturalFeature cultural_feature();
|
|
|
|
/**
|
|
* This method returns a constant representation of the appearance bits
|
|
* for a supply.
|
|
*
|
|
* @return constant supply appearance
|
|
*/
|
|
const siso::SupplyAppearance& supply() const;
|
|
|
|
/**
|
|
* This method returns a manipulatable representation of the appearance
|
|
* bits for a supply.
|
|
*
|
|
* @return manipulatable supply appearance
|
|
*/
|
|
Supply supply();
|
|
|
|
/**
|
|
* This method returns a constant representation of the appearance bits
|
|
* for a radio.
|
|
*
|
|
* @return constant radio appearance
|
|
*/
|
|
const siso::RadioAppearance& radio() const;
|
|
|
|
/**
|
|
* This method returns a manipulatable representation of the appearance
|
|
* bits for a radio.
|
|
*
|
|
* @return manipulatable radio appearance
|
|
*/
|
|
Radio radio();
|
|
|
|
/**
|
|
* This method returns a constant representation of the appearance bits
|
|
* for an expendable.
|
|
*
|
|
* @return constant expendable appearance
|
|
*/
|
|
const siso::ExpendableAppearance& expendable() const;
|
|
|
|
/**
|
|
* This method returns a manipulatable representation of the appearance
|
|
* bits for an expendable.
|
|
*
|
|
* @return manipulatable expendable appearance
|
|
*/
|
|
Expendable expendable();
|
|
|
|
/**
|
|
* This method returns a constant representation of the appearance bits
|
|
* for a sensor.
|
|
*
|
|
* @return constant sensor appearance
|
|
*/
|
|
const siso::SensorEmitterAppearance& sensor() const;
|
|
|
|
/**
|
|
* This method returns a manipulatable representation of the appearance
|
|
* bits for a sensor.
|
|
*
|
|
* @return manipulatable sensor appearance
|
|
*/
|
|
Sensor sensor();
|
|
|
|
/**
|
|
* This method returns a constant representation of the appearance bits
|
|
* for a emitter.
|
|
*
|
|
* @return constant emitter appearance
|
|
*/
|
|
const siso::SensorEmitterAppearance& emitter() const { return sensor(); }
|
|
|
|
/**
|
|
* This method returns a manipulatable representation of the appearance
|
|
* bits for a emitter.
|
|
*
|
|
* @return manipulatable emitter appearance
|
|
*/
|
|
Emitter emitter() { return sensor(); }
|
|
|
|
/**
|
|
* This method determines whether or not the entity is frozen.
|
|
*
|
|
* A frozen simulation entity does not move and only responds to Simulation
|
|
* Management PDUs.
|
|
*
|
|
* @return true if the entity is frozen, false otherwise
|
|
*/
|
|
bool frozen() const;
|
|
|
|
/**
|
|
* This method freezes or thaws an entity.
|
|
*
|
|
* @param freeze true to freeze the entity, false to thaw it
|
|
*/
|
|
void freeze(bool freeze);
|
|
|
|
private:
|
|
/**
|
|
* pointer to the entity this instance is associated with. This field can
|
|
* be nullptr, in which case this appearance record is not associated with
|
|
* an entity.
|
|
*/
|
|
Entity* entity_;
|
|
|
|
const Bits* ENTITY_APPEARANCE_BITS_;
|
|
|
|
/**
|
|
* This method provides a way for the templatized BitFieldTracker to get
|
|
* the appearance in an Entity without needing a full definition of the
|
|
* Entity type in the appearance.hpp header file.
|
|
*
|
|
* @param entity pointer to the Entity to update the appearance of
|
|
* @return current appearance of the specified entity or 0 if entity is
|
|
* nullptr
|
|
*/
|
|
static Bits entity_appearance(const Entity* entity);
|
|
|
|
/**
|
|
* This method provides a way for the templatized BitFieldTracker to update
|
|
* the appearance in an Entity without needing a full definition of the
|
|
* Entity type in the appearance.hpp header file.
|
|
*
|
|
* @param entity pointer to the Entity to update the appearance of
|
|
* @param appearance desired appearance value
|
|
*/
|
|
static void entity_appearance(Entity* entity, Bits appearance);
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|