Skip to content

Commit

Permalink
Simplify command Signature class, it's just a std::vector now that we…
Browse files Browse the repository at this point in the history
… have std::initializer_list.
  • Loading branch information
codereader committed Jan 14, 2020
1 parent a6d5d7e commit 20402e4
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 66 deletions.
46 changes: 2 additions & 44 deletions include/icommandsystem.h
Expand Up @@ -202,50 +202,8 @@ typedef std::vector<Argument> ArgumentList;
*/
typedef std::function<void (const ArgumentList&)> Function;

// A command signature consists just of arguments, no return types
class Signature :
public std::vector<std::size_t>
{
public:
Signature()
{}

// Additional convenience constructors
Signature(std::size_t type1)
{
push_back(type1);
}

Signature(std::size_t type1, std::size_t type2)
{
push_back(type1);
push_back(type2);
}

Signature(std::size_t type1, std::size_t type2, std::size_t type3)
{
push_back(type1);
push_back(type2);
push_back(type3);
}

Signature(std::size_t type1, std::size_t type2, std::size_t type3, std::size_t type4)
{
push_back(type1);
push_back(type2);
push_back(type3);
push_back(type4);
}

Signature(std::size_t type1, std::size_t type2, std::size_t type3, std::size_t type4, std::size_t type5)
{
push_back(type1);
push_back(type2);
push_back(type3);
push_back(type4);
push_back(type5);
}
};
// A command signature consists just of arguments, return type is always void
typedef std::vector<std::size_t> Signature;

