File: object.h

package info (click to toggle)
btanks 0.9.8083-8
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 43,584 kB
  • sloc: cpp: 46,425; ansic: 12,005; xml: 4,262; python: 313; sh: 13; makefile: 13
file content (143 lines) | stat: -rw-r--r-- 4,020 bytes parent folder | download | duplicates (5)
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
#ifndef CLUNK_OBJECT_H__
#define CLUNK_OBJECT_H__

/* libClunk - cross-platform 3D audio API built on top SDL library
 * Copyright (C) 2007-2008 Netive Media Group
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <string>
#include <map>
#include "export_clunk.h"
#include "v3.h"

namespace clunk {
class Context;
class Source;

/*! 
	\brief Object containing sources.
	Objects - class containing several playing sources and controlling its behaviour
*/

class CLUNKAPI Object {
public: 
	friend struct DistanceOrder;
	struct DistanceOrder {
		v3<float> listener;
		DistanceOrder(const v3<float> &listener) : listener(listener) {}

		inline bool operator()(const Object *a, const Object * b) const {
			return listener.quick_distance(a->position) < listener.quick_distance(b->position); 
		}
	};
	///dtor, do not forget to delete object if you do not need it anymore
	~Object();

	/*! 
		\brief updates object's position, velocity and direction at once.
		\param[in] pos position
	*/
	void update(const v3<float> &pos, const v3<float> &vel, const v3<float> &dir);
	
	/*! 
		\brief updates object's position
		\param[in] pos position
	*/
	void set_position(const v3<float> &pos);

	/*! 
		\brief updates object's velocity
		\param[in] vel velocity
	*/
	void set_velocity(const v3<float> &vel);
	
	/*! 
		\brief updates object's direction
		\param[in] dir velocity
	*/
	void set_direction(const v3<float> &dir);
	
	/*! 
		\brief plays given source
		\param[in] name any name you want, just for your confort :)
		\param[in] source source to be played, do not delete it, clunk::Object will delete it automatically.
	*/
	void play(const std::string &name, Source *source);
	/*!
		\brief returns status of the given source. 
		\param[in] name source name
	*/
	bool playing(const std::string &name) const;
	/*! 
		\brief cancels given source
		\param[in] name source name
		\param[in] fadeout length of the fadeout effect to avoid clicks. 
	*/
	void cancel(const std::string &name, const float fadeout = 0.1f);

	/*! 
		\brief cancels all sources for this object.
		\param[in] force quick fadeout for the all sources.
		\param[in] fadeout length of the fadeout effect to avoid clicks. seconds.
	*/
	void cancel_all(bool force = false, const float fadeout = 0.1f);
	/*! 
		\brief fades out given source
		\param[in] name source name
		\param[in] fadeout length of the fadeout effect. seconds.
	*/
	void fade_out(const std::string &name, const float fadeout = 0.1f);

	/// returns if any sources are playing now.
	bool active() const;
	
	///marks objects for autodeletion.
	/*! 
		
		If you do not want to delete objects explicitly (this immediately cancels all sources), you could 
		call this method and forget pointer. clunk::Context automatically deletes your object after all 
		sources stop.
	*/
	void autodelete();
	/*! 
		\brief sets loop flag
		\param[in] name source name
		\param[in] loop repeat source's sound
	*/
	void set_loop(const std::string &name, const bool loop);
	/*!
		\brief returns loop status
		\param[in] name source name
	*/
	bool get_loop(const std::string &name);

private: 
	friend class Context;
	
	Object(Context *context);
	Context *context;
	v3<float> position, velocity, direction;

	typedef std::multimap<const std::string, Source *> Sources;
	Sources sources;
	
	bool dead;
};
}

#endif