summaryrefslogtreecommitdiff
path: root/project2/common/sourceObject.cpp
blob: 6ddec89fe5d8a9e9bee405bdafa0a8c3fd13c647 (plain)
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
#include <pch.hpp>
#include "instanceStore.impl.h"
#include "sourceObject.h"
#include "exceptions.h"
#include "safeMapFind.h"
#include "scripts.h"

unsigned int SourceObject::loadOrder = 1;
SimpleMessageException(ComponentNotFound);

SourceObject::SourceObject(ScriptNodePtr p) :
	name(p ? p->value("name", "anon", NULL).as<std::string>() : "anon"),
	order(loadOrder++),
	script(p->script)
{
	script->namedComponents[name] = this;
}

SourceObject::SourceObject(const std::string & n) :
	name(n),
	order(loadOrder++),
	script(NULL)
{
}

void
SourceObject::loadComplete(const CommonObjects *)
{
}

void
SourceObject::send(int eventID) const
{
	for (Events::const_iterator i = events.lower_bound(eventID); i != events.upper_bound(eventID); i++) {
		i->second();
	}
}

void
SourceObject::registerFor(int eventID, const Event & event) const
{
	events.insert(Events::value_type(eventID, event));
}

SourceObject *
SourceObject::findComponent(const std::string & name) const
{
	return safeMapLookup<ComponentNotFound>(script->namedComponents, name);
}

INSTANTIATESTORE(std::string, ComponentLoader);
INSTANTIATESTORE(std::string, ElementLoader);