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 all 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
4 changes: 2 additions & 2 deletions Phoenix/Client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ add_subdirectory(Source)
add_executable(${PROJECT_NAME} ${clientSources} ${clientHeaders})
target_link_libraries(${PROJECT_NAME} PRIVATE Phoenix)

set(dependencies ${CMAKE_CURRENT_LIST_DIR}/../Quartz/ThirdParty)
target_include_directories(${PROJECT_NAME} PRIVATE ${dependencies}/SDL2/include ${dependencies}/../Quartz/Engine/Include ${dependencies}/luamod/include ${dependencies}/imgui/include)
set(dependencies ${CMAKE_CURRENT_LIST_DIR}/../../Quartz/ThirdParty)
target_include_directories(${PROJECT_NAME} PRIVATE ${dependencies}/SDL2/include ${dependencies}/../Engine/Include ${dependencies}/luamod/include ${dependencies}/imgui/include)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Include)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../Core/Include)

Expand Down
7 changes: 3 additions & 4 deletions Phoenix/Client/Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ int main(int argc, char* argv[])
// ===== Compare server mods.txt and local mods.txt, update if needed =====

// ===== Load lua =====
voxels::BlockRegistry registry = voxels::BlockRegistry();
registry.registerBlock("core:dirt", "Dirt");
registry.registerBlock("core:cobble", "CobbleStone");
registry.registerBlock("core:stone", "Stone");
voxels::BlockRegistry::get()->registerBlock("core:dirt", "Dirt");
voxels::BlockRegistry::get()->registerBlock("core:cobble", "CobbleStone");
voxels::BlockRegistry::get()->registerBlock("core:stone", "Stone");
// TODO: Replace these manual calls to register blocks with a call to run lua files based on what modules need loaded

// ===== Launch renderer outputting to main window =====
Expand Down
4 changes: 2 additions & 2 deletions Phoenix/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ add_subdirectory(Source)
add_library(${PROJECT_NAME} STATIC ${phoenixSources} ${phoenixHeaders})
target_link_libraries(${PROJECT_NAME} PRIVATE QuartzEngine)

set(dependencies ${CMAKE_CURRENT_LIST_DIR}/../Quartz/ThirdParty)
target_include_directories(${PROJECT_NAME} PRIVATE ${dependencies}/../Quartz/Engine/Include)
set(dependencies ${CMAKE_CURRENT_LIST_DIR}/../../Quartz/ThirdParty)
target_include_directories(${PROJECT_NAME} PRIVATE ${dependencies}/../Engine/Include)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Include)

foreach(FILE ${phoenixSources})
Expand Down
13 changes: 8 additions & 5 deletions Phoenix/Core/Include/Core/Voxels/Blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#pragma once

#include <Quartz/Utilities/Singleton.hpp>

#include <string>
#include <vector>

Expand All @@ -54,21 +56,22 @@ namespace phoenix
};

/// @brief Stores universal block definitions
class BlockRegistry
class BlockRegistry : public qz::utils::Singleton<BlockRegistry>
{
private:
std::vector<RegisteredBlock> Blocks;
int i;

public:
BlockRegistry();
~BlockRegistry();

/// @brief Registers a block in the registry
int registerBlock(const std::string& uniqueName,
const std::string& displayName);
int registerBlock(const std::string& uniqueName,
const std::string& displayName);
/// @brief Get the Display name for a block in the registry
const std::string& getDisplayName(int blockId);
int getBlockId(const std::string& uniqueName);
/// @brief Get the ID for a block in the registry
int getBlockId(const std::string& uniqueName);
};

/// @breif Metadata for a block, this is only created if a block needs
Expand Down
6 changes: 1 addition & 5 deletions Phoenix/Core/Source/Voxels/Blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

#include <Core/Voxels/Blocks.hpp>

#include <string>

using namespace phoenix::voxels;

RegisteredBlock::RegisteredBlock(const std::string& unique, int id,
Expand All @@ -40,13 +38,11 @@ RegisteredBlock::~RegisteredBlock() = default;

BlockRegistry::BlockRegistry() : i(0) {};

BlockRegistry::~BlockRegistry() {};

int BlockRegistry::registerBlock(const std::string& uniqueName,
const std::string& displayName)
{
i++;
Blocks[i] = RegisteredBlock(uniqueName, i, displayName);
Blocks.push_back(RegisteredBlock(uniqueName, i, displayName));
return i;
};

Expand Down
4 changes: 2 additions & 2 deletions Phoenix/Server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ add_subdirectory(Source)
add_executable(${PROJECT_NAME} ${serverSources} ${serverHeaders})
target_link_libraries(${PROJECT_NAME} PRIVATE Phoenix)

set(dependencies ${CMAKE_CURRENT_LIST_DIR}/../Quartz/ThirdParty)
target_include_directories(${PROJECT_NAME} PRIVATE ${dependencies}/SDL2/include ${dependencies}/../Quartz/Engine/Include ${dependencies}/luamod/include ${dependencies}/imgui/include)
set(dependencies ${CMAKE_CURRENT_LIST_DIR}/../../Quartz/ThirdParty)
target_include_directories(${PROJECT_NAME} PRIVATE ${dependencies}/SDL2/include ${dependencies}/../Engine/Include ${dependencies}/luamod/include ${dependencies}/imgui/include)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Include)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../Core/Include)

