NSEntity: New method CreatedByMap(). Additional work towards more vehicle related

code in preparation for WASTES.
This commit is contained in:
Marco Cawthorne 2022-04-06 16:21:07 -07:00
parent 9a6897c433
commit a8c8938408
Signed by: eukara
GPG key ID: C196CD8BA993248A
11 changed files with 148 additions and 35 deletions

View file

@ -183,6 +183,7 @@ Entities_ParseLump(void)
/* check if our classname has a matching class */ /* check if our classname has a matching class */
if (isfunction(strcat("spawnfunc_", strValue))) { if (isfunction(strcat("spawnfunc_", strValue))) {
self = eEnt; self = eEnt;
self._mapspawned = true;
callfunction(strcat("spawnfunc_", strValue)); callfunction(strcat("spawnfunc_", strValue));
self = eOld; self = eOld;
iClass = TRUE; iClass = TRUE;

View file

@ -286,7 +286,7 @@ CSQC_UpdateView(float w, float h, float focus)
if (!Client_IsSpectator(pl)) { if (!Client_IsSpectator(pl)) {
setproperty(VF_ORIGIN, pSeat->m_vecPredictedOrigin + pl.view_ofs); setproperty(VF_ORIGIN, pSeat->m_vecPredictedOrigin + pl.view_ofs);
if (pl.flags & FL_INVEHICLE) { if (pl.vehicle) {
NSVehicle veh = (NSVehicle)pl.vehicle; NSVehicle veh = (NSVehicle)pl.vehicle;
if (veh.UpdateView) if (veh.UpdateView)

View file

@ -74,4 +74,6 @@ enumflags
#else #else
BASEFL_CHANGED_ALPHA, BASEFL_CHANGED_ALPHA,
#endif #endif
}; };
.bool _mapspawned;

View file

@ -144,6 +144,7 @@ class NSEntity:NSTrigger
nonvirtual entity(void) GetGroundEntity; nonvirtual entity(void) GetGroundEntity;
virtual void(entity) Blocked; virtual void(entity) Blocked;
nonvirtual void(void) BlockedHandler; nonvirtual void(void) BlockedHandler;
nonvirtual bool(void) CreatedByMap;
virtual void(entity) StartTouch; virtual void(entity) StartTouch;
virtual void(entity) Touch; virtual void(entity) Touch;

View file

@ -160,6 +160,12 @@ NSEntity::GetGroundEntity(void)
return groundentity; return groundentity;
} }
bool
NSEntity::CreatedByMap(void)
{
return _mapspawned;
}
void void
NSEntity::Blocked(entity eBlocker) NSEntity::Blocked(entity eBlocker)
{ {
@ -826,6 +832,7 @@ NSEntity::Save(float handle)
SaveFloat(handle, "health", health); SaveFloat(handle, "health", health);
SaveString(handle, "parentname", m_parent); SaveString(handle, "parentname", m_parent);
SaveFloat(handle, "pvsflags", pvsflags); SaveFloat(handle, "pvsflags", pvsflags);
SaveFloat(handle, "_mapspawned", _mapspawned);
super::Save(handle); super::Save(handle);
} }
void void
@ -877,6 +884,9 @@ NSEntity::Restore(string strKey, string strValue)
case "pvsflags": case "pvsflags":
pvsflags = stof(strValue); pvsflags = stof(strValue);
break; break;
case "_mapspawned":
_mapspawned = stof(strValue);
break;
default: default:
super::Restore(strKey, strValue); super::Restore(strKey, strValue);
} }

View file

@ -32,6 +32,10 @@ class NSVehicle:NSSurfacePropEntity
vector velocity_net; vector velocity_net;
#ifdef CLIENT #ifdef CLIENT
PREDICTED_FLOAT(driver_entnum);
virtual void(void) DriverRelink;
virtual bool(void) IsLocalDriver;
virtual void(void) PredictPreFrame; virtual void(void) PredictPreFrame;
virtual void(void) PredictPostFrame; virtual void(void) PredictPostFrame;
virtual void(float, float) ReadEntity; virtual void(float, float) ReadEntity;
@ -40,6 +44,7 @@ class NSVehicle:NSSurfacePropEntity
virtual float(entity, float) SendEntity; virtual float(entity, float) SendEntity;
#endif #endif
virtual entity(void) GetDriver;
virtual void(void) PlayerUpdateFlags; virtual void(void) PlayerUpdateFlags;
virtual void(void) PlayerAlign; virtual void(void) PlayerAlign;
virtual void(base_player) PlayerEnter; virtual void(base_player) PlayerEnter;
@ -79,4 +84,4 @@ void
CBaseVehicle::CBaseVehicle(void) CBaseVehicle::CBaseVehicle(void)
{ {
NSVehicle::NSVehicle(); NSVehicle::NSVehicle();
} }

