NSEntity: New method CreatedByMap(). Additional work towards more vehicle related
code in preparation for WASTES.
This commit is contained in:
parent
9a6897c433
commit
a8c8938408
11 changed files with 148 additions and 35 deletions
|
@ -183,6 +183,7 @@ Entities_ParseLump(void)
|
|||
/* check if our classname has a matching class */
|
||||
if (isfunction(strcat("spawnfunc_", strValue))) {
|
||||
self = eEnt;
|
||||
self._mapspawned = true;
|
||||
callfunction(strcat("spawnfunc_", strValue));
|
||||
self = eOld;
|
||||
iClass = TRUE;
|
||||
|
|
|
@ -286,7 +286,7 @@ CSQC_UpdateView(float w, float h, float focus)
|
|||
if (!Client_IsSpectator(pl)) {
|
||||
setproperty(VF_ORIGIN, pSeat->m_vecPredictedOrigin + pl.view_ofs);
|
||||
|
||||
if (pl.flags & FL_INVEHICLE) {
|
||||
if (pl.vehicle) {
|
||||
NSVehicle veh = (NSVehicle)pl.vehicle;
|
||||
|
||||
if (veh.UpdateView)
|
||||
|
|
|
@ -74,4 +74,6 @@ enumflags
|
|||
#else
|
||||
BASEFL_CHANGED_ALPHA,
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
.bool _mapspawned;
|
||||
|
|
|
@ -144,6 +144,7 @@ class NSEntity:NSTrigger
|
|||
nonvirtual entity(void) GetGroundEntity;
|
||||
virtual void(entity) Blocked;
|
||||
nonvirtual void(void) BlockedHandler;
|
||||
nonvirtual bool(void) CreatedByMap;
|
||||
|
||||
virtual void(entity) StartTouch;
|
||||
virtual void(entity) Touch;
|
||||
|
|
|
@ -160,6 +160,12 @@ NSEntity::GetGroundEntity(void)
|
|||
return groundentity;
|
||||
}
|
||||
|
||||
bool
|
||||
NSEntity::CreatedByMap(void)
|
||||
{
|
||||
return _mapspawned;
|
||||
}
|
||||
|
||||
void
|
||||
NSEntity::Blocked(entity eBlocker)
|
||||
{
|
||||
|
@ -826,6 +832,7 @@ NSEntity::Save(float handle)
|
|||
SaveFloat(handle, "health", health);
|
||||
SaveString(handle, "parentname", m_parent);
|
||||
SaveFloat(handle, "pvsflags", pvsflags);
|
||||
SaveFloat(handle, "_mapspawned", _mapspawned);
|
||||
super::Save(handle);
|
||||
}
|
||||
void
|
||||
|
@ -877,6 +884,9 @@ NSEntity::Restore(string strKey, string strValue)
|
|||
case "pvsflags":
|
||||
pvsflags = stof(strValue);
|
||||
break;
|
||||
case "_mapspawned":
|
||||
_mapspawned = stof(strValue);
|
||||
break;
|
||||
default:
|
||||
super::Restore(strKey, strValue);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,10 @@ class NSVehicle:NSSurfacePropEntity
|
|||
vector velocity_net;
|
||||
|
||||
#ifdef CLIENT
|
||||
PREDICTED_FLOAT(driver_entnum);
|
||||
|
||||
virtual void(void) DriverRelink;
|
||||
virtual bool(void) IsLocalDriver;
|
||||
virtual void(void) PredictPreFrame;
|
||||
virtual void(void) PredictPostFrame;
|
||||
virtual void(float, float) ReadEntity;
|
||||
|
@ -40,6 +44,7 @@ class NSVehicle:NSSurfacePropEntity
|
|||
virtual float(entity, float) SendEntity;
|
||||
#endif
|
||||
|
||||
virtual entity(void) GetDriver;
|
||||
virtual void(void) PlayerUpdateFlags;
|
||||
virtual void(void) PlayerAlign;
|
||||
virtual void(base_player) PlayerEnter;
|
||||
|
@ -79,4 +84,4 @@ void
|
|||
CBaseVehicle::CBaseVehicle(void)
|
||||
{
|
||||
NSVehicle::NSVehicle();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,36 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
entity
|
||||
NSVehicle::GetDriver(void)
|
||||
{
|
||||
return (m_eDriver);
|
||||
}
|
||||
|
||||
#ifdef CLIENT
|
||||
void
|
||||
NSVehicle::DriverRelink(void)
|
||||
{
|
||||
if (!driver_entnum)
|
||||
m_eDriver = __NULL__;
|
||||
else {
|
||||
base_player pl;
|
||||
m_eDriver = findentity(world, ::entnum, driver_entnum);
|
||||
pl = (base_player)m_eDriver;
|
||||
pl.vehicle = this;
|
||||
}
|
||||
}
|
||||
bool
|
||||
NSVehicle::IsLocalDriver(void)
|
||||
{
|
||||
DriverRelink();
|
||||
|
||||
if (m_eDriver == pSeat->m_ePlayer)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
NSVehicle::UpdateView(void)
|
||||
{
|
||||
|
@ -26,6 +55,11 @@ NSVehicle::PredictPreFrame(void)
|
|||
SAVE_STATE(angles);
|
||||
SAVE_STATE(origin);
|
||||
SAVE_STATE(velocity);
|
||||
SAVE_STATE(size);
|
||||
SAVE_STATE(modelindex);
|
||||
SAVE_STATE(solid);
|
||||
SAVE_STATE(movetype);
|
||||
SAVE_STATE(m_eDriver);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -34,6 +68,11 @@ NSVehicle::PredictPostFrame(void)
|
|||
ROLL_BACK(angles);
|
||||
ROLL_BACK(origin);
|
||||
ROLL_BACK(velocity);
|
||||
ROLL_BACK(size);
|
||||
ROLL_BACK(modelindex);
|
||||
ROLL_BACK(solid);
|
||||
ROLL_BACK(movetype);
|
||||
ROLL_BACK(m_eDriver);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -91,9 +130,9 @@ NSVehicle::EvaluateEntity(void)
|
|||
{
|
||||
/* while the engine is still handling physics for these, we can't
|
||||
* predict when origin/angle might change */
|
||||
if (ATTR_CHANGED(origin)) {
|
||||
if (ATTR_CHANGED(origin))
|
||||
SetSendFlags(VEHFL_CHANGED_ORIGIN);
|
||||
}
|
||||
|
||||
if (ATTR_CHANGED(angles)) {
|
||||
angles[0] = Math_FixDelta(angles[0]);
|
||||
angles[1] = Math_FixDelta(angles[1]);
|
||||
|
@ -101,13 +140,32 @@ NSVehicle::EvaluateEntity(void)
|
|||
|
||||
SetSendFlags(VEHFL_CHANGED_ANGLES);
|
||||
}
|
||||
if (ATTR_CHANGED(velocity)) {
|
||||
if (ATTR_CHANGED(velocity))
|
||||
SetSendFlags(VEHFL_CHANGED_VELOCITY);
|
||||
}
|
||||
|
||||
if (ATTR_CHANGED(modelindex))
|
||||
SetSendFlags(VEHFL_CHANGED_MODELINDEX);
|
||||
|
||||
if (ATTR_CHANGED(solid))
|
||||
SetSendFlags(VEHFL_CHANGED_SOLID);
|
||||
|
||||
if (ATTR_CHANGED(movetype))
|
||||
SetSendFlags(VEHFL_CHANGED_MOVETYPE);
|
||||
|
||||
if (ATTR_CHANGED(size))
|
||||
SetSendFlags(VEHFL_CHANGED_SIZE);
|
||||
|
||||
if (ATTR_CHANGED(m_eDriver))
|
||||
SetSendFlags(VEHFL_CHANGED_DRIVER);
|
||||
|
||||
SAVE_STATE(origin);
|
||||
SAVE_STATE(angles);
|
||||
SAVE_STATE(velocity);
|
||||
SAVE_STATE(modelindex);
|
||||
SAVE_STATE(solid);
|
||||
SAVE_STATE(movetype);
|
||||
SAVE_STATE(size);
|
||||
SAVE_STATE(m_eDriver);
|
||||
}
|
||||
|
||||
float
|
||||
|
@ -243,6 +301,7 @@ NSVehicle::PlayerLeave(base_player pl)
|
|||
void
|
||||
NSVehicle::NSVehicle(void)
|
||||
{
|
||||
m_eDriver = __NULL__;
|
||||
super::NSSurfacePropEntity();
|
||||
}
|
||||
|
||||
|
|
|
@ -92,6 +92,8 @@ class prop_vehicle_driveable:NSVehicle
|
|||
float m_flFLWheelAxel;
|
||||
float m_flFRWheelAxel;
|
||||
|
||||
float m_flUseTime;
|
||||
|
||||
void(void) prop_vehicle_driveable;
|
||||
|
||||
virtual void(void) Physics;
|
||||
|
@ -115,11 +117,24 @@ class prop_vehicle_driveable:NSVehicle
|
|||
void
|
||||
prop_vehicle_driveable::Physics(void)
|
||||
{
|
||||
#ifdef CLIENT
|
||||
DriverRelink();
|
||||
#endif
|
||||
|
||||
/* if nobody is in the car, we need to run physics here
|
||||
* with fake input frames */
|
||||
if (num_for_edict(m_eDriver) == 0) {
|
||||
if (GetDriver() == __NULL__) {
|
||||
#ifdef SERVER
|
||||
m_flTimeLength = frametime;
|
||||
m_vecMoveValues = [0,0,0];
|
||||
m_iMoveButtons = 0;
|
||||
RunVehiclePhysics();
|
||||
}
|
||||
#else
|
||||
setorigin(this, origin);
|
||||
#endif
|
||||
} /* else {
|
||||
crossprint(sprintf("Driver: %s\n", GetDriver().classname));
|
||||
} */
|
||||
|
||||
#ifdef SERVER
|
||||
/* support for think/nextthink */
|
||||
|
@ -418,11 +433,13 @@ prop_vehicle_driveable_wheel::prop_vehicle_driveable_wheel(void)
|
|||
void
|
||||
prop_vehicle_driveable::PredictPreFrame(void)
|
||||
{
|
||||
SAVE_STATE(angles);
|
||||
SAVE_STATE(modelindex);
|
||||
SAVE_STATE(origin);
|
||||
SAVE_STATE(angles);
|
||||
SAVE_STATE(velocity);
|
||||
SAVE_STATE(m_flTurn);
|
||||
SAVE_STATE(flags);
|
||||
SAVE_STATE(driver_entnum);
|
||||
|
||||
m_wlFL.PredictPreFrame();
|
||||
m_wlFR.PredictPreFrame();
|
||||
|
@ -433,11 +450,13 @@ prop_vehicle_driveable::PredictPreFrame(void)
|
|||
void
|
||||
prop_vehicle_driveable::PredictPostFrame(void)
|
||||
{
|
||||
ROLL_BACK(modelindex);
|
||||
ROLL_BACK(angles);
|
||||
ROLL_BACK(origin);
|
||||
ROLL_BACK(velocity);
|
||||
ROLL_BACK(m_flTurn);
|
||||
ROLL_BACK(flags);
|
||||
ROLL_BACK(driver_entnum);
|
||||
|
||||
m_wlFL.PredictPostFrame();
|
||||
m_wlFR.PredictPostFrame();
|
||||
|
@ -493,12 +512,10 @@ prop_vehicle_driveable::RunVehiclePhysics(void)
|
|||
|
||||
PlayerUpdateFlags();
|
||||
|
||||
#ifdef SERVER
|
||||
if (angles[2] > 125 || angles[2] < -125)
|
||||
PlayerLeave((base_player)m_eDriver);
|
||||
} else {
|
||||
m_vecMoveValues = [240,0,0];
|
||||
m_iMoveButtons = 0;
|
||||
m_flTimeLength = frametime;
|
||||
#endif
|
||||
}
|
||||
|
||||
flags &= ~VEH_SKIDDING;
|
||||
|
@ -560,6 +577,7 @@ prop_vehicle_driveable::OnPlayerUse(void)
|
|||
PlayerEnter((base_player)eActivator);
|
||||
m_vecPlayerPos = [0,0,0];
|
||||
}
|
||||
m_flUseTime = time + 2.0f;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -594,7 +612,8 @@ void
|
|||
prop_vehicle_driveable::ReadEntity(float flSendFlags, float flNew)
|
||||
{
|
||||
if (flSendFlags & VEHFL_DRIVER) {
|
||||
m_eDriver = findfloat(world, ::entnum, readentitynum());
|
||||
driver_entnum = readentitynum();
|
||||
DriverRelink();
|
||||
}
|
||||
|
||||
if (flSendFlags & VEHFL_MODELINDEX) {
|
||||
|
@ -646,9 +665,12 @@ prop_vehicle_driveable::ReadEntity(float flSendFlags, float flNew)
|
|||
m_wlBR.velocity =
|
||||
velocity = [0,0,0];
|
||||
RunVehiclePhysics();
|
||||
customphysics = Physics;
|
||||
|
||||
print(sprintf("%v\n", origin));
|
||||
}
|
||||
|
||||
PredictPreFrame();
|
||||
}
|
||||
#else
|
||||
void
|
||||
|
@ -673,10 +695,10 @@ prop_vehicle_driveable::EvaluateEntity(void)
|
|||
if (ATTR_CHANGED(velocity)) {
|
||||
SetSendFlags(VEHFL_VELOCITY);
|
||||
}
|
||||
if (m_flTurn_net != m_flTurn) {
|
||||
if (ATTR_CHANGED(m_flTurn)) {
|
||||
SetSendFlags(VEHFL_TURNING);
|
||||
}
|
||||
if (m_eDriver_net != m_eDriver) {
|
||||
if (ATTR_CHANGED(m_eDriver)) {
|
||||
SetSendFlags(VEHFL_DRIVER);
|
||||
}
|
||||
if (ATTR_CHANGED(flags)) {
|
||||
|
@ -740,6 +762,7 @@ prop_vehicle_driveable::SendEntity(entity ePVSent, float flSendFlags)
|
|||
void
|
||||
prop_vehicle_driveable::prop_vehicle_driveable(void)
|
||||
{
|
||||
m_eDriver = __NULL__;
|
||||
m_flBounceFactor = 1.5f;
|
||||
m_flAcceleration = 600.0f;
|
||||
m_flSkidSpeed = 256.0f;
|
||||
|
|
|
@ -764,8 +764,9 @@ SV_PerformSave(float fh, float entcount, float playerslots)
|
|||
void
|
||||
CheckSpawn(void() spawnfunc)
|
||||
{
|
||||
if (spawnfunc)
|
||||
if (spawnfunc) {
|
||||
spawnfunc();
|
||||
else
|
||||
self._mapspawned = true;
|
||||
} else
|
||||
remove(self);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ base_player:spectator
|
|||
PREDICTED_INT_N(weaponframe);
|
||||
#else
|
||||
PREDICTED_INT(weaponframe);
|
||||
PREDICTED_FLOAT(vehicle_entnum);
|
||||
#endif
|
||||
PREDICTED_FLOAT(health);
|
||||
PREDICTED_FLOAT(armor);
|
||||
|
@ -85,6 +86,7 @@ base_player:spectator
|
|||
int p_model_bone;
|
||||
float lastweapon;
|
||||
|
||||
virtual void(void) VehicleRelink;
|
||||
virtual void(void) ClientRemove;
|
||||
virtual void(float, float) ReceiveEntity;
|
||||
virtual void(void) PredictPreFrame;
|
||||
|
|
|
@ -35,11 +35,10 @@ base_player::PreFrame(void)
|
|||
* information. */
|
||||
PredictPreFrame();
|
||||
|
||||
if (flags & FL_INVEHICLE)
|
||||
if (vehicle) {
|
||||
NSVehicle veh = (NSVehicle)vehicle;
|
||||
veh.PredictPreFrame();
|
||||
}
|
||||
if (vehicle) {
|
||||
NSVehicle veh = (NSVehicle)vehicle;
|
||||
veh.PredictPreFrame();
|
||||
}
|
||||
|
||||
/* run physics code for all the input frames which we've not heard back
|
||||
* from yet. This continues on in Player_ReceiveEntity! */
|
||||
|
@ -72,15 +71,13 @@ base_player::PostFrame(void)
|
|||
#ifdef CLIENT
|
||||
/* give the game/mod a chance to roll back its values too */
|
||||
PredictPostFrame();
|
||||
setorigin(this, origin); /* update bounds */
|
||||
|
||||
if (flags & FL_INVEHICLE)
|
||||
if (vehicle) {
|
||||
NSVehicle veh = (NSVehicle)vehicle;
|
||||
veh.PredictPostFrame();
|
||||
}
|
||||
|
||||
/* update bounds */
|
||||
setorigin(this, origin);
|
||||
if (vehicle) {
|
||||
NSVehicle veh = (NSVehicle)vehicle;
|
||||
veh.PredictPostFrame();
|
||||
setorigin(veh, veh.origin);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -102,6 +99,15 @@ base_player::ClientInput(void)
|
|||
}
|
||||
|
||||
#ifdef CLIENT
|
||||
void
|
||||
base_player::VehicleRelink(void)
|
||||
{
|
||||
if (!vehicle_entnum)
|
||||
vehicle = __NULL__;
|
||||
else
|
||||
vehicle = findentity(world, ::entnum, vehicle_entnum);
|
||||
}
|
||||
|
||||
void
|
||||
base_player::ClientRemove(void)
|
||||
{
|
||||
|
@ -268,12 +274,15 @@ base_player::ReceiveEntity(float new, float fl)
|
|||
punchangle[0] = readfloat();
|
||||
punchangle[1] = readfloat();
|
||||
punchangle[2] = readfloat();
|
||||
vehicle = findfloat(world, ::entnum, readentitynum());
|
||||
vehicle_entnum = readentitynum();
|
||||
VehicleRelink();
|
||||
|
||||
/* FIXME: Make this temp spec only */
|
||||
spec_ent = readbyte();
|
||||
spec_mode = readbyte();
|
||||
spec_flags = readbyte();
|
||||
|
||||
PredictPreFrame();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -313,7 +322,7 @@ base_player::PredictPreFrame(void)
|
|||
SAVE_STATE(w_attack_next);
|
||||
SAVE_STATE(w_idle_next);
|
||||
SAVE_STATE(punchangle);
|
||||
SAVE_STATE(vehicle);
|
||||
SAVE_STATE(vehicle_entnum);
|
||||
|
||||
SAVE_STATE(spec_ent);
|
||||
SAVE_STATE(spec_mode);
|
||||
|
@ -358,7 +367,7 @@ base_player::PredictPostFrame(void)
|
|||
ROLL_BACK(w_attack_next);
|
||||
ROLL_BACK(w_idle_next);
|
||||
ROLL_BACK(punchangle);
|
||||
ROLL_BACK(vehicle);
|
||||
ROLL_BACK(vehicle_entnum);
|
||||
|
||||
ROLL_BACK(spec_ent);
|
||||
ROLL_BACK(spec_mode);
|
||||
|
|
Loading…
Reference in a new issue