g_phys.c
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "g_local.h"
00027
00034 void G_PhysicsStep (edict_t *ent)
00035 {
00039 if (ent->moveinfo.currentStep < ent->moveinfo.steps) {
00040 const int contentFlags = ent->contentFlags;
00041 const int visflags = ent->moveinfo.visflags[ent->moveinfo.currentStep];
00042
00043 if (!G_IsCrouched(ent)) {
00044 if (contentFlags & CONTENTS_WATER) {
00045 if (ent->moveinfo.contentFlags[ent->moveinfo.currentStep] & CONTENTS_WATER) {
00046
00047
00048 gi.PositionedSound(~G_VisToPM(visflags), ent->origin, ent, "footsteps/water_under");
00049 } else {
00050
00051 gi.PositionedSound(~G_VisToPM(visflags), ent->origin, ent, "footsteps/water_in");
00052 }
00053 } else if (ent->contentFlags & CONTENTS_WATER) {
00054
00055 gi.PositionedSound(~G_VisToPM(visflags), ent->origin, ent, "footsteps/water_out");
00056 } else {
00057 trace_t trace;
00058 vec3_t from, to;
00059
00060 VectorCopy(ent->origin, to);
00061 VectorCopy(ent->origin, from);
00062
00063 to[2] -= UNIT_HEIGHT;
00064
00065 trace = G_Trace(from, to, NULL, MASK_SOLID);
00066 if (trace.surface) {
00067 const char *snd = gi.GetFootstepSound(trace.surface->name);
00068 if (snd)
00069 gi.PositionedSound(~G_VisToPM(visflags), ent->origin, ent, snd);
00070 }
00071 }
00072 }
00073
00074
00075 ent->contentFlags = ent->moveinfo.contentFlags[ent->moveinfo.currentStep];
00076 ent->moveinfo.currentStep++;
00077
00078
00079 ent->nextthink = (level.framenum + 3) * SERVER_FRAME_SECONDS;
00080 } else {
00081 ent->moveinfo.currentStep = 0;
00082 ent->moveinfo.steps = 0;
00083 ent->think = NULL;
00084 }
00085 }
00086
00090 static qboolean G_PhysicsThink (edict_t *ent)
00091 {
00092 if (ent->nextthink <= 0)
00093 return qtrue;
00094 if (ent->nextthink > level.time + 0.001f)
00095 return qtrue;
00096
00097 ent->nextthink = level.time + SERVER_FRAME_SECONDS;
00098 if (!ent->think)
00099 gi.Error("G_PhysicsThink ent->think is NULL");
00100 ent->think(ent);
00101
00102 return qfalse;
00103 }
00104
00109 void G_PhysicsRun (void)
00110 {
00111 edict_t *ent = NULL;
00112
00113
00114 if (!G_MatchIsRunning())
00115 return;
00116
00117 #if 0
00118
00119 if (level.framenum % 10)
00120 return;
00121 #endif
00122
00123
00124
00125 while ((ent = G_EdictsGetNextInUse(ent))) {
00126 if (ent->think)
00127 G_PhysicsThink(ent);
00128 }
00129 }