g_phys.c

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 1997-2001 Id Software, Inc.
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 
00019 See the GNU General Public License for more details.
00020 
00021 You should have received a copy of the GNU General Public License
00022 along with this program; if not, write to the Free Software
00023 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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         /* Send the sound effect to everyone how's not seeing the actor */
00043         if (!G_IsCrouched(ent)) {
00044             if (contentFlags & CONTENTS_WATER) {
00045                 if (ent->moveinfo.contentFlags[ent->moveinfo.currentStep] & CONTENTS_WATER) {
00046                     /* looks like we already are in the water */
00047                     /* send water moving sound */
00048                     gi.PositionedSound(~G_VisToPM(visflags), ent->origin, ent, "footsteps/water_under");
00049                 } else {
00050                     /* send water entering sound */
00051                     gi.PositionedSound(~G_VisToPM(visflags), ent->origin, ent, "footsteps/water_in");
00052                 }
00053             } else if (ent->contentFlags & CONTENTS_WATER) {
00054                 /* send water leaving sound */
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                 /* we should really hit the ground with this */
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         /* and now save the new contents */
00075         ent->contentFlags = ent->moveinfo.contentFlags[ent->moveinfo.currentStep];
00076         ent->moveinfo.currentStep++;
00077 
00078         /* Immediately re-think */
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     /* not all teams are spawned or game has already ended */
00114     if (!G_MatchIsRunning())
00115         return;
00116 
00117 #if 0 /* taken out - otherwise footstep sounds are too slow */
00118     /* don't run this too often to prevent overflows */
00119     if (level.framenum % 10)
00120         return;
00121 #endif
00122 
00123     /* treat each object in turn */
00124     /* even the world gets a chance to think */
00125     while ((ent = G_EdictsGetNextInUse(ent))) {
00126         if (ent->think)
00127             G_PhysicsThink(ent);
00128     }
00129 }

Generated by  doxygen 1.6.2