1
00:00:01,003 --> 00:00:02,005
- [Instructor] Hi, welcome

2
00:00:02,005 --> 00:00:04,006
to Populating the Sound Emitters.

3
00:00:04,006 --> 00:00:06,003
In the previous video we learned

4
00:00:06,003 --> 00:00:08,001
building the sound manager class

5
00:00:08,001 --> 00:00:09,009
and adding it to the game engine.

6
00:00:09,009 --> 00:00:11,004
In this video we will be coding

7
00:00:11,004 --> 00:00:13,007
the populateEmitters function.

8
00:00:13,007 --> 00:00:15,004
Let's get started then.

9
00:00:15,004 --> 00:00:17,007
First, open the engine.h file

10
00:00:17,007 --> 00:00:18,009
and add a new prototype

11
00:00:18,009 --> 00:00:21,004
for a populateEmitters function.

12
00:00:21,004 --> 00:00:23,004
After bool detectCollision,

13
00:00:23,004 --> 00:00:26,003
write a comment, make a
vector of the best places

14
00:00:26,003 --> 00:00:29,007
to emit sounds from,

15
00:00:29,007 --> 00:00:32,005
void populateEmitters vector

16
00:00:32,005 --> 00:00:37,002
Vector2f& vSoundEmitters,

17
00:00:37,002 --> 00:00:40,006
int** arrayLevel.

18
00:00:40,006 --> 00:00:42,006
Next, write another comment,

19
00:00:42,006 --> 00:00:46,000
a vector of Vector2f for
the fire emitter locations,

20
00:00:46,000 --> 00:00:51,007
then vector Vector2f m_FireEmitters.

21
00:00:51,007 --> 00:00:53,006
So here we've added a new prototype

22
00:00:53,006 --> 00:00:55,005
for a populateEmitters function,

23
00:00:55,005 --> 00:00:59,006
and a new STL vector of Vector2f objects.

24
00:00:59,006 --> 00:01:01,008
The populateEmitters function

25
00:01:01,008 --> 00:01:02,009
takes as a parameter a vector

26
00:01:02,009 --> 00:01:05,005
of Vector2f objects, as well as a pointer

27
00:01:05,005 --> 00:01:08,007
to int, a two dimensional array.

28
00:01:08,007 --> 00:01:10,002
The vector will hold the location

29
00:01:10,002 --> 00:01:11,009
of each emitter in a level,

30
00:01:11,009 --> 00:01:14,001
and the array is our
two dimensional array,

31
00:01:14,001 --> 00:01:16,004
which holds the layout of a level.

32
00:01:16,004 --> 00:01:19,002
Let's code the populateEmitters function.

33
00:01:19,002 --> 00:01:21,005
The job of the populateEmitters function

34
00:01:21,005 --> 00:01:23,000
is to scan through all the elements

35
00:01:23,000 --> 00:01:26,001
of arrayLevel and decide
where to put the emitters.

36
00:01:26,001 --> 00:01:30,000
It will store its results
in m_FireEmitters.

37
00:01:30,000 --> 00:01:32,000
Now, right click source files

38
00:01:32,000 --> 00:01:35,004
in the solution explorer
and select add new item.

39
00:01:35,004 --> 00:01:39,000
In the add new item window click C++ file,

40
00:01:39,000 --> 00:01:40,005
and then in the name field

41
00:01:40,005 --> 00:01:43,009
type PopulateEmitters.

42
00:01:43,009 --> 00:01:46,001
Lastly, click add button.

43
00:01:46,001 --> 00:01:49,008
Now we can code the new
function, populateEmitters.

44
00:01:49,008 --> 00:01:52,006
Add the code in its entirety.

45
00:01:52,006 --> 00:01:55,004
We'll study the code and then discuss it.

46
00:01:55,004 --> 00:01:57,007
This is the highlighted code.

47
00:01:57,007 --> 00:02:00,006
Some of it might appear
complex at first glance.

48
00:02:00,006 --> 00:02:02,005
Understanding the technique we used

49
00:02:02,005 --> 00:02:05,003
to choose where an emitter
will make it simpler.

50
00:02:05,003 --> 00:02:07,008
In our levels, there are
regularly large blocks

51
00:02:07,008 --> 00:02:09,001
of fire tiles.

52
00:02:09,001 --> 00:02:10,007
In one of the levels I designed,

53
00:02:10,007 --> 00:02:13,007
there are more than 30
fire tiles together.

54
00:02:13,007 --> 00:02:14,007
This code makes sure

55
00:02:14,007 --> 00:02:16,002
that there is only one emitter

56
00:02:16,002 --> 00:02:18,000
within a given rectangle.

57
00:02:18,000 --> 00:02:20,003
This rectangle is stored
in previousEmitter

58
00:02:20,003 --> 00:02:23,004
and is 300 pixels by 300 pixels.

59
00:02:23,004 --> 00:02:25,006
It then sets up a nested for loop

60
00:02:25,006 --> 00:02:26,009
that loops through arrayLevel

61
00:02:26,009 --> 00:02:28,008
looking for fire tiles.

62
00:02:28,008 --> 00:02:31,007
When it finds one with
the help of this if loop,

63
00:02:31,007 --> 00:02:34,003
that is fire is present, it makes sure

64
00:02:34,003 --> 00:02:36,008
that it does not intersect
with previousEmitter

65
00:02:36,008 --> 00:02:39,001
using this highlighted code.

66
00:02:39,001 --> 00:02:41,006
Only then does it use
the pushback function

67
00:02:41,006 --> 00:02:45,006
to add another emitter
to feed sound emitters.

68
00:02:45,006 --> 00:02:48,005
After doing so, it also
updates previousEmitter

69
00:02:48,005 --> 00:02:51,006
to avoid getting large
clusters of sound emitters.

70
00:02:51,006 --> 00:02:55,000
Great, that's all about
populating sound emitters.

71
00:02:55,000 --> 00:02:58,007
In this video we coded the
populateEmitters function.

72
00:02:58,007 --> 00:03:01,007
Let's make some noise now,
if you know what I mean.

