Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Feat commander #158

Open
wants to merge 66 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
485d58e
Initial rough draft for a command manager, running into an error and …
apachano Oct 12, 2019
6a0f6b1
added brief to class
apachano Oct 12, 2019
aa476da
merge develop into feat-commander
apachano Oct 16, 2019
c292f0e
merging develop
apachano Oct 20, 2019
369e3d8
Merge branch 'develop' of github.com:GentenStudios/QuartzEngine into …
apachano Oct 23, 2019
4cbd4b7
Commander functionally registers and runs a command
apachano Oct 23, 2019
e178fe7
fix test prints formatting
apachano Oct 23, 2019
32aad16
Add post, a loop that executes commands from the terminal
apachano Oct 23, 2019
4d15a69
fixing code to respect the standard (no need to put ; after if or for…
SuperFola Oct 23, 2019
66e7b58
fixing build
SuperFola Oct 23, 2019
a0b1754
add find(command) and ability to overwrite commands
apachano Oct 24, 2019
92ac3ac
Add m_help and getHelp()'
apachano Oct 24, 2019
c60662c
Add ability to pass arguments to fundcitons
apachano Oct 24, 2019
61b8087
stuck -> attempt to register help command
apachano Oct 24, 2019
a9b7db3
Create book object to store arrays, commander accepts stream as argument
Oct 27, 2019
bab1f2a
Clean up documentation and output
apachano Oct 27, 2019
32131d9
Remove testing sandbox for pull request
apachano Oct 27, 2019
b1acce2
Merge branch 'develop' of github.com:GentenStudios/QuartzEngine into …
apachano Oct 27, 2019
c1b9fb5
Document functions, rename book counter to page, add curly brackets t…
apachano Oct 27, 2019
ec6ecec
ran clang-format :,(
apachano Oct 27, 2019
9bd6a1c
tydef'd function definition
apachano Oct 27, 2019
957435b
updating commander
SuperFola Oct 27, 2019
d30ffe5
quick fix
SuperFola Oct 27, 2019
c14f906
Revert "quick fix"
apachano Oct 29, 2019
e63bdd2
rt "updating commander"
apachano Oct 29, 2019
75900a2
Merge branch 'develop' of github.com:GentenStudios/QuartzEngine into …
apachano Oct 29, 2019
605c1cc
Add const, change reg() to add()
apachano Oct 29, 2019
97d11c2
Remove Sandbox for PR to develop
apachano Oct 29, 2019
b525c84
Remove Sandbox for PR to develop
apachano Oct 29, 2019
d4afec4
Per PR review, removing commented out test code
apachano Oct 29, 2019
e693aee
Run clang-format
apachano Oct 29, 2019
569bca6
Per PR: Clean up constexpr naming convention
apachano Oct 29, 2019
0d50331
Per PR: Document return values, remove return where not needed
apachano Oct 29, 2019
754f84a
re-add SDL
apachano Oct 30, 2019
2195b06
re-add SDL
apachano Oct 30, 2019
c7d43a4
change functions that dont need to return int to return bool
apachano Oct 30, 2019
01195e8
change functions that dont need to return int to return bool
apachano Oct 30, 2019
77dbcdb
Run clang-format
apachano Oct 30, 2019
5e985cd
Fix check on return from list() in run()
apachano Oct 30, 2019
9719005
Merge branch 'develop' into feat-commander
apachano Dec 2, 2019
aa5f73b
save
apachano Dec 2, 2019
8da20f5
remove mis-spelled folder
apachano Dec 2, 2019
50ac7c0
merge Develop
apachano Dec 2, 2019
f44d5f4
Broken, need to change voxels to static
apachano Dec 2, 2019
a79bc72
Change block registry to singleton
apachano Dec 4, 2019
5df0250
Implemented singleton so registry can be grabbed anywhere, Blacklegi …
apachano Dec 8, 2019
6cf4d2b
implement Quartz singleton class
apachano Dec 8, 2019
3f52473
Merge pull request #181 from GentenStudios/feat-voxels-static
apachano Dec 8, 2019
b96ddec
merge from feat-voxels
apachano Dec 8, 2019
f87d344
Remove test code
apachano Dec 8, 2019
bb473eb
Merge pull request #182 from GentenStudios/feat-voxels-static
apachano Dec 8, 2019
2691e5a
Fuck this
apachano Dec 8, 2019
3186610
Merge branch 'feat-voxels' of github.com:GentenStudios/QuartzEngine i…
apachano Dec 8, 2019
2f5b70a
take 3 - push_back not [i]
apachano Dec 8, 2019
a24b888
Merge branch 'feat-voxels' of github.com:GentenStudios/QuartzEngine i…
apachano Dec 8, 2019
93f0292
Merge branch 'feat-voxels' of github.com:GentenStudios/QuartzEngine i…
apachano Dec 8, 2019
882a3db
save
apachano Dec 8, 2019
08406de
remove system file, add client back to cmake
apachano Dec 8, 2019
aa984e1
formatting
apachano Dec 8, 2019
48075a9
clang-format
apachano Dec 8, 2019
6a9711d
formatting
apachano Dec 8, 2019
389fd5e
Merge branch 'feat-voxels' of github.com:GentenStudios/QuartzEngine i…
apachano Dec 8, 2019
6c3b94c
She is alive! (Fuck vectors)
apachano Dec 8, 2019
ce812c1
pre-save before attempting to turn command book into singleton
apachano Dec 8, 2019
4c819bc
Implement singleton in command book
apachano Dec 8, 2019
36f61df
clang-format
apachano Dec 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)

add_subdirectory(Quartz)
add_subdirectory(QuartzSandbox)

add_subdirectory(Sandbox)
apachano marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions Quartz/Engine/Include/Quartz/Utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(utilityHeaders
${currentDir}/HandleAllocator.hpp
${currentDir}/EnumTools.hpp
${currentDir}/Singleton.hpp
${currentDir}/Commander.hpp
${currentDir}/Plugin.hpp

PARENT_SCOPE
Expand Down
116 changes: 116 additions & 0 deletions Quartz/Engine/Include/Quartz/Utilities/Commander.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright 2019 Genten Studios
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors
// may be used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#pragma once

#include <string>
#include <array>
#include <functional>

namespace qz
{
namespace utils
{
constexpr int MaxCommandsNumber = 100;
constexpr int MaxArgumentNumber = 10;
apachano marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief The command book stores commands and information on them to be used by a commander
*/

struct CommandBook{
std::array<std::string, MaxCommandsNumber> m_command;
std::array<std::string, MaxCommandsNumber> m_help;
std::array<std::string, MaxCommandsNumber> m_permission;
std::array<std::function<int(std::array<std::string, MaxArgumentNumber> args)>, MaxCommandsNumber> m_functions;
apachano marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Registers a command in the command registry
*
* @param command The keyword for calling the command
* @param permission What permission is required to run this command
*/
int reg(const std::string& command, const std::string& help, const std::string& permission, std::function<int(std::array<std::string, MaxArgumentNumber> args)> f);
apachano marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Searches for a command and returns the index its stored at
*/
int find(const std::string& command);

/**
* @brief Gets next open space in book
*/
int i();
apachano marked this conversation as resolved.
Show resolved Hide resolved

private:
int m_i;
apachano marked this conversation as resolved.
Show resolved Hide resolved

};

/**
* @brief The Commander handles comand line functions while the server is running. A loop will watch for commands from the terminal while the server runs but the clients can also send commands.
*
*/
class Commander{
private:
CommandBook m_book;
std::ostream& m_out;
std::istream& m_in;

public:
Commander(CommandBook& book, std::ostream& out, std::istream& in);
~Commander();

/**
* @brief Calls a command
*
* @param command The keyword for calling the command.
*/
int run(const std::string& command, const std::array<std::string, MaxArgumentNumber> args);

/**
* @brief Returns helpstring for command
*
* @param args array of input, args[0] is the command helpstring is returned for
*/
int help(std::array<std::string, qz::utils::MaxArgumentNumber> args);

/**
* @brief Returns string listing available commands
*/
int list();

/**
* @brief Listens for commands.
*/
int post();

int initialize();
apachano marked this conversation as resolved.
Show resolved Hide resolved
};
};
}
1 change: 1 addition & 0 deletions Quartz/Engine/Source/Utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(utilitySources

${currentDir}/Logger.cpp
${currentDir}/FileIO.cpp
${currentDir}/Commander.cpp
${currentDir}/Plugin.cpp

PARENT_SCOPE
Expand Down
138 changes: 138 additions & 0 deletions Quartz/Engine/Source/Utilities/Commander.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// Copyright 2019 Genten Studios
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors
// may be used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#include <Quartz/Utilities/Commander.hpp>
#include <iostream>
#include <utility>

using namespace qz::utils;

Commander::Commander(CommandBook& book, std::ostream& out, std::istream& in) :
m_book(book),
m_out(out),
m_in(in)
{}

Commander::~Commander() {}

int CommandBook::find(const std::string& command){
for(int j = 0; j < m_i; j++){
if(m_command[j] == command){
return j;
}
}
return -1;
}

int CommandBook::reg(const std::string& command, const std::string& help, const std::string& permission, std::function<int(std::array<std::string, MaxArgumentNumber> args)> f){
int j = find(command);
if(j == -1){ // if command does not already exist, enter new command
j = m_i;
m_i++;
}
m_command[j] = command;
m_help[j] = help;
m_permission[j] = permission;
m_functions[j] = std::move(f);
return j;
}

int CommandBook::i(){
return m_i;
}

int Commander::help(std::array<std::string, qz::utils::MaxArgumentNumber> args){
if (args[0] == ""){
m_out << "Type /help [command] to learn more about a command \nType /list for a list of available commands\n";
return 1;
}else if (args[0] == "help"){
m_out << "Type /help [command] to learn more about a command \n";
return 1;
}else if (args[0] == "list"){
m_out << "Lists available commands\n";
return 1;
}
int j = m_book.find(args[0]);
if (j == -1){
m_out << "Command \"" + args[0] + "\" not found \n";
return -1;
}else{
m_out << m_book.m_help[j];
return 1;
}
}

int Commander::run(const std::string& command, const std::array<std::string, MaxArgumentNumber> args){
//Check for built in functions
if (command == "help")
return this->help(args);
else if (command == "list")
return this->list();
//If no built in functions match, search library
int j = m_book.find(command);
m_out << "command at: " + std::to_string(j) + "\n";
if (j == -1){
m_out << "Command \"" + command + "\" not found \n";
return -1;
}
else
{
return m_book.m_functions[j](args);
}
}

int Commander::list(){
std::string temp = "Available commands\n";
for(int j = 0; j < m_book.i(); j++){
m_out << "-" + m_book.m_command[j] + "\n";
}
return 1;
}

int Commander::post(){
std::string input;
while(true){
m_out << "\n->";
int i = 0;
std::array<std::string, MaxArgumentNumber> args;
std::string command = "";
std::string buffer;
m_in >> command;
//in >> buffer;
apachano marked this conversation as resolved.
Show resolved Hide resolved
while(m_in.peek() != '\n' && i <= MaxArgumentNumber){
m_in >> buffer;
args[i] = buffer;
//out << "added " + buffer + " to index " + std::to_string(i) + "\n";
apachano marked this conversation as resolved.
Show resolved Hide resolved
i++;
}
if (command == "exit")
apachano marked this conversation as resolved.
Show resolved Hide resolved
break;
run(command, args);
}
return 0;
}