FreeTrainの進化系を目指す
Replace entries of contribution factories to declaration of contributions.
xmlでcontribution宣言方法を整理(basetypeとかimplementationとか紛らわしいのでclass属性に統一)。
factory-class指定はオプション。
| @@ -4,17 +4,15 @@ | ||
| 4 | 4 | <author>C477</author> |
| 5 | 5 | <homepage>http://www.rocket.ne.jp/~nao/</homepage> |
| 6 | 6 | |
| 7 | - <contribution type="factory" id="test1"> | |
| 7 | + <declare-contribution> | |
| 8 | 8 | <name>dummy</name> |
| 9 | - <class name="nft.framework.plugin.FixedClassContributionFactory"/> | |
| 10 | - <implementation name="nft.framework.plugin.DummyContribution" /> | |
| 11 | - </contribution> | |
| 9 | + <class name="nft.framework.plugin.DummyContribution" /> | |
| 10 | + </declare-contribution> | |
| 12 | 11 | |
| 13 | - <contribution type="factory" id="test2"> | |
| 14 | - <name>test_dummy</name> | |
| 15 | - <class name="nft.framework.plugin.FixedClassContributionFactory"/> | |
| 16 | - <implementation name="nft.framework.plugin.DummyContribution" /> | |
| 17 | - </contribution> | |
| 12 | + <declare-contribution type="test_dummy"> | |
| 13 | + <name>dummy2</name> | |
| 14 | + <class name="nft.framework.plugin.DummyContribution" /> | |
| 15 | + </declare-contribution> | |
| 18 | 16 | |
| 19 | 17 | <contribution type="Image" id="tex112x136x96"> |
| 20 | 18 | <src>cube112x136x96.bmp</src> |
| @@ -15,88 +15,73 @@ | ||
| 15 | 15 | <name>TestBinaryModule</name> |
| 16 | 16 | <class name="nft.debug.TestBinaryModule" codebase=".Core"/> |
| 17 | 17 | </contribution> |
| 18 | - <contribution type="factory" id="F_Anonymous"> | |
| 18 | + <declare-contribution> | |
| 19 | 19 | <name>Anonymous</name> |
| 20 | 20 | <description>Independent contributions decrared without specific factroy.</description> |
| 21 | - <implementation name="nft.framework.plugin.CtbAnonymousCtbFactory"/> | |
| 22 | - </contribution> | |
| 23 | - <contribution type="factory" id="F_Dummy"> | |
| 21 | + <factory-class name="nft.framework.plugin.CtbAnonymousCtbFactory"/> | |
| 22 | + </declare-contribution> | |
| 23 | + <declare-contribution type="ignore"> | |
| 24 | 24 | <name>Dummy(for debug)</name> |
| 25 | 25 | <description>dummy contribtions for debug/development purpose.</description> |
| 26 | - <implementation name="nft.framework.plugin.DummyContributionFactory"/> | |
| 27 | - <declare type="ignore"/> | |
| 28 | - </contribution> | |
| 29 | - <contribution type="factory" id="F_SubForm"> | |
| 26 | + <factory-class name="nft.framework.plugin.DummyContributionFactory"/> | |
| 27 | + </declare-contribution> | |
| 28 | + <declare-contribution> | |
| 30 | 29 | <name>SubForm</name> |
| 31 | 30 | <description>Child GUI forms</description> |
| 32 | - <implementation name="nft.contributions.ui.CtbSubform"/> | |
| 33 | - </contribution> | |
| 34 | - <contribution type="factory" id="F_MenuItems"> | |
| 31 | + <class name="nft.contributions.ui.CtbSubform"/> | |
| 32 | + </declare-contribution> | |
| 33 | + <declare-contribution type="MenuItems"> | |
| 35 | 34 | <name>Menu items</name> |
| 36 | - <implementation name="nft.contributions.ui.CtbMenuItem"/> | |
| 37 | - <declare type="MenuItems"/> | |
| 38 | - </contribution> | |
| 39 | - <contribution type="factory" id="F_ToolButtons"> | |
| 35 | + <class name="nft.contributions.ui.CtbMenuItem"/> | |
| 36 | + </declare-contribution> | |
| 37 | + <declare-contribution type="ToolButtons"> | |
| 40 | 38 | <name>Tool buttons</name> |
| 41 | - <implementation name="nft.contributions.ui.CtbToolButton"/> | |
| 42 | - <declare type="ToolButtons"/> | |
| 43 | - </contribution> | |
| 44 | - <contribution type="factory" id="F_Command"> | |
| 39 | + <class name="nft.contributions.ui.CtbToolButton"/> | |
| 40 | + </declare-contribution> | |
| 41 | + <declare-contribution type="Command"> | |
| 45 | 42 | <name>User commands</name> |
| 46 | - <implementation name="nft.contributions.ui.CtbCommandEntity"/> | |
| 47 | - <declare type="Command"/> | |
| 48 | - </contribution> | |
| 49 | - <contribution type="factory" id="F_CommandUI"> | |
| 43 | + <class name="nft.contributions.ui.CtbCommandEntity"/> | |
| 44 | + </declare-contribution> | |
| 45 | + <declare-contribution type="CommandUI"> | |
| 50 | 46 | <name>Command UIs</name> |
| 51 | - <implementation name="nft.contributions.ui.CtbCommandUI"/> | |
| 52 | - <declare type="CommandUI"/> | |
| 53 | - </contribution> | |
| 54 | - <contribution type="factory" id="F_CommandUIGroup"> | |
| 47 | + <class name="nft.contributions.ui.CtbCommandUI"/> | |
| 48 | + </declare-contribution> | |
| 49 | + <declare-contribution type="CommandUIGroup"> | |
| 55 | 50 | <name>Command UI Group definition</name> |
| 56 | - <implementation name="nft.contributions.ui.CtbCommandUIGroup"/> | |
| 57 | - <declare type="CommandUIGroup"/> | |
| 58 | - </contribution> | |
| 59 | - <contribution type="factory" id="F_ImageSource"> | |
| 51 | + <class name="nft.contributions.ui.CtbCommandUIGroup"/> | |
| 52 | + </declare-contribution> | |
| 53 | + <declare-contribution type="Image"> | |
| 60 | 54 | <name>Image Resources</name> |
| 61 | - <basetype name="nft.contributions.graphics.CtbImageResource" codebase=".Core"/> | |
| 62 | - <declare type="Image"/> | |
| 63 | - </contribution> | |
| 64 | - <contribution type="factory" id="F_TerrainGenerator"> | |
| 55 | + <class name="nft.contributions.graphics.CtbImageResource" codebase=".Core"/> | |
| 56 | + </declare-contribution> | |
| 57 | + <declare-contribution type="TerrainGenerator"> | |
| 65 | 58 | <name>Terrain generators</name> |
| 66 | - <class name="nft.framework.plugin.InheritableContributionFactory"/> | |
| 67 | - <basetype name="nft.contributions.game.CtbTerrainGenerator" codebase=".Core"/> | |
| 68 | - <declare type="TerrainGenerator"/> | |
| 69 | - </contribution> | |
| 70 | - <contribution type="factory" id="F_WorldDivider"> | |
| 59 | + <class name="nft.contributions.game.CtbTerrainGenerator" codebase=".Core"/> | |
| 60 | + </declare-contribution> | |
| 61 | + <declare-contribution type="WorldDivider"> | |
| 71 | 62 | <name>World dividers</name> |
| 72 | - <class name="nft.framework.plugin.InheritableContributionFactory"/> | |
| 73 | - <basetype name="nft.contributions.game.CtbWorldDivider" codebase=".Core"/> | |
| 74 | - <declare type="WorldDivider"/> | |
| 75 | - </contribution> | |
| 76 | - <contribution type="factory" id="F_GroundTextrue"> | |
| 63 | + <class name="nft.contributions.game.CtbWorldDivider" codebase=".Core"/> | |
| 64 | + </declare-contribution> | |
| 65 | + <declare-contribution type="GroundTexture"> | |
| 77 | 66 | <name>Terrain(ground) textrue sets</name> |
| 78 | - <class name="nft.contributions.terrain.CtbGroundTextureFactory" codebase=".Core"/> | |
| 79 | - <basetype name="nft.contributions.terrain.CtbSimpleGroundTexture" codebase=".Core"/> | |
| 80 | - <declare type="GroundTexture"/> | |
| 81 | - </contribution> | |
| 82 | - <contribution type="factory" id="F_CliffTexture"> | |
| 67 | + <class name="nft.contributions.terrain.CtbSimpleGroundTexture" codebase=".Core"/> | |
| 68 | + <factory-class name="nft.contributions.terrain.CtbGroundTextureFactory" codebase=".Core"/> | |
| 69 | + </declare-contribution> | |
| 70 | + <declare-contribution type="CliffTexture"> | |
| 83 | 71 | <name>Cliff texture sets</name> |
| 84 | - <class name="nft.contributions.terrain.CtbCliffTextureFactory" codebase=".Core"/> | |
| 85 | - <basetype name="nft.contributions.terrain.CtbSimpleCliffTexture" codebase=".Core"/> | |
| 86 | - <declare type="CliffTexture"/> | |
| 87 | - </contribution> | |
| 88 | - <contribution type="factory" id="F_HeightCutPlaneTexture"> | |
| 72 | + <class name="nft.contributions.terrain.CtbSimpleCliffTexture" codebase=".Core"/> | |
| 73 | + <factory-class name="nft.contributions.terrain.CtbCliffTextureFactory" codebase=".Core"/> | |
| 74 | + </declare-contribution> | |
| 75 | + <declare-contribution type="HeightCutPlaneTexture"> | |
| 89 | 76 | <name>Height-cut plane texture sets</name> |
| 90 | - <class name="nft.contributions.terrain.CtbHeightCutPlaneTextureFactory" codebase=".Core"/> | |
| 91 | - <basetype name="nft.contributions.terrain.CtbHeightCutPlaneTexture" codebase=".Core"/> | |
| 92 | - <declare type="HeightCutPlaneTexture"/> | |
| 93 | - </contribution> | |
| 94 | - <contribution type="factory" id="F_HeightCutSlopeTexture"> | |
| 77 | + <class name="nft.contributions.terrain.CtbHeightCutPlaneTexture" codebase=".Core"/> | |
| 78 | + <factory-class name="nft.contributions.terrain.CtbHeightCutPlaneTextureFactory" codebase=".Core"/> | |
| 79 | + </declare-contribution> | |
| 80 | + <declare-contribution type="HeightCutSlopeTexture"> | |
| 95 | 81 | <name>Height-cut slope (terrain) texture sets</name> |
| 96 | - <class name="nft.contributions.terrain.CtbHeightCutSlopeTextureFactory" codebase=".Core"/> | |
| 97 | - <basetype name="nft.contributions.terrain.CtbHeightCutSlopeTexture" codebase=".Core"/> | |
| 98 | - <declare type="HeightCutSlopeTexture"/> | |
| 99 | - </contribution> | |
| 82 | + <class name="nft.contributions.terrain.CtbHeightCutSlopeTexture" codebase=".Core"/> | |
| 83 | + <factory-class name="nft.contributions.terrain.CtbHeightCutSlopeTextureFactory" codebase=".Core"/> | |
| 84 | + </declare-contribution> | |
| 100 | 85 | |
| 101 | 86 | <contribution type="MenuItems" id="BaseMenu"> |
| 102 | 87 | <name>システム基本メニュー</name> |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | ・凹型(interior)/凸型(exterior)に分かれた3Dオブジェクト(線路など用) |
| 2 | -・選択UIの基本、ステータス表示の基本 | |
| 2 | +・選択UIの基本、ステータス表示の基本 InputController<-*SitePicker 見た目=skin | |
| 3 | 3 | ・MRT昼夜同時描画/HitTest用マップ |
| 4 | 4 | |
| 5 | 5 | ◎開発メモ |
| @@ -75,11 +75,12 @@ | ||
| 75 | 75 | ・Q.いつフィルタを掛けるか。 |
| 76 | 76 | A.OffScreenSerfaceを更新時に。→XNAのPSで |
| 77 | 77 | |
| 78 | -■MultiRenderTargetの用途割り当てについて | |
| 78 | +■MultiRenderTargetの用途割り当てについて(XNA4/HiDefでは最大4つ) | |
| 79 | 79 | ゲームビュー&プレコンバインドでは下記 |
| 80 | 80 | 0:RGB=昼間色、A=透過情報 |
| 81 | -1:RGB=ID塗り分け、A=深度 | |
| 82 | -2:RGB=夜間色、A=照り返し | |
| 81 | +1:AR=グループ内ID GB=ID塗り分け | |
| 82 | +2:RGB=夜間色、A= | |
| 83 | +3:RGB=照り返し、A=深度 | |
| 83 | 84 | |
| 84 | 85 | IDは24bit枠 |
| 85 | 86 | ・地形は(x-y)値(16bit)+0xff |
| @@ -21,7 +21,7 @@ | ||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public InheritableContributionFactory( ParamsReader e) : |
| 24 | - this( PluginUtil.loadTypeFromManifest(e["basetype"])) {} | |
| 24 | + this( PluginUtil.loadTypeFromManifest(e["class"])) {} | |
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | private readonly Type baseType; |
| @@ -15,7 +15,7 @@ | ||
| 15 | 15 | public abstract class CtbCustomCtbFactory : Contribution, IContributionFactory { |
| 16 | 16 | public CtbCustomCtbFactory(Plugin p, ParamsReader e) |
| 17 | 17 | : base(p, e) { |
| 18 | - baseType = PluginUtil.loadTypeFromManifest(e["basetype"]); | |
| 18 | + baseType = PluginUtil.loadTypeFromManifest(e["class"]); | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | #region IContributionFactory メンバ |
| @@ -216,6 +216,7 @@ | ||
| 216 | 216 | try |
| 217 | 217 | { |
| 218 | 218 | LoadBinaries(p, p._reader); |
| 219 | + LoadCtbDeclarations(p, p._reader); | |
| 219 | 220 | } |
| 220 | 221 | catch( Exception e ) |
| 221 | 222 | { |
| @@ -367,6 +368,40 @@ | ||
| 367 | 368 | } |
| 368 | 369 | |
| 369 | 370 | /// <summary> |
| 371 | + /// Load declaration of contributions from this plug-in | |
| 372 | + /// </summary> | |
| 373 | + internal void LoadCtbDeclarations(Plugin p, ParamsReader _reader) { | |
| 374 | + // locate contribution factories first, | |
| 375 | + // because we'll need them to load contributions. | |
| 376 | + foreach (ParamsReader ctb_reader in _reader.EnumChildren("declare-contribution")) { | |
| 377 | + //string type = ctb_reader["type"].InnerText; | |
| 378 | + try { | |
| 379 | + Contribution cb = null; | |
| 380 | + // load a contribution factory | |
| 381 | + NotifyStartParse(p, ctb_reader); | |
| 382 | + string regtype= ctb_reader["type|name"].InnerText; | |
| 383 | + object[] args = new object[] { ctb_reader }; | |
| 384 | + // create and register contribution factory | |
| 385 | + IContributionFactory factory = | |
| 386 | + PluginUtil.createCtbFactory(p, ctb_reader); | |
| 387 | + AddContributionFactory(regtype, factory); | |
| 388 | + cb = factory as Contribution; | |
| 389 | + // Register dummy contribution (in order to list on Dialog). | |
| 390 | + if (cb == null) { | |
| 391 | + cb = new CtbContributionDefiner(p, ctb_reader); | |
| 392 | + } | |
| 393 | + | |
| 394 | + cb.Attach(); | |
| 395 | + cb._state = InstallationState.Ready; | |
| 396 | + } catch (Exception e) { | |
| 397 | + p._state = InstallationState.FatalError; | |
| 398 | + string msg = MakeContribExceptionMessage(p, ctb_reader); | |
| 399 | + throw new Exception(msg, e); | |
| 400 | + } | |
| 401 | + } | |
| 402 | + } | |
| 403 | + | |
| 404 | + /// <summary> | |
| 370 | 405 | /// Loads class type contributions from this plug-in |
| 371 | 406 | /// </summary> |
| 372 | 407 | internal void LoadBinaries(Plugin p, ParamsReader _reader) { |
| @@ -376,29 +411,9 @@ | ||
| 376 | 411 | string type = ctb_reader["type"].InnerText; |
| 377 | 412 | try { |
| 378 | 413 | Contribution cb = null; |
| 379 | - // load a contribution factory | |
| 380 | - if ("factory".Equals(type)) { | |
| 414 | + // load binary module contribution. | |
| 415 | + if ("binary".Equals(type)) { | |
| 381 | 416 | NotifyStartParse(p, ctb_reader); |
| 382 | - ParamsReader nd = ctb_reader["declare"]; | |
| 383 | - string regtype; | |
| 384 | - if (!nd.IsNull) { | |
| 385 | - regtype = nd["type"].InnerText; | |
| 386 | - } else { | |
| 387 | - // use name property for alternative. | |
| 388 | - regtype = ctb_reader["name"].InnerText; | |
| 389 | - } | |
| 390 | - object[] args = new object[] { ctb_reader }; | |
| 391 | - // create and register contribution factory | |
| 392 | - IContributionFactory factory = | |
| 393 | - PluginUtil.createCtbFactory(p, ctb_reader); | |
| 394 | - AddContributionFactory(regtype, factory); | |
| 395 | - cb = factory as Contribution; | |
| 396 | - // Register dummy contribution (in order to list on Dialog). | |
| 397 | - if (cb == null) { | |
| 398 | - cb = new CtbContributionDefiner(p, ctb_reader); | |
| 399 | - } | |
| 400 | - } else if ("binary".Equals(type)) { | |
| 401 | - NotifyStartParse(p, ctb_reader); | |
| 402 | 417 | cb = PluginUtil.createContributionObject(p, ctb_reader) as BinaryModule; |
| 403 | 418 | if (cb == null) { |
| 404 | 419 | // create dummy module for list Dialog |
| @@ -429,7 +444,7 @@ | ||
| 429 | 444 | try { |
| 430 | 445 | count++; |
| 431 | 446 | string type = ctb_reader["type"].InnerText; |
| 432 | - if ("factory".Equals(type) || "binary".Equals(type)) continue; // ignore | |
| 447 | + if ("binary".Equals(type) /* || "factory".Equals(type)*/) continue; // ignore | |
| 433 | 448 | |
| 434 | 449 | NotifyStartParse(p, ctb_reader); |
| 435 | 450 | IContributionFactory factory = GetContributionFactory(type); |
| @@ -33,7 +33,10 @@ | ||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public static IContributionFactory createCtbFactory(Plugin p, ParamsReader elm) { |
| 36 | - ParamsReader el = elm["class"]; | |
| 36 | + ParamsReader el = elm["factory-class"]; | |
| 37 | + if (elm["id"].IsNull) { | |
| 38 | + elm.OverWrite("id", "factory#" + elm["name|type"]); | |
| 39 | + } | |
| 37 | 40 | if (el.IsNull) // should use default factory. |
| 38 | 41 | return new DefaultContributionFactory(p, elm); |
| 39 | 42 | Type t = loadTypeFromManifest(el); |
| @@ -33,7 +33,7 @@ | ||
| 33 | 33 | try |
| 34 | 34 | { |
| 35 | 35 | // give XmlNode as first argument of constructor. |
| 36 | - result = Activator.CreateInstance(t, new object[] { reader }) as CtbAnonymous; | |
| 36 | + result = Activator.CreateInstance(t, new object[] { owner, reader }) as CtbAnonymous; | |
| 37 | 37 | } |
| 38 | 38 | catch (Exception e) |
| 39 | 39 | { |
| @@ -16,7 +16,7 @@ | ||
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | public CustomContributionFactory(ParamsReader e) |
| 19 | - : this(PluginUtil.loadTypeFromManifest(e["basetype"])) { } | |
| 19 | + : this(PluginUtil.loadTypeFromManifest(e["class"])) { } | |
| 20 | 20 | |
| 21 | 21 | |
| 22 | 22 | private readonly Type baseType; |
| @@ -29,9 +29,9 @@ | ||
| 29 | 29 | internal protected DefaultContributionFactory(Plugin p, ParamsReader elm) |
| 30 | 30 | : base(p, elm) |
| 31 | 31 | { |
| 32 | - ParamsReader nd = elm["basetype|implementation"]; | |
| 32 | + ParamsReader nd = elm["class|implementation"]; | |
| 33 | 33 | if (nd.IsNull) { |
| 34 | - throw new PluginXmlException(p, elm, "<basetype> is required for ContributionFactory."); | |
| 34 | + throw new PluginXmlException(p, elm, "Contribution class must be specified by 'name' attribute in the <class> element."); | |
| 35 | 35 | } |
| 36 | 36 | this.baseType = PluginUtil.loadTypeFromManifest(nd); |
| 37 | 37 | } |
| @@ -41,13 +41,23 @@ | ||
| 41 | 41 | |
| 42 | 42 | public Contribution load(Plugin owner, ParamsReader e) |
| 43 | 43 | { |
| 44 | - Contribution contrib = (Contribution)Activator.CreateInstance(baseType, new object[] { owner, e }); | |
| 45 | - if( baseType.IsInstanceOfType(contrib) ) | |
| 46 | - return contrib; | |
| 47 | - else | |
| 48 | - throw new PluginXmlException(owner, e, string.Format( | |
| 49 | - "{0} is incorrect for this contribution (expected:{1})", | |
| 50 | - contrib.GetType().FullName, baseType.FullName )); | |
| 44 | + ParamsReader r = e["class"]; | |
| 45 | + Type prodtype; | |
| 46 | + if (r.IsNull) { | |
| 47 | + prodtype = this.baseType; | |
| 48 | + } else { | |
| 49 | + object[] args = new object[] { owner, e }; | |
| 50 | + prodtype = PluginUtil.loadTypeFromManifest(r); | |
| 51 | + if (!prodtype.IsSubclassOf(baseType)) { | |
| 52 | + /* | |
| 53 | + throw new PluginXmlException(owner, e, string.Format( | |
| 54 | + "{0} is incorrect for this contribution (expected:{1})", prodtype.FullName, baseType.FullName)); | |
| 55 | + */ | |
| 56 | + prodtype = this.baseType; | |
| 57 | + } | |
| 58 | + } | |
| 59 | + Contribution contrib = (Contribution)Activator.CreateInstance(prodtype, new object[] { owner, e }); | |
| 60 | + return contrib; | |
| 51 | 61 | } |
| 52 | 62 | |
| 53 | 63 | public override string Description { |