Expand Down
38 changes: 27 additions & 11 deletions Phoenix/Server/Source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <Core/Voxels/Blocks.hpp>
#include <Server/Main.hpp>

#include <Quartz/Utilities/Commander.hpp>

#include <iostream>
#include <stdio.h>

Expand All @@ -10,29 +13,42 @@ using namespace phoenix;
int main(int argc, char* argv[])
{

// ===== Launch core =====
// ===== Launch core =====
// Likely a single command from Quartz that launches the logger + any other critical tools

// ===== Load Voxel data / Load lua =====
voxels::BlockRegistry registry = voxels::BlockRegistry();
registry.registerBlock("core:dirt", "Dirt");
registry.registerBlock("core:cobble", "CobbleStone");
registry.registerBlock("core:stone", "Stone");
std::cout << "Program started \n";
//voxels::BlockRegistry *registry = registry->get();
voxels::BlockRegistry::get()->registerBlock("core:dirt", "Dirt");
voxels::BlockRegistry::get()->registerBlock("core:cobble", "CobbleStone");
voxels::BlockRegistry::get()->registerBlock("core:stone", "Stone");
// TODO: Replace these manual calls to register blocks with a call to run lua files

std::cout << voxels::BlockRegistry::get()->getDisplayName(1);
std::cout << std::to_string(voxels::BlockRegistry::get()->getBlockId("core::dirt"));

// TODO: Replace these example functions with other, permanent, systems.
//qz::utils::CommandBook commandBook = qz::utils::CommandBook();

qz::utils::CommandBook::get()->add("getBlockName",
"Gets the name of a block based on provided ID number",
"all",
[](std::vector<std::string>&& args){
std::cout << voxels::BlockRegistry::get()->getDisplayName(std::stoi(args[0]));
});

// ===== Load save data =====
// Save::Load(argv[0]) //This will detect internally if a new map needs generated based on if save exists

// ===== Launch network connection listener =====
// ===== Launch network connection listener =====
// std::thread listener (Network::Listener);

// ===== Enter main loop watching for CLI input =====
/*bool run = true;
while (run == true){
// Listen for CLI instructions
}*/
// ===== Enter main loop watching for CLI input =====
qz::utils::Commander kirk = qz::utils::Commander(std::cout, std::cin);
kirk.post();

// ===== Begin shutdown =====
std::cout << "Begin Shutdown \n \n";

// Send signal for listener to terminate
// Confirm map has saved
Expand Down
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
143 changes: 143 additions & 0 deletions Quartz/Engine/Include/Quartz/Utilities/Commander.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// 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 <Quartz/Utilities/Singleton.hpp>

#include <functional>
#include <string>
#include <vector>

namespace qz
{
namespace utils
{
typedef std::function<void(std::vector<std::string> args)> function;

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

struct CommandBook : public Singleton<CommandBook>
{
std::vector<std::string> m_command;
std::vector<std::string> m_help;
std::vector<std::string> m_permission;
std::vector<function> m_functions;

/**
* @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
*/
void add(const std::string& command, const std::string& help,
const std::string& permission, function f);

/**
* @brief Searches for a command
*
* @param command The command to search for
* @return index command is located at or -1 if its not found
*/
int find(const std::string& command);

/**
* @brief Gets next open space in book
*
* @return Returns the next open space in arrays as an integer
*/
int getPage();
apachano marked this conversation as resolved.
Show resolved Hide resolved

private:
/**
* @brief Counter that keep track of next space in the arrays (eg
* next page in the book)
*/
int m_page;
};

/**
* @brief The Commander handles comand line functions. It accepts an in
* and out stream on creation and can interact with the command line or
* another interface.
*
*/
class Commander
{
private:
CommandBook* m_book;
std::ostream& m_out;
std::istream& m_in;

public:
/**
* @brief Initializes a commander that can run and execute commands
*
* @param book The command book that the commander uses to route
* commands to functions
* @param out An output stream the commander outputs results to
* @param in An input stream the commander accepts input to
*/
Commander(std::ostream& out, std::istream& in);
~Commander();

/**
* @brief Calls a command
*
* @param command The keyword for calling the command.
* @return Returns True if the function was called and False if the
* function could not be found
*/
bool run(const std::string& command,
const std::vector<std::string>&& args);

/**
* @brief Returns helpstring for command
*
* @param args array of input, args[0] is the command helpstring is
* returned for, all other array values are not used
* @return Returns True if successful and False if it could not find
* the innputted command
*/
bool help(const std::vector<std::string>&& args);

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

/**
* @brief Listens for commands.
*/
void post();
};
}; // namespace utils
} // namespace qz
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
Loading