diff --git a/.gitmodules b/.gitmodules index 057f41f..a5fc50e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "thirdParty/Catch"] path = thirdParty/Catch url = https://github.com/philsquared/Catch.git +[submodule "thirdParty/plog"] + path = thirdParty/plog + url = https://github.com/SergiusTheBest/plog diff --git a/Jamfile b/Jamfile index a4c6778..b1050fb 100644 --- a/Jamfile +++ b/Jamfile @@ -1,3 +1,12 @@ SubDir . ; +SubDirC++Flags $(ALLLIBSC++FLAGS) ; + +# Lazy pseudotarget for Galavant - make a dummy executable which will make Jam build the libs we're +# actually going to use. There's definitely a better way to do this but I'm too lazy to find it +Main GalavantPseudotarget : src/main.cpp ; +LinkLibraries GalavantPseudotarget : libGalavant libGalaThirdPartyWrapper libGalaEntityComponent libGalaAi libGalaWorld libGalaGame ; + +MakeLocate GalavantPseudotarget : bin ; + SubInclude . src ; \ No newline at end of file diff --git a/Jamrules b/Jamrules index 64fdb7b..481139c 100644 --- a/Jamrules +++ b/Jamrules @@ -1,5 +1,12 @@ -# Temporary Unreal Command line (TODO: Fix this so there's targets or something) -# jam -j4 -a libGalavant.a libGalaThirdPartyWrapper.a libGalaEntityComponent.a libGalaAi.a libGalaWorld.a libGalaGame.a +# Building Tests: +# jam clean +# jam -j4 -q + +# Building Unreal: +# jam clean +# jam -j4 -q -sUNREAL=true GalavantPseudotarget + +# (if building the same target repeatedly, don't clean, if that wasn't obvious) ## ## Compiler @@ -20,26 +27,46 @@ LINK = clang++ ; ## # Galavant requires C++11 -# fPIC = position independent code. This is so the lib can be linked in other libs/executables + +## Argument explanation +# # g = debug symbols -# lstdc++ = standard library +# -O0 = compile without optimizations for debugging +# +# -Wall -Wextra = Error detection/tolerance +# -Wno-unused-parameter = I should probably get rid of this at some point +# +# fPIC = position independent code. This is so the lib can be linked in other libs/executables # -stdlib=lib++ = Unreal uses libc++, which is busted on Ubuntu 16.04. Remove this option # if you don't give a shit about Unreal and/or want to build the tests -# Og = compile without optimizations for debugging -# -Wall -Wextra = Error detection/tolerance +# +# lstdc++ = standard library [Unused] + +# Arguments used on all projects, regardless of any variables +C++FLAGS = -std=c++11 -Wall -Wextra -Wno-unused-parameter ; -C++FLAGS = -std=c++11 -stdlib=libc++ -fPIC -g -Og -Wall -Wextra ; # Required arguments for Unreal -#C++FLAGS = -std=c++11 -fPIC -g -Og -Wall -Wextra ; # Required arguments for tests +# Required arguments for tests +TESTSC++FLAGS = -g ; +# Required arguments for Unreal +UNREALC++FLAGS = -g -stdlib=libc++ -fPIC ; -HDRS = thirdParty/flatbuffers/include ; +# ALLLIBSC++FLAGS should be used for all libraries which might be used by both tests and Unreal +if $(UNREAL) +{ + ALLLIBSC++FLAGS = $(UNREALC++FLAGS) ; +} +else +{ + ALLLIBSC++FLAGS = $(TESTSC++FLAGS) ; +} + +OPTIM = -O0 ; + +HDRS = thirdParty/flatbuffers/include thirdParty/plog/include ; # TODO: add project-specific filetype rules for things like flatbuffer .json compilation (see "UserObject rule": # https://swarm.workshop.perforce.com/view/guest/perforce_software/jam/src/Jamfile.html ) ? -# TODO: Add variable that allows user to swap between compiling Unreal -# and compiling testse on the command line (see above page under "Variables -# used in Building Executables and Libraries) - # TODO: [Hacked done] Calling jam -dc indicates that it thinks many unmodified files are newer, # which is why it's building way more than it should be. Further investigation is needed, as if it # has nothing to build it should complete almost instantly @@ -58,4 +85,13 @@ HDRS = thirdParty/flatbuffers/include ; KEEPOBJS = true ; # This doesn't actually fix anything, though it seems like it should NOARSCAN = true ; # This actually fixes the problem #AR = ar rUu ; # I was thinking maybe the AR command was wrong (always outputting deterministically) - # It doesn't seem like this is the problem though \ No newline at end of file + # It doesn't seem like this is the problem though +AR = ar cr ; + +# Some helpful Jam commands +# -q : stop on failed target +# -jN : use N cores +# -sVAR=VAL : Set VAR to VAL. Note that setting UNREAL=false is the same as setting UNREAL=true, +# frustratingly +# -dx : print commands being used +# -n : don't actually run commands \ No newline at end of file diff --git a/README.md b/README.md index e78e5d0..69f2776 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ The following libraries are required by Galavant and included in /thirdParty: - [OpenSimplexNoise](https://gist.github.com/tombsar/716134ec71d1b8c1b530), created by Arthur Tombs (public domain) - [Flatbuffers](https://github.com/google/flatbuffers), created by Google/Fun Propulsion Labs (Apache License, v2.0) - [Catch](https://github.com/philsquared/Catch), created by various contributors/a dude named Travis (Boost Software License) +- [PLog](https://github.com/SergiusTheBest/plog), created by Sergey Podobry (Mozilla Public License v2.0) ## License diff --git a/src/GalavantMain.cpp b/src/GalavantMain.cpp index 3c82138..d32bcd9 100644 --- a/src/GalavantMain.cpp +++ b/src/GalavantMain.cpp @@ -1,7 +1,8 @@ #include "GalavantMain.hpp" -#include +#include void gv::GalavantMain::Update(float frameTime) { + LOG_VERBOSE << "GalvantMain::Update() Frame Time " << frameTime; } \ No newline at end of file diff --git a/src/Jamfile b/src/Jamfile index 135b2d5..342a7a1 100644 --- a/src/Jamfile +++ b/src/Jamfile @@ -1,5 +1,7 @@ SubDir . src ; +SubDirC++Flags $(ALLLIBSC++FLAGS) ; + Library libGalavant : GalavantMain.cpp ; LinkLibraries libGalavant : libGalaThirdPartyWrapper ; MakeLocate libGalavant.a : lib ; diff --git a/src/ai/Jamfile b/src/ai/Jamfile index 9027598..250e1d4 100644 --- a/src/ai/Jamfile +++ b/src/ai/Jamfile @@ -1,5 +1,7 @@ SubDir . src ai ; +SubDirC++Flags $(ALLLIBSC++FLAGS) ; + Library libGalaAi : htn/HTNTasks.cpp htn/HTNPlanner.cpp WorldState.cpp ; LinkLibraries LibGalaAi : LibGalaWorld ; diff --git a/src/ai/htn/HTNPlanner.cpp b/src/ai/htn/HTNPlanner.cpp index bd60590..0bce962 100644 --- a/src/ai/htn/HTNPlanner.cpp +++ b/src/ai/htn/HTNPlanner.cpp @@ -43,7 +43,7 @@ bool Planner::IsPlannerRunning() bool Planner::IsPlannerRunning(Status status) { - return (status > Status::Running_EnumBegin && status < Status::Running_EnumEnd); + return (status >= Status::Running_EnumBegin && status <= Status::Running_EnumEnd); } // When the stack is empty, find a goal task to push onto the task or add tasks as per usual diff --git a/src/entityComponentSystem/Jamfile b/src/entityComponentSystem/Jamfile index a9afb9e..3cc1292 100644 --- a/src/entityComponentSystem/Jamfile +++ b/src/entityComponentSystem/Jamfile @@ -1,5 +1,7 @@ SubDir . src entityComponentSystem ; +SubDirC++Flags $(ALLLIBSC++FLAGS) ; + Library libGalaEntityComponent : EntityTypes.cpp EntitySharedData.cpp EntityComponentManager.cpp ComponentManager.cpp ; LinkLibraries libGalaEntityComponent : libGalaWorld ; diff --git a/src/experiments/Jamfile b/src/experiments/Jamfile index c00a8c9..d7900f4 100644 --- a/src/experiments/Jamfile +++ b/src/experiments/Jamfile @@ -1,5 +1,7 @@ SubDir . src experiments ; +SubDirC++Flags $(TESTSC++FLAGS) ; + SubInclude . src experiments flatbuffers ; SubInclude . src experiments noise ; SubInclude . src experiments threading ; diff --git a/src/experiments/flatbuffers/Jamfile b/src/experiments/flatbuffers/Jamfile index e05e6d4..51fcbec 100644 --- a/src/experiments/flatbuffers/Jamfile +++ b/src/experiments/flatbuffers/Jamfile @@ -1,5 +1,7 @@ SubDir . src experiments flatbuffers ; +SubDirC++Flags $(TESTSC++FLAGS) ; + Main testFlatbuffers : testFlatbuffers.cpp ; Main testFlatbuffers_write : testFlatbuffers_WriteOut.cpp ; @@ -8,4 +10,4 @@ LinkLibraries testFlatbuffers_write : ./thirdParty/flatbuffers/libflatbuffers.a # Note that we're not moving testFlatbuffers_write to bin because it's # dependent on SavedHelloForWrite.bin (this is how lazy I am) -MakeLocate testFlatbuffers : bin ; \ No newline at end of file +MakeLocate testFlatbuffers : bin ; diff --git a/src/experiments/flatbuffers/testFlatbuffers.cpp b/src/experiments/flatbuffers/testFlatbuffers.cpp index 7a7cf2e..6675cf4 100644 --- a/src/experiments/flatbuffers/testFlatbuffers.cpp +++ b/src/experiments/flatbuffers/testFlatbuffers.cpp @@ -63,7 +63,7 @@ char *readBuffer() return nullptr; } -void createPlaceholderHelloArray(std::vector > &array, +void createPlaceholderHelloArray(std::vector> &array, flatbuffers::FlatBufferBuilder &builder, int count) { for (int i = 0; i < count; i++) @@ -114,7 +114,7 @@ void testHellos() void testHelloDict() { flatbuffers::FlatBufferBuilder builder; - std::vector > helloArray; + std::vector> helloArray; createPlaceholderHelloArray(helloArray, builder, 10000); @@ -132,12 +132,12 @@ void testHelloDict() if (readInHelloDict) { - const flatbuffers::Vector > *helloArray = + const flatbuffers::Vector> *helloArray = readInHelloDict->helloArray(); if (helloArray) { - for (int i = 0; i < helloArray->Length(); i++) + for (unsigned int i = 0; i < helloArray->Length(); i++) { const Galavant::Test::Hello *readInHello = helloArray->Get(i); diff --git a/src/experiments/flatbuffers/testFlatbuffers_WriteOut.cpp b/src/experiments/flatbuffers/testFlatbuffers_WriteOut.cpp index 7996209..c9a5061 100644 --- a/src/experiments/flatbuffers/testFlatbuffers_WriteOut.cpp +++ b/src/experiments/flatbuffers/testFlatbuffers_WriteOut.cpp @@ -62,7 +62,7 @@ char *readBinary(const char *filename) void testFlatbufferToJSON() { - const char *outputFilename = "Output.json"; + //const char *outputFilename = "Output.json"; const char *flatbufferFilename = "SavedHelloForWrite.bin"; const char *schemaFilename = "bogusSchema.flb"; const char *includePaths = { @@ -73,7 +73,7 @@ void testFlatbufferToJSON() if (memblock && schemaBlock) { - const Galavant::Test::Hello *readInHello = Galavant::Test::GetHello(memblock); + // const Galavant::Test::Hello *readInHello = Galavant::Test::GetHello(memblock); // printHello(readInHello); flatbuffers::Parser parser; @@ -84,8 +84,8 @@ void testFlatbufferToJSON() std::cout << outputString << "\n"; - //std::cout << "Generating text file...\n"; - //flatbuffers::GenerateTextFile(parser, memblock, outputFilename); + // std::cout << "Generating text file...\n"; + // flatbuffers::GenerateTextFile(parser, memblock, outputFilename); delete memblock; delete schemaBlock; diff --git a/src/experiments/noise/Jamfile b/src/experiments/noise/Jamfile index c3442c1..08a0867 100644 --- a/src/experiments/noise/Jamfile +++ b/src/experiments/noise/Jamfile @@ -1,5 +1,7 @@ SubDir . src experiments noise ; +SubDirC++Flags $(TESTSC++FLAGS) ; + Main simple2dNoiseTest : simple2dNoiseTest.cpp ; LinkLibraries simple2dNoiseTest : libGalaThirdPartyWrapper ; diff --git a/src/experiments/threading/Jamfile b/src/experiments/threading/Jamfile index 155a4f9..204dcb7 100644 --- a/src/experiments/threading/Jamfile +++ b/src/experiments/threading/Jamfile @@ -1,5 +1,7 @@ SubDir . src experiments threading ; +SubDirC++Flags $(TESTSC++FLAGS) ; + Main multithreading : multithreading.cpp ; MakeLocate multithreading : bin ; \ No newline at end of file diff --git a/src/game/Jamfile b/src/game/Jamfile index 62f9b4d..0f097da 100644 --- a/src/game/Jamfile +++ b/src/game/Jamfile @@ -1,5 +1,7 @@ SubDir . src game ; +SubDirC++Flags $(ALLLIBSC++FLAGS) ; + Library libGalaGame : agent/PlanComponentManager.cpp ; LinkLibraries libGalaGame : libGalaAi libGalaWorld ; diff --git a/src/game/agent/PlanComponentManager.cpp b/src/game/agent/PlanComponentManager.cpp index 96155dc..c6b23cb 100644 --- a/src/game/agent/PlanComponentManager.cpp +++ b/src/game/agent/PlanComponentManager.cpp @@ -65,11 +65,16 @@ void PlanComponentManager::Update(float deltaSeconds) { // We have finished all tasks; remove this entity from the manager // TODO: We'll eventually hook up some event shit + std::cout << "PlanComponentManager: Call list empty\n"; entitiesToUnsubscribe.push_back(currentEntity); } } else + { + std::cout << "PlanComponentManager: Plan not complete, status " + << (int)componentPlanner.CurrentStatus << "\n"; entitiesToUnsubscribe.push_back(currentEntity); + } } else { @@ -93,12 +98,15 @@ void PlanComponentManager::Update(float deltaSeconds) // Plan failed, remove entity // TODO: Hook up events + std::cout << "PlanComponentManager: Plan not running/failed\n"; entitiesToUnsubscribe.push_back(currentEntity); } } } } + std::cout << "PlanComponentManager: Unsubscribed " << entitiesToUnsubscribe.size() + << " entities\n"; UnsubscribeEntities(entitiesToUnsubscribe); } @@ -118,9 +126,11 @@ void PlanComponentManager::SubscribeEntitiesInternal(const EntityList& subscribe goalCallList.end()); // TODO: This is not kosher - planner.CurrentStatus = Htn::Planner::Status::Running_EnumBegin; + planner.CurrentStatus = Htn::Planner::Status::Running_SuccessfulPrimitive; planner.DebugPrint = true; } + + std::cout << "PlanComponentManager: Subscribed " << components.size() << " entities\n"; } void PlanComponentManager::UnsubscribeEntitiesInternal(const EntityList& unsubscribers, diff --git a/src/main.cpp b/src/main.cpp index 70bf4c1..2fb1094 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ -#include - int main() { - std::cout << "Galavant\n"; - return 1; + // Galavant + // This is a pseudotarget; that means the bin isn't what we care about, + // it's the libs we linked to, which forced Jam to build them (hack :( ) + return 0; } diff --git a/src/project/galavantSublime/galavant.sublime-project b/src/project/galavantSublime/galavant.sublime-project index 32b6f90..52a507f 100644 --- a/src/project/galavantSublime/galavant.sublime-project +++ b/src/project/galavantSublime/galavant.sublime-project @@ -63,6 +63,14 @@ "workingdir": "/home/macoy/Development/code/repositories/galavant/src/unitTesting/bin", "commandline": "gdb --interpreter=mi ./htnTest" }, + + "UnrealEditor": + { + // sudo gdb /home/macoy/Downloads/UnrealEngine/Engine/Binaries/Linux/UE4Editor $(ps -A | grep UE4Editor | awk '{print $1;}') + "workingdir": "/home/macoy/Downloads/UnrealEngine/Engine/Binaries/Linux", + "commandline": "gdb --interpreter=mi ./UE4Editor" + }, + // "second_executable_name": // { // "workingdir": "${folder:${project_path:second_executable_name}}", diff --git a/src/thirdPartyWrapper/Jamfile b/src/thirdPartyWrapper/Jamfile index df58dbb..5f0eb27 100644 --- a/src/thirdPartyWrapper/Jamfile +++ b/src/thirdPartyWrapper/Jamfile @@ -1,5 +1,7 @@ SubDir . src thirdPartyWrapper ; +SubDirC++Flags $(ALLLIBSC++FLAGS) ; + Library libGalaThirdPartyWrapper : noise/noise.cpp ; MakeLocate libGalaThirdPartyWrapper.a : lib/thirdPartyWrapper ; \ No newline at end of file diff --git a/src/unitTesting/HTN_test.cpp b/src/unitTesting/HTN_test.cpp index 2328d3e..b58ab9d 100644 --- a/src/unitTesting/HTN_test.cpp +++ b/src/unitTesting/HTN_test.cpp @@ -112,7 +112,9 @@ public: TEST_CASE("Hierarchical Task Networks Planner") { - Htn::Parameter testParam = {Htn::Parameter::ParamType::Int, 123}; + Htn::Parameter testParam; + testParam.Type = Htn::Parameter::ParamType::Int; + testParam.IntValue = 123; Htn::ParameterList params; params.push_back(testParam); diff --git a/src/unitTesting/Jamfile b/src/unitTesting/Jamfile index 00ba1ed..d2b263d 100644 --- a/src/unitTesting/Jamfile +++ b/src/unitTesting/Jamfile @@ -1,5 +1,7 @@ SubDir . src unitTesting ; +SubDirC++Flags $(TESTSC++FLAGS) ; + Main entityComponentTest : EntityComponentSystem_test.cpp ; LinkLibraries entityComponentTest : libGalaEntityComponent ; @@ -11,7 +13,9 @@ LinkLibraries htnTest : libGalaAi ; Main positionTest : Position_test.cpp ; LinkLibraries positionTest : libGalaWorld ; -MakeLocate objectComponentTest entityComponentTest objectPoolTest htnTest positionTest : bin ; +Main logTest : Log_test.cpp ; + +MakeLocate objectComponentTest entityComponentTest objectPoolTest htnTest positionTest logTest : bin ; SubInclude . src entityComponentSystem ; SubInclude . src ai ; \ No newline at end of file diff --git a/src/unitTesting/Log_test.cpp b/src/unitTesting/Log_test.cpp new file mode 100644 index 0000000..9186d85 --- /dev/null +++ b/src/unitTesting/Log_test.cpp @@ -0,0 +1,62 @@ +#include + +#define CATCH_CONFIG_MAIN +#include "../../thirdParty/Catch/single_include/catch.hpp" + +#include + +// for MyAppender +#include +#include + +// Copied from thirdParty/plog/samples/CustomAppender/Main.cpp +namespace plog +{ +template // Typically a formatter is passed as a template parameter. +class MyAppender : public IAppender // All appenders MUST inherit IAppender interface. +{ +public: + virtual void write( + const Record& record) // This is a method from IAppender that MUST be implemented. + { + util::nstring str = + Formatter::format(record); // Use the formatter to get a string from a record. + + m_messageList.push_back(str); // Store a log message in a list. + } + + std::list& getMessageList() + { + return m_messageList; + } + +private: + std::list m_messageList; +}; +} + +TEST_CASE("Log") +{ + SECTION("Log Writing to file") + { + const char* logName = "LOCAL_TestLog.log"; + plog::init(plog::debug, logName); + + LOG_DEBUG << "Test log"; + + // To confirm the log worked, check if the file exists + // http://stackoverflow.com/questions/12774207/fastest-way-to-check-if-a-file-exist-using-standard-c-c11-c + struct stat buffer; + REQUIRE(stat(logName, &buffer) == 0); + } + + SECTION("Log Custom Appender") + { + static plog::MyAppender myAppender; + plog::init(plog::debug, &myAppender); + + LOGD << "A debug message!"; + + REQUIRE(!myAppender.getMessageList().empty()); + } +} \ No newline at end of file diff --git a/src/unitTesting/ObjectPoolTest.cpp b/src/unitTesting/ObjectPoolTest.cpp index dbc351d..61413c3 100644 --- a/src/unitTesting/ObjectPoolTest.cpp +++ b/src/unitTesting/ObjectPoolTest.cpp @@ -6,7 +6,7 @@ int main() { ObjectPool testPool(100); - for (int i = 0; i < testPool.GetSize(); i++) + for (unsigned int i = 0; i < testPool.GetSize(); i++) { int* newData = testPool.GetNewData(); if (newData) diff --git a/src/world/Jamfile b/src/world/Jamfile index df9c9b3..b513ac1 100644 --- a/src/world/Jamfile +++ b/src/world/Jamfile @@ -1,5 +1,7 @@ SubDir . src world ; +SubDirC++Flags $(ALLLIBSC++FLAGS) ; + Library libGalaWorld : Position.cpp ; MakeLocate libGalaWorld.a : lib ; \ No newline at end of file diff --git a/thirdParty/plog b/thirdParty/plog new file mode 160000 index 0000000..b50e70e --- /dev/null +++ b/thirdParty/plog @@ -0,0 +1 @@ +Subproject commit b50e70ec46eff7946b84c8ea961b0fd25c3819d8