View file

@ -14,7 +14,36 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
entity
NSVehicle::GetDriver(void)
{
return (m_eDriver);
}
#ifdef CLIENT #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 void
NSVehicle::UpdateView(void) NSVehicle::UpdateView(void)
{ {
@ -26,6 +55,11 @@ NSVehicle::PredictPreFrame(void)
SAVE_STATE(angles); SAVE_STATE(angles);
SAVE_STATE(origin); SAVE_STATE(origin);
SAVE_STATE(velocity); SAVE_STATE(velocity);
SAVE_STATE(size);
SAVE_STATE(modelindex);
SAVE_STATE(solid);
SAVE_STATE(movetype);
SAVE_STATE(m_eDriver);
} }
void void
@ -34,6 +68,11 @@ NSVehicle::PredictPostFrame(void)
ROLL_BACK(angles); ROLL_BACK(angles);
ROLL_BACK(origin); ROLL_BACK(origin);
ROLL_BACK(velocity); ROLL_BACK(velocity);
ROLL_BACK(size);
ROLL_BACK(modelindex);
ROLL_BACK(solid);
ROLL_BACK(movetype);
ROLL_BACK(m_eDriver);
} }
void void
@ -91,9 +130,9 @@ NSVehicle::EvaluateEntity(void)
{ {
/* while the engine is still handling physics for these, we can't /* while the engine is still handling physics for these, we can't
* predict when origin/angle might change */ * predict when origin/angle might change */
if (ATTR_CHANGED(origin)) { if (ATTR_CHANGED(origin))
SetSendFlags(VEHFL_CHANGED_ORIGIN); SetSendFlags(VEHFL_CHANGED_ORIGIN);
}
if (ATTR_CHANGED(angles)) { if (ATTR_CHANGED(angles)) {
angles[0] = Math_FixDelta(angles[0]); angles[0] = Math_FixDelta(angles[0]);
angles[1] = Math_FixDelta(angles[1]); angles[1] = Math_FixDelta(angles[1]);
@ -101,13 +140,32 @@ NSVehicle::EvaluateEntity(void)
SetSendFlags(VEHFL_CHANGED_ANGLES); SetSendFlags(VEHFL_CHANGED_ANGLES);
} }
if (ATTR_CHANGED(velocity)) { if (ATTR_CHANGED(velocity))
SetSendFlags(VEHFL_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(origin);
SAVE_STATE(angles); SAVE_STATE(angles);
SAVE_STATE(velocity); SAVE_STATE(velocity);
SAVE_STATE(modelindex);
SAVE_STATE(solid);
SAVE_STATE(movetype);
SAVE_STATE(size);
SAVE_STATE(m_eDriver);
} }
float float
@ -243,6 +301,7 @@ NSVehicle::PlayerLeave(base_player pl)
void void
NSVehicle::NSVehicle(void) NSVehicle::NSVehicle(void)
{ {
m_eDriver = __NULL__;
super::NSSurfacePropEntity(); super::NSSurfacePropEntity();
} }

View file

@ -92,6 +92,8 @@ class prop_vehicle_driveable:NSVehicle
float m_flFLWheelAxel; float m_flFLWheelAxel;
float m_flFRWheelAxel; float m_flFRWheelAxel;
float m_flUseTime;
void(void) prop_vehicle_driveable; void(void) prop_vehicle_driveable;
virtual void(void) Physics; virtual void(void) Physics;
@ -115,11 +117,24 @@ class prop_vehicle_driveable:NSVehicle
void void
prop_vehicle_driveable::Physics(void) prop_vehicle_driveable::Physics(void)
{ {
#ifdef CLIENT
DriverRelink();
#endif
/* if nobody is in the car, we need to run physics here /* if nobody is in the car, we need to run physics here
* with fake input frames */ * 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(); RunVehiclePhysics();
} #else
setorigin(this, origin);
#endif
} /* else {
crossprint(sprintf("Driver: %s\n", GetDriver().classname));
} */
#ifdef SERVER #ifdef SERVER
/* support for think/nextthink */ /* support for think/nextthink */
@ -418,11 +433,13 @@ prop_vehicle_driveable_wheel::prop_vehicle_driveable_wheel(void)
void void
prop_vehicle_driveable::PredictPreFrame(void) prop_vehicle_driveable::PredictPreFrame(void)
{ {
SAVE_STATE(angles); SAVE_STATE(modelindex);
SAVE_STATE(origin); SAVE_STATE(origin);
SAVE_STATE(angles);
SAVE_STATE(velocity); SAVE_STATE(velocity);
SAVE_STATE(m_flTurn); SAVE_STATE(m_flTurn);
SAVE_STATE(flags); SAVE_STATE(flags);
SAVE_STATE(driver_entnum);
m_wlFL.PredictPreFrame(); m_wlFL.PredictPreFrame();
m_wlFR.PredictPreFrame(); m_wlFR.PredictPreFrame();
@ -433,11 +450,13 @@ prop_vehicle_driveable::PredictPreFrame(void)
void void
prop_vehicle_driveable::PredictPostFrame(void) prop_vehicle_driveable::PredictPostFrame(void)
{ {
ROLL_BACK(modelindex);
ROLL_BACK(angles); ROLL_BACK(angles);
ROLL_BACK(origin); ROLL_BACK(origin);
ROLL_BACK(velocity); ROLL_BACK(velocity);
ROLL_BACK(m_flTurn); ROLL_BACK(m_flTurn);
ROLL_BACK(flags); ROLL_BACK(flags);
ROLL_BACK(driver_entnum);
m_wlFL.PredictPostFrame(); m_wlFL.PredictPostFrame();
m_wlFR.PredictPostFrame(); m_wlFR.PredictPostFrame();
@ -493,12 +512,10 @@ prop_vehicle_driveable::RunVehiclePhysics(void)
PlayerUpdateFlags(); PlayerUpdateFlags();
#ifdef SERVER
if (angles[2] > 125 || angles[2] < -125) if (angles[2] > 125 || angles[2] < -125)
PlayerLeave((base_player)m_eDriver); PlayerLeave((base_player)m_eDriver);
} else { #endif
m_vecMoveValues = [240,0,0];
m_iMoveButtons = 0;
m_flTimeLength = frametime;
} }
flags &= ~VEH_SKIDDING; flags &= ~VEH_SKIDDING;
@ -560,6 +577,7 @@ prop_vehicle_driveable::OnPlayerUse(void)
PlayerEnter((base_player)eActivator); PlayerEnter((base_player)eActivator);
m_vecPlayerPos = [0,0,0]; m_vecPlayerPos = [0,0,0];
} }
m_flUseTime = time + 2.0f;
} }
void void
@ -594,7 +612,8 @@ void
prop_vehicle_driveable::ReadEntity(float flSendFlags, float flNew) prop_vehicle_driveable::ReadEntity(float flSendFlags, float flNew)
{ {
if (flSendFlags & VEHFL_DRIVER) { if (flSendFlags & VEHFL_DRIVER) {
m_eDriver = findfloat(world, ::entnum, readentitynum()); driver_entnum = readentitynum();
DriverRelink();
} }
if (flSendFlags & VEHFL_MODELINDEX) { if (flSendFlags & VEHFL_MODELINDEX) {
@ -646,9 +665,12 @@ prop_vehicle_driveable::ReadEntity(float flSendFlags, float flNew)
m_wlBR.velocity = m_wlBR.velocity =
velocity = [0,0,0]; velocity = [0,0,0];
RunVehiclePhysics(); RunVehiclePhysics();
customphysics = Physics;
print(sprintf("%v\n", origin)); print(sprintf("%v\n", origin));
} }
PredictPreFrame();
} }
#else #else
void void
@ -673,10 +695,10 @@ prop_vehicle_driveable::EvaluateEntity(void)
if (ATTR_CHANGED(velocity)) { if (ATTR_CHANGED(velocity)) {
SetSendFlags(VEHFL_VELOCITY); SetSendFlags(VEHFL_VELOCITY);
} }
if (m_flTurn_net != m_flTurn) { if (ATTR_CHANGED(m_flTurn)) {
SetSendFlags(VEHFL_TURNING); SetSendFlags(VEHFL_TURNING);
} }
if (m_eDriver_net != m_eDriver) { if (ATTR_CHANGED(m_eDriver)) {
SetSendFlags(VEHFL_DRIVER); SetSendFlags(VEHFL_DRIVER);
} }
if (ATTR_CHANGED(flags)) { if (ATTR_CHANGED(flags)) {
@ -740,6 +762,7 @@ prop_vehicle_driveable::SendEntity(entity ePVSent, float flSendFlags)
void void
prop_vehicle_driveable::prop_vehicle_driveable(void) prop_vehicle_driveable::prop_vehicle_driveable(void)
{ {
m_eDriver = __NULL__;
m_flBounceFactor = 1.5f; m_flBounceFactor = 1.5f;
m_flAcceleration = 600.0f; m_flAcceleration = 600.0f;
m_flSkidSpeed = 256.0f; m_flSkidSpeed = 256.0f;

View file

@ -764,8 +764,9 @@ SV_PerformSave(float fh, float entcount, float playerslots)
void void
CheckSpawn(void() spawnfunc) CheckSpawn(void() spawnfunc)
{ {
if (spawnfunc) if (spawnfunc) {
spawnfunc(); spawnfunc();
else self._mapspawned = true;
} else
remove(self); remove(self);
} }

View file

@ -21,6 +21,7 @@ base_player:spectator
PREDICTED_INT_N(weaponframe); PREDICTED_INT_N(weaponframe);
#else #else
PREDICTED_INT(weaponframe); PREDICTED_INT(weaponframe);
PREDICTED_FLOAT(vehicle_entnum);
#endif #endif
PREDICTED_FLOAT(health); PREDICTED_FLOAT(health);
PREDICTED_FLOAT(armor); PREDICTED_FLOAT(armor);
@ -85,6 +86,7 @@ base_player:spectator
int p_model_bone; int p_model_bone;
float lastweapon; float lastweapon;
virtual void(void) VehicleRelink;
virtual void(void) ClientRemove; virtual void(void) ClientRemove;
virtual void(float, float) ReceiveEntity; virtual void(float, float) ReceiveEntity;
virtual void(void) PredictPreFrame; virtual void(void) PredictPreFrame;

View file

@ -35,11 +35,10 @@ base_player::PreFrame(void)
* information. */ * information. */
PredictPreFrame(); PredictPreFrame();
if (flags & FL_INVEHICLE) if (vehicle) {
if (vehicle) { NSVehicle veh = (NSVehicle)vehicle;
NSVehicle veh = (NSVehicle)vehicle; veh.PredictPreFrame();
veh.PredictPreFrame(); }
}
/* run physics code for all the input frames which we've not heard back /* run physics code for all the input frames which we've not heard back
* from yet. This continues on in Player_ReceiveEntity! */ * from yet. This continues on in Player_ReceiveEntity! */
@ -72,15 +71,13 @@ base_player::PostFrame(void)
#ifdef CLIENT #ifdef CLIENT
/* give the game/mod a chance to roll back its values too */ /* give the game/mod a chance to roll back its values too */
PredictPostFrame(); PredictPostFrame();
setorigin(this, origin); /* update bounds */
if (flags & FL_INVEHICLE) if (vehicle) {
if (vehicle) { NSVehicle veh = (NSVehicle)vehicle;
NSVehicle veh = (NSVehicle)vehicle; veh.PredictPostFrame();
veh.PredictPostFrame(); setorigin(veh, veh.origin);
} }
/* update bounds */
setorigin(this, origin);
#endif #endif
} }
@ -102,6 +99,15 @@ base_player::ClientInput(void)
} }
#ifdef CLIENT #ifdef CLIENT
void
base_player::VehicleRelink(void)
{
if (!vehicle_entnum)
vehicle = __NULL__;
else
vehicle = findentity(world, ::entnum, vehicle_entnum);
}
void void
base_player::ClientRemove(void) base_player::ClientRemove(void)
{ {
@ -268,12 +274,15 @@ base_player::ReceiveEntity(float new, float fl)
punchangle[0] = readfloat(); punchangle[0] = readfloat();
punchangle[1] = readfloat(); punchangle[1] = readfloat();
punchangle[2] = readfloat(); punchangle[2] = readfloat();
vehicle = findfloat(world, ::entnum, readentitynum()); vehicle_entnum = readentitynum();
VehicleRelink();
/* FIXME: Make this temp spec only */ /* FIXME: Make this temp spec only */
spec_ent = readbyte(); spec_ent = readbyte();
spec_mode = readbyte(); spec_mode = readbyte();
spec_flags = readbyte(); spec_flags = readbyte();
PredictPreFrame();
} }
/* /*
@ -313,7 +322,7 @@ base_player::PredictPreFrame(void)
SAVE_STATE(w_attack_next); SAVE_STATE(w_attack_next);
SAVE_STATE(w_idle_next); SAVE_STATE(w_idle_next);
SAVE_STATE(punchangle); SAVE_STATE(punchangle);
SAVE_STATE(vehicle); SAVE_STATE(vehicle_entnum);
SAVE_STATE(spec_ent); SAVE_STATE(spec_ent);
SAVE_STATE(spec_mode); SAVE_STATE(spec_mode);
@ -358,7 +367,7 @@ base_player::PredictPostFrame(void)
ROLL_BACK(w_attack_next); ROLL_BACK(w_attack_next);
ROLL_BACK(w_idle_next); ROLL_BACK(w_idle_next);
ROLL_BACK(punchangle); ROLL_BACK(punchangle);
ROLL_BACK(vehicle); ROLL_BACK(vehicle_entnum);
ROLL_BACK(spec_ent); ROLL_BACK(spec_ent);
ROLL_BACK(spec_mode); ROLL_BACK(spec_mode);