1
0
forked from 0ad/0ad
0ad/source/simulation/Projectile.h
janwas c0ed950657 had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).

it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.

after several hours, the code now requires fewer casts and less
guesswork.

other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.

This was SVN commit r5942.
2008-05-11 18:48:32 +00:00

108 lines
3.2 KiB
C++

// Projectile.h
//
// Simple class that represents a single projectile in the simulation.
#ifndef INCLUDED_PROJECTILE
#define INCLUDED_PROJECTILE
#include "maths/Vector3D.h"
#include "ps/Vector2D.h"
#include "scripting/ScriptableObject.h"
#include "scripting/DOMEvent.h"
#include "ScriptObject.h"
#include "ps/Game.h"
#include "ps/World.h"
class CProjectileManager;
class CModel;
class CEntity;
class CProjectile : public CJSObject<CProjectile>, public IEventTarget
{
friend class CProjectileManager;
friend class CJSObject<CProjectile>;
CModel* m_Actor;
CVector3D m_Position;
CVector2D m_Axis;
CVector3D m_Position_Previous;
CVector3D m_Position_Graphics;
// Horizontal and vertical velocities
float m_Speed_H;
float m_Speed_V;
float m_Speed_V_Previous;
CEntity* m_Originator;
CScriptObject m_ImpactEventHandler;
CScriptObject m_MissEventHandler;
CProjectile( const CModel* Actor, const CVector3D& Position, const CVector3D& Target, float Speed, CEntity* Originator, const CScriptObject& ImpactScript, const CScriptObject& MissScript );
~CProjectile();
// Updates gameplay information for the specified timestep. Returns 'false' if the projectile should be removed from the world.
bool Update( int timestep_millis );
// Updates graphical information for a point timestep_millis after the previous simulation frame (and before the current one)
void Interpolate( int timestep_millis );
// Scripty things.
public:
static void ScriptingInit();
static JSBool Construct( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval );
JSObject* GetScriptExecContext( IEventTarget* UNUSED(target) ) { return( GetScript() ); }
inline CModel* GetModel() const { return( m_Actor ); }
};
class CEventProjectileImpact : public CScriptEvent
{
CEntity* m_Originator;
CEntity* m_Impact;
CVector3D m_Position;
public:
CEventProjectileImpact( CEntity* Originator, CEntity* Impact, const CVector3D& Position );
};
class CEventProjectileMiss : public CScriptEvent
{
CEntity* m_Originator;
CVector3D m_Position;
public:
CEventProjectileMiss( CEntity* Originator, const CVector3D& Position );
};
// TODO: Maybe roll this (or at least the graphics bit) into the particle system?
// Initially this had g_UnitMan managing the models and g_EntityManager holding the
// projectiles themselves. This way may be less confusing - I'm not sure.
class CProjectileManager
{
friend class CProjectile;
public:
CProjectileManager();
~CProjectileManager();
void DeleteAll();
void UpdateAll( int timestep );
void InterpolateAll( double frametime );
inline const std::list<CProjectile*>& GetProjectiles() { return m_Projectiles; }
CProjectile* AddProjectile( const CModel* Actor, const CVector3D& Position, const CVector3D& Target, float Speed, CEntity* Originator, const CScriptObject& ImpactScript, const CScriptObject& MissScript );
// Only if you have some reason to prematurely get rid of a projectile.
// Under normal circumstances, it will delete itself when it hits something.
void DeleteProjectile( CProjectile* p );
private:
// Keep this so we can go from relative->absolute offsets in interpolate.
int m_LastTurnLength;
// Maintain a list of the projectiles in the world
std::list<CProjectile*> m_Projectiles;
};
#endif