فهرست منبع

Use prototype_factory binding for burstshot pattern/general bullet patterns.

Sam Jaffe 6 سال پیش
والد
کامیت
37b0d18c42
4فایلهای تغییر یافته به همراه51 افزوده شده و 4 حذف شده
  1. 8 0
      danmaku.xcodeproj/project.pbxproj
  2. 13 4
      include/danmaku/bullet_pattern.hpp
  3. 4 0
      src/pattern/bullet_pattern.cxx
  4. 26 0
      src/pattern/burstshot_pattern.cxx

+ 8 - 0
danmaku.xcodeproj/project.pbxproj

@@ -24,6 +24,7 @@
 		CD49F76A229B0A6C00EB8926 /* bullet.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD49F769229B0A6C00EB8926 /* bullet.cxx */; };
 		CD49F76D229B0A8000EB8926 /* bullet_pattern.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD49F76C229B0A8000EB8926 /* bullet_pattern.cxx */; };
 		CD49F778229B0FCD00EB8926 /* actor.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD49F777229B0FCD00EB8926 /* actor.cxx */; };
+		CD49F783229B194C00EB8926 /* burstshot_pattern.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD49F782229B194C00EB8926 /* burstshot_pattern.cxx */; };
 		CD7E87A52295FCED00D877FE /* danmakuUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = CD7E87A42295FCED00D877FE /* danmakuUITests.m */; };
 /* End PBXBuildFile section */
 
@@ -84,6 +85,7 @@
 		CD49F769229B0A6C00EB8926 /* bullet.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = bullet.cxx; sourceTree = "<group>"; };
 		CD49F76C229B0A8000EB8926 /* bullet_pattern.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = bullet_pattern.cxx; sourceTree = "<group>"; };
 		CD49F777229B0FCD00EB8926 /* actor.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = actor.cxx; sourceTree = "<group>"; };
+		CD49F782229B194C00EB8926 /* burstshot_pattern.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = burstshot_pattern.cxx; sourceTree = "<group>"; };
 		CD7E87862295FCEA00D877FE /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
 		CD7E87872295FCEA00D877FE /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
 		CD7E878D2295FCEA00D877FE /* GameView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GameView.h; sourceTree = "<group>"; };
@@ -136,6 +138,7 @@
 			isa = PBXGroup;
 			children = (
 				CD49F76C229B0A8000EB8926 /* bullet_pattern.cxx */,
+				CD49F782229B194C00EB8926 /* burstshot_pattern.cxx */,
 			);
 			path = pattern;
 			sourceTree = "<group>";
@@ -413,6 +416,7 @@
 				CD49F778229B0FCD00EB8926 /* actor.cxx in Sources */,
 				CD1C833C2298A98700825C4E /* main.m in Sources */,
 				CD49F767229B0A3000EB8926 /* player.cxx in Sources */,
+				CD49F783229B194C00EB8926 /* burstshot_pattern.cxx in Sources */,
 				CD49F762229B0A0500EB8926 /* enemy.cxx in Sources */,
 				CD49F76A229B0A6C00EB8926 /* bullet.cxx in Sources */,
 				CD49F75F229B09F800EB8926 /* level.cxx in Sources */,
@@ -523,10 +527,12 @@
 				MTL_FAST_MATH = YES;
 				ONLY_ACTIVE_ARCH = YES;
 				SDKROOT = macosx;
+				SYSTEM_HEADER_SEARCH_PATHS = /opt/local/include/;
 				USER_HEADER_SEARCH_PATHS = (
 					"$(PROJECT_DIR)/../game/include/expect/include",
 					"$(BUILT_PRODUCTS_DIR)/usr/local/include/",
 					"$(PROJECT_DIR)/include/",
+					"$(PROJECT_DIR)/external/resource_factory/include/",
 				);
 			};
 			name = Debug;
@@ -580,10 +586,12 @@
 				MTL_ENABLE_DEBUG_INFO = NO;
 				MTL_FAST_MATH = YES;
 				SDKROOT = macosx;
+				SYSTEM_HEADER_SEARCH_PATHS = /opt/local/include/;
 				USER_HEADER_SEARCH_PATHS = (
 					"$(PROJECT_DIR)/../game/include/expect/include",
 					"$(BUILT_PRODUCTS_DIR)/usr/local/include/",
 					"$(PROJECT_DIR)/include/",
+					"$(PROJECT_DIR)/external/resource_factory/include/",
 				);
 			};
 			name = Release;

+ 13 - 4
include/danmaku/bullet_pattern.hpp

@@ -9,13 +9,22 @@
 #pragma once
 
 #include <json/forwards.h>
+#include <memory>
+
+namespace objects { namespace prototype {
+  template <typename, typename...> class factory;
+}}
 
 namespace danmaku {
   class actor;
   struct bullet_pattern {
-    static std::shared_ptr<bullet_pattern> get_pattern(actor * owner,
-                                                       Json::Value const &);
     virtual ~bullet_pattern() = default;
-    virtual void update() = 0;
-  }
+    virtual void update(float delta) = 0;
+  };
+  
+  using bullet_pattern_factory = objects::prototype::factory<
+      std::shared_ptr<bullet_pattern>, actor*, Json::Value const &>;
 }
+
+#define BIND_BULLET_PATTERN(name, function)                              \
+  bool const _ = bullet_pattern_factory::instance().bind(name, function) \

+ 4 - 0
src/pattern/bullet_pattern.cxx

@@ -7,3 +7,7 @@
 //
 
 #include "danmaku/bullet_pattern.hpp"
+
+#include "resource_factory/prototype_factory.hpp"
+
+INSTANTIATE_PROTOTYPE_FACTORY_2(danmaku::bullet_pattern_factory);

+ 26 - 0
src/pattern/burstshot_pattern.cxx

@@ -0,0 +1,26 @@
+//
+//  burstshot_pattern.cxx
+//  danmaku
+//
+//  Created by Sam Jaffe on 5/26/19.
+//  Copyright © 2019 Sam Jaffe. All rights reserved.
+//
+
+#include "danmaku/bullet_pattern.hpp"
+#include "resource_factory/prototype_factory.hpp"
+
+struct burstshot : public danmaku::bullet_pattern {
+  static std::shared_ptr<burstshot> create(danmaku::actor*,
+                                           Json::Value const &);
+  
+  void update(float delta) override {}
+};
+
+std::shared_ptr<burstshot> burstshot::create(danmaku::actor*,
+                                             Json::Value const &) {
+  return std::make_shared<burstshot>();
+}
+
+namespace danmaku {
+  BIND_BULLET_PATTERN("burstshot", &burstshot::create);
+}