#include "gameCommon.h" #include "util.h" #include "PID.h" #ifndef ENTITY_H #define ENTITY_H enum { ENTITY_NONE = -1, ENTITY_ANTIFA, ENTITY_SOLDATO, ENTITY_CAPORALE, ENTITY_SERGENTE, ENTITY_MARESCIALLO, ENTITY_GENERALE, ENTITY_MUSSOLINI }; #define ENTITY_TYPE_COUNT 7 typedef int8_t EntityType; typedef int16_t EntityId; // Id in world. typedef uint32_t EntityFingerprint; // Callbacks. typedef void (*EntityUpdateCb)(Game * game, Entity * entity); typedef void (*EntityDrawCb)(Game * game, Entity * entity); // Acceleration indeed hehehe. typedef struct EntityAcceleration { Vector3 rotation; float speedUp; float speedDown; } EntityAcceleration; float accelerateValue(float value, float lastValue, float up, float down); Vector3 accelerateVector3(Vector3 value, Vector3 lastValue, Vector3 up, Vector3 down); typedef struct EntityVelocity { Vector3 velocity; AxisAngle angularVelocity; Vector3 stick; // Pilot control stick. float speed; // Somewhat general use (: } EntityVelocity; EntityVelocity entityVelocityIdentity(); // This fucker is a entity. typedef struct Entity { EntityId id; EntityFingerprint fingerprint; EntityType type; Model * model; Vector3 position; Quaternion rotation; EntityVelocity velocity; EntityVelocity lastVelocity; bool useAcceleration; EntityAcceleration acceleration; EntityUpdateCb updateCb; EntityDrawCb drawCb; // Health is a percent from 1.0 to 0.0. float health; // Used for whatever. void * data; } Entity; typedef void (*EntityInitCb)(Entity * entity, Game * game); typedef void (*EntityCloseCb)(Entity * entity); // Info for each entity type. typedef struct EntityTypeInfo { EntityInitCb initCb; EntityCloseCb closeCb; EntityUpdateCb updateCb; EntityDrawCb drawCb; } EntityTypeInfo; const extern EntityTypeInfo entityTypeInfo[ENTITY_TYPE_COUNT]; // Do I need a fucking comment? Entity createEntity(EntityType type, Game * game); void closeEntity(Entity * entity); // Helper functions for updating and drawing. void entityDraw(Entity * entity); void entityUpdatePosition(Entity * entity); void entityUpdateRotation(Entity * entity); void entityJoystickControl(Entity * entity, Vector3 stick, float speed); enum { ENTITY_FLY_TO_POINT_PID, ENTITY_FLY_TO_POINT_BANG_BANG }; // Shit for fly to point. typedef struct EntityFlyToPointInfo { union { PID speedPID; struct { float speed; float stopAt; } bangbang; } controller; uint8_t controlType; float rotationSpeed; // 0.0 to not use. } EntityFlyToPointInfo; void entityFlyToPoint(Entity * entity, Vector3 point, EntityFlyToPointInfo * info); #endif