Debian Codegraph @

similar/main/vclip.cpp

raw
1 /*
2 * Portions of this file are copyright Rebirth contributors and licensed as
3 * described in COPYING.txt.
4 * Portions of this file are copyright Parallax Software and licensed
5 * according to the Parallax license below.
6 * See COPYING.txt for license details.
7
8 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
9 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
10 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
11 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
12 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
13 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
14 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
15 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
16 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
17 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
18 */
19
20 /*
21 *
22 * Routines for vclips.
23 *
24 */
25
26
27 #include <stdlib.h>
28 #include "dxxerror.h"
29 #include "inferno.h"
30 #include "laser.h"
31 #include "vclip.h"
32 #include "physfs-serial.h"
33 #include "render.h"
34 #include "weapon.h"
35 #include "object.h"
36
37 //----------------- Variables for video clips -------------------
38 namespace dcx {
39 unsigned Num_vclips;
40
41 vclip_index build_vclip_index_from_untrusted(const std::size_t i)
42 {
43 const auto r = Vclip.valid_index(i);
44 return r ? *r : vclip_index::None;
45 }
46
47 }
48
49 namespace dsx {
50 d_vclip_array Vclip; // General purpose vclips.
51
52 //draw an object which renders as a vclip
53 void draw_vclip_object(grs_canvas &canvas, const vcobjptridx_t obj, const fix timeleft, const vclip &vc)
54 {
55 const auto nf = vc.num_frames;
56 int bitmapnum = (nf - f2i(fixdiv((nf - 1) * timeleft, vc.play_time))) - 1;
57
58 if (bitmapnum >= vc.num_frames)
59 bitmapnum = vc.num_frames - 1;
60
61 if (bitmapnum >= 0 ) {
62 if (vc.flags & VF_ROD)
63 draw_object_tmap_rod(canvas, nullptr, obj, vc.frames[bitmapnum]);
64 else {
65 draw_object_blob(GameBitmaps, *Viewer, canvas, obj, vc.frames[bitmapnum]);
66 }
67 }
68 }
69
70 void draw_weapon_vclip(const d_vclip_array &Vclip, const weapon_info_array &Weapon_info, grs_canvas &canvas, const vcobjptridx_t obj)
71 {
72 Assert(obj->type == OBJ_WEAPON);
73
74 const auto lifeleft = obj->lifeleft;
75 const auto vclip_num = Weapon_info[get_weapon_id(obj)].weapon_vclip;
76 const auto play_time = Vclip[vclip_num].play_time;
77 fix modtime = lifeleft % play_time;
78
79 if (is_proximity_bomb_or_player_smart_mine_or_placed_mine(get_weapon_id(obj)))
80 { //make prox bombs spin out of sync
81 int objnum = obj;
82
83 modtime += (lifeleft * (objnum & 7)) / 16; //add variance to spin rate
84
85 if (modtime > play_time)
86 modtime %= play_time;
87
88 if ((objnum&1) ^ ((objnum>>1)&1)) //make some spin other way
89 modtime = play_time - modtime;
90
91 }
92
93 draw_vclip_object(canvas, obj, modtime, Vclip[vclip_num]);
94 }
95
96 }
97
98 DEFINE_VCLIP_SERIAL_UDT();
99
100 namespace dcx {
101
102 void vclip_read(const NamedPHYSFS_File fp, vclip &vc)
103 {
104 PHYSFSX_serialize_read(fp, vc);
105 }
106
107 #if 0
108 void vclip_write(PHYSFS_File *fp, const vclip &vc)
109 {
110 PHYSFSX_serialize_write(fp, vc);
111 }
112 #endif
113 }