File: EntitySettings.cpp

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (63 lines) | stat: -rw-r--r-- 2,165 bytes parent folder | download | duplicates (4)
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
#include "EntitySettings.h"

#include "registry/registry.h"
#include "registry/adaptors.h"

namespace entity
{

EntitySettings::EntitySettings() :
	_lightVertexColours(static_cast<std::size_t>(LightEditVertexType::NumberOfVertexTypes))
{
	// Wire up all booleans to update on registry value changes
	initialiseAndObserveKey(RKEY_SHOW_ENTITY_NAMES, _renderEntityNames);
	initialiseAndObserveKey(RKEY_SHOW_ALL_SPEAKER_RADII, _showAllSpeakerRadii);
	initialiseAndObserveKey(RKEY_SHOW_ALL_LIGHT_RADII, _showAllLightRadii);
	initialiseAndObserveKey(RKEY_DRAG_RESIZE_SYMMETRICALLY, _dragResizeEntitiesSymmetrically);
	initialiseAndObserveKey(RKEY_ALWAYS_SHOW_LIGHT_VERTICES, _alwaysShowLightVertices);
	initialiseAndObserveKey(RKEY_FREE_OBJECT_ROTATION, _freeObjectRotation);
	initialiseAndObserveKey(RKEY_SHOW_ENTITY_ANGLES, _showEntityAngles);

	// Initialise the default colours
	_lightVertexColours[static_cast<std::size_t>(LightEditVertexType::StartEndDeselected)] = Vector3(0,1,1);
	_lightVertexColours[static_cast<std::size_t>(LightEditVertexType::StartEndSelected)] = Vector3(0,0,1);
	_lightVertexColours[static_cast<std::size_t>(LightEditVertexType::Inactive)] = Vector3(1,0,0);
	_lightVertexColours[static_cast<std::size_t>(LightEditVertexType::Deselected)] = Vector3(0,1,0);
	_lightVertexColours[static_cast<std::size_t>(LightEditVertexType::Selected)] = Vector3(0,0,1);
}

void EntitySettings::initialiseAndObserveKey(const std::string& key, bool& targetBool)
{
	// Load the initial value from the registry
	targetBool = registry::getValue<bool>(key);

	_registryConnections.emplace_back(registry::observeBooleanKey(key,
		[&]() { targetBool = true; onSettingsChanged(); },
		[&]() { targetBool = false; onSettingsChanged(); })
	);
}

EntitySettingsPtr& EntitySettings::InstancePtr()
{
	static EntitySettingsPtr _entitySettingsInstancePtr;

	if (!_entitySettingsInstancePtr)
	{
		_entitySettingsInstancePtr.reset(new EntitySettings);
	}

	return _entitySettingsInstancePtr;
}

void EntitySettings::destroy()
{
	// free the instance
	InstancePtr().reset();
}

void EntitySettings::onSettingsChanged()
{
	_signalSettingsChanged.emit();
}

} // namespace entity