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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
/* bzflag
* Copyright (c) 1993-2025 Tim Riker
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the license found in the file
* named COPYING that should have accompanied this file.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef BZF_OBSTACLE_MGR_H
#define BZF_OBSTACLE_MGR_H
#include "common.h"
// system headers
#include <string>
#include <vector>
#include <iostream>
// common headers
#include "ObstacleList.h"
#include "MeshTransform.h"
#include "BzMaterial.h"
// avoid nasty dependencies
class Obstacle;
class BoxBuilding;
class PyramidBuilding;
class BaseBuilding;
class Teleporter;
class MeshObstacle;
class ArcObstacle;
class ConeObstacle;
class SphereObstacle;
class TetraBuilding;
class ObstacleModifier;
//
// Group Instance
// - uses a group definition and a transform to produce obstacles
//
class GroupInstance
{
friend class ObstacleModifier;
public:
GroupInstance(const std::string& groupdef);
GroupInstance();
~GroupInstance();
void init();
void setName(const std::string& name);
void setTeam(int team);
void setTint(const float tint[4]);
void setPhysicsDriver(int phydrv);
void setTransform(const MeshTransform&);
void setMaterial(const BzMaterial*);
void setDriveThrough();
void setShootThrough();
void setCanRicochet();
void addMaterialSwap(const BzMaterial* src,
const BzMaterial* dst);
const std::string& getName() const;
const std::string& getGroupDef() const;
const MeshTransform& getTransform() const;
void *pack(void*);
const void *unpack(const void*);
int packSize();
void print(std::ostream& out, const std::string& indent) const;
private:
std::string groupdef;
std::string name;
MeshTransform transform;
bool modifyTeam;
int team;
bool modifyColor;
float tint[4];
bool modifyPhysicsDriver;
int phydrv;
bool modifyMaterial;
const BzMaterial* material;
bool driveThrough;
bool shootThrough;
bool ricochet;
MaterialMap matMap;
};
//
// Group Definition
// - defines an obstacle group
//
class GroupDefinition
{
public:
GroupDefinition(const std::string& name);
~GroupDefinition();
enum ObstacleTypes
{
wallType = 0,
boxType,
pyrType,
baseType,
teleType,
meshType,
arcType,
coneType,
sphereType,
tetraType,
ObstacleTypeCount
};
void addObstacle(Obstacle* obstacle);
void addGroupInstance(GroupInstance* group);
void clear(); // delete the list and the obstacles
void tighten(); // reduce memory usage
void sort(int (*compare)(const void* a, const void* b));
void makeGroups(const MeshTransform& xform,
const ObstacleModifier& obsMod) const;
void replaceBasesWithBoxes();
void deleteInvalidObstacles();
const std::string& getName() const;
const ObstacleList& getList(int type) const;
const std::vector<GroupInstance*>& getGroups() const;
// Get the list of meshes that came from the world file.
// This includes the meshes in group definitions, even if
// they have never been instantiated.
void getSourceMeshes(std::vector<MeshObstacle*>& meshes) const;
int packSize() const;
void *pack(void*) const;
const void *unpack(const void*);
void printGrouped(std::ostream& out, const std::string& indent) const;
void printFlatFile(std::ostream& out, const std::string& indent) const;
public:
static void clearDepthName();
private:
Obstacle* newObstacle(int type);
void makeTeleName(Obstacle* obs, unsigned int pos) const;
void appendGroupName(const GroupInstance* group) const;
private:
std::string name;
ObstacleList lists[ObstacleTypeCount];
std::vector<GroupInstance*> groups;
mutable bool active; // for recursion checking
private:
static std::string depthName;
};
inline const std::string& GroupDefinition::getName() const
{
return name;
}
inline const ObstacleList& GroupDefinition::getList(int type) const
{
return lists[type];
}
inline const std::vector<GroupInstance*>& GroupDefinition::getGroups() const
{
return groups;
}
//
// Group Definition Manager
// - utility class to keep track of group definitions
//
class GroupDefinitionMgr
{
public:
GroupDefinitionMgr();
~GroupDefinitionMgr();
void clear(); // delete the lists and the obstacles
void tighten(); // reduce memory usage
void makeWorld(); // make the local obstacles for the groups
void replaceBasesWithBoxes();
void addWorldObstacle(Obstacle* obstacle);
void addGroupDef(GroupDefinition* groupdef);
GroupDefinition* findGroupDef(const std::string& name) const;
// Get the list of meshes that came from the world file.
// This includes the meshes in group definitions, even if
// they have never been instantiated.
void getSourceMeshes(std::vector<MeshObstacle*>& meshes) const;
const GroupDefinition* getWorld() const;
// convenience functions
const ObstacleList& getWalls() const;
const ObstacleList& getBoxes() const;
const ObstacleList& getPyrs() const;
const ObstacleList& getBases() const;
const ObstacleList& getTeles() const;
const ObstacleList& getMeshes() const;
const ObstacleList& getArcs() const;
const ObstacleList& getCones() const;
const ObstacleList& getSpheres() const;
const ObstacleList& getTetras() const;
int packSize() const;
void *pack(void*) const;
const void *unpack(const void*);
void print(std::ostream& out, const std::string& indent) const;
private:
GroupDefinition world;
std::vector<GroupDefinition*> list;
};
inline const GroupDefinition* GroupDefinitionMgr::getWorld() const
{
return &world;
}
inline const ObstacleList& GroupDefinitionMgr::getWalls() const
{
return world.getList(GroupDefinition::wallType);
}
inline const ObstacleList& GroupDefinitionMgr::getBoxes() const
{
return world.getList(GroupDefinition::boxType);
}
inline const ObstacleList& GroupDefinitionMgr::getPyrs() const
{
return world.getList(GroupDefinition::pyrType);
}
inline const ObstacleList& GroupDefinitionMgr::getBases() const
{
return world.getList(GroupDefinition::baseType);
}
inline const ObstacleList& GroupDefinitionMgr::getTeles() const
{
return world.getList(GroupDefinition::teleType);
}
inline const ObstacleList& GroupDefinitionMgr::getMeshes() const
{
return world.getList(GroupDefinition::meshType);
}
inline const ObstacleList& GroupDefinitionMgr::getArcs() const
{
return world.getList(GroupDefinition::arcType);
}
inline const ObstacleList& GroupDefinitionMgr::getCones() const
{
return world.getList(GroupDefinition::coneType);
}
inline const ObstacleList& GroupDefinitionMgr::getSpheres() const
{
return world.getList(GroupDefinition::sphereType);
}
inline const ObstacleList& GroupDefinitionMgr::getTetras() const
{
return world.getList(GroupDefinition::tetraType);
}
extern GroupDefinitionMgr OBSTACLEMGR;
#endif // BZF_OBSTACLE_MGR_H
// Local Variables: ***
// mode: C++ ***
// tab-width: 4 ***
// c-basic-offset: 4 ***
// indent-tabs-mode: nil ***
// End: ***
// ex: shiftwidth=4 tabstop=4
|