dxx-rebirth/similar/main/vclip.cpp
Kp 1f333868eb Fix proximity bomb failure-to-spin
Commit 7d36df315e restructured
draw_weapon_vclip, but unintentionally broke the spin of proximity bombs
because `modtime` could exceed `play_time * 2`, causing
`draw_vclip_object` to clamp `bitmapnum` to the last frame of the
animation.  Switch from `-=` to `%=` so that modtime is always brought
back in range.

Reported-by: Descender1032 <https://forum.dxx-rebirth.com/showthread.php?tid=1005>
Fixes: 7d36df315e ("Simplify draw_weapon_vclip")
2017-12-02 04:31:26 +00:00

110 lines
3 KiB
C++

/*
* Portions of this file are copyright Rebirth contributors and licensed as
* described in COPYING.txt.
* Portions of this file are copyright Parallax Software and licensed
* according to the Parallax license below.
* See COPYING.txt for license details.
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
*/
/*
*
* Routines for vclips.
*
*/
#include <stdlib.h>
#include "dxxerror.h"
#include "inferno.h"
#include "vclip.h"
#include "physfs-serial.h"
#include "weapon.h"
#include "object.h"
#if defined(DXX_BUILD_DESCENT_II)
#include "laser.h"
#endif
#include "compiler-range_for.h"
//----------------- Variables for video clips -------------------
namespace dcx {
unsigned Num_vclips;
}
namespace dsx {
array<vclip, VCLIP_MAXNUM> Vclip; // General purpose vclips.
//draw an object which renders as a vclip
void draw_vclip_object(grs_canvas &canvas, const vcobjptridx_t obj, const fix timeleft, const int lighted, const vclip &vc)
{
const auto nf = vc.num_frames;
int bitmapnum = (nf - f2i(fixdiv((nf - 1) * timeleft, vc.play_time))) - 1;
if (bitmapnum >= vc.num_frames)
bitmapnum = vc.num_frames - 1;
if (bitmapnum >= 0 ) {
if (vc.flags & VF_ROD)
draw_object_tmap_rod(canvas, obj, vc.frames[bitmapnum], lighted);
else {
Assert(lighted==0); //blob cannot now be lighted
draw_object_blob(canvas, obj, vc.frames[bitmapnum]);
}
}
}
void draw_weapon_vclip(grs_canvas &canvas, const vcobjptridx_t obj)
{
Assert(obj->type == OBJ_WEAPON);
const auto lifeleft = obj->lifeleft;
const auto vclip_num = Weapon_info[get_weapon_id(obj)].weapon_vclip;
const auto play_time = Vclip[vclip_num].play_time;
fix modtime = lifeleft % play_time;
if (is_proximity_bomb_or_smart_mine_or_placed_mine(get_weapon_id(obj)))
{ //make prox bombs spin out of sync
int objnum = obj;
modtime += (lifeleft * (objnum & 7)) / 16; //add variance to spin rate
if (modtime > play_time)
modtime %= play_time;
if ((objnum&1) ^ ((objnum>>1)&1)) //make some spin other way
modtime = play_time - modtime;
}
draw_vclip_object(canvas, obj, modtime, 0, Vclip[vclip_num]);
}
}
DEFINE_VCLIP_SERIAL_UDT();
namespace dcx {
void vclip_read(PHYSFS_File *fp, vclip &vc)
{
PHYSFSX_serialize_read(fp, vc);
}
#if 0
void vclip_write(PHYSFS_File *fp, const vclip &vc)
{
PHYSFSX_serialize_write(fp, vc);
}
#endif
}