Parcourir la source

refactor: remove event/reflection system entirely

Sam Jaffe il y a 10 mois
Parent
commit
42b943dbfc

+ 0 - 3
.gitmodules

@@ -7,9 +7,6 @@
 [submodule "external/string-utils"]
 	path = external/string-utils
 	url = ssh://git@gogs.sjaffe.name:3000/sjjaffe/cpp-string-utils.git
-[submodule "external/reflection"]
-	path = external/reflection
-	url = ssh://git@gogs.sjaffe.name:3000/sjjaffe/cpp-reflection.git
 [submodule "external/shared_random_generator"]
 	path = external/shared_random_generator
 	url = ssh://git@gogs.sjaffe.name:3000/sjjaffe/cpp-shared-random-generator.git

+ 0 - 64
engine.xcodeproj/project.pbxproj

@@ -9,8 +9,6 @@
 /* Begin PBXBuildFile section */
 		CD592BED29C2A422009AC14E /* universe.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD592BEB29C2A422009AC14E /* universe.cxx */; };
 		CDD4759429C4B7A200BDB829 /* config.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CDD4759129C4B7A200BDB829 /* config.cxx */; };
-		CDD4759529C4B7A200BDB829 /* event.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CDD4759229C4B7A200BDB829 /* event.cxx */; };
-		CDD4759629C4B7A200BDB829 /* condition.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CDD4759329C4B7A200BDB829 /* condition.cxx */; };
 		CDD475C829C4D2BF00BDB829 /* libengine.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CD592BDB29C2A399009AC14E /* libengine.a */; };
 		CDD475D029C4D2F700BDB829 /* libjsoncpp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CDD475CF29C4D2F700BDB829 /* libjsoncpp.a */; };
 		CDD475D129C4D2FC00BDB829 /* libjsoncpp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CDD475CF29C4D2F700BDB829 /* libjsoncpp.a */; };
@@ -110,20 +108,6 @@
 			remoteGlobalIDString = CDEC1E8A235248390091D9F2;
 			remoteInfo = "expect-test";
 		};
-		CDD4773D29C5492E00BDB829 /* PBXContainerItemProxy */ = {
-			isa = PBXContainerItemProxy;
-			containerPortal = CDD4773729C5492E00BDB829 /* reflection.xcodeproj */;
-			proxyType = 2;
-			remoteGlobalIDString = CD2FF8FE2310BE7C00ABA548;
-			remoteInfo = "reflection-test";
-		};
-		CDD4773F29C5492E00BDB829 /* PBXContainerItemProxy */ = {
-			isa = PBXContainerItemProxy;
-			containerPortal = CDD4773729C5492E00BDB829 /* reflection.xcodeproj */;
-			proxyType = 2;
-			remoteGlobalIDString = CDA9561728726941006ACEC2;
-			remoteInfo = reflection;
-		};
 		CDD4774B29C5493400BDB829 /* PBXContainerItemProxy */ = {
 			isa = PBXContainerItemProxy;
 			containerPortal = CDD4774129C5493400BDB829 /* serializer.xcodeproj */;
@@ -138,13 +122,6 @@
 			remoteGlobalIDString = CD592C1729C3DB32009AC14E;
 			remoteInfo = "serializer-test";
 		};
