Skip to content

Commit

Permalink
ENTS: Add support for func_bob.
Browse files Browse the repository at this point in the history
Used to move a bmodel between point A and B with an easing function at
the turning points.

Available in most SP QuakeC codebases.
  • Loading branch information
dsvensson committed Jul 28, 2023
1 parent acd5cee commit 9418cd9
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ set(SRC_COMMON
"${DIR_SRC}/doors.c"
"${DIR_SRC}/fb_globals.c"
"${DIR_SRC}/files.c"
"${DIR_SRC}/func_bob.c"
"${DIR_SRC}/g_cmd.c"
"${DIR_SRC}/globals.c"
"${DIR_SRC}/g_mem.c"
Expand Down
6 changes: 6 additions & 0 deletions include/progs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,12 @@ typedef struct gedict_s
string_t path;
string_t event;
// }

// { func_bob
float distance;
float waitmin;
float waitmin2;
// }
} gedict_t;

typedef enum
Expand Down
81 changes: 81 additions & 0 deletions src/func_bob.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include "g_local.h"

// Stripped down port of dumptruckDS's func_bob.qc

static void func_bob_timer()
{
vec3_t delta;

// Has the cycle completed?
if (self->endtime < g_globalvars.time)
{
// Setup bob cycle and half way point for slowdown
self->endtime = g_globalvars.time + self->count;
self->distance = g_globalvars.time + (self->count * 0.5);

// Flip direction of bmodel bob
self->lefty = 1 - self->lefty;
if (self->lefty < 1)
{
self->t_length = self->height;
}
else
{
self->t_length = -self->height;
}

// Always reset velocity at pivot
SetVector(self->s.v.velocity, 0, 0, 0);
}

if (self->distance < g_globalvars.time)
{
// Slow down velocity (gradually)
VectorScale(self->s.v.velocity, self->waitmin2, self->s.v.velocity);
}
else
{
// Speed up velocity (linear/exponentially)
self->t_length *= self->waitmin;
VectorScale(self->s.v.movedir, self->t_length, delta);
VectorAdd(self->s.v.velocity, delta, self->s.v.velocity);
}

self->s.v.nextthink = self->s.v.ltime + 0.1;
}

void SP_func_bob()
{
self->s.v.movetype = MOVETYPE_PUSH;
self->s.v.solid = SOLID_BSP;

setmodel(self, self->model);
setsize(self, PASSVEC3(self->s.v.mins), PASSVEC3(self->s.v.maxs));

SetMovedir();
VectorNormalize(self->s.v.movedir);

if (self->height <= 0)
{
self->height = 8; // Direction intensity
}
if (self->count < 1)
{
self->count = 2; // Direction switch timer
}
if (self->waitmin <= 0)
{
self->waitmin = 1; // Speed up
}
if (self->waitmin2 <= 0)
{
self->waitmin2 = 0.75; // Slow down
}
if (self->delay < 0)
{
self->delay = g_random() + g_random() + g_random();
}

self->think = (func_t) func_bob_timer;
self->s.v.nextthink = g_globalvars.time + 0.1 + self->delay;
}
8 changes: 8 additions & 0 deletions src/g_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ field_t fields[] =
{ "rotate", FOFS(rotate), F_VECTOR },
{ "path", FOFS(path), F_LSTRING },
{ "event", FOFS(event), F_LSTRING },

// Bob
{ "waitmin", FOFS(waitmin), F_FLOAT},
{ "waitmin2", FOFS(waitmin2), F_FLOAT},
{ NULL }
};

Expand Down Expand Up @@ -244,6 +248,8 @@ void SP_func_train();
void SP_misc_teleporttrain();
void SP_func_button();

void SP_func_bob();

void SP_trigger_multiple();
void SP_trigger_once();
void SP_trigger_relay();
Expand Down Expand Up @@ -382,6 +388,8 @@ spawn_t spawns[] =
{ "misc_teleporttrain", SP_misc_teleporttrain },
{ "func_button", SP_func_button },

{ "func_bob", SP_func_bob },

{ "trigger_multiple", SP_trigger_multiple },
{ "trigger_once", SP_trigger_once },
{ "trigger_relay", SP_trigger_relay },
Expand Down

0 comments on commit 9418cd9

Please sign in to comment.