Browse Source

Added PLog; sorted out build system

- Added PLog, a logging library, which will eventually replace all std::cout calls in Galavant. It's robust and will allow me to pipe output from Galavant lib to Unreal Engine logs
- I finally sorted out the Jam building problems. SubDirC++Flags are appended to C++Flags. They do not replace C++Flags. This was very frustrating. Lesson learned: when you find weird shit in other peoples' code, it doesn't hurt to read their code (in this case, Jambase)
- Added some debugging shit to PlanComponentManager
- Small formatting changes
combatComponentRefactor
Macoy Madson 7 years ago
parent
commit
e209e1b8ac
  1. 3
      .gitmodules
  2. 9
      Jamfile
  3. 64
      Jamrules
  4. 1
      README.md
  5. 3
      src/GalavantMain.cpp
  6. 2
      src/Jamfile
  7. 2
      src/ai/Jamfile
  8. 2
      src/ai/htn/HTNPlanner.cpp
  9. 2
      src/entityComponentSystem/Jamfile
  10. 2
      src/experiments/Jamfile
  11. 4
      src/experiments/flatbuffers/Jamfile
  12. 8
      src/experiments/flatbuffers/testFlatbuffers.cpp
  13. 8
      src/experiments/flatbuffers/testFlatbuffers_WriteOut.cpp
  14. 2
      src/experiments/noise/Jamfile
  15. 2
      src/experiments/threading/Jamfile
  16. 2
      src/game/Jamfile
  17. 12
      src/game/agent/PlanComponentManager.cpp
  18. 8
      src/main.cpp
  19. 8
      src/project/galavantSublime/galavant.sublime-project
  20. 2
      src/thirdPartyWrapper/Jamfile
  21. 4
      src/unitTesting/HTN_test.cpp
  22. 6
      src/unitTesting/Jamfile
  23. 62
      src/unitTesting/Log_test.cpp
  24. 2
      src/unitTesting/ObjectPoolTest.cpp
  25. 2
      src/world/Jamfile
  26. 1
      thirdParty/plog

3
.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

9
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 ;

64
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
# 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

1
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

3
src/GalavantMain.cpp

@ -1,7 +1,8 @@
#include "GalavantMain.hpp"
#include <iostream>
#include <plog/Log.h>
void gv::GalavantMain::Update(float frameTime)
{
LOG_VERBOSE << "GalvantMain::Update() Frame Time " << frameTime;
}

2
src/Jamfile

@ -1,5 +1,7 @@
SubDir . src ;
SubDirC++Flags $(ALLLIBSC++FLAGS) ;
Library libGalavant : GalavantMain.cpp ;
LinkLibraries libGalavant : libGalaThirdPartyWrapper ;
MakeLocate libGalavant.a : lib ;

2
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 ;

2
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

2
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 ;

2
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 ;

4
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 ;
MakeLocate testFlatbuffers : bin ;

8
src/experiments/flatbuffers/testFlatbuffers.cpp

@ -63,7 +63,7 @@ char *readBuffer()
return nullptr;
}
void createPlaceholderHelloArray(std::vector<flatbuffers::Offset<Galavant::Test::Hello> > &array,
void createPlaceholderHelloArray(std::vector<flatbuffers::Offset<Galavant::Test::Hello>> &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<flatbuffers::Offset<Galavant::Test::Hello> > helloArray;
std::vector<flatbuffers::Offset<Galavant::Test::Hello>> helloArray;
createPlaceholderHelloArray(helloArray, builder, 10000);
@ -132,12 +132,12 @@ void testHelloDict()
if (readInHelloDict)
{
const flatbuffers::Vector<flatbuffers::Offset<Galavant::Test::Hello> > *helloArray =
const flatbuffers::Vector<flatbuffers::Offset<Galavant::Test::Hello>> *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);

8
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;

2
src/experiments/noise/Jamfile

@ -1,5 +1,7 @@
SubDir . src experiments noise ;
SubDirC++Flags $(TESTSC++FLAGS) ;
Main simple2dNoiseTest : simple2dNoiseTest.cpp ;
LinkLibraries simple2dNoiseTest : libGalaThirdPartyWrapper ;

2
src/experiments/threading/Jamfile

@ -1,5 +1,7 @@
SubDir . src experiments threading ;
SubDirC++Flags $(TESTSC++FLAGS) ;
Main multithreading : multithreading.cpp ;
MakeLocate multithreading : bin ;

2
src/game/Jamfile

@ -1,5 +1,7 @@
SubDir . src game ;
SubDirC++Flags $(ALLLIBSC++FLAGS) ;
Library libGalaGame : agent/PlanComponentManager.cpp ;
LinkLibraries libGalaGame : libGalaAi libGalaWorld ;

12
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,

8
src/main.cpp

@ -1,7 +1,7 @@
#include <iostream>
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;
}

8
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}}",

2
src/thirdPartyWrapper/Jamfile

@ -1,5 +1,7 @@
SubDir . src thirdPartyWrapper ;
SubDirC++Flags $(ALLLIBSC++FLAGS) ;
Library libGalaThirdPartyWrapper : noise/noise.cpp ;
MakeLocate libGalaThirdPartyWrapper.a : lib/thirdPartyWrapper ;

4
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);

6
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 ;

62
src/unitTesting/Log_test.cpp

@ -0,0 +1,62 @@
#include <sys/stat.h>
#define CATCH_CONFIG_MAIN
#include "../../thirdParty/Catch/single_include/catch.hpp"
#include <plog/Log.h>
// for MyAppender
#include <plog/Formatters/FuncMessageFormatter.h>
#include <list>
// Copied from thirdParty/plog/samples/CustomAppender/Main.cpp
namespace plog
{
template <class Formatter> // 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<util::nstring>& getMessageList()
{
return m_messageList;
}
private:
std::list<util::nstring> 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<plog::FuncMessageFormatter> myAppender;
plog::init(plog::debug, &myAppender);
LOGD << "A debug message!";
REQUIRE(!myAppender.getMessageList().empty());
}
}

2
src/unitTesting/ObjectPoolTest.cpp

@ -6,7 +6,7 @@ int main()
{
ObjectPool<int> 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)

2
src/world/Jamfile

@ -1,5 +1,7 @@
SubDir . src world ;
SubDirC++Flags $(ALLLIBSC++FLAGS) ;
Library libGalaWorld : Position.cpp ;
MakeLocate libGalaWorld.a : lib ;

1
thirdParty/plog

@ -0,0 +1 @@
Subproject commit b50e70ec46eff7946b84c8ea961b0fd25c3819d8
Loading…
Cancel
Save