File: ParticleSourceWrapper.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (157 lines) | stat: -rw-r--r-- 3,770 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "particle/ParticleSourceWrapper.h"
#include "particle/ParticleSource.h"

namespace particle
{
	ParticleSourceWrapper::ParticleSourceWrapper(SCP_vector<ParticleSource*>&& sources) : m_sources(std::move(sources))
	{
	}

	ParticleSourceWrapper::ParticleSourceWrapper(ParticleSource* source)
	{
		m_sources.push_back(source);
	}

	ParticleSourceWrapper::ParticleSourceWrapper(ParticleSourceWrapper&& other) noexcept
	{
		*this = std::move(other);
	}

	ParticleSourceWrapper::~ParticleSourceWrapper()
	{

		// Prevent empty wrapper from causing issues
		if (!m_sources.empty())
		{
			Assertion(m_finished, "Source wrapper wasn't finished! Get a coder!\n"
					"(If you hit this then a coder hasn't properly finished creating a particle source)");
		}
	}

	ParticleSourceWrapper& ParticleSourceWrapper::operator=(ParticleSourceWrapper&& other) noexcept
	{
		std::swap(other.m_sources, m_sources);
		return *this;
	}

	void ParticleSourceWrapper::finish()
	{
		// This function is currently only used for debugging but may be extended to do some final adjustments on the sources in the future
#ifndef NDEBUG
		for (auto& source : m_sources)
		{
			Assertion(source->isValid(), "Source is not valid after initializing! Get a coder!\n"
					"(If you hit this it means that a coder hasn't properly initialized a particle source)");
		}
#endif
		for (auto& source : m_sources)
		{
			source->finishCreation();
		}

		m_finished = true;
	}

	void ParticleSourceWrapper::setCreationTimestamp(int timestamp)
	{
		for (auto& source : m_sources)
		{
			source->getTiming()->setCreationTimestamp(timestamp);
		}
	}

	void ParticleSourceWrapper::moveToParticle(const WeakParticlePtr& ptr)
	{
		for (auto& source : m_sources)
		{
			source->getOrigin()->moveToParticle(ptr);
		}
	}

	void ParticleSourceWrapper::moveToObject(const object* obj, const vec3d* d)
	{
		for (auto& source : m_sources)
		{
			source->getOrigin()->moveToObject(obj, d);
		}
	}	

	void ParticleSourceWrapper::moveToSubobject(const object* obj, int subobject, const vec3d* d)
	{
		for (auto& source : m_sources) {
			source->getOrigin()->moveToSubobject(obj, subobject, d);
		}
	}	

	void ParticleSourceWrapper::moveToTurret(const object* obj, int subobject, int fire_pos)
	{
		for (auto& source : m_sources) {
			source->getOrigin()->moveToTurret(obj, subobject, fire_pos);
		}
	}	
	
	void ParticleSourceWrapper::moveToBeam(const object* obj)
	{
		for (auto& source : m_sources)
		{
			source->getOrigin()->moveToBeam(obj);
		}
	}

	void ParticleSourceWrapper::moveTo(const vec3d* pos, const matrix* orientation)
	{
		for (auto& source : m_sources)
		{
			source->getOrigin()->moveTo(pos, orientation);
		}
	}

	void ParticleSourceWrapper::setVelocity(const vec3d* vel)
	{
		for (auto& source : m_sources)
		{
			source->getOrigin()->setVelocity(vel);
		}
	}

	void ParticleSourceWrapper::setOrientationFromNormalizedVec(const vec3d* normalizedDir, bool relative)
	{
		for (auto& source : m_sources)
		{
			source->getOrientation()->setFromNormalizedVector(*normalizedDir, relative);
		}
	}


	void ParticleSourceWrapper::setOrientationFromVec(const vec3d* dir, bool relative)
	{
		for (auto& source : m_sources)
		{
			source->getOrientation()->setFromVector(*dir, relative);
		}
	}

	void ParticleSourceWrapper::setOrientationMatrix(const matrix* mtx, bool relative)
	{
		for (auto& source : m_sources)
		{
			source->getOrientation()->setFromMatrix(*mtx, relative);
		}
	}

	void ParticleSourceWrapper::setOrientationNormal(const vec3d* normal)
	{
		for (auto& source : m_sources)
		{
			source->getOrientation()->setNormal(*normal);
		}
	}

	void ParticleSourceWrapper::setWeaponState(WeaponState state)
	{
		for (auto& source : m_sources)
		{
			source->getOrigin()->setWeaponState(state);
		}
	}
}