Skip to content

Commit

Permalink
#5231: Dependency cleanup in entity module. Refactor EntitySettings c…
Browse files Browse the repository at this point in the history
…lass for less code.
  • Loading branch information
codereader committed May 17, 2020
1 parent 71a8d73 commit bbfe1fc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 44 deletions.
1 change: 0 additions & 1 deletion radiant/entity/Doom3Entity.cpp
@@ -1,6 +1,5 @@
#include "Doom3Entity.h"

#include "iradiant.h"
#include "ieclass.h"
#include "debugging/debugging.h"
#include "string/predicate.h"
Expand Down
15 changes: 7 additions & 8 deletions radiant/entity/EntityCreator.cpp
Expand Up @@ -7,8 +7,6 @@
#include "iscenegraph.h"
#include "ieventmanager.h"
#include "inamespace.h"
#include "ifilter.h"
#include "ipreferencesystem.h"

#include "entitylib.h"
#include "gamelib.h"
Expand Down Expand Up @@ -153,20 +151,21 @@ ITargetManagerPtr Doom3EntityCreator::createTargetManager()
}

// RegisterableModule implementation
const std::string& Doom3EntityCreator::getName() const {
const std::string& Doom3EntityCreator::getName() const
{
static std::string _name(MODULE_ENTITYCREATOR);
return _name;
}

const StringSet& Doom3EntityCreator::getDependencies() const {
const StringSet& Doom3EntityCreator::getDependencies() const
{
static StringSet _dependencies;

if (_dependencies.empty()) {
if (_dependencies.empty())
{
_dependencies.insert(MODULE_XMLREGISTRY);
_dependencies.insert(MODULE_MAP);
_dependencies.insert(MODULE_SCENEGRAPH);
_dependencies.insert(MODULE_RENDERSYSTEM);
_dependencies.insert(MODULE_UNDOSYSTEM);
_dependencies.insert(MODULE_GAMEMANAGER);
}

return _dependencies;
Expand Down
53 changes: 22 additions & 31 deletions radiant/entity/EntitySettings.cpp
Expand Up @@ -4,62 +4,53 @@
#include "imainframe.h"

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

namespace entity {
namespace entity
{

EntitySettings::EntitySettings() :
_lightVertexColoursLoaded(false)
{
refreshFromRegistry();

// Register this class as keyobserver
observeKey(RKEY_SHOW_ENTITY_NAMES);
observeKey(RKEY_SHOW_ALL_SPEAKER_RADII);
observeKey(RKEY_SHOW_ALL_LIGHT_RADII);
observeKey(RKEY_DRAG_RESIZE_SYMMETRICALLY);
observeKey(RKEY_ALWAYS_SHOW_LIGHT_VERTICES);
observeKey(RKEY_FREE_OBJECT_ROTATION);
observeKey(RKEY_SHOW_ENTITY_ANGLES);
// 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);
}

void EntitySettings::observeKey(const std::string& key)
void EntitySettings::initialiseAndObserveKey(const std::string& key, bool& targetBool)
{
GlobalRegistry().signalForKey(key).connect(
sigc::mem_fun(this, &EntitySettings::keyChanged)
);
// 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(new EntitySettings);

// Put an assertion here to catch calls after shutdown
assert(_entitySettingsInstancePtr != NULL);
assert(_entitySettingsInstancePtr);

return _entitySettingsInstancePtr;
}

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

void EntitySettings::refreshFromRegistry()
void EntitySettings::onSettingsChanged()
{
_renderEntityNames = registry::getValue<bool>(RKEY_SHOW_ENTITY_NAMES);
_showAllSpeakerRadii = registry::getValue<bool>(RKEY_SHOW_ALL_SPEAKER_RADII);
_showAllLightRadii = registry::getValue<bool>(RKEY_SHOW_ALL_LIGHT_RADII);
_dragResizeEntitiesSymmetrically = registry::getValue<bool>(RKEY_DRAG_RESIZE_SYMMETRICALLY);
_alwaysShowLightVertices = registry::getValue<bool>(RKEY_ALWAYS_SHOW_LIGHT_VERTICES);
_freeObjectRotation = registry::getValue<bool>(RKEY_FREE_OBJECT_ROTATION);
_showEntityAngles = registry::getValue<bool>(RKEY_SHOW_ENTITY_ANGLES);
}

void EntitySettings::keyChanged()
{
refreshFromRegistry();

// Redraw the scene
GlobalMainFrame().updateAllWindows();
}
Expand Down
10 changes: 6 additions & 4 deletions radiant/entity/EntitySettings.h
@@ -1,6 +1,7 @@
#pragma once

#include "iregistry.h"
#include <sigc++/connection.h>
#include <memory>
#include "math/Vector3.h"

Expand All @@ -26,7 +27,7 @@ typedef std::shared_ptr<EntitySettings> EntitySettingsPtr;
* variables accordingly. This can be used as some sort of "cache"
* to avoid slow registry queries during rendering, for instance.
*/
class EntitySettings: public sigc::trackable
class EntitySettings
{
public:
enum LightEditVertexType
Expand Down Expand Up @@ -65,6 +66,8 @@ class EntitySettings: public sigc::trackable

bool _lightVertexColoursLoaded;

std::vector<sigc::connection> _registryConnections;

// Private constructor
EntitySettings();
public:
Expand Down Expand Up @@ -115,9 +118,8 @@ class EntitySettings: public sigc::trackable
static void destroy();

private:
void keyChanged();
void refreshFromRegistry();
void observeKey(const std::string&);
void onSettingsChanged();
void initialiseAndObserveKey(const std::string& key, bool& targetBool);
void loadLightVertexColours();
};

Expand Down

0 comments on commit bbfe1fc

Please sign in to comment.