Debian Codegraph @

Descent3/splinter.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20 #include "fireball.h"
21 #include "object.h"
22 #include "splinter.h"
23 #include "polymodel.h"
24 #include "renderer.h"
25 #include "gametexture.h"
26
27 #include "Macros.h"
28 #include <stdlib.h>
29
30 #include "psrand.h"
31
32 #include <algorithm>
33
34 // Given an object, renders the representation of this splinter
35 void DrawSplinterObject(object *obj) {
36 ASSERT(obj->type == OBJ_SPLINTER);
37 int i;
38 poly_model *pm = &Poly_models[obj->id];
39 bsp_info *sm = &pm->submodel[obj->ctype.splinter_info.subobj_num];
40 int facenum = obj->ctype.splinter_info.facenum;
41 vector world_verts[MAX_VERTS_PER_SPLINTER];
42 vector temp_vec;
43 g3Point pnts[MAX_VERTS_PER_SPLINTER];
44 g3Point *pntlist[MAX_VERTS_PER_SPLINTER];
45
46 int limit = std::min<int>(MAX_VERTS_PER_SPLINTER, sm->faces[facenum].nverts);
47 float lifenorm = 1.0 - ((obj->lifetime - obj->lifeleft) / obj->lifetime);
48
49 rend_SetLighting(LS_NONE);
50 rend_SetAlphaType(AT_CONSTANT);
51 rend_SetAlphaValue(255 * lifenorm);
52 rend_SetTextureType(TT_LINEAR);
53
54 lifenorm = 1.0;
55
56 for (i = 0; i < limit; i++) {
57 // Scale a vert based on the life of the object
58 temp_vec = obj->ctype.splinter_info.verts[i] * lifenorm;
59
60 vm_MatrixMulVector(&world_verts[i], &temp_vec, &obj->orient);
61
62 world_verts[i] += obj->pos;
63 g3_RotatePoint(&pnts[i], &world_verts[i]);
64 pntlist[i] = &pnts[i];
65 pnts[i].p3_u = sm->faces[facenum].u[i];
66 pnts[i].p3_v = sm->faces[facenum].v[i];
67 }
68
69 int bm_handle = GetTextureBitmap(pm->textures[sm->faces[facenum].texnum], 0);
70 g3_DrawPoly(limit, pntlist, bm_handle);
71 }
72
73 // do whatever needs to be done for this piece of splinter for this frame
74 void DoSplinterFrame(object *obj) {
75 ASSERT(obj->control_type == CT_SPLINTER);
76
77 if ((obj->lifeleft <= 0.0) && ((ps_rand() % 2) == 0)) {
78 // Mark the object to die
79 SetObjectDeadFlag(obj);
80 } else {
81 // Create smoke for some splinters
82 if (((obj - Objects) % 8) == 0) {
83 if (ps_rand() % 4) {
84 int type = ((obj - Objects) % 2) ? GetRandomSmallExplosion() : BLACK_SMOKE_INDEX;
85 CreateFireball(&obj->pos, type, obj->roomnum, VISUAL_FIREBALL);
86 }
87 }
88 }
89 }