From 9ea26d2563b8cdbb2c13b593c1b8d188bebd6118 Mon Sep 17 00:00:00 2001 From: klemek Date: Thu, 17 Dec 2020 19:26:11 +0100 Subject: [PATCH] gate definitions refactoring --- Assets/Scenes/Workspace.unity | 277 ------------ Assets/Scripts/Utils.cs | 2 + .../Scripts/Workspace/Gates/GateDefinition.cs | 214 ++++----- .../Workspace/Gates/GateDefinitionList.cs | 409 +++++++++--------- Assets/Scripts/Workspace/Gates/GateType.cs | 21 +- Assets/Scripts/Workspace/Gates/State.cs | 6 +- TODO.txt | 6 +- 7 files changed, 338 insertions(+), 597 deletions(-) diff --git a/Assets/Scenes/Workspace.unity b/Assets/Scenes/Workspace.unity index 391c32d..456361e 100755 --- a/Assets/Scenes/Workspace.unity +++ b/Assets/Scenes/Workspace.unity @@ -778,73 +778,6 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 881209084} m_CullTransparentMesh: 0 ---- !u!1 &1133128780 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1133128783} - - component: {fileID: 1133128782} - - component: {fileID: 1133128781} - m_Layer: 0 - m_Name: and - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &1133128781 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1133128780} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: ef8b96895a0ec4ba685178a052544251, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Material: {fileID: 2100000, guid: 8d66e65c66e29504199ed664979682cd, type: 2} - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 1 - m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} - m_Maskable: 1 - m_OnCullStateChanged: - m_PersistentCalls: - m_Calls: [] - m_Sprite: {fileID: 2126938960} - m_PreserveAspect: 0 ---- !u!222 &1133128782 -CanvasRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1133128780} - m_CullTransparentMesh: 0 ---- !u!224 &1133128783 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1133128780} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 6 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 100, y: 100} - m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &1741727033 GameObject: m_ObjectHideFlags: 0 @@ -939,216 +872,6 @@ Transform: m_Father: {fileID: 1741727034} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!213 &2126938960 -Sprite: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: andSprite - m_Rect: - serializedVersion: 2 - x: 0 - y: 0 - width: 500 - height: 500 - m_Offset: {x: -250, y: 250} - m_Border: {x: 0, y: 0, z: 0, w: 0} - m_PixelsToUnits: 100 - m_Pivot: {x: 0, y: 1} - m_Extrude: 0 - m_IsPolygon: 0 - m_AtlasName: - m_PackingTag: - m_RenderDataKey: - 00000000000000000000000000000000: 0 - m_AtlasTags: [] - m_SpriteAtlas: {fileID: 0} - m_RD: - serializedVersion: 3 - texture: {fileID: 0} - alphaTexture: {fileID: 0} - secondaryTextures: [] - m_SubMeshes: - - serializedVersion: 2 - firstByte: 0 - indexCount: 498 - topology: 0 - baseVertex: 0 - firstVertex: 0 - vertexCount: 168 - localAABB: - m_Center: {x: 0, y: 0, z: 0} - m_Extent: {x: 0, y: 0, z: 0} - m_IndexBuffer: 0000010002000000030001000400030000000400050003000600050004000600070005000800070006000800090007000a00090008000a000b0009000c000b000a000c000d000b000c000e000d000f000e000c000f0010000e00110010000f001100120010001300120011001300140012001500140013001500160014001500170016001800170015001800190017001a00190018001a001b0019001a001c001b001a001d001c001a001e001d001a001f001e001a0020001f001a00210020001a00220021001a00230022001a0024002300250024001a0025002600240027002600250027002800260027002900280027002a00290027002b002a0027002c002b0027002d002c0027002e002d0027002f002e00270030002f002700310030002700320031002700330032002700340033003400270035003600370039003600390038003a00380039003a0039003b003a003b003d003a003d003c003c003d003f003c003f003e003e003f0041003e0041004000400041004300400043004200420043004500420045004400440045004700440047004600460047004900460049004800480049004b0048004b004a004a004b004d004a004d004c004c004d004f004c004f004e004e004f0051004e0051005000500051005300500053005200520053005500520055005400540055005700540057005600560057005900560059005800580059005b0058005b005a005a005b005d005a005d005c005c005d005f005c005f005e005e005f0061005e0061006000600061006300600063006200620063006500620065006400640065006700640067006600660067006900660069006800680069006b0068006b006a006a006b006d006a006d006c006c006d006f006c006f006e006e006f0071006e0071007000700071007300700073007200720073007500720075007400740075007700740077007600760077007900760079007800780079007b0078007b007a007a007b007d007a007d007c007c007d007f007c007f007e007e007f0081007e0081008000800081008300800083008200820083008500820085008400840085008700840087008600860087008900860089008800880089008b0088008b008a008a008b008d008a008d008c008c008d008f008c008f008e008e008f0091008e0091009000900091009300900093009200920093009500920095009400940095009700940097009600960097009900960099009800980099009b0098009b009a009a009b009d009a009d009c009c009d009f009c009f009e009e009f00a1009e00a100a000a000a100a300a000a300a200a400a200a300a400a300a500a400a500a700a400a700a6003600a6003700a7003700a600 - m_VertexData: - serializedVersion: 3 - m_VertexCount: 168 - m_Channels: - - stream: 0 - offset: 0 - format: 0 - dimension: 3 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 1 - offset: 0 - format: 2 - dimension: 4 - - stream: 1 - offset: 4 - format: 0 - dimension: 2 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - m_DataSize: 4032 - _typelessdata: 078c6f40e72380c000000000e0207b40fd1475c000000000788f754047d77ac0000000002020804030076fc0000000008f1669401db082c000000000cb76824030b468c000000000122f6240250d85c00000000072948440442262c00000000089d55a40d53787c00000000016798640bd575bc000000000f50953400f2d89c000000000b4248840dd5a54c0000000005ecc4a40a9e98ac0000000004f978940f4314dc000000000e6d08a404de345c000000000bd1c42407c6a8cc00000000078d18b402f753ec00000000010fb384066ac8dc00000000007998c40e6ed36c00000000061672f4041ac8ec00000000090278d40be532fc000000000a6612540e7668fc000000000177d8d4002ad27c00000000099998d40fbff1fc000000000e3e91a4034d98fc000000000167d8d40f25218c000000000ffff0f40ffff8fc00000000091278d4036ac10c00000000006998c400f1209c00000000077d18b40c68a01c000000000e5d08a405239f4bf000000004e978940009ce5bf00000000b2248840304ad7bf00000000137986407050c9bf00000000709484405ebbbbbf00000000c87682408d97aebf000000001c2080408df1a1bf000000009999193fffff8fc000000000d9207b40f6d595bf000000009999193f51b88ec000000000728f75405f518abf00000000018c6f40b3e07ebf0000000087166940fb7e6abf00000000052f6240bd9657bf000000007bd55a40294146bf00000000e90953406b9736bf000000004ecc4a40a4b228bf00000000ab1c42400aac1cbf0000000000fb3840b89c12bf000000004b672f40e69d0abf0000000090612540bdc804bf00000000cce91a40613601bf00000000ffff0f40000000bf000000009999193f000000bf000000003333333f999919bf000000000000003f000000bf000000003333333f999919bf000000000000003fccccccbe000000003333333f999919bf000000009999193fccccccbe0000000000001040999919bf0000000000001040ccccccbe00000000ab8d1a4099c51abf00000000ee451b40474ecfbe0000000027a6244052371ebf00000000f91c264052b4d6be000000000d4a2e406bd323bf000000008d843040ccd0e2be00000000127a3740e17e2bbf00000000ee7b3a401e75f3be000000000d374040241f35bf000000004a024440eb3804bf00000000e78148401e9a40bf00000000b4164d4033cb10bf000000009d5b50405cd64dbf0000000034b855407b581fbf000000002cc5574014bb5cbf00000000c9e55d4042c72fbf000000008ebf5e4029306dbf000000007c9e654057fd41bf00000000ab4b65400a1e7fbf0000000063e16c40ebdf55bf000000004c6a6b40d73689bf00000000b5ad7340b8536bbf00000000211c7140338493bf00000000c2027a40871e81bf00000000ae617640e16b9ebf0000000005e07f400a408dbf00000000553b7b40aee2a9bf000000008fa282406b009abf0000000054a97f4066ddb5bf00000000e6188540b351a7bf00000000e5d58140b350c2bf00000000fb5287400a26b5bf000000005ba183402e31cfbf00000000cc508940b86fc3bf00000000053785403d73dcbf0000000060128b402421d2bf00000000d39686401c0beabf00000000c9978c40e62ce1bf00000000b2c08740e6ecf7bf0000000018e18d40c085f0bf000000008bb48840420603c00000000064ee8e404a0f00c0000000004d728940e62e0ac000000000c0bf8f4037f507c000000000e5f98940336a11c0000000003d55904038ee0fc000000000454b8a40f8b118c000000000e9ae9040eef317c00000000066668a40fbff1fc000000000cdcc9040fbff1fc000000000464b8a40fd4d27c000000000e9ae9040070c28c000000000e5f98940c4952ec0000000003d559040bc1130c0000000004e72894010d135c000000000c1bf8f40be0a38c0000000008db48840b4f93cc00000000065ee8e40adf03fc000000000b3c08740840944c00000000019e18d4015bd47c000000000d496864069fa4ac000000000ca978c4082694fc0000000000737854059c651c00000000062128b4064ef56c0000000005da18340606758c000000000ce5089401b485ec000000000e7d581409bd75ec000000000fe528740ef6c65c0000000005ca97f40461165c000000000ea1885401d576cc0000000005c3b7b40a00e6bc00000000092a28240c1ff72c000000000b361764007ca70c0000000000ce07f40f35f79c000000000271c7140de3d76c000000000cb027a40b3707fc000000000536a6b408f647bc000000000bcad7340869582c000000000b24b65403b1c80c0000000006ce16c40ff4385c0000000009bbf5e40f85982c000000000899e654052c087c0000000003bc55740996884c000000000d9e55d4012078ac000000000a95b5040304586c00000000042b85540ed148cc000000000f7814840baec87c000000000c6164d4097e68dc0000000001d374040195c89c0000000005d024440df788fc000000000247a374021908ac000000000007c3a40abc890c000000000214a2e4091858bc000000000a1843040f1d291c0000000003ca6244015398cc000000000101d2640ba9492c000000000c18d1a404da78cc00000000006461b401b0b93c00000000000001040cdcc8cc00000000000001040333393c0000000003333333fcdcc8cc0000000000000003f333393c0000000003333333fcdcc8cc0000000000000003f000090c0000000003333333fcdcc8cc0000000000000003f52b88ec000000000ffffffffffffffff0e003640ffffffff0e30dfbfffffffffffffffff000000007c213340ffffffffffffffffdd22f8bfffffffff00000000ffffffffffffffff2f4f34407735debfffffffffffffffff00000000ffffffff58123040ffffffffffffffff7c5df6bf00000000ffffffffffffffff25b33240ffffffff61e0dcbfffffffffffffffff00000000c6292d40ffffffffffffffff2ef5f3bfffffffff00000000ffffffffffffffff6a2e3140fd35dbbfffffffffffffffff00000000ffffffff656d2a40ffffffffffffffff00f5f0bf00000000fffffffffffffffff7c32f40ffffffffc03bd9bfffffffffffffffff0000000060e22740ffffffffffffffffc267edbfffffffff00000000ffffffffffffffff0a772e4094f7d6bfffffffffffffffff00000000ffffffff978d2540ffffffffffffffffc757e9bf00000000fffffffffffffffff84a2d40ffffffffd56fd4bfffffffffffffffff00000000d7732340fffffffffffffffff7cee4bfffffffff00000000fffffffffffffffff9422c4022abd1bfffffffffffffffff00000000ffffffff069a2140ffffffffffffffffefd6dfbf00000000ffffffffffffffff16622b40ffffffff0cb0cebfffffffffffffffff000000003e052040ffffffffffffffff5e79dabfffffffff00000000ffffffffffffffff17ab2a40bb84cbbfffffffffffffffff00000000ffffffffd4ba1e40ffffffffffffffff5ec0d4bf00000000ffffffffffffffff99202a40ffffffff752ec8bfffffffffffffffff000000004dc01d40ffffffffffffffffebb6cebfffffffff00000000ffffffffffffffff39c529404fb1c4bfffffffffffffffff00000000ffffffff2c1b1d40ffffffffffffffff2b69c8bf00000000000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd - m_Bindpose: [] - textureRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 0 - height: 0 - textureRectOffset: {x: 0, y: 0} - atlasRectOffset: {x: -1, y: -1} - settingsRaw: 320 - uvTransform: {x: 100, y: 0, z: 100, w: 500} - downscaleMultiplier: 1 - m_AtlasRD: - serializedVersion: 3 - texture: {fileID: 0} - alphaTexture: {fileID: 0} - secondaryTextures: [] - m_SubMeshes: - - serializedVersion: 2 - firstByte: 0 - indexCount: 498 - topology: 0 - baseVertex: 0 - firstVertex: 0 - vertexCount: 168 - localAABB: - m_Center: {x: 0, y: 0, z: 0} - m_Extent: {x: 0, y: 0, z: 0} - m_IndexBuffer: 0000010002000000030001000400030000000400050003000600050004000600070005000800070006000800090007000a00090008000a000b0009000c000b000a000c000d000b000c000e000d000f000e000c000f0010000e00110010000f001100120010001300120011001300140012001500140013001500160014001500170016001800170015001800190017001a00190018001a001b0019001a001c001b001a001d001c001a001e001d001a001f001e001a0020001f001a00210020001a00220021001a00230022001a0024002300250024001a0025002600240027002600250027002800260027002900280027002a00290027002b002a0027002c002b0027002d002c0027002e002d0027002f002e00270030002f002700310030002700320031002700330032002700340033003400270035003600370039003600390038003a00380039003a0039003b003a003b003d003a003d003c003c003d003f003c003f003e003e003f0041003e0041004000400041004300400043004200420043004500420045004400440045004700440047004600460047004900460049004800480049004b0048004b004a004a004b004d004a004d004c004c004d004f004c004f004e004e004f0051004e0051005000500051005300500053005200520053005500520055005400540055005700540057005600560057005900560059005800580059005b0058005b005a005a005b005d005a005d005c005c005d005f005c005f005e005e005f0061005e0061006000600061006300600063006200620063006500620065006400640065006700640067006600660067006900660069006800680069006b0068006b006a006a006b006d006a006d006c006c006d006f006c006f006e006e006f0071006e0071007000700071007300700073007200720073007500720075007400740075007700740077007600760077007900760079007800780079007b0078007b007a007a007b007d007a007d007c007c007d007f007c007f007e007e007f0081007e0081008000800081008300800083008200820083008500820085008400840085008700840087008600860087008900860089008800880089008b0088008b008a008a008b008d008a008d008c008c008d008f008c008f008e008e008f0091008e0091009000900091009300900093009200920093009500920095009400940095009700940097009600960097009900960099009800980099009b0098009b009a009a009b009d009a009d009c009c009d009f009c009f009e009e009f00a1009e00a100a000a000a100a300a000a300a200a400a200a300a400a300a500a400a500a700a400a700a6003600a6003700a7003700a600 - m_VertexData: - serializedVersion: 3 - m_VertexCount: 168 - m_Channels: - - stream: 0 - offset: 0 - format: 0 - dimension: 3 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 1 - offset: 0 - format: 2 - dimension: 4 - - stream: 1 - offset: 4 - format: 0 - dimension: 2 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - m_DataSize: 4032 - _typelessdata: 078c6f40e72380c000000000e0207b40fd1475c000000000788f754047d77ac0000000002020804030076fc0000000008f1669401db082c000000000cb76824030b468c000000000122f6240250d85c00000000072948440442262c00000000089d55a40d53787c00000000016798640bd575bc000000000f50953400f2d89c000000000b4248840dd5a54c0000000005ecc4a40a9e98ac0000000004f978940f4314dc000000000e6d08a404de345c000000000bd1c42407c6a8cc00000000078d18b402f753ec00000000010fb384066ac8dc00000000007998c40e6ed36c00000000061672f4041ac8ec00000000090278d40be532fc000000000a6612540e7668fc000000000177d8d4002ad27c00000000099998d40fbff1fc000000000e3e91a4034d98fc000000000167d8d40f25218c000000000ffff0f40ffff8fc00000000091278d4036ac10c00000000006998c400f1209c00000000077d18b40c68a01c000000000e5d08a405239f4bf000000004e978940009ce5bf00000000b2248840304ad7bf00000000137986407050c9bf00000000709484405ebbbbbf00000000c87682408d97aebf000000001c2080408df1a1bf000000009999193fffff8fc000000000d9207b40f6d595bf000000009999193f51b88ec000000000728f75405f518abf00000000018c6f40b3e07ebf0000000087166940fb7e6abf00000000052f6240bd9657bf000000007bd55a40294146bf00000000e90953406b9736bf000000004ecc4a40a4b228bf00000000ab1c42400aac1cbf0000000000fb3840b89c12bf000000004b672f40e69d0abf0000000090612540bdc804bf00000000cce91a40613601bf00000000ffff0f40000000bf000000009999193f000000bf000000003333333f999919bf000000000000003f000000bf000000003333333f999919bf000000000000003fccccccbe000000003333333f999919bf000000009999193fccccccbe0000000000001040999919bf0000000000001040ccccccbe00000000ab8d1a4099c51abf00000000ee451b40474ecfbe0000000027a6244052371ebf00000000f91c264052b4d6be000000000d4a2e406bd323bf000000008d843040ccd0e2be00000000127a3740e17e2bbf00000000ee7b3a401e75f3be000000000d374040241f35bf000000004a024440eb3804bf00000000e78148401e9a40bf00000000b4164d4033cb10bf000000009d5b50405cd64dbf0000000034b855407b581fbf000000002cc5574014bb5cbf00000000c9e55d4042c72fbf000000008ebf5e4029306dbf000000007c9e654057fd41bf00000000ab4b65400a1e7fbf0000000063e16c40ebdf55bf000000004c6a6b40d73689bf00000000b5ad7340b8536bbf00000000211c7140338493bf00000000c2027a40871e81bf00000000ae617640e16b9ebf0000000005e07f400a408dbf00000000553b7b40aee2a9bf000000008fa282406b009abf0000000054a97f4066ddb5bf00000000e6188540b351a7bf00000000e5d58140b350c2bf00000000fb5287400a26b5bf000000005ba183402e31cfbf00000000cc508940b86fc3bf00000000053785403d73dcbf0000000060128b402421d2bf00000000d39686401c0beabf00000000c9978c40e62ce1bf00000000b2c08740e6ecf7bf0000000018e18d40c085f0bf000000008bb48840420603c00000000064ee8e404a0f00c0000000004d728940e62e0ac000000000c0bf8f4037f507c000000000e5f98940336a11c0000000003d55904038ee0fc000000000454b8a40f8b118c000000000e9ae9040eef317c00000000066668a40fbff1fc000000000cdcc9040fbff1fc000000000464b8a40fd4d27c000000000e9ae9040070c28c000000000e5f98940c4952ec0000000003d559040bc1130c0000000004e72894010d135c000000000c1bf8f40be0a38c0000000008db48840b4f93cc00000000065ee8e40adf03fc000000000b3c08740840944c00000000019e18d4015bd47c000000000d496864069fa4ac000000000ca978c4082694fc0000000000737854059c651c00000000062128b4064ef56c0000000005da18340606758c000000000ce5089401b485ec000000000e7d581409bd75ec000000000fe528740ef6c65c0000000005ca97f40461165c000000000ea1885401d576cc0000000005c3b7b40a00e6bc00000000092a28240c1ff72c000000000b361764007ca70c0000000000ce07f40f35f79c000000000271c7140de3d76c000000000cb027a40b3707fc000000000536a6b408f647bc000000000bcad7340869582c000000000b24b65403b1c80c0000000006ce16c40ff4385c0000000009bbf5e40f85982c000000000899e654052c087c0000000003bc55740996884c000000000d9e55d4012078ac000000000a95b5040304586c00000000042b85540ed148cc000000000f7814840baec87c000000000c6164d4097e68dc0000000001d374040195c89c0000000005d024440df788fc000000000247a374021908ac000000000007c3a40abc890c000000000214a2e4091858bc000000000a1843040f1d291c0000000003ca6244015398cc000000000101d2640ba9492c000000000c18d1a404da78cc00000000006461b401b0b93c00000000000001040cdcc8cc00000000000001040333393c0000000003333333fcdcc8cc0000000000000003f333393c0000000003333333fcdcc8cc0000000000000003f000090c0000000003333333fcdcc8cc0000000000000003f52b88ec000000000ffffffffffffffff0e003640ffffffff0e30dfbfffffffffffffffff000000007c213340ffffffffffffffffdd22f8bfffffffff00000000ffffffffffffffff2f4f34407735debfffffffffffffffff00000000ffffffff58123040ffffffffffffffff7c5df6bf00000000ffffffffffffffff25b33240ffffffff61e0dcbfffffffffffffffff00000000c6292d40ffffffffffffffff2ef5f3bfffffffff00000000ffffffffffffffff6a2e3140fd35dbbfffffffffffffffff00000000ffffffff656d2a40ffffffffffffffff00f5f0bf00000000fffffffffffffffff7c32f40ffffffffc03bd9bfffffffffffffffff0000000060e22740ffffffffffffffffc267edbfffffffff00000000ffffffffffffffff0a772e4094f7d6bfffffffffffffffff00000000ffffffff978d2540ffffffffffffffffc757e9bf00000000fffffffffffffffff84a2d40ffffffffd56fd4bfffffffffffffffff00000000d7732340fffffffffffffffff7cee4bfffffffff00000000fffffffffffffffff9422c4022abd1bfffffffffffffffff00000000ffffffff069a2140ffffffffffffffffefd6dfbf00000000ffffffffffffffff16622b40ffffffff0cb0cebfffffffffffffffff000000003e052040ffffffffffffffff5e79dabfffffffff00000000ffffffffffffffff17ab2a40bb84cbbfffffffffffffffff00000000ffffffffd4ba1e40ffffffffffffffff5ec0d4bf00000000ffffffffffffffff99202a40ffffffff752ec8bfffffffffffffffff000000004dc01d40ffffffffffffffffebb6cebfffffffff00000000ffffffffffffffff39c529404fb1c4bfffffffffffffffff00000000ffffffff2c1b1d40ffffffffffffffff2b69c8bf00000000000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ffffffffffcdcdcdcd000000ffcdcdcdcdffffffff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd000000ff000000ffcdcdcdcd000000ffcdcdcdcd000000ff000000ffcdcdcdcdcdcdcdcd - m_Bindpose: [] - textureRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 0 - height: 0 - textureRectOffset: {x: 0, y: 0} - atlasRectOffset: {x: -1, y: -1} - settingsRaw: 320 - uvTransform: {x: 100, y: 0, z: 100, w: 500} - downscaleMultiplier: 1 - m_PhysicsShape: [] - m_Bones: [] - m_SpriteID: 6d9a163d366116a4fbc61bad4a744969 --- !u!1 &3254705316304510337 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Utils.cs b/Assets/Scripts/Utils.cs index dbb642d..0d2ca35 100755 --- a/Assets/Scripts/Utils.cs +++ b/Assets/Scripts/Utils.cs @@ -23,6 +23,8 @@ namespace UntitledLogicGame public static bool[][] AllBoolArrayValues(int length) { + if (length == 0) + return new bool[0][]; var count = (int)Math.Pow(2, length); return new ArrayList[count].Select((v, i) => i.ToBoolArray(length)).ToArray(); } diff --git a/Assets/Scripts/Workspace/Gates/GateDefinition.cs b/Assets/Scripts/Workspace/Gates/GateDefinition.cs index d20375e..8ae104d 100755 --- a/Assets/Scripts/Workspace/Gates/GateDefinition.cs +++ b/Assets/Scripts/Workspace/Gates/GateDefinition.cs @@ -4,118 +4,124 @@ using System.Linq; namespace UntitledLogicGame.Workspace.Gates { - public abstract class GateDefinition - { - private static Dictionary Definitions; - internal static Dictionary EmptyTruthTable = new Dictionary(); - public abstract string[] Inputs { get; } - public abstract string[] Outputs { get; } - internal abstract Dictionary TruthTable { get; } - public string Name { get; internal set; } - public bool HasState => false; - public GateDefinition New => (GateDefinition)GetType().GetConstructor(new Type[0]).Invoke(new object[0]); + public abstract class GateDefinition + { + // Static properties + private static Dictionary Definitions; - private static void LoadAll() - { - Definitions = new Dictionary(); - foreach (var gateType in Enum.GetValues(typeof(GateType)).Cast()) - { - try - { - var t = Type.GetType($"{typeof(GateDefinition).Namespace}.{gateType}Gate", true); - Definitions[gateType] = (GateDefinition)t.GetConstructor(new Type[0]).Invoke(new object[0]); - Definitions[gateType].Name = gateType.ToString(); - } - catch - { - Definitions[gateType] = (GateDefinition)typeof(NoneGate).GetConstructor(new Type[0]).Invoke(new object[0]); - Definitions[gateType].Name = gateType.ToString(); - } - } - } + // Public properties + public string Name { get; internal set; } + public bool HasState => false; + public Dictionary TruthTable { get; private set; } = new Dictionary(); - public static GateDefinition Get(GateType gateType, Gate gate) - { - if (Definitions == null) - LoadAll(); + // Herited properties + public abstract string[] Inputs { get; } + public abstract string[] Outputs { get; } + internal abstract Func Function { get; } - var definition = Definitions[gateType]; + // Private properties + private GateDefinition New => (GateDefinition)GetType().GetConstructor(new Type[0]).Invoke(new object[0]); - foreach (var inputName in definition.Inputs) - { - if(!gate.InputAnchors.Any(a => a.Name.Equals(inputName))) - throw new InvalidOperationException($"Gate has no {inputName} input anchor"); - } + private static void LoadAll() + { + Definitions = new Dictionary(); + foreach (var gateType in Enum.GetValues(typeof(GateType)).Cast()) + { + try + { + var t = Type.GetType($"{typeof(GateDefinition).Namespace}.{gateType}Gate", true); + Definitions[gateType] = (GateDefinition)t.GetConstructor(new Type[0]).Invoke(new object[0]); + Definitions[gateType].Name = gateType.ToString(); + } + catch + { + Definitions[gateType] = (GateDefinition)typeof(NoneGate).GetConstructor(new Type[0]).Invoke(new object[0]); + Definitions[gateType].Name = gateType.ToString(); + } + } + } - foreach (var outputName in definition.Outputs) - { - if (!gate.OutputAnchors.Any(a => a.Name.Equals(outputName))) - throw new InvalidOperationException($"Gate has no {outputName} output anchor"); - } + public static GateDefinition Get(GateType gateType, Gate gate) + { + if (Definitions == null) + LoadAll(); - if (definition.HasState) - return definition.New; - else - return definition; - } + var definition = Definitions[gateType]; - internal GateDefinition() - { - if (!HasState) - { - if (TruthTable.Count > 0) - { - foreach (var key in TruthTable.Keys) - { - if (key.Length != Inputs.Length) - throw new InvalidOperationException($"{GetType()} invalid inputs ({key})"); - } - if (Inputs.Length != 0) - { - foreach (var key in Utils.AllBoolArrayValues(Inputs.Length).Select(b => new InputState(b))) - { - if (!TruthTable.Keys.Contains(key)) - throw new InvalidOperationException($"{GetType()} no outputs for ({key})"); - var values = TruthTable[key]; - if (values.Length != Outputs.Length) - throw new InvalidOperationException($"{GetType()} invalid outputs for ({key})"); - } - } - } - } - else - { - // Only test basic value - var sample = new InputState(Inputs.Length); - var output = Compute(sample); - if(output.Length != Outputs.Length) - throw new InvalidOperationException($"{GetType()} invalid outputs for sample ({sample})"); - } - } + foreach (var inputName in definition.Inputs) + { + if (!gate.InputAnchors.Any(a => a.Name.Equals(inputName))) + throw new InvalidOperationException($"Gate has no {inputName} input anchor"); + } - public bool[] GetState(Gate gate) - { - return Inputs.Select(i => gate.InputAnchors.First(a => a.Name.Equals(i)).Activated).ToArray(); - } + foreach (var outputName in definition.Outputs) + { + if (!gate.OutputAnchors.Any(a => a.Name.Equals(outputName))) + throw new InvalidOperationException($"Gate has no {outputName} output anchor"); + } - public void Compute(Gate gate) - { - var input = new InputState(GetState(gate)); - var output = Compute(input); - foreach (var outputAnchor in Outputs.Select((name, i) => new { i, name })) - gate.OutputAnchors.First(a => a.Name.Equals(outputAnchor.name)).Activated = output[outputAnchor.i]; - } + if (definition.HasState) + return definition.New; + else + return definition; + } - internal OutputState Compute(InputState input) - { - if (TruthTable.Count > 0) - { - return TruthTable[input]; - } - else - { - return new OutputState(0); - } - } - } + internal GateDefinition() + { + if (!HasState) + { + CreateTruthTable(Function); + if (TruthTable.Count > 0) + { + foreach (var key in TruthTable.Keys) + { + if (key.Length != Inputs.Length) + throw new InvalidOperationException($"{GetType()} invalid inputs ({key})"); + } + if (Inputs.Length != 0) + { + foreach (var key in Utils.AllBoolArrayValues(Inputs.Length).Select(b => new InputState(b))) + { + if (!TruthTable.Keys.Contains(key)) + throw new InvalidOperationException($"{GetType()} no outputs for ({key})"); + var values = TruthTable[key]; + if (values.Length != Outputs.Length) + throw new InvalidOperationException($"{GetType()} invalid outputs for ({key})"); + } + } + } + } + else + { + // Only test basic value + var sample = new InputState(Inputs.Length); + var output = Function(sample); + if (output.Length != Outputs.Length) + throw new InvalidOperationException($"{GetType()} invalid outputs for sample ({sample})"); + } + } + + public bool[] GetState(Gate gate) + { + return Inputs.Select(i => gate.InputAnchors.First(a => a.Name.Equals(i)).Activated).ToArray(); + } + + public void Compute(Gate gate) + { + var input = new InputState(GetState(gate)); + var output = HasState ? Function(input) : (TruthTable.Count > 0 ? TruthTable[input] : new OutputState(0)); + foreach (var outputAnchor in Outputs.Select((name, i) => new { i, name })) + gate.OutputAnchors.First(a => a.Name.Equals(outputAnchor.name)).Activated = output[outputAnchor.i]; + } + + private void CreateTruthTable(Func function) + { + TruthTable = Utils.AllBoolArrayValues(Inputs.Length).ToDictionary(key => new InputState(key), key => function(new InputState(key))); + } + } + + internal abstract class StateGateDefinition : GateDefinition + { + public new bool HasState => true; + } } diff --git a/Assets/Scripts/Workspace/Gates/GateDefinitionList.cs b/Assets/Scripts/Workspace/Gates/GateDefinitionList.cs index acd0302..145aed5 100755 --- a/Assets/Scripts/Workspace/Gates/GateDefinitionList.cs +++ b/Assets/Scripts/Workspace/Gates/GateDefinitionList.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace UntitledLogicGame.Workspace.Gates { @@ -8,7 +9,8 @@ namespace UntitledLogicGame.Workspace.Gates { public override string[] Inputs { get; } = new string[] { }; public override string[] Outputs { get; } = new string[] { }; - internal override Dictionary TruthTable => EmptyTruthTable; + + internal override Func Function => (input) => new OutputState(0); } #endregion @@ -23,50 +25,32 @@ namespace UntitledLogicGame.Workspace.Gates { public override string[] Inputs { get; } = new string[] { "A" }; public override string[] Outputs { get; } = new string[] { "Q" }; - internal override Dictionary TruthTable { get; } = new Dictionary - { - { new InputState( false ), new OutputState( false ) }, - { new InputState( true ), new OutputState( true ) }, - }; + + internal override Func Function => (input) => new OutputState(input[0]); } internal class ANDGate : GateDefinition { public override string[] Inputs { get; } = new string[] { "A", "B" }; public override string[] Outputs { get; } = new string[] { "Q" }; - internal override Dictionary TruthTable { get; } = new Dictionary - { - { new InputState( false, false ), new OutputState( false ) }, - { new InputState( false, true ), new OutputState( false ) }, - { new InputState( true, false ), new OutputState( false ) }, - { new InputState( true, true ), new OutputState( true ) }, - }; + + internal override Func Function => (input) => new OutputState(input[0] && input[1]); } internal class ORGate : GateDefinition { public override string[] Inputs { get; } = new string[] { "A", "B" }; public override string[] Outputs { get; } = new string[] { "Q" }; - internal override Dictionary TruthTable { get; } = new Dictionary - { - { new InputState( false, false ), new OutputState( false ) }, - { new InputState( false, true ), new OutputState( true ) }, - { new InputState( true, false ), new OutputState( true ) }, - { new InputState( true, true ), new OutputState( true ) }, - }; + + internal override Func Function => (input) => new OutputState(input[0] || input[1]); } internal class XORGate : GateDefinition { public override string[] Inputs { get; } = new string[] { "A", "B" }; public override string[] Outputs { get; } = new string[] { "Q" }; - internal override Dictionary TruthTable { get; } = new Dictionary - { - { new InputState( false, false ), new OutputState( false ) }, - { new InputState( false, true ), new OutputState( true ) }, - { new InputState( true, false ), new OutputState( true ) }, - { new InputState( true, true ), new OutputState( false ) }, - }; + + internal override Func Function => (input) => new OutputState(input[0] ^ input[1]); } #endregion @@ -77,67 +61,47 @@ namespace UntitledLogicGame.Workspace.Gates { public override string[] Inputs { get; } = new string[] { "A" }; public override string[] Outputs { get; } = new string[] { "Q" }; - internal override Dictionary TruthTable { get; } = new Dictionary - { - { new InputState( false ), new OutputState( true ) }, - { new InputState( true ), new OutputState( false ) }, - }; + + internal override Func Function => (input) => new OutputState(!input[0]); } internal class NANDGate : GateDefinition { public override string[] Inputs { get; } = new string[] { "A", "B" }; public override string[] Outputs { get; } = new string[] { "Q" }; - internal override Dictionary TruthTable { get; } = new Dictionary - { - { new InputState( false, false ), new OutputState( true ) }, - { new InputState( false, true ), new OutputState( true ) }, - { new InputState( true, false ), new OutputState( true ) }, - { new InputState( true, true ), new OutputState( false ) }, - }; + + internal override Func Function => (input) => new OutputState(!(input[0] && input[1])); } internal class NORGate : GateDefinition { public override string[] Inputs { get; } = new string[] { "A", "B" }; public override string[] Outputs { get; } = new string[] { "Q" }; - internal override Dictionary TruthTable { get; } = new Dictionary - { - { new InputState( false, false ), new OutputState( true ) }, - { new InputState( false, true ), new OutputState( false ) }, - { new InputState( true, false ), new OutputState( false ) }, - { new InputState( true, true ), new OutputState( false ) }, - }; + + internal override Func Function => (input) => new OutputState(!(input[0] || input[1])); } internal class XNORGate : GateDefinition { public override string[] Inputs { get; } = new string[] { "A", "B" }; public override string[] Outputs { get; } = new string[] { "Q" }; - internal override Dictionary TruthTable { get; } = new Dictionary - { - { new InputState( false, false ), new OutputState( true ) }, - { new InputState( false, true ), new OutputState( false ) }, - { new InputState( true, false ), new OutputState( false ) }, - { new InputState( true, true ), new OutputState( true ) }, - }; + + internal override Func Function => (input) => new OutputState(!(input[0] ^ input[1])); } #endregion #region 400 - Latches - internal class SRLatchGate : GateDefinition + internal class SRLatchGate : StateGateDefinition { + public new string Name => "SR Latch"; public override string[] Inputs { get; } = new string[] { "S", "R" }; public override string[] Outputs { get; } = new string[] { "Q", "Q̅" }; - internal override Dictionary TruthTable => EmptyTruthTable; - public new string Name => "SR Latch"; - public new bool HasState => true; private bool _q; - internal new OutputState Compute(InputState input) + internal override Func Function => (input) => { var s = input[0]; var r = input[1]; @@ -146,20 +110,18 @@ namespace UntitledLogicGame.Workspace.Gates else if (s) // set _q = true; return new OutputState(_q, !_q); - } + }; } - internal class JKLatchGate : GateDefinition + internal class JKLatchGate : StateGateDefinition { + public new string Name => "JK Latch"; public override string[] Inputs { get; } = new string[] { "J", "K" }; public override string[] Outputs { get; } = new string[] { "Q", "Q̅" }; - internal override Dictionary TruthTable => EmptyTruthTable; - public new string Name => "JK Latch"; - public new bool HasState => true; private bool _q; - internal new OutputState Compute(InputState input) + internal override Func Function => (input) => { var j = input[0]; var k = input[1]; @@ -170,45 +132,41 @@ namespace UntitledLogicGame.Workspace.Gates else if (j) // set _q = true; return new OutputState(_q, !_q); - } + }; } - internal class DLatchGate : GateDefinition + internal class DLatchGate : StateGateDefinition { + public new string Name => "D Latch"; public override string[] Inputs { get; } = new string[] { "D", "E" }; public override string[] Outputs { get; } = new string[] { "Q", "Q̅" }; - internal override Dictionary TruthTable => EmptyTruthTable; - public new string Name => "D Latch"; - public new bool HasState => true; private bool _q; - internal new OutputState Compute(InputState input) + internal override Func Function => (input) => { var d = input[0]; var e = input[1]; if (e) // set _q = d; return new OutputState(_q, !_q); - } + }; } #endregion #region 500 - Flip-Flops - internal class SRFlipFlopGate : GateDefinition + internal class SRFlipFlopGate : StateGateDefinition { + public new string Name => "SR Flip-Flop"; public override string[] Inputs { get; } = new string[] { "CLK", "S", "R" }; public override string[] Outputs { get; } = new string[] { "Q", "Q̅" }; - internal override Dictionary TruthTable => EmptyTruthTable; - public new string Name => "SR Flip-Flop"; - public new bool HasState => true; - + private bool _q; private bool _lastClk; - internal new OutputState Compute(InputState input) + internal override Func Function => (input) => { var clk = input[0]; var s = input[1]; @@ -220,21 +178,19 @@ namespace UntitledLogicGame.Workspace.Gates _q = true; _lastClk = clk; return new OutputState(_q, !_q); - } + }; } - internal class JKFlipFlopGate : GateDefinition + internal class JKFlipFlopGate : StateGateDefinition { + public new string Name => "JK Flip-Flop"; public override string[] Inputs { get; } = new string[] { "CLK", "J", "K" }; public override string[] Outputs { get; } = new string[] { "Q", "Q̅" }; - internal override Dictionary TruthTable => EmptyTruthTable; - public new string Name => "JK Flip-Flop"; - public new bool HasState => true; private bool _q; private bool _lastClk; - internal new OutputState Compute(InputState input) + internal override Func Function => (input) => { var clk = input[0]; var j = input[1]; @@ -248,21 +204,19 @@ namespace UntitledLogicGame.Workspace.Gates _q = true; _lastClk = clk; return new OutputState(_q, !_q); - } + }; } - internal class DFlipFlopGate : GateDefinition + internal class DFlipFlopGate : StateGateDefinition { + public new string Name => "D Flip-Flop"; public override string[] Inputs { get; } = new string[] { "CLK", "D" }; public override string[] Outputs { get; } = new string[] { "Q", "Q̅" }; - internal override Dictionary TruthTable => EmptyTruthTable; - public new string Name => "D Flip-Flop"; - public new bool HasState => true; private bool _q; private bool _lastClk; - internal new OutputState Compute(InputState input) + internal override Func Function => (input) => { var clk = input[0]; var d = input[1]; @@ -270,21 +224,19 @@ namespace UntitledLogicGame.Workspace.Gates _q = d; _lastClk = clk; return new OutputState(_q, !_q); - } + }; } - internal class TFlipFlopGate : GateDefinition + internal class TFlipFlopGate : StateGateDefinition { + public new string Name => "T Flip-Flop"; public override string[] Inputs { get; } = new string[] { "CLK", "T" }; public override string[] Outputs { get; } = new string[] { "Q", "Q̅" }; - internal override Dictionary TruthTable => EmptyTruthTable; - public new string Name => "T Flip-Flop"; - public new bool HasState => true; private bool _q; private bool _lastClk; - internal new OutputState Compute(InputState input) + internal override Func Function => (input) => { var clk = input[0]; var t = input[1]; @@ -293,99 +245,108 @@ namespace UntitledLogicGame.Workspace.Gates _q = !_q; _lastClk = clk; return new OutputState(_q, !_q); - } + }; } #endregion - #region 600 - Combinational + #region 600 - Arithmetic internal class HalfAddGate : GateDefinition { + public new string Name => "Half Add."; public override string[] Inputs { get; } = new string[] { "A", "B" }; public override string[] Outputs { get; } = new string[] { "S", "C" }; - internal override Dictionary TruthTable { get; } = new Dictionary + + internal override Func Function => (input) => { - { new InputState( false, false ), new OutputState( false, false ) }, - { new InputState( false, true ), new OutputState( true, false ) }, - { new InputState( true, false ), new OutputState( true, false ) }, - { new InputState( true, true ), new OutputState( false, true ) }, + var a = input[0]; + var b = input[1]; + + var s = a || b; + var c = a && b; + + return new OutputState(s, c); }; - public new string Name => "Half Add."; } internal class FullAddGate : GateDefinition { + public new string Name => "Full Add."; public override string[] Inputs { get; } = new string[] { "A", "B", "Cɪ" }; public override string[] Outputs { get; } = new string[] { "S", "Cᴏ" }; - internal override Dictionary TruthTable { get; } = new Dictionary + + internal override Func Function => (input) => { - { new InputState( false, false, false ), new OutputState( false, false ) }, - { new InputState( false, false, true ), new OutputState( true, false ) }, - { new InputState( false, true, false ), new OutputState( true, false ) }, - { new InputState( false, true, true ), new OutputState( false, true ) }, - { new InputState( true, false, false ), new OutputState( true, false ) }, - { new InputState( true, false, true ), new OutputState( false, true ) }, - { new InputState( true, true, false ), new OutputState( false, true ) }, - { new InputState( true, true, true ), new OutputState( true, true ) }, + var a = input[0]; + var b = input[1]; + var ci = input[2]; + + var s = a || b || ci; + var co = a && b || a && ci || b && ci; + + return new OutputState(s, co); }; - public new string Name => "Full Add."; } internal class HalfSubGate : GateDefinition { + public new string Name => "Half Sub."; public override string[] Inputs { get; } = new string[] { "A", "B" }; public override string[] Outputs { get; } = new string[] { "S", "C" }; - internal override Dictionary TruthTable { get; } = new Dictionary + + internal override Func Function => (input) => { - { new InputState( false, false ), new OutputState( false, false ) }, - { new InputState( false, true ), new OutputState( true, true ) }, - { new InputState( true, false ), new OutputState( true, false ) }, - { new InputState( true, true ), new OutputState( false, false ) }, + var a = input[0]; + var b = input[1]; + + var s = a || b; + var c = !a && b; + + return new OutputState(s, c); }; - public new string Name => "Half Sub."; + } internal class FullSubGate : GateDefinition { + public new string Name => "Full Add."; public override string[] Inputs { get; } = new string[] { "A", "B", "Cɪ" }; public override string[] Outputs { get; } = new string[] { "S", "Cᴏ" }; - internal override Dictionary TruthTable { get; } = new Dictionary + + internal override Func Function => (input) => { - { new InputState( false, false, false ), new OutputState( false, false ) }, - { new InputState( false, false, true ), new OutputState( true, true ) }, - { new InputState( false, true, false ), new OutputState( true, true ) }, - { new InputState( false, true, true ), new OutputState( false, true ) }, - { new InputState( true, false, false ), new OutputState( true, false ) }, - { new InputState( true, false, true ), new OutputState( false, false ) }, - { new InputState( true, true, false ), new OutputState( false, false ) }, - { new InputState( true, true, true ), new OutputState( true, true ) }, + var a = input[0]; + var b = input[1]; + var ci = input[2]; + + var s = a || b || ci; + var co = a && !b || a && !ci || b && ci; + + return new OutputState(s, co); }; - public new string Name => "Full Add."; + } + #endregion + + #region 700 - Data + internal class MuxGate : GateDefinition { public override string[] Inputs { get; } = new string[] { "E", "S", "D₀", "D₁" }; public override string[] Outputs { get; } = new string[] { "Y" }; - internal override Dictionary TruthTable { get; } = new Dictionary + + internal override Func Function => (input) => { - { new InputState( false, false, false, false ), new OutputState( false ) }, // => E=0 - { new InputState( false, false, false, true ), new OutputState( false ) }, // => E=0 - { new InputState( false, false, true, false ), new OutputState( false ) }, // => E=0 - { new InputState( false, false, true, true ), new OutputState( false ) }, // => E=0 - { new InputState( false, true, false, false ), new OutputState( false ) }, // => E=0 - { new InputState( false, true, false, true ), new OutputState( false ) }, // => E=0 - { new InputState( false, true, true, false ), new OutputState( false ) }, // => E=0 - { new InputState( false, true, true, true ), new OutputState( false ) }, // => E=0 - { new InputState( true, false, false, false ), new OutputState( false ) }, // => S=0 => Y=D₀=0 - { new InputState( true, false, false, true ), new OutputState( false ) }, // => S=0 => Y=D₀=0 - { new InputState( true, false, true, false ), new OutputState( true ) }, // => S=0 => Y=D₀=1 - { new InputState( true, false, true, true ), new OutputState( true ) }, // => S=0 => Y=D₀=1 - { new InputState( true, true, false, false ), new OutputState( false ) }, // => S=1 => Y=D₁=0 - { new InputState( true, true, false, true ), new OutputState( true ) }, // => S=1 => Y=D₁=1 - { new InputState( true, true, true, false ), new OutputState( false ) }, // => S=1 => Y=D₁=0 - { new InputState( true, true, true, true ), new OutputState( true ) }, // => S=1 => Y=D₁=1 + var e = input[0]; + var s = input[1]; + var d0 = input[2]; + var d1 = input[3]; + + var y = e && (!s && d0 || s && d1); + + return new OutputState(y); }; } @@ -393,68 +354,118 @@ namespace UntitledLogicGame.Workspace.Gates { public override string[] Inputs { get; } = new string[] { "E", "S", "D" }; public override string[] Outputs { get; } = new string[] { "Y₀", "Y₁" }; - internal override Dictionary TruthTable { get; } = new Dictionary + + internal override Func Function => (input) => { - { new InputState( false, false, false ), new OutputState( false, false ) }, // => E=0 - { new InputState( false, false, true ), new OutputState( false, false ) }, // => E=0 - { new InputState( false, true, false ), new OutputState( false, false ) }, // => E=0 - { new InputState( false, true, true ), new OutputState( false, false ) }, // => E=0 - { new InputState( true, false, false ), new OutputState( false, false ) }, // => S=0 => Y₀=D=0 - { new InputState( true, false, true ), new OutputState( true, false ) }, // => S=0 => Y₀=D=1 - { new InputState( true, true, false ), new OutputState( false, false ) }, // => S=1 => Y₁=D=0 - { new InputState( true, true, true ), new OutputState( false, true ) }, // => S=1 => Y₁=D=1 + var e = input[0]; + var s = input[1]; + var d = input[2]; + + var y0 = e && !s && d; + var y1 = e && s && d; + + return new OutputState(y0, y1); }; } - internal class EncGate : GateDefinition + internal class Mux2bGate : GateDefinition { + public new string Name => "2bits Mux"; + public override string[] Inputs { get; } = new string[] { "E", "S₀", "S₁", "D₀", "D₁", "D₂", "D₃" }; + public override string[] Outputs { get; } = new string[] { "Y" }; + + internal override Func Function => (input) => + { + var e = input[0]; + var s0 = input[1]; + var s1 = input[2]; + var d0 = input[3]; + var d1 = input[4]; + var d2 = input[5]; + var d3 = input[6]; + + var y = e && ( + !s0 && !s1 && d0 || + s0 && !s1 && d1 || + !s0 && s1 && d2 || + s0 && s1 && d3 + ); + + return new OutputState(y); + }; + } + + internal class Demux2bGate : GateDefinition + { + public new string Name => "2bits Demux"; + public override string[] Inputs { get; } = new string[] { "E", "S₀", "S₁", "D" }; + public override string[] Outputs { get; } = new string[] { "Y₀", "Y₁", "Y₂", "Y₃" }; + + internal override Func Function => (input) => + { + var e = input[0]; + var s0 = input[1]; + var s1 = input[2]; + var d = input[3]; + + var y0 = e && !s0 && !s1 && d; + var y1 = e && s0 && !s1 && d; + var y2 = e && !s0 && s1 && d; + var y3 = e && s0 && s1 && d; + + return new OutputState(y0, y1, y2, y3); + }; + } + + internal class Enc2b4bGate : GateDefinition + { + public new string Name => "2b/4b Enc."; public override string[] Inputs { get; } = new string[] { "D₀", "D₁" }; public override string[] Outputs { get; } = new string[] { "Y₀", "Y₁", "Y₂", "Y₃" }; - internal override Dictionary TruthTable { get; } = new Dictionary + + internal override Func Function => (input) => { - { new InputState( false, false ), new OutputState( true, false, false, false ) }, // D̅₀D̅₁ - { new InputState( false, true ), new OutputState( false, true, false, false ) }, // D₀D̅₁ - { new InputState( true, false ), new OutputState( false, false, true, false ) }, // D̅₀D₁ - { new InputState( true, true ), new OutputState( false, false, false, true ) }, // D₀D₁ + var d0 = input[0]; + var d1 = input[1]; + + var y0 = !d0 && !d1; + var y1 = d0 && !d1; + var y2 = !d0 && d1; + var y3 = d0 && d1; + + return new OutputState(y0, y1, y2, y3); }; } - internal class DecGate : GateDefinition + internal class Dec4b2bGate : GateDefinition { - public override string[] Inputs { get; } = new string[] { "D₃", "D₂", "D₁", "D₀" }; + public new string Name => "4b/2b Dec."; + public override string[] Inputs { get; } = new string[] { "D₀", "D₁", "D₂", "D₃"}; public override string[] Outputs { get; } = new string[] { "Y₀", "Y₁" }; - internal override Dictionary TruthTable { get; } = new Dictionary + + internal override Func Function => (input) => { - { new InputState( false, false, false, false ), new OutputState( false, false ) }, // XX - { new InputState( false, false, false, true ), new OutputState( false, false ) }, // D̅₀D̅₁ - { new InputState( false, false, true, false ), new OutputState( true, true ) }, // D₀D̅₁ - { new InputState( false, false, true, true ), new OutputState( true, false ) }, // D₀D̅₁ - { new InputState( false, true, false, false ), new OutputState( false, true ) }, // D̅₀D₁ - { new InputState( false, true, false, true ), new OutputState( false, true ) }, // D̅₀D₁ - { new InputState( false, true, true, false ), new OutputState( false, true ) }, // D̅₀D₁ - { new InputState( false, true, true, true ), new OutputState( false, true ) }, // D̅₀D₁ - { new InputState( true, false, false, false ), new OutputState( true, true ) }, // D₀D₁ - { new InputState( true, false, false, true ), new OutputState( true, true ) }, // D₀D₁ - { new InputState( true, false, true, false ), new OutputState( true, true ) }, // D₀D₁ - { new InputState( true, false, true, true ), new OutputState( true, true ) }, // D₀D₁ - { new InputState( true, true, false, false ), new OutputState( true, true ) }, // D₀D₁ - { new InputState( true, true, false, true ), new OutputState( true, true ) }, // D₀D₁ - { new InputState( true, true, true, false ), new OutputState( true, true ) }, // D₀D₁ - { new InputState( true, true, true, true ), new OutputState( true, true ) }, // D₀D₁ + var d0 = input[0]; + var d1 = input[1]; + var d2 = input[2]; + var d3 = input[3]; + + var y0 = d1 && !d2 || d3; + var y1 = d2 || d3; + + return new OutputState(y0, y1); }; } #endregion - #region 700 - Registers + #region 800 - Registers - internal class SISO4bGate : GateDefinition + internal class SISO4bGate : StateGateDefinition { + public new string Name => "4bits SISO"; public override string[] Inputs { get; } = new string[] { "CLK", "D" }; public override string[] Outputs { get; } = new string[] { "Q" }; - internal override Dictionary TruthTable => EmptyTruthTable; - public new string Name => "4 bits SISO"; - public new bool HasState => true; private bool _q0; private bool _q1; @@ -462,7 +473,7 @@ namespace UntitledLogicGame.Workspace.Gates private bool _q3; private bool _lastClk; - internal new OutputState Compute(InputState input) + internal override Func Function => (input) => { var clk = input[0]; var d = input[1]; @@ -475,16 +486,14 @@ namespace UntitledLogicGame.Workspace.Gates } _lastClk = clk; return new OutputState(_q3); - } + }; } - internal class SIPO4bGate : GateDefinition + internal class SIPO4bGate : StateGateDefinition { + public new string Name => "4bits SIPO"; public override string[] Inputs { get; } = new string[] { "CLK", "D" }; public override string[] Outputs { get; } = new string[] { "Q₀", "Q₁", "Q₂", "Q₃" }; - internal override Dictionary TruthTable => EmptyTruthTable; - public new string Name => "4 bits SIPO"; - public new bool HasState => true; private bool _q0; private bool _q1; @@ -492,7 +501,7 @@ namespace UntitledLogicGame.Workspace.Gates private bool _q3; private bool _lastClk; - internal new OutputState Compute(InputState input) + internal override Func Function => (input) => { var clk = input[0]; var d = input[1]; @@ -505,16 +514,14 @@ namespace UntitledLogicGame.Workspace.Gates } _lastClk = clk; return new OutputState(_q0, _q1, _q2, _q3); - } + }; } - internal class PIPO4bGate : GateDefinition + internal class PIPO4bGate : StateGateDefinition { - public override string[] Inputs { get; } = new string[] { "CLK", "D₀", "D₁", "D₂", "D₃" }; + public new string Name => "4bits PIPO"; + public override string[] Inputs { get; } = new string[] { "CLK", "D₀", "D₁", "D₂", "D₃" }; public override string[] Outputs { get; } = new string[] { "Q₀", "Q₁", "Q₂", "Q₃" }; - internal override Dictionary TruthTable => EmptyTruthTable; - public new string Name => "4 bits PIPO"; - public new bool HasState => true; private bool _q0; private bool _q1; @@ -522,7 +529,7 @@ namespace UntitledLogicGame.Workspace.Gates private bool _q3; private bool _lastClk; - internal new OutputState Compute(InputState input) + internal override Func Function => (input) => { var clk = input[0]; var d0 = input[1]; @@ -538,7 +545,7 @@ namespace UntitledLogicGame.Workspace.Gates } _lastClk = clk; return new OutputState(_q0, _q1, _q2, _q3); - } + }; } #endregion diff --git a/Assets/Scripts/Workspace/Gates/GateType.cs b/Assets/Scripts/Workspace/Gates/GateType.cs index dc3a5d4..dec3701 100755 --- a/Assets/Scripts/Workspace/Gates/GateType.cs +++ b/Assets/Scripts/Workspace/Gates/GateType.cs @@ -26,18 +26,21 @@ JKFlipFlop = 510, DFlipFlop = 520, TFlipFlop = 530, - // 600 - Combinational + // 600 - Arithmetic HalfAdd = 600, FullAdd = 610, HalSub = 620, FullSub = 630, - Mux = 640, - Demux = 650, - Enc = 660, - Dec = 670, - // 700 - Registers - SISO4b = 700, - SIPO4b = 710, - PIPO4b = 720, + // 700 - Data + Mux = 710, + Demux = 720, + Mux2b = 730, + Demux2b = 740, + Enc2b4b = 750, + Dec4b2b = 760, + // 800 - Registers + SISO4b = 800, + SIPO4b = 810, + PIPO4b = 820, } } diff --git a/Assets/Scripts/Workspace/Gates/State.cs b/Assets/Scripts/Workspace/Gates/State.cs index 67605bf..842e904 100755 --- a/Assets/Scripts/Workspace/Gates/State.cs +++ b/Assets/Scripts/Workspace/Gates/State.cs @@ -3,7 +3,7 @@ using System.Linq; namespace UntitledLogicGame.Workspace.Gates { - internal class InputState : State + public class InputState : State { public InputState(IEnumerable args) : base(args) { } @@ -12,7 +12,7 @@ namespace UntitledLogicGame.Workspace.Gates public InputState(int len) : base(len) { } } - internal class OutputState : State + public class OutputState : State { public OutputState(IEnumerable args) : base(args) { } @@ -21,7 +21,7 @@ namespace UntitledLogicGame.Workspace.Gates public OutputState(int len) : base(len) { } } - internal abstract class State + public abstract class State { internal int Length => values.Length; diff --git a/TODO.txt b/TODO.txt index 1334f16..e0771a4 100755 --- a/TODO.txt +++ b/TODO.txt @@ -1,11 +1,11 @@ TODO --(0) mux/demux -(2) gate bar sub categories -(2) named anchors (dezoom hide ?) -(3) clocks (1Hz, 5Hz, 10Hz, etc.) -(3) generic rect gates --(3) state gates +-(3) state gates (automatic prefab ?) -(3) cable overlap (same/diff circuit) -(5) cable management -(5) buses --(?) find a name \ No newline at end of file +-(?) find a name +