File: SmokeProjectile.cpp

package info (click to toggle)
spring 88.0%2Bdfsg1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 41,524 kB
  • sloc: cpp: 343,114; ansic: 38,414; python: 12,257; java: 12,203; awk: 5,748; sh: 1,204; xml: 997; perl: 405; objc: 192; makefile: 181; php: 134; sed: 2
file content (126 lines) | stat: -rwxr-xr-x 3,203 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#include "System/mmgr.h"

#include "SmokeProjectile.h"

#include "Game/Camera.h"
#include "Game/GlobalUnsynced.h"
#include "Map/Ground.h"
#include "Rendering/GlobalRendering.h"
#include "Rendering/ProjectileDrawer.h"
#include "Rendering/GL/VertexArray.h"
#include "Rendering/Textures/TextureAtlas.h"
#include "Sim/Misc/Wind.h"

CR_BIND_DERIVED(CSmokeProjectile, CProjectile, );

CR_REG_METADATA(CSmokeProjectile,
(
	CR_MEMBER_BEGINFLAG(CM_Config),
		CR_MEMBER(color),
		CR_MEMBER(size),
		CR_MEMBER(startSize),
		CR_MEMBER(sizeExpansion),
		CR_MEMBER(ageSpeed),
	CR_MEMBER_ENDFLAG(CM_Config),
	CR_MEMBER(age),
	CR_RESERVED(8)
));

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSmokeProjectile::CSmokeProjectile()
:	CProjectile(),
	color(0.5f),
	age(0.0f),
	ageSpeed(1.0f),
	size(0.0f),
	startSize(0.0f),
	sizeExpansion(0.0f),
	textureNum(0)
{
	checkCol = false;
}

void CSmokeProjectile::Init(const float3& pos, CUnit* owner)
{
	textureNum = (int) (gu->usRandInt() % projectileDrawer->smoketex.size());

	if (pos.y - ground->GetApproximateHeight(pos.x, pos.z, false) > 10.0f) {
		useAirLos = true;
	}

	if (!owner) {
		alwaysVisible = true;
	}

	CProjectile::Init(pos, owner);
}

CSmokeProjectile::CSmokeProjectile(const float3& pos, const float3& speed, float ttl, float startSize, float sizeExpansion, CUnit* owner, float color):
	CProjectile(pos, speed, owner, false, false, false),
	color(color),
	age(0),
	size(0),
	startSize(startSize),
	sizeExpansion(sizeExpansion)
{
	ageSpeed = 1.0f / ttl;
	checkCol = false;
	castShadow = true;
	textureNum = (int) (gu->usRandInt() % projectileDrawer->smoketex.size());

	if ((pos.y - ground->GetApproximateHeight(pos.x, pos.z, false)) > 10) {
		useAirLos = true;
	}

	if (!owner) {
		alwaysVisible = true;
	}
}



void CSmokeProjectile::Update()
{
	pos += speed;
	pos += wind.GetCurrentWind() * age * 0.05f;
	age += ageSpeed;
	size += sizeExpansion;
	if (size < startSize) {
		size+=(startSize-size) * 0.2f;
	}
	drawRadius = size;
	if (age > 1) {
		age = 1;
		deleteMe = true;
	}
}

void CSmokeProjectile::Draw()
{
	inArray = true;
	unsigned char col[4];
	unsigned char alpha = (unsigned char) ((1 - age) * 255);
	col[0] = (unsigned char) (color * alpha);
	col[1] = (unsigned char) (color * alpha);
	col[2] = (unsigned char) (color * alpha);
	col[3] = (unsigned char) alpha/*-alphaFalloff*globalRendering->timeOffset*/;
	//int frame=textureNum;
	//float xmod=0.125f+(float(int(frame%6)))/16;
	//float ymod=(int(frame/6))/16.0f;

	const float interSize = size + (sizeExpansion * globalRendering->timeOffset);
	const float3 pos1 ((camera->right - camera->up) * interSize);
	const float3 pos2 ((camera->right + camera->up) * interSize);

	#define st projectileDrawer->smoketex[textureNum]
	va->AddVertexTC(drawPos - pos2, st->xstart, st->ystart, col);
	va->AddVertexTC(drawPos + pos1, st->xend,   st->ystart, col);
	va->AddVertexTC(drawPos + pos2, st->xend,   st->yend,   col);
	va->AddVertexTC(drawPos - pos1, st->xstart, st->yend,   col);
	#undef st
}