-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShips.cpp
More file actions
65 lines (58 loc) · 1.14 KB
/
Copy pathShips.cpp
File metadata and controls
65 lines (58 loc) · 1.14 KB
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
#include "Ship.h"
#include "Ships.h"
#include "GuardMutex.h"
#include <Box2D/Box2D.h>
/*****************************************/
Ships::Ships(b2World& world):
m_world(world),
m_index(0),
m_pMutex(SDL_CreateMutex())
{
//nothing
}
/*****************************************/
void Ships::AddShip()
{
GuardMutex guard(m_pMutex);
m_ships.push_back(new Ship(m_world));
}
/*****************************************/
ShipIntf* Ships::Next()
{
GuardMutex guard(m_pMutex);
ShipIntf *pShip = 0;
if(m_index < m_ships.size())
{
pShip = m_ships[m_index];
++m_index;
}
else
{
m_index = 0;
}
return pShip;
}
/*****************************************/
unsigned int Ships::Length() const
{
GuardMutex guard(m_pMutex);
return m_ships.size();
}
/*****************************************/
ShipIntf* Ships::operator[](unsigned int index)
{
GuardMutex guard(m_pMutex);
if(index < m_ships.size())
{
return m_ships[index];
}
else
{
return 0;
}
}
/*****************************************/
Ships::~Ships()
{
SDL_DestroyMutex(m_pMutex);
}