Subversion Repositories Games.Descent

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 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 "vclip.h"
31
#include "physfs-serial.h"
32
#include "render.h"
33
#include "weapon.h"
34
#include "object.h"
35
#if defined(DXX_BUILD_DESCENT_II)
36
#include "laser.h"
37
#endif
38
 
39
#include "compiler-range_for.h"
40
 
41
//----------------- Variables for video clips -------------------
42
namespace dcx {
43
unsigned                                        Num_vclips;
44
}
45
 
46
namespace dsx {
47
d_vclip_array Vclip;            // General purpose vclips.
48
 
49
//draw an object which renders as a vclip
50
void draw_vclip_object(grs_canvas &canvas, const vcobjptridx_t obj, const fix timeleft, const vclip &vc)
51
{
52
        const auto nf = vc.num_frames;
53
        int bitmapnum = (nf - f2i(fixdiv((nf - 1) * timeleft, vc.play_time))) - 1;
54
 
55
        if (bitmapnum >= vc.num_frames)
56
                bitmapnum = vc.num_frames - 1;
57
 
58
        if (bitmapnum >= 0 )    {
59
                if (vc.flags & VF_ROD)
60
                        draw_object_tmap_rod(canvas, nullptr, obj, vc.frames[bitmapnum]);
61
                else {
62
                        draw_object_blob(canvas, obj, vc.frames[bitmapnum]);
63
                }
64
        }
65
}
66
 
67
void draw_weapon_vclip(const d_vclip_array &Vclip, const weapon_info_array &Weapon_info, grs_canvas &canvas, const vcobjptridx_t obj)
68
{
69
        Assert(obj->type == OBJ_WEAPON);
70
 
71
        const auto lifeleft = obj->lifeleft;
72
        const auto vclip_num = Weapon_info[get_weapon_id(obj)].weapon_vclip;
73
        const auto play_time = Vclip[vclip_num].play_time;
74
        fix modtime = lifeleft % play_time;
75
 
76
        if (is_proximity_bomb_or_player_smart_mine_or_placed_mine(get_weapon_id(obj)))
77
        {               //make prox bombs spin out of sync
78
                int objnum = obj;
79
 
80
                modtime += (lifeleft * (objnum & 7)) / 16;      //add variance to spin rate
81
 
82
                if (modtime > play_time)
83
                        modtime %= play_time;
84
 
85
                if ((objnum&1) ^ ((objnum>>1)&1))                       //make some spin other way
86
                        modtime = play_time - modtime;
87
 
88
        }
89
 
90
        draw_vclip_object(canvas, obj, modtime, Vclip[vclip_num]);
91
}
92
 
93
}
94
 
95
DEFINE_VCLIP_SERIAL_UDT();
96
 
97
namespace dcx {
98
void vclip_read(PHYSFS_File *fp, vclip &vc)
99
{
100
        PHYSFSX_serialize_read(fp, vc);
101
}
102
 
103
#if 0
104
void vclip_write(PHYSFS_File *fp, const vclip &vc)
105
{
106
        PHYSFSX_serialize_write(fp, vc);
107
}
108
#endif
109
}