/** * @brief Callback for EV_DOOR_CLOSE event - rotates the inline model and recalc routing * @sa EV_DOOR_CLOSE * @sa G_ClientUseEdict * @sa Touch_DoorTrigger */ void CL_DoorClose (const eventRegister_t *self, struct dbuffer *msg) { /* get local entity */ int number; le_t *le; NET_ReadFormat(msg, self->formatString, &number); le = LE_Get(number); if (!le) LE_NotFoundError(number); if (le->type == ET_DOOR) { if (le->dir & DOOR_OPEN_REVERSE) le->angles[le->dir & 3] += DOOR_ROTATION_ANGLE; else le->angles[le->dir & 3] -= DOOR_ROTATION_ANGLE; CM_SetInlineModelOrientation(cl.mapTiles, le->inlineModelName, le->origin, le->angles); CL_RecalcRouting(le); } else if (le->type == ET_DOOR_SLIDING) { LE_SetThink(le, LET_DoorSlidingClose); le->think(le); } else { Com_Error(ERR_DROP, "Invalid door entity found of type: %i", le->type); } }
/** * @brief Rotates a door in the given speed * * @param[in] le The local entity of the door to rotate * @param[in] speed The speed to rotate the door with */ void LET_RotateDoor (le_t* le, int speed) { /** @todo lerp the rotation */ const int angle = speed > 0 ? DOOR_ROTATION_ANGLE : -DOOR_ROTATION_ANGLE; if (le->dir & DOOR_OPEN_REVERSE) le->angles[le->dir & 3] -= angle; else le->angles[le->dir & 3] += angle; CM_SetInlineModelOrientation(cl.mapTiles, le->inlineModelName, le->origin, le->angles); CL_RecalcRouting(le); /* reset the think function as the movement finished */ LE_SetThink(le, nullptr); }
/** * @note Also sets mins and maxs for inline bmodels * @sa CM_InlineModel */ static void SV_SetModel (edict_t * ent, const char *name) { if (!name) Com_Error(ERR_DROP, "SV_SetModel: NULL"); ent->modelindex = SV_ModelIndex(name); /* if it is an inline model, get the size information for it */ if (name[0] == '*') { const cBspModel_t *mod = CM_InlineModel(&sv->mapTiles, name); /* Copy model mins and maxs to entity */ VectorCopy(mod->mins, ent->mins); VectorCopy(mod->maxs, ent->maxs); /* This is to help the entity collision code out */ /* Copy entity origin and angles to model*/ CM_SetInlineModelOrientation(&sv->mapTiles, name, ent->origin, ent->angles); } }
static void SV_SetInlineModelOrientation (const char *name, const vec3_t origin, const vec3_t angles) { CM_SetInlineModelOrientation(&sv->mapTiles, name, origin, angles); }
/** * @brief Register local entities for SOLID_BSP models like func_breakable or func_door * @note func_breakable, func_door * @sa G_SendEdictsAndBrushModels * @sa EV_ADD_BRUSH_MODEL * @sa CL_SpawnParseEntitystring */ void CL_AddBrushModel (const eventRegister_t *self, struct dbuffer *msg) { le_t *le; int entnum, modelnum1, levelflags, speed, dir; entity_type_t type; const cBspModel_t *model; int angle; vec3_t origin, angles; NET_ReadFormat(msg, self->formatString, &type, &entnum, &modelnum1, &levelflags, &origin, &angles, &speed, &angle, &dir); if (type != ET_BREAKABLE && type != ET_DOOR && type != ET_ROTATING && type != ET_DOOR_SLIDING && type != ET_TRIGGER_RESCUE && type != ET_TRIGGER_NEXTMAP) Com_Error(ERR_DROP, "Invalid le announced via EV_ADD_BRUSH_MODEL type: %i\n", type); else if (modelnum1 > MAX_MODELS || modelnum1 < 1) Com_Error(ERR_DROP, "Invalid le modelnum1 announced via EV_ADD_BRUSH_MODEL\n"); /* check if the ent is already visible */ le = LE_Get(entnum); if (le) Com_Error(ERR_DROP, "le announced a second time - le for entnum %i (type: %i) already exists (via EV_ADD_BRUSH_MODEL)\n", entnum, type); le = LE_Add(entnum); assert(le); le->rotationSpeed = speed / 100.0f; le->slidingSpeed = speed; le->angle = angle; le->dir = dir; le->type = type; le->modelnum1 = modelnum1; le->levelflags = levelflags; le->addFunc = LE_BrushModelAction; LE_SetThink(le, LET_BrushModel); /* The origin and angles are REQUIRED for doors to work! */ VectorCopy(origin, le->origin); /* store the initial position - needed for sliding doors */ VectorCopy(le->origin, le->oldOrigin); VectorCopy(angles, le->angles); Com_sprintf(le->inlineModelName, sizeof(le->inlineModelName), "*%i", le->modelnum1); model = LE_GetClipModel(le); le->model1 = R_FindModel(le->inlineModelName); if (!le->model1) Com_Error(ERR_DROP, "CL_AddBrushModel: Could not register inline model %i", le->modelnum1); /* Transfer model mins and maxs to entity */ VectorCopy(model->mins, le->mins); VectorCopy(model->maxs, le->maxs); VectorSubtract(le->maxs, le->mins, le->size); VecToPos(le->origin, le->pos); /* to allow tracing against this le */ if (!LE_IsNotSolid(le)) { /* This is to help the entity collision code out */ /* Copy entity origin and angles to model*/ CM_SetInlineModelOrientation(cl.mapTiles, le->inlineModelName, le->origin, le->angles); le->contents = CONTENTS_SOLID; CL_RecalcRouting(le); } }