DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

BrittleFracture.h (5260B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code.  If not, please request a copy in writing from id Software at the address below.
     23 
     24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
     25 
     26 ===========================================================================
     27 */
     28 
     29 #ifndef __GAME_BRITTLEFRACTURE_H__
     30 #define __GAME_BRITTLEFRACTURE_H__
     31 
     32 
     33 /*
     34 ===============================================================================
     35 
     36 B-rep Brittle Fracture - Static entity using the boundary representation
     37 of the render model which can fracture.
     38 
     39 ===============================================================================
     40 */
     41 
     42 typedef struct shard_s {
     43 	idClipModel *				clipModel;
     44 	idFixedWinding				winding;
     45 	idList<idFixedWinding *, TAG_PHYSICS_BRITTLE>	decals;
     46 	idList<bool>				edgeHasNeighbour;
     47 	idList<struct shard_s *, TAG_PHYSICS_BRITTLE>	neighbours;
     48 	idPhysics_RigidBody			physicsObj;
     49 	int							droppedTime;
     50 	bool						atEdge;
     51 	int							islandNum;
     52 } shard_t;
     53 
     54 
     55 class idBrittleFracture : public idEntity {
     56 
     57 public:
     58 	CLASS_PROTOTYPE( idBrittleFracture );
     59 
     60 								idBrittleFracture();
     61 	virtual						~idBrittleFracture();
     62 
     63 	void						Save( idSaveGame *savefile ) const;
     64 	void						Restore( idRestoreGame *savefile );
     65 
     66 	void						Spawn();
     67 
     68 	virtual void				Present();
     69 	virtual void				Think();
     70 	virtual void				ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse );
     71 	virtual void				AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force );
     72 	virtual void				AddDamageEffect( const trace_t &collision, const idVec3 &velocity, const char *damageDefName );
     73 	virtual void				Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
     74 
     75 	void						ProjectDecal( const idVec3 &point, const idVec3 &dir, const int time, const char *damageDefName );
     76 	bool						IsBroken() const;
     77 
     78 	enum {
     79 		EVENT_PROJECT_DECAL = idEntity::EVENT_MAXEVENTS,
     80 		EVENT_SHATTER,
     81 		EVENT_MAXEVENTS
     82 	};
     83 
     84 	virtual void				ClientThink( const int curTime, const float fraction, const bool predict );
     85 	virtual void				ClientPredictionThink();
     86 	virtual bool				ClientReceiveEvent( int event, int time, const idBitMsg &msg );
     87 
     88 private:
     89 	// setttings
     90 	const idMaterial *			material;
     91 	const idMaterial *			decalMaterial;
     92 	float						decalSize;
     93 	float						maxShardArea;
     94 	float						maxShatterRadius;
     95 	float						minShatterRadius;
     96 	float						linearVelocityScale;
     97 	float						angularVelocityScale;
     98 	float						shardMass;
     99 	float						density;
    100 	float						friction;
    101 	float						bouncyness;
    102 	idStr						fxFracture;
    103 
    104 	struct fractureEvent_s {
    105 		int				eventType;
    106 		idVec3			point;
    107 		idVec3			vector;
    108 	};
    109 	idList<fractureEvent_s>		storedEvents;
    110 	bool						processStoredEvents;
    111 	idRenderModel *				defaultRenderModel;
    112 	bool						isXraySurface;
    113 
    114 	// state
    115 	idPhysics_StaticMulti		physicsObj;
    116 	idList<shard_t *, TAG_PHYSICS_BRITTLE>	shards;
    117 	idBounds					bounds;
    118 	bool						disableFracture;
    119 
    120 	// for rendering
    121 	mutable int					lastRenderEntityUpdate;
    122 	mutable bool				changed;
    123 
    124 	bool						UpdateRenderEntity( renderEntity_s *renderEntity, const renderView_t *renderView ) const;
    125 	static bool					ModelCallback( renderEntity_s *renderEntity, const renderView_t *renderView );
    126 
    127 	void						AddShard( idClipModel *clipModel, idFixedWinding &w );
    128 	void						RemoveShard( int index );
    129 	void						DropShard( shard_t *shard, const idVec3 &point, const idVec3 &dir, const float impulse, const int time );
    130 	void						Shatter( const idVec3 &point, const idVec3 &impulse, const int time );
    131 	void						DropFloatingIslands( const idVec3 &point, const idVec3 &impulse, const int time );
    132 	void						Break();
    133 	void						Fracture_r( idFixedWinding &w, idRandom2 & random );
    134 	void						CreateFractures( const idRenderModel *renderModel );
    135 	void						FindNeighbours();
    136 
    137 	void						Event_Activate( idEntity *activator );
    138 	void						Event_Touch( idEntity *other, trace_t *trace );
    139 };
    140 
    141 #endif /* !__GAME_BRITTLEFRACTURE_H__ */