1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef EVENT_BATCH_HANDLER_HDR
#define EVENT_BATCH_HANDLER_HDR
#include "lib/gml/ThreadSafeContainers.h"
#include "Sim/Projectiles/ProjectileHandler.h" // for UNSYNCED_PROJ_NOEVENT
class CUnit;
class CFeature;
class CProjectile;
struct EventBatchHandler {
private:
struct ProjectileCreatedDestroyedEvent {
static void Add(const CProjectile*);
static void Remove(const CProjectile*);
static void Delete(const CProjectile*);
};
typedef ThreadListRender<
const CProjectile*,
std::set<const CProjectile*>,
const CProjectile*,
ProjectileCreatedDestroyedEvent
> ProjectileCreatedDestroyedEventBatch;
#if UNSYNCED_PROJ_NOEVENT
struct UnsyncedProjectileCreatedDestroyedEvent {
static void Add(const CProjectile*);
static void Remove(const CProjectile*);
static void Delete(const CProjectile*);
};
typedef ThreadListRender<
const CProjectile*,
std::set<const CProjectile*>,
const CProjectile*,
UnsyncedProjectileCreatedDestroyedEvent
> UnsyncedProjectileCreatedDestroyedEventBatch;
#endif
struct UAD {
const CUnit* unit;
int data;
int status;
UAD(const CUnit* u, int d): unit(u), data(d), status(0) {}
UAD(const CUnit* u, int d, int s): unit(u), data(d), status(s) {}
bool operator==(const CUnit* u) const { return unit == u; }
bool operator==(const UAD& u) const { return unit == u.unit && data == u.data && status == u.status; }
bool operator<(const UAD& u) const { return unit < u.unit || (unit == u.unit && (data < u.data || (data == u.data && status < u.status))); }
};
public:
struct UD {
const CUnit* unit;
int data;
UD(const CUnit* u): unit(u), data(0) {}
UD(const CUnit* u, int d): unit(u), data(d) {}
bool operator==(const UD& u) const { return unit == u.unit; }
bool operator<(const UD& u) const { return unit < u.unit; }
};
private:
struct UnitCreatedDestroyedEvent {
static void Add(const UD&);
static void Remove(const UD&);
static void Delete(const UD&) { }
};
struct UnitCloakStateChangedEvent {
static void Add(const UAD&);
static void Remove(const UAD&) { }
static void Delete(const UAD&) { }
};
struct UnitLOSStateChangedEvent {
static void Add(const UAD&);
static void Remove(const UAD&) { }
static void Delete(const UAD&) { }
};
typedef ThreadListRender<const CUnit *, std::set<UD>, UD, UnitCreatedDestroyedEvent> UnitCreatedDestroyedEventBatch;
typedef ThreadListRender<const CUnit *, std::set<UAD>, UAD, UnitCloakStateChangedEvent> UnitCloakStateChangedEventBatch;
typedef ThreadListRender<const CUnit *, std::set<UAD>, UAD, UnitLOSStateChangedEvent> UnitLOSStateChangedEventBatch;
struct FeatureCreatedDestroyedEvent {
static void Add(const CFeature*);
static void Remove(const CFeature*);
static void Delete(const CFeature*) { }
};
struct FeatureMovedEvent {
static void Add(const CFeature*);
static void Remove(const CFeature*) { }
static void Delete(const CFeature*) { }
};
typedef ThreadListRender<
const CFeature*,
std::set<const CFeature*>,
const CFeature*,
FeatureCreatedDestroyedEvent
> FeatureCreatedDestroyedEventBatch;
typedef ThreadListRender<
const CFeature*,
std::set<const CFeature*>,
const CFeature*,
FeatureMovedEvent
> FeatureMovedEventBatch;
//! contains only projectiles that can change simulation state
ProjectileCreatedDestroyedEventBatch syncedProjectileCreatedDestroyedEventBatch;
#if UNSYNCED_PROJ_NOEVENT
static UnsyncedProjectileCreatedDestroyedEventBatch
#else
ProjectileCreatedDestroyedEventBatch
#endif
//! contains only projectiles that cannot change simulation state
unsyncedProjectileCreatedDestroyedEventBatch;
UnitCreatedDestroyedEventBatch unitCreatedDestroyedEventBatch;
UnitCloakStateChangedEventBatch unitCloakStateChangedEventBatch;
UnitLOSStateChangedEventBatch unitLOSStateChangedEventBatch;
FeatureCreatedDestroyedEventBatch featureCreatedDestroyedEventBatch;
FeatureMovedEventBatch featureMovedEventBatch;
public:
static EventBatchHandler* GetInstance();
void UpdateUnits();
void UpdateDrawUnits();
void DeleteSyncedUnits();
void UpdateFeatures();
void UpdateDrawFeatures();
void DeleteSyncedFeatures();
void UpdateProjectiles();
void UpdateDrawProjectiles();
void DeleteSyncedProjectiles();
void UpdateObjects();
void LoadedModelRequested();
void EnqueueUnitLOSStateChangeEvent(const CUnit* unit, int allyteam, int newstatus) { unitLOSStateChangedEventBatch.enqueue(UAD(unit, allyteam, newstatus)); }
void EnqueueUnitCloakStateChangeEvent(const CUnit* unit, int cloaked) { unitCloakStateChangedEventBatch.enqueue(UAD(unit, cloaked)); }
ProjectileCreatedDestroyedEventBatch& GetSyncedProjectileCreatedDestroyedBatch() { return syncedProjectileCreatedDestroyedEventBatch; }
#if UNSYNCED_PROJ_NOEVENT
static inline UnsyncedProjectileCreatedDestroyedEventBatch&
#else
ProjectileCreatedDestroyedEventBatch&
#endif
GetUnsyncedProjectileCreatedDestroyedBatch() { return unsyncedProjectileCreatedDestroyedEventBatch; }
UnitCreatedDestroyedEventBatch& GetUnitCreatedDestroyedBatch() { return unitCreatedDestroyedEventBatch; }
UnitCloakStateChangedEventBatch& GetUnitCloakStateChangedBatch() { return unitCloakStateChangedEventBatch; }
UnitLOSStateChangedEventBatch& GetUnitLOSStateChangedBatch() { return unitLOSStateChangedEventBatch; }
FeatureCreatedDestroyedEventBatch& GetFeatureCreatedDestroyedEventBatch() { return featureCreatedDestroyedEventBatch; }
FeatureMovedEventBatch& GetFeatureMovedEventBatch() { return featureMovedEventBatch; }
};
#define eventBatchHandler (EventBatchHandler::GetInstance())
#endif
|