-		CDD4775129C5498E00BDB829 /* PBXContainerItemProxy */ = {
-			isa = PBXContainerItemProxy;
-			containerPortal = CDD4773729C5492E00BDB829 /* reflection.xcodeproj */;
-			proxyType = 1;
-			remoteGlobalIDString = CDA9561628726941006ACEC2;
-			remoteInfo = reflection;
-		};
 		CDD4775329C5498E00BDB829 /* PBXContainerItemProxy */ = {
 			isa = PBXContainerItemProxy;
 			containerPortal = CDD4774129C5493400BDB829 /* serializer.xcodeproj */;
@@ -177,8 +154,6 @@
 		CD592BF329C2A531009AC14E /* universe.tpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = universe.tpp; sourceTree = "<group>"; };
 		CD592C0E29C3D1E7009AC14E /* mailbox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mailbox.h; sourceTree = "<group>"; };
 		CDD4759129C4B7A200BDB829 /* config.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = config.cxx; sourceTree = "<group>"; };
-		CDD4759229C4B7A200BDB829 /* event.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = event.cxx; sourceTree = "<group>"; };
-		CDD4759329C4B7A200BDB829 /* condition.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = condition.cxx; sourceTree = "<group>"; };
 		CDD4759729C4BB0C00BDB829 /* event.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = event.h; sourceTree = "<group>"; };
 		CDD4759829C4BB0C00BDB829 /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
 		CDD4759929C4BB0C00BDB829 /* condition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = condition.h; sourceTree = "<group>"; };
@@ -197,7 +172,6 @@
 		CDD4760629C4DB2400BDB829 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
 		CDD4760729C4FE1900BDB829 /* condition_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = condition_test.cxx; sourceTree = "<group>"; };
 		CDD4772629C5492700BDB829 /* expect.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = expect.xcodeproj; path = external/expect/expect.xcodeproj; sourceTree = "<group>"; };
-		CDD4773729C5492E00BDB829 /* reflection.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = reflection.xcodeproj; path = external/reflection/reflection.xcodeproj; sourceTree = "<group>"; };
 		CDD4774129C5493400BDB829 /* serializer.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = serializer.xcodeproj; path = external/serializer/serializer.xcodeproj; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
@@ -229,7 +203,6 @@
 			children = (
 				CDD475B129C4CDBF00BDB829 /* GoogleMock.xcodeproj */,
 				CDD4772629C5492700BDB829 /* expect.xcodeproj */,
-				CDD4773729C5492E00BDB829 /* reflection.xcodeproj */,
 				CDD4774129C5493400BDB829 /* serializer.xcodeproj */,
 				CDD4759D29C4CDB500BDB829 /* shared_random_generator.xcodeproj */,
 				CDD475A729C4CDBA00BDB829 /* string-utils.xcodeproj */,
@@ -276,9 +249,7 @@
 		CD592BE429C2A3C8009AC14E /* src */ = {
 			isa = PBXGroup;
 			children = (
-				CDD4759329C4B7A200BDB829 /* condition.cxx */,
 				CDD4759129C4B7A200BDB829 /* config.cxx */,
-				CDD4759229C4B7A200BDB829 /* event.cxx */,
 				CD592BEB29C2A422009AC14E /* universe.cxx */,
 			);
 			path = src;
@@ -362,15 +333,6 @@
 			name = Products;
 			sourceTree = "<group>";
 		};
-		CDD4773829C5492E00BDB829 /* Products */ = {
-			isa = PBXGroup;
-			children = (
-				CDD4773E29C5492E00BDB829 /* reflection-test.xctest */,
-				CDD4774029C5492E00BDB829 /* libreflection.a */,
-			);
-			name = Products;
-			sourceTree = "<group>";
-		};
 		CDD4774229C5493400BDB829 /* Products */ = {
 			isa = PBXGroup;
 			children = (
@@ -412,7 +374,6 @@
 			buildRules = (
 			);
 			dependencies = (
-				CDD4775229C5498E00BDB829 /* PBXTargetDependency */,
 				CDD4775429C5498E00BDB829 /* PBXTargetDependency */,
 				CDD4775629C5498E00BDB829 /* PBXTargetDependency */,
 			);
@@ -478,10 +439,6 @@
 					ProductGroup = CDD475B229C4CDBF00BDB829 /* Products */;
 					ProjectRef = CDD475B129C4CDBF00BDB829 /* GoogleMock.xcodeproj */;
 				},
-				{
-					ProductGroup = CDD4773829C5492E00BDB829 /* Products */;
-					ProjectRef = CDD4773729C5492E00BDB829 /* reflection.xcodeproj */;
-				},
 				{
 					ProductGroup = CDD4774229C5493400BDB829 /* Products */;
 					ProjectRef = CDD4774129C5493400BDB829 /* serializer.xcodeproj */;
@@ -574,20 +531,6 @@
 			remoteRef = CDD4772E29C5492700BDB829 /* PBXContainerItemProxy */;
 			sourceTree = BUILT_PRODUCTS_DIR;
 		};
-		CDD4773E29C5492E00BDB829 /* reflection-test.xctest */ = {
-			isa = PBXReferenceProxy;
-			fileType = wrapper.cfbundle;
-			path = "reflection-test.xctest";
-			remoteRef = CDD4773D29C5492E00BDB829 /* PBXContainerItemProxy */;
-			sourceTree = BUILT_PRODUCTS_DIR;
-		};
-		CDD4774029C5492E00BDB829 /* libreflection.a */ = {
-			isa = PBXReferenceProxy;
-			fileType = archive.ar;
-			path = libreflection.a;
-			remoteRef = CDD4773F29C5492E00BDB829 /* PBXContainerItemProxy */;
-			sourceTree = BUILT_PRODUCTS_DIR;
-		};
 		CDD4774C29C5493400BDB829 /* libserializer.a */ = {
 			isa = PBXReferenceProxy;
 			fileType = archive.ar;
@@ -622,8 +565,6 @@
 			buildActionMask = 2147483647;
 			files = (
 				CD592BED29C2A422009AC14E /* universe.cxx in Sources */,
-				CDD4759629C4B7A200BDB829 /* condition.cxx in Sources */,
-				CDD4759529C4B7A200BDB829 /* event.cxx in Sources */,
 				CDD4759429C4B7A200BDB829 /* config.cxx in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
@@ -647,11 +588,6 @@
 			target = CD592BDA29C2A399009AC14E /* engine */;
 			targetProxy = CDD475C929C4D2BF00BDB829 /* PBXContainerItemProxy */;
 		};
-		CDD4775229C5498E00BDB829 /* PBXTargetDependency */ = {
-			isa = PBXTargetDependency;
-			name = reflection;
-			targetProxy = CDD4775129C5498E00BDB829 /* PBXContainerItemProxy */;
-		};
 		CDD4775429C5498E00BDB829 /* PBXTargetDependency */ = {
 			isa = PBXTargetDependency;
 			name = serializer;

+ 0 - 1
external/reflection

@@ -1 +0,0 @@
-Subproject commit 55d120ac81d4bf0c0377b6e704f8391e37b0cadb

+ 0 - 43
include/engine/condition.h

@@ -1,43 +0,0 @@
-//
-//  condition.hpp
-//  pokemon-engine
-//
-//  Created by Sam Jaffe on 7/6/22.
-//  Copyright © 2022 Sam Jaffe. All rights reserved.
-//
-
-#pragma once
-
-#include <functional>
-#include <string>
-#include <vector>
-
-#include <reflection/forward.h>
-#include <reflection/property.h>
-
-#include <engine/forwards.h>
-
-namespace engine {
-
-class Condition {
-public:
-  using Predicate = std::function<bool(engine::Event const &)>;
-  enum class Comparator { NOT_EQUAL = 0, EQUAL = 1, LESS = 2, GREATER = 4 };
-
-private:
-  std::string event_type_;
-  std::vector<Predicate> predicates_;
-
-public:
-  Condition() = default;
-  Condition(std::string event_type, std::vector<Predicate> predicates);
-
-  std::string_view event_type() const { return event_type_; }
-  bool operator()(Event const & on) const;
-
-  template <typename T>
-  static Predicate make_predicate(reflection::Property const & scope,
-                                  Comparator cmp, T const & value);
-};
-
-}

+ 0 - 31
include/engine/event.h

@@ -1,31 +0,0 @@
-#pragma once
-
-#include <cstdlib>
-#include <string>
-
-#include <reflection/context.h>
-#include <reflection/object.h>
-
-#include <engine/forwards.h>
-
-namespace engine {
-
-class Event {
-private:
-  uint64_t id_;
-  std::string_view type_;
-  reflection::Object source_;
-  reflection::Context context_;
-
-public:
-  Event(std::string_view type, reflection::Object const & source,
-        reflection::Context const & context);
-
-  bool is_a(std::string_view type) const { return type_ == type; }
-  std::string_view type() const { return type_; }
-
-  reflection::Object const & source() const { return source_; }
-  reflection::Context const & context() const { return context_; }
-};
-
-}

+ 0 - 2
include/engine/forwards.h

@@ -11,8 +11,6 @@
 #include <serializer/forwards.h>
 
 namespace engine {
-class Condition;
-class Event;
 class Mailbox;
 class Universe;
 }

+ 0 - 64
src/condition.cxx

@@ -1,64 +0,0 @@
-//
-//  condition.cxx
-//  pokemon-engine
-//
-//  Created by Sam Jaffe on 7/6/22.
-//  Copyright © 2022 Sam Jaffe. All rights reserved.
-//
-
-#include <engine/condition.h>
-
-#include <string>
-
-#include <expect/expect.hpp>
-#include <reflection/context.h>
-#include <string_utils/tokenizer.h>
-
-#include <engine/event.h>
-
-#define DEFINE_MAKE_PREDICATE(T)                                               \
-  template Condition::Predicate Condition::make_predicate(                     \
-      reflection::Property const &, Comparator, T const &)
-
-namespace engine {
-
-Condition::Condition(std::string event_type, std::vector<Predicate> predicates)
-    : event_type_(std::move(event_type)), predicates_(std::move(predicates)) {
-  expects(!predicates_.empty(),
-          "must provide at least one predicate in condition");
-}
-
-bool Condition::operator()(Event const & on) const {
-  return on.type() == event_type_ &&
-         std::all_of(predicates_.begin(), predicates_.end(),
-                     [&](auto & pred) { return pred(on); });
-}
-
-template <typename T>
-Condition::Predicate
-Condition::make_predicate(reflection::Property const & scope, Comparator cmp,
-                          T const & value) {
-  using C = Comparator;
-  using namespace magic_enum::bitwise_operators;
-
-  // Replace zero Comparator with bitwise not equals
-  if (cmp == C::NOT_EQUAL) { cmp = C::LESS | C::GREATER; }
-  // Prohibit tautologies
-  expects(cmp < (C::EQUAL | C::LESS | C::GREATER),
-          "cannot use all states in Comparitor");
-
-  return [=](engine::Event const & event) {
-    T const & state(event.context().get(scope));
-    if (state == value) {
-      return static_cast<bool>(cmp & C::EQUAL);
-    } else if (state < value) {
-      return static_cast<bool>(cmp & C::LESS);
-    } else {
-      return static_cast<bool>(cmp & C::GREATER);
-    }
-  };
-}
-
-DEFINE_MAKE_PREDICATE(int);
-DEFINE_MAKE_PREDICATE(std::string);
-}

+ 0 - 27
src/event.cxx

@@ -1,27 +0,0 @@
-//
-//  event.cxx
-//  pokemon-engine
-//
-//  Created by Sam Jaffe on 6/18/22.
-//  Copyright © 2022 Sam Jaffe. All rights reserved.
-//
-
-#include <engine/event.h>
-
-#include <atomic>
-#include <functional>
-#include <string>
-#include <utility>
-
-namespace engine {
-
-static uint64_t next_id() {
-  static std::atomic<uint64_t> value_{0};
-  return value_.fetch_add(1);
-}
-
-Event::Event(std::string_view type, reflection::Object const & source,
-             reflection::Context const & context)
-    : id_(next_id()), type_(type), source_(source), context_(context) {}
-
-}