/**
* greebo: Auto-completion information returned by the CommandSystem
Expand Down
4 changes: 2 additions & 2 deletions plugins/script/ScriptingSystem.cpp
Expand Up @@ -458,7 +458,7 @@ void ScriptingSystem::initialiseModule(const ApplicationContext& ctx)
GlobalCommandSystem().addCommand(
"RunScript",
std::bind(&ScriptingSystem::runScriptFile, this, std::placeholders::_1),
cmd::ARGTYPE_STRING
{ cmd::ARGTYPE_STRING }
);

GlobalCommandSystem().addCommand(
Expand All @@ -469,7 +469,7 @@ void ScriptingSystem::initialiseModule(const ApplicationContext& ctx)
GlobalCommandSystem().addCommand(
"RunScriptCommand",
std::bind(&ScriptingSystem::runScriptCommand, this, std::placeholders::_1),
cmd::ARGTYPE_STRING
{ cmd::ARGTYPE_STRING }
);

// Bind the reloadscripts command to the menu
Expand Down
4 changes: 2 additions & 2 deletions radiant/brush/BrushModule.cpp
Expand Up @@ -120,14 +120,14 @@ void BrushModuleImpl::registerBrushCommands()
{
GlobalEventManager().addRegistryToggle("TogTexLock", RKEY_ENABLE_TEXTURE_LOCK);

GlobalCommandSystem().addCommand("BrushMakePrefab", selection::algorithm::brushMakePrefab, cmd::ARGTYPE_INT);
GlobalCommandSystem().addCommand("BrushMakePrefab", selection::algorithm::brushMakePrefab, { cmd::ARGTYPE_INT });

GlobalEventManager().addCommand("BrushCuboid", "BrushCuboid");
GlobalEventManager().addCommand("BrushPrism", "BrushPrism");
GlobalEventManager().addCommand("BrushCone", "BrushCone");
GlobalEventManager().addCommand("BrushSphere", "BrushSphere");

GlobalCommandSystem().addCommand("BrushMakeSided", selection::algorithm::brushMakeSided, cmd::ARGTYPE_INT);
GlobalCommandSystem().addCommand("BrushMakeSided", selection::algorithm::brushMakeSided, { cmd::ARGTYPE_INT });

// Link the Events to the corresponding statements
GlobalEventManager().addCommand("Brush3Sided", "Brush3Sided");
Expand Down
6 changes: 3 additions & 3 deletions radiant/commandsystem/CommandSystem.cpp
Expand Up @@ -44,10 +44,10 @@ void CommandSystem::initialiseModule(const ApplicationContext& ctx)
rMessage() << "CommandSystem::initialiseModule called." << std::endl;

// Add the built-in commands
addCommand("bind", std::bind(&CommandSystem::bindCmd, this, std::placeholders::_1), Signature(ARGTYPE_STRING, ARGTYPE_STRING));
addCommand("unbind", std::bind(&CommandSystem::unbindCmd, this, std::placeholders::_1), ARGTYPE_STRING);
addCommand("bind", std::bind(&CommandSystem::bindCmd, this, std::placeholders::_1), { ARGTYPE_STRING, ARGTYPE_STRING });
addCommand("unbind", std::bind(&CommandSystem::unbindCmd, this, std::placeholders::_1), { ARGTYPE_STRING });
addCommand("listCmds", std::bind(&CommandSystem::listCmds, this, std::placeholders::_1));
addCommand("print", std::bind(&CommandSystem::printCmd, this, std::placeholders::_1), ARGTYPE_STRING);
addCommand("print", std::bind(&CommandSystem::printCmd, this, std::placeholders::_1), { ARGTYPE_STRING });

loadBinds();
}
Expand Down
2 changes: 1 addition & 1 deletion radiant/filters/BasicFilterSystem.cpp
Expand Up @@ -89,7 +89,7 @@ void BasicFilterSystem::initialiseModule(const ApplicationContext& ctx)

// Add the (de-)activate all commands
GlobalCommandSystem().addCommand("SetAllFilterStates",
std::bind(&BasicFilterSystem::setAllFilterStatesCmd, this, std::placeholders::_1), cmd::ARGTYPE_INT);
std::bind(&BasicFilterSystem::setAllFilterStatesCmd, this, std::placeholders::_1), { cmd::ARGTYPE_INT });

// Register two shortcuts
GlobalCommandSystem().addStatement("ActivateAllFilters", "SetAllFilterStates 1", false);
Expand Down
2 changes: 1 addition & 1 deletion radiant/layers/LayerSystem.cpp
Expand Up @@ -524,7 +524,7 @@ void LayerSystem::initialiseModule(const ApplicationContext& ctx)
// Register the "create layer" command
GlobalCommandSystem().addCommand("CreateNewLayer",
std::bind(&LayerSystem::createLayerCmd, this, std::placeholders::_1),
cmd::ARGTYPE_STRING|cmd::ARGTYPE_OPTIONAL);
{ cmd::ARGTYPE_STRING | cmd::ARGTYPE_OPTIONAL });
IEventPtr ev = GlobalEventManager().addCommand("CreateNewLayer", "CreateNewLayer");

GlobalMapModule().signal_mapEvent().connect(
Expand Down
9 changes: 5 additions & 4 deletions radiant/map/Map.cpp
Expand Up @@ -760,10 +760,11 @@ void Map::registerCommands()
GlobalCommandSystem().addCommand("SaveSelected", Map::exportMap);
GlobalCommandSystem().addCommand("ReloadSkins", map::algorithm::reloadSkins);
GlobalCommandSystem().addCommand("ExportSelectedAsModel", map::algorithm::exportSelectedAsModelCmd,
cmd::Signature(cmd::ARGTYPE_STRING, cmd::ARGTYPE_STRING,
cmd::ARGTYPE_INT|cmd::ARGTYPE_OPTIONAL,
cmd::ARGTYPE_INT|cmd::ARGTYPE_OPTIONAL,
cmd::ARGTYPE_INT|cmd::ARGTYPE_OPTIONAL));
{ cmd::ARGTYPE_STRING,
cmd::ARGTYPE_STRING,
cmd::ARGTYPE_INT | cmd::ARGTYPE_OPTIONAL,
cmd::ARGTYPE_INT | cmd::ARGTYPE_OPTIONAL,
cmd::ARGTYPE_INT | cmd::ARGTYPE_OPTIONAL });

GlobalEventManager().addCommand("NewMap", "NewMap");
GlobalEventManager().addCommand("OpenMap", "OpenMap");
Expand Down
4 changes: 2 additions & 2 deletions radiant/patch/PatchCreators.cpp
Expand Up @@ -66,11 +66,11 @@ void Doom3PatchCreator::initialiseModule(const ApplicationContext& ctx)
void Doom3PatchCreator::registerPatchCommands()
{
// First connect the commands to the code
GlobalCommandSystem().addCommand("CreatePatchPrefab", patch::algorithm::createPrefab, cmd::ARGTYPE_STRING);
GlobalCommandSystem().addCommand("CreatePatchPrefab", patch::algorithm::createPrefab, { cmd::ARGTYPE_STRING });

// Two optional integer arguments
GlobalCommandSystem().addCommand("SimplePatchMesh", patch::algorithm::createSimplePatch,
cmd::Signature(cmd::ARGTYPE_INT|cmd::ARGTYPE_OPTIONAL, cmd::ARGTYPE_INT|cmd::ARGTYPE_OPTIONAL));
{ cmd::ARGTYPE_INT | cmd::ARGTYPE_OPTIONAL, cmd::ARGTYPE_INT | cmd::ARGTYPE_OPTIONAL });

GlobalCommandSystem().addCommand("PatchInsertColumnEnd", selection::algorithm::insertPatchColumnsAtEnd);
GlobalCommandSystem().addCommand("PatchInsertColumnBeginning", selection::algorithm::insertPatchColumnsAtBeginning);
Expand Down
14 changes: 7 additions & 7 deletions radiant/selection/algorithm/General.cpp
Expand Up @@ -1043,14 +1043,14 @@ void registerCommands()
GlobalCommandSystem().addCommand("GroupCycleForward", selection::GroupCycle::cycleForward);
GlobalCommandSystem().addCommand("GroupCycleBackward", selection::GroupCycle::cycleBackward);

GlobalCommandSystem().addCommand("TexRotate", rotateTexture, cmd::ARGTYPE_INT|cmd::ARGTYPE_STRING);
GlobalCommandSystem().addCommand("TexScale", scaleTexture, cmd::ARGTYPE_VECTOR2|cmd::ARGTYPE_STRING);
GlobalCommandSystem().addCommand("TexShift", shiftTextureCmd, cmd::ARGTYPE_VECTOR2|cmd::ARGTYPE_STRING);
GlobalCommandSystem().addCommand("TexRotate", rotateTexture, { cmd::ARGTYPE_INT | cmd::ARGTYPE_STRING });
GlobalCommandSystem().addCommand("TexScale", scaleTexture, { cmd::ARGTYPE_VECTOR2 | cmd::ARGTYPE_STRING });
GlobalCommandSystem().addCommand("TexShift", shiftTextureCmd, { cmd::ARGTYPE_VECTOR2 | cmd::ARGTYPE_STRING });

GlobalCommandSystem().addCommand("TexAlign", alignTextureCmd, cmd::ARGTYPE_STRING);
GlobalCommandSystem().addCommand("TexAlign", alignTextureCmd, { cmd::ARGTYPE_STRING });

// Add the nudge commands (one general, four specialised ones)
GlobalCommandSystem().addCommand("NudgeSelected", nudgeSelectedCmd, cmd::ARGTYPE_STRING);
GlobalCommandSystem().addCommand("NudgeSelected", nudgeSelectedCmd, { cmd::ARGTYPE_STRING });

GlobalCommandSystem().addCommand("NormaliseTexture", normaliseTexture);

Expand All @@ -1061,7 +1061,7 @@ void registerCommands()
GlobalCommandSystem().addCommand("FlipTextureX", flipTextureS);
GlobalCommandSystem().addCommand("FlipTextureY", flipTextureT);

GlobalCommandSystem().addCommand("MoveSelectionVertically", moveSelectedCmd, cmd::ARGTYPE_STRING);
GlobalCommandSystem().addCommand("MoveSelectionVertically", moveSelectedCmd, { cmd::ARGTYPE_STRING });

GlobalCommandSystem().addCommand("CurveAppendControlPoint", appendCurveControlPoint);
GlobalCommandSystem().addCommand("CurveRemoveControlPoint", removeCurveControlPoints);
Expand All @@ -1082,7 +1082,7 @@ void registerCommands()
GlobalCommandSystem().addCommand("CreateCurveCatmullRom", createCurveCatmullRom);

GlobalCommandSystem().addCommand("FloorSelection", floorSelection);
GlobalCommandSystem().addCommand("BrushSetDetailFlag", brushSetDetailFlag, cmd::ARGTYPE_STRING);
GlobalCommandSystem().addCommand("BrushSetDetailFlag", brushSetDetailFlag, { cmd::ARGTYPE_STRING });
GlobalCommandSystem().addStatement("BrushMakeDetail", "BrushSetDetailFlag detail", false);
GlobalCommandSystem().addStatement("BrushMakeStructural", "BrushSetDetailFlag structural", false);

Expand Down

0 comments on commit 20402e4

Please sign in to comment.