openmohaa/code/cgame/cg_swipe.cpp

262 lines
7.9 KiB
C++
Raw Permalink Normal View History

2023-04-30 00:02:16 +02:00
/*
===========================================================================
Copyright (C) 2023 the OpenMoHAA team
This file is part of OpenMoHAA source code.
OpenMoHAA source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
OpenMoHAA source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// DESCRIPTION:
// General swiping functions
#include "cg_commands.h"
2023-07-05 21:24:23 +02:00
swipething_t m_swipes[MAX_SWIPES];
extern int current_entity_number;
2023-04-30 00:02:16 +02:00
extern refEntity_t *current_entity;
2023-07-05 21:24:23 +02:00
extern dtiki_t *current_tiki;
extern centity_t *current_centity;
void ClientGameCommandManager::SwipeOn(Event *ev)
{
// Make a swipe for this if available
int i;
int freeswipe = -1;
str tagname_start, tagname_end;
qhandle_t shader;
if (ev->NumArgs() != 4) {
return;
}
shader = cgi.R_RegisterShader(ev->GetString(1));
tagname_start = ev->GetString(2);
tagname_end = ev->GetString(3);
for (i = 0; i < MAX_SWIPES; i++) {
swipething_t& swipe = m_swipes[i];
if (!swipe.enabled
|| ((swipe.entitynum == current_entity_number) && (tagname_start == swipe.tagname_start)
&& (tagname_end == swipe.tagname_end) && (shader == swipe.shader))) {
freeswipe = i;
break;
}
}
if (freeswipe == -1) {
return;
}
swipething_t& swipe = m_swipes[freeswipe];
if (!swipe.enabled) {
swipe.Init();
swipe.enabled = qtrue;
swipe.entitynum = current_entity_number;
}
swipe.shader = cgi.R_RegisterShader(ev->GetString(1));
swipe.tagname_start = ev->GetString(2);
swipe.tagname_end = ev->GetString(3);
swipe.life = ev->GetFloat(4) * 1000.f;
if (current_centity) {
current_centity->clientFlags |= CF_UPDATESWIPE;
}
}
void ClientGameCommandManager::SwipeOff(Event *ev)
{
qboolean was_enabled;
int i;
was_enabled = qfalse;
for (i = 0; i < MAX_SWIPES; i++) {
swipething_t& swipe = m_swipes[i];
if (swipe.enabled && swipe.entitynum == current_entity_number) {
swipe.enabled = qfalse;
was_enabled = qtrue;
}
}
if (was_enabled) {
//cgi.R_SwipeBegin ( 0.f, 0.f, -1 );
//cgi.R_SwipeEnd ();
if (current_centity) {
current_centity->clientFlags &= ~CF_UPDATESWIPE;
}
}
}
void ClientGameCommandManager::Swipe(Event *ev)
{
// This does a swipe effect on the entity
int i, swipenum;
orientation_t _or;
int tagnum_start, tagnum_end;
qboolean add_cnt_point = qfalse;
vec3_t tmp;
assert(current_entity);
assert(current_tiki);
if (!current_entity || !current_tiki) {
return;
}
// Let's find us a new (or current) swipe
for (swipenum = 0; swipenum < MAX_SWIPES; swipenum++) {
swipething_t& swipe = m_swipes[swipenum];
if (swipe.enabled && swipe.entitynum == current_entity_number) {
while (swipe.num_live_swipes > 1) {
i = (swipe.first_swipe + 1) % MAX_SWIPE_POINTS;
swipepoint_t& swipepoint = swipe.swipepoints[i];
if (swipepoint.time < cg.time - swipe.life) {
// then let's delete the previous
swipe.first_swipe = (swipe.first_swipe + 1) % MAX_SWIPE_POINTS;
swipe.num_live_swipes--;
} else {
break;
}
2023-04-30 00:02:16 +02:00
}
2023-07-05 21:24:23 +02:00
if (swipe.num_live_swipes == 1) {
swipepoint_t& swipepoint = swipe.swipepoints[swipe.first_swipe];
if (swipepoint.time < cg.time - swipe.life) {
swipe.num_live_swipes = 0;
}
2023-04-30 00:02:16 +02:00
}
2023-07-05 21:24:23 +02:00
swipe.cntPoint.time = cg.time;
VectorCopy(current_entity->origin, swipe.cntPoint.points[0]);
tagnum_start = cgi.Tag_NumForName(current_tiki, swipe.tagname_start.c_str());
_or = cgi.TIKI_Orientation(current_entity, tagnum_start);
// Clear out the points
VectorClear(tmp);
VectorClear(swipe.cntPoint.points[0]);
VectorClear(swipe.cntPoint.points[1]);
if (ev->NumArgs() > 0) {
VectorCopy(ev->GetVector(1), tmp);
} else {
VectorCopy(current_entity->origin, tmp);
2023-04-30 00:02:16 +02:00
}
2023-07-05 21:24:23 +02:00
// Transform the origin of the tag by the axis of the entity and add it to the origin of the entity
for (i = 0; i < 3; i++) {
VectorMA(tmp, _or.origin[i], current_entity->axis[i], tmp);
2023-04-30 00:02:16 +02:00
}
2023-07-05 21:24:23 +02:00
// Copy tmp into the startpoint
VectorCopy(tmp, swipe.cntPoint.points[0]);
2023-04-30 00:02:16 +02:00
2023-07-05 21:24:23 +02:00
tagnum_end = cgi.Tag_NumForName(current_tiki, swipe.tagname_end.c_str());
_or = cgi.TIKI_Orientation(current_entity, tagnum_end);
if (ev->NumArgs() > 0) {
VectorCopy(ev->GetVector(1), tmp);
} else {
VectorCopy(current_entity->origin, tmp);
}
2023-04-30 00:02:16 +02:00
2023-07-05 21:24:23 +02:00
// Transform the origin of the tag by the axis of the entity and add it to the origin of the entity
for (i = 0; i < 3; i++) {
VectorMA(tmp, _or.origin[i], current_entity->axis[i], tmp);
2023-04-30 00:02:16 +02:00
}
2023-07-05 21:24:23 +02:00
// Copy tmp into the startpoint
VectorCopy(tmp, swipe.cntPoint.points[1]);
2023-04-30 00:02:16 +02:00
2023-07-05 21:24:23 +02:00
if (swipe.num_live_swipes == 0) {
add_cnt_point = qtrue;
} else {
float deltime = swipe.life / float(MAX_SWIPES);
swipepoint_t& lastpoint =
swipe.swipepoints[(swipe.first_swipe + swipe.num_live_swipes - 1) % MAX_SWIPE_POINTS];
2023-04-30 00:02:16 +02:00
2023-07-05 21:24:23 +02:00
if (swipe.cntPoint.time - lastpoint.time >= deltime) {
add_cnt_point = qtrue;
}
2023-04-30 00:02:16 +02:00
}
2023-07-05 21:24:23 +02:00
cgi.R_SwipeBegin(cg.time, swipe.life, swipe.shader);
2023-04-30 00:02:16 +02:00
2023-07-05 21:24:23 +02:00
if (add_cnt_point) {
swipepoint_t& swipepoint =
swipe.swipepoints[(swipe.first_swipe + swipe.num_live_swipes) % MAX_SWIPE_POINTS];
swipepoint = swipe.cntPoint;
if (swipe.num_live_swipes == MAX_SWIPE_POINTS) {
swipe.first_swipe = (swipe.first_swipe + 1) % MAX_SWIPE_POINTS;
} else {
swipe.num_live_swipes++;
}
2023-04-30 00:02:16 +02:00
}
2023-07-05 21:24:23 +02:00
for (i = 0; i != swipe.num_live_swipes; i++) {
swipepoint_t& swipepoint = swipe.swipepoints[(swipe.first_swipe + i) % MAX_SWIPE_POINTS];
2023-04-30 00:02:16 +02:00
2023-07-05 21:24:23 +02:00
cgi.R_SwipePoint(swipepoint.points[0], swipepoint.points[1], swipepoint.time);
}
if (!add_cnt_point) {
cgi.R_SwipePoint(swipe.cntPoint.points[0], swipe.cntPoint.points[1], swipe.cntPoint.time);
}
2023-04-30 00:02:16 +02:00
2023-07-05 21:24:23 +02:00
cgi.R_SwipeEnd();
}
}
}
2023-04-30 00:02:16 +02:00
2023-07-05 21:24:23 +02:00
void ClientGameCommandManager::ClearSwipes(void)
2023-04-30 00:02:16 +02:00
2023-07-05 21:24:23 +02:00
{
int i;
2023-04-30 00:02:16 +02:00
2023-07-05 21:24:23 +02:00
for (i = 0; i < MAX_SWIPES; i++) {
swipething_t& swipe = m_swipes[i];
2023-04-30 00:02:16 +02:00
2023-07-05 21:24:23 +02:00
swipe.enabled = qfalse;
}
2023-04-30 00:02:16 +02:00
2023-07-05 21:24:23 +02:00
cgi.R_SwipeBegin(0.f, 0.f, -1);
cgi.R_SwipeEnd();
}
2023-04-30 00:02:16 +02:00
/*
===================
CG_ClearSwipes
This is called at startup and for tournement restarts
===================
*/
2023-07-05 21:24:23 +02:00
void CG_ClearSwipes(void)
{
commandManager.ClearSwipes();
}